:root {
  --bg: #1d2735;
  --bg-2: #26334a;
  --bg-3: #2f3f5a;
  --fg: #eef2f7;
  --muted: #9fb0c4;
  --line: #34435b;
  --ink: #0d131c;
  --accent: #ff7a1a;
  --accent-2: #ffb347;
  --accent-fg: #1a1205;
  --good: #57d17a;
  --font: "Pixelify Sans", system-ui, sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: #cfc8b4;
  color: var(--fg);
  font: 15px/1.35 var(--font);
  overflow: hidden;
  -webkit-font-smoothing: none;
}
#map { position: fixed; inset: 0; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
code { font-family: ui-monospace, monospace; font-size: .9em; }
a { color: var(--accent-2); }

/* ---------- pixelové boxy a tlačítka ---------- */
.px-box {
  background: var(--bg);
  border: 0;
  box-shadow: 0 0 0 2px var(--ink), 0 0 0 4px var(--line), 6px 6px 0 4px rgba(13, 19, 28, .45);
}
.px-btn {
  font: inherit; color: var(--fg); background: var(--bg-3); cursor: pointer;
  border: 0; padding: 7px 12px;
  box-shadow: inset 0 -3px 0 rgba(0, 0, 0, .35), inset 0 2px 0 rgba(255, 255, 255, .08), 0 0 0 2px var(--ink);
  transition: transform .05s;
}
.px-btn:hover { background: #3a4d6d; }
.px-btn:active { transform: translateY(2px); box-shadow: inset 0 -1px 0 rgba(0, 0, 0, .35), 0 0 0 2px var(--ink); }
.px-btn:focus-visible { outline: 2px solid var(--accent-2); outline-offset: 3px; }
.px-btn.accent { background: var(--accent); color: var(--accent-fg); font-weight: 700; }
.px-btn.accent:hover { background: #ff8f3d; }
.px-btn.wide { width: 100%; }
.px-btn.big { font-size: 20px; padding: 12px; }
.px-btn.sq { width: 34px; height: 34px; padding: 0; font-size: 18px; font-weight: 700; }

.ico {
  display: inline-block; width: 20px; height: 20px;
  background-repeat: no-repeat; background-position: center; background-size: 20px 20px;
  image-rendering: pixelated;
}

/* ---------- panel ---------- */
.panel {
  position: absolute; top: 14px; left: 14px; max-height: calc(100% - 28px);
  width: 344px; display: flex; flex-direction: column;
  z-index: 2; transition: transform .2s steps(4), opacity .2s steps(4);
}
.panel.hidden { transform: translateX(calc(-100% - 30px)); opacity: 0; pointer-events: none; }
.panel-toggle {
  position: absolute; top: 14px; left: 14px; z-index: 3; width: 46px; height: 46px; padding: 0;
  display: none;
}
.panel-toggle.collapsed { display: grid; place-items: center; }
.panel-toggle .ico { width: 24px; height: 24px; background-size: 24px 24px; }

.panel-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 14px 8px; }
.panel-head h1 { margin: 0; font-size: 26px; font-weight: 700; letter-spacing: .01em; }
.panel-head h1 b { color: var(--accent); margin-left: 6px; }
.head-btns { display: flex; gap: 8px; }

.tabs { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; padding: 4px 14px 12px; }
.tabs button {
  font: inherit; font-size: 12.5px; color: var(--fg); background: var(--bg-2); cursor: pointer;
  border: 0; padding: 7px 2px 5px; display: flex; flex-direction: column; align-items: center; gap: 3px;
  box-shadow: inset 0 -3px 0 rgba(0, 0, 0, .3), 0 0 0 2px var(--ink);
}
.tabs button:hover { background: var(--bg-3); }
.tabs button.on { background: var(--accent); color: var(--accent-fg); font-weight: 700; }
.tabs button.tab-game:not(.on) { color: var(--accent-2); }

.panes { overflow-y: auto; padding: 0 14px 14px; min-height: 0; }
.pane { display: none; }
.pane.on { display: block; }
h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 14px 0 8px; font-weight: 600; }
.pane > h2:first-child { margin-top: 2px; }
.sub { margin: 10px 0 0; color: var(--muted); font-size: 13px; }

.search input {
  width: 100%; padding: 10px 12px; font: inherit; color: var(--fg);
  background: var(--ink); border: 0; box-shadow: inset 0 0 0 2px var(--line);
}
.search input::placeholder { color: #71839a; }
.search input:focus { outline: 0; box-shadow: inset 0 0 0 2px var(--accent); }
.results { list-style: none; margin: 8px 0 0; padding: 0; max-height: 280px; overflow-y: auto; }
.results:empty { display: none; }
.results li { padding: 7px 9px; cursor: pointer; display: flex; justify-content: space-between; gap: 8px; }
.results li:hover, .results li.active { background: var(--bg-3); }
.results li small { color: var(--muted); white-space: nowrap; }

.seg { display: flex; gap: 4px; background: var(--ink); padding: 4px; }
.seg button {
  flex: 1; border: 0; background: transparent; color: var(--muted); font: inherit; font-size: 13.5px;
  padding: 6px 2px; cursor: pointer;
}
.seg button:hover { color: var(--fg); }
.seg button.on { background: var(--bg-3); color: var(--fg); box-shadow: inset 0 -2px 0 var(--accent); }

.row { display: flex; align-items: center; gap: 9px; margin-top: 8px; cursor: pointer; }
.row.slider { display: grid; grid-template-columns: 1fr auto; row-gap: 4px; margin-top: 12px; }
.row.slider input { grid-column: 1 / -1; width: 100%; accent-color: var(--accent); }
.row output { color: var(--accent-2); }
input[type="checkbox"] {
  appearance: none; width: 18px; height: 18px; margin: 0; background: var(--ink);
  box-shadow: inset 0 0 0 2px var(--line); cursor: pointer; display: grid; place-items: center;
}
input[type="checkbox"]:checked { background: var(--accent); box-shadow: inset 0 0 0 2px var(--ink); }
input[type="checkbox"]:checked::after { content: ""; width: 6px; height: 6px; background: var(--ink); }

.legend { display: flex; flex-wrap: wrap; gap: 4px 12px; margin-top: 10px; font-size: 13px; color: var(--muted); }
.legend .sw { display: inline-block; width: 12px; height: 12px; margin-right: 5px; vertical-align: -1px; box-shadow: 0 0 0 1px var(--ink); }
.legend .ramp { width: 100%; height: 10px; box-shadow: 0 0 0 2px var(--ink); }
.legend .ramp-labels { width: 100%; display: flex; justify-content: space-between; }

.places { display: flex; flex-wrap: wrap; gap: 8px; }
.places button { font-size: 13.5px; padding: 6px 10px; }

.btn-row { display: flex; gap: 8px; margin-top: 10px; }
.hint { color: var(--muted); font-size: 12.5px; margin: 10px 0 0; }

.game-intro { margin: 0 0 10px; }
.game-intro b { color: var(--accent-2); }
.game-legend { display: flex; gap: 16px; margin-bottom: 12px; color: var(--muted); font-size: 13.5px; }
.game-legend span { display: flex; align-items: center; gap: 6px; }
.game-legend canvas { width: 24px; height: 24px; image-rendering: pixelated; }

/* ---------- dialog ---------- */
.dialog { color: var(--fg); padding: 18px 20px; max-width: min(460px, calc(100vw - 40px)); }
.dialog::backdrop { background: rgba(13, 19, 28, .55); }
.dialog h2 { margin-top: 0; font-size: 18px; color: var(--fg); text-transform: none; letter-spacing: 0; }
.sources { padding-left: 18px; margin: 10px 0; }
.sources li { margin-bottom: 4px; }
.dialog form { margin-top: 14px; }

/* ---------- mapové prvky ---------- */
.maplibregl-ctrl-group { border-radius: 0 !important; box-shadow: 0 0 0 2px var(--ink), 4px 4px 0 2px rgba(13, 19, 28, .35) !important; }
.maplibregl-ctrl-attrib { font-family: system-ui, sans-serif; }
.maplibregl-popup-content {
  background: var(--bg); color: var(--fg); border-radius: 0; padding: 12px 14px; font: inherit; min-width: 210px;
  box-shadow: 0 0 0 2px var(--ink), 0 0 0 4px var(--line), 5px 5px 0 4px rgba(13, 19, 28, .45);
}
.maplibregl-popup-anchor-bottom .maplibregl-popup-tip { border-top-color: var(--line); }
.maplibregl-popup-anchor-top .maplibregl-popup-tip { border-bottom-color: var(--line); }
.maplibregl-popup-anchor-left .maplibregl-popup-tip { border-right-color: var(--line); }
.maplibregl-popup-anchor-right .maplibregl-popup-tip { border-left-color: var(--line); }
.maplibregl-popup-close-button { color: var(--muted); font-size: 20px; padding: 0 7px; font-family: var(--font); }
.pop h3 { margin: 0 20px 4px 0; font-size: 17px; }
.pop .kind { color: var(--accent-2); font-size: 13px; margin-bottom: 8px; }
.pop dl { display: grid; grid-template-columns: auto 1fr; gap: 3px 10px; margin: 0; font-size: 14px; }
.pop dt { color: var(--muted); }
.pop dd { margin: 0; }
.pop .links { margin-top: 10px; display: flex; gap: 12px; font-size: 13px; }

/* ---------- hra ---------- */
body.game-on .panel, body.game-on .panel-toggle { display: none; }
body.game-on .maplibregl-ctrl-top-right { display: none; }
body.game-on .maplibregl-ctrl-scale { display: none; }
body.game-on .maplibregl-ctrl-attrib-inner { display: none; }
body.game-on .maplibregl-ctrl-attrib { padding: 0 !important; }
@media (max-width: 640px) { body.game-on .maplibregl-ctrl-bottom-right { bottom: auto; top: 86px; } }
.g-hud {
  position: absolute; top: 12px; left: 50%; transform: translateX(-50%); z-index: 5;
  display: flex; align-items: center; gap: 14px; padding: 8px 12px; white-space: nowrap;
  top: max(12px, env(safe-area-inset-top));
}
.g-stat { display: flex; flex-direction: column; align-items: center; line-height: 1.05; }
.g-stat small { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .08em; }
.g-stat b { font-size: 22px; color: var(--accent-2); font-variant-numeric: tabular-nums; }
.g-lives { display: flex; gap: 3px; }
.g-lives img { width: 21px; height: 21px; image-rendering: pixelated; }
.g-btns { display: flex; gap: 6px; }
.g-btns .px-btn { width: 36px; height: 36px; padding: 0; font-size: 16px; }
.g-power { height: 6px; background: var(--ink); width: 100%; margin-top: 4px; }
.g-power i { display: block; height: 100%; background: var(--accent); width: 0; }

.g-sprite {
  width: 48px; height: 48px; background-repeat: no-repeat; background-size: 200% 100%;
  image-rendering: pixelated; pointer-events: none; animation: g-walk .26s steps(1) infinite;
  filter: drop-shadow(0 3px 0 rgba(13, 19, 28, .35));
}
.g-sprite.flip { transform: scaleX(-1); }
.g-sprite.drone { animation-duration: .12s; }
.g-sprite.ghost { opacity: .35; }
.g-sprite.idle { animation-play-state: paused; }
@keyframes g-walk { 0% { background-position: 0 0; } 50% { background-position: 100% 0; } }
.g-zone {
  position: absolute; left: 50%; transform: translateX(-50%); z-index: 5; white-space: nowrap;
  top: calc(max(12px, env(safe-area-inset-top)) + 70px); padding: 4px 10px; font-size: 13px; color: var(--accent-2);
  max-width: calc(100vw - 24px); overflow: hidden; text-overflow: ellipsis;
}
.g-arrow { position: absolute; z-index: 4; width: 56px; height: 56px; pointer-events: none; }
.g-arrow i {
  position: absolute; inset: 0; background: var(--accent);
  clip-path: polygon(100% 50%, 20% 10%, 38% 50%, 20% 90%);
  filter: drop-shadow(0 0 0 var(--ink));
  animation: g-pulse .7s steps(2) infinite;
}
.g-arrow span {
  position: absolute; left: 50%; top: 50%; margin: -9px 0 0 -26px; width: 52px; text-align: center;
  font-size: 12px; font-weight: 700; color: #fff; text-shadow: 0 1px 0 var(--ink), 0 0 3px var(--ink);
}
@keyframes g-pulse { 50% { opacity: .55; } }
.g-landing { background: rgba(13, 19, 28, .55); z-index: 10; }
.g-sprites { display: flex; justify-content: center; align-items: flex-end; gap: 14px; margin: 6px 0 10px; }
.g-sprites canvas { width: 40px; height: 40px; image-rendering: pixelated; }
.g-landing .px-btn + .px-btn { margin-top: 8px; }
.g-landing .px-btn[disabled] { opacity: .7; cursor: progress; }
.g-float { position: absolute; font-weight: 700; color: #fff; font-size: 18px; text-shadow: 0 2px 0 var(--ink), 0 0 4px var(--ink); pointer-events: none; animation: g-up .9s ease-out forwards; }
@keyframes g-up { from { transform: translateY(0); opacity: 1; } to { transform: translateY(-34px); opacity: 0; } }

.g-overlay {
  position: absolute; inset: 0; z-index: 6; display: grid; place-items: center;
  background: rgba(13, 19, 28, .45); padding: 16px;
}
.g-card { padding: 20px 22px; text-align: center; max-width: 360px; width: 100%; }
.g-card h2 { font-size: 26px; color: var(--accent); text-transform: none; letter-spacing: 0; margin: 0 0 8px; }
.g-card p { margin: 6px 0; }
.g-card .big-num { font-size: 64px; color: var(--accent-2); font-weight: 700; line-height: 1; margin: 10px 0; }
.g-card .px-btn { margin-top: 10px; }

.g-pad {
  position: absolute; z-index: 5; right: 16px; bottom: calc(26px + env(safe-area-inset-bottom));
  display: grid; grid-template-columns: repeat(3, 58px); grid-template-rows: repeat(3, 58px); gap: 4px;
  touch-action: none; user-select: none; -webkit-user-select: none;
}
.g-pad button { font-size: 24px; padding: 0; touch-action: none; opacity: .92; }
.g-pad button[data-d="up"] { grid-area: 1 / 2; }
.g-pad button[data-d="left"] { grid-area: 2 / 1; }
.g-pad button[data-d="right"] { grid-area: 2 / 3; }
.g-pad button[data-d="down"] { grid-area: 3 / 2; }
.g-pad button.held { background: var(--accent); color: var(--accent-fg); }
body.game-on #map { touch-action: none; }

/* ---------- mobil ---------- */
@media (max-width: 640px) {
  .panel { top: auto; left: 0; right: 0; bottom: 0; width: auto; max-height: 62vh; }
  .panel.hidden { transform: translateY(calc(100% + 30px)); }
  .tabs button { font-size: 11.5px; }
  .g-hud { gap: 8px; padding: 6px 8px; }
  .g-stat b { font-size: 18px; }
  .g-btns .px-btn { width: 32px; height: 32px; }
  .g-pad { left: 50%; right: auto; transform: translateX(-50%); grid-template-columns: repeat(3, 66px); grid-template-rows: repeat(3, 66px); }
}
@media (pointer: fine) and (min-width: 641px) {
  .g-pad { display: none; }
  body.show-pad .g-pad { display: grid; }
}
