@font-face { font-family: "Press Start 2P"; src: url(/assets/fonts/PressStart2P.woff2?v=4a9fe17b8c) format("woff2"); font-display: swap; }
@font-face { font-family: "Pixelify Sans"; src: url(/assets/fonts/PixelifySans.woff2?v=4a9fe17b8c) format("woff2"); font-display: swap; }

:root {
  --bg: #0b1a17;
  --panel: #122924;
  --panel-2: #18302b;
  --line: #2c4a42;
  --gold: #e2b254;
  --gold-dark: #a77d35;
  --cream: #d9cca6;
  --hop: #78b048;
  --red: #e0533f;
  --muted: #8fa59c;
  --pixel: "Press Start 2P", monospace;
  --text: "Pixelify Sans", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--cream);
  font: 18px/1.4 var(--text);
  -webkit-font-smoothing: none;
  -webkit-tap-highlight-color: transparent;
}
body.playing { overflow: hidden; overscroll-behavior: none; touch-action: none; -webkit-touch-callout: none; -webkit-user-select: none; user-select: none; }
button, input { font: inherit; }

#app { min-height: 100%; }
.screen { display: none; }
.screen.active { display: flex; }
#screen-start, #screen-over, #screen-board {
  flex-direction: column; align-items: center; text-align: center;
  max-width: 520px; margin: 0 auto;
  padding: max(24px, env(safe-area-inset-top)) 18px max(28px, env(safe-area-inset-bottom));
  gap: 14px;
}

.brand { width: 170px; height: auto; opacity: .85; image-rendering: auto; }
.logo {
  margin: 4px 0 0;
  font: 400 clamp(34px, 11vw, 54px)/1 var(--pixel);
  color: var(--gold);
  text-shadow: 4px 4px 0 #6b4a17, 8px 8px 0 #000;
  letter-spacing: .02em;
}
.subtitle, .title, .result-label, .gallery-title { font-family: var(--pixel); letter-spacing: .08em; }
.subtitle { margin: 0; font-size: 11px; color: var(--cream); }
.title { margin: 8px 0 0; font-size: 22px; color: var(--gold); text-shadow: 3px 3px 0 #000; }

.howto {
  display: flex; gap: 14px; align-items: center; text-align: left;
  background: var(--panel); border: 3px solid var(--line); padding: 12px 14px;
  font-size: 16px;
}
.howto img { image-rendering: pixelated; flex: none; }
.howto p { margin: 0; }
.howto b { color: var(--gold); font-weight: 400; }

form { width: 100%; display: grid; gap: 12px; }
.field { display: grid; gap: 6px; text-align: left; }
.field span { font-family: var(--pixel); font-size: 10px; color: var(--muted); }
.field input {
  width: 100%; padding: 12px 14px; font-size: 20px;
  background: #06110f; color: var(--cream); border: 3px solid var(--line); border-radius: 0; outline: none;
}
.field input:focus { border-color: var(--gold); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 12px 18px; border: 3px solid var(--line); border-radius: 0;
  background: var(--panel-2); color: var(--cream); cursor: pointer; font-size: 18px;
  box-shadow: 4px 4px 0 #000;
}
.btn:active { transform: translate(2px, 2px); box-shadow: 2px 2px 0 #000; }
.btn.primary { background: var(--gold); border-color: #fff3c4; color: #1b1206; font-family: var(--pixel); font-size: 14px; }
.btn.big { padding: 18px; font-size: 18px; }
.btn.link { background: none; border: 0; box-shadow: none; color: var(--muted); text-decoration: underline; padding: 6px 10px; }
.btn:disabled { opacity: .5; }
.start-links, .actions { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }

.error { color: var(--red); margin: 0; }
.muted { color: var(--muted); }

.round-banner {
  width: 100%; padding: 10px 12px; background: #2a1d07; border: 3px solid var(--gold-dark);
  font-size: 16px;
}
.round-banner strong { color: var(--gold); font-family: var(--pixel); font-size: 12px; font-weight: 400; }
.round-prize { color: var(--gold); margin-top: 4px; }
.opens { width: 100%; padding: 14px; background: #2a1d07; border: 3px solid var(--gold); display: grid; gap: 8px; }
.opens b { color: var(--gold); font-weight: 400; }
.opens strong { font-family: var(--pixel); font-size: 18px; color: var(--cream); font-weight: 400; }
.opens small { color: var(--muted); font-size: 15px; }

/* ---------- Game ---------- */
#screen-game {
  flex-direction: column; align-items: center; justify-content: flex-start;
  height: 100dvh; padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom);
  background: #000;
  position: relative; touch-action: none; user-select: none; -webkit-user-select: none;
}
/* Free space under the field (most phones): the thumb steers there without covering the game. */
.pad { flex: 1; width: 100%; display: grid; place-items: center; min-height: 0; }
.pad span { font-size: 15px; color: #4d6a60; text-align: center; line-height: 1.6; }
@media (max-aspect-ratio: 3/5) { .pad { border-top: 2px dashed #1b2b27; } }
.hud {
  width: min(100vw, calc((100dvh - 56px - env(safe-area-inset-top) - env(safe-area-inset-bottom)) * .75));
  min-width: 300px;
  display: grid; grid-template-columns: auto 1fr auto; gap: 10px; align-items: center;
  height: 56px; padding: 6px 8px;
  font-family: var(--pixel); font-size: 10px; color: var(--cream);
}
.hud small { display: block; color: var(--muted); font-size: 8px; margin-bottom: 4px; }
.hud-score b { font-size: 14px; color: var(--gold); font-weight: 400; }
.hud-mid { display: grid; gap: 4px; }
.hud-level { font-size: 8px; color: var(--muted); }
.hud-bar { position: relative; height: 8px; background: #1b2b27; border: 2px solid var(--line); }
.hud-bar i { position: absolute; inset: 0 auto 0 0; width: 0; background: var(--gold); }
.hud-target { position: absolute; top: -4px; bottom: -4px; left: 75%; width: 2px; background: #fff; }
.hud-pct { font-size: 8px; color: var(--muted); }
.hud-pct b { color: var(--cream); font-weight: 400; }
.hud-right { display: grid; justify-items: end; gap: 6px; }
.hud-lives { display: flex; gap: 3px; height: 21px; }
.hud-lives img { width: 12px; height: 21px; image-rendering: pixelated; }
.hud-lives img.lost { opacity: .2; }
.hud-time { font-size: 12px; }
.hud-time.low { color: var(--red); }

.stage {
  position: relative;
  width: min(100vw, calc((100dvh - 56px - env(safe-area-inset-top) - env(safe-area-inset-bottom)) * .75));
  aspect-ratio: 3 / 4;
  touch-action: none; user-select: none; -webkit-user-select: none;
}
#game { display: block; width: 100%; height: 100%; image-rendering: pixelated; image-rendering: crisp-edges; }
.crt {
  position: absolute; inset: 0; pointer-events: none;
  background: repeating-linear-gradient(to bottom, rgba(0, 0, 0, .14) 0 1px, transparent 1px 3px);
  box-shadow: inset 0 0 60px rgba(0, 0, 0, .55);
}
.stick {
  position: absolute; width: 84px; height: 84px; margin: -42px 0 0 -42px; pointer-events: none;
  border: 2px solid rgba(226, 178, 84, .5); border-radius: 50%;
}
.stick i {
  position: absolute; left: 50%; top: 50%; width: 30px; height: 30px; margin: -15px 0 0 -15px;
  border-radius: 50%; background: rgba(226, 178, 84, .45);
}
.pause-btn {
  position: absolute; top: 8px; right: 8px; width: 40px; height: 40px;
  background: rgba(0, 0, 0, .55); color: var(--cream); border: 2px solid var(--line);
  font-size: 14px; cursor: pointer;
}
.pause-menu { position: absolute; inset: 0; display: grid; place-items: center; background: rgba(0, 0, 0, .7); }
.pause-menu[hidden] { display: none; }
.pause-card { background: var(--panel); border: 3px solid var(--gold-dark); padding: 22px; width: min(86%, 320px); text-align: center; box-shadow: 6px 6px 0 #000; }
.pause-card h2 { font-family: var(--pixel); font-size: 18px; color: var(--gold); margin: 0 0 10px; }
.pause-actions { display: flex; flex-direction: column; gap: 12px; }

/* ---------- Results ---------- */
.result { display: grid; gap: 6px; }
.result-label { font-size: 10px; color: var(--muted); }
.result-score { font-family: var(--pixel); font-size: clamp(28px, 10vw, 44px); color: var(--gold); text-shadow: 4px 4px 0 #000; }
.result-sub { color: var(--muted); }
.result-rank { color: var(--gold); font-size: 20px; }
.claim { background: var(--panel); border: 3px dashed var(--gold-dark); padding: 12px 16px; }
.claim strong { font-family: var(--pixel); font-size: 18px; color: var(--gold); letter-spacing: .15em; font-weight: 400; }
.claim small { display: block; color: var(--muted); margin-top: 6px; }
.gallery { width: 100%; }
.gallery-title { font-size: 10px; color: var(--muted); margin-bottom: 8px; }
.gallery-items { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 6px; justify-content: center; flex-wrap: wrap; }
.gallery-items figure { margin: 0; width: 84px; }
.gallery-items img { width: 84px; height: 112px; image-rendering: pixelated; border: 2px solid var(--gold-dark); display: block; }
.gallery-items figcaption { font-size: 12px; color: var(--cream); margin-top: 4px; line-height: 1.1; }

/* ---------- Leaderboard ---------- */
.tabs { display: flex; gap: 6px; }
.tab { padding: 8px 12px; background: var(--panel); border: 2px solid var(--line); color: var(--muted); cursor: pointer; }
.tab[aria-selected="true"] { border-color: var(--gold); color: var(--gold); }
.table-wrap { width: 100%; max-height: 55vh; overflow: auto; border: 3px solid var(--line); }
.board { width: 100%; border-collapse: collapse; font-size: 17px; }
.board th { position: sticky; top: 0; background: var(--panel-2); font-family: var(--pixel); font-size: 9px; color: var(--muted); font-weight: 400; padding: 8px 6px; text-align: left; }
.board td { padding: 7px 6px; border-top: 1px solid var(--line); text-align: left; }
.board .num { text-align: right; font-family: var(--pixel); font-size: 11px; }
.board tr.me td { background: #2a1d07; color: var(--gold); }
.board tr:first-child td { color: var(--gold); }

/* ---------- Settings ---------- */
.settings { background: var(--panel); color: var(--cream); border: 3px solid var(--gold-dark); padding: 22px; width: min(90vw, 340px); box-shadow: 6px 6px 0 #000; }
.settings::backdrop { background: rgba(0, 0, 0, .7); }
.settings h2 { font-family: var(--pixel); font-size: 16px; color: var(--gold); text-align: center; margin: 0 0 14px; }
.settings form { gap: 0; }
.settings .btn { width: 100%; margin-top: 18px; }
.set-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.set-row input[type="range"] { width: 140px; accent-color: var(--gold); }
.switch {
  appearance: none; -webkit-appearance: none; flex: none; position: relative;
  width: 50px; height: 28px; margin: 0; background: var(--line); cursor: pointer;
}
.switch::after { content: ""; position: absolute; top: 4px; left: 4px; width: 20px; height: 20px; background: var(--cream); transition: transform .12s; }
.switch:checked { background: var(--gold-dark); }
.switch:checked::after { transform: translateX(22px); }
