:root {
    color-scheme: dark;
    --topbar-height: 70px;
    --bg: #000000;
    --surface: #141414;
    --input: #0c0c0c;
    --hover: #242424;
    --text: #f1f1f1;
    --muted: #b8b8b8;
    --line: #454545;
    --accent: #ffff00;
    --selected: #252525;
    --danger: #ff0000;
}
* { box-sizing: border-box; }
html { height: 100%; overflow: hidden; overscroll-behavior: none; }
body {
    margin: 0;
    height: 100dvh;
    overflow: hidden;
    padding-top: var(--topbar-height);
    background: var(--bg);
    color: var(--text);
    font: 16px/1.5 "Segoe UI", sans-serif;
    overscroll-behavior: none;
    -webkit-user-select: none;
    user-select: none;
    touch-action: none;
}
button { font: inherit; height: 40px; min-height: 40px; border: 1px solid var(--line); border-radius: 6px; padding: 6px 12px; background: var(--surface); color: var(--text); font-weight: 600; cursor: pointer; -webkit-tap-highlight-color: transparent; }
button:hover { background: var(--hover); border-color: var(--muted); }
:focus-visible { outline: none; }

.topbar { position: fixed; top: 0; right: 0; left: 0; z-index: 20; height: var(--topbar-height); padding: 14px max(20px, calc((100% - 1080px) / 2)); padding-top: max(14px, env(safe-area-inset-top)); display: flex; align-items: center; justify-content: space-between; gap: 20px; }
.brand { display: flex; align-items: center; gap: 12px; font-size: 23px; font-weight: 700; line-height: 1.2; color: var(--text); }
.brand-flag { width: 36px; height: 36px; object-fit: contain; }
.settings-button { width: 40px; height: 40px; padding: 0; display: grid; place-items: center; border-color: transparent; background: transparent; color: var(--muted); font-size: 22px; }
.settings-button:hover { background: var(--hover); color: var(--accent); }

main { width: 100%; height: calc(100dvh - var(--topbar-height)); margin: 0 auto; padding: 12px 20px max(16px, env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 16px; }

/* Velké dětské přepínače */
.quick { display: flex; justify-content: center; gap: 16px; flex-wrap: wrap; }
.seg.big { flex: 0 1 auto; }
.seg.big button { min-width: 88px; height: 68px; min-height: 68px; padding: 0 20px; font-size: 30px; font-weight: 700; }

/* Home tiles */
.tiles { flex: 1 1 0; min-height: 0; display: grid; gap: 14px; grid-template-columns: repeat(4, 1fr); grid-template-rows: repeat(2, 1fr); }
@media (orientation: portrait) { .tiles { grid-template-columns: repeat(2, 1fr); grid-template-rows: repeat(4, 1fr); } }
.tile { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2vmin; height: 100%; min-height: 0; padding: 12px; background: var(--surface); border: 1px solid var(--line); border-radius: 6px; font-size: clamp(18px, 3.2vmin, 30px); font-weight: 600; }
.tile:hover { background: var(--hover); border-color: var(--accent); color: var(--accent); }
.tile-icon { width: clamp(48px, 12vmin, 110px); height: clamp(48px, 12vmin, 110px); color: var(--accent); }

/* Stage */
#stage { position: fixed; inset: 0; z-index: 30; background: var(--bg); touch-action: none; }
#arena { position: absolute; inset: 0; overflow: hidden; touch-action: none; }
#exit { position: absolute; top: max(14px, env(safe-area-inset-top)); left: max(14px, env(safe-area-inset-left)); z-index: 5; width: 48px; height: 48px; padding: 0; font-size: 20px; color: var(--muted); background: rgba(20, 20, 20, .8); }
#score { position: absolute; top: max(14px, env(safe-area-inset-top)); right: max(20px, env(safe-area-inset-right)); z-index: 5; font-size: 26px; font-weight: 700; font-variant-numeric: tabular-nums; padding: 4px 16px; background: rgba(12, 12, 12, .88); border: 1px solid var(--line); border-radius: 6px; }
#bar { position: absolute; left: 0; right: 0; bottom: 0; z-index: 5; height: 6px; background: var(--surface); }
#bar-fill { height: 100%; width: 100%; background: var(--accent); }

.obj { position: absolute; left: 0; top: 0; line-height: 1; font-weight: 800; will-change: transform; }
.obj img { display: block; pointer-events: none; }
.obj.tappable { cursor: pointer; }
.obj.pop { transition: transform .25s, opacity .25s; transform-origin: center; opacity: 0 !important; }

.fix-dot { position: absolute; left: 50%; top: 50%; display: grid; place-items: center; border-radius: 50%; will-change: transform; }

/* Had */
.snake-seg { position: absolute; left: 0; top: 0; border-radius: 50%; background: #00c853; will-change: transform; }
.snake-head { background: var(--accent); z-index: 2; }
.snake-head::before, .snake-head::after { content: ""; position: absolute; width: 20%; height: 20%; border-radius: 50%; background: #000; top: 24%; }
.snake-head::before { left: 22%; }
.snake-head::after { right: 22%; }

#line-svg { position: absolute; inset: 0; width: 100%; height: 100%; }

/* Šachovnice */
.chess-board { position: absolute; inset: 0; background-image: conic-gradient(#f1f1f1 0 25%, #0a0a0a 0 50%, #f1f1f1 0 75%, #0a0a0a 0); }
.chess-board.inv { background-image: conic-gradient(#0a0a0a 0 25%, #f1f1f1 0 50%, #0a0a0a 0 75%, #f1f1f1 0); }
.chess-target { background: rgba(12, 12, 12, .92); border: 3px solid var(--accent); border-radius: 50%; display: grid; place-items: center; }

/* Bludiště */
#maze-canvas { position: absolute; inset: 0; touch-action: none; }

/* Skládané slovo a ohňostroj */
#word-progress { position: absolute; top: max(14px, env(safe-area-inset-top)); left: 50%; transform: translateX(-50%); z-index: 5; display: flex; gap: 8px; padding: 4px 16px; font-size: 32px; font-weight: 800; color: var(--muted); background: rgba(12, 12, 12, .88); border: 1px solid var(--line); border-radius: 6px; pointer-events: none; }
#word-progress span.done { color: var(--accent); }
.spark { position: absolute; width: 10px; height: 10px; border-radius: 50%; z-index: 4; pointer-events: none; opacity: 1; transition: transform 1.1s ease-out, opacity 1.1s ease-out; }

/* Pexeso */
.cards { display: grid; gap: 10px; height: 100%; padding: 70px 16px max(16px, env(safe-area-inset-bottom)); grid-template-columns: repeat(4, 1fr); grid-template-rows: repeat(3, 1fr); }
@media (orientation: portrait) { .cards { grid-template-columns: repeat(3, 1fr); grid-template-rows: repeat(4, 1fr); } }
.card { height: 100%; min-height: 0; padding: 0; display: grid; place-items: center; font-size: clamp(32px, 9vmin, 72px); background: var(--input); border: 1px solid var(--line); border-radius: 6px; transition: transform .2s, background .2s, border-color .2s; }
.card .face { visibility: hidden; }
.card::before { content: "❓"; position: absolute; color: var(--muted); font-size: .6em; }
.card.revealed { background: var(--surface); border-color: var(--accent); }
.card.revealed .face { visibility: visible; }
.card.revealed::before { content: none; }
.card.matched { background: var(--selected); border-color: var(--line); opacity: .9; }
.card { position: relative; }

/* Úvodní popis cvičení */
#intro { position: absolute; inset: 0; z-index: 8; display: grid; place-items: center; background: var(--bg); }
#intro[hidden] { display: none; }
.intro-card { display: grid; gap: 32px; justify-items: center; padding: 24px; max-width: min(620px, 92%); }
#intro-text { font-size: clamp(26px, 5vmin, 42px); font-weight: 800; line-height: 1.3; text-align: center; letter-spacing: .04em; }
#intro-ok { width: 100px; height: 100px; min-height: 100px; border-radius: 50%; font-size: 48px; background: var(--accent); color: #000; border-color: var(--accent); }

/* Done overlay */
#done { position: absolute; inset: 0; z-index: 10; display: grid; place-items: center; background: rgba(0, 0, 0, .75); }
#done[hidden] { display: none; }
.done-card { display: grid; gap: 14px; justify-items: center; padding: 28px 40px; background: var(--surface); border: 1px solid var(--line); border-radius: 6px; }
.done-emoji { font-size: 64px; line-height: 1; }
#done-msg { font-size: 24px; font-weight: 700; text-align: center; }
.done-actions { display: flex; gap: 12px; }
.done-actions button { min-width: 110px; height: 48px; font-size: 18px; }
#again { background: var(--accent); color: #000; border-color: var(--accent); }

/* Settings dialog */
dialog { border: 1px solid var(--line); border-radius: 6px; background: var(--surface); color: var(--text); padding: 24px; width: min(440px, calc(100% - 40px)); touch-action: pan-y; }
dialog::backdrop { background: rgba(0, 0, 0, .6); }
dialog h2 { font-size: 18px; font-weight: 600; margin: 0 0 18px; }
.setting { display: grid; gap: 8px; margin-bottom: 16px; }
.setting-label { font-size: 14px; font-weight: 600; }
.seg { display: flex; padding: 4px; gap: 4px; border: 1px solid var(--line); border-radius: 6px; background: var(--input); }
.seg button { flex: 1; min-width: 0; height: 44px; border-color: transparent; background: transparent; color: var(--muted); }
.seg button:hover { background: var(--hover); color: var(--text); }
.seg button[aria-pressed="true"] { background: var(--selected); color: var(--accent); }
.settings-close { width: 100%; height: 48px; margin-top: 6px; }

#stage[hidden], #score[hidden], #bar[hidden] { display: none; }
