/* ============================================================
   SimMaven — "The Maven's Ledger" design system v2
   Ink on paper, tabular numbers, receipts with sources.
   Zero dependencies. Light + dark. Motion with restraint.
   ============================================================ */

:root {
  color-scheme: light dark;

  /* palette — light (warm paper) */
  --paper: #faf8f4;
  --paper-deep: #f3efe8;
  --card: #fffdf9;
  --ink: #201d1a;
  --ink-soft: #44403c;
  --muted: #6b655e;
  --faint: #a8a29e;
  --line: #e5e0d8;
  --line-strong: #d6d0c6;
  --accent: #0c6b5c;
  --accent-dark: #085246;
  --accent-soft: #e4f1ee;
  --gold: #a16207;
  --gold-soft: #fdf6e3;
  --gold-line: #d9a441;
  --red: #b42318;
  --green-soft: #eefbf2;
  --green-line: #a7e3bb;
  --blue-soft: #eff6ff;
  --blue-line: #93c5fd;

  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(32, 29, 26, .05), 0 2px 10px rgba(32, 29, 26, .05);
  --shadow-lift: 0 2px 4px rgba(32, 29, 26, .07), 0 10px 28px rgba(32, 29, 26, .09);

  /* type */
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, Consolas, monospace;

  /* rhythm */
  --space-section: clamp(2.4rem, 5vw, 3.6rem);
}

[data-theme="dark"] {
  color-scheme: dark;
  --paper: #16130f;
  --paper-deep: #1c1915;
  --card: #211d18;
  --ink: #ece6dc;
  --ink-soft: #d6cfc4;
  --muted: #a39b90;
  --faint: #7a736a;
  --line: #35302a;
  --line-strong: #45403a;
  --accent: #4cd7bd;
  --accent-dark: #7ae3cf;
  --accent-soft: #12332d;
  --gold: #e0a52e;
  --gold-soft: #2a2214;
  --gold-line: #8a6a20;
  --red: #f07f72;
  --green-soft: #122419;
  --green-line: #1f5c38;
  --blue-soft: #101c2c;
  --blue-line: #2b4a6f;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 2px 10px rgba(0, 0, 0, .3);
  --shadow-lift: 0 2px 6px rgba(0, 0, 0, .45), 0 12px 32px rgba(0, 0, 0, .4);
}

/* ---------- base ---------- */

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

body {
  margin: 0;
  font-family: var(--sans);
  font-size: 1.03rem;
  line-height: 1.7;
  color: var(--ink);
  background: var(--paper);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

::selection { background: var(--accent); color: #fff; }

.wrap { max-width: 64rem; margin: 0 auto; padding: 0 clamp(1.1rem, 3.5vw, 1.6rem); }
.narrow { max-width: 47rem; }

a { color: var(--accent); text-decoration-thickness: 1px; text-underline-offset: 3px; transition: color .15s ease; }
a:hover { color: var(--accent-dark); }

:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; border-radius: 4px; }

.skip {
  position: absolute; left: -9999px; top: 0;
  background: var(--ink); color: var(--paper);
  padding: 0.6rem 1rem; z-index: 100; border-radius: 0 0 8px 0;
}
.skip:focus { left: 0.5rem; top: 0.5rem; }

/* ---------- header ---------- */

.site-header {
  background: color-mix(in srgb, var(--paper) 88%, transparent);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 50;
}
.site-header .wrap {
  display: flex; flex-wrap: wrap; align-items: center;
  gap: 0.5rem 1.4rem;
  padding-top: 0.85rem; padding-bottom: 0.85rem;
}

.brand {
  font-family: var(--serif);
  font-size: 1.3rem; font-weight: 700;
  letter-spacing: 0.005em;
  color: var(--ink); text-decoration: none;
  display: inline-flex; align-items: center; gap: 0.45rem;
}
.brand:hover { color: var(--accent-dark); }
.brand .amp { color: var(--accent); }

.site-nav { display: flex; flex-wrap: wrap; gap: 0.2rem 0.9rem; margin-left: auto; align-items: center; }
.site-nav a {
  color: var(--muted); text-decoration: none; font-size: 0.92rem; font-weight: 500;
  padding: 0.25rem 0.1rem; position: relative;
}
.site-nav a::after {
  content: ""; position: absolute; left: 0; right: 100%; bottom: 0;
  height: 2px; background: var(--accent); transition: right .22s ease;
}
.site-nav a:hover { color: var(--ink); }
.site-nav a:hover::after { right: 0; }

.theme-toggle {
  width: 34px; height: 34px; flex-shrink: 0;
  display: inline-grid; place-items: center;
  border: 1px solid var(--line-strong); border-radius: 999px;
  background: transparent; color: var(--muted); cursor: pointer;
  transition: color .15s, border-color .15s, transform .12s;
}
.theme-toggle:hover { color: var(--accent-dark); border-color: var(--accent); }
.theme-toggle:active { transform: scale(0.92); }
.theme-toggle svg { width: 17px; height: 17px; }
[data-theme="dark"] .icon-sun { display: block; }
[data-theme="dark"] .icon-moon { display: none; }
.icon-sun { display: none; }
.icon-moon { display: block; }

/* ---------- page rhythm & type ---------- */

main { padding-bottom: clamp(3rem, 7vw, 4.5rem); animation: page-in .45s ease both; }
@keyframes page-in { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

h1, h2, h3 { font-family: var(--serif); font-weight: 700; line-height: 1.18; letter-spacing: -0.01em; }
h1 {
  font-size: clamp(1.85rem, 4.2vw, 2.7rem);
  margin: clamp(1.6rem, 4vw, 2.4rem) 0 0.65rem;
  text-wrap: balance;
}
h2 {
  font-size: clamp(1.28rem, 2.4vw, 1.5rem);
  margin: var(--space-section) 0 0.55rem;
  padding-top: 0.9rem;
  border-top: 1px solid var(--line);
}
h2:first-of-type { border-top: none; padding-top: 0; margin-top: 1.6rem; }
h3 { font-size: 1.12rem; margin: 1.3rem 0 0.4rem; }

p { margin: 0.65rem 0; }
.lede { font-size: clamp(1.08rem, 2vw, 1.2rem); color: var(--muted); margin: 0.4rem 0 1.4rem; text-wrap: pretty; }
.small { font-size: 0.9rem; }
.muted { color: var(--muted); }

ul.tight li, ol.tight li { margin: 0.35rem 0; }
ul, ol { padding-left: 1.3rem; }
li::marker { color: var(--accent); }

/* ---------- breadcrumb ---------- */

.breadcrumb { margin-top: 1.1rem; font-size: 0.85rem; color: var(--faint); }
.breadcrumb ol { list-style: none; display: flex; flex-wrap: wrap; gap: 0.35rem; margin: 0; padding: 0; }
.breadcrumb li:not(:last-child)::after { content: "›"; margin-left: 0.35rem; }
.breadcrumb a { color: var(--muted); text-decoration: none; }
.breadcrumb a:hover { color: var(--accent-dark); text-decoration: underline; }

/* ---------- pills / banners ---------- */

.pill {
  display: inline-block; font-size: 0.76rem; font-weight: 700;
  letter-spacing: 0.04em; padding: 0.18rem 0.68rem; border-radius: 999px;
  vertical-align: 3px; font-family: var(--sans);
}
.pill-live { background: var(--green-soft); color: #166534; border: 1px solid var(--green-line); }
[data-theme="dark"] .pill-live { color: #7ee2a8; }
.pill-src { background: var(--blue-soft); color: #1d4ed8; border: 1px solid var(--blue-line); }
[data-theme="dark"] .pill-src { color: #93c5fd; }
.pill-draft { background: var(--gold-soft); color: var(--gold); border: 1px dashed var(--gold-line); }

.draft-banner {
  background: var(--gold-soft); border: 1px solid var(--gold-line);
  border-radius: var(--radius); padding: 0.9rem 1.15rem; margin: 1.2rem 0; font-size: 0.95rem;
}
.draft-banner strong { color: var(--gold); }

.fact-slot {
  border: 2px dashed var(--gold-line); background: var(--gold-soft);
  border-radius: var(--radius); padding: 0.9rem 1.2rem; margin: 1rem 0; font-size: 0.95rem;
}
.fact-slot h4 {
  margin: 0 0 0.35rem; font-family: var(--sans); font-size: 0.85rem;
  text-transform: uppercase; letter-spacing: 0.06em; color: var(--gold);
}
.fact-slot p { margin: 0.35rem 0; }
.fact-slot .ledger-ref { font-family: var(--mono); font-size: 0.82rem; color: var(--muted); }

/* ---------- cards & grids ---------- */

.card {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: clamp(1.15rem, 2.6vw, 1.5rem) clamp(1.25rem, 3vw, 1.6rem);
  margin: 1rem 0;
  transition: transform .18s ease, box-shadow .18s ease, border-color .18s ease;
}
a.card:hover, .grid .card:hover { transform: translateY(-2px); box-shadow: var(--shadow-lift); border-color: var(--line-strong); }

.grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(14.5rem, 1fr));
  gap: clamp(0.8rem, 2vw, 1.1rem); margin: 1.3rem 0;
}
.grid .card { margin: 0; display: flex; flex-direction: column; }
.grid .card h3 { margin: 0.2rem 0 0.45rem; }
.grid .card p { font-size: 0.94rem; color: var(--muted); flex-grow: 1; }
.grid .card .btn, .grid .card .result-actions { margin-top: auto; }
.card-kicker {
  font-family: var(--mono); font-size: 0.72rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.14em;
  color: var(--accent); margin: 0 0 0.4rem;
}

/* ---------- buttons ---------- */

.btn {
  display: inline-block; padding: 0.55rem 1.05rem;
  border-radius: 9px; border: 1px solid var(--line-strong);
  background: var(--card); color: var(--ink);
  font-size: 0.94rem; font-weight: 600; text-decoration: none;
  cursor: pointer; font-family: var(--sans);
  transition: transform .12s ease, background .15s, border-color .15s, box-shadow .15s;
}
.btn:hover { border-color: var(--faint); background: var(--paper-deep); }
.btn:active { transform: scale(0.975); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; box-shadow: var(--shadow); }
.btn-primary:hover { background: var(--accent-dark); border-color: var(--accent-dark); color: #fff; box-shadow: var(--shadow-lift); }
[data-theme="dark"] .btn-primary { color: #06231e; }
.btn-small { padding: 0.35rem 0.75rem; font-size: 0.85rem; }

/* ---------- tables ---------- */

.data-table {
  width: 100%; border-collapse: collapse; font-size: 0.95rem; margin: 1rem 0;
}
.data-table th, .data-table td {
  text-align: left; padding: 0.6rem 0.7rem; border-bottom: 1px solid var(--line); vertical-align: top;
}
.data-table th {
  border-bottom: 2px solid var(--ink);
  font-family: var(--sans); font-size: 0.8rem;
  text-transform: uppercase; letter-spacing: 0.06em;
}
.data-table td.num, .data-table th.num { text-align: right; font-variant-numeric: tabular-nums; font-family: var(--mono); font-size: 0.92em; }
.data-table tbody tr { transition: background .12s; }
.data-table tbody tr:hover { background: var(--paper-deep); }
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }

/* ---------- formula blocks ---------- */

.formula {
  background: var(--paper-deep); border: 1px solid var(--line);
  border-radius: var(--radius-sm); padding: 0.75rem 1.05rem;
  font-family: var(--mono); font-size: 0.9rem;
  overflow-x: auto; margin: 0.9rem 0; line-height: 1.75;
}

/* ---------- calculator ---------- */

.calc-grid { display: grid; grid-template-columns: 1fr; gap: 1.25rem; margin: 1.2rem 0; }
@media (min-width: 56rem) { .calc-grid { grid-template-columns: 1fr 1fr; align-items: start; } }

.calc-field { margin: 0.9rem 0; }
.calc-field label, .calc-field .field-label {
  display: block; font-weight: 600; font-size: 0.9rem; margin-bottom: 0.32rem;
}
.calc-field .hint { font-weight: 400; color: var(--muted); font-size: 0.84rem; }

.calc-field input[type="text"], .calc-field select {
  width: 100%; padding: 0.6rem 0.75rem; font-size: 1rem;
  font-family: var(--sans); color: var(--ink); background: var(--card);
  border: 1px solid var(--line-strong); border-radius: var(--radius-sm);
  transition: border-color .15s, box-shadow .15s;
}
.calc-field input[type="text"]:focus, .calc-field select:focus {
  border-color: var(--accent); outline: none;
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.calc-field input[disabled] { background: var(--paper-deep); color: var(--faint); }

fieldset.chips { border: none; padding: 0; margin: 0.9rem 0; }
fieldset.chips legend { font-weight: 600; font-size: 0.92rem; padding: 0; margin-bottom: 0.3rem; }
.chip-row { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.chip { position: relative; display: inline-block; }
.chip input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.chip span {
  display: inline-block; padding: 0.4rem 0.85rem; border: 1px solid var(--line-strong);
  border-radius: 999px; font-size: 0.9rem; font-weight: 600; background: var(--card); color: var(--muted);
}
.chip input:checked + span { background: var(--accent); border-color: var(--accent); color: #fff; }
.chip input:focus-visible + span { outline: 3px solid var(--gold); outline-offset: 2px; }

/* receipt-style result (ledger motif) */
.receipt {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 1.05rem 1.25rem; margin-top: 1rem;
}
.receipt-title {
  font-family: var(--mono); font-size: 0.72rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.16em; color: var(--faint);
  text-align: center; margin: 0 0 0.65rem;
}
.receipt { width: 100%; font-size: 0.94rem; }
.receipt th, .receipt td { padding: 0.55rem 0.45rem; text-align: left; }
.receipt th {
  font-family: var(--sans); font-size: 0.74rem; text-transform: uppercase;
  letter-spacing: 0.08em; color: var(--muted); border-bottom: 2px solid var(--ink);
}
.receipt td { border-bottom: 1px dashed var(--line-strong); font-variant-numeric: tabular-nums; }
.receipt td.num, .receipt th.num { text-align: right; font-family: var(--mono); font-size: 0.93em; }
.receipt tbody tr { animation: row-in .3s ease both; }
.receipt tbody tr:nth-child(2) { animation-delay: .04s; }
.receipt tbody tr:nth-child(3) { animation-delay: .08s; }
.receipt tbody tr:nth-child(4) { animation-delay: .12s; }
.receipt tbody tr:hover { background: var(--paper-deep); }
.receipt .price-strong { font-weight: 700; font-size: 1.02em; }
@keyframes row-in { from { opacity: 0; transform: translateX(-6px); } to { opacity: 1; transform: none; } }

.result-panel {
  background: var(--green-soft); border: 1px solid var(--green-line);
  border-radius: var(--radius); padding: 1.1rem 1.3rem; margin-top: 1rem;
}
.result-panel .price-big { font-size: 2.1rem; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.2; }
.result-row {
  display: flex; justify-content: space-between; gap: 1rem;
  padding: 0.45rem 0; border-top: 1px dashed var(--line-strong); font-size: 0.95rem;
}
.result-row:first-of-type { border-top: none; }
.result-row .val { font-variant-numeric: tabular-nums; font-weight: 600; font-family: var(--mono); }
.result-row .val.neg, td.num.neg { color: var(--red); }
.result-actions { margin-top: 0.75rem; display: flex; gap: 0.6rem; flex-wrap: wrap; }

.result-error { color: var(--red); font-size: 0.95rem; margin-top: 0.8rem; }
.result-hint { color: var(--muted); font-size: 0.95rem; margin-top: 0.8rem; }
.result-note { color: var(--gold); font-size: 0.88rem; margin-top: 0.55rem; }

.calc-limits { font-size: 0.92rem; color: var(--muted); }
.calc-limits li { margin: 0.3rem 0; }

/* ---------- quick answer ---------- */

.quick-answer {
  background: var(--accent-soft); border: 1px solid var(--accent);
  border-radius: var(--radius); padding: 0.95rem 1.25rem; margin: 1.2rem 0;
}
.quick-answer .qa-title {
  font-family: var(--mono); font-size: 0.74rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.14em;
  color: var(--accent-dark); margin: 0 0 0.3rem;
}
.quick-answer p { margin: 0.25rem 0; }
.quick-answer a { color: var(--accent-dark); }

/* ---------- footer ---------- */

.site-footer {
  border-top: 1px solid var(--line);
  margin-top: clamp(2.5rem, 6vw, 4rem);
  padding: 1.7rem 0 2.4rem; font-size: 0.9rem; color: var(--muted);
  background: var(--paper-deep);
}
.site-footer nav { display: flex; flex-wrap: wrap; gap: 1rem; margin: 0.4rem 0; }
.site-footer a { color: var(--muted); }
.site-footer a:hover { color: var(--accent-dark); }
.site-footer .disclaimer { max-width: 46rem; }

/* ---------- responsive ---------- */

@media (max-width: 40rem) {
  h1 { font-size: clamp(1.7rem, 7.5vw, 2rem); }
  .site-header .wrap { gap: 0.4rem 1rem; }
  .site-nav { margin-left: 0; }
  .data-table { display: block; overflow-x: auto; -webkit-overflow-scrolling: touch; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
  html { scroll-behavior: auto; }
}

/* ---------- cross-document view transitions (progressive) ---------- */

@view-transition { navigation: auto; }
@media (prefers-reduced-motion: no-preference) {
  ::view-transition-old(root) { animation: vt-out .18s ease both; }
  ::view-transition-new(root) { animation: page-in .3s ease both; }
  @keyframes vt-out { to { opacity: 0; } }
}

@media (max-width: 48rem) {
  .receipt { padding: 0.85rem 0.95rem; }
  .receipt-title { text-align: left; }
}
