:root {
  --bg: #f6f3ee;
  --surface: #ffffff;
  --surface-2: #fbf9f5;
  --border: #e6e0d4;
  --text: #2a261f;
  --text-muted: #837a68;
  --accent: #a8763e;
  --accent-strong: #8c5f2c;
  --accent-soft: #f1e4d0;
  --danger: #b0402f;
  --danger-bg: #fbe9e6;
  --radius-lg: 18px;
  --radius-md: 12px;
  --radius-sm: 8px;
  --shadow: 0 2px 14px rgba(40, 30, 10, 0.07);
  --shadow-sm: 0 1px 4px rgba(40, 30, 10, 0.05);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15130f;
    --surface: #201d17;
    --surface-2: #262219;
    --border: #38332a;
    --text: #ece7dc;
    --text-muted: #a89d89;
    --accent: #d7a55f;
    --accent-strong: #e8bc7d;
    --accent-soft: #3a2f1e;
    --danger: #e0796a;
    --danger-bg: #3a221f;
    --shadow: 0 2px 14px rgba(0, 0, 0, 0.35);
    --shadow-sm: 0 1px 4px rgba(0, 0, 0, 0.25);
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, "Segoe UI", "PingFang SC", "Hiragino Sans", "Noto Sans JP", sans-serif;
  line-height: 1.6;
  padding-bottom: env(safe-area-inset-bottom);
}

/* ---------- 顶部条 ---------- */
.top-bar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px max(16px, env(safe-area-inset-left));
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}
.brand {
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.08em;
  color: var(--text-muted);
}
.logout-btn {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  font-size: 12.5px;
  padding: 6px 14px;
  border-radius: 999px;
  cursor: pointer;
  min-height: 32px;
}
.logout-btn:hover { border-color: var(--accent); color: var(--accent); }

/* ---------- 头部 ---------- */
.app-header {
  text-align: center;
  padding: 32px 20px 18px;
}
.app-header h1 {
  margin: 0 0 6px;
  font-size: clamp(24px, 5vw, 30px);
  letter-spacing: 0.02em;
  color: var(--accent);
}
.subtitle {
  margin: 0;
  color: var(--text-muted);
  font-size: 13.5px;
}

/* ---------- 关系挡位 ---------- */
.context-bar {
  max-width: 980px;
  margin: 0 auto 22px;
  padding: 18px 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
}
.context-row {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}
.context-row:last-child { margin-bottom: 0; }
.context-label {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-muted);
  min-width: 80px;
  flex-shrink: 0;
}
.preset-group {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  flex: 1;
}
.preset-btn {
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  padding: 9px 16px;
  border-radius: 999px;
  font-size: 13.5px;
  cursor: pointer;
  transition: transform 0.1s ease, border-color 0.15s ease, background 0.15s ease;
  min-height: 38px;
}
.preset-btn:hover { border-color: var(--accent); }
.preset-btn:active { transform: scale(0.97); }
.preset-btn.active {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent-strong);
  font-weight: 700;
}
#customContext {
  flex: 1;
  min-width: 200px;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text);
  font-size: 13.5px;
  min-height: 38px;
}
#customContext:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

/* ---------- 面板 ---------- */
.panels {
  max-width: 980px;
  margin: 0 auto;
  padding: 0 20px 40px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: 20px;
  display: flex;
  flex-direction: column;
}
.panel-title {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 2px;
}
.panel-icon { font-size: 18px; }
.panel h2 {
  margin: 0;
  font-size: 17px;
}
.hint {
  margin: 4px 0 12px;
  font-size: 12.5px;
  color: var(--text-muted);
}

textarea {
  width: 100%;
  resize: vertical;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface-2);
  color: var(--text);
  font-size: 15px;
  font-family: inherit;
}
textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

.primary-btn {
  margin-top: 12px;
  width: 100%;
  min-height: 46px;
  padding: 10px 16px;
  border: none;
  border-radius: var(--radius-md);
  background: var(--accent);
  color: #fff;
  font-size: 14.5px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: opacity 0.15s ease, transform 0.1s ease;
}
.primary-btn:hover { opacity: 0.92; }
.primary-btn:active { transform: scale(0.99); }
.primary-btn:disabled { opacity: 0.6; cursor: default; }

.btn-spinner {
  width: 15px;
  height: 15px;
  border: 2px solid rgba(255, 255, 255, 0.4);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- 结果卡片 ---------- */
.result-card {
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
  animation: fade-in 0.2s ease;
}
@keyframes fade-in {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}
.result-row { margin-bottom: 12px; }
.result-row:last-child { margin-bottom: 0; }
.result-label {
  display: inline-block;
  font-size: 11px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 3px;
}
.result-row p {
  margin: 0;
  font-size: 14.5px;
  white-space: pre-wrap;
}
.tone-summary p {
  color: var(--accent-strong);
  font-weight: 600;
}

.badge-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}
.badge {
  display: inline-block;
  font-size: 12.5px;
  padding: 5px 12px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
}
.badge-accent {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent-strong);
  font-weight: 600;
}

.callout {
  display: flex;
  gap: 10px;
  background: var(--accent-soft);
  border: 1px solid color-mix(in srgb, var(--accent) 40%, var(--border));
  border-radius: var(--radius-md);
  padding: 12px 14px;
  margin-bottom: 12px;
}
.callout-icon { font-size: 16px; line-height: 1.4; }
.callout .result-label { color: var(--accent-strong); }
.callout p { margin: 0; font-size: 14px; }

.options {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 8px;
}
.option-card {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 13px 14px;
  background: var(--surface-2);
}
.option-card .option-label {
  font-size: 12px;
  font-weight: 700;
  color: var(--accent-strong);
  margin-bottom: 6px;
  display: block;
}
.option-card .option-text {
  font-size: 15.5px;
  margin: 0 0 6px;
  white-space: pre-wrap;
}
.option-card .option-note {
  font-size: 12.5px;
  color: var(--text-muted);
  margin: 0 0 10px;
}
.copy-btn {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 12.5px;
  padding: 6px 14px;
  border-radius: 999px;
  cursor: pointer;
  min-height: 32px;
}
.copy-btn:hover { border-color: var(--accent); color: var(--accent); }

.error-box {
  margin-top: 14px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: var(--danger-bg);
  color: var(--danger);
  font-size: 13px;
}

.app-footer {
  text-align: center;
  padding: 10px 20px 26px;
  color: var(--text-muted);
  font-size: 11.5px;
}

/* ---------- 登录页 ---------- */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.login-card {
  width: 100%;
  max-width: 340px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: 34px 28px;
  text-align: center;
}
.login-card h1 {
  margin: 0 0 6px;
  font-size: 22px;
  color: var(--accent);
}
.login-card .subtitle {
  margin: 0 0 22px;
  font-size: 13px;
}
.login-card input {
  width: 100%;
  min-height: 44px;
  padding: 10px 14px;
  margin-bottom: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface-2);
  color: var(--text);
  font-size: 15px;
}
.login-card input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.login-card .primary-btn { margin-top: 4px; }
.login-card .error-box { text-align: left; }

/* ---------- 手机自适应 ---------- */
@media (max-width: 760px) {
  .panels { grid-template-columns: 1fr; padding: 0 14px 32px; gap: 16px; }
  .context-bar { margin: 0 14px 18px; padding: 16px; }
  .context-row { gap: 10px; }
  .context-label { min-width: 100%; }
  .preset-btn { flex: 1 1 calc(50% - 8px); text-align: center; }
  #customContext { min-width: 100%; }
  .app-header { padding: 22px 16px 14px; }
  .panel { padding: 16px; border-radius: var(--radius-md); }
  textarea { font-size: 16px; } /* 16px 防止 iOS 聚焦时自动放大页面 */
  .top-bar { padding: 8px 14px; }
}

@media (max-width: 420px) {
  .preset-btn { flex: 1 1 100%; }
}
