@font-face {
  font-family: "Press Start 2P";
  src: url("../assets/fonts/PressStart2P.woff2") format("woff2");
  font-display: swap;
}

:root {
  /* v1 palette tokens (sleigh / pad colours) */
  --bg: #000000;
  --snow: #5A6470;
  --red: #FF3B5C;
  --green: #2BFF88;
  --gold: #FFC93C;
  --blue: #3CC8FF;
  --ui: #8A94A6;

  --pixel: "Press Start 2P", ui-monospace, monospace;
  --page: #04070f;
  --text: #e6eaf4;
  --text-dim: #9aa4bc;
  --accent: var(--gold);
  --win-top: #22307a;
  --win-bottom: #0e1542;
  --win-edge: #d4dcef;
  --win-inner: #4a5aa8;
  --win-outline: #04060e;
  --btn: #182260;
  --btn-shade: #0a0f30;
  --hud-h: calc(44px + env(safe-area-inset-top, 0px));
}

/* Backstage mode: pure black and the UI at ~40% luminance */
body.backstage {
  --page: var(--bg);
  --text: #6c7488;
  --text-dim: #4c5366;
  --accent: #8c7434;
  --win-top: #0f1636;
  --win-bottom: #070b1e;
  --win-edge: #4f5870;
  --win-inner: #1d2752;
  --btn: #0b1130;
  --btn-shade: #04060f;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--page);
  color: var(--text);
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  position: fixed;
  inset: 0;
  font: 10px/1.8 var(--pixel);
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: none;
  -webkit-font-smoothing: none;
}

img.icon { width: 20px; height: 20px; image-rendering: pixelated; vertical-align: middle; }

#stage {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  top: var(--hud-h);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

#game { display: block; width: 100%; height: 100%; touch-action: none; }

/* ---------- HUD ---------- */
#hud {
  position: absolute;
  top: 0; left: 0; right: 0;
  height: var(--hud-h);
  padding: env(safe-area-inset-top, 0px) 6px 0 10px;
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 16px;
  background: linear-gradient(var(--win-top), var(--win-bottom));
  border-bottom: 4px solid var(--win-edge);
  box-shadow: 0 4px 0 var(--win-outline);
  z-index: 5;
}
#hud[hidden] { display: none; }
.hud-route { flex: 1; color: var(--accent); white-space: nowrap; }
.hud-stat { display: flex; align-items: center; gap: 6px; }
.hud-stat b { font-weight: normal; font-variant-numeric: tabular-nums; min-width: 2ch; }
.hud-pause { min-width: 40px; min-height: 32px; padding: 0; }
.pause-icon { display: inline-block; width: 12px; height: 12px; border-left: 4px solid currentColor; border-right: 4px solid currentColor; vertical-align: middle; }

/* ---------- screens & windows ---------- */
.screen {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 24px 16px calc(24px + env(safe-area-inset-bottom, 0px));
  background: rgba(0, 0, 0, 0.55);
  touch-action: manipulation;
  overflow-y: auto;
}
.screen.dim { background: rgba(0, 0, 0, 0.45); }
.screen.title { background: rgba(0, 0, 0, 0.35); }
.screen.active { display: flex; }

/* SNES-RPG style dialogue window: hard pixel borders, no rounding */
.window {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  width: min(320px, 100%);
  padding: 18px 16px;
  background: linear-gradient(var(--win-top), var(--win-bottom));
  border: 4px solid var(--win-edge);
  box-shadow: 0 0 0 4px var(--win-outline), inset 0 0 0 4px var(--win-inner), 8px 8px 0 4px rgba(0, 0, 0, 0.5);
}
.window.wide { width: min(360px, 100%); }

h1, h2 { margin: 0; font-weight: normal; text-align: center; }
h2 { font-size: 16px; color: var(--accent); text-shadow: 2px 2px 0 var(--win-outline); margin-bottom: 4px; }
h2.danger { color: var(--red); }
body.backstage h2.danger { color: #8e2a3a; }

.logo { display: flex; flex-direction: column; align-items: center; gap: 10px; }
.logo-1 {
  font-size: 40px;
  line-height: 1;
  color: var(--accent);
  text-shadow: 4px 0 0 #8a1428, -4px 0 0 #8a1428, 0 4px 0 #8a1428, 0 -4px 0 #8a1428, 4px 4px 0 #8a1428, 8px 8px 0 #000;
}
.logo-2 { font-size: 13px; color: var(--text); text-shadow: 2px 2px 0 #000; letter-spacing: 1px; }
body.backstage .logo-1 { text-shadow: 4px 0 0 #4a0d18, -4px 0 0 #4a0d18, 0 4px 0 #4a0d18, 0 -4px 0 #4a0d18, 4px 4px 0 #4a0d18, 8px 8px 0 #000; }

.title-sleigh {
  width: 108px;   /* one 27x13 frame at 4x */
  height: 52px;
  background: url("../assets/sprites/sleigh-rudolph-red.png") 0 0 / 216px 52px no-repeat;
  image-rendering: pixelated;
  animation: gallop 0.2s steps(2) infinite, bob 1.6s steps(4) infinite;
}
@keyframes gallop { to { background-position: -216px 0; } }
@keyframes bob { 50% { transform: translateY(-8px); } }

.hint { margin: 0; text-align: center; color: var(--text-dim); font-size: 10px; line-height: 2; }

button {
  font: 12px/1 var(--pixel);
  color: var(--text);
  background: var(--btn);
  border: 2px solid var(--win-edge);
  border-radius: 0;
  min-height: 44px;
  min-width: 200px;
  padding: 0 14px 4px;
  cursor: pointer;
  touch-action: manipulation;
  box-shadow: inset 0 -4px 0 var(--btn-shade), 0 0 0 2px var(--win-outline);
  position: relative;
}
button:active { padding: 4px 14px 0; box-shadow: inset 0 4px 0 var(--btn-shade), 0 0 0 2px var(--win-outline); }
button.primary { color: var(--accent); }
button.primary::before {
  content: "";
  position: absolute;
  left: 12px;
  top: calc(50% - 6px);
  border: 6px solid transparent;
  border-left: 8px solid currentColor;
  animation: blink 0.8s steps(2) infinite;
}
button:disabled { opacity: 0.45; cursor: default; }
@keyframes blink { 50% { opacity: 0; } }

.resume { text-align: center; width: 100%; }
.resume p { margin: 0 0 10px; color: var(--accent); }
.resume span { color: var(--text-dim); font-size: 8px; }
.row { display: flex; gap: 10px; justify-content: center; }
.row button { min-width: 0; flex: 1; }

.route-list { display: flex; flex-direction: column; gap: 10px; width: 100%; }
.route-card {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
  gap: 8px;
  min-height: 60px;
  width: 100%;
  text-align: left;
  padding: 8px 12px 12px;
}
.route-card:active { padding: 12px 12px 8px; }
.rc-name { font-size: 11px; color: var(--accent); }
.route-card.locked .rc-name { color: var(--text-dim); }
.rc-sub { font-size: 8px; color: var(--text-dim); line-height: 1.6; }

.setting { display: flex; align-items: center; justify-content: space-between; gap: 12px; width: 100%; font-size: 11px; }
.setting button { min-width: 76px; min-height: 36px; font-size: 11px; }
.setting button.on { color: var(--accent); }

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  flex: 1;
  max-width: 150px;
  height: 12px;
  background: var(--btn-shade);
  border: 2px solid var(--win-edge);
  margin: 0;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px;
  height: 24px;
  background: var(--accent);
  border: 2px solid var(--win-outline);
  border-radius: 0;
}
input[type="range"]::-moz-range-thumb {
  width: 14px;
  height: 22px;
  background: var(--accent);
  border: 2px solid var(--win-outline);
  border-radius: 0;
}

.results { display: flex; gap: 32px; margin: 4px 0; }
.results div { display: flex; flex-direction: column; align-items: center; gap: 8px; font-size: 8px; color: var(--text-dim); }
.results img.icon { width: 30px; height: 30px; }
.big { font-size: 32px; line-height: 1; color: var(--text); font-variant-numeric: tabular-nums; }
.badge {
  margin: 0;
  padding: 6px 10px;
  border: 2px solid var(--accent);
  color: var(--accent);
  font-size: 10px;
  animation: blink 1s steps(2) 3;
}
.badge.unlock { border-color: var(--green); color: var(--green); }
body.backstage .badge.unlock { border-color: #1f7a48; color: #1f7a48; }

.countdown {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  font: 72px/1 var(--pixel);
  color: var(--accent);
  text-shadow: 6px 6px 0 #000;
  pointer-events: none;
}
.countdown[hidden] { display: none; }

/* Brightness: one black layer over everything (opacity set from JS). */
#dimmer {
  position: fixed;
  inset: 0;
  background: #000;
  opacity: 0.3;
  pointer-events: none;
  z-index: 100;
}
