/* ==================== CSS Variables & Reset ==================== */
:root {
  --color-primary: #FF6B35;
  --color-primary-dark: #E55A2B;
  --color-primary-light: #FFF0E8;
  --color-bg: #FFF8F5;
  --color-white: #FFFFFF;
  --color-text: #333333;
  --color-text-secondary: #666666;
  --color-text-light: #999999;
  --color-border: #F0E0D8;
  --color-shadow: rgba(255, 107, 53, 0.12);
  --color-success: #52C41A;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 20px;
  --font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Helvetica Neue", sans-serif;
}

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: var(--font-family);
  background: var(--color-bg);
  color: var(--color-text);
  line-height: 1.6;
  min-height: 100vh;
  max-width: 428px;
  margin: 0 auto;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow-x: hidden;
}

a {
  color: var(--color-primary);
  text-decoration: none;
}

/* ==================== Utility ==================== */
.hidden {
  display: none !important;
}

/* ==================== Header ==================== */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  background: var(--color-white);
  border-bottom: 1px solid var(--color-border);
  position: sticky;
  top: 0;
  z-index: 100;
  min-height: 56px;
}

.header__title {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--color-primary);
  text-align: center;
  flex: 1;
}

.header__title--small {
  font-size: 1rem;
  font-weight: 600;
}

.header__settings {
  font-size: 1.3rem;
  text-decoration: none;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  transition: background 0.2s;
}

.header__settings:active {
  background: var(--color-primary-light);
}

.header__back {
  background: none;
  border: none;
  color: var(--color-primary);
  font-size: 0.95rem;
  cursor: pointer;
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  transition: background 0.2s;
  text-decoration: none;
}

.header__back:active {
  background: var(--color-primary-light);
}

/* ==================== View System ==================== */
.view {
  display: none;
  animation: fadeIn 0.25s ease;
}

.view.active {
  display: block;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ==================== Main Content ==================== */
.main {
  padding: 16px 20px 32px;
}

/* ==================== City Row ==================== */
.city-row {
  margin-bottom: 12px;
}

.city-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: var(--color-white);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-xl);
  padding: 8px 16px;
  font-size: 0.9rem;
  color: var(--color-text);
  cursor: pointer;
  transition: all 0.2s;
  box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}

.city-btn:active {
  background: var(--color-primary-light);
  border-color: var(--color-primary);
}

/* ==================== City Picker ==================== */
.city-picker {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 200;
  max-width: 428px;
  margin: 0 auto;
}

.city-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.4);
  animation: fadeIn 0.2s ease;
}

.city-dropdown {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--color-white);
  border-radius: var(--radius-xl) var(--radius-xl) 0 0;
  padding: 20px 20px 32px;
  max-height: 60vh;
  overflow-y: auto;
  animation: slideUp 0.3s ease;
}

@keyframes slideUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

.city-dropdown__title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--color-text);
  margin-bottom: 12px;
  text-align: center;
}

.city-list {
  list-style: none;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

.city-list li {
  text-align: center;
  padding: 10px 4px;
  background: var(--color-bg);
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  cursor: pointer;
  transition: all 0.15s;
  color: var(--color-text);
}

.city-list li:active {
  background: var(--color-primary);
  color: var(--color-white);
}

/* ==================== Search ==================== */
.search-wrap {
  position: relative;
  margin-bottom: 12px;
}

.search-input {
  width: 100%;
  padding: 14px 16px;
  font-size: 1rem;
  border: 2px solid var(--color-border);
  border-radius: var(--radius-lg);
  background: var(--color-white);
  color: var(--color-text);
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
  font-family: var(--font-family);
}

.search-input:focus {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px var(--color-primary-light);
}

.search-input::placeholder {
  color: var(--color-text-light);
}

/* ==================== Suggestion Box ==================== */
.suggestion-box {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: var(--color-white);
  border: 1px solid var(--color-border);
  border-top: none;
  border-radius: 0 0 var(--radius-md) var(--radius-md);
  list-style: none;
  z-index: 50;
  max-height: 320px;
  overflow-y: auto;
  box-shadow: 0 8px 24px var(--color-shadow);
}

.suggestion-item {
  padding: 12px 16px;
  cursor: pointer;
  border-bottom: 1px solid var(--color-border);
  transition: background 0.15s;
}

.suggestion-item:last-child {
  border-bottom: none;
}

.suggestion-item:active {
  background: var(--color-primary-light);
}

.suggestion-name {
  font-size: 0.95rem;
  font-weight: 500;
  color: var(--color-text);
  display: block;
  margin-bottom: 2px;
}

.suggestion-addr {
  font-size: 0.78rem;
  color: var(--color-text-light);
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ==================== Search Results ==================== */
.search-results {
  margin-bottom: 12px;
}

.results-empty {
  text-align: center;
  color: var(--color-text-light);
  padding: 32px 16px;
  font-size: 0.9rem;
}

.result-card {
  background: var(--color-white);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  margin-bottom: 8px;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(0,0,0,0.04);
  transition: transform 0.15s, box-shadow 0.15s;
  border: 1px solid var(--color-border);
}

.result-card:active {
  transform: scale(0.98);
  box-shadow: 0 4px 16px var(--color-shadow);
  border-color: var(--color-primary);
}

.result-card__name {
  font-size: 1rem;
  font-weight: 600;
  color: var(--color-text);
  margin-bottom: 4px;
}

.result-card__addr {
  font-size: 0.82rem;
  color: var(--color-text-secondary);
  margin-bottom: 6px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.result-card__meta {
  font-size: 0.8rem;
  color: var(--color-text-light);
}

/* ==================== Selected Card ==================== */
.selected-card {
  background: linear-gradient(135deg, var(--color-primary-light), #FFF5EE);
  border: 2px solid var(--color-primary);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  margin-bottom: 16px;
  animation: fadeIn 0.3s ease;
}

.selected-card__check {
  font-size: 0.82rem;
  color: var(--color-primary);
  font-weight: 600;
  margin-bottom: 4px;
}

.selected-card__name {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--color-text);
  margin-bottom: 2px;
}

.selected-card__addr {
  font-size: 0.82rem;
  color: var(--color-text-secondary);
}

/* ==================== Input Groups ==================== */
.input-group {
  margin-bottom: 16px;
}

.input-label {
  display: block;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--color-text);
  margin-bottom: 6px;
}

.text-input {
  width: 100%;
  padding: 12px 14px;
  font-size: 0.9rem;
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-white);
  color: var(--color-text);
  outline: none;
  resize: vertical;
  font-family: var(--font-family);
  line-height: 1.5;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.text-input:focus {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px var(--color-primary-light);
}

.text-input::placeholder {
  color: var(--color-text-light);
}

/* ==================== Generate Button ==================== */
.btn-generate {
  display: block;
  width: 100%;
  padding: 16px;
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--color-white);
  background: linear-gradient(135deg, var(--color-primary), #FF8C60);
  border: none;
  border-radius: var(--radius-lg);
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s, opacity 0.15s;
  box-shadow: 0 4px 16px rgba(255, 107, 53, 0.3);
  font-family: var(--font-family);
  letter-spacing: 0.5px;
}

.btn-generate:active {
  transform: scale(0.97);
  box-shadow: 0 2px 8px rgba(255, 107, 53, 0.2);
  opacity: 0.9;
}

/* ==================== Result View ==================== */
.review-card {
  background: var(--color-white);
  border-radius: var(--radius-lg);
  padding: 20px;
  margin-bottom: 20px;
  box-shadow: 0 4px 20px var(--color-shadow);
  border: 1px solid var(--color-border);
  min-height: 120px;
}

.result-text {
  font-size: 1rem;
  line-height: 1.8;
  color: var(--color-text);
  white-space: pre-wrap;
  word-break: break-word;
}

.result-actions {
  display: flex;
  gap: 12px;
}

.btn-copy,
.btn-regenerate {
  flex: 1;
  padding: 14px;
  font-size: 0.95rem;
  font-weight: 600;
  border-radius: var(--radius-md);
  border: none;
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s;
  font-family: var(--font-family);
}

.btn-copy {
  background: var(--color-primary);
  color: var(--color-white);
  box-shadow: 0 3px 12px rgba(255, 107, 53, 0.25);
}

.btn-copy:active {
  transform: scale(0.97);
}

.btn-regenerate {
  background: var(--color-white);
  color: var(--color-primary);
  border: 1.5px solid var(--color-primary);
}

.btn-regenerate:active {
  background: var(--color-primary-light);
  transform: scale(0.97);
}

/* ==================== Toast ==================== */
.toast {
  position: fixed;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(51, 51, 51, 0.92);
  color: var(--color-white);
  padding: 12px 24px;
  border-radius: var(--radius-xl);
  font-size: 0.9rem;
  z-index: 300;
  max-width: 85vw;
  text-align: center;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  transition: opacity 0.3s ease, transform 0.3s ease;
  opacity: 0;
  transform: translateX(-50%) translateY(10px);
  pointer-events: none;
}

.toast.toast--show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ==================== Loading Overlay ==================== */
.loading-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(255, 255, 255, 0.85);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 250;
  max-width: 428px;
  margin: 0 auto;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

.loading-spinner {
  width: 44px;
  height: 44px;
  border: 3px solid var(--color-border);
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin-bottom: 16px;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.loading-text {
  font-size: 0.95rem;
  color: var(--color-text-secondary);
  font-weight: 500;
}

/* ==================== Settings Page ==================== */
.settings-page .main {
  padding-top: 24px;
}

.settings-section {
  margin-bottom: 24px;
}

.settings-section__title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--color-text);
  margin-bottom: 10px;
}

.settings-input {
  width: 100%;
  padding: 14px 16px;
  font-size: 0.95rem;
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-white);
  color: var(--color-text);
  outline: none;
  font-family: monospace;
  letter-spacing: 0.5px;
  transition: border-color 0.2s, box-shadow 0.2s;
  margin-bottom: 8px;
}

.settings-input:focus {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px var(--color-primary-light);
}

.settings-input::placeholder {
  color: #ccc;
  font-family: var(--font-family);
}

.settings-hint {
  font-size: 0.8rem;
  color: var(--color-text-light);
  line-height: 1.6;
}

.settings-hint a {
  color: var(--color-primary);
  font-weight: 500;
}

.settings-page .btn-generate {
  margin-bottom: 24px;
}

/* ==================== Privacy Note ==================== */
.privacy-note {
  background: var(--color-primary-light);
  border-radius: var(--radius-md);
  padding: 16px;
  font-size: 0.82rem;
  color: var(--color-text-secondary);
  line-height: 1.7;
}

.privacy-note p:first-child {
  margin-bottom: 6px;
  color: var(--color-text);
}

/* ==================== Tap Highlight ==================== */
* {
  -webkit-tap-highlight-color: transparent;
}

button, a, li, .result-card, .suggestion-item {
  -webkit-touch-callout: none;
  user-select: none;
  -webkit-user-select: none;
}

/* ==================== Scrollbar ==================== */
::-webkit-scrollbar {
  width: 4px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: #ddd;
  border-radius: 2px;
}

/* ==================== Safe Area (iPhone notch) ==================== */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
  .main {
    padding-bottom: calc(32px + env(safe-area-inset-bottom));
  }

  .toast {
    bottom: calc(80px + env(safe-area-inset-bottom));
  }

  .city-dropdown {
    padding-bottom: calc(32px + env(safe-area-inset-bottom));
  }
}
