/* Layout: one narrow column; a numbered measuring rail sits beside the five cards, like a ruler you sort against.
   Single black look in every theme, by request. */
:root {
  --bg: #000000;
  --surface: #141414;
  --ink: #f2f2f2;
  --muted: #9a9a9a;
  --line: #2c2c2c;
  --tape: #f5c02a;
  --tape-ink: #1a1400;
  --good: #2fae6c;
  --good-ink: #04140b;
  --miss: #333333;
  --shadow: none;
  --f-display: "Unbounded", "Arial Black", system-ui, sans-serif;
  --f-body: "Atkinson Hyperlegible", system-ui, -apple-system, "Segoe UI", sans-serif;
  --f-mono: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, monospace;
  --card-h: 56px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.45 var(--f-body);
  -webkit-tap-highlight-color: transparent;
}
.app {
  max-width: 460px;
  margin: 0 auto;
  padding-inline: 16px;
  padding-block: 8px 32px;
}

/* Header */
.bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding-block: 10px;
  border-bottom: 2px solid var(--ink);
}
.logo {
  margin: 0;
  font: 800 1.5rem/1 var(--f-display);
  letter-spacing: .04em;
}
.num {
  font: 700 .8rem var(--f-mono);
  background: var(--tape);
  color: var(--tape-ink);
  padding: 3px 6px;
  border-radius: 3px;
  margin-right: auto;
}
.icon-btn {
  width: 36px; height: 36px;
  display: grid; place-items: center;
  border: 1.5px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  border-radius: 50%;
  font: 700 1rem var(--f-body);
  cursor: pointer;
}

/* Board */
.board { display: flex; flex-direction: column; gap: 14px; padding-top: 18px; }
.topic {
  margin: 0;
  font: 700 .75rem var(--f-mono);
  text-transform: uppercase;
  letter-spacing: .12em;
  color: var(--muted);
}
.question {
  margin: -8px 0 0;
  font: 600 1.35rem/1.2 var(--f-display);
  text-wrap: balance;
}

.scale { display: grid; grid-template-columns: 40px 1fr; gap: 10px; }
.end {
  margin: 0 0 -6px 50px;
  font: 700 .72rem var(--f-mono);
  text-transform: uppercase;
  letter-spacing: .1em;
  color: var(--muted);
}
.end + .scale { margin-top: 0; }
.scale + .end { margin: -6px 0 0 50px; }
.ticks {
  list-style: none; margin: 0; padding: 0;
  display: grid; grid-template-rows: repeat(var(--slots, 6), var(--card-h)); gap: 8px;
  background: var(--tape);
  color: var(--tape-ink);
  border-radius: 6px;
  /* ruler tick marks along the right edge */
  background-image: repeating-linear-gradient(to bottom, rgba(0,0,0,.22) 0 1px, transparent 1px 7px);
  background-size: 6px 100%;
  background-repeat: no-repeat;
  background-position: right 0 top 0;
}
.ticks li {
  display: grid; place-items: center;
  font: 700 1.05rem var(--f-mono);
}

.cards {
  list-style: none; margin: 0; padding: 0;
  display: flex; flex-direction: column; gap: 8px;
  min-width: 0;
}
.card {
  display: flex; align-items: center; gap: 10px;
  height: var(--card-h);
  padding: 8px 12px;
  background: var(--surface);
  border: 2px solid var(--line);
  border-radius: 10px;
  box-shadow: var(--shadow);
  cursor: grab;
  user-select: none;
  touch-action: manipulation;
  transition: border-color .15s, background-color .25s, transform .15s;
}
.card:focus-visible { outline: 3px solid var(--tape); outline-offset: 2px; }
.card .txt { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.card .name { font-weight: 700; line-height: 1.15; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.card .detail { font-size: .8rem; color: var(--muted); }
.card .val { font: 700 .85rem var(--f-mono); white-space: nowrap; }
.card .grip { color: var(--muted); font-size: 1.1rem; line-height: 1; }
.card.selected { border-color: var(--tape); transform: translateX(4px); }
.card.locked {
  background: var(--good);
  border-color: var(--good);
  color: var(--good-ink);
  cursor: default;
}
.card.locked .detail, .card.locked .grip { color: inherit; opacity: .8; }
.card.missed { border-style: dashed; }
.card.ghost { opacity: .35; }
.card.drag { box-shadow: 0 14px 30px -10px rgba(0,0,0,.45); }
.done .card { cursor: default; }

/* Guess history */
.tries { display: flex; flex-direction: column; gap: 8px; }
.try {
  border: 1.5px solid var(--line);
  border-radius: 10px;
  padding: 8px 10px;
  display: flex; flex-direction: column; gap: 6px;
}
.try.pending { border-style: dashed; padding-block: 6px; }
.try-head {
  display: flex; justify-content: space-between;
  font: 700 .72rem var(--f-mono); text-transform: uppercase; letter-spacing: .08em;
  color: var(--muted);
}
.try-score { color: var(--ink); }
.chips {
  list-style: none; margin: 0; padding: 0;
  display: grid; grid-auto-flow: column; grid-template-rows: repeat(var(--rows, 3), auto); grid-template-columns: 1fr 1fr;
  gap: 4px 6px;
}
.chip {
  display: flex; align-items: baseline; gap: 6px; min-width: 0;
  background: var(--miss); color: var(--ink);
  border-radius: 5px; padding: 3px 7px;
  font-size: .8rem; line-height: 1.25;
}
.chip b { font: 700 .72rem var(--f-mono); opacity: .75; }
.chip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip.ok { background: var(--good); color: var(--good-ink); }
.sq { width: 22px; height: 22px; border-radius: 4px; background: var(--miss); }
.sq.g { background: var(--good); }

/* Actions */
.actions { display: flex; flex-direction: column; gap: 8px; align-items: stretch; }
.hint { margin: 0; text-align: center; font-size: .85rem; color: var(--muted); }
.primary {
  font: 700 1rem var(--f-body);
  padding: 14px 18px;
  border: 0;
  border-radius: 10px;
  background: var(--ink);
  color: var(--bg);
  cursor: pointer;
}
.primary:focus-visible, .icon-btn:focus-visible { outline: 3px solid var(--tape); outline-offset: 2px; }
.primary:active { transform: translateY(1px); }

/* Result */
.result {
  display: flex; flex-direction: column; gap: 10px;
  padding-top: 6px;
  border-top: 2px solid var(--ink);
}
.verdict { margin: 0; font: 800 1.2rem var(--f-display); }
.fact { margin: 0; color: var(--muted); }
.share-preview {
  margin: 0;
  font: 500 .95rem/1.35 var(--f-mono);
  background: var(--surface);
  border: 1.5px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  white-space: pre-wrap;
  user-select: all;
}
.toast { margin: 0; min-height: 1.2em; text-align: center; font-size: .85rem; color: var(--muted); }
.next { margin: 0; text-align: center; color: var(--muted); }
#countdown { font: 700 1rem var(--f-mono); color: var(--ink); font-variant-numeric: tabular-nums; }

.fine { margin: 24px 0 0; font-size: .75rem; color: var(--muted); text-align: center; }

/* Wide screens: game in the middle, past tries on the right, left column kept free for ads. */
.ad-slot { display: none; }
@media (min-width: 1000px) {
  .app { max-width: 1240px; }
  .bar, .fine { max-width: 460px; margin-inline: auto; }
  .board {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 460px minmax(0, 1fr);
    column-gap: 40px;
    row-gap: 14px;
    align-items: start;
  }
  .board > * { grid-column: 2; }
  .board > .tries { grid-column: 3; grid-row: 1 / span 9; max-width: 340px; }
  .tries::before {
    content: "Your tries";
    font: 700 .75rem var(--f-mono); text-transform: uppercase; letter-spacing: .12em;
    color: var(--muted);
  }
  .board > .ad-slot {
    grid-column: 1; grid-row: 1 / span 9;
    display: grid; place-items: center;
    justify-self: end; width: 300px; height: 600px; max-width: 100%;
    border: 1.5px dashed var(--line); border-radius: 10px;
    font: 700 .75rem var(--f-mono); text-transform: uppercase; letter-spacing: .12em;
    color: var(--muted);
  }
  .question { margin-top: 0; }
}

/* Calendar of past puzzles */
#calendar[open] { display: flex; flex-direction: column; gap: 10px; }
#calendar .primary { margin-top: 4px; }
.cal-nav { display: flex; align-items: center; justify-content: space-between; }
.cal-nav b { font: 700 1rem var(--f-body); }
.cal-nav .icon-btn:disabled { opacity: .3; cursor: default; }
.cal-week, .cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; text-align: center; }
.cal-week span { font: 700 .7rem var(--f-mono); color: var(--muted); }
.day {
  aspect-ratio: 1; max-width: 100%;
  border: 1.5px solid var(--line); border-radius: 8px;
  background: transparent; color: var(--ink);
  font: 700 .9rem var(--f-mono); cursor: pointer;
}
.day:disabled { border-color: transparent; color: var(--muted); opacity: .35; cursor: default; }
.day.won { background: var(--good); border-color: var(--good); color: var(--good-ink); }
.day.lost { background: var(--miss); border-color: var(--miss); }
.day.started { border-style: dashed; border-color: var(--ink); }
.day.today { outline: 2px solid var(--tape); outline-offset: 1px; }
.day.current { box-shadow: inset 0 0 0 2px var(--ink); }
.day:focus-visible { outline: 3px solid var(--tape); outline-offset: 2px; }
.cal-key { display: flex; gap: 14px; flex-wrap: wrap; font-size: .75rem; color: var(--muted); }
.cal-key span { display: flex; align-items: center; gap: 5px; }
.k { width: 12px; height: 12px; border-radius: 3px; display: inline-block; border: 1.5px solid var(--line); }
.k.won { background: var(--good); border-color: var(--good); }
.k.lost { background: var(--miss); border-color: var(--miss); }
.k.today { border: 2px solid var(--tape); }

/* Units switch */
.units { display: flex; align-items: center; gap: 6px; font: 700 .72rem var(--f-mono); text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.units span { margin-right: 4px; }
.units button {
  font: 700 .8rem var(--f-body); text-transform: none; letter-spacing: 0;
  padding: 5px 12px; border-radius: 999px; cursor: pointer;
  border: 1.5px solid var(--line); background: transparent; color: var(--ink);
}
.units button[aria-pressed="true"] { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.units button:focus-visible { outline: 3px solid var(--tape); outline-offset: 2px; }
.sheet .units { margin-top: 12px; }

/* Dialogs */
#end { display: none; }
#end[open] { display: flex; flex-direction: column; gap: 10px; }
#end h2 { margin: 0; }
#end .primary { margin-top: 0; }
.did { background: var(--tape); color: var(--tape-ink); border-radius: 10px; padding: 12px 14px; }
.sheet .did h3 { margin: 0 0 4px; color: inherit; }
.did p { margin: 0; font-size: 1.05rem; line-height: 1.4; }
.ghost { font: 700 .95rem var(--f-body); padding: 10px; border: 1.5px solid var(--line); border-radius: 10px; background: transparent; color: var(--ink); cursor: pointer; }
.ghost:focus-visible { outline: 3px solid var(--tape); outline-offset: 2px; }

.sheet {
  width: min(420px, calc(100% - 32px));
  border: 0;
  border-radius: 14px;
  padding: 20px;
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 20px 60px -20px rgba(0,0,0,.6);
}
.sheet::backdrop { background: rgba(0, 0, 0, .7); }
.sheet h2 { margin: 0 0 8px; font: 800 1.2rem var(--f-display); }
.sheet h3 { margin: 16px 0 8px; font: 700 .75rem var(--f-mono); text-transform: uppercase; letter-spacing: .1em; color: var(--muted); }
.sheet ul { padding-left: 1.1em; }
.sheet li + li { margin-top: 4px; }
.sheet .primary { width: 100%; margin-top: 14px; }
.small { font-size: .85rem; color: var(--muted); margin: 4px 0 0; }
.demo { display: flex; gap: 5px; }
.stat-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; text-align: center; }
.stat-row b { display: block; font: 700 1.6rem var(--f-mono); font-variant-numeric: tabular-nums; }
.stat-row span { font-size: .72rem; color: var(--muted); }
.dist { display: flex; flex-direction: column; gap: 5px; }
.dist-row { display: grid; grid-template-columns: 1.6em 1fr; gap: 6px; align-items: center; font: 700 .85rem var(--f-mono); }
.dist-bar {
  background: var(--miss); color: var(--ink);
  padding: 2px 6px; text-align: right; border-radius: 3px;
  min-width: 1.8em;
}
.dist-bar.today { background: var(--good); color: var(--good-ink); }

@keyframes pop { 50% { transform: scale(1.04); } }
.card.just-locked { animation: pop .35s ease-out; }
@keyframes shake { 25% { transform: translateX(-4px); } 75% { transform: translateX(4px); } }
.cards.shake { animation: shake .25s 2; }
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

/* The reveal: when a game ends the cards drop into the true order, top to bottom. */
@keyframes fall { from { transform: translateY(-32px); opacity: 0; } 65% { transform: translateY(4px); opacity: 1; } to { transform: none; opacity: 1; } }
@keyframes fadein { from { opacity: 0; } to { opacity: 1; } }
.card.fall { animation: fall .45s cubic-bezier(.3, 1.3, .5, 1) both; animation-delay: calc(var(--i) * 170ms); }
.card.fall .val { animation: fadein .3s both; animation-delay: calc(var(--i) * 170ms + 350ms); }
/* "Wait, really?": the card the first try was furthest off on */
.card.shock { outline: 3px solid var(--tape); outline-offset: 2px; }
.card .was { font: 700 .7rem var(--f-mono); background: var(--tape); color: var(--tape-ink); border-radius: 4px; padding: 2px 6px; white-space: nowrap; }
.card.fall .was { animation: fadein .3s both; animation-delay: 1.3s; }
.shock { margin: 0; }
.shock b { color: var(--tape); }
.wow { border: 2px solid var(--tape); border-radius: 10px; padding: 12px 14px; margin-bottom: 10px; }
.sheet .wow h3 { margin: 0 0 4px; color: var(--tape); }
.wow p { margin: 0; font-size: 1.05rem; line-height: 1.4; }
.card-img { display: block; width: 100%; margin-top: 12px; border-radius: 10px; border: 1.5px solid var(--line); }
#end .share-preview { display: none; }
.card .detail .was { margin-left: 6px; }
.pair { display: flex; gap: 8px; margin-top: 12px; }
.pair > * { flex: 1; min-width: 0; }
.sheet .pair .primary { margin-top: 0; }
.primary.alt { background: var(--tape); color: var(--tape-ink); }
.card-img { max-width: 320px; margin-left: auto; margin-right: auto; }
@media (prefers-reduced-motion: reduce) { .card.fall, .card.fall .val, .card.fall .was { animation: none; } }

/* How everyone did: shared results */
.crowd { border: 1.5px solid var(--line); border-radius: 10px; padding: 12px 14px; margin-top: 10px; }
.crowd h3, .sheet .crowd h3 { margin: 0 0 6px; font: 700 .75rem var(--f-mono); text-transform: uppercase; letter-spacing: .1em; color: var(--muted); }
.crowd p { margin: 0; }
.crowd-line b { color: var(--good); }
.crowd-bars { display: grid; gap: 4px; margin: 10px 0 4px; }
.cb { display: grid; grid-template-columns: 1.2em 1fr 3em; align-items: center; gap: 8px; font: 700 .85rem var(--f-mono); color: var(--muted); }
.cb i { display: block; height: 16px; width: var(--w); background: var(--miss); border-radius: 3px; }
.cb b { text-align: right; }
.cb.me { color: var(--ink); }
.cb.me i { background: var(--good); }
.crowd-key { font-size: .75rem; color: var(--muted); }
.crowd-fool { margin-top: 8px !important; }
.crowd-fool b { color: var(--tape); }

/* Win: the cards hop one after another, and a word drops in at the top. */
@keyframes hop { 0%, 100% { transform: none; } 35% { transform: translateY(-14px); } 60% { transform: translateY(2px); } }
.card.win { animation: hop .5s ease-out both; animation-delay: calc(var(--i) * 100ms + 150ms); }
.cheer {
  position: fixed; top: 72px; left: 50%; z-index: 50;
  transform: translate(-50%, -10px); opacity: 0; pointer-events: none;
  background: var(--ink); color: var(--bg); font: 800 1rem var(--f-display);
  padding: 10px 18px; border-radius: 8px; letter-spacing: .02em;
}
@keyframes cheer { 0% { opacity: 0; transform: translate(-50%, -10px); } 12%, 82% { opacity: 1; transform: translate(-50%, 0); } 100% { opacity: 0; transform: translate(-50%, 0); } }
.cheer.show { animation: cheer 1.9s ease-out both; }
@media (prefers-reduced-motion: reduce) { .card.win { animation: none; } }
