:root {
  --ink: #ece6d8;
  --ink-dim: #b8b0a0;
  --panel: rgba(10, 10, 12, 0.82);
  --panel-edge: rgba(236, 230, 216, 0.16);
  --p1: #ff8a3d;
  --p2: #3dd6c8;
  --gold: #f2c94c;
  --bad: #ff4040;
  --warn: #ffb03a;
  --good: #9fe870;
  --syn: #b58cff;
  --light: #fff0c8;
  --mono: "Courier New", ui-monospace, "DejaVu Sans Mono", monospace;
  font-family: "Trebuchet MS", "Segoe UI", system-ui, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #000;
  color: var(--ink);
}

#game { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }

[hidden] { display: none !important; }

/* ---------------- filtr VHS: linie, ziarno, winieta */
#vhs {
  position: fixed; inset: 0;
  pointer-events: none;
  background:
    radial-gradient(ellipse at center, transparent 55%, rgba(0, 0, 0, 0.75) 100%),
    repeating-linear-gradient(0deg, rgba(0, 0, 0, 0.22) 0 1px, transparent 1px 3px);
  mix-blend-mode: multiply;
}
#vhs::after {
  content: "";
  position: absolute; inset: -50%;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='160' height='160'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 1  0 0 0 0 1  0 0 0 0 1  0 0 0 0.55 0'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>");
  opacity: 0.09;
  mix-blend-mode: screen;
  animation: grain 0.5s steps(5) infinite;
}
@keyframes grain {
  0% { transform: translate(0, 0); }
  20% { transform: translate(-6%, 4%); }
  40% { transform: translate(5%, -7%); }
  60% { transform: translate(-3%, 8%); }
  80% { transform: translate(7%, 2%); }
  100% { transform: translate(0, 0); }
}

#flash { position: fixed; inset: 0; pointer-events: none; opacity: 0; }
#flash.red { animation: flashRed 0.9s ease-out; }
#flash.white { animation: flashWhite 0.25s ease-out; }
@keyframes flashRed { from { opacity: 1; background: rgba(160, 0, 0, 0.55); } to { opacity: 0; background: rgba(160, 0, 0, 0); } }
@keyframes flashWhite { from { opacity: 1; background: rgba(255, 255, 255, 0.25); } to { opacity: 0; } }

kbd {
  display: inline-block;
  min-width: 1.6em;
  padding: 0.05em 0.4em;
  margin: 0 0.1em;
  border-radius: 5px;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.28);
  border-bottom-width: 3px;
  font: inherit;
  font-size: 0.88em;
  text-align: center;
}
kbd.big { font-size: 1.1em; padding: 0.15em 0.6em; }

.p1 { color: var(--p1); font-weight: bold; }
.p2 { color: var(--p2); font-weight: bold; }
.muted { color: var(--ink-dim); opacity: 0.85; }

/* ---------------- HUD */
#hud {
  position: fixed;
  top: 0; left: 0; right: 0;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: start;
  padding: 14px 18px;
  pointer-events: none;
  font-family: var(--mono);
  text-shadow: 0 0 6px rgba(0, 0, 0, 0.9);
}
#night { font-size: 16px; letter-spacing: 0.15em; text-transform: uppercase; color: var(--ink-dim); }
#clock { font-size: 40px; font-weight: bold; letter-spacing: 0.05em; color: #ffdf9a; text-shadow: 0 0 12px rgba(255, 190, 90, 0.45); }

.hud-center { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.fuel-label { font-size: 12px; letter-spacing: 0.2em; text-transform: uppercase; color: var(--ink-dim); }
#fuel { width: 180px; height: 12px; border: 1px solid rgba(255, 223, 154, 0.5); border-radius: 2px; background: rgba(0, 0, 0, 0.6); overflow: hidden; }
#fuel-fill { height: 100%; width: 100%; background: linear-gradient(90deg, #d38b2a, #ffdf9a); transition: width 0.1s linear; }
#fuel.low #fuel-fill { background: var(--warn); animation: blink 0.5s steps(2) infinite; }
#fuel.out { border-color: var(--bad); }
#fuel.out #fuel-fill { background: var(--bad); }

.hud-right { justify-self: end; }
.coins { display: flex; align-items: center; gap: 8px; font-size: 24px; font-weight: bold; }
.coin-icon {
  width: 18px; height: 18px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #fff3a0, var(--gold) 55%, #9a7000);
}

@keyframes blink { 50% { opacity: 0.35; } }

/* ---------------- panele graczy */
#panels {
  position: fixed;
  left: 16px; right: 16px; bottom: 16px;
  display: flex; justify-content: space-between; gap: 16px;
  pointer-events: none;
}
.panel {
  width: min(330px, 46vw);
  padding: 8px 12px 10px;
  border-radius: 6px;
  background: var(--panel);
  border: 1px solid var(--panel-edge);
  font-size: 14px;
}
.panel.p1 { border-left: 4px solid var(--p1); }
.panel.p2 { border-left: 4px solid var(--p2); margin-left: auto; }
.pname { font-weight: bold; margin-bottom: 5px; }
.panel.p1 .pname { color: var(--p1); }
.panel.p2 .pname { color: var(--p2); }
.pname .beam { color: var(--ink-dim); font-weight: normal; font-size: 12px; margin-left: 6px; }
.pname .off { color: var(--bad); font-weight: normal; font-size: 12px; }
.bar { height: 10px; border-radius: 2px; background: rgba(255, 255, 255, 0.08); overflow: hidden; }
.bar > div { height: 100%; background: linear-gradient(90deg, #9fe870, #e6ff9a); }
.bar.battery.low > div { background: var(--warn); animation: blink 0.4s steps(2) infinite; }
.bar.battery.empty { outline: 1px solid var(--bad); }
.bar.revive > div { background: linear-gradient(90deg, #fff0c8, #ffffff); }
.items { margin-top: 5px; min-height: 1.2em; color: var(--ink-dim); font-size: 13px; }
.hint { margin-top: 3px; min-height: 1.2em; font-size: 13px; color: var(--light); }
.panel.caught { border-color: rgba(255, 64, 64, 0.5); }
.panel.caught .pname { color: var(--bad) !important; letter-spacing: 0.05em; }
.prog { display: inline-block; width: 70px; height: 7px; margin-left: 6px; background: rgba(255, 255, 255, 0.12); vertical-align: middle; }
.prog i { display: block; height: 100%; background: var(--light); }

/* ---------------- build */
#builds {
  position: fixed;
  left: 16px; top: 100px;
  display: flex; flex-direction: column; gap: 6px;
  pointer-events: none;
  max-width: min(60vw, 380px);
}
.build {
  display: flex; flex-wrap: wrap; gap: 5px; align-items: center;
  padding: 5px 9px;
  border-radius: 6px;
  background: var(--panel);
  font-size: 12px;
}
.build.p1 { border-left: 3px solid var(--p1); }
.build.p2 { border-left: 3px solid var(--p2); }
.build span { padding: 1px 6px; border-radius: 4px; background: rgba(255, 255, 255, 0.1); }
.build.syn { color: var(--syn); font-weight: bold; border-left: 3px solid var(--syn); }

/* ---------------- komunikaty */
#toast {
  position: fixed;
  top: 92px; left: 50%;
  transform: translate(-50%, -10px);
  padding: 9px 18px;
  border-radius: 6px;
  background: var(--panel);
  border: 1px solid var(--panel-edge);
  font-size: 18px; font-weight: bold;
  opacity: 0;
  transition: opacity 0.25s, transform 0.25s;
  pointer-events: none;
  text-align: center;
  max-width: min(760px, calc(100vw - 32px));
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.bad { color: var(--bad); }
#toast.warn { color: var(--warn); }
#toast.good { color: var(--good); }
#toast.news { color: var(--light); }
#toast.boss { color: var(--bad); font-size: 22px; border-color: var(--bad); }
#toast.syn { color: var(--syn); }

#floaters { position: fixed; inset: 0; pointer-events: none; }
.floater {
  position: absolute;
  top: 44%;
  font-size: 24px; font-weight: 900;
  text-shadow: 0 2px 4px #000;
  animation: floatUp 1.2s ease-out forwards;
}
.floater.coin { color: var(--gold); }
.floater.bat { color: var(--good); }
@keyframes floatUp {
  from { transform: translateY(0); opacity: 1; }
  to { transform: translateY(-80px); opacity: 0; }
}

/* ---------------- ekrany */
#overlay {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  padding: 16px;
  background: rgba(0, 0, 0, 0.45);
  overflow-y: auto;
}
.card {
  width: min(760px, 100%);
  margin: auto;
  padding: 26px 32px;
  border-radius: 8px;
  background: var(--panel);
  border: 1px solid var(--panel-edge);
  box-shadow: 0 0 60px rgba(0, 0, 0, 0.8);
  text-align: center;
  line-height: 1.45;
}
.card h1 {
  margin: 0;
  font-family: var(--mono);
  font-size: clamp(54px, 13vw, 104px);
  letter-spacing: 0.25em;
  padding-left: 0.25em;
  color: var(--light);
  text-shadow: 0 0 18px rgba(255, 220, 140, 0.8), 0 0 60px rgba(255, 180, 80, 0.45);
  animation: flicker 4s infinite;
}
@keyframes flicker {
  0%, 18%, 22%, 62%, 64%, 100% { opacity: 1; }
  20%, 63% { opacity: 0.35; }
}
.card h2 { margin: 0 0 10px; font-size: 28px; }
.tag { font-size: 20px; margin: 6px 0 16px; color: var(--ink); font-style: italic; }
.rules { text-align: left; color: var(--ink-dim); }
.rules p { margin: 8px 0; }
.controls { margin: 16px 0; display: grid; gap: 8px; font-size: 14px; text-align: left; }
.cta { display: flex; justify-content: center; gap: 28px; flex-wrap: wrap; margin-top: 18px; font-size: 18px; font-weight: bold; }

.cards { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin: 16px 0; }
@media (max-width: 640px) { .cards { grid-template-columns: 1fr; } }
.upgrade {
  position: relative;
  display: flex; flex-direction: column; gap: 6px; align-items: flex-start;
  padding: 16px 14px 14px;
  border-radius: 6px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: rgba(255, 255, 255, 0.05);
  color: var(--ink);
  font: inherit;
  text-align: left;
  cursor: pointer;
  transition: transform 0.1s, border-color 0.1s, box-shadow 0.1s;
}
.upgrade:hover { transform: translateY(-3px); border-color: var(--light); box-shadow: 0 0 24px rgba(255, 230, 170, 0.2); }
.upgrade .key {
  position: absolute; top: -12px; right: -10px;
  width: 28px; height: 28px; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--light); color: #1a1408; font-weight: 900;
}
.uname { font-size: 17px; font-weight: bold; }
.uname small { font-weight: normal; color: var(--ink-dim); }
.utag { font-size: 12px; padding: 1px 8px; border-radius: 4px; background: rgba(255, 255, 255, 0.1); }
.tag-Światło { color: #fff0a0; background: rgba(255, 240, 160, 0.15); }
.tag-Ogień { color: #ff9a6a; background: rgba(255, 120, 60, 0.15); }
.tag-Prąd { color: #8ad8ff; background: rgba(100, 200, 255, 0.15); }
.udesc { font-size: 14px; color: var(--ink-dim); }
.synergies { text-align: left; font-size: 13px; color: var(--ink-dim); padding-left: 18px; margin: 0; }
.synergies li.on { color: var(--syn); }
.end.won h2 { color: var(--good); }
.end.lost h2 { color: var(--bad); }
.big-stat { font-size: 20px; }
.record { color: var(--gold); font-weight: bold; font-size: 20px; }

@media (max-width: 640px) {
  #clock { font-size: 28px; }
  #fuel { width: 110px; }
  .card { padding: 20px 16px; }
  #panels { flex-direction: column; }
  .panel { width: 100%; }
  .panel.p2 { margin-left: 0; }
}

code {
  font-family: var(--mono);
  font-size: 0.85em;
  padding: 1px 5px;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.08);
  word-break: break-all;
}
