/* Tallow: paper town at dusk. One palette ("Tallow Dusk 8"), Fraunces for display, Atkinson Hyperlegible for reading. */
:root {
  --ink: #120e1c;
  --night: #261d38;
  --dusk: #43335a;
  --haze: #6e5a85;
  --rose: #c77d8e;
  --wax: #f6e7c8;
  --flame: #ffb440;
  --water: #5fd4e6;
  --wax-dim: #cdbfa3;        /* wax at reading weight: 8.8:1 on night, 10.5:1 on ink */
  --panel: rgba(18, 14, 28, 0.72);
  --display: "Fraunces", Georgia, "Times New Roman", serif;
  --text: "Atkinson Hyperlegible", system-ui, -apple-system, "Segoe UI", sans-serif;
  --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px; --s5: 24px; --s6: 32px; --s7: 48px; --s8: 64px;
  --r: 12px;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: var(--ink); color: var(--wax); overscroll-behavior: none; }
body { font: 400 17px/1.55 var(--text); -webkit-font-smoothing: antialiased; }
body.playing { overflow: hidden; }
h1, h2, h3 { font-family: var(--display); font-weight: 800; line-height: 1.05; margin: 0; letter-spacing: -0.01em; }
p { margin: 0; }
a { color: var(--flame); }
kbd {
  display: inline-block; min-width: 1.9em; padding: 1px 7px; margin: 0 2px; border-radius: 6px;
  font: 700 0.86em/1.5 var(--text); text-align: center; color: var(--wax);
  background: var(--night); border: 1px solid var(--haze); border-bottom-width: 3px;
}
[hidden] { display: none !important; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip { position: absolute; left: var(--s4); top: -60px; z-index: 50; background: var(--wax); color: var(--ink); padding: var(--s2) var(--s4); border-radius: 8px; }
.skip:focus { top: var(--s4); }
:focus-visible { outline: 3px solid var(--flame); outline-offset: 3px; }

/* ---------- Buttons ---------- */
.btn {
  position: relative; display: inline-flex; flex-direction: column; align-items: flex-start; justify-content: center;
  min-height: 52px; padding: 10px 22px; border-radius: var(--r);
  font: 700 18px/1.2 var(--text); color: var(--wax); text-decoration: none; text-align: left;
  background: rgba(38, 29, 56, 0.78); border: 2px solid rgba(246, 231, 200, 0.28); cursor: pointer;
  transition: transform 120ms ease-out, border-color 120ms ease-out, background-color 120ms ease-out;
}
.btn:hover { border-color: var(--wax); background: var(--night); }
.btn:active { transform: scale(0.97); }
.btn-primary {
  min-height: 64px; color: var(--ink); background: var(--flame); border-color: var(--ink);
  box-shadow: 0 4px 0 var(--ink), 0 0 0 2px rgba(255, 180, 64, 0.25), 0 10px 40px rgba(255, 180, 64, 0.25);
}
.btn-primary:hover { background: #ffc566; border-color: var(--ink); }
.btn-primary:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--ink); }
/* The wax drip under the primary button: its signature detail. */
.btn-primary::after {
  content: ""; position: absolute; left: 26px; bottom: -11px; width: 12px; height: 14px;
  background: var(--flame); border: 2px solid var(--ink); border-top: 0; border-radius: 0 0 8px 8px;
}
.btn-primary span:first-child { font: 800 26px/1 var(--display); }
.btn-sub { font: 700 14px/1.3 var(--text); opacity: 0.8; margin-top: 3px; }
.btn-icon { flex-direction: row; align-items: center; gap: var(--s2); }
.btn-icon svg, .hud-btn svg { width: 24px; height: 24px; fill: currentColor; stroke: currentColor; }
.i-cross { display: none; }
[aria-pressed="true"] .i-waves { display: none; }
[aria-pressed="true"] .i-cross { display: inline; }
.btn-key { min-width: 120px; align-items: center; font-variant-numeric: tabular-nums; }
.btn-key.listening { border-color: var(--flame); color: var(--flame); }
.link-btn { background: none; border: 0; padding: 10px 8px; min-height: 44px; font: 700 16px var(--text); color: var(--flame); text-decoration: underline; cursor: pointer; }

/* ---------- Title ---------- */
.title {
  position: relative; min-height: 100vh; min-height: 100dvh; overflow: hidden;
  display: grid; grid-template-columns: minmax(0, 1.05fr) minmax(0, 0.95fr); align-items: center;
  gap: var(--s6); padding: calc(var(--s7) + var(--safe-t)) calc(clamp(16px, 6vw, 96px) + var(--safe-r)) calc(var(--s8) + var(--safe-b)) calc(clamp(16px, 6vw, 96px) + var(--safe-l));
  background:
    radial-gradient(1.5px 1.5px at 12% 18%, rgba(246,231,200,.7), transparent),
    radial-gradient(1.5px 1.5px at 28% 8%, rgba(246,231,200,.5), transparent),
    radial-gradient(1px 1px at 46% 22%, rgba(246,231,200,.6), transparent),
    radial-gradient(1.5px 1.5px at 63% 12%, rgba(246,231,200,.45), transparent),
    radial-gradient(1px 1px at 88% 30%, rgba(246,231,200,.6), transparent),
    radial-gradient(1px 1px at 8% 40%, rgba(246,231,200,.4), transparent),
    radial-gradient(circle at 80% 18%, rgba(246,231,200,.18) 0 56px, transparent 57px),
    linear-gradient(180deg, var(--ink) 0%, var(--night) 45%, var(--dusk) 78%, #7a5a7e 100%);
}
.title-sky { position: absolute; inset: auto 0 0 0; height: min(46vh, 360px); pointer-events: none; }
.title-roofs { position: absolute; inset: 0; width: 100%; height: 100%; }
.title-inner { position: relative; z-index: 1; max-width: 560px; }
.kicker { font: 700 14px/1.3 var(--text); letter-spacing: 0.14em; text-transform: uppercase; color: var(--rose); }
.wordmark {
  position: relative; font-size: clamp(76px, 15vw, 176px); line-height: 0.9; margin: 0.34em 0 var(--s4);
  color: var(--wax); font-weight: 800; letter-spacing: -0.03em;
  text-shadow: 0 4px 0 var(--ink), 0 0 60px rgba(255, 180, 64, 0.22);
}
/* A small flame stands on the T. */
.wordmark::before {
  content: ""; position: absolute; left: 0.235em; top: -0.2em; width: 0.17em; height: 0.27em;
  background: var(--flame); border-radius: 50% 50% 50% 50% / 62% 62% 38% 38%;
  clip-path: polygon(50% 0, 100% 62%, 92% 82%, 72% 97%, 50% 100%, 28% 97%, 8% 82%, 0 62%);
  box-shadow: 0 0 30px rgba(255, 180, 64, 0.8);
  animation: flicker 1.6s ease-in-out infinite;
  transform-origin: 50% 100%;
}
@keyframes flicker { 0%, 100% { transform: scale(1, 1); } 40% { transform: scale(0.92, 1.08) rotate(-3deg); } 70% { transform: scale(1.05, 0.95) rotate(2deg); } }
.lede { font-size: 19px; max-width: 34ch; color: var(--wax-dim); }
.menu { display: grid; grid-template-columns: repeat(2, minmax(0, max-content)); gap: var(--s3); margin-top: var(--s6); align-items: stretch; }
.menu .btn-primary { grid-column: 1 / -1; width: min(100%, 340px); margin-bottom: var(--s3); }
.menu .btn:not(.btn-primary) { min-width: 168px; }
.loading-line { margin-top: var(--s5); font: 600 20px/1.3 var(--display); color: var(--flame); }
.noscript { margin-top: var(--s4); color: var(--wax-dim); }
.keys { list-style: none; padding: 0; margin: var(--s6) 0 0; display: flex; flex-wrap: wrap; gap: var(--s2) var(--s5); color: var(--wax-dim); font-size: 16px; }
.title-hero { position: relative; z-index: 1; margin: 0; justify-self: center; align-self: end; }
.title-hero img { display: block; width: min(420px, 38vw); height: auto; filter: drop-shadow(0 18px 40px rgba(255, 180, 64, 0.18)); }
.title-hero figcaption { margin-top: var(--s2); font: 600 italic 16px var(--display); color: var(--wax-dim); text-align: center; }

@media (max-width: 760px) {
  .title { background: linear-gradient(180deg, var(--ink) 0%, var(--night) 45%, var(--dusk) 78%, #7a5a7e 100%); }
  .title { grid-template-columns: 1fr; gap: var(--s4); padding-top: calc(var(--s6) + var(--safe-t)); align-content: start; }
  .title-hero { order: -1; justify-self: start; }
  .title-hero img { width: 132px; }
  .title-hero figcaption { display: none; }
  .menu { grid-template-columns: 1fr 1fr; }
  .menu .btn-primary { width: 100%; }
  .menu .btn:not(.btn-primary) { min-width: 0; }
  .keys { display: none; }
}
@media (max-height: 520px) and (orientation: landscape) {
  .title { padding-top: var(--s4); padding-bottom: var(--s4); align-content: center; }
  .wordmark { font-size: 64px; margin-bottom: var(--s3); }
  .kicker, .lede, .keys { display: none; }
  .menu { margin-top: var(--s3); grid-template-columns: repeat(2, minmax(0, max-content)); }
  .menu .btn-primary { min-height: 56px; }
  .menu .btn:not(.btn-primary) { min-height: 48px; padding: 8px 16px; }
  .title-hero { display: none; }
  .tbtn { width: 72px; height: 72px; opacity: 0.7; }
  .tbtn-jump { width: 88px; height: 88px; }
}

/* ---------- Sheets (pause, results, settings) ---------- */
.sheet {
  position: fixed; inset: 0; z-index: 30; display: grid; place-items: center; overflow-y: auto;
  padding: calc(var(--s5) + var(--safe-t)) calc(var(--s4) + var(--safe-r)) calc(var(--s5) + var(--safe-b)) calc(var(--s4) + var(--safe-l));
  background: rgba(18, 14, 28, 0.74); -webkit-backdrop-filter: blur(4px); backdrop-filter: blur(4px);
  animation: sheet-in 200ms ease-out;
}
.sheet-top { z-index: 40; }
@keyframes sheet-in { from { opacity: 0; } to { opacity: 1; } }
.sheet-card {
  position: relative; width: min(100%, 460px); padding: var(--s6); border-radius: 18px;
  background: var(--night); border: 2px solid var(--ink);
  box-shadow: inset 0 0 0 1px rgba(246, 231, 200, 0.14), 0 6px 0 var(--ink), 0 30px 80px rgba(0, 0, 0, 0.5);
  animation: card-in 240ms cubic-bezier(.2, .9, .3, 1.2);
}
@keyframes card-in { from { transform: translateY(14px) scale(0.98); } to { transform: none; } }
.sheet-wide { width: min(100%, 560px); }
.sheet-card h2 { font-size: clamp(32px, 6vw, 44px); color: var(--wax); margin: var(--s1) 0 var(--s3); }
.sheet-note { color: var(--wax-dim); margin-bottom: var(--s5); max-width: 42ch; }
.stack { display: grid; gap: var(--s3); margin-top: var(--s5); }
.stack .btn { width: 100%; }
.row { display: flex; gap: var(--s3); justify-content: flex-end; margin-top: var(--s5); }
.sheet-result::before {
  content: ""; position: absolute; right: 24px; top: -30px; width: 46px; height: 60px;
  background: var(--flame); clip-path: polygon(50% 0, 100% 60%, 92% 82%, 72% 97%, 50% 100%, 28% 97%, 8% 82%, 0 60%);
  filter: drop-shadow(0 0 18px rgba(255,180,64,.9));
}
.sheet-lose::before {
  content: ""; position: absolute; right: 30px; top: -18px; width: 12px; height: 40px; border-radius: 6px;
  background: linear-gradient(var(--haze), transparent);
}
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--s3); margin: var(--s4) 0 0; }
.stats div { padding: var(--s3); border-radius: 10px; background: rgba(18, 14, 28, 0.6); border: 1px solid rgba(246, 231, 200, 0.12); }
.stats dt { font: 700 14px/1.2 var(--text); letter-spacing: 0.1em; text-transform: uppercase; color: var(--rose); }
.stats dd { margin: var(--s1) 0 0; font: 800 28px/1.1 var(--display); font-variant-numeric: tabular-nums; color: var(--wax); }
.stats .best { display: block; font: 700 14px/1.3 var(--text); color: var(--flame); margin-top: 2px; }
.controls-mini { margin: var(--s5) 0 0; padding-top: var(--s4); border-top: 1px solid rgba(246, 231, 200, 0.12); display: grid; gap: var(--s2); font-size: 16px; color: var(--wax-dim); }
.controls-mini div { display: grid; grid-template-columns: 84px 1fr; gap: var(--s3); }
.controls-mini dt { font-weight: 700; color: var(--wax); }
.controls-mini dd { margin: 0; }
.street-list { list-style: none; padding: 0; margin: 0; display: grid; gap: var(--s3); }
.street-list .btn { width: 100%; flex-direction: row; align-items: center; justify-content: space-between; gap: var(--s4); min-height: 64px; }
.street-list .num { font: 800 28px/1 var(--display); color: var(--flame); width: 1.2em; }
.street-list .name { flex: 1; }
.street-list .best { font-size: 15px; color: var(--wax-dim); font-variant-numeric: tabular-nums; }
.street-list .btn[disabled] { opacity: 0.55; cursor: not-allowed; }
.street-list .btn[disabled] .num { color: var(--haze); }
.final-table { width: 100%; border-collapse: collapse; margin-top: var(--s4); font-variant-numeric: tabular-nums; }
.final-table th, .final-table td { text-align: left; padding: 10px 6px; border-bottom: 1px solid rgba(246, 231, 200, 0.12); }
.final-table thead th { font: 700 14px/1.2 var(--text); letter-spacing: 0.1em; text-transform: uppercase; color: var(--rose); }
.final-table tfoot th, .final-table tfoot td { font: 800 22px/1.2 var(--display); border-bottom: 0; color: var(--flame); }

/* ---------- Settings ---------- */
.settings fieldset { border: 0; padding: 0; margin: 0 0 var(--s5); }
.settings legend { font: 800 20px/1.2 var(--display); color: var(--wax); margin-bottom: var(--s3); padding: 0; }
.check { display: flex; align-items: center; gap: var(--s3); min-height: 48px; cursor: pointer; flex-wrap: wrap; }
.check input { width: 24px; height: 24px; accent-color: var(--flame); margin: 0; }
.range { display: grid; grid-template-columns: 110px 1fr 52px; align-items: center; gap: var(--s3); min-height: 48px; }
.range input { width: 100%; accent-color: var(--flame); height: 32px; }
.range output { font-variant-numeric: tabular-nums; text-align: right; color: var(--wax-dim); }
.hint, .hint-inline { font-size: 15px; color: var(--wax-dim); }
.hint { margin-top: var(--s1); }
.bind-row { display: flex; align-items: center; gap: var(--s3); flex-wrap: wrap; }
.bind-row > span { min-width: 98px; font-weight: 700; }

/* ---------- The game shell ---------- */
.shell { position: fixed; inset: 0; background: var(--ink); display: grid; grid-template-rows: 1fr; grid-template-columns: minmax(0, 1fr); touch-action: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
.stage-wrap { position: relative; grid-row: 1; grid-column: 1; min-height: 0; }
.stage { position: absolute; inset: 0; touch-action: none; }
.stage canvas { display: block; }
.loading { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; gap: var(--s3); font: 600 22px var(--display); color: var(--flame); pointer-events: none; }
.loading-flame { width: 14px; height: 20px; background: var(--flame); clip-path: polygon(50% 0, 100% 62%, 92% 82%, 72% 97%, 50% 100%, 28% 97%, 8% 82%, 0 62%); animation: flicker 1s ease-in-out infinite; transform-origin: 50% 100%; }
.countdown { position: absolute; inset: 0; display: grid; place-items: center; font: 800 clamp(72px, 14vw, 140px)/1 var(--display); color: var(--wax); text-shadow: 0 5px 0 var(--ink); pointer-events: none; }

.hud {
  grid-row: 1; grid-column: 1; align-self: start; z-index: 5; position: relative; pointer-events: none;
  display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); align-items: start; gap: var(--s3);
  padding: calc(var(--s3) + var(--safe-t)) calc(var(--s4) + var(--safe-r)) 0 calc(var(--s4) + var(--safe-l));
}
.hud > div { display: flex; align-items: center; gap: var(--s2); }
.hud-right { justify-content: flex-end; }
.hud-mid { flex-direction: column; gap: 0 !important; padding: 4px 16px 6px; border-radius: 12px; background: var(--panel); }
.hud-street { font: 700 14px/1.3 var(--text); letter-spacing: 0.08em; text-transform: uppercase; color: var(--rose); }
.hud-time { font: 700 24px/1.1 var(--text); font-variant-numeric: tabular-nums; color: var(--wax); }
.flames { display: flex; gap: 6px; padding: 8px 12px; border-radius: 12px; background: var(--panel); }
.flames svg { width: 20px; height: 26px; }
.flames path { fill: var(--flame); stroke: var(--ink); stroke-width: 1.6; transition: transform 150ms ease-out; transform-origin: 50% 100%; }
.flames svg.out path { fill: none; stroke: var(--haze); stroke-width: 1.8; stroke-dasharray: 3 2.5; }
.flames.pop { animation: pop 220ms ease-out; }
.hud-embers { display: flex; align-items: center; gap: 8px; padding: 6px 12px; border-radius: 12px; background: var(--panel); font: 700 22px/1 var(--text); font-variant-numeric: tabular-nums; min-height: 44px; }
.hud-embers svg { width: 18px; height: 18px; fill: var(--flame); stroke: var(--ink); stroke-width: 1.5; }
.hud-embers.pop { animation: pop 180ms ease-out; }
@keyframes pop { 50% { transform: scale(1.14); } }
.hud-btn {
  pointer-events: auto; width: 48px; height: 48px; display: grid; place-items: center; border-radius: 12px;
  background: var(--panel); color: var(--wax); border: 2px solid rgba(246, 231, 200, 0.22); cursor: pointer;
}
.hud-btn:hover { border-color: var(--wax); }

.pad-area { grid-row: 1; grid-column: 1; align-self: end; z-index: 4; position: relative; pointer-events: none; padding: 0 calc(var(--s4) + var(--safe-r)) calc(var(--s4) + var(--safe-b)) calc(var(--s4) + var(--safe-l)); }
.desk-keys { display: none; }
.touch { display: flex; justify-content: space-between; align-items: flex-end; gap: var(--s4); }
.touch-move { pointer-events: auto; display: flex; gap: 12px; padding: 0; touch-action: none; }
.tbtn {
  display: grid; place-items: center; width: 80px; height: 80px; border-radius: 50%;
  background: rgba(246, 231, 200, 0.16); border: 2px solid rgba(246, 231, 200, 0.5); color: var(--wax);
  opacity: 0.85; transition: transform 80ms ease-out, background-color 80ms ease-out;
}
.tbtn svg { width: 34px; height: 34px; fill: none; stroke: currentColor; stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; }
.tbtn.on { background: rgba(255, 180, 64, 0.45); border-color: var(--flame); transform: scale(0.94); }
.tbtn-jump { pointer-events: auto; width: 100px; height: 100px; touch-action: none; grid-template-rows: auto auto; align-content: center; gap: 0; }
.tbtn-jump span { font: 700 14px var(--text); letter-spacing: 0.06em; text-transform: uppercase; }
.rotate-hint {
  pointer-events: auto; display: flex; align-items: center; gap: var(--s3); margin: 0 auto var(--s3); width: fit-content; max-width: 100%;
  padding: 6px 6px 6px 14px; border-radius: 12px; background: var(--night); border: 1px solid var(--haze); font-size: 16px; color: var(--wax);
}
.rotate-hint svg { width: 24px; height: 24px; stroke: var(--flame); flex: none; }

/* Portrait: the canvas across the top, the controls in the space below. */
@media (orientation: portrait) {
  .shell { grid-template-rows: auto auto 1fr; }
  .hud { grid-row: 1; padding-bottom: var(--s3); }
  .hud-street { display: none; }
  .stage-wrap { grid-row: 2; aspect-ratio: 1 / 1; width: 100%; max-height: 58vh; }
  .pad-area { grid-row: 3; align-self: stretch; display: flex; flex-direction: column; justify-content: flex-end; padding-top: var(--s4); }
  .touch { padding-bottom: var(--s5); }
  .tbtn { width: 86px; height: 86px; }
  .tbtn-jump { width: 116px; height: 116px; }
  .desk-keys { display: block; text-align: center; color: var(--wax-dim); font-size: 16px; padding-bottom: var(--s6); }
  .touch:not([hidden]) ~ .desk-keys { display: none; }
}
@media (max-width: 420px) {
  .hud { gap: var(--s2); padding-left: calc(var(--s3) + var(--safe-l)); padding-right: calc(var(--s3) + var(--safe-r)); }
  .flames { padding: 8px; gap: 3px; }
  .flames svg { width: 16px; height: 22px; }
  .hud-mid { padding: 4px 10px 6px; }
  .hud-embers { padding: 6px 8px; font-size: 20px; }
  .hud-right { gap: 6px !important; }
  .hud-btn { width: 44px; height: 44px; }
  #btn-mute { display: none; }
  .stats { grid-template-columns: 1fr 1fr 1fr; gap: var(--s2); }
  .stats dd { font-size: 22px; }
  .sheet-card { padding: var(--s5); }
  .range { grid-template-columns: 86px 1fr 46px; }
}

/* ---------- How to play page ---------- */
.page { max-width: 760px; margin: 0 auto; padding: calc(var(--s6) + var(--safe-t)) calc(var(--s4) + var(--safe-r)) var(--s8) calc(var(--s4) + var(--safe-l)); }
.page-top { display: flex; justify-content: space-between; align-items: center; gap: var(--s4); margin-bottom: var(--s7); }
.page-mark { font: 800 32px/1 var(--display); color: var(--wax); text-decoration: none; }
.page h1 { font-size: clamp(44px, 9vw, 72px); margin: var(--s2) 0 var(--s4); }
.page h2 { font-size: 28px; margin: var(--s7) 0 var(--s4); }
.page p { color: var(--wax-dim); max-width: 60ch; margin-bottom: var(--s4); }
.page .lede { font-size: 20px; }
.how-grid { display: grid; border-top: 1px solid rgba(246, 231, 200, 0.12); }
.how-item { display: grid; grid-template-columns: 64px minmax(0, 1fr); column-gap: var(--s5); padding: var(--s5) 0; border-bottom: 1px solid rgba(246, 231, 200, 0.12); }
.how-item img { display: block; width: 64px; height: 64px; grid-row: span 2; }
.how-item h3 { font-size: 22px; margin-bottom: var(--s1); }
.how-item p { font-size: 16px; margin: 0; }
.ctl-table { width: 100%; border-collapse: collapse; font-size: 16px; }
.ctl-table th, .ctl-table td { text-align: left; padding: 12px 8px; border-bottom: 1px solid rgba(246, 231, 200, 0.12); vertical-align: top; }
.ctl-table thead th { font: 700 14px/1.2 var(--text); letter-spacing: 0.1em; text-transform: uppercase; color: var(--rose); }
.table-scroll { overflow-x: auto; }
.page-cta { margin-top: var(--s7); }
.page-cta .btn-primary { display: inline-flex; padding: 10px 28px; }
.page-foot { margin-top: var(--s8); font-size: 15px; color: var(--wax-dim); }

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