/* DESIGN.md tokens. Light default. Hex first. */
@font-face {
  font-family: "EB Garamond";
  src: url("../fonts/eb-garamond-400.woff2") format("woff2");
  font-style: normal;
  font-weight: 400;
  font-display: swap;
}
@font-face {
  font-family: "EB Garamond";
  src: url("../fonts/eb-garamond-400i.woff2") format("woff2");
  font-style: italic;
  font-weight: 400;
  font-display: swap;
}
@font-face {
  font-family: "Source Sans 3";
  src: url("../fonts/source-sans-3-400.woff2") format("woff2");
  font-style: normal;
  font-weight: 400;
  font-display: swap;
}
@font-face {
  font-family: "Source Sans 3";
  src: url("../fonts/source-sans-3-600.woff2") format("woff2");
  font-style: normal;
  font-weight: 600;
  font-display: swap;
}

:root {
  color-scheme: light;
  --bg: #F3EFE6;
  --bg-elev: #FAF7F0;
  --ink: #1A1814;
  --ink-soft: #4F4B42;
  --line: #8A8274;
  --line-soft: #C9C2B3;
  --gold: #6B5420;
  --gold-bright: #A68428;
  --on-gold: #FAF7F0;
  --ok: #2C5A3A;
  --fire: #8B3A2A;
  --earth: #5C5A38;
  --air: #5A6B7A;
  --water: #3E5A5E;
  --focus: #1A1814;
  --shadow: none;
  --font-display: "EB Garamond", "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --font-ui: "Source Sans 3", "Source Sans Pro", "Helvetica Neue", system-ui, sans-serif;
  --fs-body: 16px;
  --lh-body: 24px;
  --fs-dek: 20px;
  --lh-dek: 28px;
  --fs-title: 25px;
  --lh-title: 32px;
  --fs-display: 31.25px;
  --lh-display: 36px;
  --fs-kicker: 16px;
  --lh-kicker: 20px;
  --s-2: 2px; --s-4: 4px; --s-8: 8px; --s-12: 12px; --s-16: 16px;
  --s-24: 24px; --s-32: 32px; --s-40: 40px; --s-48: 48px; --s-64: 64px;
  --radius: 4px;
  --radius-sm: 2px;
  --header-h: 48px;
  --footer-h: 64px;
  --dur-micro: 120ms;
  --dur-ui: 200ms;
  --dur-page: 280ms;
  --dur-draw: 480ms;
  --dur-wheel: 480ms;
  --ease-out: cubic-bezier(0.2, 0.8, 0.2, 1);
  --ease-in: cubic-bezier(0.4, 0, 1, 1);
  --ease-standard: cubic-bezier(0.2, 0.7, 0.2, 1);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #161410;
    --bg-elev: #1E1B16;
    --ink: #EDE8DC;
    --ink-soft: #B4AFA3;
    --line: #6A6358;
    --line-soft: #3A362E;
    --gold: #D4B36A;
    --gold-bright: #D4B36A;
    --on-gold: #161410;
    --ok: #8FB89E;
    --fire: #D4897C;
    --earth: #A8A070;
    --air: #8A9AAB;
    --water: #8AA8AC;
    --focus: #EDE8DC;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #161410;
  --bg-elev: #1E1B16;
  --ink: #EDE8DC;
  --ink-soft: #B4AFA3;
  --line: #6A6358;
  --line-soft: #3A362E;
  --gold: #D4B36A;
  --gold-bright: #D4B36A;
  --on-gold: #161410;
  --ok: #8FB89E;
  --fire: #D4897C;
  --earth: #A8A070;
  --air: #8A9AAB;
  --water: #8AA8AC;
  --focus: #EDE8DC;
}

@supports (color: oklch(0.5 0.1 80)) {
  :root:not([data-theme="dark"]) {
    --bg: oklch(0.95 0.012 92);
    --ink: oklch(0.21 0.01 80);
    --gold: oklch(0.45 0.08 85);
  }
}
@media (prefers-color-scheme: dark) {
  @supports (color: oklch(0.5 0.1 80)) {
    :root:not([data-theme="light"]) {
      --bg: #161410;
      --ink: #EDE8DC;
      --gold: #D4B36A;
    }
  }
}

@media (prefers-reduced-motion: reduce) {
  :root {
    --dur-micro: 0ms;
    --dur-ui: 0ms;
    --dur-page: 100ms;
    --dur-draw: 0ms;
    --dur-wheel: 0ms;
  }
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  height: 100dvh;
  max-height: 100dvh;
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: var(--fs-body);
  line-height: var(--lh-body);
  font-weight: 400;
}
button, input, select {
  font-family: var(--font-ui);
  font-size: var(--fs-body);
}

.app {
  height: 100%;
  height: 100dvh;
  max-height: 100dvh;
  overflow: hidden;
  display: grid;
  grid-template-rows: var(--header-h) 1fr var(--footer-h);
  grid-template-columns: 1fr;
}

.rail { display: none; }

.top {
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-rows: auto auto;
  align-items: center;
  padding: 0 var(--s-24);
  border-bottom: 1px solid var(--line-soft);
  min-height: var(--header-h);
}
.brand {
  font-family: var(--font-display);
  font-size: 16px;
  line-height: 20px;
  color: var(--ink);
  letter-spacing: 0.02em;
}
.progress {
  font-variant-numeric: tabular-nums;
  color: var(--ink-soft);
  font-size: 16px;
  line-height: 20px;
  justify-self: end;
}
.ticks {
  grid-column: 1 / -1;
  display: flex;
  justify-content: center;
  gap: 2px;
  padding-bottom: 4px;
}
.tick {
  appearance: none;
  width: 24px;
  height: 24px;
  padding: 8px;
  border: 0;
  background: transparent;
  cursor: pointer;
  display: grid;
  place-items: center;
}
.tick i {
  width: 8px;
  height: 8px;
  background: var(--line);
  display: block;
  border-radius: var(--radius-sm);
  font-style: normal;
}
.tick.is-current i { background: var(--ink); }
.tick.is-done i { background: var(--gold); }
.tick:focus-visible, .btn:focus-visible, .chip:focus-visible, .cell:focus-visible,
input:focus-visible, select:focus-visible, .theme-btn:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.deck {
  overflow: hidden;
  min-height: 0;
  position: relative;
}
.page {
  position: absolute;
  inset: 0;
  overflow: hidden;
  display: none;
  padding: var(--s-24);
  flex-direction: column;
}
.page.is-on { display: flex; }

.foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--s-24);
  border-top: 1px solid var(--line-soft);
  min-height: var(--footer-h);
}

.btn {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--ink);
  min-height: 44px;
  min-width: 44px;
  padding: 0 16px;
  border-radius: var(--radius);
  cursor: pointer;
  line-height: 20px;
  transition: background-color var(--dur-micro) var(--ease-standard), color var(--dur-micro) var(--ease-standard);
}
.btn[aria-disabled="true"] { opacity: 0.4; cursor: default; pointer-events: none; }
.btn-quiet { background: transparent; color: var(--ink); }
.btn-primary {
  background: var(--gold);
  color: var(--on-gold);
}
.btn-primary:hover { filter: brightness(1.05); }
.btn-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--s-12);
  margin-top: auto;
}

.kicker {
  margin: 0 0 var(--s-8);
  font-size: var(--fs-kicker);
  line-height: var(--lh-kicker);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--gold);
  font-weight: 400;
  font-family: var(--font-ui);
}
h1, h2 {
  margin: 0 0 var(--s-12);
  font-family: var(--font-display);
  font-weight: 400;
  color: var(--ink);
}
h1 { font-size: var(--fs-display); line-height: var(--lh-display); }
h2 { font-size: var(--fs-title); line-height: var(--lh-title); }
.dek { font-size: var(--fs-dek); line-height: var(--lh-dek); margin: 0 0 var(--s-16); color: var(--ink); }
p { margin: 0 0 var(--s-12); }
.soft { color: var(--ink-soft); }
.note-sm { font-size: var(--fs-body); color: var(--ink-soft); margin: 0 0 var(--s-8); }

.epigraph {
  margin: 0 0 var(--s-24);
  padding: 0;
  border: 0;
  max-width: 40ch;
  font-family: var(--font-display);
  font-style: italic;
  font-size: var(--fs-dek);
  line-height: var(--lh-dek);
  color: var(--ink-soft);
}
.epigraph cite {
  display: block;
  margin-top: var(--s-8);
  font-style: normal;
  font-size: var(--fs-body);
  line-height: var(--lh-body);
  font-family: var(--font-ui);
  color: var(--ink-soft);
}

.honesty {
  border: 1px solid var(--line);
  border-radius: 0;
  padding: 12px 16px;
  margin: 0 0 var(--s-16);
  background: var(--bg-elev);
}
.honesty .kicker { margin-bottom: var(--s-4); }
.honesty p { margin: 0 0 var(--s-4); color: var(--ink-soft); }
.honesty a { color: var(--ink); text-decoration: underline; }

.intro { max-width: 40ch; }
.intro .btn-primary { align-self: center; margin-top: var(--s-16); min-width: 8rem; }

.method-body { display: flex; flex-direction: column; min-height: 0; flex: 1; overflow: hidden; }
.emblem {
  width: 96px;
  height: 96px;
  margin: var(--s-8) auto 0;
  color: var(--ink);
}
.emblem svg { width: 100%; height: 100%; display: block; }

.blocks { display: flex; flex-direction: column; gap: var(--s-16); }
.block h3 {
  margin: 0 0 var(--s-4);
  font-family: var(--font-ui);
  font-size: var(--fs-kicker);
  line-height: var(--lh-kicker);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--gold);
  font-weight: 400;
}
.block p { margin: 0; }

/* widgets */
.field {
  display: flex;
  flex-direction: column;
  gap: var(--s-4);
  margin: 0 0 var(--s-12);
}
.field label { font-size: var(--fs-body); color: var(--ink); }
.field input, .field select {
  height: 44px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg-elev);
  color: var(--ink);
  padding: 0 12px;
}
.hint { font-size: var(--fs-body); color: var(--ink-soft); min-height: 24px; }
.stage-label {
  font-size: var(--fs-kicker);
  line-height: var(--lh-kicker);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--gold);
  margin: 0 0 var(--s-8);
}

.grid-letters {
  display: grid;
  grid-template-columns: repeat(7, 44px);
  gap: var(--s-4);
  justify-content: center;
  margin: 0 0 var(--s-12);
}
.cell {
  appearance: none;
  width: 44px;
  height: 44px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--bg-elev);
  color: var(--ink);
  cursor: pointer;
  padding: 0;
}
.cell.is-on { outline: 2px solid var(--ink); outline-offset: 0; background: var(--bg-elev); }
.cell.is-built { border-color: var(--gold); color: var(--gold); }

.sigil-stage {
  width: 160px;
  height: 160px;
  margin: 0 auto var(--s-12);
  border: 1px solid var(--line);
  background: var(--bg-elev);
  position: relative;
  display: grid;
  place-items: center;
}
.sigil-stage svg { width: 148px; height: 148px; display: block; }
.sigil-stage.is-bound { background: color-mix(in srgb, var(--gold-bright) 20%, var(--bg-elev)); }
.bind-ring {
  position: absolute;
  inset: 6px;
  pointer-events: none;
}
.bind-num {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-variant-numeric: tabular-nums;
  font-size: var(--fs-title);
  color: var(--ink);
  pointer-events: none;
}

.wheel-box { display: flex; flex-direction: column; align-items: center; min-height: 0; }
.wheel-stage { width: 220px; height: 220px; position: relative; }
.wheel-stage svg { width: 220px; height: 220px; display: block; }
.pointer {
  position: absolute;
  left: 50%;
  top: 0;
  width: 0;
  height: 0;
  border-left: 6px solid transparent;
  border-right: 6px solid transparent;
  border-top: 10px solid var(--ink);
  transform: translateX(-50%);
  pointer-events: none;
}
.deity-card {
  border: 1px solid var(--line);
  padding: var(--s-12);
  margin: var(--s-8) 0;
  min-height: 56px;
}
.deity-card b { font-family: var(--font-display); font-size: var(--fs-dek); font-weight: 400; display: block; }
.house-list {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--s-4);
}
.house-list button, .choices button {
  min-height: 44px;
  border: 1px solid var(--line);
  background: var(--bg-elev);
  color: var(--ink);
  border-radius: var(--radius-sm);
  cursor: pointer;
}
.house-list button.is-on, .choices button.is-on { outline: 2px solid var(--ink); }

.picks { display: flex; flex-direction: column; gap: var(--s-8); }
.picks .row { display: flex; flex-wrap: wrap; gap: var(--s-4); }
.chip {
  appearance: none;
  min-height: 44px;
  padding: 0 12px;
  border: 1px solid var(--line);
  background: var(--bg-elev);
  color: var(--ink);
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
.chip.is-on { outline: 2px solid var(--ink); }
.chip .mark { width: 12px; height: 12px; display: inline-block; }
.tickmark { width: 6px; height: 6px; background: var(--ink); display: none; }
.chip.is-on .tickmark { display: inline-block; }
.phrase {
  font-family: var(--font-display);
  font-size: var(--fs-dek);
  line-height: var(--lh-dek);
  margin: var(--s-8) 0;
  min-height: 28px;
}
.ok { color: var(--ok); }
.bad { color: var(--fire); }
.score { font-variant-numeric: tabular-nums; color: var(--ink-soft); margin: 0 0 var(--s-8); }

.choices { display: flex; flex-direction: column; gap: var(--s-8); margin: var(--s-12) 0; }
.needs-js { color: var(--ink-soft); padding: 24px; }

/* 1280 composition */
@media (min-width: 1024px) {
  .app {
    grid-template-columns: 200px 1fr;
    grid-template-rows: 1fr var(--footer-h);
  }
  .rail {
    display: flex;
    flex-direction: column;
    grid-row: 1 / span 2;
    border-right: 1px solid var(--line-soft);
    padding: var(--s-32) var(--s-16);
    overflow: hidden;
  }
  .rail .brand { font-size: var(--fs-title); line-height: var(--lh-title); margin-bottom: var(--s-24); }
  .rail nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
  .rail nav a {
    color: var(--ink-soft);
    text-decoration: none;
    padding: 4px 8px 4px 10px;
    border-left: 2px solid transparent;
    font-size: 16px;
    line-height: 20px;
    white-space: nowrap;
  }
  .rail nav a.is-current { color: var(--gold); border-left-color: var(--gold); }
  .theme-btn { margin-top: auto; min-height: 44px; align-self: stretch; }
  .top {
    display: none;
  }
  .deck { grid-column: 2; }
  .foot {
    grid-column: 2;
    justify-content: flex-end;
    gap: var(--s-16);
    padding: 0 var(--s-32);
  }
  .page {
    padding: var(--s-32);
    justify-content: center;
  }
  .intro {
    max-width: 28ch;
    position: relative;
  }
  .intro::after {
    content: "";
    position: absolute;
    top: 0;
    bottom: 0;
    right: -32px;
    width: 1px;
    background: var(--gold);
  }
  .intro .btn-primary { align-self: flex-start; }
  .method-split {
    display: grid;
    grid-template-columns: 1fr 240px;
    gap: var(--s-16);
    align-items: center;
    width: 100%;
    max-width: 900px;
  }
  .emblem { width: 240px; height: 240px; margin: 0; }
  .practice-split {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--s-16);
    width: 100%;
    max-width: 980px;
    align-items: start;
  }
  .page[data-page="science"] .blocks,
  .page[data-page="colophon"] h2,
  .page[data-page="colophon"] p,
  .page[data-page="quiz"] { max-width: 66ch; }
  .page[data-page="colophon"] { align-items: flex-start; }

  .sigil-stage { width: 240px; height: 240px; }
  .sigil-stage svg { width: 220px; height: 220px; }
  .wheel-stage, .wheel-stage svg { width: 280px; height: 280px; }
  .grid-letters { grid-template-columns: repeat(13, 44px); }
}

::view-transition-old(page) {
  animation: fa-out var(--dur-page) var(--ease-in) both;
}
::view-transition-new(page) {
  animation: fa-in var(--dur-page) var(--ease-out) both;
}
@keyframes fa-out { to { opacity: 0; transform: translateX(-12px); } }
@keyframes fa-in { from { opacity: 0; transform: translateX(12px); } }
.deck { view-transition-name: page; }

@media (prefers-reduced-motion: reduce) {
  ::view-transition-old(page), ::view-transition-new(page) {
    animation: fa-fade 100ms linear both;
  }
  @keyframes fa-fade { from { opacity: 0; } to { opacity: 1; } }
}

.draw-stroke {
  stroke-dasharray: 240;
  stroke-dashoffset: 240;
  animation: draw var(--dur-draw) var(--ease-out) forwards;
}
@keyframes draw { to { stroke-dashoffset: 0; } }
@media (prefers-reduced-motion: reduce) {
  .draw-stroke { animation: none; stroke-dashoffset: 0; }
}
