/* Calm palette: neutral surfaces + one accent (teal). Colour is used only to mark
   what matters: primary actions, income figures, selected state, progress. */
:root {
  --bg: #F6F6F4;
  --surface: #FFFFFF;
  --surface-2: #F1F1EE;
  --ink: #1F2328;
  --ink-soft: #5E646B;
  --line: #E4E4E0;
  --accent: #0E7C66;
  --accent-dark: #0A604F;
  --accent-soft: #E8F3EF;
  --on-accent: #FFFFFF;          /* text on a filled accent surface */
  --warn-soft: #FBF5E6;
  --warn-line: #EADCB4;
  --danger: #C2410C;
  --shadow: 0 1px 2px rgba(20, 20, 20, .05);
  --radius: 16px;
  /* aliases kept so older inline styles still resolve to the calm palette */
  --primary: var(--accent); --primary-dark: var(--accent-dark); --primary-soft: var(--accent-soft);
  --mint: var(--accent); --mint-soft: var(--accent-soft);
  --sun-soft: var(--surface-2); --grape-soft: var(--surface-2); --grape: var(--accent);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #17191C; --surface: #1F2226; --surface-2: #272A2F; --ink: #ECEDEE; --ink-soft: #A3A8AE;
    --line: #33373D; --accent: #3FB89A; --accent-dark: #5FCCB0; --accent-soft: #1D3631;
    --on-accent: #0B1F1A;
    --warn-soft: #2E2A1E; --warn-line: #4A4230; --shadow: none;
  }
}
:root[data-theme="dark"] {
  --bg: #17191C; --surface: #1F2226; --surface-2: #272A2F; --ink: #ECEDEE; --ink-soft: #A3A8AE;
  --line: #33373D; --accent: #3FB89A; --accent-dark: #5FCCB0; --accent-soft: #1D3631;
  --on-accent: #0B1F1A;
  --warn-soft: #2E2A1E; --warn-line: #4A4230; --shadow: none;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--ink);
  font-family: 'Noto Sans Thai', system-ui, sans-serif; font-size: 1rem; line-height: 1.75;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, h4 { font-family: 'Kanit', sans-serif; line-height: 1.35; margin: 0 0 .4em; font-weight: 500; color: var(--ink); }
h1 { font-size: clamp(1.625rem, 1rem + 3vw, 2.5rem); font-weight: 600; }
h2 { font-size: clamp(1.25rem, 1rem + 1vw, 1.5rem); }
h3 { font-size: 1.125rem; }
p { margin: 0 0 .8em; }
a { color: var(--accent); }
.container { max-width: 1040px; margin: 0 auto; padding: 0 16px; }
main.container { padding-top: 28px; padding-bottom: 64px; min-height: 70vh; outline: none; }
.muted { color: var(--ink-soft); }
.center { text-align: center; }

/* ---------- top bar ---------- */
.topbar { position: sticky; top: 0; z-index: 50; background: var(--surface); border-bottom: 1px solid var(--line); }
.topbar-inner { max-width: 1040px; margin: 0 auto; padding: 10px 16px; display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.brand { display: flex; align-items: center; gap: 8px; text-decoration: none; color: var(--ink); font-family: 'Kanit'; font-weight: 600; font-size: 1.1875rem; white-space: nowrap; }
.brand-icon { display: grid; place-items: center; width: 1.9em; height: 1.9em; border-radius: 10px; background: var(--surface-2); font-size: 1.125rem; }
.topnav { display: flex; gap: 2px; overflow-x: auto; scrollbar-width: none; }
.topnav::-webkit-scrollbar { display: none; }
.brand { min-height: 44px; min-width: 44px; }
.topnav a { display: inline-flex; align-items: center; min-height: 44px; text-decoration: none; color: var(--ink-soft); font-weight: 500; padding: 0 12px; border-radius: 8px; white-space: nowrap; font-size: 0.9375rem; }
.topnav a:hover { color: var(--ink); background: var(--surface-2); }
.topnav a.active { color: var(--accent); font-weight: 500; }
@media (max-width: 560px) {
  .brand span:last-child { display: none; }
  .topnav a { padding: 7px 9px; font-size: 0.875rem; }
}

/* ---------- buttons ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; border: 1px solid transparent; cursor: pointer; text-decoration: none;
  font-family: 'Kanit'; font-weight: 500; font-size: 1rem; padding: 11px 20px; border-radius: 10px; transition: background .15s ease, border-color .15s ease; }
.btn:focus-visible, .chip:focus-visible, .opt:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn-primary { background: var(--accent); color: var(--on-accent); }
.btn-primary:hover { background: var(--accent-dark); }
.btn-ghost { background: var(--surface); color: var(--ink); border-color: var(--line); }
.btn-ghost:hover { border-color: var(--ink-soft); }
.btn-sm { font-size: 0.875rem; padding: 7px 14px; min-height: 44px; }
.btn[disabled] { opacity: .45; cursor: not-allowed; }
.btn-shop { background: var(--surface); color: var(--accent); border-color: var(--accent); font-size: 0.875rem; padding: 6px 14px; min-height: 44px; }
.btn-shop:hover { background: var(--accent-soft); }

/* ---------- hero ---------- */
.hero { position: relative; background: var(--surface); border: 1px solid var(--line); border-radius: 20px; padding: clamp(28px, 6vw, 52px); margin-bottom: 20px; }
.hero h1 { max-width: 620px; }
.hero h1 .hl { color: var(--accent); }
.hero p.lead { font-size: 1.0625rem; max-width: 560px; color: var(--ink-soft); }
.hero-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 20px; }
.perks { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px 24px; margin-bottom: 36px; padding-top: 16px; border-top: 1px solid var(--line); }
.perk strong { display: block; font-family: 'Kanit'; font-weight: 500; font-size: 1rem; }
.perk span { font-size: 0.875rem; color: var(--ink-soft); }
@media (max-width: 760px) { .perks { grid-template-columns: 1fr; } }

.section-head { display: flex; justify-content: space-between; align-items: end; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }

/* ---------- chips / filters ---------- */
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 18px; }
.chip { border: 1px solid var(--line); background: var(--surface); color: var(--ink-soft); border-radius: 999px; padding: 6px 16px; min-height: 44px; font-family: inherit; font-size: 0.9375rem; cursor: pointer; }
.chip:hover { color: var(--ink); border-color: var(--ink-soft); }
.chip.on { background: var(--accent-soft); color: var(--accent); border-color: var(--accent); }

/* ---------- path cards ---------- */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 14px; }
.pcard { position: relative; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; text-decoration: none; color: var(--ink); display: flex; flex-direction: column; gap: 8px; transition: border-color .15s ease; }
.pcard:hover { border-color: var(--accent); }
.card-title { font-size: 1.125rem; margin: 0; }
.emo { margin-right: .4em; font-weight: 400; }
.q-title { font-size: clamp(1.25rem, 1rem + 1vw, 1.5rem); font-weight: 500; }
.h-sm { font-size: clamp(1.25rem, 1rem + 1vw, 1.5rem); font-weight: 500; }
h1[tabindex="-1"]:focus { outline: none; }
.page-title { font-size: clamp(1.625rem, 1rem + 2.5vw, 2rem); }
.home-section { margin-bottom: 32px; }
.results-sub { margin-top: 28px; }
.results-foot { margin-top: 20px; }
.small-note { font-size: 0.875rem; margin-top: 8px; }
.is-hidden { visibility: hidden; }
.pcard p { font-size: 0.9063rem; color: var(--ink-soft); margin: 0; flex: 1; }
.tags { display: flex; flex-wrap: wrap; gap: 6px; }
.tag { font-size: 0.8125rem; padding: 2px 10px; border-radius: 6px; background: var(--surface-2); color: var(--ink-soft); }
.tag.money { color: var(--accent); background: var(--accent-soft); font-weight: 600; }
.progress-pill { position: absolute; top: 16px; right: 16px; font-size: 0.75rem; font-weight: 600; color: var(--accent); }

/* ---------- quiz ---------- */
.quiz { max-width: 660px; margin: 0 auto; }
.quiz-card { background: var(--surface); border: 1px solid var(--line); border-radius: 20px; padding: clamp(20px, 5vw, 36px); }
.quiz-top { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; font-size: 0.875rem; color: var(--ink-soft); }
.bar { height: 6px; border-radius: 999px; background: var(--surface-2); overflow: hidden; margin-bottom: 26px; }
.bar > i { display: block; height: 100%; background: var(--accent); border-radius: 999px; transition: width .3s ease; }
.quiz .hint { color: var(--ink-soft); font-size: 0.9375rem; margin-bottom: 18px; }
.hint-gap { height: 8px; }
.gate-emoji { font-size: 3.5rem; }
.gate-opts { margin-top: 8px; }
.opt-sub { font-size: 0.875rem; }
.opts { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 8px; }
.opts.list { grid-template-columns: 1fr; }
.opt { display: flex; align-items: center; gap: 10px; text-align: left; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); cursor: pointer; font-family: inherit; font-size: 0.9688rem; transition: border-color .12s, background .12s; }
.opt:hover { border-color: var(--ink-soft); }
.opt.on { border-color: var(--accent); background: var(--accent-soft); }
.opt .oe { font-size: 1.1875rem; }
.quiz textarea { width: 100%; min-height: 110px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); padding: 12px 14px; font: inherit; resize: vertical; }
.quiz textarea:focus, .other-input:focus, .dfield select:focus { outline: 2px solid var(--accent); outline-offset: 1px; border-color: var(--accent); }
a:focus-visible, input[type="checkbox"]:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.counter { text-align: right; font-size: 0.8125rem; color: var(--ink-soft); margin-top: 4px; }
.other-input, .dfield select { width: 100%; margin-top: 12px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); padding: 11px 14px; font: inherit; }
.detail-form { display: grid; gap: 16px; }
.dfield { display: block; }
.dfield > span { display: block; font-weight: 500; margin-bottom: 6px; }
.dfield textarea { min-height: 64px; }
.dfield select { margin-top: 0; }
.quiz-nav { display: flex; justify-content: space-between; gap: 10px; margin-top: 26px; }

/* ---------- loading ---------- */
.loading { text-align: center; padding: 60px 16px; }
.spinner { font-size: 2.75rem; display: inline-block; animation: bob 1.4s ease-in-out infinite; }
@keyframes bob { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-8px); } }

/* ---------- results ---------- */
.ai-box { background: var(--accent-soft); border-radius: 12px; padding: 16px 18px; margin-bottom: 20px; }
.ai-box.local { background: var(--surface-2); }
.ai-box .badge { display: block; }
.ai-box p { margin: 0; }
.badge { display: inline-block; font-size: 0.7813rem; font-weight: 600; color: var(--accent); margin-bottom: 4px; }
.badge.local { color: var(--ink-soft); }
.rcard { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 22px; margin-bottom: 14px; display: grid; grid-template-columns: auto 1fr; gap: 16px; }
.rcard .rank { width: 2.1em; height: 2.1em; border-radius: 50%; display: grid; place-items: center; font-family: 'Kanit'; font-weight: 500; font-size: 1.0625rem; background: var(--surface-2); color: var(--ink); }
.rcard .card-title { margin-bottom: 8px; }
.rcard .why { font-size: 0.9375rem; margin: 12px 0; color: var(--ink); }
.rcard .first { font-size: 0.9063rem; color: var(--ink-soft); }
.rcard .actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 14px; }
.rcard.idea { grid-template-columns: 1fr; }
.rcard .steps { margin-top: 8px; }
.idea-eq { margin-top: 14px; border-top: 1px solid var(--line); padding-top: 10px; }
.idea-eq summary { cursor: pointer; font-weight: 500; }
@media (max-width: 520px) { .rcard { grid-template-columns: 1fr; } }

/* ---------- path detail ---------- */
.back { display: inline-flex; gap: 6px; align-items: center; min-height: 44px; padding-right: 8px; color: var(--ink-soft); text-decoration: none; margin-bottom: 4px; }
.section-head > a { display: inline-flex; align-items: center; min-height: 44px; }
.back:hover { color: var(--ink); }
.dhero { background: var(--surface); border: 1px solid var(--line); border-radius: 20px; padding: clamp(20px, 5vw, 32px); margin-bottom: 16px; }
.dhero-top { display: flex; flex-wrap: wrap; gap: 8px 14px; align-items: baseline; margin-bottom: 12px; }
.dhero h1 { font-size: clamp(1.5rem, 1rem + 2.5vw, 2rem); margin: 0; }
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 0; margin: 20px 0 6px; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.stat { padding: 12px 16px 12px 0; }
.stat .k { font-size: 0.8125rem; color: var(--ink-soft); display: block; }
.stat .v { font-family: 'Kanit'; font-weight: 500; font-size: 1.125rem; }
.stat:first-child .v { color: var(--accent); }
@media (max-width: 700px) {
  .stats { grid-template-columns: 1fr 1fr; }
}
.note { border: 1px solid var(--warn-line); background: var(--warn-soft); border-radius: 10px; padding: 10px 14px; font-size: 0.9063rem; margin-top: 14px; }
.action-bar { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 18px; }

.dgrid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 820px) { .dgrid { grid-template-columns: 1fr; } }
.box { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 22px; margin-bottom: 16px; }
.box h2 { font-size: 1.1875rem; display: flex; align-items: center; gap: 8px; }
ol.steps { counter-reset: s; list-style: none; padding: 0; margin: 0; }
ol.steps li { counter-increment: s; position: relative; padding: 5px 0 5px 2.4em; min-height: 2em; }
ol.steps li::before { content: counter(s); position: absolute; left: 0; top: 6px; width: 1.85em; height: 1.85em; border-radius: 50%; background: var(--surface-2); color: var(--ink-soft); display: grid; place-items: center; font-family: 'Kanit'; font-size: 0.875rem; }
ul.plain { padding-left: 20px; margin: 0; }
ul.plain li { margin-bottom: 6px; }
ul.plain.bare { list-style: none; padding: 0; }
.free, .paid { font-size: 0.75rem; padding: 1px 8px; border-radius: 6px; margin-right: 6px; border: 1px solid var(--line); color: var(--ink-soft); }
.free { color: var(--accent); border-color: var(--accent); }

.eq { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.eq:last-of-type { border-bottom: none; }
.eq-name { font-weight: 500; }
.eq-price { font-size: 0.875rem; color: var(--ink-soft); }
.eq-right { display: flex; align-items: center; gap: 10px; }
.own { display: flex; align-items: center; gap: 8px; min-height: 44px; padding: 0 4px; font-size: 0.875rem; color: var(--ink-soft); cursor: pointer; user-select: none; }
.own input { width: 17px; height: 17px; accent-color: var(--accent); }
.eq.owned .eq-name { text-decoration: line-through; color: var(--ink-soft); }
.eq-total { display: flex; justify-content: space-between; border-top: 1px solid var(--line); padding: 12px 0 0; margin-top: 4px; font-weight: 600; }
.eq-hint { font-size: 0.875rem; }
.disclose { font-size: 0.8125rem; color: var(--ink-soft); margin-top: 10px; }

.phase { margin-bottom: 28px; }
.phase:last-child { margin-bottom: 0; }
.phase-h { display: flex; justify-content: space-between; gap: 10px; align-items: baseline; flex-wrap: wrap; }
.phase-goal { font-size: 0.9063rem; color: var(--ink-soft); margin-bottom: 6px; }
.week { display: grid; grid-template-columns: 6rem 1fr; gap: 0 12px; padding: 8px 0; border-top: 1px solid var(--line); }
.week h4 { font-size: 0.875rem; font-weight: 500; margin: 0; padding-top: 6px; color: var(--ink-soft); }
@media (max-width: 520px) { .week { grid-template-columns: 1fr; } .week h4 { padding-top: 2px; } }
.task { display: flex; align-items: flex-start; gap: 10px; padding: 8px 0; min-height: 44px; cursor: pointer; }
.task input { width: 18px; height: 18px; margin-top: 4px; accent-color: var(--accent); flex-shrink: 0; cursor: pointer; }
.task.done span { text-decoration: line-through; color: var(--ink-soft); }
.overall { margin-bottom: 18px; }
.overall .bar { margin: 8px 0 0; }

/* ---------- my plans / links table ---------- */
.empty { text-align: center; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 40px 20px; }
.empty .big { font-size: 2.75rem; }
.tbl { width: 100%; border-collapse: collapse; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; font-size: 0.9063rem; }
.tbl th, .tbl td { padding: 10px 12px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
.tbl th { background: var(--surface-2); font-family: 'Kanit'; font-weight: 500; }
.tbl-wrap { overflow-x: auto; }
.tbl .used { font-size: 0.8125rem; }
.ok { color: var(--accent); font-weight: 600; }
.no { color: var(--danger); font-weight: 600; }
code { background: var(--surface-2); padding: 1px 6px; border-radius: 6px; font-size: 0.8438rem; }

/* ---------- footer / toast ---------- */
.footer { border-top: 1px solid var(--line); background: var(--surface); padding: 28px 0; font-size: 0.8438rem; color: var(--ink-soft); }
.footer-copy { margin-top: 12px; }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 120px); background: var(--ink); color: var(--bg); padding: 10px 18px; border-radius: 10px; font-size: 0.9375rem; z-index: 100; transition: transform .25s ease; max-width: calc(100% - 32px); text-align: center; }
.toast.show { transform: translate(-50%, 0); }

/* ---------- PDF stage (rendered off-screen, always light) ---------- */
#pdfStage { position: fixed; left: -10000px; top: 0; width: 794px; }
.pdf { width: 794px; background: #fff; color: #1F2328; padding: 40px 44px; font-family: 'Noto Sans Thai', sans-serif; font-size: 13px; line-height: 1.7; }
.pdf h1 { font-size: 24px; margin: 0 0 4px; color: #1F2328; font-weight: 600; }
.pdf h2 { font-size: 16px; margin: 18px 0 8px; color: #1F2328; font-weight: 500; border-bottom: 1px solid #E4E4E0; padding-bottom: 4px; }
.pdf h3 { font-size: 14px; margin: 10px 0 4px; color: #1F2328; font-weight: 500; }
.pdf .pdf-head { border-bottom: 2px solid #0E7C66; padding: 0 0 14px; margin-bottom: 14px; }
.pdf .pdf-stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-bottom: 8px; }
.pdf .pdf-stats.two { grid-template-columns: 1fr 1fr; }
.pdf .pdf-meta { font-size: 12px; color: #5E646B; }
.pdf .pdf-note { margin-top: 12px; }
.pdf .pdf-stats div { border: 1px solid #E4E4E0; border-radius: 8px; padding: 8px 10px; }
.pdf .pdf-stats b { display: block; font-size: 14px; font-weight: 600; }
.pdf .pdf-stats span { font-size: 11px; color: #5E646B; }
.pdf table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.pdf td, .pdf th { border: 1px solid #E4E4E0; padding: 6px 8px; text-align: left; }
.pdf th { background: #F6F6F4; font-weight: 500; }
.pdf a { color: #0E7C66; }
.pdf .pdf-week { break-inside: avoid; page-break-inside: avoid; border: 1px solid #E4E4E0; border-radius: 8px; padding: 8px 12px; margin-bottom: 6px; }
.pdf .box-check { display: inline-block; width: 11px; height: 11px; border: 1.5px solid #5E646B; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }
.pdf .pdf-foot { margin-top: 18px; font-size: 11px; color: #5E646B; border-top: 1px solid #E4E4E0; padding-top: 8px; }

@media print {
  .topbar, .footer, .action-bar, .no-print, .back { display: none !important; }
  body { background: #fff; }
}
/* Reduced motion: no movement, but state changes still show — the loader pulses
   in place and the toast fades instead of sliding. */
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: .35; } }
@media (prefers-reduced-motion: reduce) {
  .spinner { animation: pulse 2s ease-in-out infinite; }
  .bar > i { transition: none; }
  .toast { transform: translate(-50%, 0); opacity: 0; visibility: hidden; transition: opacity .2s ease, visibility .2s; }
  .toast.show { opacity: 1; visibility: visible; }
}
