:root{--bg:#f3efe5;--paper:#fbf8f0;--ink:#1f2422;--muted:#6e746f;--line:#cec8bb;--blue:#315f89;--blue-soft:#dbe8f2;--red:#94463f;--red-soft:#f2d9d4;--gold:#b88a3b;--green:#3b7654;--wall:#8f897d;--shadow:0 18px 50px rgba(31,36,34,.12)}
*{box-sizing:border-box}
html,body{height:100%;margin:0;overscroll-behavior:none}
body{color:var(--ink);background:radial-gradient(circle at 20% 5%,rgba(255,255,255,.75),transparent 26rem),var(--bg);font-family:Inter,ui-sans-serif,system-ui,-apple-system,BlinkMacSystemFont,"Segoe UI",sans-serif;overflow:hidden;-webkit-tap-highlight-color:transparent}

/* One screen: header, then the stage (status line, board, controls); nothing scrolls. One column that never grows past the screen for its content: a long label shortens instead (below). */
.app{height:100vh;height:100dvh;display:grid;grid-template-columns:minmax(0,1fr);grid-template-rows:auto minmax(0,1fr);gap:clamp(6px,1.2vh,14px);padding:0 clamp(10px,2vw,24px) clamp(10px,1.6vh,18px)}
/* viewport-fit=cover draws under a phone's notch and home bar: keep content inside the safe area. */
@supports (padding:max(0px)){.app{padding-left:max(clamp(10px,2vw,24px),env(safe-area-inset-left));padding-right:max(clamp(10px,2vw,24px),env(safe-area-inset-right));padding-bottom:max(clamp(10px,1.6vh,18px),env(safe-area-inset-bottom))}}
/* The header: Back to all the games and the game's name on the left, the timer in the middle, the board's label and
   help on the right. The sides share what the timer leaves, so it stays in the middle; a long name or label ends in
   an ellipsis. */
.top{display:grid;grid-template-columns:minmax(0,1fr) auto minmax(0,1fr);align-items:center;gap:12px;padding-top:clamp(8px,1.6vh,16px)}
.brand{justify-self:start;display:flex;align-items:center;gap:10px;min-width:0;max-width:100%}
/* Back is a round button, as help is: a link that looks like one. */
.back{flex:none;border:1px solid var(--line);background:#fff;color:var(--ink)}
.back svg{width:20px;height:20px;fill:none;stroke:currentColor;stroke-width:2.4;stroke-linecap:round;stroke-linejoin:round}
/* The label gives way before the page ever widens: a long one ends in an ellipsis. */
.board-label{flex:0 1 auto;min-width:0;overflow:hidden;text-overflow:ellipsis;font-size:11px;font-weight:800;letter-spacing:.08em;text-transform:uppercase;color:var(--gold);white-space:nowrap}
.board-label:empty{display:none}
/* Free play's level switch: today's board at each level. */
.levels{display:flex;border:1px solid var(--line);border-radius:999px;overflow:hidden;background:#fff}
.levels[hidden]{display:none}
.levels a{padding:6px 10px;font-size:13px;font-weight:700;color:var(--muted);text-decoration:none}
.levels a[aria-current="page"]{background:var(--ink);color:#fff}
.name{font-family:Georgia,"Times New Roman",serif;font-weight:600;font-size:clamp(18px,2.4vw,26px);white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.top-actions{justify-self:end;display:flex;align-items:center;gap:8px;min-width:0;max-width:100%}
.top-actions .round{flex:none}
button{font:inherit;border:1px solid var(--line);border-radius:11px;background:#fff;color:var(--ink);padding:9px 13px;cursor:pointer;font-weight:700;touch-action:manipulation}
button:disabled{opacity:.35;cursor:not-allowed}
button.primary{background:var(--ink);color:#fff;border-color:var(--ink)}
button.wide{width:100%;margin-top:8px}
.round{width:38px;height:38px;padding:0;border-radius:50%;display:grid;place-items:center;font-size:17px;font-family:Georgia,serif}

/* The status line, then the board, then the controls, in a column as wide as the stage and no wider: the strip's one
   line never widens it, which would widen the room beside the board, the strip's margins, and so on without end. */
.stage{display:grid;grid-template-columns:minmax(0,1fr);grid-template-rows:auto minmax(0,1fr) auto;min-height:0;gap:clamp(6px,1.2vh,12px);max-width:560px;width:100%;margin:0 auto}
/* Every game's page has the same rows from the top: the header, the status line, the board at the top of its room, and
   the controls closed up to the board. So the level switch, a duel's strip, and the board's top are in the same place
   in each game, and any height left over goes below. What lines up with the board comes in by the room beside it,
   which src/shared/board-room.ts measures, so its edges are the board's; the controls close up by the room below it,
   in how they are drawn rather than in the layout, which would change the room. */
.controls{margin-inline:var(--board-inset-x,0px);translate:0 calc(-1 * var(--board-room-below,0px))}
/* Free play: today's level switch, from the board's left edge. Under it, on a line of its own, a note when a duel can't
   open here, or why the page failed to load: centered, as wide as its text needs, so its lines never hang on the
   board's width, which hangs on them. */
.status-line{display:flex;flex-wrap:wrap;align-items:center;gap:6px 10px;min-height:32px}
.status-line .levels{margin-left:var(--board-inset-x,0px)}
.status-line .duel-strip{order:1;flex:1 0 100%;margin-inline:auto}
/* On a duel board the strip takes the switch's place, as wide as the board: one line, which crawls when its text is
   longer (src/shared/crawl.ts), and holding its place while hidden, before Start and after the try, so the board never
   moves. */
.status-line.duel .duel-strip{order:0;flex:1 1 0;min-width:0;max-width:none;margin:0 var(--board-inset-x,0px);box-sizing:content-box;min-height:1lh;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.status-line.duel .duel-strip[hidden]{display:block;visibility:hidden}
.timer{font-variant-numeric:tabular-nums;font-weight:700;color:var(--ink);font-size:16px;white-space:nowrap}
.timer.short{color:var(--red)}
/* Under the board, at its right edge: how far the board has come. One line tall even while empty, so it never moves
   the controls under it when it fills. */
.count{justify-self:end;min-height:1lh;font-size:14px;color:var(--muted);font-variant-numeric:tabular-nums;white-space:nowrap}
/* Under a duel's cover there's nothing to count yet, and a cover taller than a wide board reaches down over the count. */
.stage:has(.duel-cover:not([hidden])) .count{visibility:hidden}

/*
 * The board keeps its shape and is as large as the space allows: container units size it. Swipes on it never scroll,
 * zoom, or select, and a margin keeps it clear of the screen's edges, where iOS swipes back.
 */
.board-shell{container-type:size;display:grid;place-items:start center;min-height:0;min-width:0;padding:0 4px}
.frame{--cols:7;--rows:7;position:relative;width:min(100%,80vmin);width:min(100cqw,calc(100cqh * var(--cols) / var(--rows)));aspect-ratio:var(--cols)/var(--rows)}
/* Only the board, not the frame: the duel's cover, with its name field, goes in the frame too. */
.board{position:absolute;inset:0;display:grid;grid-template-columns:repeat(var(--cols),minmax(0,1fr));grid-template-rows:repeat(var(--rows),minmax(0,1fr));cursor:pointer;touch-action:none;user-select:none;-webkit-user-select:none;-webkit-touch-callout:none}
.t{position:relative;min-width:0;min-height:0}
.t.wall{background:var(--wall);border-radius:3px;box-shadow:inset 0 -3px 0 rgba(31,36,34,.2)}
.t.floor{background:var(--paper);box-shadow:inset 0 0 0 .5px rgba(31,36,34,.09)}
.t.goal::after{content:"";position:absolute;inset:31%;border-radius:50%;border:max(2px,.5cqmin) solid var(--gold);background:rgba(184,138,59,.14)}
.sprite{position:absolute;left:0;top:0;width:calc(100% / var(--cols));height:calc(100% / var(--rows));transform:translate(calc(var(--c,0) * 100%),calc(var(--r,0) * 100%));transition:transform 80ms ease-out;pointer-events:none}
.sprite svg{width:100%;height:100%;display:block}
.crate{fill:#c99a4b;stroke:#7a5524;stroke-width:6}
.slats{fill:none;stroke:#7a5524;stroke-width:7;stroke-linecap:round}
.box.home .crate{fill:#79ad87;stroke:#2f5f43}
.box.home .slats{stroke:#2f5f43}
.you-fill{fill:var(--blue)}
@media (prefers-reduced-motion:reduce){.sprite{transition:none!important}}

.overlay{position:absolute;inset:0;display:grid;place-items:center;background:rgba(243,239,229,.55);backdrop-filter:blur(1.5px);border-radius:10px;z-index:5}
.overlay[hidden]{display:none}
.overlay .card{background:#fff;border:1px solid var(--line);border-radius:16px;padding:16px 20px;text-align:center;box-shadow:var(--shadow);max-width:84%}
.overlay.solved .card{border-color:var(--green)}
.overlay.stopped .card{border-color:var(--red)}
.overlay h2{font-family:Georgia,serif;margin:0 0 4px;font-size:clamp(20px,6cqw,28px)}
.overlay p{margin:0 0 12px;color:var(--muted);font-size:15px}
.btns{display:flex;gap:8px;justify-content:center}

/* Controls: the four arrows, then Undo, Restart, and, in a duel, Give up. */
.controls{display:grid;gap:8px}
.arrows{display:grid;grid-template-columns:repeat(4,minmax(0,1fr));gap:6px}
.arrows button{font-size:22px;line-height:1;padding:8px 0;color:var(--blue)}
.tools{display:grid;grid-auto-flow:column;grid-auto-columns:minmax(0,1fr);gap:8px}
.tools .give-up{color:var(--red);border-color:var(--red-soft)}
.tools button[hidden]{display:none}
.sr-only{position:absolute;width:1px;height:1px;padding:0;margin:-1px;overflow:hidden;clip:rect(0,0,0,0);white-space:nowrap;border:0}

/* Help sheet. */
.modal{position:fixed;inset:0;display:grid;place-items:center;background:rgba(31,36,34,.45);z-index:20;padding:16px}
.modal[hidden]{display:none}
.sheet{background:var(--paper);border-radius:18px;padding:20px 22px;max-width:440px;width:100%;max-height:92vh;max-height:92dvh;overflow:auto;box-shadow:var(--shadow)}
.sheet h2{font-family:Georgia,serif;margin:0 0 8px;font-size:22px}
.sheet .lead{margin:0 0 10px;font-size:15px;line-height:1.5}
.rules{margin:0 0 10px;padding-left:18px;font-size:14px;line-height:1.5;color:var(--muted)}
.rules b{color:var(--ink)}
.tiny{font-size:12px;color:var(--muted);line-height:1.5;margin:6px 0}
@media (hover:none){.hover-only{display:none}}

@media (max-width:420px){.name{display:none}.levels a{padding:6px 8px}}

/* Short landscape screens: the board on the left, the controls on the right. */
@media (max-height:540px) and (orientation:landscape){
  .stage{max-width:none;grid-template-columns:minmax(0,1fr) minmax(220px,300px);grid-template-rows:auto minmax(0,1fr)}
  .status-line{grid-column:1/-1}
  .board-shell{grid-row:2;grid-column:1}
  /* Beside the board, at its top and as tall as it, their middle level with its middle: the board sits in the middle of
     its column across, so the controls move left by the room beside it, and the two keep the column gap between them. */
  .controls{grid-column:2;grid-row:2;align-self:start;height:var(--board-height,100%);align-content:center;margin-inline:calc(-1 * var(--board-inset-x,0px)) var(--board-inset-x,0px);translate:none}
}

/* Duels (src/duel/page.ts): the cover over a duel board, the strip above it, and the results sheet. Every game's
   export appends this to its stylesheet; it uses the color tokens and the .modal, .sheet, .btns, and .tiny styles
   each game defines. */

/* The cover hides a duel board until Start, so nobody studies it off the clock. Over a board shorter than its card, a
   wide Sokoban's on a phone, it grows down over what's below the board, as far as the board's area goes (100cqh, the
   height of the board-shell the board sits at the top of), and scrolls past that. */
.duel-cover{position:absolute;inset:0 0 auto;min-height:100%;max-height:100cqh;display:grid;place-items:safe center;overflow:auto;background:var(--paper);border:2px solid var(--ink);border-radius:14px;z-index:6;padding:14px}
.duel-cover[hidden]{display:none}
.duel-cover .card{max-width:340px;text-align:center;display:grid;gap:8px}
.duel-cover .kicker{margin:0;font-size:11px;font-weight:800;letter-spacing:.1em;text-transform:uppercase;color:var(--gold)}
.duel-cover h2{margin:0;font-family:Georgia,serif;font-size:clamp(20px,6cqw,28px);line-height:1.2}
.duel-cover p{margin:0;color:var(--muted);font-size:13px;line-height:1.45}
.duel-cover p.lead{font-size:15px}
.duel-cover p b{color:var(--ink)}
.duel-cover button{justify-self:center;min-width:140px;margin:4px 0;font-size:16px;padding:11px 20px}
/* Your name, asked before Start: 16px, so iOS doesn't zoom in on it. */
.duel-cover .field{display:block;margin:6px 0 -4px;font-weight:700;font-size:13px;text-align:left;color:var(--ink)}
.duel-cover input{display:block;width:100%;font:inherit;font-size:16px;border:1px solid var(--line);border-radius:10px;padding:9px 11px;background:#fff;color:var(--ink)}
.duel-cover .status{color:var(--red);font-size:13px}
/* Live regions stay in the page while empty, so what arrives in them is announced. */
.duel-cover .status:empty{display:block;margin:0}
.duel-cover .more{display:grid;gap:6px}

/* The strip names the stake and what to beat while the try counts. */
.duel-strip{margin:0;max-width:640px;text-align:center;color:var(--muted);font-size:clamp(12.5px,1.5vw,14px);line-height:1.45;background:var(--paper);border:1px solid var(--gold);border-radius:12px;padding:6px 12px}
.duel-strip b{color:var(--ink)}
.duel-strip[hidden]{display:none}

/* Results: the stake's answer first, then the verdict, the standings, where your result stands, and the message with
   Copy. The verdict and the status line stay in the page while empty, so what arrives in them is announced. */
.duel-sheet .results .verdict{margin:0 0 6px;font-weight:700;font-size:15px}
.duel-sheet .results .verdict:empty{margin:0}
.duel-sheet .stake-answer{margin:4px 0 10px;padding:10px 12px;border:1px solid var(--gold);border-radius:12px;background:#fff}
.duel-sheet .stake-answer[hidden]{display:none}
.duel-sheet .stake-answer .line{margin:0;font-size:13px;color:var(--muted)}
.duel-sheet .stake-answer .a{margin:2px 0 0;font-family:Georgia,serif;font-size:20px;line-height:1.3}
.duel-sheet .standings{list-style:none;margin:8px 0 6px;padding:0;display:grid;gap:4px;max-height:28vh;max-height:28dvh;overflow:auto}
.duel-sheet .standings li{display:grid;grid-template-columns:2.6em minmax(0,1fr) auto;gap:8px;align-items:center;padding:6px 10px;border:1px solid var(--line);border-radius:10px;background:#fff;font-size:14px}
.duel-sheet .standings li.me{border-color:var(--ink);box-shadow:inset 0 0 0 1px var(--ink)}
.duel-sheet .standings .rank{font-weight:800;color:var(--muted)}
.duel-sheet .standings .who{min-width:0;overflow-wrap:anywhere;font-weight:600}
.duel-sheet .standings .who small{display:inline-block;white-space:nowrap;margin-left:6px;font-size:10.5px;font-weight:800;letter-spacing:.06em;text-transform:uppercase;color:var(--gold)}
.duel-sheet .standings .what{white-space:nowrap;color:var(--muted);font-size:13px}
.duel-sheet .field{display:block;margin:12px 0 4px;font-weight:700;font-size:14px}
.duel-sheet textarea{display:block;width:100%;font:inherit;font-size:16px;border:1px solid var(--line);border-radius:10px;padding:8px 10px;background:#fff;color:var(--ink)}
.duel-sheet textarea{font-family:ui-monospace,SFMono-Regular,Menlo,monospace;font-size:13px;line-height:1.45;resize:none;margin-bottom:8px}
@media (hover:none){.duel-sheet textarea{font-size:16px}}
.duel-sheet .send{margin:2px 0 6px}
.duel-sheet .send:empty{display:block;margin:0}
.duel-sheet .tiny.warn{color:var(--red)}
.duel-sheet .tiny.warn[hidden]{display:none}
/* Copy stays in reach while the sheet scrolls on a small phone. */
.duel-sheet .sheet-actions{position:sticky;bottom:-20px;margin:0 -22px -20px;padding:10px 22px 14px;background:var(--paper);border-top:1px solid var(--line)}
.duel-sheet .sheet-actions .tiny{margin:6px 0 0}
.duel-sheet .btns{justify-content:flex-end;flex-wrap:wrap}
.duel-sheet .btns button,.duel-sheet .btns a.button{min-width:88px}
a.button{display:inline-grid;place-items:center;font:inherit;font-weight:700;border:1px solid var(--line);border-radius:11px;background:#fff;color:var(--ink);padding:9px 13px;text-decoration:none}

/* The duel page (src/duel/setup.ts): a game with its usual time, the stake, your name, and Create the duel; then the
   duel's one link, ready to send; and Your duels. */
.duel-setup{display:grid;gap:28px}
.duel-setup .form{display:grid;gap:20px}
.duel-setup fieldset{border:0;margin:0;padding:0;display:grid;gap:8px;min-width:0}
.duel-setup legend{font-weight:800;font-size:15px;padding:0;margin-bottom:8px}
.duel-setup .choice{display:flex;align-items:center;gap:12px;padding:12px 14px;border:1px solid var(--line);border-radius:12px;background:#fff;cursor:pointer}
.duel-setup .choice:has(input:checked){border-color:var(--ink);box-shadow:inset 0 0 0 1px var(--ink)}
.duel-setup .choice:has(input:disabled){opacity:.55;cursor:not-allowed}
.duel-setup .choice input{width:18px;height:18px;margin:0;accent-color:var(--ink);flex:none}
.duel-setup .choice .text{display:grid;gap:2px;min-width:0}
.duel-setup .choice .label{font-weight:700}
.duel-setup .choice .about{font-size:13px;color:var(--muted)}
.duel-setup .chips{display:flex;flex-wrap:wrap;gap:8px}
.duel-setup .chip{border-radius:999px;padding:8px 14px;font-weight:600;font-size:14px}
.duel-setup .chip[aria-pressed="true"]{background:var(--ink);color:#fff;border-color:var(--ink)}
.duel-setup .own{display:grid;gap:8px;margin-top:6px}
.duel-setup .own[hidden]{display:none}
.duel-setup .own-line{display:flex;align-items:center;gap:8px;font-weight:700}
.duel-setup input[type=text],.duel-setup select{font:inherit;font-size:16px;border:1px solid var(--line);border-radius:10px;padding:10px 12px;background:#fff;color:var(--ink);width:100%;min-width:0}
.duel-setup .own-line input{flex:1}
.duel-setup .own-line select{width:auto;flex:none}
.duel-setup .go{font-size:17px;padding:14px 20px;border-radius:999px;width:100%}
.duel-setup .status{color:var(--red);font-size:14px;margin:8px 0 0}
/* Kept in the page while empty, so what arrives in it is announced; it takes no room. */
.duel-setup .status:empty{display:block;margin:0}
.duel-setup .ready{display:grid;gap:12px;padding:18px;border:1px solid var(--ink);border-radius:14px;background:#fff}
.duel-setup .ready h2{margin:0;font-family:Georgia,serif;font-size:24px;line-height:1.2}
.duel-setup .ready h2:focus{outline:none}
.duel-setup .ready .lead{margin:0;color:var(--muted);font-size:15px}
.duel-setup .ready textarea{display:block;width:100%;font-family:ui-monospace,SFMono-Regular,Menlo,monospace;font-size:13px;line-height:1.45;border:1px solid var(--line);border-radius:10px;padding:8px 10px;background:var(--paper);color:var(--ink);resize:none}
@media (hover:none){.duel-setup .ready textarea{font-size:16px}}
.duel-setup .ready .btns{display:flex;gap:8px;flex-wrap:wrap}
.duel-setup .ready .btns > *{flex:1;min-width:120px;font-size:16px;padding:12px 16px}
.duel-setup .ready .warn{color:var(--red)}
.duel-setup .ready .warn[hidden]{display:none}
.duel-setup .ready > a.tiny{justify-self:start;color:var(--muted)}
/* Your duels: each with its game, its stake, and who has finished. */
.duel-setup .yours{display:grid;gap:10px}
.duel-setup .yours[hidden]{display:none}
.duel-setup .yours h2{margin:0;font-size:15px;font-weight:800}
.duel-list{list-style:none;margin:0;padding:0;display:grid;gap:6px}
.duel-list a{display:grid;gap:2px;padding:10px 14px;border:1px solid var(--line);border-radius:12px;background:#fff;color:var(--ink);text-decoration:none}
.duel-list a:hover{border-color:var(--ink)}
.duel-list .label{font-weight:700}
.duel-list .detail{font-size:13px;color:var(--muted);overflow-wrap:anywhere}
/* A name this device already has, in place of the name field (name.ts); hidden parts stay hidden whatever they show as. */
.duel-cover [hidden],.duel-setup [hidden]{display:none}
.duel-cover p.known-name,.duel-setup .known-name{margin:2px 0;font-size:15px;color:var(--ink)}
.known-name bdi{font-weight:700}
.duel-cover .known-name button,.duel-setup .known-name button{font:inherit;font-weight:600;color:var(--ink);background:none;border:0;border-radius:0;padding:0;margin:0;min-width:0;text-decoration:underline;text-underline-offset:3px;cursor:pointer}
