/* Keyline. The play surface is the canvas (render.mjs: the keyboard in the mark's cells); around it the page keeps
 * solid graphite tones, readable words (14px and up) and the shared tempos: 70ms presses, 180ms state changes, 240ms
 * entrances. The palette's keys look like the board's: a light keycap with its legend in the colour of what it sends,
 * on a key of the page; the chosen one is ringed in ink. The board is about 2:1 (86 × 42 cells) on a wide window and
 * turns upright on a phone held upright (render.mjs turns the picture to match the box). */
.keyline-page{--kl-ground:#181818;--kl-plate:#222222;--kl-key:#2b2b2b;--kl-key-band:#1f1f1f;--kl-ink:#ededed;--kl-muted:#a3a3a3;--kl-short:#f2958c;--kl-ratio:2.0476}

/* The board: the shared frame round the canvas. Moves on it are the game's, so the page scrolls from outside it. */
.keyline-page .keyline-board{position:relative;touch-action:none;container:kl-board / size;-webkit-user-select:none;user-select:none;-webkit-touch-callout:none;-webkit-tap-highlight-color:transparent;cursor:pointer}
.keyline-page .keyline-board:is([data-card],[data-mode=ending]){cursor:default;touch-action:pinch-zoom}
.keyline-page .keyline-board[data-pulling=true]{cursor:cell}
.keyline-canvas{display:block;width:100%;height:100%;border-radius:10px;background:var(--kl-ground)}
.keyline-page .keyline-board:focus{outline:none}
.keyline-page .keyline-board:focus-visible{outline:2px solid #d6d6d6;outline-offset:2px}

/* Cards over the board: the round chooser, a pause, a clear, a loss. */
.kl-card{position:absolute;left:50%;top:50%;z-index:4;display:flex;flex-direction:column;align-items:center;box-sizing:border-box;width:min(400px,calc(100% - 24px));max-height:calc(100% - 24px);overflow:auto;padding:22px 18px 20px;border-radius:18px;background:var(--kl-plate);box-shadow:0 4px 12px #00000047;color:var(--kl-ink);text-align:center;transform:translate(-50%,-50%);scrollbar-width:none}
.kl-card[hidden]{display:none}
.kl-card::-webkit-scrollbar{display:none}
.kl-card.is-entering{animation:kl-card-in 240ms cubic-bezier(.2,.8,.2,1) both}
@keyframes kl-card-in{from{opacity:0;transform:translate(-50%,calc(-50% + 8px))}to{opacity:1;transform:translate(-50%,-50%)}}
.kl-card-eyebrow{margin:0 0 6px;font-size:14px;line-height:1.4;color:var(--kl-muted)}
.kl-card h2{margin:0;font-size:26px;line-height:1.2;font-weight:400;letter-spacing:-.02em}
.kl-card-detail{margin:8px 0 0;font-size:14px;line-height:1.5;color:var(--kl-muted)}
.kl-levels{display:flex;flex-wrap:wrap;justify-content:center;gap:7px;margin:18px 0 0}
.kl-levels[hidden]{display:none}
.kl-level{position:relative;display:grid;place-items:center;width:44px;height:44px;padding:0;border:0;border-radius:11px;background:var(--kl-key);box-shadow:inset 0 -3px 0 var(--kl-key-band);color:#d8d8d8;font:500 16px/1 var(--sans);font-variant-numeric:tabular-nums;cursor:pointer;transition:background-color 180ms,color 180ms,transform 70ms}
.kl-level:hover:enabled{background:#333333}
.kl-level:active:enabled{transform:translateY(1px)}
.kl-level[aria-pressed=true]{background:var(--kl-ink);box-shadow:inset 0 -3px 0 #cecece;color:#181818}
.kl-level[data-state=cleared]::after{content:'';position:absolute;bottom:8px;width:4px;height:4px;border-radius:1px;background:currentColor;opacity:.55}
.kl-level:disabled{background:#1e1e1e;box-shadow:none;color:#5e5e5e;cursor:default}
.kl-card-actions{display:flex;flex-wrap:wrap;justify-content:center;gap:8px;margin-top:20px;width:100%}
.kl-card-actions .kl-button{flex:1 1 0;min-width:0}
.kl-card-actions .kl-button.is-primary{flex-basis:100%}
.kl-button{display:inline-flex;align-items:center;justify-content:center;gap:8px;min-width:88px;height:44px;padding:0 16px;border:0;border-radius:11px;background:var(--kl-key);box-shadow:inset 0 -3px 0 var(--kl-key-band);color:#dcdcdc;font:500 15px/1 var(--sans);cursor:pointer;transition:background-color 180ms,transform 70ms}
.kl-button:hover{background:#333333}
.kl-button:active{transform:translateY(1px)}
.kl-button.is-primary{background:var(--kl-ink);box-shadow:inset 0 -3px 0 #c4c4c4;color:#1c1c1c}
.kl-button.is-primary:hover{background:#ffffff}

/* How to play: words at reading size on every screen. */
.keyline-page .game-help>summary,.keyline-page .game-help .rules-list li,.keyline-page .game-help .rules-list li span{font-size:14px}

/* The numbers: energy leads (it pays for every key), and flashes when a key costs more than there is. */
.keyline-page .stats-row .stat-value{font-variant-numeric:tabular-nums;transition:color 180ms}
.keyline-page .kl-energy[data-short=true] .stat-value{color:var(--kl-short)}
.keyline-page .game-status{font-size:14px;line-height:1.4;color:var(--kl-muted)}

/* The palette: one key for each key the round allows, with its legend on a light cap and its cost. */
.kl-palette{display:flex;align-items:center;gap:6px;min-width:0}
.kl-pick{position:relative;display:inline-flex;align-items:center;gap:8px;height:48px;padding:0 10px 0 8px;border:0;border-radius:11px;background:var(--kl-key);box-shadow:inset 0 -3px 0 var(--kl-key-band);color:#dcdcdc;font:500 14px/1 var(--sans);cursor:pointer;transition:background-color 180ms,box-shadow 180ms,transform 70ms}
.kl-pick[hidden]{display:none}
.kl-pick:hover{background:#333333}
.kl-pick:active{transform:translateY(1px);box-shadow:inset 0 -1px 0 var(--kl-key-band)}
.kl-pick[aria-pressed=true]{background:#383838;box-shadow:inset 0 -3px 0 var(--kl-key-band),0 0 0 2px var(--kl-ink)}
.kl-glyph{display:grid;place-items:center;min-width:30px;height:30px;padding:0 4px;box-sizing:border-box;border-radius:8px;background:#cecece;box-shadow:inset 0 -3px 0 #6e6e6e}
.kl-glyph svg{display:block;margin-bottom:3px}
.kl-cost{font-variant-numeric:tabular-nums;color:var(--kl-muted)}
.kl-pick[aria-disabled=true] .kl-cost{color:var(--kl-short)}
.kl-pick[aria-disabled=true] .kl-glyph{background:#9d9d9d}
.kl-tools{display:flex;align-items:center;gap:8px;min-width:0}
.keyline-panel{container:kl-panel / inline-size}
@container kl-panel (max-width:720px){.kl-pick .kl-name{position:absolute;width:1px;height:1px;overflow:hidden;clip-path:inset(50%);white-space:nowrap}}
.kl-key{position:relative;display:inline-flex;align-items:center;justify-content:center;min-width:64px;height:44px;padding:0 14px;border:0;border-radius:11px;background:var(--kl-key);box-shadow:inset 0 -3px 0 var(--kl-key-band);color:#dcdcdc;font:500 14px/1 var(--sans);cursor:pointer;transition:background-color 180ms,transform 70ms}
.kl-key:hover{background:#333333}
.kl-key:active{transform:translateY(1px);box-shadow:inset 0 -1px 0 var(--kl-key-band)}
.kl-key[aria-pressed=true]{background:var(--kl-ink);box-shadow:inset 0 -3px 0 #c4c4c4;color:#1c1c1c}
.kl-key[aria-disabled=true]{color:#6e6e6e}
.kl-pick:focus-visible,.kl-key:focus-visible,.kl-card button:focus-visible{outline:2px solid #d6d6d6;outline-offset:3px}
/* A short board (a phone on its side): the card tightens round the same keys. */
@container kl-board (max-height:360px){
  .kl-card{padding:14px 14px 14px}
  .kl-card h2{font-size:22px}
  .kl-card-eyebrow{margin-bottom:2px}
  .kl-card-detail{margin-top:4px}
  .kl-levels{margin-top:10px}
  .kl-card-actions{margin-top:12px}
}
@media (prefers-reduced-motion:reduce){.kl-level,.kl-button,.kl-key,.kl-pick,.keyline-page .stats-row .stat-value{transition:none}.kl-key:active,.kl-pick:active,.kl-button:active,.kl-level:active:enabled{transform:none}.kl-card.is-entering{animation:none}}
@media (forced-colors:active){
  .keyline-page .keyline-board{outline:1px solid CanvasText}
  .kl-key,.kl-button,.kl-level,.kl-pick{outline:1px solid CanvasText}
  .kl-pick[aria-pressed=true],.kl-key[aria-pressed=true]{outline:3px solid Highlight}
  .kl-card{border:1px solid CanvasText}
  .kl-glyph{forced-color-adjust:none}
}

/* ── Wider windows: one panel, the numbers, the words and the tools along its top, the board, then the palette under
   it like a keyboard's bottom row ──────────────────────────────────────────────────────────────────────────────── */
@media (min-width:761px) and (min-height:501px), (min-width:1001px) {
  .keyline-page .play-layout.keyline-layout{display:block;max-width:1180px;margin:0 auto}
  .keyline-page .keyline-layout .game-intro{margin:0 0 14px}
  .keyline-page .keyline-layout .game-intro h1{font-size:26px;line-height:1.15;margin:0 0 4px}
  .keyline-page .keyline-panel{display:grid;grid-template-columns:auto minmax(0,1fr) auto;grid-template-rows:auto auto auto;gap:12px 16px;align-items:center}
  .keyline-page .keyline-panel .game-panel-bottom{display:contents}
  .keyline-page .keyline-panel .stats-row{grid-column:1;grid-row:1;display:flex;gap:18px;margin:0}
  .keyline-page .keyline-panel .stats-row>div{display:flex;flex-direction:column;gap:2px;min-width:0}
  .keyline-page .stat-label{font-size:14px;line-height:18px}
  .keyline-page .stat-value{font-size:24px;line-height:28px}
  .keyline-page .keyline-panel .game-status{grid-column:2;grid-row:1;min-width:0;text-align:right;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
  .keyline-page .keyline-panel .kl-tools{grid-column:3;grid-row:1}
  .keyline-page .keyline-panel .board-container.keyline-board{grid-column:1 / -1;grid-row:2;width:100%;height:auto;aspect-ratio:86 / 42;max-height:calc(100dvh - var(--site-header-h,60px) - 250px);margin:0;padding:0}
  .keyline-page .keyline-panel .kl-palette{grid-column:1 / -1;grid-row:3;justify-content:center;flex-wrap:wrap}
}

/* ── Phones: the numbers, then the board (upright when the phone is), the words, the palette and the tools ─── */
@media (max-width:760px), (max-width:1000px) and (max-height:500px) {
  .keyline-page .game-panel.keyline-panel{display:flex;flex-direction:column}
  .keyline-page .stats-row{display:flex;justify-content:flex-start;align-items:center;gap:14px;min-height:32px}
  .keyline-page .stats-row>div{display:flex;align-items:center;gap:6px;min-width:0}
  .keyline-page .stats-row .stat-label{font-size:14px;line-height:1.2;color:var(--kl-muted)}
  .keyline-page .stats-row .stat-value{font-size:20px;line-height:1.2}
  .keyline-page .board-container.keyline-board{width:100%;margin:6px 0 0;aspect-ratio:42 / 86;max-height:calc(100dvh - 330px - env(safe-area-inset-top) - env(safe-area-inset-bottom));min-height:320px}
  .keyline-page .game-panel-bottom{display:flex;flex-direction:column;align-items:stretch;gap:8px;margin-top:8px}
  .keyline-page .game-panel-bottom>.game-status{min-height:20px}
  .kl-palette{display:grid;grid-template-columns:repeat(auto-fit,minmax(52px,1fr));gap:6px}
  .kl-pick{flex-direction:column;justify-content:center;gap:3px;height:62px;padding:6px 4px}
  .kl-pick .kl-name{position:absolute;width:1px;height:1px;overflow:hidden;clip-path:inset(50%);white-space:nowrap}
  .kl-tools .kl-key{flex:1 1 0}
}
/* Phones on their side: the board as wide as it gets, short. */
@media (max-width:1000px) and (max-height:500px) and (orientation:landscape) {
  .keyline-page .board-container.keyline-board{aspect-ratio:86 / 42;max-height:calc(100dvh - 150px)}
  .kl-palette{display:flex}
  .kl-pick{flex-direction:row;height:44px}
}

/* ── Beside the frame's aside (game-frame.css, body.game-aside-beside) ───────────────────────────────────────────
   The aside names the game and says how to play, so the page's own title and 玩法 step out of sight; the site's "…"
   still presses 玩法, which then opens as a card in the board's corner. The board takes the stage at about 2:1; the
   numbers, the words and the tools are one 56px row inside the window above the board, the palette a row under it. */
body.game-aside-beside[data-game=keyline]>[data-game-stage]{margin:0;padding:0 0 0 24px}
body.game-aside-beside[data-game=keyline]>[data-game-stage]>main{padding:0 0 24px}
body.game-aside-beside .keyline-layout{
  --stage-w:calc(100vw - var(--site-nav-offset,0px) - var(--game-aside-space,0px) - 24px);
  --stage-h:calc(100dvh - var(--site-header-h,60px) - 24px);
  --hud-h:56px;--dock-h:58px;--hud-gap:6px;
  --play-height:max(240px,min(calc(var(--stage-h) - var(--hud-h) - var(--dock-h) - var(--hud-gap)),calc((var(--stage-w) - 12px) / var(--kl-ratio))));
  --play-width:min(calc(var(--stage-w) - 12px),calc(var(--play-height) * var(--kl-ratio)));
  position:relative;width:calc(var(--play-width) + 12px);max-width:none;height:auto;margin:0 auto}
body.game-aside-beside .keyline-layout .play-column{height:auto}
body.game-aside-beside .keyline-layout .game-panel{grid-template-columns:minmax(0,auto) minmax(0,1fr) auto;grid-template-rows:var(--hud-h) var(--play-height) var(--dock-h);gap:0 16px;height:auto;padding:0 6px var(--hud-gap);border-radius:22px;background:#1b1b1b;box-shadow:inset 0 0 0 1px #ffffff0a}
body.game-aside-beside .keyline-layout .board-container{grid-column:1 / -1;grid-row:2;width:auto;height:var(--play-height);max-height:none;aspect-ratio:auto;box-shadow:none}
body.game-aside-beside .keyline-layout .stats-row{grid-column:1;grid-row:1;flex-direction:row;align-items:center;gap:14px;padding:0 0 0 14px}
body.game-aside-beside .keyline-layout .stats-row>div{flex-direction:row;align-items:center;justify-content:flex-start;gap:8px;min-width:0}
body.game-aside-beside .keyline-layout .stat-label{font-size:14px;line-height:20px}
body.game-aside-beside .keyline-layout .stat-value{display:flex;align-items:center;height:28px;font-size:22px;line-height:28px}
body.game-aside-beside .keyline-layout .game-status{grid-column:2;grid-row:1;align-self:center;font-size:14px;line-height:20px}
body.game-aside-beside .keyline-layout .kl-tools{grid-column:3;grid-row:1;align-self:center;padding:0 4px 0 0}
body.game-aside-beside .keyline-layout .kl-tools .kl-key{min-width:56px;padding:0 12px}
body.game-aside-beside .keyline-layout .kl-palette{grid-column:1 / -1;grid-row:3;align-self:center;justify-content:center;flex-wrap:nowrap}
body.game-aside-beside .keyline-layout .kl-pick{height:44px}
/* The page's own title and 玩法: out of sight, still in the page; opened by the site's "…", 玩法 is a card in the corner. */
body.game-aside-beside .keyline-layout .game-intro{top:calc(var(--hud-h) + 12px);right:18px;position:absolute;z-index:30;width:auto;max-width:calc(var(--play-width) - 24px);margin:0}
body.game-aside-beside .keyline-layout .game-intro>h1,
body.game-aside-beside .keyline-layout .game-help:not([open])>summary:not(:focus-visible){position:absolute;width:1px;height:1px;margin:-1px;padding:0;overflow:hidden;clip-path:inset(50%);white-space:nowrap}
body.game-aside-beside .keyline-layout .game-help{margin:0}
body.game-aside-beside .keyline-layout .game-help:not([open])>summary:focus-visible{min-height:36px;padding:0 12px;border-radius:10px;background:var(--kl-plate);color:var(--kl-ink)}
body.game-aside-beside .keyline-layout .game-help[open]{position:static;width:min(340px,calc(var(--play-width) - 24px));max-height:calc(var(--play-height) - 24px);overflow:auto;padding:12px 18px 14px;border-radius:14px;background:var(--kl-plate);box-shadow:0 4px 12px #00000047}
@media (forced-colors:active){
  body.game-aside-beside .keyline-layout :is(.game-help[open],.game-help:not([open])>summary:focus-visible){border:1px solid CanvasText}
}
/* Phones: the game keeps the whole screen and the frame's cards begin below it. */
@media (max-width:760px), (max-width:1000px) and (max-height:500px) {
  body.game-framed[data-game=keyline]>[data-game-stage]{min-height:100dvh}
}
