:root {
  --bg: #0a0a0f;
  --bg-2: #14141c;
  --wall: #2a2438;
  --wall-hi: #3f3552;
  --floor: #0f0e16;
  --ink: #e8e6f0;
  --ink-dim: #8b86a0;
  --accent: #ffd84a;
  --accent-2: #ff7e3a;
  --danger: #ff3a5e;
  --good: #4ade80;
  --info: #6ec3ff;
  --hud-bg: #0d0c14;
  --hud-border: #261f36;
  --shadow: rgba(0, 0, 0, 0.55);
  font-family: ui-monospace, "JetBrains Mono", "SF Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
  touch-action: none;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  width: 100vw;
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
}

/* ---------- HUD ---------- */
#hud {
  display: flex;
  flex-direction: column;
  background: var(--hud-bg);
  border-bottom: 1px solid var(--hud-border);
  flex-shrink: 0;
}

.hud-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 10px;
}

.hud-stat {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 20px;
  font-weight: 800;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
  line-height: 1;
  background: var(--bg);
  border: 1px solid var(--hud-border);
  border-radius: 5px;
  padding: 5px 8px;
}

.hud-stat[hidden] { display: none; }

.hud-stat .hud-val { min-width: 0; }

.hud-tag {
  font-size: 10px;
  letter-spacing: 0.12em;
  font-weight: 700;
  color: var(--ink-dim);
  background: var(--bg);
  padding: 2px 5px;
  border-radius: 3px;
  border: 1px solid var(--hud-border);
}

.hud-icon {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
}

.hud-icon-treasure { filter: drop-shadow(0 0 4px rgba(255, 216, 74, 0.35)); }

#hud-treasure-cell[data-has-treasure="false"] .hud-icon-treasure { opacity: 0.25; }
#hud-treasure-cell[data-has-treasure="false"] .hud-val { color: var(--ink-dim); }

.hud-actions {
  margin-left: auto;
  display: flex;
  gap: 6px;
}

.btn-mini {
  width: 38px;
  height: 38px;
  background: var(--bg);
  border: 1px solid var(--hud-border);
  border-radius: 4px;
  color: var(--ink);
  font-size: 18px;
  cursor: pointer;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 120ms, border-color 120ms;
}
.btn-mini:hover { background: var(--wall); border-color: var(--wall-hi); }
.btn-mini:active { transform: scale(0.96); }

/* Aktivní perky v HUD (desktop sidebar) */
.hud-perks {
  display: none;
  flex-direction: column;
  gap: 4px;
  padding: 0 14px 8px;
}

.hud-perk-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 8px;
  font-size: 12px;
  color: var(--ink);
  background: var(--bg);
  border: 1px solid var(--hud-border);
  border-radius: 4px;
  cursor: help;
}

.hud-perk-row .pi { font-size: 16px; }
.hud-perk-row .pn { font-weight: 700; letter-spacing: 0.04em; }

/* Energy row — TLUSTÝ bar TĚSNĚ nad bludištěm, v zorném poli. */
.hud-energy-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 14px 10px;
  background: linear-gradient(to bottom, var(--hud-bg), rgba(0,0,0,0));
}

.hud-energy-row .bar {
  flex: 1;
  height: 14px;
  background: #15121f;
  border: 1px solid var(--hud-border);
  border-radius: 3px;
  overflow: hidden;
  position: relative;
}

.hud-energy-row .bar::before {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, rgba(255,255,255,0.06), rgba(255,255,255,0) 40%);
  pointer-events: none;
}

.hud-energy-val {
  font-size: 14px;
  font-weight: 700;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
  min-width: 56px;
  text-align: right;
}

/* Kompaktní portrait — schovat HI a LV pokud je málo místa */
@media (max-width: 500px) {
  .hud-bar { gap: 5px; padding: 6px 8px; }
  .hud-stat { font-size: 16px; gap: 4px; padding: 4px 6px; border-radius: 4px; }
  .hud-tag { font-size: 9px; padding: 1px 4px; }
  .hud-icon { width: 16px; height: 16px; }
  .btn-mini { width: 32px; height: 32px; font-size: 14px; }
  .hud-bar .hud-stat:nth-child(4), /* LV */
  .hud-bar .hud-stat:nth-child(5)  /* HI */ {
    display: none;
  }
  .hud-energy-row { padding: 4px 10px 8px; gap: 8px; }
  .hud-energy-val { font-size: 13px; min-width: 50px; }
}

/* (default mobil: btn-perks v hud-actions, hud-perks skrytý — viz .hud-perks display:none nahoře) */

/* Desktop landscape — HUD jako sidebar vlevo */
@media (min-width: 900px) and (orientation: landscape) {
  #app { flex-direction: row; }
  #hud {
    width: 250px;
    min-width: 250px;
    border-bottom: none;
    border-right: 1px solid var(--hud-border);
  }
  .hud-bar {
    flex-direction: column;
    align-items: stretch;
    padding: 18px 18px 8px;
    gap: 14px;
  }
  .hud-stat {
    justify-content: space-between;
    font-size: 28px;
    background: var(--bg);
    padding: 10px 12px;
    border-radius: 4px;
    border: 1px solid var(--hud-border);
  }
  .hud-tag { font-size: 11px; }
  .hud-icon { width: 24px; height: 24px; }
  .hud-actions { margin-left: 0; }
  .btn-mini { flex: 1; height: 44px; }
  .hud-energy-row {
    padding: 8px 18px 18px;
    flex-direction: column;
    align-items: stretch;
    gap: 6px;
  }
  /* v sidebar column layoutu flex:1 zmizí, drž bar na plné šířce */
  .hud-energy-row .bar { height: 18px; width: 100%; flex: 0 0 auto; }
  .hud-energy-val { font-size: 14px; text-align: center; }

  /* Desktop: sidebar zobrazuje seznam perků; mobilní btn-perks naopak schovaný */
  .hud-perks { display: flex; }
  #btn-perks { display: none; }
}

.bar-fill {
  height: 100%;
  width: 100%;
  transition: width 180ms ease-out, background-color 240ms ease-out;
}

.bar-fill.energy { background: linear-gradient(90deg, var(--good), #a3e635); }
.bar-fill.energy.low { background: linear-gradient(90deg, var(--accent-2), var(--accent)); }
.bar-fill.energy.critical { background: linear-gradient(90deg, var(--danger), #ff7081); }

/* ---------- Stage ---------- */
#stage {
  position: relative;
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  min-height: 0;
  overflow: hidden;
}

#game {
  background: #000;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  display: block;
  /* width/height nastavuje JS (fitCanvasToStage) podle dostupné plochy */
  box-shadow: 0 0 40px rgba(255, 216, 74, 0.04), 0 0 0 1px var(--hud-border);
}

/* ---------- Overlay (menu / game over) ---------- */
.overlay {
  /* Karel: Profile na iOS pořád nešel scrollovat (rubber band na body
     po puštění). Předchozí fixy s nested scroll (panel + overlay oba
     overflow-y) selhaly. Konečné řešení: overlay je BLOK (ne flex)
     a scrolluje celý sám. Panel uvnitř je centrovaný margin:auto,
     bez vlastního scroll. Jeden scroll container, jeden touch-action.
     iOS to zpracuje jako normální stránku. */
  position: absolute;
  inset: 0;
  background: rgba(8, 6, 14, 0.86);
  backdrop-filter: blur(6px);
  display: block;
  padding: 16px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  /* Klíčové pro iOS: explicitně povolit svislé scroll gesture
     uvnitř overlay (body má touch-action:none kvůli hře). */
  touch-action: pan-y;
  /* Safe-area padding pro iPhone notch + home indicator. Bez tohoto
     jsou spodní tlačítka schovaná pod systémovou lištou. */
  padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px) + 40px);
  padding-top: calc(16px + env(safe-area-inset-top, 0px));
  opacity: 0;
  pointer-events: none;
  transition: opacity 200ms ease-out;
  z-index: 10;
}

.overlay.visible {
  opacity: 1;
  pointer-events: auto;
}

.panel {
  /* Panel nemá vlastní scroll — overlay scrolluje za něj. Centrovaný
     přes margin:auto v block overlay. */
  max-width: 460px;
  width: 100%;
  margin: 0 auto;
  background: var(--bg-2);
  border: 1px solid var(--hud-border);
  border-radius: 8px;
  padding: 24px;
  text-align: left;
  box-shadow: 0 24px 60px var(--shadow);
}

.panel h1 {
  margin: 0 0 6px;
  font-size: 28px;
  letter-spacing: 0.18em;
  color: var(--accent);
  text-shadow: 0 0 24px rgba(255, 216, 74, 0.25);
}

.panel .subtitle {
  margin: 0 0 16px;
  color: var(--ink-dim);
  font-size: 13px;
}

.panel .legend {
  list-style: none;
  margin: 0 0 16px;
  padding: 0;
  display: grid;
  grid-template-columns: 1fr;
  gap: 6px;
  font-size: 13px;
  color: var(--ink);
}

.panel .legend li {
  display: flex;
  align-items: center;
  gap: 10px;
}

.icon-mini {
  display: inline-block;
  width: 18px;
  height: 18px;
  border-radius: 3px;
  flex-shrink: 0;
}

.icon-mini.player    { background: #6ec3ff; box-shadow: inset 0 0 0 2px #1d4f80; }
.icon-mini.treasure  { background: var(--accent); box-shadow: inset 0 0 0 2px #8a6a00; }
.icon-mini.sword     { background: #cfd8e3; box-shadow: inset 0 0 0 2px #555c66; }
.icon-mini.food      { background: var(--good); box-shadow: inset 0 0 0 2px #1f6b39; }
.icon-mini.prisoner  { background: #b89dff; box-shadow: inset 0 0 0 2px #4a3690; }
.icon-mini.maziac    { background: var(--danger); box-shadow: inset 0 0 0 2px #6e0a20; }
.icon-mini.warrior   { background: #ff9966; box-shadow: inset 0 0 0 2px #7a3a14; }

.panel .controls {
  font-size: 12px;
  color: var(--ink-dim);
  line-height: 1.6;
  margin: 0 0 16px;
}

.menu-stats {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px 14px;
  background: var(--bg);
  border: 1px solid var(--hud-border);
  border-radius: 4px;
  margin: 0 0 16px;
}

.menu-stat-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.menu-buttons {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 8px;
}

.menu-buttons .btn { width: 100%; }

.btn[disabled] {
  opacity: 0.5;
  cursor: not-allowed;
}
.btn[disabled]:hover { background: var(--bg); border-color: var(--hud-border); }

/* ---------- Perk selection ---------- */
.perk-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 12px 0;
}

.perk-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  background: var(--bg);
  border: 1px solid var(--hud-border);
  border-radius: 6px;
  color: var(--ink);
  cursor: pointer;
  text-align: left;
  font: inherit;
  transition: background 120ms, border-color 120ms, transform 120ms;
}

.perk-card:hover {
  background: var(--wall);
  border-color: var(--accent);
}

.perk-card:active { transform: scale(0.98); }

.perk-icon {
  font-size: 28px;
  flex-shrink: 0;
  width: 36px;
  text-align: center;
}

.perk-body {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
}

.perk-name {
  font-size: 14px;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.perk-desc {
  font-size: 12px;
  color: var(--ink-dim);
}

/* ---------- Settings ---------- */
.settings-grid {
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin: 12px 0;
}

.settings-row {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.settings-label {
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-dim);
  font-weight: 700;
}

.settings-options {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.setting-pill {
  background: var(--bg);
  border: 1px solid var(--hud-border);
  color: var(--ink);
  font: inherit;
  font-size: 13px;
  padding: 8px 14px;
  border-radius: 4px;
  cursor: pointer;
  transition: background 120ms, border-color 120ms;
}
.setting-pill:hover { background: var(--wall); border-color: var(--wall-hi); }
.setting-pill.active {
  background: var(--accent);
  color: #1a1300;
  border-color: var(--accent);
  font-weight: 700;
}

.color-pill {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  padding: 0;
  transition: transform 120ms, border-color 120ms;
}
.color-pill:hover { transform: scale(1.1); }
.color-pill.active { border-color: var(--ink); transform: scale(1.15); }

.settings-select {
  background: var(--bg);
  border: 1px solid var(--hud-border);
  color: var(--ink);
  font: inherit;
  font-size: 14px;
  padding: 8px 12px;
  border-radius: 4px;
  cursor: pointer;
}

.settings-desc {
  font-size: 12px;
  color: var(--ink-dim);
  margin: 0;
  padding: 8px 12px;
  background: var(--bg);
  border: 1px solid var(--hud-border);
  border-radius: 4px;
  border-left: 3px solid var(--accent);
}

.settings-input {
  background: var(--bg);
  border: 1px solid var(--hud-border);
  color: var(--ink);
  font: inherit;
  font-size: 16px;
  padding: 10px 12px;
  border-radius: 4px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.settings-input:focus {
  outline: none;
  border-color: var(--accent);
}

.flag-grid {
  flex-wrap: wrap;
  gap: 4px;
}

.flag-pill {
  background: var(--bg);
  border: 2px solid transparent;
  border-radius: 4px;
  font-size: 22px;
  padding: 4px 6px;
  cursor: pointer;
  transition: border-color 100ms, transform 100ms;
}
.flag-pill:hover { transform: scale(1.1); }
.flag-pill.active {
  border-color: var(--accent);
  background: var(--wall);
}

/* ---------- Score card ---------- */
.score-banner {
  background: var(--bg);
  border: 1px solid var(--hud-border);
  border-radius: 6px;
  padding: 14px 16px;
  margin: 12px 0;
  text-align: center;
}

.score-banner-headline {
  font-size: 18px;
  color: var(--ink);
  letter-spacing: 0.06em;
}

.score-banner-headline strong {
  color: var(--accent);
  font-size: 28px;
  font-weight: 800;
  padding: 0 4px;
}

.score-banner-sub {
  font-size: 13px;
  color: var(--ink-dim);
  margin-top: 4px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
}

.score-banner-mini {
  margin-top: 10px;
  font-size: 12px;
  color: var(--ink-dim);
}

.lb {
  list-style: none;
  margin: 0 0 12px;
  padding: 0;
  background: var(--bg);
  border: 1px solid var(--hud-border);
  border-radius: 6px;
  /* Nested scroll na iOS Safari má známý bug: když uživatel doscrolluje
     dolů, momentum přejde na panel, ale nahoru už se nedostane („zasekne
     se"). Řešení: jediný scroll = .panel, vnitřní listy jdou volně. */
}

.lb-full {
  /* žádný vlastní max-height — panel se postará o scroll */
}

.lb-row {
  display: grid;
  grid-template-columns: 44px 28px 1fr auto;
  gap: 8px;
  align-items: center;
  padding: 6px 10px;
  font-size: 13px;
  color: var(--ink);
  border-bottom: 1px solid var(--hud-border);
  font-variant-numeric: tabular-nums;
}

.lb-row:last-child { border-bottom: none; }

.lb-row.you {
  background: rgba(255, 216, 74, 0.12);
  color: var(--accent);
  font-weight: 700;
  border-left: 3px solid var(--accent);
  padding-left: 7px;
}

.lb-rank { color: var(--ink-dim); }
.lb-row.you .lb-rank { color: var(--accent); }
.lb-flag { font-size: 16px; }
.lb-name { letter-spacing: 0.06em; text-transform: uppercase; }
.lb-score { color: var(--accent); font-weight: 700; }
.lb-row.you .lb-score { color: var(--accent); }

.lb-sep {
  text-align: center;
  color: var(--ink-dim);
  font-size: 14px;
  padding: 6px 0;
  letter-spacing: 0.4em;
  border-bottom: 1px solid var(--hud-border);
}

/* ---------- Bestiary ---------- */
.bestiary-list {
  list-style: none;
  margin: 0 0 12px;
  padding: 0;
  /* nested scroll odstraněn — viz .panel komentář */
}

.bestiary-row {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  padding: 12px 10px;
  background: var(--bg);
  border: 1px solid var(--hud-border);
  border-radius: 6px;
  margin-bottom: 8px;
}

.bestiary-row[data-enemy="false"] {
  border-left: 3px solid var(--good);
}

.bestiary-row[data-enemy="true"] {
  border-left: 3px solid var(--danger);
}

.bestiary-icon {
  flex-shrink: 0;
  background: #0a0810;
  border-radius: 4px;
  border: 1px solid var(--hud-border);
}

.bestiary-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

.bestiary-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
}

.bestiary-name {
  font-size: 15px;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.bestiary-level {
  font-size: 11px;
  color: var(--ink-dim);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.bestiary-fact {
  font-size: 12px;
  color: var(--ink);
  line-height: 1.4;
}

.bestiary-fact b {
  color: var(--ink-dim);
  font-weight: 600;
  text-transform: uppercase;
  font-size: 10px;
  letter-spacing: 0.08em;
  margin-right: 4px;
}

/* ---------- Perks catalog ---------- */
.perks-cat {
  list-style: none;
  margin: 0 0 12px;
  padding: 0;
  /* nested scroll odstraněn — viz .panel komentář */
}

.perks-cat-row {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 10px;
  background: var(--bg);
  border: 1px solid var(--hud-border);
  border-left: 3px solid var(--hud-border);
  border-radius: 5px;
  margin-bottom: 6px;
}

.perks-cat-row.owned {
  border-left-color: var(--accent);
  background: rgba(255, 216, 74, 0.06);
}

.perks-cat-row.locked {
  opacity: 0.5;
}

.perks-cat-icon {
  font-size: 24px;
  width: 32px;
  text-align: center;
  flex-shrink: 0;
}

.perks-cat-body { flex: 1; min-width: 0; }

.perks-cat-name {
  font-size: 14px;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.perks-cat-desc {
  font-size: 12px;
  color: var(--ink);
  margin-top: 3px;
}

.perks-cat-req {
  font-size: 11px;
  color: var(--ink-dim);
  margin-top: 4px;
  font-style: italic;
}

/* ---------- Achievmenty ---------- */
.ach-list {
  list-style: none;
  margin: 0 0 12px;
  padding: 0;
  /* nested scroll odstraněn — viz .panel komentář */
}

.ach-row {
  display: flex;
  gap: 10px;
  align-items: center;
  padding: 10px;
  background: var(--bg);
  border: 1px solid var(--hud-border);
  border-radius: 5px;
  margin-bottom: 6px;
}

.ach-row.owned {
  border-left: 3px solid var(--accent);
  background: rgba(255, 216, 74, 0.06);
}

.ach-row.hidden {
  opacity: 0.65;
  filter: saturate(0.4);
}

.ach-icon {
  font-size: 28px;
  width: 40px;
  text-align: center;
  flex-shrink: 0;
}

.ach-body { flex: 1; min-width: 0; }

.ach-name {
  font-size: 14px;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.ach-desc {
  font-size: 12px;
  color: var(--ink);
  margin-top: 3px;
}

.ach-stat {
  font-size: 11px;
  color: var(--ink-dim);
  margin-top: 4px;
}

.ach-reveal {
  width: 30px;
  height: 30px;
  font-size: 14px;
}

/* ---------- Profil ---------- */
.profile-grid {
  display: grid;
  grid-template-columns: 140px 1fr;
  gap: 12px;
}

.profile-card {
  background: var(--bg);
  border: 1px solid var(--hud-border);
  border-radius: 6px;
  padding: 12px;
}

.profile-avatar {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.profile-avatar canvas {
  background: #0a0810;
  border-radius: 6px;
  border: 1px solid var(--hud-border);
}

.profile-name-row {
  display: flex;
  gap: 6px;
  align-items: baseline;
  font-size: 16px;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: 0.06em;
}

.profile-flag { font-size: 18px; }

.profile-stats {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.profile-stat {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: 13px;
}

.profile-stat span {
  color: var(--ink-dim);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-size: 10px;
}

.profile-stat strong {
  color: var(--accent);
  font-size: 18px;
  font-variant-numeric: tabular-nums;
}

@media (max-width: 500px) {
  .profile-grid {
    grid-template-columns: 1fr;
  }
}

.btn {
  border: 1px solid var(--hud-border);
  background: var(--bg);
  color: var(--ink);
  padding: 10px 18px;
  font: inherit;
  font-size: 14px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  border-radius: 4px;
  cursor: pointer;
  transition: transform 120ms ease-out, background 120ms ease-out, border-color 120ms ease-out;
}

.btn:hover { background: var(--wall); border-color: var(--wall-hi); }
.btn:active { transform: scale(0.97); }
.btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-color: var(--accent);
}

.btn.primary {
  background: var(--accent);
  color: #1a1300;
  border-color: var(--accent);
  font-weight: 700;
}

.btn.primary:hover { background: #ffe884; border-color: #ffe884; }

.btn.btn-danger {
  background: transparent;
  color: #ff6b8a;
  border-color: #ff6b8a;
}
.btn.btn-danger:hover {
  background: rgba(255, 107, 138, 0.12);
  border-color: #ff8aa3;
  color: #ff8aa3;
}

/* ---------- Jazyk: vlajkové pilulky ---------- */
.lang-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.lang-pill {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: var(--bg);
  border: 1px solid var(--hud-border);
  border-radius: 6px;
  color: var(--ink);
  cursor: pointer;
  font: inherit;
  font-size: 13px;
  transition: transform 120ms ease-out, border-color 120ms ease-out, background 120ms ease-out;
  min-width: 100px;
}
.lang-pill .lang-flag {
  font-size: 20px;
  line-height: 1;
}
.lang-pill .lang-label {
  font-size: 12px;
  letter-spacing: 0.04em;
}
.lang-pill:hover {
  background: var(--wall);
  border-color: var(--wall-hi);
}
.lang-pill.active {
  background: var(--accent);
  color: #1a1300;
  border-color: var(--accent);
  font-weight: 700;
}
.lang-pill:active { transform: scale(0.96); }

/* ---------- Katalog: tabs ---------- */
.catalog-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 14px;
  justify-content: center;
}
.catalog-tab {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 18px;
  background: var(--bg);
  border: 1px solid var(--hud-border);
  border-radius: 6px;
  color: var(--ink);
  cursor: pointer;
  font: inherit;
  font-size: 13px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  transition: transform 120ms ease-out, border-color 120ms ease-out, background 120ms ease-out;
  flex: 1 1 0;
  max-width: 200px;
  justify-content: center;
}
.catalog-tab .catalog-tab-icon { font-size: 18px; line-height: 1; }
.catalog-tab:hover { background: var(--wall); border-color: var(--wall-hi); }
.catalog-tab.active {
  background: var(--accent);
  color: #1a1300;
  border-color: var(--accent);
  font-weight: 700;
}
.catalog-tab:active { transform: scale(0.97); }
.catalog-content {
  /* nested scroll odstraněn — panel scrolluje celý obsah */
}

/* ---------- Katalog: Jak hrát ---------- */
.howto {
  font-size: 14px;
  line-height: 1.6;
  color: var(--ink);
}
.howto-intro {
  margin: 0 0 16px 0;
  padding: 12px 14px;
  background: rgba(255, 216, 74, 0.08);
  border-left: 3px solid var(--accent);
  border-radius: 4px;
  font-size: 14px;
  color: var(--ink);
}
.howto-section {
  font-size: 13px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--accent);
  margin: 20px 0 10px 0;
  font-weight: 700;
}
.howto-list {
  list-style: none;
  padding: 0;
  margin: 0 0 12px 0;
}
.howto-list li {
  padding: 6px 0;
  display: flex;
  gap: 10px;
  align-items: flex-start;
  border-bottom: 1px dashed var(--hud-border);
  font-size: 13px;
}
.howto-list li:last-child { border-bottom: none; }
.howto-icon {
  font-size: 18px;
  flex-shrink: 0;
  width: 24px;
  text-align: center;
}
.howto-score {
  width: 100%;
  border-collapse: collapse;
  margin: 0 0 12px 0;
  font-size: 13px;
}
.howto-score td {
  padding: 8px 10px;
  border-bottom: 1px dashed var(--hud-border);
}
.howto-score td:last-child {
  text-align: right;
  color: var(--accent);
  font-weight: 700;
  font-family: ui-monospace, monospace;
}
.howto-score tr:last-child td { border-bottom: none; }
.howto-note {
  font-size: 12px;
  color: var(--ink-dim);
  font-style: italic;
  margin: 0;
}

/* ---------- Win overlay: animovaný breakdown ---------- */
.win-counter {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 14px;
  margin: 16px 0 18px 0;
  padding: 14px 18px;
  background: linear-gradient(180deg, rgba(255, 216, 74, 0.18), rgba(255, 216, 74, 0.04));
  border: 1px solid rgba(255, 216, 74, 0.35);
  border-radius: 10px;
}
.win-counter-label {
  font-size: 13px;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--ink-dim);
}
.win-counter-value {
  font-family: ui-monospace, monospace;
  font-size: 36px;
  font-weight: 900;
  color: var(--accent);
  text-shadow: 0 0 12px rgba(255, 216, 74, 0.4);
}

.win-breakdown {
  list-style: none;
  padding: 0;
  margin: 0 0 12px 0;
}
.win-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  border-bottom: 1px dashed var(--hud-border);
  opacity: 0;
  transform: translateX(-12px);
  transition: opacity 250ms ease-out, transform 250ms ease-out;
}
.win-row:last-child { border-bottom: none; }
.win-row.revealed {
  opacity: 1;
  transform: translateX(0);
}
.win-row-icon {
  font-size: 22px;
  width: 28px;
  text-align: center;
  flex-shrink: 0;
}
.win-row-label {
  flex: 1;
  font-size: 14px;
  color: var(--ink);
}
.win-row-count {
  color: var(--ink-dim);
  font-family: ui-monospace, monospace;
  font-size: 13px;
  margin-left: 4px;
}
.win-row-value {
  font-family: ui-monospace, monospace;
  font-size: 16px;
  font-weight: 700;
  color: var(--accent);
}

.win-best {
  text-align: center;
  font-size: 13px;
  color: var(--ink-dim);
  margin: 8px 0 4px 0;
}
.win-best strong { color: var(--ink); font-family: ui-monospace, monospace; }

.win-skip {
  position: absolute;
  top: 16px;
  right: 16px;
  background: transparent;
  border: 1px solid var(--hud-border);
  color: var(--ink-dim);
  padding: 4px 10px;
  border-radius: 4px;
  font: inherit;
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  cursor: pointer;
  transition: border-color 150ms ease-out, color 150ms ease-out;
}
.win-skip:hover { border-color: var(--accent); color: var(--accent); }

/* ---------- Gameover lebka + breakdown ---------- */
.go-skull {
  text-align: center;
  font-size: 64px;
  line-height: 1;
  margin: 0 0 8px 0;
  filter: drop-shadow(0 0 16px rgba(255, 58, 94, 0.45));
  animation: go-skull-pulse 2.2s ease-in-out infinite;
}
@keyframes go-skull-pulse {
  0%, 100% { transform: scale(1); filter: drop-shadow(0 0 16px rgba(255, 58, 94, 0.45)); }
  50%      { transform: scale(1.05); filter: drop-shadow(0 0 24px rgba(255, 58, 94, 0.7)); }
}

/* Empty leaderboard hláška */
.lb-row.lb-empty {
  display: block;
  text-align: center;
  font-style: italic;
  color: var(--ink-dim);
  padding: 24px 12px;
}

/* Duplicate suffix — rozlišuje 2 hráče se stejným nick+vlajka */
.lb-suffix {
  font-family: ui-monospace, monospace;
  font-size: 11px;
  color: var(--ink-dim);
  margin-left: 4px;
  letter-spacing: 0.04em;
}
.lb-device { font-size: 0.85em; margin-left: 2px; opacity: 0.85; }

/* ---------- Profile: sekce s pohárky ---------- */
.profile-section {
  margin-top: 16px;
  padding-top: 12px;
  border-top: 1px solid var(--hud-border);
}
.profile-section-title {
  font-size: 13px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-dim);
  margin: 0 0 8px 0;
}
.profile-section-count {
  color: var(--accent);
  font-size: 13px;
  font-weight: 700;
  margin-left: 6px;
}
.profile-trophies .ach-list {
  /* nested scroll odstraněn — panel scrolluje celý obsah */
}

/* ---------- Tutoriál (onboarding) ---------- */
.tutorial-step {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  padding: 8px 0 4px 0;
}
.tutorial-step canvas {
  background: linear-gradient(to bottom, var(--bg) 0%, rgba(110, 195, 255, 0.06) 100%);
  border: 1px solid var(--hud-border);
  border-radius: 8px;
}
.tutorial-text {
  font-size: 16px;
  line-height: 1.5;
  text-align: center;
  max-width: 460px;
  color: var(--ink);
  margin: 0;
}
.tutorial-progress {
  display: flex;
  gap: 6px;
  margin-top: 4px;
}
.tutorial-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--hud-border);
  transition: background 200ms ease-out;
}
.tutorial-dot.done { background: rgba(255, 216, 74, 0.4); }
.tutorial-dot.active { background: var(--accent); transform: scale(1.2); }

/* ---------- Splash screen 2minutesGames ---------- */
.splash {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 48px 16px;
  gap: 6px;
  animation: splash-fade 2s ease-in-out forwards;
}
@keyframes splash-fade {
  0%   { opacity: 0; transform: scale(0.96); }
  20%  { opacity: 1; transform: scale(1); }
  80%  { opacity: 1; transform: scale(1); }
  100% { opacity: 0; transform: scale(0.98); }
}
.splash-logo {
  display: flex;
  align-items: center;
  gap: 10px;
}
.splash-num {
  font-size: 72px;
  font-weight: 900;
  color: var(--accent);
  line-height: 1;
  letter-spacing: -0.04em;
}
.splash-clock svg {
  display: block;
}
.splash-name {
  font-size: 32px;
  font-weight: 700;
  color: var(--ink);
  letter-spacing: 0.04em;
  margin: 4px 0 0 0;
}
.splash-name strong { color: var(--accent); }
.splash-presents {
  font-size: 12px;
  letter-spacing: 0.3em;
  color: var(--ink-dim);
  text-transform: uppercase;
  margin: 12px 0 0 0;
}

/* Credit „by 2minutesGames" pod menu tlačítky */
.menu-credit {
  margin: 18px 0 0 0;
  text-align: center;
  font-size: 11px;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--ink-dim);
}
.menu-credit strong {
  color: var(--accent);
  font-weight: 700;
}
.menu-build {
  margin: 4px 0 0 0;
  text-align: center;
  font-size: 10px;
  letter-spacing: 0.08em;
  color: var(--ink-dim);
  opacity: 0.55;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

/* ---------- Dialog (NPC speech) ---------- */
.dialog {
  position: absolute;
  left: 50%;
  bottom: 16px;
  transform: translateX(-50%);
  max-width: min(520px, calc(100% - 32px));
  z-index: 8;
  pointer-events: none;
  animation: dialogIn 180ms ease-out;
}

.dialog-inner {
  background: rgba(20, 16, 32, 0.94);
  border: 1px solid var(--hud-border);
  border-radius: 6px;
  padding: 12px 16px;
  font-size: 14px;
  color: var(--ink);
  box-shadow: 0 12px 30px var(--shadow);
  line-height: 1.4;
}

@keyframes dialogIn {
  from { opacity: 0; transform: translate(-50%, 8px); }
  to   { opacity: 1; transform: translate(-50%, 0); }
}

/* ---------- Toast ---------- */
.toast {
  position: absolute;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(20, 16, 32, 0.94);
  border: 1px solid var(--hud-border);
  padding: 8px 14px;
  font-size: 13px;
  color: var(--accent);
  border-radius: 4px;
  z-index: 9;
  animation: toastIn 200ms ease-out;
  pointer-events: none;
}

@keyframes toastIn {
  from { opacity: 0; transform: translate(-50%, -8px); }
  to   { opacity: 1; transform: translate(-50%, 0); }
}

/* ---------- Touch controls ---------- */
.touch {
  display: none;
  position: fixed;
  left: 0;
  right: 0;
  bottom: calc(env(safe-area-inset-bottom) + 8px);
  padding: 0 24px;
  justify-content: space-between;
  align-items: center;
  z-index: 20;
  pointer-events: none;
}

.touch > * { pointer-events: auto; }

.joystick {
  position: relative;
  width: 120px;
  height: 120px;
  background: radial-gradient(circle, rgba(255,255,255,0.06), rgba(255,255,255,0.02));
  border: 1px solid var(--hud-border);
  border-radius: 50%;
  touch-action: none;
  margin-left: auto;
  margin-right: auto;
}

/* ---------- D-pad — 4 quadrantní tap zóny ---------- */
.dpad-zones {
  position: relative;
  width: 100%;
  height: 220px;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  background:
    linear-gradient(45deg, rgba(255,255,255,0.04), rgba(255,255,255,0)) ,
    linear-gradient(-45deg, rgba(255,255,255,0.04), rgba(255,255,255,0));
  /* křížové linie aby uživatel viděl rozdělení */
  border-top: 1px solid var(--hud-border);
}

.dpad-zones::before,
.dpad-zones::after {
  content: "";
  position: absolute;
  background: rgba(255, 255, 255, 0.06);
  pointer-events: none;
}
/* diagonála \ */
.dpad-zones::before {
  top: -10%; bottom: -10%; left: 50%; width: 1px;
  transform: rotate(45deg);
  transform-origin: top center;
}
/* diagonála / */
.dpad-zones::after {
  top: -10%; bottom: -10%; right: 50%; width: 1px;
  transform: rotate(-45deg);
  transform-origin: top center;
}

.zone-glyph {
  position: absolute;
  font-size: 40px;
  color: rgba(255, 255, 255, 0.35);
  pointer-events: none;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.6);
}
.zone-glyph.up    { top: 8px;    left: 50%; transform: translateX(-50%); }
.zone-glyph.down  { bottom: 8px; left: 50%; transform: translateX(-50%); }
.zone-glyph.left  { left: 16px;  top: 50%; transform: translateY(-50%); }
.zone-glyph.right { right: 16px; top: 50%; transform: translateY(-50%); }

/* aktivní zóna se highlightuje */
.zone-active {
  position: absolute;
  pointer-events: none;
  background: rgba(255, 216, 74, 0.18);
  transition: opacity 80ms;
  opacity: 0;
}
.dpad-zones[data-active="north"] .zone-active { opacity: 1; top: 0; left: 0; right: 0; height: 50%; clip-path: polygon(0 0, 100% 0, 50% 100%); }
.dpad-zones[data-active="south"] .zone-active { opacity: 1; bottom: 0; left: 0; right: 0; height: 50%; clip-path: polygon(50% 0, 100% 100%, 0 100%); }
.dpad-zones[data-active="west"]  .zone-active { opacity: 1; top: 0; left: 0; bottom: 0; width: 50%; clip-path: polygon(0 0, 100% 50%, 0 100%); }
.dpad-zones[data-active="east"]  .zone-active { opacity: 1; top: 0; right: 0; bottom: 0; width: 50%; clip-path: polygon(0 50%, 100% 0, 100% 100%); }

/* Volba ovládání — schovat to, co se nevybralo */
#touch[data-controls="dpad"] #joystick { display: none; }
#touch[data-controls="joystick"] #dpad { display: none; }

.knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: rgba(255, 216, 74, 0.85);
  border: 2px solid #b08a00;
  transform: translate(-50%, -50%);
  transition: background 120ms ease-out;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
}

/* btn-action odebráno z mobilu — žádné herní využití. Pokud by se v budoucnu
   přidalo, .btn-action třída zde už neslouží. */

/* show touch UI on touch-capable devices AND on narrow portrait screens
   (Preview mobile a klasické mobil prohlížeče bez touch capability detekce) */
@media (hover: none) and (pointer: coarse),
       (max-width: 600px) and (orientation: portrait) {
  .touch { display: flex; }
  #stage { padding-bottom: 230px; }
}
