/* Block Puzzle — styles
 *
 * One cartoon world: a bright sky, thick ink outlines and hard drop shadows.
 * Blocks are painted as solid colour tiles with a darker inner edge, so a
 * pile of them reads as a stack rather than a smear. No prefers-color-scheme
 * blocks — every colour is painted explicitly and the page holds whatever
 * ground the viewer's own theme paints behind it. */

:root {
  /* the scene */
  --sky-top:   #79cbf2;
  --sky-mid:   #a5e2fa;
  --sky-low:   #d3f1fc;
  --arena-sky: #d5eff9;

  /* wood shelf */
  --wood:      #f7cd97;
  --wood-edge: #d89a55;
  --wood-under:#a86f36;

  /* surfaces and ink */
  --paper:     #fffdf7;
  --paper-warm:#fff3e0;
  --ink:       #2b2142;
  --ink-soft:  #6f6389;
  --ink-faint: rgba(43, 33, 66, .16);

  /* action */
  --accent:      #ff5d8f;
  --accent-deep: #e0446f;
  --gold:        #ffc93c;
  --grass:       #35c46b;
  --danger:      #d8365f;
  --rock:        #9aa6b8;
  --rock-edge:   #6b7688;

  --lift:   4px;
  --stroke: 3px;
  --radius: 16px;

  --cell:     40px;      /* set inline by app.js when the level starts */
}

*, *::before, *::after { box-sizing: border-box; }

/* No zoom, no text selection anywhere by default — the game is a set of
   controls, not a page. Inputs opt back in below. */
html {
  touch-action: manipulation;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}
* {
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}
input, textarea {
  -webkit-user-select: text;
  user-select: text;
}

html, body { margin: 0; height: 100%; overflow: hidden; overscroll-behavior: none; }

body {
  background-color: var(--sky-mid);
  background-image:
    linear-gradient(180deg, var(--sky-top) 0%, var(--sky-mid) 42%, var(--sky-low) 100%);
  background-attachment: fixed;
  color: var(--ink);
  font: 16px/1.55 "Nunito", ui-rounded, "Segoe UI", system-ui, sans-serif;
  font-weight: 600;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

.app {
  max-width: 1040px;
  margin: 0 auto;
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding:
    calc(18px + env(safe-area-inset-top))
    calc(16px + env(safe-area-inset-right))
    calc(16px + env(safe-area-inset-bottom))
    calc(16px + env(safe-area-inset-left));
}

.screen { display: none; flex: 1; min-height: 0; }
.screen.is-active {
  display: flex;
  flex-direction: column;
  animation: rise .34s cubic-bezier(.2, .9, .3, 1.2) both;
}
#screen-levels.is-active { overflow: hidden; }
#screen-levels.is-active .level-grid {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 2px 2px 12px;
}

body.playing { overflow: hidden; }
body.playing .app {
  padding-top: calc(10px + env(safe-area-inset-top));
  padding-bottom: calc(10px + env(safe-area-inset-bottom));
}
body.playing #screen-game.is-active {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow: hidden;
}
body.playing #screen-game.is-active > * { flex: none; margin-block: 0; }
body.playing #screen-game.is-active > .board { flex: 1 1 0; min-height: 0; }
body.playing.is-tight #screen-game.is-active { gap: 5px; }

@keyframes rise {
  from { opacity: 0; transform: translateY(14px) scale(.985); }
  to   { opacity: 1; transform: none; }
}

/* ───────── buttons ───────── */

.btn {
  appearance: none;
  border: var(--stroke) solid var(--ink);
  background: var(--paper);
  color: var(--ink);
  font: inherit;
  font-family: "Baloo 2", "Nunito", sans-serif;
  font-weight: 700;
  font-size: 16px;
  line-height: 1.1;
  padding: 10px 16px;
  border-radius: 12px;
  cursor: pointer;
  box-shadow: 0 var(--lift) 0 var(--ink);
  transition: transform .09s ease, box-shadow .09s ease, background .14s ease;
  -webkit-user-select: none; user-select: none;
}
.btn:hover:not(:disabled) { background: var(--paper-warm); }
.btn:active:not(:disabled) { transform: translateY(var(--lift)); box-shadow: 0 0 0 var(--ink); }
.btn:disabled { opacity: .45; cursor: default; box-shadow: 0 var(--lift) 0 var(--ink-faint); }

.btn:focus-visible,
.tile:focus-visible,
.choice:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 3px;
}

.btn--primary { background: var(--accent); color: #fff; }
.btn--primary:hover:not(:disabled) { background: var(--accent-deep); }
.btn--ghost {
  background: rgba(255, 255, 255, .62);
  box-shadow: 0 var(--lift) 0 var(--ink-faint);
}
.btn--ghost:hover:not(:disabled) { background: #fff; }
.btn--quiet { font-size: 14px; color: var(--ink-soft); }
.btn--icon {
  padding: 9px 12px;
  font-size: 20px;
  line-height: 1;
  min-width: 44px;
}

/* ───────── masthead (home) ───────── */

.masthead { text-align: center; margin: 16px 0 30px; }

.masthead__mark {
  display: flex;
  justify-content: center;
  gap: 10px;
  margin-bottom: 14px;
}
.masthead__mark span {
  width: 32px; height: 32px;
  border-radius: 6px;
  background: var(--c);
  border: var(--stroke) solid var(--ink);
  box-shadow: inset 0 -6px 0 rgba(0,0,0,.18);
  animation: bob 2.4s ease-in-out infinite;
}
.masthead__mark span:nth-child(2) { animation-delay: .18s; }
.masthead__mark span:nth-child(3) { animation-delay: .36s; }
@keyframes bob { 50% { transform: translateY(-8px) rotate(-6deg); } }

.masthead h1 {
  margin: 0;
  font-family: "Baloo 2", sans-serif;
  font-weight: 800;
  font-size: clamp(42px, 9vw, 74px);
  line-height: .98;
  letter-spacing: -.01em;
  color: #fff;
  -webkit-text-stroke: 7px var(--ink);
  paint-order: stroke fill;
  text-shadow: 0 7px 0 var(--ink);
  text-wrap: balance;
}
.masthead__tag {
  margin: 16px auto 0;
  max-width: 34ch;
  color: var(--ink);
  font-weight: 700;
  font-size: 17px;
  text-wrap: balance;
}

/* ───────── home: choice ───────── */

.choices {
  display: grid;
  gap: 16px;
  width: 100%;
  max-width: 520px;
  margin: 0 auto;
}

.choice {
  display: flex;
  align-items: center;
  gap: 16px;
  width: 100%;
  padding: 18px 20px;
  text-align: left;
  border: var(--stroke) solid var(--ink);
  border-radius: var(--radius);
  background: var(--paper);
  color: var(--ink);
  font: inherit;
  cursor: pointer;
  box-shadow: 0 6px 0 var(--ink);
  transition: transform .09s ease, box-shadow .09s ease, background .14s ease;
}
.choice:hover { background: var(--paper-warm); }
.choice:active { transform: translateY(6px); box-shadow: 0 0 0 var(--ink); }

.choice__body { flex: 1; min-width: 0; line-height: 1.2; }
.choice__name {
  display: block;
  font-family: "Baloo 2", sans-serif;
  font-weight: 800;
  font-size: 26px;
}
.choice__sub { display: block; color: var(--ink-soft); font-size: 14.5px; font-weight: 700; }
.choice__go {
  font-family: "Baloo 2", sans-serif;
  font-weight: 800;
  font-size: 30px;
  color: var(--ink-soft);
  line-height: 1;
}

/* A block-filled crate that fills with how far through you are. */
.choice__jar {
  position: relative;
  flex: 0 0 46px;
  width: 46px;
  height: 60px;
  border: var(--stroke) solid var(--ink);
  border-radius: 6px;
  background: rgba(203, 233, 248, .72);
  overflow: hidden;
}
.choice__jar i {
  position: absolute;
  inset: auto 0 0 0;
  height: 0;
  background:
    repeating-linear-gradient(90deg, var(--accent) 0, var(--accent) 11px,
    var(--accent-deep) 11px, var(--accent-deep) 12px);
  border-top: 2px solid rgba(43, 33, 66, .32);
  transition: height .4s cubic-bezier(.2, .9, .3, 1.3);
}

/* A tiny calendar for the Daily Puzzle option, drawn the same weight as the
   crate beside it. The big number is today's date; the pink strip is the
   calendar's binder. */
.choice__cal {
  position: relative;
  flex: 0 0 46px;
  width: 46px;
  height: 60px;
  border: var(--stroke) solid var(--ink);
  border-radius: 8px;
  background: var(--paper);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.choice__cal-top {
  position: absolute;
  inset: 0 0 auto 0;
  height: 14px;
  background: var(--accent);
  border-bottom: 2px solid var(--ink);
}
.choice__cal b {
  margin-top: 12px;
  font-family: "Baloo 2", sans-serif;
  font-weight: 800;
  font-size: 22px;
  color: var(--ink);
  line-height: 1;
}

/* Three little jars at odd heights, standing in as blocks on a shelf — the
   old shape of the Random Puzzle icon carried over from the colour-jars
   project this game shares its bones with. */
.choice__shelf {
  flex: 0 0 46px;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  width: 46px;
  height: 60px;
}
.choice__shelf i {
  width: 13px;
  border: 2px solid var(--ink);
  border-radius: 3px 3px 7px 7px;
  background: linear-gradient(180deg, rgba(203, 233, 248, .8) 40%, var(--c) 40%);
}
.choice__shelf i:nth-child(1) { height: 36px; --c: #f5423c; }
.choice__shelf i:nth-child(2) { height: 54px; --c: #0ec3c6; }
.choice__shelf i:nth-child(3) { height: 44px; --c: #9a53ef; }

.save-warning {
  text-align: center;
  color: var(--ink-soft);
  font-size: 14px;
  margin: 14px auto 0;
  max-width: 40ch;
}

.menu-foot {
  margin-top: auto;
  padding-top: 20px;
  display: flex;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
}

/* ───────── subhead (levels, game) ───────── */

.subhead {
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  max-width: 620px;
  margin: 0 auto 22px;
}
.subhead__title { flex: 1; text-align: center; line-height: 1.15; }
.subhead__title h2 {
  margin: 0;
  font-family: "Baloo 2", sans-serif;
  font-weight: 800;
  font-size: 27px;
}
.subhead__title span { color: var(--ink-soft); font-size: 14px; font-weight: 700; }
.subhead__balance { flex: 0 0 96px; }

/* ───────── cards (daily / random) ───────── */

.card {
  background: var(--paper);
  border: var(--stroke) solid var(--ink);
  border-radius: var(--radius);
  padding: 22px;
  box-shadow: 0 6px 0 var(--ink);
}
.card--single { width: 100%; max-width: 420px; margin: 0 auto; }
.card__body { margin: 0 0 16px; color: var(--ink-soft); font-size: 15px; }
.card__note { margin: 14px 0 0; color: var(--ink-soft); font-size: 14px; min-height: 1.2em; }

/* ───────── the calendar of days ───────── */

.cal__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 10px;
}
.cal__head h3 {
  margin: 0;
  flex: 1;
  font-family: "Baloo 2", sans-serif;
  font-weight: 800;
  font-size: 21px;
}
.cal__head .btn { padding: 6px 14px; font-size: 22px; line-height: 1; }

.cal__names, .cal {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 6px;
  margin: 0;
  padding: 0;
  list-style: none;
}
.cal__names {
  margin-bottom: 6px;
  color: var(--ink-soft);
  font-weight: 800;
  font-size: 13px;
  text-align: center;
}

.cal__day {
  position: relative;
  width: 100%;
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid var(--ink);
  border-radius: 10px;
  background: var(--paper-warm);
  font-family: "Baloo 2", sans-serif;
  font-weight: 800;
  font-size: 15px;
  color: var(--ink);
  cursor: pointer;
  padding: 0;
}
.cal__day:hover:not(:disabled) { background: #fff; }
.cal__day:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.cal__day:disabled { opacity: .38; cursor: default; border-style: dashed; }
.cal__day.is-today { box-shadow: 0 0 0 3px var(--gold); }
.cal__day.is-done { background: var(--grass); color: #fff; }
.cal--blank { visibility: hidden; }

.cal__legend {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  margin: 12px 0 0;
  color: var(--ink-soft);
  font-size: 13.5px;
  font-weight: 700;
  min-height: 1.2em;
}

/* ───────── the difficulty slider ─────────
   A slider is the one control here whose meaning is an ordering, and it
   stays on one line at any width. */
.setting { margin-bottom: 4px; }
.setting__head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 6px;
}
.setting__label {
  font-size: 13px;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--ink-soft);
}
.setting__name {
  font-family: "Baloo 2", sans-serif;
  font-size: 20px;
  color: var(--ink);
}
.setting__slider {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 26px;
  margin: 0;
  background: transparent;
  cursor: pointer;
}
.setting__slider::-webkit-slider-runnable-track {
  height: 10px;
  border-radius: 999px;
  border: var(--stroke) solid var(--ink);
  background: var(--paper-warm);
}
.setting__slider::-moz-range-track {
  height: 10px;
  border-radius: 999px;
  border: var(--stroke) solid var(--ink);
  background: var(--paper-warm);
}
.setting__slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 26px;
  height: 26px;
  margin-top: -10px;
  border-radius: 50%;
  border: var(--stroke) solid var(--ink);
  background: var(--gold);
  box-shadow: 0 2px 0 var(--ink);
  transition: transform .09s ease;
}
.setting__slider::-moz-range-thumb {
  width: 26px;
  height: 26px;
  border: var(--stroke) solid var(--ink);
  border-radius: 50%;
  background: var(--gold);
  box-shadow: 0 2px 0 var(--ink);
}
.setting__slider:active::-webkit-slider-thumb { transform: scale(1.08); }
.setting__slider:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 4px;
  border-radius: 999px;
}
.setting__ticks {
  display: flex;
  justify-content: space-between;
  padding: 0 4px;
  margin-top: 2px;
}
.setting__ticks span {
  font-size: 11px;
  color: var(--ink-soft);
  flex: 1;
  text-align: center;
}
.setting__ticks span:first-child { text-align: left; }
.setting__ticks span:last-child { text-align: right; }
.setting__ticks span.is-on { color: var(--ink); font-weight: 700; }

.difficulty__blurb {
  margin: 12px 0 14px;
  color: var(--ink-soft);
  font-size: 14px;
  line-height: 1.5;
  min-height: 3em;
}

.seed {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 14px;
  color: var(--ink-soft);
  font-size: 14px;
}
.seed input {
  flex: 1;
  min-width: 0;
  background: #fff;
  border: 2px solid var(--ink);
  border-radius: 10px;
  color: var(--ink);
  font: inherit;
  font-size: 15px;
  font-variant-numeric: tabular-nums;
  padding: 8px 11px;
}

/* ───────── level grid ───────── */

.level-pager {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 0 0 12px;
  font-family: "Baloo 2", sans-serif;
}
.pager__label {
  font-weight: 800;
  font-size: 16px;
  color: var(--ink);
  letter-spacing: 0.02em;
}
.btn--pager {
  min-width: 52px;
  padding: 6px 14px;
  font-size: 18px;
  font-weight: 800;
}

.level-grid {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(88px, 1fr));
  gap: 10px;
  align-content: start;
}

.tile {
  width: 100%;
  aspect-ratio: 1 / 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  border: var(--stroke) solid var(--ink);
  border-radius: 12px;
  background: var(--paper);
  color: var(--ink);
  font: inherit;
  font-family: "Baloo 2", sans-serif;
  font-weight: 800;
  cursor: pointer;
  box-shadow: 0 4px 0 var(--ink);
  padding: 4px;
  transition: transform .09s ease, box-shadow .09s ease, background .14s ease;
}
.tile:hover:not(:disabled) { background: var(--paper-warm); }
.tile:active:not(:disabled) { transform: translateY(4px); box-shadow: 0 0 0 var(--ink); }
.tile__num { font-size: 22px; line-height: 1; }
.tile__name { font-size: 10.5px; font-weight: 700; color: var(--ink-soft); text-align: center; }
.tile__stars { color: var(--gold); font-size: 12px; letter-spacing: 1px; }
.tile__lock { font-size: 18px; opacity: .55; }
.tile--done { background: #eef7ff; }
.tile--locked {
  background: rgba(255, 255, 255, .45);
  color: var(--ink-soft);
  box-shadow: 0 4px 0 var(--ink-faint);
  cursor: default;
}

/* ───────── game topbar ───────── */

.topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border: var(--stroke) solid var(--ink);
  border-radius: var(--radius);
  background: var(--paper);
  box-shadow: 0 4px 0 var(--ink);
}
.topbar__title { flex: 1; text-align: center; line-height: 1.15; }
.topbar__title h2 {
  margin: 0;
  font-family: "Baloo 2", sans-serif;
  font-weight: 800;
  font-size: 20px;
}
.topbar__title span { display: block; color: var(--ink-soft); font-size: 12px; font-weight: 700; }
.topbar__stats { display: flex; gap: 8px; }
.stat {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  min-width: 46px;
  padding: 4px 8px;
  border: 2px solid var(--ink);
  border-radius: 10px;
  background: var(--paper-warm);
  line-height: 1;
}
.stat b {
  font-family: "Baloo 2", sans-serif;
  font-weight: 800;
  font-size: 18px;
}
.stat small { font-size: 9px; letter-spacing: .12em; color: var(--ink-soft); margin-top: 2px; }

.brief {
  margin: 0;
  padding: 0 8px;
  text-align: center;
  color: var(--ink);
  font-size: 14px;
  font-weight: 700;
  text-wrap: balance;
}

/* ───────── the board ───────── */

.board {
  display: flex;
  justify-content: center;
  /* Anchor to the top so the piece's runway is always in view — fitBoard
     shrinks the cell size until the whole arena fits, so the pile at the
     bottom never falls out of the frame either. */
  align-items: flex-start;
  padding: 4px 0;
  overflow: hidden;
}

.arena {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  touch-action: none;
}

/* The frame is the clickable surface. All the painting — the sky-blue
   playable interior and the ink outline — is done by the SVG child below;
   the frame itself is transparent so the arena's actual shape is jagged,
   not rectangular. */
.arena__frame {
  position: relative;
  overflow: visible;
  cursor: pointer;
  touch-action: none;
  filter: drop-shadow(0 6px 0 var(--ink));
}
.arena__shape {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: visible;
  pointer-events: none;
}

.arena__grid {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-rows: repeat(var(--rows), var(--cell));
  grid-template-columns: repeat(var(--w), var(--cell));
}

/* Row-column subgrid cells. Sky rows are transparent; arena rows carry a
   faint hairline so a partly-filled arena reads as a grid, not a blob. */
.cell {
  position: relative;
  width: var(--cell);
  height: var(--cell);
}
.cell--sky { background: transparent; }
.cell--arena {
  background: rgba(255, 255, 255, .18);
  box-shadow:
    inset 0 0 0 1px rgba(43, 33, 66, .08);
}

/* A block cell: solid colour with a darker inset lip, so the pile reads as
   3D without a real shadow. --fill, --edge and --ink are set per cell. */
.cell--block {
  background: var(--fill);
  box-shadow:
    inset 0 -6px 0 var(--edge),
    inset 0 0 0 1.5px rgba(43, 33, 66, .38);
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.cell__mark {
  display: none;
  color: var(--ink);
  font-family: "Baloo 2", sans-serif;
  font-weight: 800;
  font-size: calc(var(--cell) * .48);
  line-height: 1;
  pointer-events: none;
}
body.cb-assist .cell__mark { display: block; opacity: .9; }

/* The ceiling line — an ink dash across the arena at the top of the play
   area. Drawn as a background image so it does not steal clicks. */
.arena__ceiling {
  position: absolute;
  left: 0; right: 0;
  top: var(--sky);
  height: 3px;
  background: repeating-linear-gradient(90deg,
    var(--ink) 0, var(--ink) 8px, transparent 8px, transparent 14px);
  pointer-events: none;
  z-index: 2;
}

/* The piece and ghost layers: one wrapper each, positioned by inline
   transform, blocks laid out inside using --r and --c. The wrapper carries
   the column so a sideways move can ease across; the inner layer carries
   the fall, which is rewritten every frame and must never lag behind. */
.arena__piece,
.arena__ghost {
  position: absolute;
  left: 0; top: 0;
  width: 0;
  height: 0;
  pointer-events: none;
  transform: translateX(0);
  transition: transform .1s cubic-bezier(.25, .8, .35, 1), opacity .12s ease;
  z-index: 3;
}
.arena__layer {
  position: absolute;
  left: 0; top: 0;
  transform: translateY(0);
  will-change: transform;
}
.arena__ghost { z-index: 2; }

.arena__piece .block,
.arena__ghost .block,
.queue .block {
  position: absolute;
  width: var(--cell);
  height: var(--cell);
  left: calc(var(--c) * var(--cell));
  top:  calc(var(--r) * var(--cell));
  background: var(--fill);
  box-shadow:
    inset 0 -6px 0 var(--edge),
    inset 0 0 0 1.5px rgba(43, 33, 66, .38);
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.arena__piece .block { z-index: 3; }
.block__mark {
  display: none;
  color: var(--ink);
  font-family: "Baloo 2", sans-serif;
  font-weight: 800;
  font-size: calc(var(--cell) * .48);
  line-height: 1;
  pointer-events: none;
}
body.cb-assist .block__mark { display: block; opacity: .9; }

.arena__ghost .block {
  background: transparent;
  box-shadow:
    inset 0 0 0 3px var(--fill),
    inset 0 0 0 4px rgba(43, 33, 66, .35);
  border-radius: 4px;
}

/* ───────── queue ───────── */

.shelf-wrap {
  display: flex;
  justify-content: center;
  padding: 0 4px;
}
.queue {
  display: flex;
  align-items: flex-end;
  justify-content: flex-start;
  gap: 6px;
  padding: 6px 10px 5px;
  border: var(--stroke) solid var(--ink);
  border-radius: 12px;
  background: var(--paper-warm);
  box-shadow: 0 4px 0 var(--ink-faint);
  overflow-x: auto;
  overflow-y: hidden;
  max-width: 100%;
  scrollbar-width: none;
}
.queue::-webkit-scrollbar { display: none; }

.queue__slot {
  --qcell: 14px;
  --qslot: 4;                          /* every slot is 4 cells wide/tall */
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  width: calc(var(--qslot) * var(--qcell) + 4px);
}
.queue__slot.is-now { --qcell: 18px; }

/* When the arena cannot get a comfortable cell size, the queue gives up
   its height first — a cramped board is worse than small thumbnails. */
.shelf-wrap--compact .queue { gap: 4px; padding: 3px 8px 2px; }
.shelf-wrap--compact .queue__slot { --qcell: 9px; gap: 1px; }
.shelf-wrap--compact .queue__slot.is-now { --qcell: 12px; }
.shelf-wrap--compact .queue__cue {
  font-size: 8px;
  padding: 0 4px;
  border-width: 1.5px;
}
.queue__cue {
  font-family: "Baloo 2", sans-serif;
  font-weight: 800;
  font-size: 10px;
  letter-spacing: .15em;
  color: var(--ink);
  background: var(--gold);
  border: 2px solid var(--ink);
  padding: 1px 6px;
  border-radius: 6px;
}
/* Fixed 4×4 thumb per slot so the queue never changes height as pieces
   with different shapes come and go. --ox and --oy shift the piece so it
   sits centred horizontally and pinned to the bottom of the box. */
.queue__thumb {
  position: relative;
  --cell: var(--qcell);
  width: calc(var(--qslot) * var(--cell));
  height: calc(var(--qslot) * var(--cell));
}
.queue .block {
  --cell: var(--qcell);
  box-shadow: inset 0 -3px 0 var(--edge), inset 0 0 0 1px rgba(43, 33, 66, .38);
  left: calc((var(--c) + var(--ox, 0)) * var(--cell));
  top:  calc((var(--r) + var(--oy, 0)) * var(--cell));
}
.queue .block__mark { display: none; }

/* ───────── toolbar and status ───────── */

.toolbar {
  display: flex;
  justify-content: center;
  gap: 6px;
  flex-wrap: wrap;
}
.toolbar .btn { padding: 9px 12px; font-size: 15px; }
.toolbar .btn--primary { padding: 9px 16px; }

.status {
  text-align: center;
  color: var(--ink-soft);
  font-size: 14px;
  min-height: 1.2em;
  margin: 0;
}
.keys {
  text-align: center;
  color: var(--ink-soft);
  font-size: 11.5px;
  margin: 0;
  opacity: .82;
}
@media (hover: none) and (pointer: coarse) {
  .keys { display: none; }
}

/* ───────── modals ───────── */

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(43, 33, 66, .48);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 20;
  animation: overlayIn .18s ease-out both;
}
/* The `hidden` attribute alone is not enough once a rule sets display: an
   element-level `display: flex` out-specifies the browser's own
   `[hidden] { display: none }`, so every overlay would open at boot. */
.overlay[hidden] { display: none; }
@keyframes overlayIn { from { opacity: 0; } to { opacity: 1; } }

.modal {
  background: var(--paper);
  border: var(--stroke) solid var(--ink);
  border-radius: var(--radius);
  padding: 22px;
  max-width: 400px;
  width: 100%;
  box-shadow: 0 8px 0 var(--ink);
  animation: modalIn .28s cubic-bezier(.2,.9,.3,1.35) both;
  max-height: 92dvh;
  overflow-y: auto;
}
.modal--wide { max-width: 540px; }

/* The link is stacked above the single button rather than beside it, so the
   button stays the obvious thing to press and the link is not mistaken for a
   second answer. Stuck to the bottom so a consent dialog's only button can
   never end up below the fold on a short screen. */
.modal__actions--consent {
  flex-direction: column;
  align-items: center;
  gap: 4px;
  margin-top: 18px;
  position: sticky;
  bottom: -22px;
  margin-left: -22px;
  margin-right: -22px;
  padding: 10px 22px 22px;
  background: var(--paper);
}

/* Drawn in the app's own ink rather than left as browser blue, and padded
   out to a 44px tap target — the link is small text, the finger is not. */
.policy-link {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding: 0 12px;
  color: var(--ink-soft);
  font-family: "Baloo 2", sans-serif;
  font-weight: 800;
  font-size: 15px;
  text-decoration: underline;
  text-underline-offset: 3px;
  text-decoration-thickness: 2px;
}
.policy-link:active { color: var(--ink); }
.policy-link[hidden] { display: none; }
@keyframes modalIn {
  from { opacity: 0; transform: translateY(20px) scale(.95); }
  to   { opacity: 1; transform: none; }
}

/* Result modal — larger title, a bouncy badge on top, and a shimmer strip
   of colour tabs behind the badge on a win. Sits on top of the confetti,
   which handles the celebration outside the modal. */
.modal--result { text-align: center; padding-top: 44px; overflow: visible; }
.result__flare {
  position: absolute;
  top: -18px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 6px;
  pointer-events: none;
}
.result__flare span {
  width: 14px;
  height: 22px;
  border: 2px solid var(--ink);
  border-radius: 3px 3px 7px 7px;
  animation: flareBob 1.4s ease-in-out infinite;
}
.result__flare span:nth-child(1) { background: #f5423c; animation-delay: 0s; }
.result__flare span:nth-child(2) { background: #0ec3c6; animation-delay: .1s; }
.result__flare span:nth-child(3) { background: #9a53ef; animation-delay: .2s; }
.result__flare span:nth-child(4) { background: #ffd028; animation-delay: .3s; }
/* Fail flare — muted, tumbling flags to hint "so close, try again" rather
   than punishing. Same silhouette, different palette + animation. */
.result__flare--fail span { animation-name: flareTumble; }
.result__flare--fail span:nth-child(1) { background: var(--accent); }
.result__flare--fail span:nth-child(2) { background: #7f7160; }
.result__flare--fail span:nth-child(3) { background: var(--accent); }
.result__flare--fail span:nth-child(4) { background: #7f7160; }
@keyframes flareBob {
  0%, 100% { transform: translateY(0) rotate(-6deg); }
  50%      { transform: translateY(-8px) rotate(6deg); }
}
@keyframes flareTumble {
  0%, 100% { transform: translateY(0) rotate(-12deg); }
  50%      { transform: translateY(4px) rotate(12deg); }
}
.result__badge {
  width: 74px;
  height: 74px;
  flex: none;
  aspect-ratio: 1;
  margin: 0 auto 10px;
  border-radius: 50%;
  border: var(--stroke) solid var(--ink);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  box-shadow: 0 4px 0 var(--ink);
  animation: badgePop .55s cubic-bezier(.25,.9,.35,1.5) both;
}
/* Drawn rather than typed: the tick and cross characters carry their own
   font bearings, which left the mark sitting off-centre in the circle. */
.result__mark {
  width: 48%;
  height: 48%;
  display: block;
  overflow: visible;
  fill: none;
  stroke: currentColor;
  stroke-width: 3.1;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.result__badge--win  { background: var(--grass); }
.result__badge--fail { background: var(--accent); animation-name: badgeShake; }
@keyframes badgePop {
  0%   { transform: scale(0) rotate(-20deg); }
  60%  { transform: scale(1.15) rotate(6deg); }
  100% { transform: scale(1)    rotate(0); }
}
@keyframes badgeShake {
  0%   { transform: scale(0) rotate(0); }
  60%  { transform: scale(1.1); }
  70%  { transform: scale(1) translateX(-6px); }
  80%  { transform: scale(1) translateX(6px); }
  90%  { transform: scale(1) translateX(-3px); }
  100% { transform: scale(1) translateX(0); }
}
.result__title {
  margin: 0 0 6px;
  font-size: 34px;
  letter-spacing: -.01em;
  animation: titlePop .5s cubic-bezier(.2,.9,.3,1.4) both;
  animation-delay: .12s;
}
.result__title--win  { color: var(--ink); text-shadow: 0 3px 0 rgba(53, 196, 107, .35); }
.result__title--fail { color: var(--ink); text-shadow: 0 3px 0 rgba(255, 93, 143, .35); }
@keyframes titlePop {
  from { opacity: 0; transform: translateY(10px) scale(.9); }
  to   { opacity: 1; transform: none; }
}
.modal--result .modal__line {
  margin-top: 8px;
  font-size: 16px;
  color: var(--ink);
  font-weight: 700;
}

.modal h2 {
  margin: 0 0 8px;
  font-family: "Baloo 2", sans-serif;
  font-weight: 800;
  font-size: 24px;
  text-align: center;
}
.modal__line {
  margin: 10px 0 0;
  color: var(--ink-soft);
  font-size: 15px;
  line-height: 1.45;
  text-align: center;
  text-wrap: balance;
}
.modal__actions {
  display: flex;
  justify-content: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 16px;
}
.stars {
  text-align: center;
  font-size: 30px;
  color: var(--gold);
  letter-spacing: 4px;
  margin: 6px 0 0;
}
.rules {
  padding-left: 22px;
  margin: 8px 0;
}
.rules li {
  margin: 8px 0;
  color: var(--ink);
  font-size: 15px;
  line-height: 1.4;
}
.rules b { color: var(--ink); }

.settings-list { margin: 6px 0 4px; }
.settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 0;
  border-top: 1px solid var(--ink-faint);
}
.settings-row:first-child { border-top: 0; }

/* Set after .settings-row, whose border shorthand would otherwise reset the
   colour. */
.settings-row--danger { border-color: var(--danger); }
.settings-row--danger > span { color: var(--danger); }

/* ───────── press and hold to erase ───────── */

.hold {
  position: relative;
  display: block;
  width: 100%;
  margin: 4px 0 2px;
  padding: 16px 18px;
  border: var(--stroke) solid var(--ink);
  border-radius: 16px;
  background: var(--paper-warm);
  box-shadow: 0 5px 0 var(--ink);
  font: inherit;
  font-family: "Baloo 2", sans-serif;
  font-weight: 800;
  font-size: 19px;
  color: var(--ink);
  cursor: pointer;
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: none;          /* holding must not scroll the page instead */
}
.hold:focus-visible { outline: 3px solid var(--accent); outline-offset: 3px; }
.hold:active { transform: translateY(3px); box-shadow: 0 2px 0 var(--ink); }

/* Driven from script rather than a transition, so letting go stops the bar
   dead instead of animating on to somewhere it never reached. */
.hold__fill {
  position: absolute;
  inset: 0;
  transform-origin: left center;
  transform: scaleX(var(--held, 0));
  background: linear-gradient(90deg, #ff8fb1, var(--danger));
  border-radius: 0;
}
.hold__label { position: relative; }
.hold.is-done .hold__fill { background: var(--grass); }

/* Rows in the privacy dialogs stack a title, a small note, and a toggle, so a
   two-line description is not clipped by the default label/toggle row. */
.settings-row--stack { align-items: flex-start; }
.settings-row--stack > div {
  flex: 1 1 auto;
  min-width: 0;
}
.settings-row--stack > div > b {
  font-family: "Baloo 2", sans-serif;
  font-weight: 800;
  font-size: 17px;
  color: var(--ink);
  display: block;
}
.settings-row__note {
  margin: 4px 0 0;
  font-size: 13px;
  color: var(--ink-soft);
}

/* ───────── confetti ───────── */

.confetti {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 30;
  display: none;
}
