@import './src/screens/screens.css';

@font-face {
  font-family: 'DM Sans'; src: url('./fonts/dm-sans-var.woff2') format('woff2');
  font-weight: 400 700; font-style: normal; font-display: swap;
}
/* Retained for existing exported card rendering. */
@font-face { font-family: 'Newsreader'; src: url('./fonts/newsreader-roman.woff2') format('woff2'); font-weight: 400 600; font-display: swap; }
@font-face { font-family: 'Newsreader'; src: url('./fonts/newsreader-italic.woff2') format('woff2'); font-style: italic; font-display: swap; }
@font-face { font-family: 'Martian Mono'; src: url('./fonts/martian-mono.woff2') format('woff2'); font-weight: 300 800; font-display: swap; }

:root {
  color-scheme: light dark;
  --paper: #FBFAF7; --desk: #F0EFEA; --ink: #202422; --ink-2: #737971;
  --dot: #E0E3DC; --rule: #CED3CB; --truth: #287D69; --blush: #F2B8A2;
  --rust: #B4513A; --graphite: #92998F; --gold: #AF8429; --muted-fill: #ECEEE7;
  --font-head: 'DM Sans', ui-sans-serif, system-ui, -apple-system, sans-serif;
  --font-ui: var(--font-head);
  --ease: cubic-bezier(.16,1,.3,1); --t-1: 120ms; --t-2: 200ms; --t-3: 320ms;
  --pad-x: 20px; --r-pill: 12px; --r-sheet: 16px;
  --board-h: clamp(290px, calc(100svh - 350px), 450px);
  --bg: var(--paper); --bg-elev: var(--paper); --bg-sunken: var(--desk);
  --fg: var(--ink); --fg-muted: var(--ink-2); --fg-faint: var(--ink-2);
  --line: var(--dot); --line-strong: var(--rule); --accent: var(--truth); --accent-fg: #fff;
  --font-sans: var(--font-head); --font-display: var(--font-head); --font-mono: var(--font-head);
  --page-max: none;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    --paper: #17191B; --desk: #202426; --ink: #F2F3EC; --ink-2: #A2AAA3;
    --dot: #303738; --rule: #46514C; --truth: #5DC1A3; --blush: #A56653;
    --rust: #DF9176; --graphite: #88938D; --gold: #D9B85D; --muted-fill: #282F2B;
  }
}
:root[data-theme='dark'] {
  --paper: #17191B; --desk: #202426; --ink: #F2F3EC; --ink-2: #A2AAA3;
  --dot: #303738; --rule: #46514C; --truth: #5DC1A3; --blush: #A56653;
  --rust: #DF9176; --graphite: #88938D; --gold: #D9B85D; --muted-fill: #282F2B;
}
:root[data-theme='light'] { color-scheme: light; }
:root[data-theme='dark'] { color-scheme: dark; }
:root[data-cb='on'] { --truth: #597ED4; --rust: #C88942; }

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--paper); }
body { color: var(--ink); font-family: var(--font-head); font-size: 16px; line-height: 1.5; -webkit-font-smoothing: antialiased; -webkit-text-size-adjust: 100%; }
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; touch-action: manipulation; -webkit-tap-highlight-color: transparent; }
button:disabled { cursor: default; }
a { color: inherit; text-decoration: none; }
[hidden] { display: none !important; }
:focus-visible { outline: 3px solid var(--truth); outline-offset: 4px; border-radius: 6px; }
.screen:focus { outline: none; }
.kit-sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; }
#defs { position: absolute; width: 0; height: 0; overflow: hidden; }
.app { min-height: 100svh; padding: env(safe-area-inset-top,0px) 0 env(safe-area-inset-bottom,0px); }
.header { width: min(100% - 48px, 1080px); margin: auto; height: 82px; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--dot); gap: 12px; }
.header__left, .header__right { display: flex; align-items: center; }
.header__left { min-width: 0; gap: 12px; }
.header__right { gap: 6px; }
.wordmark { display: inline-flex; align-items: center; min-height: 44px; font-weight: 700; font-size: 24px; letter-spacing: -.9px; line-height: 1; }
.wordmark svg { margin: 3px 0 0 1px; width: 30px; }
.num:empty { display: none; }
.chip { display: inline-flex; align-items: center; justify-content: center; min-height: 44px; padding: 0 16px; border: 1px solid var(--dot); border-radius: 999px; font-size: 14px; font-weight: 600; white-space: nowrap; }
.chip:hover, .icon-btn:hover, .streak:hover { background: var(--muted-fill); }
.chip--archive { font-size: 12px; color: var(--ink-2); }
.icon-btn { width: 44px; height: 44px; display: grid; place-items: center; border-radius: 50%; }
.streak { display: flex; align-items: center; justify-content: center; gap: 5px; min-width: 44px; height: 44px; padding: 0 6px; border-radius: 8px; font-size: 13px; }
.streak .spark { width: 24px; }
.ui, .serif-num { font-family: var(--font-head); font-variant-numeric: tabular-nums; }
.serif-num { font-weight: 700; }
.main { width: min(100% - 64px, 900px); margin: 32px auto 40px; }
.screen { display: block; }
.titlebar { margin-bottom: 4px; }
.roundbar { display: flex; align-items: center; justify-content: space-between; gap: 10px; min-height: 32px; margin-bottom: 15px; }
.eyebrow { margin: 0; font-size: 12px; line-height: 18px; font-weight: 600; color: var(--ink-2); letter-spacing: .025em; }
.title { margin: 0; font-size: clamp(25px,3.2vw,36px); line-height: 1.2; letter-spacing: -.8px; font-weight: 600; max-width: 850px; text-wrap: balance; }
.prompt { margin: 9px 0 0; font-size: 15px; color: var(--ink-2); }
.column { flex: none; }
.slots { display: flex; gap: 6px; }
.slot { display: grid; place-items: center; width: 28px; height: 28px; border-radius: 50%; color: var(--ink-2); font-size: 11px; border: 1px solid var(--dot); font-variant-numeric: tabular-nums; }
.slot--live { border-color: var(--ink); color: var(--ink); font-weight: 700; }
.slot--done { background: var(--ink); border-color: var(--ink); color: var(--paper); }
.board { position: relative; height: var(--board-h); margin: 8px 0 0; }
.board__svg { display: block; margin: 0 auto; max-width: 100%; max-height: 100%; overflow: visible; touch-action: none; user-select: none; -webkit-user-select: none; }
.board__svg:focus { outline: none; }
.board__svg:focus-visible { outline: 2px solid var(--truth); outline-offset: -2px; }
.l-axis, .l-dots { opacity: 1; }
.chart-legend { display: flex; align-items: center; justify-content: center; gap: 24px; margin: 0 0 18px; min-height: 22px; font-size: 12px; color: var(--ink-2); }
.chart-legend > span { display: inline-flex; align-items: center; gap: 8px; }
.legend-line { display: inline-block; width: 23px; height: 3px; border-radius: 3px; background: var(--ink); }
.legend-line--actual { background: var(--truth); }
.legend-actual { visibility: hidden; }
[data-state='REVEALING'] .legend-actual, [data-state='REACTING'] .legend-actual, [data-state='REVEALED'] .legend-actual { visibility: visible; }
.rail { position: relative; }
.dock { min-height: 22px; margin: 0 0 12px; color: var(--ink-2); font-size: 13px; text-align: center; }
.toolbar { display: flex; align-items: center; justify-content: center; gap: 10px; }
.toolbar__slot:nth-child(1) { order: 1; }
.toolbar__slot:nth-child(3) { order: 2; }
.toolbar__slot:nth-child(2) { order: 3; margin-left: auto; width: 220px; }
.tool { min-height: 48px; padding: 0 14px; display: inline-flex; gap: 7px; align-items: center; border-radius: 10px; font-size: 14px; }
.tool:hover { background: var(--muted-fill); }
.tool svg { width: 18px; height: 18px; }
.tool--muted, .tool[aria-disabled='true'] { color: var(--graphite); }
.pill { display: inline-flex; align-items: center; justify-content: center; gap: 8px; width: 100%; min-height: 48px; padding: 12px 20px; border-radius: 12px; font-size: 15px; font-weight: 600; line-height: 22px; transition: background 120ms ease, transform 120ms ease; }
.pill--ink { background: var(--ink); color: var(--paper); }
.pill--truth { background: var(--truth); color: var(--paper); }
.pill--ghost, .pill--muted { border: 1px solid var(--rule); color: var(--ink-2); }
.pill:hover { filter: brightness(.94); }
.pill:active { transform: translateY(1px); }
[data-state='SEALING'] .toolbar, [data-state='REVEALING'] .toolbar, [data-state='REACTING'] .toolbar { visibility: hidden; }
[data-state='REVEALED'] .toolbar { display: none; }
[data-state='REVEALED'] .prompt { display: none; }
.sheet { position: relative; border-top: 1px solid var(--dot); padding: 20px 0 0; display: grid; grid-template-columns: 1fr auto; column-gap: 24px; animation: result-in 200ms ease; }
.handle { display: none; }
.verdict__top { grid-row: 1; grid-column: 1; }
.verdict__head { display: flex; align-items: center; gap: 18px; }
.verdict__line { display: flex; align-items: baseline; gap: 3px; }
.score { font-size: 44px; line-height: 1; letter-spacing: -1.5px; }
.score__max { font-size: 18px; color: var(--ink-2); }
.result-feedback { margin: 0; font-size: 19px; font-weight: 500; }
.result-breakdown { grid-column: 1; margin: 8px 0 0; font-size: 12px; color: var(--ink-2); }
.story { grid-column: 1; margin: 14px 0 0; font-size: 15px; line-height: 1.55; font-style: normal; }
.source { grid-column: 1; margin: 7px 0 0; font-size: 11px; color: var(--ink-2); line-height: 1.5; }
.source__label { font-weight: 600; }
#next { grid-column: 2; grid-row: 1 / 5; align-self: center; min-width: 180px; }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 65; max-width: calc(100vw - 32px); padding: 10px 18px; border-radius: 12px; background: var(--ink); color: var(--paper); box-shadow: 0 4px 20px #0002; font-size: 14px; pointer-events: none; text-align: center; }
@keyframes result-in { from { opacity: 0; transform: translateY(5px); } to { opacity: 1; transform: none; } }
.say { display: inline-grid; align-items: center; justify-items: center; }
.say > * { grid-area: 1 / 1; }
.say__msg { opacity: 0; visibility: hidden; }
.say__do { display: inline-flex; gap: 8px; align-items: center; }
.say__msg.is-on { opacity: 1; visibility: visible; }
.say.is-saying .say__do { opacity: 0; visibility: hidden; }
.say.is-saying.pill--ink { color: var(--paper); }

/* Secondary screens use ordinary document flow: no hidden scroll regions. */
.d-panel, .d-panel.runs { width: 100%; max-width: 720px; margin: 0 auto; padding: 4px 0; max-height: none; min-height: 0; overflow: visible; }
.sum-heading { font-size: 28px; line-height: 1.2; letter-spacing: -.6px; margin: 12px 0 18px; font-weight: 600; }
.sum-total { margin-top: 12px; }
.sum-total .sum-total__n { font-size: 64px; line-height: 1; font-weight: 600; }
.sum-total__max { font-size: 25px; }
.sum-caption { font-size: 13px; color: var(--ink-2); margin: 8px 0 24px; }
.sum .chart-legend { justify-content: flex-start; margin-bottom: 8px; }
.sum-rows { margin: 0; }
.row.sum-row { grid-template-columns: 120px minmax(0,1fr) 52px; height: auto; min-height: 86px; padding: 14px 0; column-gap: 20px; }
.sum-row__title { display: block; -webkit-line-clamp: unset; overflow: visible; white-space: normal; font-size: 15px; line-height: 21px; }
.sum-row__score { font-size: 24px; }
.sum-row__sheet { width: 120px; height: 48px; }
.sum-actions { position: static; border-top: 1px solid var(--dot); margin-top: 18px; padding: 20px 0 0; max-width: none; }
.sum-actions > .pill { width: min(100%,340px); display: flex; margin: auto; }
.sum-actions > .say { display: inline-grid; margin-left: calc((100% - min(100%,340px)) / 2); }
.sum-links { margin-top: 10px; gap: 16px; }
.sum-tail { margin-top: 16px; }
.sum-back { margin: 0 0 10px -10px; }
.climax { position: fixed; inset: 0; z-index: 45; pointer-events: none; }
.runs-title { margin: 0; font-size: 32px; font-weight: 600; }
.runs-intro { margin: 8px 0 8px; font-size: 15px; color: var(--ink-2); }
.runs-streak { display: none; }
.runs-grid { gap: 10px; margin-top: 18px; }
.shelf { border: 1px solid var(--dot); background: var(--paper); }
.shelf.runs-card { height: 100px; border-radius: 12px; box-shadow: none; }
.shelf.runs-card:hover { border-color: var(--ink-2); }
.runs-card__name { font-size: 16px; font-weight: 600; }
.runs-card__meta { font-size: 12px; }
.shelf.runs-card.shelf--on { box-shadow: none; border-color: var(--ink); }
.runs-foot { position: static; padding: 20px 0 0; margin-top: 0; border: 0; background: none; }
.runs-foot .pill { width: min(100%,340px); margin: auto; display: flex; }
.kit-modal, .kit-sheet, .kit-dialog { font-family: var(--font-head); }
.kit-modal__title, .kit-dialog__title { font-family: var(--font-head); font-weight: 600; }
.kit-btn { font-family: var(--font-head); text-transform: none; letter-spacing: 0; }
.d-modal.help .kit-modal__head { justify-content: space-between; }
.help-intro { margin: 0 0 18px; font-size: 16px; }
.help-steps { padding-left: 22px; margin: 18px 0; font-size: 14px; line-height: 1.6; }
.help-steps li { padding-left: 4px; margin: 8px 0; }
.help-legend { display: flex; justify-content: center; gap: 24px; font-size: 12px; margin: 10px 0; }
.help-legend > * { display: inline-flex; align-items: center; gap: 8px; }
.help-legend__line { display: inline-block; width: 24px; height: 3px; background: var(--ink); }
.help-legend__line--actual { background: var(--truth); }
.help-keyboard { color: var(--ink-2); font-size: 12px; line-height: 1.6; margin: 14px 0; }
.help-cta { margin-top: 12px; }

@media (max-width: 699px) {
  :root { --board-h: clamp(270px, calc(100svh - 320px), 420px); }
  .header { width: calc(100% - 32px); height: 64px; }
  .header__right { gap: 0; }
  .wordmark { font-size: 21px; }
  .wordmark svg { width: 27px; }
  .chip { padding: 0 12px; font-size: 12px; min-height: 38px; }
  .chip--archive { display: none; }
  .main { width: calc(100% - 32px); margin: 20px auto 28px; }
  .roundbar { margin-bottom: 14px; }
  .eyebrow { font-size: 11px; }
  .slot { width: 24px; height: 24px; font-size: 10px; }
  .slots { gap: 4px; }
  .title { font-size: 25px; line-height: 1.22; letter-spacing: -.5px; }
  .prompt { font-size: 14px; margin-top: 8px; }
  .board { margin-top: 0; margin-left: -8px; margin-right: -8px; }
  .chart-legend { margin-bottom: 14px; }
  .dock { font-size: 12px; margin-bottom: 10px; }
  .toolbar { gap: 0; }
  .toolbar__slot:nth-child(2) { width: 42%; }
  .tool { padding: 0 9px; font-size: 13px; }
  .tool svg { width: 16px; }
  .sheet { display: block; padding-top: 16px; }
  .score { font-size: 40px; }
  .result-feedback { font-size: 18px; }
  .story { font-size: 14px; margin-top: 12px; }
  #next { width: 100%; margin-top: 18px; }
  [data-state='REVEALED'] .board { height: 285px; }
  .row.sum-row { grid-template-columns: 84px minmax(0,1fr) 38px; gap: 12px; min-height: 80px; }
  .sum-row__sheet { width: 84px; height: 38px; }
  .sum-row__score { font-size: 21px; }
  .sum-row__title { font-size: 13px; line-height: 18px; }
  .sum-heading { font-size: 26px; }
  .sum-total .sum-total__n { font-size: 56px; }
  .sum-caption { margin-bottom: 20px; }
}
@media (max-width: 379px) {
  .header { width: calc(100% - 24px); gap: 4px; }
  .wordmark { font-size: 18px; }
  .wordmark svg { width: 23px; height: 15px; }
  .streak .spark { display: none; }
  .icon-btn { width: 40px; }
  .header .chip { padding: 0 10px; }
  .main { width: calc(100% - 28px); }
  .title { font-size: 23px; }
  .roundbar { gap: 6px; }
}
@media (max-height: 550px) and (min-width: 600px) {
  .header { height: 58px; }
  .main { margin-top: 18px; }
  :root { --board-h: 280px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: 0s !important; }
}
:root[data-motion='reduce'] *, :root[data-motion='reduce'] *::before, :root[data-motion='reduce'] *::after { animation-duration: .01ms !important; transition-duration: 0s !important; }

.ax { font-family: var(--font-ui); font-size: 11px; font-weight: 400; fill: var(--ink-2); }
.readout { font-family: var(--font-ui); font-size: 12px; font-weight: 600; fill: var(--ink); paint-order: stroke; stroke: var(--paper); stroke-width: 4px; }
.readout--truth { fill: var(--truth); }
.help-score { font-size: 14px; color: var(--ink-2); }
@media (min-width: 700px) {
  [data-state='REVEALED'] .board { height: clamp(240px, calc(100svh - 455px), 360px); }
}

.shelf.runs-card { height: 88px; }
@media (min-width: 700px) { .runs-grid { grid-template-columns: repeat(3, minmax(0,1fr)); } }

@media (min-width: 900px) {
  .d-panel.sum { display: grid; grid-template-columns: 230px minmax(0,1fr); column-gap: 54px; max-width: 900px; align-items: start; }
  .sum-back { grid-column: 1; grid-row: 1; margin-bottom: 12px; }
  .sum-eyebrow { grid-column: 1; grid-row: 2; }
  .sum-heading { grid-column: 1; grid-row: 3; margin: 10px 0 12px; }
  .sum-total { grid-column: 1; grid-row: 4; }
  .sum-caption { grid-column: 1; grid-row: 5; margin-bottom: 18px; }
  .sum .chart-legend { grid-column: 1; grid-row: 6; gap: 16px; }
  .sum-rows { grid-column: 2; grid-row: 2 / 9; }
  .sum-actions { grid-column: 1; grid-row: 7; margin-top: 18px; padding-top: 18px; }
  .sum-links { gap: 0; flex-wrap: wrap; }
  .sum-tail { grid-column: 1; grid-row: 8; }
  .sum-actions > .say { margin-left: 0; }
  .sum-row__title { font-size: 14px; line-height: 20px; }
  .row.sum-row { column-gap: 16px; }
}

/* Actions belong to the viewport, including split windows and browser zoom.
   The document reserves their space, so the last result/source can scroll clear. */
html, body { overflow-x: clip; }
.main { padding-bottom: calc(132px + env(safe-area-inset-bottom, 0px)); }
.toolbar, .next-actions, .sum-actions, .runs-foot {
  position: fixed; z-index: 20; left: 50%; bottom: 0; transform: translateX(-50%);
  width: min(900px, calc(100% - 32px)); margin: 0;
  padding: 12px 0 calc(12px + env(safe-area-inset-bottom, 0px));
  background: var(--paper); border-top: 1px solid var(--dot);
  box-shadow: 0 0 0 16px var(--paper);
}
.next-actions { display: flex; justify-content: flex-end; }
#next { width: min(100%, 260px); margin: 0; min-height: 52px; }
.sum-actions { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.sum-actions > .pill { min-height: 54px; font-size: 17px; }
.sum-links { margin-top: 0; justify-content: center; }
.sum-actions .sum-links .say { margin: 0; }
.runs-foot > .pill { display: flex; width: min(100%, 340px); margin: auto; }
:root { --board-h: clamp(160px, calc(100dvh - 340px), 450px); }
[data-state='REVEALED'] .board { height: clamp(160px, calc(100dvh - 440px), 360px); }
@keyframes result-in { from { opacity: 0; } to { opacity: 1; } }
@media (max-width: 699px) {
  .next-actions #next { width: 100%; }
  .header__right { flex-shrink: 0; }
}
@media (max-height: 650px) {
  .header { height: 56px; }
  .main { margin-top: 12px; }
  .roundbar { margin-bottom: 8px; }
  .title { font-size: 24px; }
  .chart-legend { margin-bottom: 8px; }
}
/* A retained transform animation also traps fixed descendants after it ends. */
@keyframes d-rise { from { opacity: 0; } to { opacity: 1; } }
.header .chip { min-height: 44px; }
