/* Khel ON Chess */
:root {
  --navy: #141721; --panel: #1d2131; --panel2: #262b3f; --line: #343a55;
  --text: #f5f1ea; --muted: #a9adc4;
  --orange: #ff9a3c; --pink: #f04fa8; --purple: #8b5cf6; --teal: #2fd4c8;
  --grad: linear-gradient(90deg, #ff9a3c, #f04fa8 55%, #8b5cf6);
  --sq-light: #f1e6d3; --sq-dark: #8a79cf;
  --pw-fill: #fffaf1; --pw-line: #141721;
  --pb-fill: #262a3d; --pb-line: #0b0d14; --pb-detail: #cfd3ea;
  --font-head: 'Outfit', 'Lilita One', 'Nunito', system-ui, sans-serif;
  --font-body: 'Nunito', system-ui, -apple-system, 'Segoe UI', sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--navy); color: var(--text); font-family: var(--font-body); -webkit-tap-highlight-color: transparent; }
body { min-height: 100vh; overflow-x: hidden; }
.defs { position: absolute; width: 0; height: 0; overflow: hidden; }
.hidden { display: none !important; }
button { font: inherit; color: inherit; }

.app { max-width: 560px; margin: 0 auto; padding: 0 12px calc(16px + env(safe-area-inset-bottom)); }
.topbar { display: flex; align-items: center; gap: 10px; padding: 10px 0; }
.menu-link { appearance: none; border: 0; background: transparent; display: inline-flex; align-items: center; gap: 4px; padding: 8px 12px 8px 4px; margin-left: -4px; min-height: 44px; border-radius: 12px; font-family: var(--font-body); font-weight: 800; font-size: 16px; color: var(--text); cursor: pointer; }
.menu-link svg { width: 20px; height: 20px; color: var(--muted); }
.menu-link:hover { background: rgba(255,255,255,.06); }
.menu-link:focus-visible { outline: 3px solid var(--teal); outline-offset: 2px; }
.topbar-title { flex: 1; font-family: var(--font-head); font-weight: 700; font-size: 17px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; text-align: center; }
.topbar-title b { color: var(--text); font-weight: 800; }
#topTitle:not(:empty)::before { content: '· '; }
.icon-btn { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; width: 44px; height: 44px; cursor: pointer; font-size: 18px; }
.icon-btn:hover { background: var(--panel2); }

h1, h2, h3, h4 { font-family: var(--font-head); margin: 0 0 8px; }
h1 { font-size: 40px; line-height: 1.05; }
h2 { font-size: 26px; margin-top: 6px; }
h3 { font-size: 22px; }
h4 { font-size: 16px; margin-top: 14px; color: var(--teal); }
p { line-height: 1.5; }
.sub, .tag { color: var(--muted); margin: 0 0 14px; }
.small { font-size: 13px; color: var(--muted); }

.btn { background: var(--panel2); border: 1px solid var(--line); border-radius: 14px; padding: 11px 16px; cursor: pointer; font-weight: 700; font-size: 16px; min-height: 46px; transition: transform .08s ease, filter .15s; }
.btn:active { transform: scale(.97); }
.btn.primary { background: var(--grad); border: 0; color: #fff; text-shadow: 0 1px 2px rgba(0,0,0,.25); }
.btn.big { width: 100%; font-size: 18px; min-height: 56px; display: flex; align-items: center; justify-content: center; gap: 10px; }
.btn.small { padding: 8px 10px; font-size: 14px; min-height: 42px; flex: 1; }
.btn:disabled { opacity: .45; cursor: default; }
.btn:focus-visible, .chip:focus-visible, .sq:focus-visible, .lesson:focus-visible { outline: 3px solid var(--teal); outline-offset: 2px; }
.linkbtn { background: none; border: 0; color: var(--muted); text-decoration: underline; cursor: pointer; margin-top: 10px; font-size: 15px; }
.pill { background: rgba(255,255,255,.12); border-radius: 999px; padding: 2px 10px; font-size: 14px; }

.hero { text-align: center; padding: 12px 0 6px; }
.hero-pieces { display: flex; justify-content: center; gap: 4px; margin-bottom: 4px; }
.hero-pieces .pc { width: 64px; height: 64px; }
.menu { display: grid; gap: 12px; margin-top: 10px; }
.menu-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.newbie { text-align: center; color: var(--muted); margin-top: 16px; }
.newbie b { color: var(--teal); }

.setup-block { background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 14px; margin: 12px 0; }
.label { font-weight: 800; margin-bottom: 10px; }
.chips { display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: 8px; }
.chip { background: var(--panel2); border: 2px solid var(--line); border-radius: 12px; padding: 10px 8px; font-weight: 800; cursor: pointer; display: flex; flex-direction: column; align-items: center; gap: 2px; min-height: 50px; justify-content: center; }
.chip small { font-weight: 600; color: var(--muted); font-size: 12px; }
.chip[aria-checked="true"] { border-color: var(--teal); background: rgba(47,212,200,.14); }
.toggle { display: flex; gap: 10px; align-items: center; cursor: pointer; font-weight: 600; }
.toggle input { width: 22px; height: 22px; accent-color: var(--teal); flex: none; }
.setup-actions { display: flex; gap: 10px; margin-top: 16px; }
.setup-actions .btn { flex: 1; }

/* board */
.board-wrap { position: relative; margin: 0 auto; width: min(100%, 520px, calc(100vh - 290px)); min-width: 280px; }
.board { display: grid; grid-template-columns: repeat(8, 1fr); width: 100%; aspect-ratio: 1 / 1; border-radius: 10px; overflow: hidden; box-shadow: 0 8px 28px rgba(0,0,0,.45), 0 0 0 3px #2a2f45; touch-action: none; user-select: none; -webkit-user-select: none; }
.sq { position: relative; border: 0; padding: 0; margin: 0; background: var(--sq-light); cursor: pointer; aspect-ratio: 1 / 1; display: block; min-width: 0; }
.sq.dk { background: var(--sq-dark); }
.sq .pc { position: absolute; inset: 4%; width: 92%; height: 92%; pointer-events: none; z-index: 2; }
.sq.last::before { content: ''; position: absolute; inset: 0; background: rgba(255,154,60,.38); z-index: 0; }
.sq.sel::before { content: ''; position: absolute; inset: 0; background: rgba(47,212,200,.55); z-index: 0; }
.sq.hint::before { content: ''; position: absolute; inset: 0; background: rgba(47,212,200,.5); z-index: 0; animation: pulse 1s ease-in-out infinite alternate; }
.sq.check::after { content: ''; position: absolute; inset: 0; background: radial-gradient(circle, rgba(240,79,168,.95) 0%, rgba(240,79,168,.55) 45%, rgba(240,79,168,0) 72%); z-index: 1; }
.sq.danger .pc { filter: drop-shadow(0 0 3px #ff9a3c) drop-shadow(0 0 3px #ff9a3c); }
.sq .dot { position: absolute; left: 35%; top: 35%; width: 30%; height: 30%; border-radius: 50%; background: rgba(20,23,33,.32); z-index: 3; pointer-events: none; }
.sq .ring { position: absolute; inset: 3%; border-radius: 50%; border: 5px solid rgba(20,23,33,.32); z-index: 3; pointer-events: none; }
.sq .coord { position: absolute; font-size: 10px; font-weight: 800; z-index: 1; pointer-events: none; opacity: .8; }
.sq .coord.f { right: 3px; bottom: 1px; }
.sq .coord.r { left: 3px; top: 1px; }
.sq.dk .coord { color: var(--sq-light); }
.sq:not(.dk) .coord { color: var(--sq-dark); }
.sq .starmark { position: absolute; inset: 18%; width: 64%; height: 64%; fill: #ffc93c; stroke: #b36b00; stroke-width: 4; z-index: 1; pointer-events: none; animation: twinkle 1.4s ease-in-out infinite alternate; }
.sq .starmark.got { fill: rgba(255,255,255,.3); stroke: none; animation: none; }
.sq.drag-from .pc { opacity: .35; }
.ghost { position: fixed; z-index: 50; pointer-events: none; transform: translate(-50%, -60%); }
.ghost .pc { width: 100%; height: 100%; }
@keyframes pulse { from { opacity: .35; } to { opacity: .9; } }
@keyframes twinkle { from { transform: scale(.9); } to { transform: scale(1.05); } }

/* pieces */
.pc { display: block; }
.pc .f { stroke-width: 3.2; stroke-linejoin: round; }
.pc .d { fill: none; stroke-width: 3; stroke-linecap: round; }
.pc.w { fill: var(--pw-fill); stroke: var(--pw-line); }
.pc.w .d { stroke: var(--pw-line); }
.pc.w .e { fill: var(--pw-line); }
.pc.b { fill: var(--pb-fill); stroke: var(--pb-line); }
.pc.b .d { stroke: var(--pb-detail); }
.pc.b .e { fill: var(--pb-detail); }

.player-bar { display: flex; align-items: center; gap: 8px; min-height: 34px; padding: 4px 2px; font-weight: 800; }
.player-bar .who { white-space: nowrap; display: inline-flex; align-items: center; gap: 6px; }
.player-bar .who .dotc { width: 14px; height: 14px; border-radius: 50%; border: 2px solid #000; display: inline-block; }
.player-bar .who .dotc.w { background: var(--pw-fill); }
.player-bar .who .dotc.b { background: var(--pb-fill); border-color: var(--pb-detail); }
.player-bar.turn .who { color: var(--teal); }
.player-bar .caps { display: flex; flex-wrap: wrap; flex: 1; min-width: 0; }
.player-bar .caps .pc { width: 18px; height: 18px; margin-right: -4px; }
.player-bar .adv { color: var(--muted); font-size: 14px; }
.thinking { display: inline-flex; gap: 3px; margin-left: 4px; }
.thinking i { width: 6px; height: 6px; border-radius: 50%; background: var(--teal); animation: bob .9s infinite ease-in-out; }
.thinking i:nth-child(2) { animation-delay: .15s; }
.thinking i:nth-child(3) { animation-delay: .3s; }
@keyframes bob { 0%, 100% { transform: translateY(0); opacity: .4; } 50% { transform: translateY(-4px); opacity: 1; } }

.coach { min-height: 48px; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 10px 12px; margin: 6px 0 10px; font-weight: 600; line-height: 1.35; }
.coach b { color: var(--teal); }
.coach.warn { border-color: var(--orange); }
.coach.good { border-color: var(--teal); }
.game-actions, .lesson-actions { display: flex; gap: 8px; }
.movelist { list-style: none; margin: 12px 0 0; padding: 8px 10px; background: var(--panel); border-radius: 12px; display: flex; flex-wrap: wrap; gap: 4px 12px; font-size: 14px; color: var(--muted); max-height: 92px; overflow-y: auto; }
.movelist:empty { display: none; }
.movelist li span { color: var(--text); font-weight: 700; margin-left: 4px; }

/* lessons */
.lesson-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.lesson { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 12px; text-align: left; cursor: pointer; display: flex; flex-direction: column; gap: 6px; }
.lesson .ltop { display: flex; align-items: center; gap: 8px; }
.lesson .pc { width: 34px; height: 34px; flex: none; }
.lesson .lnum { color: var(--muted); font-size: 12px; font-weight: 800; }
.lesson .lname { font-weight: 800; font-size: 16px; }
.stars { display: inline-flex; gap: 2px; }
.stars svg { width: 18px; height: 18px; fill: #4a506c; }
.stars svg.on { fill: #ffc93c; }

/* badges */
.star-total { font-family: var(--font-head); font-size: 34px; font-weight: 800; display: flex; align-items: center; gap: 8px; margin: 6px 0 12px; }
.star-total .st { width: 34px; height: 34px; fill: #ffc93c; }
.star-total .of { font-size: 17px; color: var(--muted); font-weight: 700; }
.level-stars { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 14px; }
.level-stars div { background: var(--panel); border-radius: 12px; padding: 10px; font-weight: 800; display: flex; justify-content: space-between; align-items: center; gap: 6px; }
.badge-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.badge { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 12px; text-align: center; }
.badge .bi { font-size: 30px; display: block; filter: grayscale(1); opacity: .35; }
.badge.on .bi { filter: none; opacity: 1; }
.badge.on { border-color: var(--teal); }
.badge .bn { font-weight: 800; display: block; margin-top: 4px; }
.badge .bd { font-size: 12px; color: var(--muted); }

/* modals */
.modal { position: fixed; inset: 0; background: rgba(8,10,16,.72); display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 2147482950; } /* above the front door (How to play opens from it), below the online panel */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 20px; padding: 20px; width: 100%; max-width: 420px; text-align: center; max-height: calc(100vh - 32px); overflow-y: auto; }
.card.rules { text-align: left; max-width: 520px; }
.card.rules ul { padding-left: 20px; margin: 6px 0; }
.card.rules li { margin: 6px 0; line-height: 1.4; }
.rules-list { list-style: none; padding: 0 !important; }
.rules-list li { display: flex; gap: 10px; align-items: center; }
.rules-list .pc { width: 36px; height: 36px; flex: none; }
.card-actions { display: flex; gap: 10px; margin-top: 14px; }
.card-actions .btn { flex: 1; }
.stack { display: grid; gap: 10px; text-align: left; }
.promo-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.promo-row button { background: var(--sq-light); border: 2px solid var(--line); border-radius: 12px; padding: 6px; cursor: pointer; aspect-ratio: 1; }
.promo-row .pc { width: 100%; height: 100%; }
.result-stars { display: flex; justify-content: center; gap: 6px; margin-bottom: 6px; }
.result-stars svg { width: 44px; height: 44px; fill: #4a506c; }
.result-stars svg.on { fill: #ffc93c; animation: pop .4s ease-out both; }
.result-stars svg.on:nth-child(2) { animation-delay: .15s; }
.result-stars svg.on:nth-child(3) { animation-delay: .3s; }
@keyframes pop { from { transform: scale(.2); } 70% { transform: scale(1.2); } to { transform: scale(1); } }
.new-badges { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.new-badges .badge { min-width: 120px; }
.toast { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); background: var(--panel2); border: 1px solid var(--teal); padding: 10px 16px; border-radius: 12px; z-index: 60; font-weight: 700; max-width: calc(100vw - 32px); pointer-events: none; }

@media (max-width: 380px) {
  h1 { font-size: 34px; }
  .btn.small { font-size: 13px; padding: 6px 4px; }
  .chips { grid-template-columns: 1fr 1fr; }
}
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

/* No text caret, no text selection, no tap flash anywhere in the game (mouse double-clicks and caret browsing included).
   The only real text box is the online table-code field, which keeps its caret. Keyboard focus rings stay (:focus-visible). */
html, body { caret-color: transparent; -webkit-tap-highlight-color: transparent; }
body { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
input[type=text], input:not([type]), textarea, .kn-in { caret-color: auto; -webkit-user-select: text; user-select: text; }
button, [role=button], [role=radio], a, svg, canvas, img { -webkit-user-select: none; user-select: none; -webkit-tap-highlight-color: transparent; }
img, svg image { -webkit-user-drag: none; }

/* ---------- mouse: an arrow on things you cannot click, a hand on things you can, never a text I-beam ---------- */
html, body, body * { cursor: default; }
button:not(:disabled), button:not(:disabled) *, a[href], a[href] *, label.toggle, label.toggle * { cursor: pointer; }
.btn:hover:not(:disabled) { filter: brightness(1.12); }
.lesson:hover { border-color: var(--teal); }
.kn-in { cursor: text; }

/* ---------- lessons and badges: centred, roomier on big screens ---------- */
#scrLessons, #scrBadges { max-width: 960px; margin: 0 auto; }
#scrLessons h2, #scrBadges h2 { font-size: 30px; }

/* colour choice tiles in the setup step: each king on a board square, so the black king shows on the dark page */
.opt-sq { display: grid; place-items: center; width: 100%; height: 100%; border-radius: 10px; }
.opt-sq.w { background: var(--sq-dark); } .opt-sq.b { background: var(--sq-light); }
.opt-sq .pc { width: 84%; height: 84%; }
/* icons: drawn, not emoji, so they match the rest of Khel ON */
.btn .bi { width: 18px; height: 18px; flex: none; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; vertical-align: -3px; margin-right: 6px; }
#lessonNext .bi { margin: 0 0 0 6px; }
#soundBtn .snd { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
#soundBtn .snd .spk { fill: currentColor; stroke: none; }
#soundBtn .snd .off, #soundBtn.muted .snd .on { display: none; }
#soundBtn.muted .snd .off { display: inline; }
@media (max-width: 520px) { .game-actions .btn .bi { display: block; margin: 0 auto 3px; width: 20px; height: 20px; } }

/* lesson progress card beside the board */
.lesson-info { background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 14px 16px; margin-top: 10px; }
.lesson-info .li-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; font-size: 16px; }
.lesson-info .li-stars svg { width: 22px; height: 22px; fill: #3a3f58; margin-left: 2px; }
.lesson-info .li-stars svg.on { fill: #ffd257; }
.lesson-info .li-dots { display: flex; gap: 6px; margin: 12px 0 10px; flex-wrap: wrap; }
.lesson-info .li-dots i { width: 14px; height: 14px; border-radius: 50%; background: #2c3149; }
.lesson-info .li-dots i.done { background: var(--teal); }
.lesson-info .li-dots i.cur { background: #fff; box-shadow: 0 0 0 3px rgba(47, 212, 200, .45); }
.lesson-info p { margin: 0; color: var(--muted); font-size: 15px; font-weight: 700; }

/* ================= Option A "game dock" layout (18 Oct 2026) =================
   Slim header · board big on the left · side panel: turn card, players, moves, invite · the shared dock at the bottom. */
:root { --navy: #121521; --panel: #1c2133; --panel2: #262c42; --line: #2e3550; --pri: linear-gradient(135deg, #ff9a3c, #f04fa8); --pri-ink: #241024; }
.topbar { min-height: 52px; padding: 6px 0; gap: 12px; }
.topbar-title { text-align: left; font-size: 16px; }
.topbar-title b { font-size: 20px; margin-right: 2px; }
#topTitle:not(:empty)::before { content: '· '; }
.btn.primary { background: var(--pri); color: var(--pri-ink); text-shadow: none; font-family: var(--font-head); font-weight: 800; border-radius: 999px; }
.side { display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.turn-card { background: var(--panel); border-radius: 22px; padding: 14px 16px; display: flex; flex-direction: column; gap: 8px; box-shadow: inset 0 0 0 1px var(--line); transition: box-shadow .25s; }
.turn-card.mine { box-shadow: inset 0 0 0 2px var(--teal), 0 0 28px rgba(47,212,200,.18); }
.turn-card.over { box-shadow: inset 0 0 0 2px #ffb057, 0 0 28px rgba(255,154,60,.18); }
.tc-head { display: flex; align-items: center; gap: 10px; min-width: 0; }
.tc-head h2 { margin: 0; font: 800 24px/1.1 var(--font-head); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tc-dot { width: 20px; height: 20px; border-radius: 50%; flex: none; border: 2px solid #000; background: var(--pw-fill); }
.tc-dot.b { background: var(--pb-fill); border-color: var(--pb-detail); }
.tc-dot.none { display: none; }
.turn-card .coach { margin: 0; padding: 0; border: 0; background: none; min-height: 0; font-size: 15px; color: #d6d8ea; font-weight: 700; }
.turn-card .coach.warn { color: #ffc58a; }
.turn-card .coach.good b, .turn-card .coach b { color: var(--teal); }
.turn-card .coach.warn b { color: #ffb057; }
.tc-actions { display: flex; flex-direction: column; gap: 8px; }
.tc-actions:not(:has(> :not(.hidden))) { display: none; }
.tc-actions .btn.big { min-height: 56px; font-size: 20px; box-shadow: 0 8px 26px rgba(240,79,168,.35); }
.tc-small { display: flex; flex-wrap: wrap; gap: 8px; }
.chipbtn { appearance: none; border: 1.5px solid rgba(255,255,255,.16); background: transparent; color: #e6e7f4; border-radius: 999px; padding: 7px 14px; min-height: 38px; font: 700 14px/1 var(--font-body); display: inline-flex; align-items: center; gap: 6px; cursor: pointer; }
.chipbtn:hover { border-color: var(--teal); }
.chipbtn[aria-pressed="false"] { color: var(--muted); }
.chipbtn .bi { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.chipbtn:focus-visible { outline: 3px solid var(--teal); outline-offset: 2px; }
.players { background: var(--panel); border-radius: 22px; padding: 6px; display: flex; flex-direction: column; gap: 4px; }
.player-bar { border-radius: 16px; padding: 8px 12px; min-height: 52px; }
.player-bar.turn { background: rgba(47,212,200,.1); box-shadow: inset 0 0 0 1.5px rgba(47,212,200,.7); }
.player-bar .who small { display: block; font-weight: 700; font-size: 12px; color: var(--muted); margin-top: 1px; }
.player-bar .who .nm { display: flex; flex-direction: column; line-height: 1.15; }
.player-bar .caps { justify-content: flex-end; }
.moves-card { background: var(--panel); border-radius: 22px; padding: 12px 8px 12px 16px; display: flex; flex-direction: column; min-height: 0; }
.moves-card h3 { margin: 0 0 4px; font: 800 13px var(--font-head); letter-spacing: .1em; text-transform: uppercase; color: var(--muted); }
.moves-card .movelist { margin: 0; padding: 0 6px 0 0; background: none; border-radius: 0; }
.moves-card .movelist:empty { display: block; }
.moves-card .movelist:empty::after { content: 'The moves of this game will appear here.'; color: var(--muted); font-size: 14px; }
.lesson-info { margin: 0; border-radius: 22px; border: 0; }
.invite-card { appearance: none; display: flex; align-items: center; gap: 14px; text-align: left; width: 100%; padding: 14px 16px; border-radius: 22px; border: 2px dashed rgba(47,212,200,.55); background: rgba(47,212,200,.06); color: #e9fbf9; cursor: pointer; font-family: var(--font-body); }
.invite-card:hover { background: rgba(47,212,200,.12); border-color: var(--teal); }
.invite-card:focus-visible { outline: 3px solid var(--teal); outline-offset: 2px; }
.invite-card svg { width: 30px; height: 30px; flex: none; fill: none; stroke: var(--teal); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.invite-card b { display: block; font: 800 16px/1.2 var(--font-head); color: var(--teal); }
.invite-card small { display: block; font-size: 13px; color: #b9c9d6; font-weight: 700; margin-top: 2px; line-height: 1.3; }
.invite-card[hidden] { display: none; }
#scrGame.is-lesson .players, #scrGame.is-lesson .moves-card, #scrGame.is-lesson .invite-card { display: none; }
/* the dock covers the old toast spot */
.toast { bottom: calc(var(--kd-h, 0px) + 18px); }

/* phone and tablet: header, board full width, a compact turn card and players strip, the dock at the bottom */
@media (max-width: 899px) {
  .app { padding-bottom: 8px; }
  #scrGame:not(.hidden) { display: flex; flex-direction: column; gap: 8px; }
  .board-wrap { width: min(100%, 560px, calc(100vh - var(--kd-h, 0px) - 300px)); }
  @supports (height: 1dvh) { .board-wrap { width: min(100%, 560px, calc(100dvh - var(--kd-h, 0px) - 300px)); } }
  .side { gap: 8px; }
  .turn-card { padding: 10px 14px; border-radius: 18px; gap: 4px; }
  .tc-head h2 { font-size: 19px; }
  .tc-dot { width: 16px; height: 16px; }
  .turn-card .coach { font-size: 14px; }
  .tc-actions .btn.big { min-height: 48px; font-size: 18px; }
  .chipbtn { min-height: 34px; padding: 5px 12px; font-size: 13px; }
  .players { flex-direction: row; border-radius: 18px; padding: 4px; }
  .players .player-bar { flex: 1 1 0; min-width: 0; min-height: 44px; padding: 5px 8px; font-size: 14px; flex-wrap: wrap; gap: 2px 6px; }
  .players .player-bar .who { min-width: 0; overflow: hidden; }
  .players .player-bar .who .nm span { overflow: hidden; text-overflow: ellipsis; }
  .players .player-bar .who small { display: none; }
  .players .player-bar .caps { flex: 1 1 100%; justify-content: flex-start; order: 3; min-height: 14px; overflow: hidden; flex-wrap: nowrap; }
  .players .player-bar .caps .pc { width: 15px; height: 15px; flex: none; }
  .moves-card { padding: 8px 10px 8px 14px; border-radius: 18px; }
  .moves-card h3 { display: none; }
  .moves-card .movelist { max-height: 48px; }
  .invite-card { display: none; }
  .lesson-info { padding: 10px 14px; }
  .lesson-info .li-dots { margin: 8px 0 6px; }
}
/* desktop: the board as big as the height allows, the side panel fills the rest of the width */
@media (min-width: 900px) {
  :root { --gut: 24px; --gap: 28px; --bs: min(calc(100vh - 52px - var(--kd-h, 0px) - 20px), calc(100vw - 2 * var(--gut) - var(--gap) - 360px), 1000px); }
  body.in-game .app { max-width: none; width: auto; margin: 0; padding: 0 var(--gut) 0; }
  .topbar { padding: 6px 0; }
  #scrGame:not(.hidden) { display: grid; grid-template-columns: var(--bs) minmax(360px, 720px); justify-content: center; column-gap: var(--gap); height: var(--bs); align-items: stretch; }
  #scrGame .board-wrap { width: var(--bs); max-width: none; min-width: 0; margin: 0; }
  #scrGame .board { border-radius: 14px; box-shadow: 0 18px 50px rgba(0,0,0,.5), 0 0 0 4px #2a2f45; }
  .sq .coord { font-size: 13px; }
  .sq .coord.f { right: 5px; bottom: 3px; } .sq .coord.r { left: 5px; top: 3px; }
  .side { height: var(--bs); min-height: 0; display: grid; grid-template-columns: minmax(0, 1fr); grid-template-rows: auto auto minmax(0, 1fr) auto; gap: 14px; }
  #scrGame.is-lesson .side { grid-template-rows: auto auto minmax(0, 1fr); }
  .turn-card { padding: 20px 22px; gap: 10px; }
  .tc-head h2 { font-size: 30px; }
  .tc-dot { width: 24px; height: 24px; }
  .turn-card .coach { font-size: 17px; line-height: 1.4; }
  .player-bar { font-size: 17px; min-height: 60px; padding: 10px 14px; }
  .player-bar .who .dotc { width: 20px; height: 20px; }
  .player-bar .caps { flex-wrap: nowrap; overflow: hidden; }
  .player-bar .caps .pc { width: 22px; height: 22px; margin-right: -7px; flex: none; }
  .moves-card .movelist { display: grid; grid-template-columns: 1fr; align-content: start; gap: 0; max-height: none; min-height: 0; overflow-y: auto; font-size: 16px; }
  .moves-card .movelist li { display: grid; grid-template-columns: 52px minmax(0, 140px) minmax(0, 140px); padding: 4px 0; border-top: 1px solid rgba(255,255,255,.05); }
  .moves-card .movelist li span { margin-left: 0; }
  .lesson-info { padding: 18px 20px; align-self: start; }
  .lesson-info .li-head { font-size: 19px; }
  .lesson-info p { font-size: 16px; }
  .invite-card { padding: 16px 20px; }
  .invite-card b { font-size: 18px; }
  .invite-card small { font-size: 14px; }
  .modal .card { max-width: 480px; padding: 28px; }
  .modal .card h3 { font-size: 28px; }
  .result-stars svg { width: 56px; height: 56px; }
  .lesson-grid { grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 14px; }
  .lesson { padding: 16px; }
  .badge-grid { grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); }
  .card { padding: 26px; }
  .card.rules { max-width: 980px; column-count: 2; column-gap: 40px; padding: 30px 34px; }
  .card.rules h3, .card.rules .card-actions { column-span: all; }
  .card.rules h3 { font-size: 30px; margin-bottom: 4px; }
  .card.rules h4:first-of-type { margin-top: 4px; }
  .card.rules h4:nth-of-type(2) { break-before: column; margin-top: 0; }
  .card.rules ul, .card.rules p { break-inside: avoid; }
  .card.rules .card-actions { max-width: 320px; margin: 18px auto 0; }
}

.phone-only { display: none; }
@media (max-width: 640px) {
  .phone-only { display: inline-flex; }
  #scrGame:not(.hidden) { min-height: calc(100vh - var(--kd-h, 0px) - 64px); justify-content: center; }
  @supports (height: 1dvh) { #scrGame:not(.hidden) { min-height: calc(100dvh - var(--kd-h, 0px) - 64px); } }
  .topbar-title { font-size: 14px; } .topbar-title b { font-size: 18px; }
  /* seven buttons in the dock on a phone: long labels may take two short lines */
  #kd-dock .kd-b .kd-lab { white-space: normal; text-align: center; line-height: 1.05; max-width: 100%; }
}
/* dock.js shows every button as flex, which overrides [hidden] on its extra buttons: keep hidden ones hidden */
#kd-dock .kd-b[hidden] { display: none; }

/* lessons: the whole list beside the board, so the panel is never half empty */
.lesson-map { display: none; }
#scrGame.is-lesson .lesson-map { display: flex; flex-direction: column; min-height: 0; background: var(--panel); border-radius: 22px; padding: 14px 10px 10px 16px; }
.lesson-map h3 { margin: 0 0 8px; font: 800 13px var(--font-head); letter-spacing: .1em; text-transform: uppercase; color: var(--muted); }
.lm-list { flex: 1 1 auto; min-height: 0; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; overflow-y: auto; padding-right: 6px; align-content: start; }
.lm { appearance: none; display: flex; align-items: center; gap: 6px; min-height: 38px; padding: 5px 8px; border-radius: 12px; border: 1.5px solid transparent; background: rgba(255,255,255,.04); color: var(--text); font: 700 14px var(--font-body); text-align: left; cursor: pointer; }
.lm:hover { border-color: var(--teal); }
.lm.cur, .lm.cur:disabled { border-color: var(--teal); background: rgba(47,212,200,.12); opacity: 1; }
.lm-n { color: var(--muted); font-weight: 800; min-width: 18px; }
.lm-t { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lm .stars svg { width: 13px; height: 13px; }
.lm:focus-visible { outline: 3px solid var(--teal); outline-offset: 2px; }
@media (max-width: 899px) { #scrGame.is-lesson .lesson-map { display: none; } }
@media (min-width: 900px) { #scrGame.is-lesson .side { grid-template-rows: auto auto minmax(0, 1fr); } }
.lm:disabled, .lm:disabled * { cursor: default; }
