:root {
  --bg: #0b0d17;
  --bg2: #12152a;
  --panel: rgba(255, 255, 255, 0.06);
  --panel-strong: rgba(255, 255, 255, 0.1);
  --border: rgba(255, 255, 255, 0.12);
  --text: #eef0ff;
  --muted: #9aa0c3;
  --accent: #8b7bff;
  --accent2: #5ee7ff;
  --danger: #ff5577;
  --ok: #4ade80;
  --gold: #ffd34d;
  --radius: 18px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --cell: 40px;
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Outfit', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  overflow: hidden;
  overscroll-behavior: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}
body::before {
  content: '';
  position: fixed; inset: -20%;
  background:
    radial-gradient(40% 35% at 15% 10%, rgba(139, 123, 255, 0.28), transparent 70%),
    radial-gradient(35% 30% at 90% 20%, rgba(94, 231, 255, 0.16), transparent 70%),
    radial-gradient(45% 40% at 60% 100%, rgba(255, 85, 160, 0.14), transparent 70%);
  filter: blur(10px);
  z-index: -1;
  pointer-events: none;
}
button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; }
button:disabled { opacity: .45; cursor: default; }
[hidden] { display: none !important; }

#app { position: fixed; inset: 0; }
.screen {
  position: absolute; inset: 0;
  display: none; flex-direction: column;
  padding: calc(var(--safe-top) + 10px) 16px calc(var(--safe-bottom) + 10px);
  max-width: 720px; margin: 0 auto;
}
.screen.active { display: flex; animation: screenIn .28s ease both; }
@keyframes screenIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ---------- buttons ---------- */
.btn {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; padding: 14px 18px; border-radius: 16px; font-weight: 600; font-size: 17px;
  transition: transform .12s ease, background .2s ease, box-shadow .2s ease;
}
.btn:active { transform: scale(.97); }
.btn-primary {
  background: linear-gradient(135deg, #8b7bff, #5b8cff 55%, #4fd1ff);
  box-shadow: 0 10px 30px -10px rgba(110, 120, 255, .8), inset 0 1px 0 rgba(255,255,255,.35);
  color: #fff;
}
.btn-glass { background: var(--panel); border: 1px solid var(--border); backdrop-filter: blur(12px); }
.btn-danger { background: linear-gradient(135deg, #ff5577, #ff8a5b); color: #fff; }
.btn-xl { padding: 18px; font-size: 20px; }
.btn-small { padding: 9px 14px; font-size: 14px; border-radius: 12px; }
.btn-main { font-size: 1em; }
.btn-sub { font-size: 13px; font-weight: 500; opacity: .8; }
.btn-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.icon-btn {
  width: 42px; height: 42px; border-radius: 14px; font-size: 26px; line-height: 1;
  background: var(--panel); border: 1px solid var(--border);
  display: grid; place-items: center;
}
.icon-btn.small { width: 30px; height: 30px; font-size: 14px; border-radius: 10px; }

/* ---------- home ---------- */
#screen-home { justify-content: space-between; }
.home-hero { text-align: center; margin-top: 6vh; }
.logo-row { display: flex; justify-content: center; }
.logo-verita { width: 110px; height: 110px; filter: drop-shadow(0 14px 30px rgba(167, 139, 250, .55)); animation: bob 3.2s ease-in-out infinite; }
@keyframes bob { 50% { transform: translateY(-8px) rotate(-3deg); } }
.title {
  font-size: clamp(42px, 12vw, 64px); margin: 10px 0 4px; font-weight: 800; letter-spacing: -1.5px;
  background: linear-gradient(120deg, #fff, #c8bfff 40%, #7de3ff);
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.subtitle { color: var(--muted); margin: 0 auto; max-width: 320px; line-height: 1.45; }
.home-actions { display: flex; flex-direction: column; gap: 12px; width: 100%; max-width: 420px; margin: 0 auto; }
.home-stats { display: flex; justify-content: center; gap: 10px; flex-wrap: wrap; margin: 10px 0 6px; }
.stat { background: var(--panel); border: 1px solid var(--border); border-radius: 14px; padding: 8px 14px; text-align: center; min-width: 88px; }
.stat b { display: block; font-size: 20px; }
.stat span { font-size: 12px; color: var(--muted); }

/* ---------- topbar ---------- */
.topbar { display: flex; align-items: center; gap: 12px; min-height: 48px; }
.topbar h2 { margin: 0; font-size: 20px; flex: 1; text-align: center; }
.spacer { width: 42px; }

/* ---------- level picker ---------- */
.level-picker { flex: 1; overflow-y: auto; padding: 8px 2px 24px; -webkit-overflow-scrolling: touch; }
.picker-card {
  background: linear-gradient(160deg, rgba(139,123,255,.18), rgba(94,231,255,.06));
  border: 1px solid var(--border); border-radius: 22px; padding: 16px; margin-bottom: 16px;
  display: flex; flex-direction: column; gap: 12px;
}
.picker-head { display: flex; justify-content: space-between; align-items: flex-start; }
.picker-level { font-size: 26px; font-weight: 700; }
.picker-info { color: var(--muted); font-size: 14px; margin-top: 2px; }
.tier-badge { font-size: 12px; font-weight: 700; padding: 6px 10px; border-radius: 999px; background: var(--panel-strong); letter-spacing: .5px; text-transform: uppercase; }
.tier-Lehká { background: rgba(74, 222, 128, .2); color: #86efac; }
.tier-Střední { background: rgba(94, 231, 255, .18); color: #7de3ff; }
.tier-Těžká { background: rgba(250, 204, 21, .18); color: #fde047; }
.tier-Expert { background: rgba(251, 146, 60, .2); color: #fdba74; }
.tier-Mistr { background: rgba(255, 85, 119, .2); color: #fda4af; }
.tier-ULTRA { background: linear-gradient(90deg, #ff3d77, #8b5cf6); color: #fff; box-shadow: 0 0 18px rgba(255, 61, 119, .5); }
input[type=range] { width: 100%; accent-color: var(--accent); height: 28px; }
.picker-scale { display: flex; justify-content: space-between; color: var(--muted); font-size: 12px; margin-top: -6px; }
.level-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; }
.lvl {
  aspect-ratio: 1; border-radius: 14px; background: var(--panel); border: 1px solid var(--border);
  display: flex; flex-direction: column; align-items: center; justify-content: center; font-weight: 700; font-size: 18px;
  position: relative; transition: transform .12s;
}
.lvl:active { transform: scale(.94); }
.lvl small { font-size: 10px; font-weight: 500; color: var(--muted); }
.lvl .lstars { font-size: 10px; color: var(--gold); letter-spacing: 1px; min-height: 12px; }
.lvl.done { background: linear-gradient(160deg, rgba(74,222,128,.22), rgba(74,222,128,.05)); border-color: rgba(74,222,128,.35); }
.lvl.selected { outline: 2px solid var(--accent2); outline-offset: 1px; }
.lvl.t-Expert { border-color: rgba(251,146,60,.35); }
.lvl.t-Mistr { border-color: rgba(255,85,119,.45); }
.lvl.t-ULTRA { background: linear-gradient(135deg, rgba(255,61,119,.35), rgba(139,92,246,.35)); border-color: #ff3d77; }
.level-sep { grid-column: 1 / -1; color: var(--muted); font-size: 13px; font-weight: 600; margin: 10px 2px 0; text-transform: uppercase; letter-spacing: .8px; }

/* ---------- game ---------- */
.game-top { gap: 10px; }
.game-title { flex: 1; min-width: 0; }
.gt-level { font-weight: 700; font-size: 19px; }
.gt-meta { color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lives { display: flex; gap: 4px; }
.lives svg { width: 26px; height: 26px; fill: var(--danger); filter: drop-shadow(0 2px 8px rgba(255, 85, 119, .6)); transition: transform .3s, opacity .3s; }
.lives svg.lost { fill: rgba(255,255,255,.14); filter: none; }
.lives svg.pop { animation: heartPop .6s ease; }
@keyframes heartPop { 30% { transform: scale(1.5); } 100% { transform: scale(1); } }
.status-row { display: flex; gap: 8px; margin: 8px 0 10px; justify-content: center; }
.chip { background: var(--panel); border: 1px solid var(--border); border-radius: 999px; padding: 5px 12px; font-size: 13px; font-weight: 600; font-variant-numeric: tabular-nums; }
.mode-chip.drawing { background: rgba(255, 211, 77, .2); border-color: rgba(255, 211, 77, .5); color: var(--gold); }

.board-wrap {
  flex: 1; min-height: 0; position: relative; overflow: hidden; touch-action: none;
  display: flex; align-items: center; justify-content: center;
}
.board-zoom { position: relative; transform-origin: 0 0; will-change: transform; }
.board {
  display: grid; position: relative;
  grid-template-columns: repeat(var(--n), var(--cell));
  grid-auto-rows: var(--cell);
  border-radius: 14px; overflow: hidden;
  box-shadow: 0 0 0 2px #141627, 0 20px 50px -18px rgba(0, 0, 0, .9), 0 0 60px -20px rgba(139, 123, 255, .5);
  background: #141627;
}
.cell {
  position: relative; background: var(--rc);
  box-shadow: inset 0 0 0 .5px rgba(20, 22, 39, .35);
  display: grid; place-items: center;
  transition: filter .15s;
}
.cell.bt { border-top: 2px solid #141627; }
.cell.bl { border-left: 2px solid #141627; }
.cell.bb { border-bottom: 2px solid #141627; }
.cell.br { border-right: 2px solid #141627; }
.cell .x {
  width: 42%; height: 42%; opacity: .78; position: absolute;
}
.cell .x::before, .cell .x::after {
  content: ''; position: absolute; left: 50%; top: 0; width: 14%; min-width: 2px; height: 100%;
  background: #1b1d33; border-radius: 4px; transform: translateX(-50%) rotate(45deg);
}
.cell .x::after { transform: translateX(-50%) rotate(-45deg); }
.cell.auto .x { opacity: .4; }
.cell.locked .x::before, .cell.locked .x::after { background: #d1123f; }
.cell.locked .x { opacity: 1; width: 50%; height: 50%; }
.cell svg.v { width: 94%; height: 94%; position: absolute; filter: drop-shadow(0 2px 3px rgba(0,0,0,.35)); }
.cell.placed svg.v { animation: vIn .38s cubic-bezier(.3, 1.6, .5, 1); }
@keyframes vIn { from { transform: scale(.2) rotate(-25deg); opacity: 0; } to { transform: none; opacity: 1; } }
.cell.wrong { animation: shake .45s ease; }
.cell.wrong svg.v { filter: drop-shadow(0 0 6px #ff1e55) saturate(.4) brightness(.9); }
@keyframes shake { 20%, 60% { transform: translateX(-4px); } 40%, 80% { transform: translateX(4px); } }
.cell.focus::after {
  content: ''; position: absolute; inset: 2px; border-radius: 6px;
  box-shadow: 0 0 0 3px #fff, 0 0 18px 4px rgba(255,255,255,.7); animation: pulse 1.2s ease-in-out infinite; z-index: 2;
}
.cell.target::after {
  content: ''; position: absolute; inset: 2px; border-radius: 6px;
  box-shadow: 0 0 0 3px var(--accent2), 0 0 18px 4px rgba(94, 231, 255, .8); animation: pulse 1.2s ease-in-out infinite; z-index: 2;
}
.cell.dim { filter: brightness(.55) saturate(.6); }
.cell.sol-miss::before { content: ''; position: absolute; inset: 18%; border-radius: 50%; border: 3px dashed rgba(20,22,39,.7); }
@keyframes pulse { 50% { opacity: .55; } }
.board.won .cell { animation: wonWave .8s ease both; animation-delay: calc(var(--d) * 18ms); }
@keyframes wonWave { 40% { filter: brightness(1.35) saturate(1.2); transform: scale(1.04); } }

.ink { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 5; }
.ink.active { pointer-events: auto; cursor: crosshair; }

.hint-panel {
  background: rgba(18, 21, 42, .92); border: 1px solid rgba(139, 123, 255, .5); border-radius: 18px; padding: 12px 14px;
  margin-top: 10px; box-shadow: 0 10px 40px -10px rgba(139, 123, 255, .6); animation: screenIn .25s ease both;
  max-height: 34vh; overflow-y: auto;
}
.hint-head { display: flex; justify-content: space-between; align-items: center; }
.hint-title { font-weight: 700; color: #c8bfff; }
.hint-text { margin: 6px 0 10px; line-height: 1.45; font-size: 15px; }
.hint-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.ink-tools { display: flex; align-items: center; gap: 8px; margin-top: 10px; flex-wrap: wrap; justify-content: center; }
.swatches { display: flex; gap: 6px; }
.swatch { width: 30px; height: 30px; border-radius: 50%; border: 2px solid rgba(255,255,255,.25); }
.swatch.on { border-color: #fff; box-shadow: 0 0 0 3px rgba(255,255,255,.25); }
.tool-chip { background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 6px 10px; font-size: 14px; min-width: 36px; }
.tool-chip.on { background: rgba(255, 211, 77, .2); border-color: var(--gold); }

.toolbar {
  display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; margin-top: 10px;
  background: var(--panel); border: 1px solid var(--border); border-radius: 20px; padding: 6px; backdrop-filter: blur(14px);
}
.tool { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 2px; border-radius: 14px; font-size: 12px; color: var(--muted); font-weight: 600; }
.tool .ti { font-size: 20px; color: var(--text); line-height: 1.1; }
.tool:active { background: var(--panel-strong); }
.tool.on { background: rgba(255, 211, 77, .16); color: var(--gold); }
.gesture-tip { text-align: center; color: var(--muted); font-size: 12px; margin-top: 6px; transition: opacity .6s; }
.gesture-tip.gone { opacity: 0; height: 0; margin: 0; overflow: hidden; }

/* ---------- modal ---------- */
.modal {
  position: fixed; inset: 0; z-index: 50; display: flex; align-items: flex-end; justify-content: center;
  background: rgba(5, 6, 14, .6); backdrop-filter: blur(6px); animation: fadeIn .2s ease;
}
@keyframes fadeIn { from { opacity: 0; } }
.modal-card {
  width: 100%; max-width: 560px; max-height: 88vh; overflow-y: auto;
  background: linear-gradient(180deg, #1a1d38, #121429); border: 1px solid var(--border);
  border-radius: 26px 26px 0 0; padding: 20px 18px calc(var(--safe-bottom) + 20px);
  animation: sheetUp .3s cubic-bezier(.2, .9, .3, 1);
}
@media (min-width: 600px) { .modal { align-items: center; } .modal-card { border-radius: 26px; } }
@keyframes sheetUp { from { transform: translateY(40px); opacity: 0; } }
.modal-card h3 { margin: 0 0 8px; font-size: 22px; }
.modal-card p { color: #cfd3ef; line-height: 1.5; }
.modal-actions { display: flex; flex-direction: column; gap: 10px; margin-top: 16px; }
.big-emoji { font-size: 54px; text-align: center; }
.win-stars { text-align: center; font-size: 40px; letter-spacing: 6px; color: var(--gold); text-shadow: 0 0 20px rgba(255,211,77,.7); }
.win-stars .off { color: rgba(255,255,255,.15); text-shadow: none; }
.kv { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 12px 0; }
.kv div { background: var(--panel); border-radius: 14px; padding: 10px; text-align: center; }
.kv b { display: block; font-size: 18px; }
.kv span { font-size: 12px; color: var(--muted); }
.setting { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--border); }
.setting div small { display: block; color: var(--muted); font-size: 13px; margin-top: 2px; }
.switch { position: relative; width: 50px; height: 30px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span { position: absolute; inset: 0; background: rgba(255,255,255,.15); border-radius: 999px; transition: .2s; }
.switch span::before { content: ''; position: absolute; width: 24px; height: 24px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: .2s; }
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::before { transform: translateX(20px); }
.howto-demo { display: flex; justify-content: center; gap: 14px; margin: 10px 0; }
.howto-demo svg { width: 44px; height: 44px; }
.rules { padding-left: 18px; line-height: 1.55; color: #cfd3ef; }
.rules li { margin-bottom: 6px; }

/* ---------- report ---------- */
.report { flex: 1; overflow-y: auto; padding-bottom: 30px; -webkit-overflow-scrolling: touch; }
.report-hero { text-align: center; padding: 6px 0 10px; }
.report-hero h3 { margin: 4px 0; font-size: 26px; }
.report-hero p { margin: 0; color: var(--muted); }
.card { background: var(--panel); border: 1px solid var(--border); border-radius: 20px; padding: 14px; margin-top: 12px; }
.card h4 { margin: 0 0 8px; font-size: 16px; display: flex; align-items: center; gap: 8px; }
.card p, .card li { line-height: 1.5; color: #d6d9f3; font-size: 15px; }
.card ul { padding-left: 18px; margin: 6px 0; }
.mistake-num { width: 26px; height: 26px; border-radius: 50%; background: var(--danger); color: #fff; display: grid; place-items: center; font-size: 14px; flex: none; }
.tag { display: inline-block; font-size: 11px; font-weight: 700; padding: 3px 8px; border-radius: 999px; margin-left: auto; text-transform: uppercase; letter-spacing: .4px; }
.tag-conflict { background: rgba(255, 85, 119, .2); color: #fda4af; }
.tag-blocker, .tag-contradiction { background: rgba(250, 204, 21, .18); color: #fde047; }
.tag-guess { background: rgba(139, 123, 255, .25); color: #c8bfff; }
.sub { font-weight: 700; color: #fff; font-size: 13px; text-transform: uppercase; letter-spacing: .6px; margin: 12px 0 2px; opacity: .75; }
.mini-board-wrap { display: flex; justify-content: center; margin: 10px 0 4px; }
.mini-board { display: grid; grid-template-columns: repeat(var(--n), var(--mc)); grid-auto-rows: var(--mc); border-radius: 10px; overflow: hidden; box-shadow: 0 0 0 2px #141627; background: #141627; }
.mini-board .cell .x { width: 46%; height: 46%; }
.legend { display: flex; gap: 12px; flex-wrap: wrap; justify-content: center; font-size: 12px; color: var(--muted); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 4px; vertical-align: -1px; }
.walk-controls { display: flex; gap: 8px; align-items: center; justify-content: center; margin-top: 10px; }
.walk-text { min-height: 72px; }

/* ---------- toast & loading ---------- */
.toast {
  position: fixed; left: 50%; top: calc(var(--safe-top) + 96px); transform: translate(-50%, -14px);
  background: rgba(20, 22, 44, .95); border: 1px solid var(--border); padding: 10px 16px; border-radius: 14px;
  font-size: 14px; opacity: 0; pointer-events: none; transition: .25s; z-index: 60; max-width: 90vw; text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.bad { border-color: rgba(255, 85, 119, .6); }
.loading {
  position: fixed; inset: 0; z-index: 70; background: rgba(8, 9, 20, .85); backdrop-filter: blur(6px);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; color: var(--muted);
}
.loading-verita { width: 80px; height: 80px; animation: spinBob 1.2s ease-in-out infinite; }
@keyframes spinBob { 50% { transform: translateY(-10px) rotate(12deg); } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* ---------- verity types: Veritárium & win ---------- */
.btn-dex { background: linear-gradient(135deg, rgba(255, 95, 162, .22), rgba(139, 123, 255, .22)); border: 1px solid rgba(255, 95, 162, .4); }
.dex-intro { color: var(--muted); margin: 6px 2px 12px; line-height: 1.45; font-size: 14px; }
.dex-grid {
  flex: 1; overflow-y: auto; display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px;
  padding-bottom: 24px; align-content: start; -webkit-overflow-scrolling: touch;
}
@media (min-width: 480px) { .dex-grid { grid-template-columns: repeat(4, 1fr); } }
.dex-card {
  background: var(--panel); border: 1px solid var(--border); border-radius: 18px; padding: 10px 6px 8px;
  display: flex; flex-direction: column; align-items: center; gap: 2px; transition: transform .12s;
}
.dex-card:active { transform: scale(.95); }
.dex-card b { font-size: 13px; }
.dex-card small { font-size: 10px; color: var(--muted); }
.dex-v { width: 68px; height: 68px; filter: drop-shadow(0 4px 8px rgba(0,0,0,.4)); }
.dex-card.unknown .dex-v { filter: brightness(0) invert(1) opacity(.22); }
.dex-card.unknown b { color: var(--muted); }
.dex-big { display: flex; justify-content: center; }
.dex-big-v { width: 150px; height: 150px; filter: drop-shadow(0 12px 28px rgba(139, 123, 255, .5)); animation: bob 3.2s ease-in-out infinite; }
.win-types { display: flex; flex-wrap: wrap; justify-content: center; gap: 2px; margin-bottom: 6px; }
.wt { width: 42px; height: 42px; animation: vIn .5s cubic-bezier(.3, 1.6, .5, 1) both; }
.howto-demo svg { width: 48px; height: 48px; }
