:root {
  --bg: #E9E3D3;
  --bg-elevated: #F6F1E4;
  --text: #211D16;
  --text-muted: #6B6255;
  --accent: #8A6D3B;
  --accent-strong: #6B5229;
  --accent-soft: #E4D8B8;
  --border: #D2C6A6;
  --danger: #A23B2E;
  --success: #4C6A4C;
  --shadow: 0 8px 22px rgba(33, 29, 22, 0.14);
  --carve: inset 0 1px 2px rgba(33, 29, 22, 0.18), inset 0 -1px 0 rgba(255, 255, 255, 0.5);
  --on-accent: #FBF7EC;
  --radius-lg: 18px;
  --radius-md: 12px;
  --radius-sm: 9px;
  --font-display: Georgia, "Times New Roman", "Noto Serif", serif;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17140F;
    --bg-elevated: #241F17;
    --text: #EAE2D0;
    --text-muted: #A79B85;
    --accent: #C9A567;
    --accent-strong: #DBBB84;
    --accent-soft: #332B1C;
    --border: #3A3225;
    --shadow: 0 8px 22px rgba(0, 0, 0, 0.45);
    --carve: inset 0 1px 2px rgba(0, 0, 0, 0.5), inset 0 -1px 0 rgba(255, 255, 255, 0.04);
    --on-accent: #211A0E;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Inter", Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}

button { font-family: inherit; }

#app {
  position: relative;
  max-width: 520px;
  margin: 0 auto;
  min-height: 100vh;
  min-height: 100dvh;
  overflow: hidden;
  background: var(--bg);
}

.screen {
  display: none;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
  padding: calc(20px + var(--safe-top)) 20px calc(20px + var(--safe-bottom));
  animation: fadeIn 0.25s ease;
}
.screen.active { display: flex; }

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

/* ===== Buttons ===== */
.btn {
  border: none;
  border-radius: var(--radius-md);
  padding: 15px 20px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  width: 100%;
  transition: transform 0.12s ease, opacity 0.12s ease, background 0.15s ease;
  touch-action: manipulation;
}
.btn:active { transform: scale(0.97); }
.btn-lg { padding: 17px 20px; font-size: 17px; border-radius: var(--radius-lg); }
.btn-sm { padding: 10px 14px; font-size: 14px; width: auto; }

.btn-primary { background: var(--accent); color: var(--on-accent); box-shadow: var(--shadow); }
.btn-primary:hover { background: var(--accent-strong); }
.btn-secondary { background: var(--accent-soft); color: var(--accent-strong); }
.btn-ghost { background: transparent; color: var(--text-muted); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger-outline { background: transparent; color: var(--danger); border: 1.5px solid var(--danger); margin-top: 8px; }

.link-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 14px;
  cursor: pointer;
  text-decoration: underline;
  padding: 8px;
}

.icon-btn {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  box-shadow: var(--carve);
  color: var(--text);
  width: 40px;
  height: 40px;
  border-radius: 50%;
  font-size: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
}

/* ===== Welcome Screen ===== */
.lang-toggle {
  position: absolute;
  top: calc(20px + var(--safe-top));
  right: 20px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 999px;
  padding: 7px 14px;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.03em;
  cursor: pointer;
}

.welcome-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 6px;
  padding-top: 40px;
}

.brand-mark { margin-bottom: 10px; }

.app-title {
  font-family: var(--font-display);
  font-size: 30px;
  font-weight: 700;
  margin: 0;
  letter-spacing: 0.01em;
}

.app-tagline {
  color: var(--text-muted);
  font-size: 15px;
  margin: 4px 0 20px;
}

.welcome-wrap .btn { max-width: 320px; margin-bottom: 10px; }

.resume-block { width: 100%; max-width: 320px; margin-top: 6px; display: flex; flex-direction: column; gap: 8px; }
.hidden { display: none !important; }

.bottom-links {
  align-self: center;
  margin-top: auto;
  display: flex;
  align-items: center;
  gap: 8px;
}
.bottom-link-sep { color: var(--border); font-size: 13px; }

/* ===== Modal ===== */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(10, 8, 16, 0.55);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 100;
  animation: fadeIn 0.2s ease;
}
@media (min-width: 560px) {
  .modal-backdrop { align-items: center; }
}
.modal-card {
  background: var(--bg-elevated);
  border-radius: 22px 22px 0 0;
  padding: 26px 22px calc(26px + var(--safe-bottom));
  width: 100%;
  max-width: 480px;
  box-shadow: var(--shadow);
  animation: slideUp 0.25s ease;
}
@media (min-width: 560px) {
  .modal-card { border-radius: 22px; }
}
@keyframes slideUp { from { transform: translateY(30px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
.modal-card h2 { font-family: var(--font-display); margin: 0 0 12px; font-size: 20px; }
.modal-card p { color: var(--text-muted); line-height: 1.55; font-size: 14.5px; margin: 0 0 20px; }
.modal-card p.about-body { white-space: pre-line; }
.modal-actions { display: flex; gap: 10px; }
.modal-actions .btn { flex: 1; }

/* ===== Test Screen ===== */
.test-topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 28px;
}
.topbar-spacer { width: 40px; flex-shrink: 0; }

.progress-wrap { flex: 1; text-align: center; }
.progress-track {
  height: 6px;
  background: var(--border);
  border-radius: 999px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  width: 0%;
  background: var(--accent);
  border-radius: 999px;
  transition: width 0.3s ease;
}
.progress-label {
  display: block;
  margin-top: 6px;
  font-size: 12.5px;
  color: var(--text-muted);
  font-weight: 600;
}

.card-stage {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 180px;
}

.test-card {
  width: 100%;
  max-width: 380px;
  min-height: 200px;
  background: var(--bg-elevated);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow), var(--carve);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 30px;
  text-align: center;
  border: 1px solid var(--border);
}
.test-card.pop { animation: cardPop 0.28s ease; }
@keyframes cardPop {
  0% { transform: scale(0.9) translateY(10px); opacity: 0; }
  100% { transform: scale(1) translateY(0); opacity: 1; }
}

.card-word {
  font-family: var(--font-display);
  font-size: 28px;
  font-weight: 700;
  line-height: 1.25;
  letter-spacing: 0.01em;
}

.scale-wrap {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 24px;
}

.scale-btn {
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  padding: 13px 16px;
  border-radius: var(--radius-md);
  border: 1.5px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text);
  font-size: 14.5px;
  font-weight: 600;
  cursor: pointer;
  text-align: left;
  transition: transform 0.1s ease, background 0.15s ease, border-color 0.15s ease;
}
.scale-btn:active { transform: scale(0.98); }
.scale-btn.selected {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--on-accent);
}
.scale-num {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent-strong);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 800;
  flex-shrink: 0;
}
.scale-btn.selected .scale-num { background: rgba(0,0,0,0.15); color: var(--on-accent); }

.back-btn { margin-top: 16px; }

/* ===== Mode Choice Screen ===== */
.mode-choice-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  text-align: center;
  padding-top: 10px;
}
.mode-choice-wrap .results-title { margin: 0; }
.mode-choice-wrap .results-subtitle { margin: 0 0 8px; max-width: 340px; }
.mode-card {
  width: 100%;
  max-width: 380px;
  text-align: left;
  background: var(--bg-elevated);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px 20px;
  box-shadow: var(--shadow), var(--carve);
  display: flex;
  flex-direction: column;
  gap: 4px;
  transition: border-color 0.2s ease;
}
.mode-card:active { border-color: var(--accent); }
.mode-card-title { font-family: var(--font-display); font-size: 17px; font-weight: 700; color: var(--text); }
.mode-card-desc { font-size: 13.5px; color: var(--text-muted); line-height: 1.5; }
.mode-card-meta { font-size: 11px; letter-spacing: 0.04em; text-transform: uppercase; color: var(--accent-strong); margin-top: 6px; font-weight: 700; }

/* ===== Deep Test (duo choice) Screen ===== */
.duo-stage {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  min-height: 180px;
}
.duo-instruction { font-size: 12.5px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.06em; margin: 0 0 4px; }
.duo-option {
  width: 100%;
  max-width: 400px;
  min-height: 88px;
  background: var(--bg-elevated);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow), var(--carve);
  border: 1.5px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px 22px;
  text-align: center;
  transition: border-color 0.15s ease, transform 0.1s ease;
}
.duo-option:active { border-color: var(--accent); transform: scale(0.98); }
.duo-option.selected { border-color: var(--accent); box-shadow: var(--shadow), var(--carve), 0 0 0 2px var(--accent-soft); }
.duo-option-text { font-family: var(--font-display); font-size: 16px; font-weight: 600; line-height: 1.4; }

/* ===== Results Screen ===== */
.results-scroll {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.results-title { font-family: var(--font-display); font-size: 25px; font-weight: 700; margin: 8px 0 2px; }
.results-subtitle { color: var(--text-muted); font-size: 14px; margin: 0 0 20px; }

.dominant-card {
  background: var(--bg-elevated);
  border-radius: var(--radius-lg);
  padding: 20px;
  box-shadow: var(--shadow), var(--carve);
  border: 1px solid var(--border);
  margin-bottom: 16px;
}
.dominant-label {
  display: inline-block;
  font-size: 11.5px;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--accent-strong);
  background: var(--accent-soft);
  padding: 4px 10px;
  border-radius: 999px;
  margin-bottom: 12px;
}
.dominant-body { display: flex; gap: 14px; align-items: flex-start; }
.dominant-symbol {
  width: 52px;
  height: 52px;
  border-radius: 16px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 20px;
  color: var(--on-accent);
  background: var(--accent);
}
.dominant-name { font-family: var(--font-display); font-size: 20px; margin: 0 0 4px; }
.dominant-triad { font-size: 12.5px; color: var(--text-muted); margin: 0; text-transform: uppercase; letter-spacing: 0.05em; font-weight: 700; }
.dominant-aspect { margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--border); }
.aspect-label {
  display: block;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--accent-strong);
  margin-bottom: 5px;
}
.aspect-text { font-size: 13.5px; color: var(--text); margin: 0; line-height: 1.5; }
.aspect-text-follow { margin-top: 10px; }
.dominant-inspiration {
  font-size: 12px;
  color: var(--text-muted);
  font-style: italic;
  margin: 14px 0 0;
  line-height: 1.5;
}
.dominant-accuracy { margin-top: 14px; font-size: 13px; color: var(--text-muted); font-weight: 600; }
.dominant-accuracy b { color: var(--text); font-size: 15px; }

.tie-note {
  font-size: 13px;
  color: var(--text-muted);
  background: var(--accent-soft);
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  margin: 0 0 10px;
  line-height: 1.5;
}
.tie-note-muted {
  background: transparent;
  border: 1px dashed var(--border);
  margin-bottom: 16px;
}

.section-heading {
  font-size: 15px;
  font-weight: 800;
  margin: 22px 0 10px;
}

.score-bars { display: flex; flex-direction: column; gap: 10px; }
.score-bar-row { display: flex; align-items: center; gap: 10px; }
.score-bar-label { width: 112px; font-size: 11.5px; line-height: 1.3; font-weight: 700; flex-shrink: 0; }
.score-bar-track {
  flex: 1;
  height: 20px;
  background: var(--accent-soft);
  border-radius: 999px;
  overflow: hidden;
  position: relative;
}
.score-bar-fill {
  display: block;
  height: 100%;
  background: var(--accent);
  border-radius: 999px;
  transition: width 0.6s ease;
}
.score-bar-pct {
  width: 40px;
  font-size: 12px;
  font-weight: 700;
  text-align: right;
  color: var(--text-muted);
  flex-shrink: 0;
}

.levels-list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 4px; }
.levels-row {
  display: flex;
  gap: 12px;
  align-items: baseline;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
}
.levels-tag {
  flex-shrink: 0;
  width: 84px;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--accent-strong);
}
.levels-text { font-size: 13px; color: var(--text); margin: 0; line-height: 1.45; }
.levels-healthy { border-left: 3px solid var(--success); }
.levels-stress { border-left: 3px solid var(--danger); }

.paywall-card {
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: flex-start;
  background: var(--bg-elevated);
  border: 1px dashed var(--accent);
  border-radius: var(--radius-lg);
  padding: 20px;
  margin: 4px 0 10px;
}
.paywall-heading { font-family: var(--font-display); font-size: 16px; font-weight: 700; color: var(--text); }
.paywall-body { font-size: 13px; color: var(--text-muted); line-height: 1.5; margin: 0; }
#btnUnlockReport, #detailBtnUnlockReport { display: block; margin-top: 4px; text-decoration: none; text-align: center; box-sizing: border-box; }
.coupon-divider {
  align-self: center;
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-top: 4px;
}
.coupon-row { display: flex; gap: 8px; width: 100%; }
.coupon-input { flex: 1; }
.coupon-row .btn { width: auto; flex-shrink: 0; }

.verdict-box {
  background: var(--bg-elevated);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  margin: 12px 0 4px;
}
.verdict-text { font-size: 13.5px; color: var(--text); margin: 4px 0 0; line-height: 1.55; font-style: italic; }

.trait-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.trait-chip {
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-size: 13px;
  font-weight: 700;
  padding: 8px 14px;
  border-radius: 999px;
}

.challenges-list, .faq-list { display: flex; flex-direction: column; gap: 10px; margin-bottom: 4px; }
.challenge-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
}
.challenge-title {
  display: block;
  font-size: 11.5px;
  font-weight: 800;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--accent-strong);
  margin-bottom: 5px;
}
.challenge-text { font-size: 13px; color: var(--text); margin: 0; line-height: 1.45; }
.faq-item {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
}
.faq-q { font-size: 13.5px; font-weight: 800; color: var(--text); margin: 0 0 6px; line-height: 1.4; }
.faq-a { font-size: 13px; color: var(--text-muted); margin: 0; line-height: 1.5; }

.results-actions { display: flex; flex-direction: column; gap: 10px; margin: 26px 0 10px; }

.cta-card {
  display: flex;
  flex-direction: column;
  gap: 6px;
  text-decoration: none;
  background: var(--accent);
  color: var(--on-accent);
  border-radius: var(--radius-lg);
  padding: 20px;
  margin-top: 24px;
  box-shadow: var(--shadow), var(--carve);
}
.cta-heading { font-family: var(--font-display); font-size: 17px; font-weight: 700; }
.cta-body { font-size: 13px; line-height: 1.5; opacity: 0.92; }
.cta-button {
  display: inline-block;
  margin-top: 6px;
  font-size: 13.5px;
  font-weight: 800;
  text-decoration: underline;
}

.brand-signature {
  display: block;
  text-align: center;
  margin-top: 10px;
  font-size: 11.5px;
  color: var(--text-muted);
  text-decoration: none;
}
.brand-signature:hover { text-decoration: underline; }

.lead-gate-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 6px;
  padding-bottom: 20px;
}
.lead-gate-heading { font-family: var(--font-display); font-size: 22px; font-weight: 700; color: var(--text); }
.lead-gate-body { font-size: 14px; line-height: 1.55; color: var(--text-muted); margin: 6px 0 4px; }
.lead-form { display: flex; flex-direction: column; gap: 10px; margin-top: 8px; }
.lead-field { display: flex; flex-direction: column; gap: 4px; }
.lead-field-label { font-size: 12px; font-weight: 700; color: var(--text-muted); }
.lead-input {
  width: 100%;
  padding: 12px 14px;
  border-radius: var(--radius-md);
  border: 1.5px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
}
.lead-input:focus { outline: none; border-color: var(--accent); }
.lead-consent {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.5;
  cursor: pointer;
}
.lead-consent input { margin-top: 2px; flex-shrink: 0; }
.lead-status { font-size: 13px; font-weight: 600; margin: 4px 0 0; }
.lead-status.success { color: var(--success); }
.lead-status.error { color: var(--danger); }

/* ===== History ===== */
.history-title { font-size: 18px; font-weight: 800; margin: 0; flex: 1; text-align: center; }
.history-scroll { flex: 1; overflow-y: auto; }
.history-list { display: flex; flex-direction: column; gap: 10px; margin-bottom: 16px; }
.history-item {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 14px;
  cursor: pointer;
}
.history-symbol {
  width: 40px; height: 40px; border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  color: var(--on-accent); background: var(--accent); font-weight: 800; font-size: 15px; flex-shrink: 0;
}
.history-info { flex: 1; min-width: 0; }
.history-type { font-size: 14.5px; font-weight: 700; margin: 0; }
.history-date { font-size: 12px; color: var(--text-muted); margin: 2px 0 0; }
.history-delete {
  background: none; border: none; color: var(--text-muted);
  font-size: 16px; cursor: pointer; padding: 6px;
}
.history-empty { color: var(--text-muted); font-size: 14px; text-align: center; margin-top: 60px; }
.detail-back { margin-bottom: 8px; }

/* ===== Install Banner ===== */
.install-banner {
  position: fixed;
  left: 16px;
  right: 16px;
  bottom: calc(16px + var(--safe-bottom));
  max-width: 488px;
  margin: 0 auto;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  border-radius: var(--radius-md);
  padding: 14px;
  z-index: 90;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.install-text { display: flex; flex-direction: column; gap: 2px; font-size: 13px; }
.install-text strong { font-size: 14px; }
.install-text span { color: var(--text-muted); }
.install-actions { display: flex; gap: 8px; justify-content: flex-end; }
