:root {
  --ink: #181425; --plum: #68386c; --red: #e43b44; --orange: #f77622;
  --sand: #feae34; --lime: #63c74d; --green: #3e8948; --teal: #265c42;
  --navy: #124e89; --blue: #0099db; --sky: #2ce8f5; --ice: #2ce8f5;
  --white: #ffffff; --silver: #c0cbdc; --slate: #8b9bb4; --night: #3a4466;
  --bg: #0f0d1a;
  --panel: rgba(24, 20, 37, 0.94);
  --px: 'Silkscreen', ui-monospace, 'Consolas', monospace;
  --sans: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --scale: 3;
  --w: calc(360px * var(--scale));
  --h: calc(312px * var(--scale));
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { margin: 0; min-height: 100%; }
body {
  background: radial-gradient(ellipse at 50% -10%, #262b44 0%, var(--bg) 60%) fixed, var(--bg);
  color: var(--white);
  font: 15px/1.5 var(--sans);
  display: flex;
  justify-content: center;
}

.app {
  width: var(--w);
  max-width: calc(100vw - 32px);
  padding: 20px 0 28px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* ---------- fejléc ---------- */

.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.brand { font-family: var(--px); font-size: 20px; letter-spacing: 1px; color: var(--white); }
.brand span { color: var(--lime); }
.who { display: flex; align-items: center; gap: 12px; font-family: var(--px); font-size: 13px; color: var(--silver); }
.link { background: none; border: 0; color: var(--slate); font: inherit; cursor: pointer; padding: 0; }
.link:hover { color: var(--white); }

/* ---------- HUD ---------- */

.hud {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto auto auto;
  gap: 4px 22px;
  align-items: end;
  padding: 8px 16px 10px;
  background: var(--ink);
  border: 2px solid var(--night);
  opacity: 0.45;
  transition: opacity 0.2s;
}
.hud.active { opacity: 1; }
.hud-item { display: grid; gap: 4px; min-width: 0; }
.hud-label { font-size: 10px; text-transform: uppercase; letter-spacing: 0.1em; color: var(--slate); }
.hud-value { font-family: var(--px); font-size: 16px; line-height: 20px; color: var(--white); white-space: nowrap; }
#hud-env { color: var(--lime); }
.hud-time { grid-template-columns: minmax(0, 1fr) auto; column-gap: 10px; align-items: center; }
.hud-time .hud-label { grid-column: 1 / -1; }
.hud-score { text-align: right; }
.hud-score .hud-value { color: var(--sand); min-width: 5ch; }
.timebar { height: 8px; background: var(--night); }
#hud-timebar { height: 100%; width: 0; background: var(--green); transition: width 1s linear, background-color 0.3s; }
#hud-timebar.mid { background: var(--sand); }
#hud-timebar.low { background: var(--red); }
.lives, .effects { display: flex; gap: 2px; height: 24px; align-items: center; }
.lives canvas, .effects canvas { width: 24px; height: 24px; image-rendering: pixelated; }
.effects { gap: 8px; min-width: 70px; }
.effects .none { color: var(--night); font-family: var(--px); }
.effects .fx { display: flex; align-items: center; gap: 2px; animation: pop 0.25s ease-out; }
.effects .fx b { font: 13px var(--px); color: var(--white); }
.effects .fx-flag b { color: var(--lime); }
.effects .fx-window b, .effects .fx-shield b { color: var(--sky); }
.effects .fx-coffee b { color: var(--sand); }
@keyframes pop { from { transform: scale(1.6); } to { transform: scale(1); } }
.legend canvas { width: 24px; height: 24px; image-rendering: pixelated; }
.lives canvas.lost { opacity: 0.18; filter: grayscale(1); }

/* ---------- játéktér ---------- */

.stage {
  position: relative;
  width: var(--w);
  height: var(--h);
  max-width: 100%;
  box-shadow: 0 0 0 3px var(--night), 0 0 0 6px var(--ink), 0 24px 60px rgba(0, 0, 0, 0.55);
}
#game {
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(18, 19, 31, 0.72);
  backdrop-filter: blur(2px);
}

.panel {
  width: min(400px, 100%);
  max-height: 100%;
  overflow: auto;
  padding: 24px 26px;
  background: var(--panel);
  border: 2px solid var(--night);
  box-shadow: 6px 6px 0 rgba(0, 0, 0, 0.35);
}
.panel-wide { width: min(520px, 100%); }
.panel.good { border-color: var(--green); }
.panel.bad { border-color: var(--red); }

.kicker { margin: 0 0 4px; font-family: var(--px); font-size: 12px; letter-spacing: 0.06em; color: var(--lime); }
.panel.bad .kicker { color: var(--orange); }
h1, h2, h3 { font-family: var(--px); font-weight: 400; margin: 0; line-height: 1.15; }
h1 { font-size: 30px; margin-bottom: 10px; }
h2 { font-size: 24px; margin-bottom: 14px; }
h3 { font-size: 14px; color: var(--silver); margin: 20px 0 8px; }
.lead { margin: 0 0 18px; color: var(--silver); }
.hint { margin: 8px 0 0; font-size: 13px; color: var(--slate); }
.hint b { color: var(--white); font-weight: 600; }
.error { margin: -6px 0 14px; color: var(--orange); font-size: 13px; }

.field { display: grid; gap: 6px; margin-bottom: 16px; }
.field span { font-size: 12px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--slate); }
.field input {
  font: 16px var(--sans);
  color: var(--white);
  background: var(--ink);
  border: 2px solid var(--night);
  padding: 10px 12px;
  outline: none;
}
.field input:focus { border-color: var(--lime); }

.actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 18px; }
.btn {
  font: 14px var(--px);
  color: var(--ink);
  background: var(--green);
  border: 0;
  padding: 11px 16px;
  cursor: pointer;
  box-shadow: inset -3px -3px 0 rgba(0, 0, 0, 0.25);
  transition: background-color 0.12s, transform 0.08s;
}
.btn:hover { background: var(--lime); }
.btn:active { transform: translateY(1px); }
.btn.ghost { color: var(--silver); background: transparent; box-shadow: inset 0 0 0 2px var(--night); }
.btn.ghost:hover { color: var(--white); box-shadow: inset 0 0 0 2px var(--slate); }
kbd { font: 10px var(--px); opacity: 0.6; margin-left: 6px; }

/* ---------- menü ---------- */

.envs { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.env {
  display: grid;
  gap: 4px;
  align-content: start;
  text-align: left;
  padding: 10px;
  color: var(--white);
  background: var(--ink);
  border: 2px solid var(--green);
  cursor: pointer;
  font: inherit;
  transition: transform 0.1s, border-color 0.1s;
}
.env:hover { transform: translateY(-2px); border-color: var(--lime); }
.env.locked { border-color: var(--night); color: var(--slate); cursor: not-allowed; transform: none; }
.env-name { font-family: var(--px); font-size: 14px; }
.env-desc { font-size: 12px; line-height: 1.35; color: var(--silver); }
.env.locked .env-desc { color: var(--slate); }
.env-meta { font-size: 10px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--green); }
.env.locked .env-meta { color: var(--slate); }

.board { list-style: none; margin: 0; padding: 0; }
.board li {
  display: grid;
  grid-template-columns: 2.4em 1fr auto 6em;
  gap: 10px;
  padding: 5px 8px;
  font-size: 14px;
  border-bottom: 1px solid rgba(86, 108, 134, 0.25);
}
.board .rank { font-family: var(--px); color: var(--slate); }
.board li:nth-child(-n+3) .rank { color: var(--sand); }
.board .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.board .lvl { font-family: var(--px); font-size: 11px; color: var(--slate); align-self: center; }
.board .pts { font-family: var(--px); text-align: right; color: var(--white); }
.board li.me { background: rgba(56, 183, 100, 0.14); }
.board li.me .name { color: var(--lime); font-weight: 600; }

/* ---------- eredmény ---------- */

.breakdown { margin: 0; display: grid; gap: 2px; }
.breakdown div { display: flex; justify-content: space-between; gap: 12px; padding: 5px 0; border-bottom: 1px solid rgba(86, 108, 134, 0.25); }
.breakdown dt { color: var(--silver); }
.breakdown dt small { color: var(--slate); margin-left: 6px; }
.breakdown dd { margin: 0; font-family: var(--px); color: var(--lime); }
.breakdown .sum dt { color: var(--white); font-weight: 600; }
.breakdown .sum dd { color: var(--white); }
.breakdown .total { border-bottom: 0; }
.breakdown .total dd { color: var(--sand); font-size: 18px; }
.big-score { margin: 16px 0 0; font-family: var(--px); font-size: 34px; color: var(--sand); }
.big-score small { font-size: 14px; color: var(--slate); }

/* ---------- toast ---------- */

.toast {
  position: absolute;
  top: 14px;
  left: 50%;
  transform: translate(-50%, -8px);
  padding: 8px 14px;
  font: 13px var(--px);
  color: var(--white);
  background: var(--ink);
  border: 2px solid var(--slate);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s, transform 0.15s;
  white-space: nowrap;
  z-index: 5;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.bad { border-color: var(--red); color: var(--orange); }
.toast.good { border-color: var(--green); color: var(--lime); }
.toast.warn { border-color: var(--sand); color: var(--sand); }

/* ---------- jelmagyarázat ---------- */

.legend {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px 28px;
  margin-top: 8px;
  font-size: 12.5px;
  color: var(--slate);
}
.legend section { display: grid; gap: 4px; align-content: start; }
.legend h4 { margin: 0 0 4px; font: 11px var(--px); letter-spacing: 0.08em; color: var(--night); text-transform: uppercase; }
.legend div { display: flex; align-items: center; gap: 6px; }
@media (max-width: 640px) { .legend { grid-template-columns: 1fr; } }
.legend b { color: var(--silver); font-weight: 600; }

/* ---------- érintős irányítás ---------- */

.touchpad { display: none; }
.touch .touchpad {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 8px;
  opacity: 0.35;
  pointer-events: none;
  transition: opacity 0.2s;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}
.touch .touchpad.active { opacity: 1; pointer-events: auto; }
.touchpad button {
  font: 20px var(--px);
  color: var(--white);
  background: var(--ink);
  border: 2px solid var(--night);
  box-shadow: inset 0 -4px 0 rgba(0, 0, 0, 0.35);
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  cursor: pointer;
}
.touchpad button.pressed, .touchpad button:active { background: var(--green); border-color: var(--lime); color: var(--ink); transform: translateY(2px); box-shadow: none; }
.dpad {
  grid-column: 2;
  display: grid;
  grid-template-columns: repeat(3, 64px);
  grid-template-rows: repeat(2, 56px);
  gap: 6px;
}
.dpad .tp-up { grid-column: 2; grid-row: 1; }
.dpad .tp-left { grid-column: 1; grid-row: 2; }
.dpad .tp-down { grid-column: 2; grid-row: 2; }
.dpad .tp-right { grid-column: 3; grid-row: 2; }
.tp-pause { grid-column: 1; justify-self: start; width: 48px; height: 48px; font-size: 14px !important; }
.tp-hint { grid-column: 1 / -1; margin: 0; text-align: center; font-size: 12px; color: var(--slate); }
.touch .stage { touch-action: none; }
.touch kbd { display: none; }

/* ---------- keskeny képernyő ---------- */

@media (max-width: 640px) {
  .app { padding: 10px 0 20px; gap: 8px; max-width: calc(100vw - 16px); }
  .brand { font-size: 16px; }
  .who { font-size: 11px; gap: 8px; }
  .hud { grid-template-columns: auto auto auto 1fr; gap: 6px 14px; padding: 8px 10px; }
  .hud-time { grid-column: 1 / -1; grid-row: 1; }
  .hud-score { justify-self: end; }
  .hud-value { font-size: 14px; }
  .lives canvas, .effects canvas { width: 20px; height: 20px; }
  .overlay { position: fixed; z-index: 10; padding: 12px; background: rgba(15, 13, 26, 0.88); }
  .panel { max-height: calc(100dvh - 24px); }
  .panel { padding: 16px; }
  h1 { font-size: 22px; }
  h2 { font-size: 18px; margin-bottom: 10px; }
  .lead { font-size: 14px; margin-bottom: 12px; }
  .envs { grid-template-columns: repeat(2, 1fr); }
  .board li { grid-template-columns: 2em 1fr auto 4.5em; gap: 6px; font-size: 13px; }
  .toast { font-size: 11px; top: 8px; }
}
