/* The game's HUD font, if supplied in Fonts/ (see README). */
@font-face {
  font-family: 'HUD';
  src: url('fonts/hud.woff2') format('woff2'), url('fonts/hud.ttf') format('truetype');
  font-display: swap;
}

:root {
  color-scheme: dark;
  --bg: #000;
  --sky: #000;
  --floor: #8b3a0e;
  --floor-edge: #e0905c;
  --text: #fff;
  --muted: #a8a8a8;
  --panel: #161616;
  --panel-2: #262626;
  --gain: #f8d878;
  --spend: #ff6b5b;
  --neg: #ff3b30;
  --accent: #e45c10;
  --font: 'HUD', ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

@media (prefers-color-scheme: light) {
  :root:not([data-theme='dark']) {
    --sky: #5c94fc;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

body {
  padding: var(--safe-top) 0 calc(var(--safe-bottom) + 16px);
  min-height: 100dvh;
  user-select: none;
  -webkit-user-select: none;
}

img, .spr { image-rendering: pixelated; image-rendering: crisp-edges; }

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
  touch-action: manipulation;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 12px;
  background: var(--bg);
  border-bottom: 2px solid var(--panel-2);
}
.topbar h1 { margin: 0; font-size: 16px; letter-spacing: 1px; }
.top-actions { display: flex; gap: 6px; }

.tool {
  min-height: 44px;
  padding: 0 12px;
  border: 2px solid var(--panel-2);
  border-radius: 6px;
  background: var(--panel);
  font-size: 13px;
  letter-spacing: 1px;
}
.tool.icon { font-size: 20px; min-width: 48px; }
.edit-only { display: none; }
body.unlocked .edit-only { display: inline-block; }

.banner {
  margin: 8px 12px 0;
  padding: 12px;
  text-align: center;
  background: var(--gain);
  color: #000;
  border-radius: 6px;
  animation: blink 0.8s steps(2) infinite;
}
@keyframes blink { 50% { opacity: 0.5; } }

.empty { text-align: center; color: var(--muted); line-height: 1.8; padding: 48px 16px; }

/* ---- a kid's lane ---- */

.lane {
  max-width: 560px;
  margin: 12px auto 0;
  padding: 0 12px;
}

.hud {
  display: grid;
  grid-template-columns: 1.4fr 1fr 1fr;
  gap: 4px;
  padding: 6px 4px;
  font-size: clamp(14px, 4.4vw, 20px);
  letter-spacing: 1px;
  text-transform: uppercase;
}
.hud-label { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hud-val { display: flex; align-items: center; gap: 4px; white-space: nowrap; }
.hud-val .neg { color: var(--neg); }
.hud-icon { height: 1em; width: auto; }
.hud-icon.big { height: 48px; }

.stage {
  --s: 1.4;
  position: relative;
  width: 100%;
  aspect-ratio: 256 / 176;
  overflow: hidden;
  border-radius: 6px;
  background: var(--sky);
}
.scene {
  position: absolute;
  left: 0;
  top: 0;
  width: 256px;
  height: 176px;
  transform: scale(var(--s));
  transform-origin: 0 0;
}
.scene .spr, .scene .vine, .scene .lava { position: absolute; }
.floor {
  position: absolute;
  left: 0;
  right: 0;
  top: 152px;
  bottom: 0;
  background: var(--floor);
  border-top: 2px solid var(--floor-edge);
}
.block { z-index: 2; }
.behind { z-index: 1; }
.hero { z-index: 3; cursor: pointer; }
.fx { position: absolute; inset: 0; z-index: 4; pointer-events: none; }
.vine, .lava { background-repeat: repeat; image-rendering: pixelated; }
.lava { left: 0; right: 0; }
.float, .caption, .goal-label, .wall-more {
  position: absolute;
  font-size: 8px;
  line-height: 1.2;
  white-space: nowrap;
  text-shadow: 1px 1px 0 #000;
}
.float.gain { color: var(--gain); }
.float.spend { color: var(--spend); }
.caption {
  left: 0;
  right: 0;
  top: 8px;
  text-align: center;
  font-size: 10px;
  z-index: 5;
  animation: blink 0.5s steps(2) infinite;
}
.caption:empty { display: none; }
.goal-label { right: 4px; top: 4px; text-align: right; font-size: 7px; color: var(--gain); }
.wall-more { color: var(--text); }

.controls {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 8px;
  margin-top: 8px;
}
.btn {
  min-height: 72px;
  border: 3px solid #000;
  border-radius: 10px;
  font-size: 34px;
  box-shadow: inset 0 -5px 0 rgba(0, 0, 0, 0.35);
}
.btn:active { transform: translateY(2px); box-shadow: inset 0 -2px 0 rgba(0, 0, 0, 0.35); }
.btn.plus { background: #2e9e3e; }
.btn.minus { background: #c8341c; }
.btn.custom { background: #c88b14; font-size: 24px; }
.lane-tools { display: flex; gap: 6px; margin-top: 8px; flex-wrap: wrap; }
.lane-tools .tool { flex: 1; }
body:not(.unlocked) .lane-tools .tool:not(:first-child) { display: none; }

/* ---- full-screen cards ---- */

.overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 24px;
  background: #000;
  color: #fff;
  font-size: clamp(22px, 7vw, 36px);
  text-align: center;
  letter-spacing: 2px;
}
.overlay.game-over div + div { font-size: 16px; color: var(--muted); letter-spacing: 1px; }
.card-lives { display: flex; align-items: center; gap: 16px; }

/* ---- dialogs ---- */

dialog.sheet {
  width: min(440px, calc(100vw - 24px));
  max-height: calc(100dvh - 24px);
  padding: 20px;
  border: 3px solid var(--panel-2);
  border-radius: 12px;
  background: var(--panel);
  color: var(--text);
  display: flex;
  flex-direction: column;
  gap: 12px;
}
dialog.sheet:not([open]) { display: none; }
dialog::backdrop { background: rgba(0, 0, 0, 0.75); }
dialog h2 { margin: 0; font-size: 18px; text-align: center; letter-spacing: 1px; }
dialog p { margin: 0; color: var(--muted); text-align: center; line-height: 1.5; }
dialog input, dialog select {
  width: 100%;
  min-height: 52px;
  padding: 0 12px;
  border: 2px solid var(--panel-2);
  border-radius: 8px;
  background: #000;
  color: var(--text);
  font: inherit;
  font-size: 18px;
  user-select: text;
  -webkit-user-select: text;
}
.money { display: flex; align-items: center; gap: 8px; font-size: 32px; }
.money input { font-size: 32px; min-height: 64px; }
.field { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.row { display: flex; gap: 8px; }
.btn-wide {
  flex: 1;
  min-height: 60px;
  border: 0;
  border-radius: 10px;
  background: var(--accent);
  font-size: 18px;
}
.btn-wide.secondary { background: var(--panel-2); }
.btn-wide.gain { background: #2e9e3e; }
.btn-wide.spend { background: #c8341c; }
.link { background: none; border: 0; color: var(--muted); min-height: 44px; text-decoration: underline; }
.link.danger { color: var(--neg); }
.error { color: var(--neg); font-size: 13px; min-height: 1em; text-align: center; }
.chars { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.char {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 10px;
  border: 3px solid var(--panel-2);
  border-radius: 10px;
  background: #000;
}
.char img { width: 48px; height: 96px; }
.char[aria-pressed='true'] { border-color: var(--gain); }

.pin-msg { text-align: center; }
.pin-dots { text-align: center; font-size: 28px; letter-spacing: 8px; min-height: 36px; }
.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.key {
  min-height: 64px;
  border: 0;
  border-radius: 10px;
  background: var(--panel-2);
  font-size: 26px;
}
.key-ok { background: var(--accent); }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--safe-bottom) + 24px);
  transform: translateX(-50%);
  z-index: 60;
  max-width: calc(100vw - 32px);
  padding: 12px 16px;
  border-radius: 8px;
  background: var(--panel-2);
  font-size: 14px;
}

/* ---- history level ---- */

.history {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: flex;
  flex-direction: column;
  padding-top: var(--safe-top);
  background: var(--bg);
}
.history-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 12px;
}
.history-bar h2 { margin: 0; font-size: 15px; }
.level {
  flex: 1;
  overflow-x: auto;
  overflow-y: hidden;
  background: var(--sky);
  scroll-snap-type: x proximity;
  -webkit-overflow-scrolling: touch;
}
.track { display: flex; height: 100%; min-width: 100%; }
.seg {
  position: relative;
  flex: 0 0 132px;
  scroll-snap-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
}
.seg-label {
  position: absolute;
  top: 18%;
  left: 6px;
  right: 6px;
  text-align: center;
  font-size: 13px;
  line-height: 1.5;
}
.seg-label .amt { font-size: 18px; }
.seg-label .amt.gain { color: var(--gain); }
.seg-label .amt.spend { color: var(--spend); }
.seg-label .date { color: var(--text); }
.seg-label .note { color: var(--muted); overflow-wrap: anywhere; user-select: text; -webkit-user-select: text; }
.seg-coin { margin-bottom: 72px; }
.seg-hero { margin-bottom: 0; }
.seg.end { flex-basis: 160px; }
.ground, .hole { width: 100%; height: 72px; flex: none; }
.ground { background: var(--floor); border-top: 3px solid var(--floor-edge); }
.hole { background: transparent; }
.seg.pit .hole { border-left: 3px solid var(--floor-edge); border-right: 3px solid var(--floor-edge); }
