/* Flipsum. Cut slabs on a ledge. The operation is in the material, not a candy
   colour: plus is solid, minus is hollow, times is dense. A plain number has
   chamfered shoulders, so it only looks right as the top of a column. Ochre is
   kept for the goal and nothing else. */
:root {
  color-scheme: light dark;
  --ground: light-dark(#e6eae8, #18292c);
  --lane: light-dark(#d8dedb, #203639);
  --lane-on: light-dark(#eef1ef, #2b464a);
  --ink: light-dark(#182422, #e8efec);
  --soft: light-dark(#4b5c59, #a3b8b4);
  --paper: light-dark(#f3f5f4, #203639);
  --line: light-dark(#1824223d, #e8efec3d);
  --petrol: light-dark(#1d5a60, #6fb5b1);
  --on-petrol: light-dark(#ffffff, #102022);
  --dense: light-dark(#182422, #0b1517);
  --on-dense: #eef3f0;
  --cap: light-dark(#ffffff, #eef3f0);
  --on-cap: #182422;
  --goal-ink: light-dark(#8f5400, #efb24a);
  --bad: light-dark(#96321b, #f2a48c);
  --bh: 44px;
  --r: 4px;
}
* { box-sizing: border-box; min-width: 0; }
[hidden] { display: none !important; }
/* A block dragged past the side must not widen the page. */
/* Two quick taps must not zoom the page (Safari does). Pinching still zooms,
   so players who need larger text keep it. */
html { background: var(--ground); overflow-x: hidden; touch-action: manipulation; }
body {
  margin: 0;
  overflow-x: clip;
  color: var(--ink);
  font: 450 16px/1.45 Archivo, "Helvetica Neue", Arial, system-ui, sans-serif;
  -webkit-tap-highlight-color: transparent;
}
h1, h2, h3, p, dl, dd, ul { margin: 0; }
button { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--ink); outline-offset: 3px; }

/* Layout: one column on phones, brief beside the tray on wide screens.
   svh, not dvh: dvh grows as a phone's browser bar slides away, which resized the board on every frame of a scroll. */
.app {
  min-height: 100svh;
  max-width: 1120px;
  margin: 0 auto;
  padding: max(10px, env(safe-area-inset-top)) 16px max(8px, env(safe-area-inset-bottom));
  display: grid;
  grid-template: "top" auto "brief" auto "board" 1fr "dock" auto "foot" auto / minmax(0, 1fr);
  gap: 10px;
}
.top { grid-area: top; display: flex; flex-wrap: wrap; align-items: center; gap: 0 12px; }
.top > * { flex: none; max-width: 100%; }
.brief { grid-area: brief; display: flex; flex-wrap: wrap; gap: 4px 16px; align-items: flex-end; }
.brief > * { flex: 0 0 100%; }
.board { grid-area: board; }
.dock { grid-area: dock; }
footer { grid-area: foot; color: var(--soft); font-size: 13px; text-align: center; text-wrap: balance; }

.brand { display: flex; align-items: center; gap: 8px; font-size: 20px; font-weight: 650; font-stretch: 112%; letter-spacing: -.01em; }
.tabs { display: flex; flex-wrap: wrap; gap: 2px; margin-left: auto; }
.tabs button { border: 0; background: none; min-height: 44px; padding: 0 10px; font-weight: 500; color: var(--soft); cursor: pointer; }
.tabs button[aria-current] { color: var(--ink); box-shadow: inset 0 -2px 0 var(--ink); }
.tools { display: flex; }
.icon { width: 44px; height: 44px; border: 0; border-radius: var(--r); background: none; display: grid; place-items: center; cursor: pointer; }
svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: square; stroke-linejoin: miter; }
svg .dot { fill: currentColor; stroke: none; }
#sound[data-on=true] .off, #sound[data-on=false] .on { display: none; }

.which { color: var(--soft); }
.goal { flex: 1 0 0; min-width: min-content; font-size: clamp(27px, 7.4vw, 36px); font-weight: 600; line-height: 1.06; letter-spacing: -.02em; text-wrap: balance; }
.goal:focus { outline: none; }
.lesson { padding-right: max(0px, 100% - 60ch); margin-top: 4px; text-wrap: pretty; }
.counts { flex: none; max-width: 100%; display: flex; flex-wrap: wrap; gap: 0 18px; }
.counts div { display: flex; flex-direction: column-reverse; }
.counts dt { color: var(--soft); font-size: 14px; line-height: 1.2; }
.counts dd { font-size: 27px; font-weight: 600; line-height: 1; font-variant-numeric: tabular-nums; white-space: nowrap; }
/* Par in Endless until it is asked for: a small button where the number goes, as tall as the number, so nothing moves. */
.counts .reveal { display: block; height: 27px; padding: 0 8px; border: 1px solid var(--line); border-radius: var(--r); background: var(--paper); font-size: 15px; font-weight: 550; line-height: 1; cursor: pointer; }
.tries { display: flex; gap: 10px; list-style: none; margin: 6px 0 4px; padding: 0; }
.tries li { flex: 1; display: flex; gap: 2px; padding-bottom: 5px; border-bottom: 2px solid transparent; }
.tries li.now { border-color: var(--ink); }
.tries i { flex: 1; height: 12px; border-radius: 1px; background: var(--lane); }
.tries .used i { background: none; box-shadow: inset 0 0 0 1.5px var(--petrol); }
.tries .used i.hit { background: var(--petrol); }
.options { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 14px; }
.levels { display: flex; flex-wrap: wrap; gap: 4px; margin-left: -10px; }
.levels button { flex: none; border: 0; background: none; min-height: 40px; padding: 0 10px; border-radius: var(--r); color: var(--soft); font-weight: 500; cursor: pointer; }
.levels button[aria-pressed=true] { background: var(--paper); color: var(--ink); }
.switch { display: inline-flex; align-items: center; gap: 8px; min-height: 40px; cursor: pointer; }
.switch input { position: absolute; opacity: 0; }
.track { flex: none; width: 40px; height: 24px; border-radius: 12px; background: var(--line); position: relative; transition: background .15s; }
.track::after { content: ""; position: absolute; inset: 3px auto 3px 3px; width: 18px; border-radius: 50%; background: var(--cap); transition: transform .15s; }
input:checked + .track { background: var(--petrol); }
input:checked + .track::after { transform: translateX(16px); }
input:focus-visible + .track { outline: 3px solid var(--ink); outline-offset: 3px; }

/* Board. render() says how tall the tallest column is, and which column and row each block is in. Everything else
   happens here, so the blocks can't be out of step with the board. A row is as tall as fits, from 28px to 54px: when
   28px rows don't fit, the board grows and the page scrolls. The 23px is for the goal label and a lifted group.
   Blocks move by parts of their own size, so a change of place animates and a resize doesn't. */
.board {
  position: relative; container-type: inline-size; min-height: 250px; user-select: none; -webkit-user-select: none;
  --readout: 66px;
  --rows: calc(var(--tall, 6) + .45);
  --fit: calc((100cqh - 19px) / var(--rows));
  --bh: clamp(28px, var(--fit), 54px);
  display: grid; grid-template: minmax(calc(23px + var(--rows) * 28px), 1fr) auto / minmax(0, 1fr);
}
@supports (width: round(down, 1px, 1px)) { .board { --bh: clamp(28px, round(down, var(--fit), 1px), 54px); } }
.lanes { grid-area: 1 / 1 / 3 / 2; display: grid; grid-template: subgrid / repeat(4, minmax(0, 1fr)); column-gap: 2%; }
.lane { grid-row: 1 / 3; border: 0; padding: 0; background: none; display: grid; grid-template: subgrid / minmax(0, 1fr); text-align: center; cursor: pointer; border-radius: var(--r); outline-offset: 2px; }
.lane .well { background: var(--lane); border-radius: var(--r) var(--r) 0 0; border-bottom: 4px solid var(--ink); transition: background .15s; }
.lane.source .well, .lane.target .well { background: var(--lane-on); }
@media (hover: hover) { .holding .lane:hover .well { background: var(--lane-on); } }
.lane.target .well { box-shadow: inset 0 0 0 2px var(--ink); }
.readout { min-height: var(--readout); padding-top: 6px; line-height: 1.15; }
.readout b { display: block; font-size: min(22px, 6.6cqw); font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
.readout span { font-size: min(13px, 6.6cqw); color: var(--soft); display: block; text-wrap: balance; overflow-wrap: anywhere; }
.readout .match { color: var(--goal-ink); }
.lane.won .well { background: color-mix(in srgb, var(--goal-ink) 18%, var(--lane)); border-bottom-color: var(--goal-ink); }
.lane.won b { color: var(--goal-ink); }

/* Where blocks stand: the wells without their floor. */
.pit { grid-area: 1 / 1; margin-bottom: 4px; position: relative; container-type: size; pointer-events: none; }
.goalline { position: absolute; z-index: 5; left: -6px; right: -6px; bottom: 2px; height: var(--bh); translate: 0 calc((var(--goal, 5) - 1) * -100%); border-top: 2px solid var(--goal-ink); transition: translate .3s; }
.goalline span { position: absolute; right: calc(var(--in, 0) * .255 * (100% - 12px)); bottom: calc(100% + 2px); padding: 0 6px; background: var(--goal-ink); color: var(--ground); font-size: 13px; font-weight: 550; line-height: 1.5; white-space: nowrap; -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
.goalline .up { translate: 0 -10px; }

.blocks { position: absolute; inset: 0; }
.block { position: relative; isolation: isolate; display: grid; place-items: center; font-style: normal; font-weight: 600; font-stretch: 108%; font-size: calc(var(--bh) * .48); line-height: 1; font-variant-numeric: tabular-nums; letter-spacing: -.02em; border-radius: 2px; }
.block.num { color: var(--on-cap); }
.block.num::before { --c: calc(var(--bh) * .26); content: ""; position: absolute; inset: 0; z-index: -1; background: var(--cap); clip-path: polygon(var(--c) 0, calc(100% - var(--c)) 0, 100% var(--c), 100% 100%, 0 100%, 0 var(--c)); }
.block.add { background: var(--petrol); color: var(--on-petrol); }
.block.sub { background: var(--lane); color: var(--petrol); box-shadow: inset 0 0 0 2px var(--petrol); }
.block.mul { background: var(--dense); color: var(--on-dense); }
.blocks .block {
  position: absolute; bottom: 1px; left: 4px;
  width: calc(23.5% - 8px); height: calc(var(--bh) - 2px);
  font-size: max(14px, min(var(--bh) * .48, 8.3cqw));
  transform: translate(calc(var(--x) * 255 / 235 * (100% + 8px) + var(--dx, 0) * 1px), calc(var(--y) * (-100% - 2px) + var(--dy, 0) * 1px));
  translate: 0 calc(-1 * var(--lift, 0px));
  transition: .22s cubic-bezier(.2, .8, .2, 1);
  transition-property: transform, translate;
  pointer-events: auto; cursor: grab; touch-action: none;
}
.locked .blocks .block { cursor: default; }
.blocks .block.held { --lift: 12px; z-index: 10; filter: drop-shadow(0 6px 5px #0b151759); }
.blocks .block.drag { transition-property: translate; cursor: grabbing; pointer-events: none; }
.blocks .block.aim { outline: 2px dashed var(--goal-ink); outline-offset: 1px; z-index: 3; }
.blocks .block.cue { outline: 2px solid var(--goal-ink); outline-offset: 1px; z-index: 4; }
.blocks .block.pick { outline: 2px dashed var(--ink); outline-offset: 1px; }
.block.hop { animation: rise .45s ease-out calc(var(--i) * 80ms) both; }
@keyframes rise { 40% { translate: 0 -5px; } }
.loading { grid-area: 1 / 1; place-self: center; z-index: 1; color: var(--soft); }

/* While a puzzle loads, hold the space it will fill so nothing jumps. */
.which:empty::before, .goal:empty::before { content: "\200b"; }
.tries:empty { height: 19px; }
.board:has(.loading:not([hidden])) .goalline { visibility: hidden; }
.board:has(.loading:not([hidden])) ~ .dock { min-height: 153px; }
@media (scripting: none) { .loading { display: none; } }

/* A new board is simply there: nothing slides in from the last one. */
.instant .goalline, .instant .blocks .block { transition: none; }

/* Controls keep their place: nothing here moves while you play. */
.dock { display: grid; gap: 8px; align-content: start; }
.msg { min-height: 2.8em; display: flex; align-items: center; text-wrap: pretty; }
.msg.bad { color: var(--bad); }
.row { display: flex; flex-wrap: wrap; gap: 8px; }
.row + .row { margin-top: 8px; }
.btn { flex: 1; min-width: min-content; min-height: 48px; padding: 4px 10px; border: 1px solid var(--line); border-radius: var(--r); background: var(--paper); font-weight: 550; line-height: 1.1; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 6px; }
.btn svg { width: 20px; height: 20px; flex: none; }
.btn:active:not(:disabled) { background: var(--lane-on); color: var(--ink); }
.btn.strong, .btn[aria-pressed=true] { background: var(--ink); border-color: var(--ink); color: var(--ground); }
.btn:disabled { opacity: .5; cursor: default; background: none; color: inherit; border-color: var(--line); }
/* Borderless, so a small gap is enough: five fit on one line from 320px wide. */
.quiet { gap: 4px; }
.quiet .btn { background: none; border-color: transparent; min-height: 44px; padding-inline: 4px; white-space: nowrap; }
#endbtns .btn { white-space: nowrap; }
.quiet .btn.cue:not(:disabled) { border-color: var(--goal-ink); box-shadow: inset 0 0 0 1px var(--goal-ink); }
/* Start over: a quiet text button, last in the row, that drops to its own line when space runs out. */
.btn.minor { flex: 0 1 auto; background: none; border-color: transparent; }
.panel { display: grid; gap: 10px; min-height: 104px; align-content: center; }
.headline { font-size: 21px; font-weight: 600; line-height: 1.15; letter-spacing: -.01em; }
.stepper { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.stepper .btn { flex: 0 0 52px; font-size: 22px; }
.stepper .btn.strong { flex: 1; font-size: 16px; }
.stepper output { flex: none; min-width: 48px; text-align: center; font-size: 30px; font-weight: 600; line-height: 1; }

.link { border: 0; padding: 6px 4px; background: none; color: inherit; text-decoration: underline; text-underline-offset: 3px; cursor: pointer; white-space: nowrap; }
.link:hover { color: var(--ink); }
#aboutbox p { margin-top: 10px; text-wrap: pretty; }

.countdown { color: var(--soft); font-variant-numeric: tabular-nums; }
.chart { width: 100%; border-collapse: collapse; margin-top: 18px; font-variant-numeric: tabular-nums; }
.chart caption { text-align: left; font-weight: 700; margin-bottom: 6px; }
.chart th { width: 1%; padding: 3px 12px 3px 0; text-align: left; font-weight: 500; }
.chart td { display: flex; align-items: center; gap: 8px; padding: 3px 0; }
.chart i { width: calc(var(--w) * (100% - 40px)); min-width: 2px; height: 18px; background: var(--petrol); }
.chart .today th, .chart .today span { font-weight: 700; }

dialog { border: 0; border-radius: 6px; padding: 24px; width: min(560px, calc(100vw - 24px)); max-height: calc(100dvh - 24px); background: var(--paper); color: var(--ink); }
dialog::backdrop { background: #0b1517a6; }
dialog h2 { padding-right: 36px; font-size: 24px; font-weight: 600; letter-spacing: -.015em; margin-bottom: 8px; }
dialog h3 { font-size: 18px; margin: 18px 0 8px; }
dialog ul { padding-left: 20px; }
dialog li { margin: 6px 0; }
dialog .row { margin-top: 18px; }
.close { position: absolute; top: 14px; right: 14px; }
#soundbox { width: min(360px, calc(100vw - 24px)); }
#soundbox .switch { display: flex; min-height: 44px; }
.volume { display: grid; margin-top: 8px; }
.volume input { width: 100%; height: 44px; margin: 0; accent-color: var(--petrol); }
#musicmsg:not(:empty) { margin-top: 10px; color: var(--bad); }
#soundbox .tip { margin-top: 10px; color: var(--soft); font-size: 14px; }
.example { display: grid; grid-template-columns: 76px 1fr; gap: 18px; align-items: center; margin: 14px 0; --bh: 38px; }
.pile { background: var(--lane); display: grid; gap: 2px; border-bottom: 4px solid var(--ink); padding: 0 4px 2px; }
.pile .block { height: 35px; }
.keys { margin-top: 14px; color: var(--soft); font-size: 14px; line-height: 1.8; }
kbd { font: inherit; color: var(--ink); border: 1px solid var(--line); border-radius: 3px; padding: 1px 6px; }
@media (hover: none) { .keys { display: none; } }

@media (max-width: 420px) {
  .brand { font-size: 18px; gap: 6px; }
  .brand img { width: 24px; height: 24px; }
  .top { gap: 4px; }
  .tabs button { padding: 0 5px; }
  .tools { flex: 1 1 52px; max-width: 80px; }
  .icon { width: 40px; }
  .btn { padding: 4px 6px; font-size: 15px; }
}
@media (max-width: 389px) {
  .brand { font-size: 16px; }
  .tabs { gap: 0; }
  .tabs button { padding: 0 4px; }
}
@media (max-width: 359px) { .brand { font-size: 0; } }
@media (min-width: 900px) {
  .app {
    grid-template: "top top" auto "brief board" auto "dock board" 1fr "foot foot" auto / 320px minmax(0, 1fr);
    gap: 22px 48px; padding-inline: 32px; padding-top: 18px; min-height: min(100svh, 900px);
  }
  .board { min-height: 480px; }
  .brief { flex-flow: column; align-items: stretch; gap: 14px; }
  .brief > * { flex: none; }
  .goal { font-size: 46px; }
  .counts dd { font-size: 34px; }
  .counts .reveal { height: 34px; }
  .tabs { margin-left: 28px; }
  .tools { margin-left: auto; }
  .hold .btn { flex: 1 1 40%; }
  .hold #fliphere { flex-basis: 100%; }
  .board { --readout: 70px; }
  .readout b { font-size: 26px; }
  .readout span { font-size: 15px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

.nb { white-space: nowrap; }
.sr { position: absolute; top: 0; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
