:root {
  --bg: #0d2259;
  --panel: rgba(12, 24, 52, 0.86);
  --line: rgba(255, 255, 255, 0.14);
  --text: #f2f6ff;
  --muted: #a9b8d6;
  --accent: #ffcc33;
  --ice: #9fe6ff;
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--bg); color: var(--text); }
body { -webkit-user-select: none; user-select: none; -webkit-tap-highlight-color: transparent; }
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }
.muted { color: var(--muted); }

#scene { position: fixed; inset: 0; }
#scene canvas { display: block; }

/* Slow-mo: a cool purple wash and a vignette. */
#slowmo-tint {
  position: fixed; inset: 0; pointer-events: none; opacity: 0; transition: opacity 0.4s; z-index: 2;
  background: radial-gradient(ellipse at center, transparent 45%, rgba(90, 40, 170, 0.45) 100%);
}
body.slowmo #slowmo-tint { opacity: 1; }

/* ── Screens ─────────────────────────────────────────────────────────────── */

.screen {
  position: fixed; inset: 0; z-index: 10; overflow-y: auto;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: max(16px, env(safe-area-inset-top)) 16px max(16px, env(safe-area-inset-bottom));
}
/* The menu sits to one side so the penguin on the turntable stays in view. */
.screen.side { align-items: flex-start; padding-left: max(24px, 4vw); }
.screen.bottom { justify-content: space-between; }
#pause, #over, #scores { background: rgba(6, 14, 34, 0.55); backdrop-filter: blur(3px); }

.panel {
  background: var(--panel); border: 1px solid var(--line); border-radius: 16px;
  padding: 20px; box-shadow: 0 20px 60px rgba(0, 0, 0, 0.35); backdrop-filter: blur(6px);
}
.menu-panel { width: min(400px, 100%); display: flex; flex-direction: column; gap: 10px; text-align: center; }
.menu-panel.wide { width: min(640px, 100%); }
.menu-panel > button {
  padding: 11px 10px; border-radius: 10px; font-weight: 600;
  background: rgba(255, 255, 255, 0.07); border: 1px solid var(--line);
}
.menu-panel > button:hover { background: rgba(255, 255, 255, 0.14); }
button.primary { background: linear-gradient(180deg, #ffd95a, #f2a91a) !important; border: 0 !important; color: #2a1800; font-weight: 800; }
button.big { font-size: 22px; padding: 14px; letter-spacing: 0.1em; }
h2 { margin: 0; font-size: 28px; letter-spacing: 0.05em; }

.logo {
  margin: 0; font-size: clamp(40px, 9vw, 64px); line-height: 0.95; letter-spacing: 0.06em; font-weight: 900;
  background: linear-gradient(180deg, #ffffff 20%, #9fe6ff 100%); -webkit-background-clip: text; background-clip: text; color: transparent;
  filter: drop-shadow(0 3px 0 rgba(13, 34, 89, 0.9)) drop-shadow(0 0 18px rgba(159, 230, 255, 0.35));
}
.tag { margin: 0; color: var(--muted); }
.wallet-row { display: flex; justify-content: space-between; align-items: center; padding: 0 4px; }
.wallet { font-size: 18px; background: rgba(0, 0, 0, 0.3); padding: 4px 12px; border-radius: 999px; border: 1px solid var(--line); }
.wallet b { color: var(--accent); }
.settings { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; }
.chip { padding: 6px 12px; border-radius: 999px; border: 1px solid var(--line); background: rgba(255, 255, 255, 0.07); font-size: 14px; }
.chip.active { background: var(--ice); color: #06213a; border-color: var(--ice); font-weight: 700; }
body:not(.touch) .touch-only { display: none; }
.help { text-align: left; color: var(--muted); font-size: 14px; }
.help summary { cursor: pointer; text-align: center; }
.help-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 16px; margin-top: 10px; }
.help b { color: var(--text); }
.help p { margin: 8px 0 0; }
.touch-help { display: none; }
body.touch .touch-help { display: block; }
body.touch .help-grid { display: none; }

@media (max-width: 720px), (max-aspect-ratio: 1/1) {
  .screen.side { align-items: center; justify-content: flex-end; padding-left: 16px; }
  .screen.side .menu-panel { gap: 8px; padding: 16px; }
  .logo { font-size: clamp(34px, 11vw, 52px); }
}

/* ── Garage ──────────────────────────────────────────────────────────────── */

.garage-top { width: min(980px, 100%); display: flex; align-items: center; gap: 10px; justify-content: space-between; }
.tabs { display: flex; gap: 4px; background: rgba(0, 0, 0, 0.35); padding: 4px; border-radius: 999px; }
.tab { padding: 7px 14px; border-radius: 999px; border: 0; background: transparent; font-weight: 700; }
.tab.active { background: #fff; color: #0d2259; }
.garage-panel { width: min(980px, 100%); display: flex; flex-direction: column; gap: 10px; padding: 14px; }
.slots { display: flex; gap: 6px; justify-content: center; }
.detail { display: grid; grid-template-columns: 1fr auto; gap: 4px 14px; align-items: center; }
.detail-head { display: flex; gap: 8px; align-items: center; }
.detail h3 { margin: 0; font-size: 20px; }
.detail p { margin: 0; grid-column: 1; font-size: 14px; }
#item-action { grid-column: 2; grid-row: 1 / span 3; padding: 12px 20px; border-radius: 10px; min-width: 130px; font-size: 16px; }
#item-action:disabled { opacity: 0.55; cursor: default; filter: grayscale(0.6); }
.stats { grid-column: 1; display: grid; grid-template-columns: auto 1fr; gap: 3px 10px; font-size: 13px; color: var(--muted); align-items: center; }
.bar { height: 7px; border-radius: 4px; background: rgba(255, 255, 255, 0.12); overflow: hidden; }
.bar i { display: block; height: 100%; background: linear-gradient(90deg, #9fe6ff, #ffffff); border-radius: 4px; }
.badge { font-size: 12px; font-weight: 800; padding: 2px 8px; border-radius: 999px; background: rgba(255, 255, 255, 0.12); letter-spacing: 0.04em; }
.badge.gold { background: var(--accent); color: #2a1800; align-self: center; font-size: 14px; padding: 4px 12px; }
.items { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; scroll-snap-type: x proximity; }
.item {
  flex: 0 0 auto; width: 104px; scroll-snap-align: start; position: relative;
  border-radius: 12px; border: 2px solid var(--line); background: rgba(255, 255, 255, 0.06); padding: 8px 6px; text-align: center;
}
.item.selected { border-color: var(--ice); background: rgba(159, 230, 255, 0.14); }
.item.equipped::after { content: "✓"; position: absolute; top: 4px; right: 7px; color: #6dff9b; font-weight: 900; }
.item .sw { display: block; width: 44px; height: 44px; border-radius: 50%; margin: 0 auto 6px; border: 2px solid rgba(255, 255, 255, 0.5); box-shadow: inset -6px -8px 12px rgba(0, 0, 0, 0.25); }
.item .sw.split { background: linear-gradient(90deg, var(--a) 50%, var(--b) 50%); }
.item .nm { font-size: 12px; font-weight: 700; display: block; line-height: 1.2; min-height: 2.4em; }
.item .pr { font-size: 12px; color: var(--accent); font-weight: 700; }
.item .pr.own { color: var(--muted); font-weight: 600; }

@media (max-width: 720px) {
  .detail { grid-template-columns: 1fr; }
  #item-action { grid-column: 1; grid-row: auto; width: 100%; }
  .tab { padding: 6px 10px; font-size: 14px; }
  .garage-top .wallet { font-size: 15px; padding: 3px 9px; }
}

/* ── High scores ─────────────────────────────────────────────────────────── */

.hs-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.hs-table th { color: var(--muted); font-weight: 600; font-size: 12px; text-align: left; padding: 4px 6px; border-bottom: 1px solid var(--line); }
.hs-table td { padding: 6px; text-align: left; border-bottom: 1px solid rgba(255, 255, 255, 0.05); }
.hs-table td:nth-child(3) { font-weight: 800; color: var(--accent); }
.hs-table tr.first td { background: rgba(255, 204, 51, 0.1); }
.stat-row { display: flex; gap: 14px; justify-content: center; flex-wrap: wrap; color: var(--muted); font-size: 14px; }
.stat-row b { color: var(--text); }
@media (max-width: 520px) { .hs-table th:nth-child(5), .hs-table td:nth-child(5), .hs-table th:nth-child(6), .hs-table td:nth-child(6) { display: none; } }

/* ── HUD ─────────────────────────────────────────────────────────────────── */

#hud { position: fixed; inset: 0; pointer-events: none; z-index: 5; text-shadow: 0 2px 6px rgba(0, 20, 60, 0.6); }
#hud-top { position: absolute; top: max(10px, env(safe-area-inset-top)); left: 0; right: 0; display: flex; justify-content: center; gap: 10px; padding: 0 60px; }
.hud-cell { background: rgba(10, 24, 56, 0.5); border: 1px solid var(--line); border-radius: 12px; padding: 4px 14px; text-align: center; min-width: 92px; }
.hud-cell small { display: block; font-size: 10px; letter-spacing: 0.14em; color: var(--muted); }
.hud-cell b { font-size: 22px; font-variant-numeric: tabular-nums; }
.hud-cell.score b { color: var(--accent); font-size: 26px; }
#hud-sub { position: absolute; top: calc(max(10px, env(safe-area-inset-top)) + 62px); left: 0; right: 0; display: flex; justify-content: center; gap: 14px; font-weight: 700; font-size: 15px; }
#hud-powers { position: absolute; left: max(12px, env(safe-area-inset-left)); top: 50%; transform: translateY(-50%); display: flex; flex-direction: column; gap: 8px; }
.pw { display: flex; align-items: center; gap: 8px; background: rgba(10, 24, 56, 0.55); border: 1px solid var(--line); border-left: 4px solid var(--c); border-radius: 10px; padding: 5px 10px; min-width: 120px; }
.pw .ic { font-size: 20px; }
.pw .tm { flex: 1; height: 5px; background: rgba(255, 255, 255, 0.15); border-radius: 3px; overflow: hidden; }
.pw .tm i { display: block; height: 100%; background: var(--c); }
#big-msg { position: absolute; top: 34%; left: 0; right: 0; text-align: center; font-size: clamp(44px, 12vw, 96px); font-weight: 900; letter-spacing: 0.06em; opacity: 0; transition: opacity 0.2s, transform 0.2s; transform: scale(0.8); }
#big-msg.show { opacity: 1; transform: scale(1); }
#toast { position: absolute; top: 25%; left: 0; right: 0; text-align: center; font-size: 22px; font-weight: 800; opacity: 0; transition: opacity 0.2s, transform 0.2s; transform: translateY(8px); color: #fff; }
#toast.show { opacity: 1; transform: translateY(0); }
@media (max-width: 520px) {
  #hud-top { gap: 6px; padding: 0 52px; }
  .hud-cell { min-width: 0; padding: 3px 9px; }
  .hud-cell b { font-size: 17px; }
  .hud-cell.score b { font-size: 20px; }
  #hud-sub { top: calc(max(10px, env(safe-area-inset-top)) + 52px); font-size: 13px; }
  #hud-powers { top: auto; bottom: 150px; transform: none; }
  .pw { min-width: 96px; padding: 4px 8px; }
}

/* ── Game over ───────────────────────────────────────────────────────────── */

#over-title { font-size: 34px; color: #ff9b8a; }
#over-cause { margin: -6px 0 0; }
.big-score { font-size: 54px; font-weight: 900; color: var(--accent); line-height: 1; font-variant-numeric: tabular-nums; }
#hs-form { display: flex; gap: 8px; align-items: center; justify-content: center; flex-wrap: wrap; }
#hs-form input { width: 70px; text-transform: uppercase; text-align: center; font-weight: 800; letter-spacing: 0.15em; padding: 7px; border-radius: 8px; border: 1px solid var(--line); background: rgba(255, 255, 255, 0.1); }
#hs-form button { padding: 8px 16px; border-radius: 8px; }
.hs-list { margin: 0; padding: 0 0 0 26px; text-align: left; font-size: 14px; max-height: 200px; overflow-y: auto; }
.hs-list li { display: flex; justify-content: space-between; padding: 2px 6px; border-radius: 6px; }
.hs-list li::marker { color: var(--muted); }
.hs-list li.mine { background: rgba(255, 204, 51, 0.2); }
.hs-list li b { font-variant-numeric: tabular-nums; }
.hs-list small { color: var(--muted); margin-left: 6px; }

#loading { position: fixed; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center; background: var(--bg); font-size: 20px; color: var(--muted); }

/* ── Touch controls ─────────────────────────────────────────────────────── */

#touch-ui { position: fixed; inset: 0; z-index: 6; }
.steer-zone { position: absolute; top: 0; bottom: 0; width: 50%; display: flex; align-items: flex-end; padding: 0 0 max(28px, env(safe-area-inset-bottom)); touch-action: none; }
#steer-left { left: 0; justify-content: flex-start; padding-left: 22px; }
#steer-right { right: 0; justify-content: flex-end; padding-right: 22px; }
.steer-zone span {
  width: 76px; height: 76px; border-radius: 50%; display: flex; align-items: center; justify-content: center;
  font-size: 30px; background: rgba(10, 24, 56, 0.35); border: 2px solid rgba(255, 255, 255, 0.35); color: #fff; transition: transform 0.06s, background 0.06s;
}
.steer-zone.down span { background: rgba(159, 230, 255, 0.45); transform: scale(0.92); }
#touch-ui.tilt .steer-zone span { opacity: 0; }
.tb { position: absolute; border-radius: 999px; border: 2px solid rgba(255, 255, 255, 0.45); background: rgba(10, 24, 56, 0.45); color: #fff; font-weight: 900; touch-action: none; }
.tb.jump { left: 50%; transform: translateX(-50%); bottom: max(30px, env(safe-area-inset-bottom)); width: 110px; height: 72px; font-size: 18px; letter-spacing: 0.08em; }
.tb.jump.down { background: rgba(255, 204, 51, 0.6); }
#touch-top { position: absolute; top: max(12px, env(safe-area-inset-top)); right: max(12px, env(safe-area-inset-right)); }
#touch-top .tb { position: static; width: 44px; height: 44px; font-size: 18px; }
@media (orientation: landscape) and (max-height: 500px) {
  .tb.jump { width: 96px; height: 60px; bottom: 18px; }
  .steer-zone span { width: 64px; height: 64px; }
}
