* { box-sizing: border-box; margin: 0; padding: 0; }
html, body {
  height: 100%;
  background: #020509;
  overflow: hidden;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}
#game { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }

/* ---------- Menus (ui.js) over the game canvas ---------- */
:root {
  --bg: #050b14; --panel: rgba(10, 22, 38, 0.92); --panel-2: #0f1f33; --line: rgba(120, 200, 220, 0.18);
  --fg: #e4f1f4; --dim: #8aa4b0; --accent: #6ff2e0; --brass: #e2b04a; --red: #ff4d6a;
}
#ui {
  position: fixed; inset: 0; z-index: 2;
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif; color: var(--fg); font-size: 15px; line-height: 1.4;
}
#ui.on-run { pointer-events: none; }
#ui:not(.on-run) { background: radial-gradient(ellipse at 50% 20%, rgba(5, 11, 20, 0.35), rgba(2, 5, 9, 0.85)); }
#ui.on-title { background: linear-gradient(rgba(2, 5, 9, 0.15), rgba(2, 5, 9, 0.65)); }

.scr {
  position: absolute; inset: 0; overflow-y: auto; overflow-x: hidden; touch-action: pan-y; scrollbar-width: none;
  display: flex; flex-direction: column; gap: 14px;
  padding: max(14px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(14px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
}
.scr::-webkit-scrollbar { display: none; }
.scr.narrow { max-width: 460px; margin: 0 auto; }
.scr.center { justify-content: center; align-items: stretch; text-align: center; }
h2 { font-size: 22px; letter-spacing: 0.06em; text-transform: uppercase; color: var(--brass); }
h3 { font-size: 13px; letter-spacing: 0.12em; text-transform: uppercase; color: var(--dim); margin-bottom: 10px; display: flex; justify-content: space-between; gap: 8px; }
h3 small { letter-spacing: 0; text-transform: none; }
.dim { color: var(--dim); font-size: 13px; }
.pearl { display: inline-block; width: 0.75em; height: 0.75em; border-radius: 50%; margin-right: 0.3em; vertical-align: -0.05em;
  background: radial-gradient(circle at 35% 35%, #ffffff, #cfeefa 45%, #7fa8c0); box-shadow: 0 0 6px rgba(234, 255, 255, 0.5); }

.btn {
  font: inherit; font-weight: 700; color: var(--fg); cursor: pointer;
  background: var(--panel-2); border: 1.5px solid var(--line); border-radius: 10px;
  padding: 12px 18px; min-height: 46px; display: inline-flex; align-items: center; justify-content: center; gap: 10px;
}
.btn small { font-weight: 600; color: var(--dim); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: linear-gradient(#f0c35e, #c8902e); color: #1a1006; border-color: #ffd36b; font-size: 18px; letter-spacing: 0.06em; text-transform: uppercase; box-shadow: 0 0 22px rgba(226, 176, 74, 0.35); }
.btn.ghost { background: transparent; }
.btn.small { min-height: 38px; padding: 8px 12px; font-size: 14px; }
.btn.danger { border-color: rgba(255, 77, 106, 0.5); color: #ff9aa8; background: transparent; }
.btn.danger.armed { background: var(--red); color: #fff; }
.btn:disabled { opacity: 0.4; cursor: default; }
.maxed { font-size: 13px; font-weight: 700; color: var(--accent); }

.menu { display: flex; flex-direction: column; gap: 10px; width: min(340px, 100%); }
.menu.row { flex-direction: row; flex-wrap: wrap; width: 100%; justify-content: center; }
.menu.row .btn { flex: 1 1 160px; }

/* Title */
.title { align-items: center; justify-content: center; text-align: center; gap: 10px; }
.logo { font-size: clamp(30px, min(7.5vw, 14vh), 76px); font-weight: 900; letter-spacing: 0.05em; text-transform: uppercase; line-height: 1; white-space: nowrap; }
.logo span { color: var(--brass); text-shadow: 0 0 24px rgba(226, 176, 74, 0.45), 0 3px 0 #6a4310; }
.logo b { color: var(--accent); text-shadow: 0 0 24px rgba(111, 242, 224, 0.45), 0 3px 0 #1a5a52; }
.tag { color: var(--dim); margin-bottom: 8px; }

/* Shared panels */
.top { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.top h2 { flex: 1; text-align: center; }
.pearls { font-weight: 700; white-space: nowrap; }
.pearls b { font-size: 18px; margin-right: 4px; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 14px; display: flex; flex-direction: column; gap: 8px; text-align: left; }
.msg { text-align: center; color: var(--accent); font-weight: 600; }

/* The walkable Bell (lobby.js): a menu button top left, pearls top right; the rest of the screen is the game */
#ui.on-lobby { pointer-events: none; }
.lobbybtn {
  pointer-events: auto; position: absolute; left: max(10px, env(safe-area-inset-left)); top: max(8px, env(safe-area-inset-top));
  width: 44px; height: 44px; border-radius: 10px; border: 1.5px solid rgba(228, 241, 244, 0.25); background: rgba(2, 5, 9, 0.45);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; cursor: pointer;
}
.lobbybtn span { width: 18px; height: 2px; border-radius: 1px; background: rgba(228, 241, 244, 0.8); }
.lobbypearls { position: absolute; right: max(12px, env(safe-area-inset-right)); top: max(12px, env(safe-area-inset-top)); font-weight: 700; background: rgba(2, 5, 9, 0.45); padding: 6px 12px; border-radius: 10px; }
.lobbypearls b { font-size: 18px; }
#ui.on-station { background: radial-gradient(ellipse at 50% 30%, rgba(5, 11, 20, 0.55), rgba(2, 5, 9, 0.9)); }

/* Station menus */
.up { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.up:last-child { border-bottom: 0; }
.up small { display: block; color: var(--dim); font-size: 13px; }
.pips { margin-left: 8px; }
.pips i { display: inline-block; width: 8px; height: 8px; border-radius: 2px; border: 1px solid var(--brass); margin-right: 3px; }
.pips i.on { background: var(--brass); }
.shelf { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; }
.art { width: 36px; height: 36px; border-radius: 8px; background: var(--panel-2); border: 1px solid var(--line); display: grid; place-items: center; }
.art img { width: 24px; height: 24px; image-rendering: pixelated; }
.art.locked img { filter: brightness(0) invert(0.25); }
.cyl { font: inherit; color: var(--fg); background: transparent; border: 0; border-bottom: 1px solid var(--line); display: flex; gap: 10px; align-items: center; padding: 9px 2px; text-align: left; cursor: pointer; width: 100%; }
.cyl span { width: 24px; height: 24px; border-radius: 50%; display: grid; place-items: center; font-size: 12px; font-weight: 700; background: #5a4a3a; color: #ffe9a8; flex: none; }
.cyl.locked { color: var(--dim); cursor: default; }
.cyl.locked span { background: var(--panel-2); color: var(--dim); }
.cyl.open b { color: var(--brass); }
blockquote { font-style: italic; color: #f3dcae; border-left: 3px solid var(--brass); padding: 8px 12px; background: rgba(226, 176, 74, 0.07); border-radius: 0 8px 8px 0; }
blockquote cite { display: block; margin-top: 6px; font-style: normal; font-size: 12px; color: var(--dim); }
.stats { display: grid; grid-template-columns: 1fr auto; gap: 6px 16px; }
.stats dt { color: var(--dim); }
.stats dd { font-weight: 700; text-align: right; font-variant-numeric: tabular-nums; }
.stats.big { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 14px 18px; text-align: left; }
.earned { font-size: 20px; font-weight: 800; color: #eaffff; }
.earned small { font-size: 13px; font-weight: 500; color: var(--dim); }

/* New diver unlocked (run summary) */
.unlock { display: flex; align-items: center; gap: 12px; text-align: left; background: rgba(226, 176, 74, 0.1); border: 1px solid var(--brass); border-radius: 12px; padding: 10px 14px; }
.unlock img { width: 36px; height: 36px; image-rendering: pixelated; }
.unlock small { display: block; color: var(--dim); }

/* The ending */
#ui.on-ending { background: radial-gradient(ellipse at 50% 40%, rgba(40,10,32,0.82), rgba(2,4,10,0.96) 70%); }
.ending h2 { color: #ffd0e6; text-shadow: 0 0 18px rgba(255, 95, 168, 0.5); }
.ending blockquote { font-size: 16px; text-align: left; }
.epilogue { font-size: 16px; line-height: 1.6; color: #e4f1f4; max-width: 46ch; margin: 0 auto; }

/* Settings toggles */
.toggle { font: inherit; color: var(--fg); background: transparent; border: 0; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 2px; text-align: left; cursor: pointer; width: 100%; }
.toggle small { display: block; color: var(--dim); font-size: 13px; }
.toggle i { width: 44px; height: 26px; border-radius: 13px; background: #26323a; position: relative; flex: none; transition: background 0.15s; }
.toggle i::after { content: ''; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: #8aa4b0; transition: transform 0.15s; }
.toggle.on i { background: #1f6a5a; }
.toggle.on i::after { transform: translateX(18px); background: var(--accent); }

/* Side by side buttons, and toggles in two columns on wide screens, so menus fit a phone held sideways */
.pair { display: flex; gap: 10px; }
.pair .btn { flex: 1 1 0; }
.panel.toggles { display: grid; grid-template-columns: minmax(0, 1fr); column-gap: 18px; row-gap: 0; }
@media (min-width: 600px) { .panel.toggles { grid-template-columns: repeat(2, minmax(0, 1fr)); } .scr.narrow:has(.toggles) { max-width: 640px; } }
.panel.toggles .toggle { padding: 8px 2px; }

/* Developer menu */
.dev .grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
@media (max-width: 720px) { .dev .grid { grid-template-columns: minmax(0, 1fr); } }
.devgrid { display: flex; flex-wrap: wrap; gap: 6px; }
.devgrid .btn.small { min-height: 40px; font-weight: 600; }
.devgrid .btn.on { border-color: var(--brass); color: var(--brass); }
.devgrid .art { width: 44px; height: 44px; cursor: pointer; padding: 0; }
.devgrid .art img { width: 28px; height: 28px; }
.devspeed { font-size: 18px; color: var(--accent); }

/* Pause button during a run, top centre */
.pausebtn {
  pointer-events: auto; position: absolute; left: 50%; top: max(6px, env(safe-area-inset-top)); transform: translateX(-50%);
  width: 40px; height: 40px; border-radius: 50%; border: 1.5px solid rgba(228, 241, 244, 0.25); background: rgba(2, 5, 9, 0.35);
  display: flex; align-items: center; justify-content: center; gap: 5px; cursor: pointer;
}
.pausebtn span { width: 4px; height: 14px; border-radius: 1px; background: rgba(228, 241, 244, 0.7); }
