/* ==========================================================================
   Manapla Money Coach — design tokens
   Concept: the bank passbook / harvest ledger. Ruled lines, stamped seals,
   tabular figures — same layout language as before, now carrying the
   bank's actual logo colors (deep indigo seal, periwinkle-blue accent,
   pale lavender-grey ground) instead of the earlier placeholder
   sugarcane-green/harvest-gold guess. Built to be legible on cheap phones
   in bright daylight, at default zoom, with big tap targets and no
   dependency on network fonts.
   ========================================================================== */

:root {
  /* Color: named after the old palette on purpose — see site/css/styles.css */
  --green-900: #14113f;   /* near-black indigo, for text */
  --green-800: #2f2b8f;   /* primary brand indigo (from the logo seal, lightened) */
  --green-700: #4744ad;
  --green-100: #eceafa;   /* pale lavender tint for surfaces */
  --gold-600: #423d99;    /* accent text-on-cream, clears 4.5:1 contrast */
  --gold-500: #7d82e6;    /* periwinkle blue, primary accent — lightened for a softer look */
  --gold-300: #d9d8f5;    /* light lavender, highlights */
  --cream-100: #f5f4fa;   /* ledger paper background */
  --cream-50: #fbfafd;
  --ink: #201d3d;         /* body text */
  --ink-soft: #55527a;    /* secondary text */
  --line: #d6d4ea;        /* ruled ledger line */
  --stamp-red: #9c3b2e;   /* used sparingly: alerts, incorrect */
  --white: #ffffff;

  --radius-sm: 4px;
  --radius-md: 10px;
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;
  --space-7: 48px;

  --font-body: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Noto Sans", Helvetica, Arial, sans-serif;
  --font-display: Georgia, "Noto Serif", "Times New Roman", serif;

  --max-width: 480px;
  --focus-ring: 3px solid var(--gold-500);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --green-100: #1a1852;
    --cream-100: #14122c;
    --cream-50: #191733;
    --ink: #ece9fb;
    --ink-soft: #b6b2d9;
    --line: #363268;
    --white: #1c1a3a;
    --gold-600: #8f92e6; /* lighter periwinkle so text stays 4.5:1+ on dark backgrounds */
  }
}
:root[data-theme="dark"] {
  --green-100: #1a1852;
  --cream-100: #14122c;
  --cream-50: #191733;
  --ink: #ece9fb;
  --ink-soft: #b6b2d9;
  --line: #363268;
  --white: #1c1a3a;
  --gold-600: #8f92e6;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: var(--font-body);
  background: var(--cream-100);
  color: var(--ink);
  line-height: 1.5;
  font-size: 17px;
  font-variant-numeric: tabular-nums;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}

a { color: var(--green-800); }
:root[data-theme="dark"] a, @media (prefers-color-scheme: dark) { }

button, input, select, textarea { font-family: inherit; font-size: inherit; color: inherit; }

:focus-visible { outline: var(--focus-ring); outline-offset: 2px; }

h1, h2, h3 { font-family: var(--font-display); font-weight: 700; margin: 0 0 var(--space-2); line-height: 1.2; }
h1 { font-size: 1.7rem; }
h2 { font-size: 1.3rem; }
h3 { font-size: 1.08rem; }
p { margin: 0 0 var(--space-3); }

.app-shell {
  max-width: var(--max-width);
  margin: 0 auto;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--cream-100);
  position: relative;
}

/* ---- Header: ledger masthead ------------------------------------------ */
.masthead {
  background: var(--green-800);
  color: var(--cream-50);
  padding: var(--space-4) var(--space-4) var(--space-3);
  border-bottom: 3px solid var(--gold-500);
}
.masthead-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
}
.masthead-brand {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-width: 0;
  text-decoration: none;
}
a.masthead-brand:hover .masthead-title,
a.masthead-brand:focus-visible .masthead-title {
  text-decoration: underline;
}
.masthead-brand img { width: 34px; height: 34px; flex: none; }
.masthead-title { font-family: var(--font-display); font-weight: 700; font-size: 1.05rem; color: var(--cream-50); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.masthead-tagline { font-size: 0.78rem; color: var(--gold-300); margin: 0; }

.lang-switcher {
  display: flex;
  border: 1px solid var(--gold-500);
  border-radius: var(--radius-sm);
  overflow: hidden;
  flex: none;
}
.lang-switcher button {
  background: transparent;
  border: 0;
  color: var(--cream-50);
  padding: var(--space-1) var(--space-2);
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  border-left: 1px solid var(--gold-500);
}
.lang-switcher button:first-child { border-left: 0; }
.lang-switcher button[aria-pressed="true"] { background: var(--gold-500); color: var(--green-900); }

/* ---- Main content area -------------------------------------------------*/
main {
  flex: 1;
  min-height: 60vh;
  padding: var(--space-4);
  padding-bottom: calc(var(--space-7) + env(safe-area-inset-bottom, 0px));
}

.offline-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.74rem;
  color: var(--green-700);
  background: var(--green-100);
  border: 1px solid var(--line);
  padding: 3px 8px;
  border-radius: 999px;
  margin-bottom: var(--space-4);
}
.offline-badge::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: #3f8a5c; flex: none; }

/* ---- Ledger list: the recurring structural motif ---------------------- */
.ledger-list { list-style: none; margin: 0; padding: 0; border-top: 1px solid var(--line); }
.ledger-row {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-4) var(--space-1);
  border-bottom: 1px solid var(--line);
  text-decoration: none;
  color: inherit;
  background: none;
  border-left: none;
  border-right: none;
  border-top: none;
  width: 100%;
  text-align: left;
  cursor: pointer;
}
.ledger-row:hover, .ledger-row:active { background: var(--green-100); }
.ledger-index {
  font-family: var(--font-display);
  font-weight: 700;
  color: var(--gold-600);
  font-size: 1rem;
  width: 1.6em;
  flex: none;
  text-align: center;
}
.ledger-body { flex: 1; min-width: 0; }
.ledger-title { font-weight: 700; margin: 0; font-size: 1rem; }
.ledger-meta { color: var(--ink-soft); font-size: 0.85rem; margin: 2px 0 0; }
.ledger-check {
  flex: none;
  width: 26px; height: 26px;
  border-radius: 50%;
  border: 2px solid var(--line);
  display: flex; align-items: center; justify-content: center;
  color: var(--white);
  font-size: 0.85rem;
}
.ledger-check.done { background: var(--green-700); border-color: var(--green-700); color: var(--cream-50); }

/* ---- Cards for tools / summary numbers --------------------------------- */
.stamp-card {
  background: var(--cream-50);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  padding: var(--space-4);
  margin-bottom: var(--space-4);
}
.stamp-card + .stamp-card { margin-top: 0; }

.figure-row { display: flex; justify-content: space-between; align-items: baseline; padding: var(--space-2) 0; border-bottom: 1px dashed var(--line); gap: var(--space-3); }
.figure-row:last-child { border-bottom: none; }
.figure-label { color: var(--ink-soft); font-size: 0.92rem; }
.figure-value { font-weight: 700; font-size: 1.05rem; white-space: nowrap; }
.figure-value.positive { color: var(--green-700); }
.figure-value.negative { color: var(--stamp-red); }

/* ---- Buttons ------------------------------------------------------------*/
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: 48px;
  padding: 0 var(--space-4);
  border-radius: var(--radius-sm);
  border: 2px solid var(--green-800);
  background: var(--green-800);
  color: var(--cream-50);
  font-weight: 700;
  font-size: 1rem;
  cursor: pointer;
  width: 100%;
  text-decoration: none;
}
.btn:hover { background: var(--green-700); border-color: var(--green-700); }
.btn.btn-secondary { background: transparent; color: var(--green-800); }
.btn.btn-secondary:hover { background: var(--green-100); }
.btn.btn-gold { background: var(--gold-500); border-color: var(--gold-500); color: var(--green-900); }
.btn.btn-gold:hover { background: var(--gold-300); border-color: var(--gold-300); }
.btn[disabled] { opacity: 0.5; cursor: not-allowed; }
.btn-row { display: flex; gap: var(--space-3); margin-top: var(--space-4); }
.btn-row .btn { width: auto; flex: 1; }

/* ---- Forms ---------------------------------------------------------------*/
.field { margin-bottom: var(--space-4); }
.field label { display: block; font-weight: 600; font-size: 0.9rem; margin-bottom: var(--space-1); }
.field input, .field select {
  width: 100%;
  min-height: 48px;
  padding: var(--space-2) var(--space-3);
  border: 1.5px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--cream-50);
  color: var(--ink);
}
.field input:focus, .field select:focus { border-color: var(--gold-500); }
.field-hint { font-size: 0.8rem; color: var(--ink-soft); margin-top: 4px; }
.field-error { font-size: 0.8rem; color: var(--stamp-red); margin-top: 4px; }

.field-group {
  border: 1.5px solid var(--line);
  border-radius: var(--radius-sm);
  padding: var(--space-3);
  margin-bottom: var(--space-4);
  background: var(--cream-50);
}
.field-group summary { font-weight: 700; cursor: pointer; }
.field-group[open] summary { margin-bottom: var(--space-2); }

.category-row { display: flex; gap: var(--space-2); align-items: center; margin-bottom: var(--space-2); }
.category-row input[type="text"] { flex: 1.3; }
.category-row input[type="number"] { flex: 1; }
.category-row .icon-btn { flex: none; }

.icon-btn {
  min-width: 40px; min-height: 40px;
  border: 1.5px solid var(--line);
  background: var(--cream-50);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 1.1rem;
  color: var(--ink-soft);
}

/* ---- Lesson reading view ---------------------------------------------- */
.lesson-intro { font-size: 1.02rem; color: var(--ink-soft); }
.points-list { list-style: none; margin: 0; padding: 0; }
.points-list li {
  position: relative;
  padding: var(--space-3) 0 var(--space-3) var(--space-5);
  border-bottom: 1px solid var(--line);
}
.points-list li::before {
  content: "—";
  position: absolute;
  left: 0;
  color: var(--gold-600);
  font-weight: 700;
}
.points-list li:last-child { border-bottom: none; }

/* ---- Quiz ---------------------------------------------------------------*/
.quiz-progress { font-size: 0.85rem; color: var(--ink-soft); margin-bottom: var(--space-2); }
.quiz-question { font-size: 1.1rem; font-weight: 700; margin-bottom: var(--space-4); }
.quiz-choices { list-style: none; margin: 0 0 var(--space-4); padding: 0; }
.quiz-choice {
  display: block;
  width: 100%;
  text-align: left;
  padding: var(--space-3);
  margin-bottom: var(--space-2);
  border: 1.5px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--cream-50);
  cursor: pointer;
  font-size: 0.98rem;
}
.quiz-choice:hover { border-color: var(--gold-500); }
.quiz-choice[aria-pressed="true"] { border-color: var(--gold-500); background: var(--green-100); }
.quiz-choice.correct { border-color: var(--green-700); background: var(--green-100); }
.quiz-choice.incorrect { border-color: var(--stamp-red); background: #fbeae7; }
:root[data-theme="dark"] .quiz-choice.incorrect { background: #3a1d17; }
.quiz-feedback { padding: var(--space-3); border-radius: var(--radius-sm); background: var(--green-100); margin-bottom: var(--space-4); font-size: 0.95rem; }
.quiz-feedback.incorrect { background: #fbeae7; }
:root[data-theme="dark"] .quiz-feedback.incorrect { background: #3a1d17; }

/* ---- Badges --------------------------------------------------------------*/
.badge-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); gap: var(--space-3); }
.badge {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  text-align: center; font-size: 0.72rem; color: var(--ink-soft);
}
.badge-seal {
  width: 56px; height: 56px; border-radius: 50%;
  border: 2px solid var(--line);
  display: flex; align-items: center; justify-content: center;
  font-size: 1.4rem;
  background: var(--cream-50);
}
.badge.earned .badge-seal { border-color: var(--gold-500); background: var(--gold-300); }
.badge.earned { color: var(--ink); font-weight: 600; }

/* ---- Bottom nav (ledger tab strip) ------------------------------------ */
.tab-bar {
  position: sticky;
  bottom: 0;
  display: flex;
  background: var(--green-800);
  border-top: 3px solid var(--gold-500);
  max-width: var(--max-width);
  margin: 0 auto;
  width: 100%;
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
.tab-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: var(--space-2) 0;
  background: none;
  border: none;
  color: var(--gold-300);
  font-size: 0.68rem;
  font-weight: 600;
  text-decoration: none;
  min-height: 56px;
  justify-content: center;
}
.tab-item .tab-icon { font-size: 1.25rem; line-height: 1; }
.tab-item[aria-current="page"] { color: var(--cream-50); }
.tab-item[aria-current="page"] .tab-icon { color: var(--gold-500); }

/* ---- Misc ---------------------------------------------------------------*/
.section-title { display: flex; align-items: baseline; justify-content: space-between; margin: var(--space-6) 0 var(--space-2); }
.section-title:first-child { margin-top: 0; }
.muted { color: var(--ink-soft); }
.center { text-align: center; }
.stack { display: flex; flex-direction: column; gap: var(--space-3); }
hr.rule { border: none; border-top: 1px solid var(--line); margin: var(--space-5) 0; }

.install-banner {
  display: flex; align-items: center; gap: var(--space-3);
  background: var(--green-100); border: 1px solid var(--line);
  border-radius: var(--radius-md); padding: var(--space-3);
  margin-bottom: var(--space-4);
}
.install-banner p { margin: 0; font-size: 0.85rem; flex: 1; }
.install-banner button { flex: none; }

.progress-track { height: 8px; background: var(--line); border-radius: 999px; overflow: hidden; margin: var(--space-2) 0 var(--space-4); }
.progress-fill { height: 100%; background: var(--gold-500); }

.scale-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: var(--space-2); margin-bottom: var(--space-5); }
.scale-btn {
  min-height: 56px;
  border: 1.5px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--cream-50);
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
}
.scale-btn[aria-pressed="true"] { border-color: var(--gold-500); background: var(--green-100); }

.result-hero {
  text-align: center;
  padding: var(--space-6) var(--space-4);
  background: var(--green-800);
  color: var(--cream-50);
  border-radius: var(--radius-md);
  margin-bottom: var(--space-4);
}
.result-hero .big-seal {
  width: 88px; height: 88px; border-radius: 50%;
  border: 3px solid var(--gold-500);
  display: flex; align-items: center; justify-content: center;
  font-size: 2.2rem; margin: 0 auto var(--space-3);
  background: var(--green-700);
}
.result-hero h2 { color: var(--cream-50); }

a.skip-link {
  position: absolute; left: -9999px; top: 0;
  background: var(--gold-500); color: var(--green-900);
  padding: var(--space-2) var(--space-3); z-index: 100;
}
a.skip-link:focus { left: var(--space-3); top: var(--space-3); }

.empty-state { text-align: center; padding: var(--space-6) var(--space-4); color: var(--ink-soft); }

@media (min-width: 481px) {
  .app-shell { box-shadow: 0 0 0 1px var(--line); min-height: 100vh; }
  body { background: var(--green-900); }
}

/* ---- Money Plan "prescription" report ----------------------------------- */
.rx-card {
  background: var(--cream-50);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  padding: var(--space-4);
}
.rx-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: var(--space-3);
  border-bottom: 2px dashed var(--green-800);
  padding-bottom: var(--space-3);
  margin-bottom: var(--space-3);
}
.rx-bank { margin: 0; font-size: 0.8rem; letter-spacing: 0.03em; text-transform: uppercase; color: var(--ink-soft); }
.rx-date { margin: 0; font-size: 0.85rem; color: var(--ink-soft); white-space: nowrap; }
.rx-status-row { margin-bottom: var(--space-3); }

/* Print / "Save as PDF": show only the report itself, in plain black on
   white — the app shell (masthead, tab bar, buttons) is chrome that has
   no place on a printed page someone hands to another person. */
@media print {
  .masthead, .tab-bar, .no-print, .install-banner, .offline-badge { display: none !important; }
  body, .app-shell { background: #fff !important; }
  .rx-card { border: none; padding: 0; }
  a[href]::after { content: none !important; }
}
