:root {
  /* Brand colours, taken from a white plastic shape-sorter cube with red, blue and green straps. */
  --red: #de4e1c;
  --blue: #1c9cc4;
  --green: #6ba02a;
  --bg: #eef1ec;
  --surface: #f9faf8;
  --paper: #ffffff;
  --ink: #22262a;
  --muted: #6e757b;
  --grid: #d5dad3;
  --accent: #de4e1c;
  --primary: #0f7193;
  --primary-ink: #ffffff;
  /* The strap red, a shade deeper so white words read on it: Close, Sign out and anything that removes. */
  --orange: #c8420f;
  --orange-ink: #ffffff;
  --good: #5c9122;
  --gap: #d3d8d2;
  --bad: #de4e1c;
  /* Premium's own colour: the sunshine yellow of a toy block, kept for buying Premium and nothing else. */
  --gold: #f7b614;
  --gold-hi: #ffdc63;
  --gold-edge: #b97700;
  --gold-ink: #3a2400;
  --gold-text: #8a5800;
  --shadow: 0 2px 0 rgba(34, 38, 42, 0.12), 0 8px 24px rgba(34, 38, 42, 0.08);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #16191c;
    --surface: #1e2126;
    --paper: #262a30;
    --ink: #f4f6f2;
    --muted: #9aa1a6;
    --grid: #40464d;
    --accent: #f0653a;
    --primary: #1c9cc4;
    --primary-ink: #10171b;
    --orange: #f0653a;
    --orange-ink: #1f0d05;
    --good: #7db83a;
    --gap: #4a5057;
    --bad: #f0653a;
    --gold-edge: #ffe9a3;
    --gold-text: #ffd257;
    --shadow: 0 2px 0 rgba(0, 0, 0, 0.3), 0 8px 24px rgba(0, 0, 0, 0.3);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.45 ui-rounded, "SF Pro Rounded", "Nunito", system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-tap-highlight-color: transparent;
}

.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  max-width: 480px;
  margin: 0 auto;
  padding: 12px 16px 4px;
}
.brand { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
h1 { font-size: 1.35rem; margin: 0; letter-spacing: -0.01em; }
.logo { display: inline-flex; color: var(--ink); }
.logo svg { display: block; height: 24px; width: auto; }
.chip {
  font-size: 0.8rem;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--surface);
  box-shadow: var(--shadow);
}
.icon-btn {
  width: 36px; height: 36px;
  border-radius: 50%;
  border: 0;
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-weight: 800;
  box-shadow: var(--shadow);
  cursor: pointer;
}

main { max-width: 480px; margin: 0 auto; padding: 0 16px 40px; }

.modes { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; margin: 6px 0 0; padding: 4px; border-radius: 16px; background: var(--surface); box-shadow: var(--shadow); }
.modes button { font: inherit; font-size: 0.85rem; white-space: nowrap; font-weight: 700; min-height: 40px; padding: 0 2px; border: 0; border-radius: 12px; background: none; color: var(--muted); cursor: pointer; }
.modes button[aria-pressed="true"] { background: var(--primary); color: var(--primary-ink); }
.modes button:disabled { opacity: 0.5; cursor: default; }

.prompt { min-height: 1.5em; margin: 6px 0 10px; text-align: center; font-weight: 700; font-size: 1.05rem; }

.stage {
  position: relative;
  width: min(100%, max(280px, 100svh - var(--chrome, 345px)));
  aspect-ratio: 1;
  margin: 0 auto;
  border-radius: 22px;
  overflow: hidden;
  background: var(--paper);
  box-shadow: var(--shadow);
}
#board, .three, .three canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
#board { touch-action: none; cursor: crosshair; }
[hidden] { display: none !important; }
.three { background: radial-gradient(circle at 50% 30%, var(--surface), var(--bg)); }

.intro {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 12px 24px;
  text-align: center;
  background: color-mix(in srgb, var(--paper) 88%, transparent);
}
.intro h2 { margin: 0 0 6px; font-size: 1.6rem; }
.intro p { margin: 0 0 8px; max-width: 30ch; }
/* Under a series' number: its date, a little smaller, then where the player is in it. */
.intro .intro-when { margin: -6px 0 0; color: var(--muted); font-size: 0.85rem; font-weight: 700; }
.intro .intro-step { margin: 0 0 6px; font-size: 1.15rem; font-weight: 800; }
.note { color: var(--muted); font-size: 0.9rem; }
.intro-panel { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.link.small { min-height: 0; padding: 0 0 0 8px; font-size: inherit; }
.link { font: inherit; font-weight: 700; min-height: 40px; padding: 6px 12px; border: 0; background: none; color: var(--primary); text-decoration: underline; text-underline-offset: 3px; cursor: pointer; }

.practice-picks { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; width: 100%; max-width: 340px; margin: 6px auto; }
.practice-picks .btn { display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 12px 4px 10px; font-size: 0.95rem; }
.glyph { display: block; width: 26px; height: 26px; background: var(--red); }
.glyph.circle { border-radius: 50%; }
.glyph.square { background: var(--blue); border-radius: 3px; }
.glyph.triangle { background: var(--green); clip-path: polygon(50% 4%, 100% 96%, 0 96%); }

.banner {
  position: absolute;
  top: 14px;
  left: 50%;
  transform: translateX(-50%);
  padding: 8px 18px;
  border-radius: 999px;
  color: #fff;
  font-weight: 800;
  font-size: 1.3rem;
  white-space: nowrap;
  animation: pop 0.35s cubic-bezier(0.2, 1.6, 0.4, 1);
  box-shadow: var(--shadow);
}
.banner.good { background: var(--good); }
.banner.bad { background: var(--bad); }
@keyframes pop { from { transform: translateX(-50%) scale(0.4); opacity: 0; } }

.btn {
  font: inherit;
  font-weight: 700;
  border: 0;
  border-radius: 14px;
  padding: 12px 18px;
  min-height: 48px;
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: transform 0.08s;
}
.btn:active:not(:disabled) { transform: translateY(2px); }
.btn:disabled { opacity: 0.4; cursor: default; }
.btn.primary { background: var(--primary); color: var(--primary-ink); }
/* Go on to the next shape: green, beside a blue Retry. */
.btn.go { background: var(--good); color: var(--primary-ink); }
.btn.big { font-size: 1.1rem; padding: 14px 24px; margin-top: 8px; white-space: nowrap; }
/* Ways out, in orange: a popup's Close is filled; Sign out and the links that remove something are
   outlined or plain, so they aren't mistaken for Close. */
.btn.leave, .icon-btn.leave { background: var(--orange); color: var(--orange-ink); }
.btn.leave.quiet { background: var(--paper); color: var(--orange); box-shadow: inset 0 0 0 2px var(--orange), var(--shadow); }
.link.leave { color: var(--orange); }
/* The cross in a popup's upper right. It stays in that corner while a long popup scrolls (sticky
   offsets count from inside the popup's padding, hence the negative top). */
.popup-x { position: sticky; top: -6px; float: right; z-index: 1; margin: -6px -6px 0 10px; }

/* Buying Premium: gold with a lit top edge, a ring around it and a sheen that crosses it every few
   seconds. The sheen is a still gloss for anyone who has asked for less motion. */
.btn.premium {
  position: relative;
  isolation: isolate;
  overflow: hidden;
  background: linear-gradient(180deg, var(--gold-hi), var(--gold) 62%);
  color: var(--gold-ink);
  font-weight: 800;
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.65),
    inset 0 -2px 0 rgba(122, 76, 0, 0.22),
    0 0 0 2px var(--gold-edge),
    0 3px 0 2px rgba(122, 76, 0, 0.35),
    0 8px 22px color-mix(in srgb, var(--gold) 50%, transparent);
}
.btn.premium::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(105deg, transparent 36%, #fff 50%, transparent 64%);
  mix-blend-mode: overlay;  /* lights the gold and leaves the words dark */
  transform: translateX(-110%);
  animation: sheen 3.6s ease-in-out 0.6s infinite;
  pointer-events: none;
}
.btn.premium:disabled::after { animation: none; }
@keyframes sheen { 0%, 60% { transform: translateX(-110%); } 100% { transform: translateX(110%); } }
@media (prefers-reduced-motion: reduce) {
  .btn.premium::after { animation: none; transform: none; background: linear-gradient(105deg, transparent 20%, rgba(255, 255, 255, 0.6) 34%, transparent 48%); }
}

.controls { display: grid; grid-template-columns: repeat(3, 1fr); grid-template-areas: "undo reset peek" "drop drop drop"; gap: 10px; margin-top: 14px; }
#undo { grid-area: undo; }
#reset { grid-area: reset; }
#peek { grid-area: peek; padding-inline: 6px; font-size: 0.95rem; white-space: nowrap; }
#drop { grid-area: drop; }

.timer { display: flex; align-items: center; gap: 10px; margin-top: 14px; }
.timer-track { flex: 1; height: 12px; border-radius: 999px; background: var(--surface); overflow: hidden; box-shadow: var(--shadow); }
.timer-fill { height: 100%; background: var(--accent); transform-origin: left; }
.timer-label { font-weight: 800; font-size: 1.3rem; width: 1.5ch; text-align: center; }

.result {
  margin-top: 18px;
  padding: 18px;
  border-radius: 22px;
  background: var(--surface);
  box-shadow: var(--shadow);
  scroll-margin-top: 12px;
}
.result h2 { margin: 0 0 10px; font-size: 1.5rem; }
.result.good #verdict { color: var(--good); }
.result.bad #verdict { color: var(--bad); }
.score-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.score { display: flex; flex-direction: column; align-items: center; padding: 10px 4px; border-radius: 16px; background: var(--paper); }
.detail { margin: 10px 0 0; }
.detail:empty { display: none; }
.score b { font-size: 2.4rem; line-height: 1.1; font-variant-numeric: tabular-nums; }
.score b.landed { animation: land 0.4s cubic-bezier(0.2, 1.6, 0.4, 1); }
@keyframes land { from { transform: scale(1.35); color: var(--good); } }
.score span { color: var(--muted); font-size: 0.85rem; }
.reveal { font-weight: 700; margin: 14px 0 8px; }
/* After a miss, Retry sits right beside the reveal, where the eye lands, not down past the boards. */
.result-meta { display: flex; align-items: center; gap: 12px; }
.result-meta-text { flex: 1; min-width: 0; }
#jam-retry { flex: none; min-height: 56px; padding: 10px 26px; font-size: 1.1rem; margin: 6px 0 0; }
.compare { display: block; width: 100%; aspect-ratio: 1; border-radius: 16px; }
.legend { display: flex; gap: 16px; list-style: none; padding: 0; margin: 8px 0 14px; font-size: 0.9rem; color: var(--muted); }
.legend li { display: flex; align-items: center; gap: 6px; }
.sw { width: 14px; height: 14px; border-radius: 4px; display: inline-block; }
.sw.good { background: var(--good); }
.sw.gap { background: var(--gap); }
.sw.bad { background: var(--bad); }
/* The two share buttons, straight under the score: the replay first, as it is what people post. */
.share-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 12px; }
.share-row .btn { display: flex; align-items: center; justify-content: center; gap: 8px; min-width: 0; min-height: 60px; padding: 8px 10px; text-align: left; }
.share-row .btn:not(.primary) { background: var(--paper); }
.share-row .btn svg { flex: none; fill: currentColor; }
.share-row .btn span { display: grid; min-width: 0; line-height: 1.15; }
.share-row .btn b { font-size: 1.05rem; white-space: nowrap; }
.share-row .btn small { font-size: 0.75rem; font-weight: 400; opacity: 0.85; white-space: nowrap; }
@media (max-width: 360px) { .share-row .btn svg { display: none; } }
.series { display: grid; gap: 10px; }
.series-chips { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; list-style: none; margin: 0; padding: 0; }
.series-chips li { padding: 8px 0; border-radius: 12px; background: var(--paper); border: 2px solid var(--grid); text-align: center; font-weight: 800; font-size: 0.85rem; font-variant-numeric: tabular-nums; color: var(--muted); }
.series-chips li.good { border-color: var(--good); color: var(--good); }
.series-chips li.bad { border-color: var(--bad); color: var(--bad); }

/* A finished series as a whole, at the top of the result (main.js showSeriesWhole): the total, a
   tile per shape that opens it on its own, then sharing the series and watching it again. */
.series-done { display: grid; gap: 4px; text-align: center; }
.series-done-kicker { justify-self: center; margin: 0; padding: 2px 10px; border-radius: 999px; background: var(--good); color: var(--paper); font-size: 0.8rem; font-weight: 800; }
.series-done h2 { margin: 4px 0 0; font-size: 1.5rem; }
.series-done > .note { margin: 0; }
.series-done-sum { display: grid; margin: 8px 0 0; }
.series-done-sum b { font-size: 3rem; line-height: 1; font-variant-numeric: tabular-nums; }
.series-done-sum span { color: var(--muted); }
.series-done-verdict { margin: 6px 0 0; font-weight: 800; font-size: 1.15rem; color: var(--good); }
.series-done-where { margin: 0; font-weight: 800; color: var(--good); }
.series-done-where:empty { display: none; }
.series-done-tiles { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 6px; list-style: none; margin: 10px 0 6px; padding: 0; }
.series-done-tiles button { display: grid; gap: 2px; width: 100%; padding: 4px 4px 6px; border: 0; border-radius: 14px; background: var(--paper); color: var(--ink); font: inherit; cursor: pointer; box-shadow: inset 0 0 0 2px var(--good); }
.series-done-tiles button.bad { box-shadow: inset 0 0 0 2px var(--bad); }
.series-done-tiles button:hover, .series-done-tiles button:focus-visible { box-shadow: inset 0 0 0 3px var(--primary); }
.series-done-tiles button[aria-pressed="true"] { background: var(--primary); color: var(--primary-ink); box-shadow: inset 0 0 0 3px var(--primary); }
.series-done-tiles canvas { display: block; width: 100%; aspect-ratio: 1; border-radius: 10px; }
.series-done-tiles b { font-size: 0.72rem; line-height: 1.2; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.series-done-tiles span { font-size: 0.75rem; font-weight: 700; color: var(--muted); font-variant-numeric: tabular-nums; }
.series-done-tiles button.bad span { color: var(--bad); }
.series-done-tiles button[aria-pressed="true"] span { color: inherit; }
/* Sharing the series is the big button, as the replay is under a single round. */
.series-share { display: flex; align-items: center; justify-content: center; gap: 10px; width: 100%; min-height: 64px; margin-top: 8px; text-align: left; }
.series-share svg { flex: none; fill: currentColor; }
.series-share span { display: grid; line-height: 1.15; }
.series-share b { font-size: 1.15rem; }
.series-share small { font-size: 0.8rem; font-weight: 400; opacity: 0.85; }
.series-done-links { display: flex; flex-wrap: wrap; justify-content: center; gap: 0 18px; margin: 4px 0 0; }
.series-done-links .link.small { min-height: 40px; }
/* The stage's panel on a finished series: watching is its main button, sharing the next. */
.done-share { display: inline-flex; align-items: center; justify-content: center; gap: 8px; }
.done-share svg { flex: none; fill: currentColor; }
/* The stage's own invitation to watch a finished series sits on a plain board, with no dot to draw around. */
.intro:has(> #intro-done:not([hidden])) { background: var(--paper); }
/* One shape picked from it: its own result follows the summary, under a line. */
.series-done:not([hidden]) + #shape-result { margin-top: 18px; padding-top: 14px; border-top: 2px solid var(--grid); }
.shape-result-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
.shape-result-head b { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); }
.shape-result-head .link.small { flex: none; min-height: 40px; }
/* The series' drops playing again: which shape, along the bottom of the stage, and Stop. */
.watch-bar { position: absolute; left: 10px; right: 10px; bottom: 10px; display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 6px 6px 6px 14px; border-radius: 999px; background: color-mix(in srgb, var(--paper) 92%, transparent); box-shadow: var(--shadow); font-weight: 800; }
.watch-bar span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.watch-stop { flex: none; min-height: 36px; padding: 0 14px; border: 0; border-radius: 999px; background: var(--orange); color: var(--orange-ink); font: inherit; font-weight: 800; cursor: pointer; }
a.btn { display: grid; place-items: center; text-decoration: none; }
.tools .note { margin: 0; }
.tools.trio { grid-template-columns: repeat(3, 1fr); }
.tools.trio .btn { padding-inline: 6px; white-space: nowrap; }
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin: 16px 0 0; text-align: center; }
.stats dt { font-size: 0.75rem; color: var(--muted); }
.stats dd { margin: 0; font-size: 1.4rem; font-weight: 800; }
.next { text-align: center; color: var(--muted); margin: 14px 0 0; }
.tools { margin-top: 16px; padding-top: 14px; border-top: 2px dashed var(--grid); display: grid; gap: 10px; }
.tools .practice-picks { max-width: none; margin: 0; }
.tools-label { margin: 0; font-weight: 700; }
.picker {
  display: grid;
  grid-template-columns: auto 44px 1fr 44px;
  gap: 8px;
  margin: 8px 0 0;
  padding: 0;
  border: 0;
  min-width: 0;
}
.picker .btn { min-height: 44px; padding: 0 12px; }
#prev-shape, #next-shape-bar { font-size: 1.5rem; line-height: 1; padding: 0; }
.picker select { min-height: 44px; min-width: 0; }
select {
  font: inherit;
  min-height: 48px;
  padding: 0 12px;
  border-radius: 14px;
  border: 2px solid var(--grid);
  background: var(--paper);
  color: var(--ink);
}

.help {
  max-width: min(420px, calc(100vw - 32px));
  border: 0;
  border-radius: 22px;
  padding: 20px;
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow);
}
.help::backdrop { background: rgba(0, 0, 0, 0.4); }
.help h2 { margin-top: 0; }
.help ol { padding-left: 1.2em; }
.help li { margin-bottom: 8px; }

body:has(.picker:not([hidden])) { --chrome: 400px; }
.help a { color: var(--primary); }

/* All shapes: while the gallery is open it takes the place of the board. */
body[data-view="gallery"] :is(.prompt, .stage, .timer, .controls, .result) { display: none; }
.gallery-view { margin-top: 12px; }
.gallery-intro { color: var(--muted); margin: 0 0 10px; }
.filters { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 14px; }
.filters button { font: inherit; font-size: 0.85rem; font-weight: 700; border: 0; border-radius: 999px; padding: 6px 12px; background: var(--surface); color: var(--ink); box-shadow: var(--shadow); cursor: pointer; }
.filters button[aria-pressed="true"] { background: var(--primary); color: var(--primary-ink); }
.gallery { list-style: none; padding: 0; margin: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); gap: 10px; }
.gallery li button { display: block; width: 100%; font: inherit; padding: 8px 6px 10px; border: 0; border-radius: 16px; background: var(--surface); box-shadow: var(--shadow); color: var(--ink); text-align: center; cursor: pointer; }
.gallery svg { display: block; width: 100%; aspect-ratio: 1; }
.gallery .day { display: block; font-size: 0.7rem; color: var(--muted); }
.gallery .name { display: block; font-size: 0.85rem; font-weight: 700; line-height: 1.2; min-height: 2.4em; }
.help { max-height: calc(100svh - 32px); overflow: auto; }
.help h3 { margin: 14px 0 4px; font-size: 1rem; }
.help ul { padding-left: 1.2em; margin: 0 0 12px; }

.top-buttons { display: flex; gap: 8px; }
.icon-btn svg { display: block; margin: auto; fill: currentColor; }
/* A leaderboard: rank, username, then the number it is ranked by with a smaller detail under it. */
.board { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; font-weight: 700; font-size: 0.95rem; }
.board:empty { display: none; }
.board li { display: grid; grid-template-columns: 1.7em minmax(0, 1fr) auto; gap: 6px; align-items: baseline; margin: 0; padding: 6px 10px; border-radius: 10px; }
.board .rank { color: var(--muted); font-variant-numeric: tabular-nums; }
.board .who { display: flex; flex-wrap: wrap; column-gap: 6px; overflow-wrap: anywhere; }
.board .tag { font-weight: 400; }
.board .val { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; line-height: 1.2; }
.board .sub { display: block; color: var(--muted); font-weight: 400; font-size: 0.8rem; }
.board li.you { background: var(--paper); box-shadow: inset 0 0 0 2px var(--primary); color: var(--primary); }
/* A friend's row: a bar down its side and the word, so it never rests on colour alone. */
.board li.friend { box-shadow: inset 4px 0 0 var(--good); background: var(--paper); }
.board .mark { align-self: center; padding: 0 7px; border: 1.5px solid var(--good); border-radius: 999px; color: var(--good); font-size: 0.7rem; font-weight: 800; line-height: 1.5; }
/* An all-time record's trophy under the place: a line high, inside the place's column so it never widens the row, held still. */
.board .record { display: block; margin-top: 2px; line-height: 0; }
.board .record svg { width: 1.15em; height: 1.15em; }
.board .record .glint { animation: none; transform: translateX(-16%); opacity: 0.6; }
.board .record .spark { animation: none; }
.board li.more { display: block; padding: 0 10px; color: var(--muted); text-align: center; line-height: 1; }
.standing { margin: 0; font-size: 1.15rem; font-weight: 800; color: var(--good); }
.standing:empty, .tools .note:empty { display: none; }

.tools .filters { margin: 0; }
.tools-label:empty, #drawn:empty { display: none; }
#drawn { margin: 6px 0 0; }
/* The leaderboards: a page of their own over the game, not a popup. The tabs and filters stay at
   the top, the list scrolls, and the player's own row stays pinned to the bottom edge. */
.boards { position: fixed; inset: 0; width: 100vw; max-width: 100vw; height: 100dvh; max-height: 100dvh; margin: 0; padding: 0; border: 0; overflow: hidden; background: var(--bg); color: var(--ink); }
.boards::backdrop { background: var(--bg); }
.boards-page { display: grid; grid-template-rows: auto auto minmax(0, 1fr) auto; width: min(100%, 560px); height: 100%; margin: 0 auto; }
.boards-top { display: flex; align-items: center; gap: 12px; padding: calc(12px + env(safe-area-inset-top, 0px)) 16px 10px; }
.boards-top h2 { margin: 0; font-size: 1.4rem; }
.boards-top .icon-btn { flex: none; width: 44px; height: 44px; display: grid; place-items: center; cursor: pointer; }
.boards-controls { display: grid; gap: 10px; padding: 0 16px 10px; }
.boards-controls .switch { margin: 0; background: var(--surface); box-shadow: var(--shadow); }
.switch.four { grid-template-columns: repeat(4, 1fr); }
.switch.four button { font-size: 0.95rem; padding: 0 2px; }
.switch.five { grid-template-columns: repeat(5, 1fr); gap: 2px; }
.switch.five button { font-size: 0.85rem; padding: 0; }
.boards-pick { flex: 1; flex-wrap: nowrap; }
.boards-pick select { flex: 1; min-width: 0; min-height: 44px; }
#boards-play { flex: none; min-height: 44px; padding: 8px 18px; white-space: nowrap; }
.player-list li.go { cursor: pointer; }
.player-go { flex: none; color: var(--muted); }
.boards-filters { display: flex; flex-wrap: wrap; gap: 6px 16px; }
.boards-filters:not(:has(.filters:not([hidden]))) { display: none; }
.boards .filters { margin: 0; }
.boards .note { margin: 0; }
.boards .note:empty { display: none; }
.boards-scroll { display: grid; align-content: start; gap: 10px; overflow: auto; overscroll-behavior: contain; padding: 2px 16px 20px; }
.boards .board { gap: 6px; font-size: 1rem; }
.boards .board li { padding: 9px 14px; border-radius: 14px; background: var(--surface); }
.boards .board li.you { background: var(--paper); }
.boards .board li.more { background: none; }
.boards .board .rank { font-weight: 800; }
.boards-scroll .board li:nth-child(1) .rank { color: var(--gold-text); }
.boards-me { padding: 10px 16px calc(10px + env(safe-area-inset-bottom, 0px)); border-top: 2px dashed var(--grid); background: var(--surface); box-shadow: 0 -6px 18px rgba(34, 38, 42, 0.08); }
@media (min-width: 592px) { .boards-me { margin: 0 16px 16px; padding: 10px; border: 0; border-radius: 18px; box-shadow: var(--shadow); } }
/* The player's own page (js/player.js): the same full page as the leaderboards, all of it scrolling. */
.player-page { grid-template-rows: auto minmax(0, 1fr); }
.boards-player { margin-left: auto; min-height: 44px; padding: 8px 14px; }
.player-body { display: grid; gap: 16px; }
.player-body h3 { margin: 0; font-size: 1.05rem; }
.player-who { display: flex; align-items: center; gap: 14px; }
.player-who div { display: grid; min-width: 0; }
.player-who b { font-size: 1.5rem; line-height: 1.15; letter-spacing: -0.01em; overflow-wrap: anywhere; }
.player-face { flex: none; width: 64px; height: 64px; border-radius: 14px; overflow: hidden; box-shadow: 0 0 0 2px var(--grid); }
.player-face svg { display: block; width: 100%; height: 100%; }
.player-part { display: grid; gap: 10px; padding: 14px; border-radius: 22px; background: var(--surface); box-shadow: var(--shadow); }
.player-part .note { margin: 0; }
.player-part .note:empty { display: none; }
.player-shelf { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; text-align: center; }
.player-shelf li { display: grid; justify-items: center; padding: 12px 4px; border-radius: 16px; background: var(--paper); }
.player-shelf b { font-size: 1.5rem; line-height: 1.1; font-variant-numeric: tabular-nums; }
.player-shelf span:last-child { font-size: 0.85rem; font-weight: 700; }
.player-token { display: block; width: 72px; height: 72px; color: var(--ink); }
.player-token.small { flex: none; width: 44px; height: 44px; }
.player-token svg, .player-badge svg { display: block; width: 100%; height: 100%; }
.player-token text, .player-badge text { font-family: inherit; }
.player-stats { grid-template-columns: repeat(3, 1fr); margin: 0; }
.player-stats div { padding: 10px 4px; border-radius: 16px; background: var(--surface); box-shadow: var(--shadow); }
.player-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.player-list:empty { display: none; }
.player-list li { position: relative; display: flex; align-items: center; gap: 10px; padding: 10px; border-radius: 14px; background: var(--paper); }
.player-list li.new { box-shadow: inset 0 0 0 2px var(--primary); }
/* What is new wears its tag on the row's top edge, so the words under it keep their full width. */
.player-list li > .new-tag { position: absolute; top: -9px; right: 12px; margin: 0; }
.player-share-one { flex: none; width: 44px; height: 44px; display: grid; place-items: center; background: var(--surface); cursor: pointer; }
.player-what { flex: 1; min-width: 0; display: grid; }
.player-what b { font-size: 0.95rem; line-height: 1.25; }
.player-what span { font-size: 0.875rem; }
.player-badge { flex: none; display: block; width: 44px; height: 44px; }
.player-list.locked li { background: none; box-shadow: inset 0 0 0 2px var(--grid); }
.player-list.locked .player-badge { filter: grayscale(1); opacity: 0.45; }
.new-tag { display: inline-block; margin-left: 8px; padding: 0 7px; border-radius: 999px; background: var(--primary); color: var(--primary-ink); font-size: 0.7rem; font-weight: 800; line-height: 1.6; vertical-align: middle; }
.stats-more { margin: 8px 0 0; text-align: center; }
.stats-more:not(:has(button:not([hidden]))) { display: none; }
#account-open { position: relative; }
.help form, .account-me { display: grid; gap: 10px; margin-bottom: 12px; }
.help label { display: grid; gap: 4px; font-weight: 700; font-size: 0.9rem; }
.help label.check { display: flex; gap: 8px; align-items: flex-start; font-weight: 400; font-size: 1rem; }
.help input:not([type="checkbox"]) { font: inherit; min-height: 44px; padding: 4px 10px; border-radius: 12px; border: 2px solid var(--grid); background: var(--paper); color: var(--ink); }
.help p { margin: 0; }
.tools.two { grid-template-columns: 1fr 1fr; }
@media (max-height: 700px) {
  .intro h2 { font-size: 1.35rem; margin-bottom: 2px; }
  .intro p { font-size: 0.9rem; margin-bottom: 6px; }
  .intro .intro-when { margin-top: -2px; font-size: 0.8rem; }
  .intro .intro-step { margin-bottom: 4px; font-size: 1rem; }
  .intro-panel { gap: 2px; }
  .btn.big { padding: 10px 16px; margin-top: 4px; }
}
.gallery-intro a { color: var(--primary); }

/* The account dialog: Create account / Sign in, then the ways each offers. */
.account { width: min(420px, calc(100vw - 32px)); }
.switch { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; margin-bottom: 12px; padding: 4px; border-radius: 16px; background: var(--paper); }
.switch button { font: inherit; font-weight: 700; white-space: nowrap; padding: 0 4px; min-height: 44px; border: 0; border-radius: 12px; background: none; color: var(--muted); cursor: pointer; }
.switch button[aria-pressed="true"] { background: var(--primary); color: var(--primary-ink); }
.help form.account-form, .account-form { display: grid; gap: 10px; margin-bottom: 12px; }
.account-form .link { justify-self: center; min-height: 44px; }
.account .or { color: var(--muted); font-size: 0.9rem; text-align: center; }
.account .hint { font-weight: 400; color: var(--muted); }
.account .note.error { color: var(--bad); }
.account .note:empty { display: none; }
.account .welcome { font-weight: 800; color: var(--good); }
.premium-tag { justify-self: start; padding: 1px 10px; border-radius: 999px; border: 1.5px solid currentColor; background: color-mix(in srgb, var(--gold) 16%, transparent); color: var(--gold-text); font-size: 0.8rem; font-weight: 800; letter-spacing: 0.04em; text-transform: uppercase; }
.account h3 { margin: 6px 0 0; font-size: 1rem; }
/* Plain buttons in the account, friends and invite popups: the popup is the same colour as a plain
   button, so give them a white face and a blue outline to read as buttons at a glance. */
.account .btn:not(.primary, .premium, .leave, .google) { background: var(--paper); color: var(--primary); box-shadow: inset 0 0 0 2px var(--primary), var(--shadow); }
.account .btn:not(.primary, .premium, .leave, .google):hover { background: color-mix(in srgb, var(--primary) 8%, var(--paper)); }
.account .btn:focus-visible, .account .link:focus-visible { outline: 3px solid var(--primary); outline-offset: 2px; }
/* A button that opens another page of the popup: label on the left, a chevron on the right. */
.account .btn.more { display: flex; justify-content: space-between; align-items: center; text-align: left; }
.account .btn.more::after { content: "›"; font-size: 1.5rem; line-height: 1; }
.account .link.back { justify-self: start; padding-left: 0; text-decoration: none; }
.account .link.back::before { content: "‹ "; }
.account .current-name { font-size: 1.15rem; font-weight: 800; }
.account .confirm { display: grid; gap: 10px; padding: 12px; border-radius: 14px; background: var(--paper); box-shadow: inset 0 0 0 2px var(--orange); }
.account .confirm .clip-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.account .confirm .btn { padding-inline: 8px; white-space: nowrap; }
/* A switch: the label on the left, the switch on the right; on is blue with the knob to the right. */
.help label.toggle { display: flex; justify-content: space-between; align-items: center; gap: 12px; min-height: 44px; font-weight: 400; font-size: 1rem; cursor: pointer; }
.toggle input { appearance: none; flex: none; position: relative; width: 52px; height: 32px; margin: 0; border-radius: 999px; background: var(--gap); cursor: pointer; transition: background 0.15s; }
.toggle input::before { content: ""; position: absolute; top: 3px; left: 3px; width: 26px; height: 26px; border-radius: 50%; background: var(--paper); box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3); transition: transform 0.15s; }
.toggle input:checked { background: var(--primary); }
.toggle input:checked::before { transform: translateX(20px); }
.toggle input:focus-visible { outline: 3px solid var(--primary); outline-offset: 2px; }
@media (prefers-reduced-motion: reduce) { .toggle input, .toggle input::before { transition: none; } }
.account .subpage > h3 { margin: 0; font-size: 1.25rem; }
.account .subpage section { margin: 0; padding-top: 12px; border-top: 2px solid var(--grid); }
.help .ways { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.help a.btn { color: var(--ink); }
/* Google's sign-in button as people know it, to Google's branding guidelines: white with a grey
   outline (near-black in the dark theme), the "G" in its own colours, a medium-weight label. */
.help a.btn.google { display: flex; justify-content: center; align-items: center; gap: 10px; border: 1px solid #747775; background: #ffffff; color: #1f1f1f; box-shadow: none; font-family: Roboto, system-ui, sans-serif; font-weight: 500; }
.help a.btn.google svg { flex: none; width: 20px; height: 20px; }
@media (prefers-color-scheme: dark) {
  .help a.btn.google { border-color: #8e918f; background: #131314; color: #e3e3e3; }
}
.help .ways li { margin: 0; }
.ways li { display: flex; align-items: center; justify-content: space-between; gap: 8px; min-height: 44px; padding: 4px 12px; border-radius: 12px; background: var(--paper); }
.ways .link.small { min-height: 40px; padding: 0 0 0 8px; }
.ways .link:disabled { color: var(--muted); text-decoration: none; cursor: default; }

/* Friends and invites. */
#friends-open { position: relative; }
.dot { position: absolute; top: 0; right: 0; width: 10px; height: 10px; border-radius: 50%; background: var(--red); box-shadow: 0 0 0 2px var(--bg); }
.friends section { margin-bottom: 16px; }
.friends .done:empty { display: none; }
.friends .done { color: var(--good); font-weight: 700; margin-bottom: 10px; }
.offer { padding: 14px; border-radius: 18px; background: var(--paper); box-shadow: inset 0 0 0 2px var(--gold); display: grid; gap: 8px; }
.offer h3 { margin: 0; }
.offer-dots { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 6px; }
.offer-dots li { width: 28px; height: 28px; border-radius: 50%; border: 3px solid var(--grid); }
.offer-dots li:nth-child(3n + 1) { --c: var(--red); }
.offer-dots li:nth-child(3n + 2) { --c: var(--blue); border-radius: 4px; }
/* The triangle is an outline like the other two: a 3px frame cut out of the box (a border can't
   follow a clip-path), in the same grey until a friend joins, and filled once they count. */
.offer-dots li:nth-child(3n) { --c: var(--green); border-radius: 0; border: 0; background: var(--grid);
  clip-path: polygon(evenodd, 50% 0, 100% 100%, 0 100%, 50% 0, 50% 24%, 17.3% 89.3%, 82.7% 89.3%, 50% 24%); }
.offer-dots li.joined { border-color: var(--c); }
.offer-dots li:nth-child(3n).joined { background: var(--c); }
.offer-dots li.counted { background: var(--c); border-color: var(--c); }
.offer-dots li:nth-child(3n).counted { clip-path: polygon(50% 0, 100% 100%, 0 100%); }
.qr { width: min(220px, 70%); margin: 4px auto; }
.qr svg { display: block; width: 100%; height: auto; border-radius: 12px; }
.invite-link { text-align: center; font-weight: 700; overflow-wrap: anywhere; user-select: all; }
.friends .clip-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.friends .clip-row .btn:only-child { grid-column: 1 / -1; }
.friends .link.small { justify-self: center; padding: 4px; min-height: 40px; }
.friends .ways .actions { display: flex; gap: 4px; }
.friends .ways .who { font-weight: 700; overflow-wrap: anywhere; }
.friends .ways .who small { display: block; font-weight: 400; color: var(--muted); }
.policy { border: 0; padding: 0; margin: 0 0 12px; display: grid; gap: 8px; }
.policy legend { font-weight: 700; margin-bottom: 6px; padding: 0; }
.account .note.error:empty { display: none; }
.help .offer-dots { padding: 0; }
.help .offer-dots li { margin: 0; }
.help a.btn.primary { color: var(--primary-ink); }
.friends .clip-row:has(#invite-share[hidden]) #invite-copy { grid-column: 1 / -1; }

/* The invite offer where nobody can miss it: a strip above the header (it can be dismissed) and
   a card at the top of Friends. Both open the Invite friends dialog. */
.promo { display: flex; align-items: stretch; background: var(--gold); color: var(--gold-ink); }
.promo-go, .promo-close { font: inherit; font-weight: 800; border: 0; background: none; color: inherit; cursor: pointer; min-height: 40px; }
.promo-go { flex: 1; padding: 6px 4px 6px 48px; text-align: center; font-size: 0.95rem; }
.promo-close { flex: none; width: 44px; font-size: 1.3rem; line-height: 1; }
body:has(.promo:not([hidden])) .stage { width: min(100%, max(280px, 100svh - var(--chrome, 345px) - 40px)); }
.friends .offer .btn { justify-self: stretch; }
.friends .note .link.small { padding: 0; min-height: 0; }
/* Five buttons in the header: on a narrow phone they and the name tighten up to stay on one line. */
@media (max-width: 400px) {
  .top { padding-inline: 12px; }
  .top-buttons { gap: 5px; }
  .icon-btn { width: 33px; height: 33px; }
  .brand { gap: 6px; }
  .brand h1 { font-size: 1.2rem; }
  .logo svg { height: 21px; }
}

/* All-time records: the record trophy (logo.js recordSvg), its section and the result's banner. */
.record-trophy .glint { mix-blend-mode: overlay; transform-box: fill-box; transform: translateX(-110%); animation: sheen 3.6s ease-in-out 0.6s infinite; }  /* the Premium button's sheen */
.record-trophy .spark { transform-box: fill-box; transform-origin: center; animation: spark 2.4s ease-in-out infinite; }
.record-trophy .spark.late { animation-delay: 1.2s; }
@keyframes spark { 0%, 100% { opacity: 0.25; scale: 0.6; } 50% { opacity: 1; scale: 1; } }
@media (prefers-reduced-motion: reduce) { .record-trophy .glint { animation: none; transform: translateX(-16%); opacity: 0.6; } .record-trophy .spark { animation: none; } }
.records-part { box-shadow: var(--shadow), inset 0 0 0 2px #f7b614; }
.record-token { flex: none; width: 56px; height: 56px; }
.record-token svg { width: 100%; height: 100%; display: block; }
.record-banner { display: flex; align-items: center; gap: 12px; margin: 0 0 12px; padding: 12px 14px; border-radius: 18px; background: var(--paper); box-shadow: inset 0 0 0 2px #f7b614; text-align: left; animation: record-in 0.5s cubic-bezier(0.2, 1.4, 0.4, 1); }
.record-banner b { display: block; font-size: 1.05rem; }
.record-banner span { color: var(--muted); font-size: 0.9rem; }
@keyframes record-in { from { scale: 0.85; opacity: 0; } }
.record-mark { display: inline-flex; align-items: center; gap: 4px; margin-top: 2px; font-size: 0.75rem; font-weight: 700; color: var(--muted); }
.record-mark svg { width: 18px; height: 18px; }
.record-mark .glint { animation: none; transform: translateX(-16%); opacity: 0.6; }
.record-mark .spark { animation: none; }
.player-watch { flex: none; min-height: 44px; padding: 0 12px; border: 0; border-radius: 12px; background: var(--surface); color: var(--ink); font: inherit; font-weight: 700; font-size: 0.875rem; cursor: pointer; box-shadow: inset 0 0 0 2px var(--grid); }
.player-watch:hover, .player-watch:focus-visible { box-shadow: inset 0 0 0 2px var(--primary); }

/* The series recap (js/recap.js). */
.recap { width: min(460px, calc(100vw - 24px)); text-align: center; }
.recap h2 { margin-bottom: 0; }
.recap-verdict { margin: 2px 0 12px; font-weight: 700; color: var(--muted); }
.recap.done .recap-verdict { color: var(--good); font-size: 1.2rem; }
.recap-tiles { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; list-style: none; margin: 0; padding: 0; }
.recap-tiles li { flex: 0 0 calc((100% - 16px) / 3); display: grid; gap: 2px; padding: 6px 6px 8px; border-radius: 16px; background: var(--paper); box-shadow: inset 0 0 0 2px var(--grid); opacity: 0.25; scale: 0.9; transition: opacity 0.3s, scale 0.35s cubic-bezier(0.2, 1.5, 0.4, 1), box-shadow 0.3s; }
.recap-tiles li.shown { opacity: 1; scale: 1; }
.recap-tiles li:not(.shown) :is(b, span) { visibility: hidden; }  /* no score before its turn */
.recap-tiles li.shown.good { box-shadow: inset 0 0 0 2px var(--good); }
.recap-tiles li.shown.bad { box-shadow: inset 0 0 0 2px var(--bad); }
.recap-tiles canvas { display: block; width: 100%; aspect-ratio: 1; border-radius: 10px; }
.recap-tiles b { font-size: 0.8rem; line-height: 1.2; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.recap-tiles span { font-size: 0.8rem; font-weight: 700; color: var(--muted); font-variant-numeric: tabular-nums; }
.recap-tiles li.bad span { color: var(--bad); }
.recap-sum { margin: 14px 0 2px; display: grid; }
.recap-sum b { font-size: 3rem; line-height: 1; font-variant-numeric: tabular-nums; }
.recap-sum span { color: var(--muted); }
.recap-end { display: grid; gap: 10px; margin: 12px 0; animation: record-in 0.4s ease-out; }
.recap-where { margin: 0; font-weight: 700; }
.recap-end .btn, .recap > #recap-close { width: 100%; }
.recap-end .round-actions { margin: 0; }
.recap-end .round-actions .btn { width: auto; }
@media (prefers-reduced-motion: reduce) { .recap-tiles li { transition: none; } .recap-end { animation: none; } }

/* The player's history (js/history.js) and a round shown again. */
.player-tabs { margin: 0; background: var(--surface); box-shadow: var(--shadow); }
.history-day .player-what { gap: 6px; }
.history-entries { display: flex; flex-wrap: wrap; gap: 6px; }
.history-entry { display: grid; gap: 0; min-height: 44px; padding: 6px 12px; border: 0; border-radius: 12px; background: var(--surface); color: var(--ink); font: inherit; text-align: left; cursor: pointer; box-shadow: inset 0 0 0 2px var(--grid); }
.history-entry b { font-size: 0.8rem; color: var(--muted); }
.history-entry span { font-weight: 700; font-size: 0.95rem; }
.history-entry.plain { cursor: default; box-shadow: none; background: none; }
button.history-entry:hover, button.history-entry:focus-visible { box-shadow: inset 0 0 0 2px var(--primary); }
.history-tap { padding: 0 !important; }
.history-open { flex: 1; display: flex; align-items: center; gap: 10px; padding: 10px; border: 0; border-radius: 14px; background: none; color: inherit; font: inherit; text-align: left; cursor: pointer; }
.history-open:hover, .history-open:focus-visible { box-shadow: inset 0 0 0 2px var(--primary); }
.round-view { width: min(460px, calc(100vw - 24px)); }
.round-view h2 { margin-bottom: 2px; }
.round-view > .note { margin-top: 0; }
.round-stage { width: 100%; max-width: 420px; margin: 8px auto 0; }
.round-fit { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.round-numbers { text-align: center; font-weight: 700; margin: 10px 0; }
.round-tabs { display: grid; grid-template-columns: repeat(5, 1fr); gap: 4px; margin: 8px 0; }
.round-tabs button { min-height: 44px; border: 0; border-radius: 12px; background: var(--paper); color: var(--ink); font: inherit; font-weight: 700; cursor: pointer; box-shadow: inset 0 -4px 0 var(--good); }
.round-tabs button.jam { box-shadow: inset 0 -4px 0 var(--bad); }
.round-tabs button[aria-pressed="true"] { background: var(--primary); color: var(--primary-ink); }
.round-actions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-bottom: 10px; }
.round-actions .btn { flex: 1 1 120px; }
.round-series { display: grid; gap: 8px; margin: 8px 0 4px; }
.round-series .round-actions { margin: 0; }
.round-series .round-actions .btn { display: flex; align-items: center; justify-content: center; gap: 6px; }
.round-series svg { flex: none; fill: currentColor; }
.round-view > #round-close { width: 100%; }
