/* The values of the page. The rules below use only these values. */
:root {
  --bg: #10141f; --card: #1a2030; --well: #10141f; --line: #2c354a; --ink: #f2f4f8; --soft: #9aa5bd;
  --accent: #a78bfa; --on-accent: #150d33; --good: #3ddc97; --bad: #ff5d73; --gold: #ffb703;
  --tile-low: #222a3d; --tile-mid: #262f45; --tile-high: #2b3550; --tile-line: #333d55;
  --tile-neg: #3a1f2b; --tile-neg-line: #6b2a3a; --tile-dbl: #3d3113; --tile-dbl-line: #ffb703;
  --tile-on: #453b80; --tile-head: #6a59c4; --tile-head-line: #ffffff;
  --num-low: #aab4ca; --num-mid: #e6eaf2; --num-high: #ffffff; --num-neg: #ff7186; --num-dbl: #ffc233; --num-on: #ffffff;
  --halo: rgba(16, 20, 31, .8); --path: #a78bfa; --can: #a78bfa; --tile-depth: none;
  --radius: 18px; --head-font: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif; --head-weight: 800;
  --sans: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --shadow: 6px 6px 0 #070a12; --digits: Impact, Haettenschweiler, 'Arial Narrow Bold', 'Helvetica Neue', sans-serif;
}

* { box-sizing: border-box; }
html { background: var(--bg); }
body { margin: 0; background: var(--bg); color: var(--ink); font: 16px/1.5 var(--sans); }
.page { max-width: 480px; margin: 0 auto; padding: 18px 16px 40px; }
.top { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 0 12px; margin-bottom: 14px; }
.top-actions { display: flex; gap: 6px; flex-shrink: 0; }
h1 { margin: 0; font: var(--head-weight) 2rem/1.1 var(--head-font); letter-spacing: -.02em; }
h1::after { content: ''; display: block; width: 44px; height: 4px; border-radius: 2px; background: var(--accent); margin-top: 6px; }
@media (max-width: 420px) { h1 { font-size: 1.7rem; } .ghost { padding: 7px 11px; font-size: .78rem; } }
.day { grid-column: 1 / -1; margin: 8px 0 0; color: var(--soft); font-size: .85rem; }
button { font: inherit; color: inherit; cursor: pointer; border-radius: 999px; border: 1px solid var(--line); background: var(--card); padding: 8px 14px; }
button:disabled { opacity: .4; cursor: default; }
.ghost { font-size: .82rem; }
.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); font-weight: 700; }
.link { border: 0; background: none; padding: 0; color: var(--accent); text-decoration: underline; font-size: .85rem; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.layout { display: grid; gap: 14px; }

.clock { display: flex; align-items: baseline; gap: 10px; }
.clock b { font: var(--head-weight) 2.3rem/1 var(--digits, var(--head-font)); font-variant-numeric: tabular-nums; letter-spacing: -.02em; }
.clock span { color: var(--soft); font-size: .9rem; }
/* Each digit of the clock has a cell of one width, so the clock does not move when a digit changes. */
.clock b i { display: inline-block; width: .57em; text-align: center; font-style: normal; }
.clock b i.sep { width: .24em; }
.clock.hurry b { color: var(--bad); animation: pulse 1s infinite; }
.clock.rest b { color: var(--soft); }
@keyframes pulse { 50% { opacity: .55; } }
.timebar { height: 6px; border-radius: 3px; background: var(--well); margin: 10px 0 12px; overflow: hidden; }
.timebar i { display: block; height: 100%; width: 100%; background: var(--accent); border-radius: 3px; transform-origin: left; transition: transform .2s linear; }
.clock.hurry + .timebar i { background: var(--bad); }
.clock.rest + .timebar i { background: var(--soft); opacity: .5; }

.board { display: block; width: 100%; height: auto; touch-action: none; user-select: none; -webkit-user-select: none; -webkit-tap-highlight-color: transparent; cursor: pointer; overflow: visible; }
.board.locked { cursor: default; }
.board .cell rect { stroke: var(--tile-line); stroke-width: 1; transition: fill .1s; filter: var(--tile-depth); }
.board .cell.low rect { fill: var(--tile-low); }
.board .cell.mid rect { fill: var(--tile-mid); }
.board .cell.high rect { fill: var(--tile-high); }
.board .cell.neg rect { fill: var(--tile-neg); stroke: var(--tile-neg-line); }
.board .cell.dbl rect { fill: var(--tile-dbl); stroke: var(--tile-dbl-line); stroke-width: 1.5; }
.board .cell.on rect { fill: var(--tile-on); stroke: var(--path); stroke-width: 1.5; }
.board .cell.can rect { stroke: var(--can); stroke-width: 2; stroke-dasharray: 5 4; }
.board .cell.head rect { fill: var(--tile-head); stroke: var(--tile-head-line); stroke-width: 3; }
.board .cell.win rect { stroke: var(--good); stroke-width: 3; }
/* Only for a mouse. On a touch screen the hover state stays on the last tapped square. */
@media (hover: hover) { .board:not(.locked) .cell:not(.on):not(.head):hover rect { stroke: var(--can); stroke-width: 2; } }
.board .cell.no { animation: no .3s; transform-box: fill-box; transform-origin: center; }
@keyframes no { 25% { transform: translateX(-4px); } 75% { transform: translateX(4px); } }
.board .labels text { font: 700 22px var(--sans); text-anchor: middle; dominant-baseline: central; pointer-events: none; paint-order: stroke; stroke: var(--halo); stroke-width: 4px; }
.board .labels .low { fill: var(--num-low); }
.board .labels .mid { fill: var(--num-mid); }
.board .labels .high { fill: var(--num-high); font-weight: 800; }
.board .labels .neg { fill: var(--num-neg); }
.board .labels .dbl { fill: var(--num-dbl); font-size: 20px; font-weight: 800; }
.board .labels .on, .board .labels .head { fill: var(--num-on); stroke: transparent; }
.board polyline { fill: none; stroke-linecap: round; stroke-linejoin: round; pointer-events: none; }
.board .path-line { stroke: var(--path); stroke-width: 9; opacity: .6; }
.board .best-line { stroke: var(--good); stroke-width: 8; opacity: .8; }
.board .start { fill: none; stroke: var(--good); stroke-width: 3; pointer-events: none; }

.under { display: flex; align-items: center; gap: 10px; margin-top: 10px; min-height: 3.4em; }
.hint { flex: 1; margin: 0; color: var(--soft); font-size: .82rem; line-height: 1.35; }

.numbers { padding: 10px; }
.scores { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; text-align: center; }
.scores div { background: var(--well); border-radius: calc(var(--radius) * .6); padding: 8px 4px; }
.scores span { display: block; color: var(--soft); font-size: .66rem; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; }
.scores b { display: block; font: var(--head-weight) 1.7rem/1.25 var(--digits, var(--head-font)); font-variant-numeric: tabular-nums; }
.scores small { display: block; color: var(--soft); font-size: .72rem; min-height: 1.4em; }
#path-score { color: var(--accent); }
#best-score.bump { animation: bump .35s; }
#top-score.good { color: var(--good); }
@keyframes bump { 40% { transform: scale(1.25); color: var(--good); } }

.verdict { margin: 12px 0 6px; text-align: center; }
.verdict .grade { font: var(--head-weight) 1.5rem/1.2 var(--head-font); min-height: 1.2em; }
.verdict .grade.hit { color: var(--good); } .verdict .grade.mid { color: var(--gold); } .verdict .grade.miss { color: var(--accent); }
.verdict p { margin: 4px 0 0; color: var(--soft); font-size: .92rem; }
.verdict p b { color: var(--ink); }

.side-head { display: flex; justify-content: space-between; align-items: baseline; border-bottom: 1px solid var(--line); padding-bottom: 8px; }
.side-head h2 { margin: 0; font-size: .8rem; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; color: var(--soft); }
.side-head span { color: var(--soft); font-size: .85rem; }
.leaders { list-style: none; margin: 0; padding: 0; }
.leaders li { display: grid; grid-template-columns: 2em 1fr auto; align-items: center; padding: 10px 6px; border-bottom: 1px solid var(--line); font-size: .95rem; }
.leaders .n { color: var(--soft); font-variant-numeric: tabular-nums; }
.leaders .who { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.leaders .s { font-weight: 700; font-variant-numeric: tabular-nums; }
.leaders li.first .s { color: var(--good); }
.leaders li.you { background: var(--well); border-radius: 8px; font-weight: 700; }
.leaders li.you .who { color: var(--accent); }
.leaders li { position: relative; }
.leaders li.flash .s { animation: flash .7s; }
.leaders li.new { animation: arrive .35s; }
@keyframes flash { 0% { transform: scale(1.5); color: var(--good); } 100% { transform: scale(1); } }
@keyframes arrive { 0% { opacity: 0; transform: translateX(12px); } }
.leaders .s { display: inline-block; transform-origin: right center; }
.leaders li.apart { margin-top: 8px; border-top: 1px dashed var(--line); }
.status { margin: 10px 0 0; color: var(--soft); font-size: .88rem; }
.status:empty { display: none; }
.me { margin-top: 14px; font-size: .9rem; }
.me p { margin: 0; }
.me form { display: flex; gap: 8px; margin-top: 8px; }
.me input { flex: 1; min-width: 0; font: inherit; font-size: 16px; color: var(--ink); background: var(--well); border: 1px solid var(--line); border-radius: 999px; padding: 8px 14px; }
.me input:focus-visible, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.me .note { color: var(--soft); font-size: .8rem; margin-top: 6px; }
.me .note:empty { display: none; }
[hidden] { display: none !important; }

.about { margin-top: 36px; padding-top: 22px; border-top: 1px solid var(--line); color: var(--soft); font-size: .92rem; }
.about h2 { font-size: 1.1rem; color: var(--ink); margin: 0 0 8px; }
.about h3 { font-size: .95rem; color: var(--ink); margin: 18px 0 6px; }
.about details { border-bottom: 1px solid var(--line); padding: 10px 0; }
.about summary { cursor: pointer; color: var(--ink); font-weight: 600; }
.about details p { margin: 8px 0 0; }
.about a { color: var(--soft); }
.about .small { margin-top: 16px; font-size: .8rem; text-align: center; }

dialog { background: var(--card); color: var(--ink); border: 1px solid var(--line); border-radius: var(--radius); max-width: 440px; width: calc(100% - 32px); padding: 20px; }
dialog::backdrop { background: rgba(0, 0, 0, .6); }
dialog h2 { margin: 0 0 8px; font-family: var(--head-font); }
dialog ol { padding-left: 20px; display: grid; gap: 6px; font-size: .95rem; }
dialog b { color: var(--accent); }
dialog form { margin-top: 14px; text-align: right; }

/* A wide screen: the list of players is beside the board. */
@media (min-width: 860px) {
  .page { max-width: 940px; padding-top: 28px; }
  .layout { grid-template-columns: minmax(0, 500px) minmax(0, 1fr); grid-template-rows: auto 1fr; align-items: start; gap: 16px 18px; }
  .play { grid-row: 1 / span 2; }
  h1 { font-size: 2.4rem; }
}
@media (prefers-reduced-motion: reduce) {
  .board .best-line { transition: none !important; }
  #best-score.bump, .clock.hurry b, .board .cell.no, .leaders li.flash .s, .leaders li.new { animation: none; }
}


/* ------------------------------------------------------------------------------------------------
   The look that Neil chose on 19/11 from seven test looks: dark tiles, large condensed numbers,
   capital labels, cards with a hard shadow, and an inverted row for the player.
   These rules refine the base rules above. ":root" in a selector makes a rule win over its base rule.
   ------------------------------------------------------------------------------------------------ */
:root .card { border: 2px solid #323c55; }
:root h1 { font: 400 2.9rem/.9 var(--digits); text-transform: uppercase; letter-spacing: .01em; }
:root h1 { justify-self: start; }
:root h1::after { width: 100%; height: 6px; border-radius: 0; margin-top: 8px; }
:root .day { text-transform: uppercase; font-size: .7rem; font-weight: 700; letter-spacing: .09em; }
:root .ghost { border-radius: 8px; border-width: 2px; text-transform: uppercase; font-weight: 700; letter-spacing: .05em; font-size: .72rem; }
:root .clock { align-items: flex-end; }
:root .clock b { font-weight: 400; font-size: 4.2rem; line-height: .82; letter-spacing: .01em; }
:root .clock span { text-transform: uppercase; font-size: .7rem; font-weight: 700; letter-spacing: .09em; padding-bottom: 3px; }
:root .timebar { height: 10px; border-radius: 0; }
:root .timebar i { border-radius: 0; }
:root .board .labels text { font: 400 27px var(--digits); letter-spacing: .02em; stroke: none; }
:root .board .labels .dbl { font-size: 24px; }
:root .scores { gap: 0; }
:root .scores div { background: none; border-radius: 0; border-left: 2px solid #323c55; text-align: left; padding: 2px 0 2px 12px; }
:root .scores div:first-child { border-left: 0; padding-left: 4px; }
:root .scores b { font-weight: 400; font-size: 2.9rem; line-height: 1; letter-spacing: .01em; }
:root .side-head { border-bottom: 2px solid #323c55; }
:root .leaders li { grid-template-columns: 2.1em 1fr auto; padding: 7px 8px; }
:root .leaders .n, :root .leaders .s { font: 400 1.65rem/1 var(--digits); letter-spacing: .02em; }
:root .leaders .n { color: var(--soft); }
:root .leaders li.you { background: var(--accent); color: var(--on-accent); border-radius: 0; border-bottom-color: var(--accent); }
:root .leaders li.you .who, :root .leaders li.you .n, :root .leaders li.you .s { color: var(--on-accent); }
:root .verdict .grade { font: 400 2.1rem/1.05 var(--digits); text-transform: uppercase; letter-spacing: .02em; }
:root dialog { border: 2px solid #323c55; box-shadow: var(--shadow); }
@media (max-width: 420px) {
  :root h1 { font-size: 1.9rem; white-space: nowrap; }
  :root .ghost { white-space: nowrap; padding: 7px 9px; font-size: .66rem; }
  :root .clock b { font-size: 3.4rem; }
  :root .scores b { font-size: 2.3rem; }
  :root .card { box-shadow: 4px 4px 0 #070a12; }
}

/* Reactions. Each one is a short animation that the page starts when a number or a place changes. */
.scores div.jolt { animation: jolt .45s; }
@keyframes jolt { 0% { transform: scale(1); } 15% { transform: scale(1.12) rotate(-2deg); } 35% { transform: scale(1.08) rotate(2deg); } 55% { transform: translateX(-4px); } 75% { transform: translateX(3px); } 100% { transform: none; } }
.board .cell.pop { animation: pop .18s; transform-box: fill-box; transform-origin: center; }
@keyframes pop { 0% { transform: scale(.8); } 60% { transform: scale(1.08); } 100% { transform: scale(1); } }
.leaders li.up { animation: up .6s; z-index: 1; }
@keyframes up { 0% { box-shadow: 0 0 0 0 var(--good); } 25% { transform: scale(1.06); box-shadow: 0 0 0 4px var(--good); } 45% { transform: scale(1.04) rotate(-1deg); } 65% { transform: scale(1.04) rotate(1deg); } 100% { transform: none; box-shadow: 0 0 0 0 transparent; } }
.leaders li.down { animation: down .5s; }
@keyframes down { 0%, 100% { transform: none; } 20% { transform: translateX(-7px); } 40% { transform: translateX(6px); } 60% { transform: translateX(-4px); } 80% { transform: translateX(3px); box-shadow: 0 0 0 3px var(--bad); } }
/* The score of the player's own row grows for a moment. It keeps its colour, because green on the row colour is hard to read. */
:root .leaders li.you.flash .s { animation-name: flash-you; }
@keyframes flash-you { 0% { transform: scale(1.5); } 100% { transform: scale(1); } }
/* The change that a square made floats up from the square. */
.board text.float { font: 400 20px var(--digits); text-anchor: middle; dominant-baseline: central; pointer-events: none; paint-order: stroke; stroke: var(--bg); stroke-width: 5px; animation: float .75s ease-out forwards; }
.board text.float.pos { fill: var(--good); } .board text.float.neg { fill: var(--bad); } .board text.float.dbl { fill: var(--gold); font-size: 24px; }
@keyframes float { 0% { opacity: 0; transform: translateY(6px); } 20% { opacity: 1; } 70% { opacity: 1; } 100% { opacity: 0; transform: translateY(-16px); } }
/* On the line of the best path each number is white with a dark edge, so that the line does not hide it. */
:root .board .labels text.win { paint-order: stroke; stroke: #0c2a20; stroke-width: 5px; }
:root .board .labels text.win.low, :root .board .labels text.win.mid { fill: #ffffff; }
/* After a round the top three are under the result. The full list then starts at the fourth place, so no name shows two times. */
.leaders.topped li:nth-child(-n+3) { display: none; }
.leaders.leaving li:nth-child(-n+3) { overflow: hidden; animation: leave .42s ease-in forwards; }
@keyframes leave { 0% { opacity: 1; max-height: 60px; } 50% { opacity: 0; max-height: 60px; } 100% { opacity: 0; max-height: 0; padding-top: 0; padding-bottom: 0; border-width: 0; } }
/* With no fourth place the list has no row, so its heading and the list are hidden. The name of the player stays. */
.side:has(.leaders.topped):not(:has(.leaders li:nth-child(4))) :is(.side-head, .leaders) { display: none; }
.side:has(.leaders.topped):not(:has(.leaders li:nth-child(4))) .me { margin-top: 0; }
@media (prefers-reduced-motion: reduce) { .leaders.leaving li:nth-child(-n+3) { animation: none; display: none; } }
/* The top three players of a round. They arrive in turn: third, second, first. */
.podium { margin-top: 12px; border-top: 2px solid #323c55; padding-top: 10px; }
.podium h2 { margin: 0 0 6px; font-size: .7rem; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; color: var(--soft); }
.podium ol { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; }
.podium li { display: grid; grid-template-columns: 2.1em 1fr auto; align-items: center; padding: 6px 8px; background: var(--well); animation: step .45s cubic-bezier(.2, .9, .3, 1.3) both; animation-delay: calc(var(--turn) * 380ms); }
.podium .n, .podium .s { font: 400 1.5rem/1 var(--digits); letter-spacing: .02em; }
.podium .who { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 700; }
.podium li.p1 { background: var(--gold); color: #231a00; padding: 9px 8px; }
.podium li.p1 .n, .podium li.p1 .s { font-size: 1.9rem; }
.podium li.p2 .n { color: #d5dbe8; } .podium li.p3 .n { color: #d39a6a; }
.podium li.you:not(.p1) { box-shadow: inset 0 0 0 2px var(--accent); }
@keyframes step { 0% { opacity: 0; transform: translateX(-18px) scale(.94); } }
/* A perfect score: the squares of the best path jump in turn and the word shines. */
.board .cell.cheer, .board .labels text.cheer { animation: cheer .5s ease-out 2 both; animation-delay: calc(var(--i) * 70ms); transform-box: fill-box; transform-origin: center; }
.board .cell.cheer rect { stroke: var(--gold); stroke-width: 4; fill: #4a3a10; }
@keyframes cheer { 0% { transform: none; } 40% { transform: translateY(-7px) scale(1.12); } 100% { transform: none; } }
:root .verdict .grade.perfect { color: var(--gold); animation: shine 1.2s ease-out; }
@keyframes shine { 0% { transform: scale(.6); opacity: 0; } 30% { transform: scale(1.35) rotate(-3deg); opacity: 1; } 50% { transform: scale(1.2) rotate(3deg); } 100% { transform: none; } }
@media (prefers-reduced-motion: reduce) { .podium li, .board .cell.cheer, .board .labels text.cheer, :root .verdict .grade.perfect { animation: none; } }
/* The squares of a new board arrive in a wave. */
.board.deal .cell, .board.deal .labels text { animation: deal .3s cubic-bezier(.2, .9, .3, 1.3) both; animation-delay: calc(var(--i) * 32ms); transform-box: fill-box; transform-origin: center; }
@keyframes deal { 0% { opacity: 0; transform: scale(.55); } }
@media (prefers-reduced-motion: reduce) { .scores div.jolt, .board .cell.pop, .leaders li.up, .leaders li.down, .board.deal .cell, .board.deal .labels text { animation: none; } }

/* The lesson for a new player. */
#lesson { max-width: 400px; }
.lesson-say { min-height: 4.6em; margin: 0 0 10px; font-size: 1rem; line-height: 1.45; }
.lesson-play { display: grid; grid-template-columns: minmax(0, 190px) 1fr; gap: 16px; align-items: center; }
.lesson-total { text-align: center; }
.lesson-total span { display: block; color: var(--soft); font-size: .7rem; font-weight: 700; letter-spacing: .09em; text-transform: uppercase; }
.lesson-total b { display: block; font: 400 4rem/1 var(--digits); color: var(--accent); font-variant-numeric: tabular-nums; }
.lesson-total b.bump { animation: bump .35s; }
.lesson-foot { display: flex; justify-content: space-between; align-items: center; margin-top: 14px; }
.lesson-foot form { margin: 0; }
.lesson-dots { display: flex; gap: 6px; }
.lesson-dots i { width: 9px; height: 9px; border-radius: 50%; background: var(--line); }
.lesson-dots i.done { background: var(--accent); }
/* The square to tap next has a ring that grows and fades. */
.board .cell.want rect { stroke: #ffffff; stroke-width: 3; animation: want 1s ease-in-out infinite; }
@keyframes want { 50% { stroke: var(--accent); stroke-width: 5; } }
dialog form { display: flex; gap: 8px; justify-content: flex-end; }
@media (prefers-reduced-motion: reduce) { .board .cell.want rect, .lesson-total b.bump { animation: none; } }

/* The number of squares in the path, beside the clock. It goes gold when the path is full. */
:root .clock > b { white-space: nowrap; flex-shrink: 0; }
.count { margin-left: auto; text-align: right; white-space: nowrap; }
:root .clock .count b { font-size: 2.5rem; line-height: .85; color: var(--accent); display: inline-block; min-width: .6em; }
.count em { font: 400 1.25rem/1 var(--digits); font-style: normal; color: var(--soft); margin-left: 2px; }
:root .clock .count span { display: block; padding: 4px 0 0; font-size: .6rem; }
:root .clock.hurry .count b { color: var(--accent); animation: none; }
:root .clock .count.full b, .count.full em, :root .clock .count.full span { color: var(--gold); }
.clock.rest .count { visibility: hidden; }
.count.full { animation: jolt .45s; }
@media (prefers-reduced-motion: reduce) { .count.full { animation: none; } }

/* A phone zooms the page on a fast double tap, and this game has many fast taps.
   "manipulation" stops the double-tap zoom. A zoom with two fingers and a scroll still work. */
html, body, body * { touch-action: manipulation; }
/* In the card of the board a drag up or down scrolls the page, and two fingers do not zoom. */
.play, .play * { touch-action: pan-y; }
.board, .board * { touch-action: none; }
/* The page has one look, and it is dark. This tells a browser with a night mode not to change the colours. */
:root { color-scheme: dark; }
