/* ============================================================
   Estuary Assault :: page theme
   The playfield and HUD are drawn by the game on the canvas; this styles the
   menus, panels and touch controls around it.
   ============================================================ */

:root {
  --bg: #050c16;
  --bg-2: #0a1726;
  --panel: rgba(6, 16, 28, 0.93);
  --edge: #2fd6c4;
  --edge-dim: rgba(47, 214, 196, 0.35);
  --ink: #e9f3f1;
  --dim: #8aa6b4;
  --accent: #ffd84a;
  --accent-ink: #1a1405;
  --danger: #ff5a3c;
  --ok: #5fe08a;
  --font-pixel: "Press Start 2P", ui-monospace, monospace;
  --font-ui: "Chakra Petch", system-ui, sans-serif;
  --foot-h: 34px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: radial-gradient(ellipse at 50% 30%, var(--bg-2), var(--bg) 70%);
  background-color: var(--bg);
  color: var(--ink);
  font-family: var(--font-ui);
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}

button { font: inherit; color: inherit; }
.hidden { display: none !important; }

#app {
  display: flex;
  flex-direction: column;
  height: 100%;
  height: 100dvh;
}

#stage-wrap {
  flex: 1;
  min-height: 0;
  display: grid;
  place-items: center;
  padding: 8px 16px;
}

/* The canvas is 320 x 256 logical units: keep its 5:4 shape as large as fits. */
#stage {
  position: relative;
  width: min(100%, calc((100dvh - var(--foot-h) - 16px) * 1.25));
  aspect-ratio: 5 / 4;
  max-height: 100%;
  border: 1px solid var(--edge-dim);
  box-shadow: 0 0 0 1px #000, 0 18px 60px rgba(0, 0, 0, 0.6), 0 0 40px rgba(47, 214, 196, 0.08);
  background: #000;
}

#game {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  image-rendering: pixelated;
  outline: none;
  touch-action: none;
}

/* CRT scanlines over the playfield, under the menus: one dark line on each of
   the game's 256 rows, as on an arcade monitor. */
body.scanlines #stage::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 1;
  background: linear-gradient(to bottom, transparent 50%, rgba(0, 0, 0, 0.2) 50%) 0 0 / 100% calc(100% / 256);
}

/* ---------- corner buttons ---------- */
.corner-btns {
  position: absolute;
  top: 6px;
  right: 6px;
  display: flex;
  gap: 6px;
  z-index: 3;
}
.icon-btn {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border: 1px solid var(--edge-dim);
  border-radius: 6px;
  background: rgba(5, 12, 22, 0.7);
  cursor: pointer;
  padding: 0;
}
.icon-btn:hover, .icon-btn:focus-visible { border-color: var(--edge); outline: none; }
.icon-btn svg { width: 18px; height: 18px; color: var(--ink); }
body:not([data-view="play"]) .play-only { display: none; }

/* ---------- overlays over the canvas ---------- */
.overlay {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: grid;
  place-items: center;
  padding: 12px;
  overflow: auto;
  background: rgba(3, 8, 14, 0.35);
}
#ov-title { background: linear-gradient(to bottom, rgba(3, 8, 14, 0.15), rgba(3, 8, 14, 0.55)); }
#ov-pause, #ov-over, #ov-settings { background: rgba(3, 8, 14, 0.6); }

/* ---------- modals over the whole page ---------- */
.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 16px;
  overflow: auto;
  background: rgba(2, 6, 12, 0.78);
  backdrop-filter: blur(3px);
}

.panel {
  width: 100%;
  max-width: 560px;
  padding: 20px 24px;
  background: var(--panel);
  border: 2px solid var(--edge);
  border-radius: 10px;
  box-shadow: 0 0 0 1px #000, 0 10px 40px rgba(0, 0, 0, 0.55), inset 0 0 30px rgba(47, 214, 196, 0.06);
  text-align: center;
}
.panel.small { max-width: 420px; }

h2 {
  margin: 0 0 16px;
  font-family: var(--font-pixel);
  font-size: 18px;
  letter-spacing: 2px;
  color: var(--accent);
  text-shadow: 2px 2px 0 #000;
}
h2.danger { color: var(--danger); }

.loading {
  margin: 0;
  font-family: var(--font-pixel);
  font-size: 12px;
  line-height: 1.8;
  color: var(--ink);
}
.loading.bad { color: var(--danger); font-family: var(--font-ui); font-size: 15px; }

/* ---------- title ---------- */
.panel.title { max-width: 600px; background: rgba(6, 16, 28, 0.86); }
.kicker {
  margin: 0 0 10px;
  font-family: var(--font-pixel);
  font-size: 8px;
  letter-spacing: 3px;
  color: var(--dim);
}
.logo {
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-family: var(--font-pixel);
  font-weight: 400;
  line-height: 1;
}
/* Chrome-gradient arcade lettering, like the in-game banners. */
.logo span {
  color: transparent;
  -webkit-background-clip: text;
  background-clip: text;
}
.logo span:first-child {
  font-size: clamp(22px, 5.4vw, 40px);
  background-image: linear-gradient(to bottom, #fffbe0 0%, #ffd84a 42%, #ff8a1f 58%, #ffc94a 100%);
  filter: drop-shadow(3px 3px 0 #5a2a00) drop-shadow(0 0 10px rgba(255, 170, 40, 0.55));
}
.logo span:last-child {
  font-size: clamp(16px, 3.6vw, 26px);
  letter-spacing: 6px;
  background-image: linear-gradient(to bottom, #e6fffb 0%, #2fd6c4 55%, #138a80 100%);
  filter: drop-shadow(2px 2px 0 #021c19) drop-shadow(0 0 8px rgba(47, 214, 196, 0.5));
}
.tagline { margin: 14px 0 10px; color: var(--ink); font-size: 16px; }
.insert-coin {
  margin: 0 0 14px;
  font-family: var(--font-pixel);
  font-size: 10px;
  letter-spacing: 2px;
  color: #fff;
  text-shadow: 0 0 6px rgba(255, 216, 74, 0.9);
  animation: blink 1.1s steps(2, start) infinite;
}
@keyframes blink { to { visibility: hidden; } }
@media (prefers-reduced-motion: reduce) { .insert-coin { animation: none; } }
h2 {
  text-shadow: 2px 2px 0 #000, 0 0 10px rgba(255, 190, 60, 0.45);
}
h2.danger { text-shadow: 2px 2px 0 #000, 0 0 10px rgba(255, 70, 40, 0.6); }

.btn-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
  margin-bottom: 16px;
}

.big-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: 44px;
  padding: 10px 18px;
  border: 2px solid var(--accent);
  border-radius: 8px;
  background: var(--accent);
  color: var(--accent-ink);
  font-family: var(--font-pixel);
  font-size: 11px;
  letter-spacing: 1px;
  cursor: pointer;
  box-shadow: 0 3px 0 #b8860b;
  transition: transform 0.06s, box-shadow 0.06s, filter 0.1s;
}
.big-btn svg { width: 14px; height: 14px; flex: none; }
.big-btn:hover { filter: brightness(1.08); }
.big-btn:active { transform: translateY(2px); box-shadow: 0 1px 0 #b8860b; }
.big-btn:focus-visible { outline: 2px solid #fff; outline-offset: 3px; }
.big-btn.alt {
  background: transparent;
  color: var(--ink);
  border-color: var(--edge);
  box-shadow: 0 3px 0 rgba(47, 214, 196, 0.35);
}
.big-btn.alt:active { box-shadow: 0 1px 0 rgba(47, 214, 196, 0.35); }
.big-btn:disabled { opacity: 0.45; cursor: default; transform: none; }
.big-btn.locked { border-color: var(--dim); color: var(--dim); }

.text-btn {
  display: block;
  margin: 14px auto 0;
  padding: 6px 10px;
  border: 0;
  background: none;
  color: var(--dim);
  font-family: var(--font-pixel);
  font-size: 9px;
  letter-spacing: 1px;
  cursor: pointer;
}
.text-btn:hover, .text-btn:focus-visible { color: var(--ink); outline: none; text-decoration: underline; }

.help {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px 18px;
  margin: 4px auto 12px;
  max-width: 480px;
  text-align: left;
  font-size: 14px;
  color: var(--dim);
}
.help-row { display: flex; align-items: center; gap: 10px; }
.keys { display: inline-flex; gap: 3px; flex: none; min-width: 112px; }

kbd {
  display: inline-grid;
  place-items: center;
  min-width: 22px;
  height: 22px;
  padding: 0 5px;
  border: 1px solid var(--edge-dim);
  border-bottom-width: 3px;
  border-radius: 5px;
  background: rgba(255, 255, 255, 0.04);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 12px;
  font-weight: 600;
}
kbd.wide { min-width: 58px; font-size: 10px; letter-spacing: 1px; }

.points {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 4px 14px;
  margin: 0;
  font-size: 13px;
  color: var(--dim);
}
.points b { color: var(--accent); font-weight: 700; }
.hi-line {
  margin: 12px 0 0;
  font-family: var(--font-pixel);
  font-size: 9px;
  color: var(--edge);
}
.hi-line:empty { display: none; }

/* ---------- settings ---------- */
.setting { margin: 0 0 16px; text-align: left; }
.setting-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 8px; }
.opt-lbl { font-family: var(--font-pixel); font-size: 9px; letter-spacing: 1px; color: var(--ink); }
.setting-note { margin: 6px 0 0; font-size: 13px; line-height: 1.45; color: var(--dim); }
.lb-note { margin: 0 0 14px; padding: 8px 10px; border-left: 3px solid var(--ok); background: rgba(95, 224, 138, 0.06); text-align: left; }
.lb-note.warn { border-color: var(--danger); background: rgba(255, 90, 60, 0.08); color: var(--ink); }

.seg { display: flex; gap: 6px; }
.seg button {
  flex: 1;
  min-height: 38px;
  border: 1px solid var(--edge-dim);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.03);
  font-family: var(--font-pixel);
  font-size: 10px;
  cursor: pointer;
}
.seg button:hover { border-color: var(--edge); }
.seg button[aria-checked="true"] { background: var(--edge); border-color: var(--edge); color: #04211e; }
.seg button.default::after { content: "*"; margin-left: 2px; opacity: 0.6; }

.toggles { display: flex; flex-wrap: wrap; gap: 10px 18px; }
.toggle {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 4px 0;
  border: 0;
  background: none;
  font-family: var(--font-pixel);
  font-size: 9px;
  cursor: pointer;
}
.toggle-track {
  position: relative;
  width: 38px;
  height: 20px;
  border: 1px solid var(--edge-dim);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.05);
  transition: background 0.15s;
}
.toggle-knob {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--dim);
  transition: transform 0.15s, background 0.15s;
}
.toggle[aria-checked="true"] .toggle-track { background: rgba(47, 214, 196, 0.25); border-color: var(--edge); }
.toggle[aria-checked="true"] .toggle-knob { transform: translateX(18px); background: var(--edge); }
.toggle:focus-visible .toggle-track { outline: 2px solid #fff; outline-offset: 2px; }

/* ---------- game over ---------- */
.over-cause { margin: -6px 0 14px; font-family: var(--font-pixel); font-size: 9px; color: var(--dim); }
.stats {
  display: grid;
  grid-template-columns: auto auto;
  gap: 6px 18px;
  justify-content: center;
  margin: 0 0 16px;
  text-align: left;
}
.stats .k { font-family: var(--font-pixel); font-size: 8px; color: var(--dim); align-self: center; }
.stats .v { font-family: var(--font-pixel); font-size: 10px; color: var(--ink); text-align: right; }
.stats .v.hl { color: var(--accent); }
.stats .v.new { color: var(--ok); }
.over-account { display: flex; flex-direction: column; gap: 8px; margin-bottom: 14px; }

/* ---------- account + leaderboard ---------- */
.acct-step { display: flex; flex-direction: column; gap: 8px; text-align: left; }
.acct-step .big-btn { margin-top: 6px; }
.acct-note { margin: 0 0 6px; font-size: 15px; line-height: 1.5; color: var(--ink); }
.acct-field { font-family: var(--font-pixel); font-size: 8px; color: var(--dim); margin-top: 4px; }
.acct-step input {
  width: 100%;
  min-height: 42px;
  padding: 8px 12px;
  border: 1px solid var(--edge-dim);
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.35);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 17px;
}
.acct-step input:focus { outline: none; border-color: var(--edge); }
.acct-qr { width: 196px; height: 196px; margin: 4px auto; image-rendering: pixelated; background: #fff; padding: 6px; border-radius: 6px; }
.acct-secret { margin: 0; text-align: center; font-family: ui-monospace, monospace; font-size: 12px; color: var(--dim); word-break: break-all; }
.acct-msg { min-height: 1.4em; margin-top: 10px; font-size: 14px; color: var(--ok); }
.acct-msg.bad { color: var(--danger); }
.acct-msg:empty { min-height: 0; margin: 0; }

.panel.leaderboard { max-width: 560px; }
.lb-tabs { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; margin-bottom: 12px; }
.lb-tab {
  padding: 8px 10px;
  border: 1px solid var(--edge-dim);
  border-radius: 6px;
  background: none;
  font-family: var(--font-pixel);
  font-size: 8px;
  cursor: pointer;
}
.lb-tab.on { background: var(--edge); border-color: var(--edge); color: #04211e; }
.lb-body { max-height: min(52vh, 460px); overflow: auto; margin-bottom: 14px; }
.lb-table { width: 100%; border-collapse: collapse; font-size: 15px; }
.lb-table th {
  position: sticky;
  top: 0;
  padding: 8px 6px;
  background: #0b1828;
  font-family: var(--font-pixel);
  font-size: 8px;
  color: var(--dim);
  text-align: left;
}
.lb-table td { padding: 7px 6px; border-top: 1px solid rgba(47, 214, 196, 0.12); text-align: left; }
.lb-table .lb-num { text-align: right; font-variant-numeric: tabular-nums; }
.lb-table .lb-rank { width: 36px; color: var(--dim); }
.lb-table tr.me td { color: var(--accent); }
.lb-status { padding: 10px; color: var(--dim); font-size: 14px; }

/* ---------- touch controls ----------
   FIRE sits bottom left; the steering and throttle readout bottom right. The
   rest of the screen takes swipes, so the browser must not scroll, zoom or
   select anything while a game is on. */
body.touch[data-view="play"],
body.touch[data-view="play"] #app {
  touch-action: none;
  overscroll-behavior: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}
.touch-ui {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 20;
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  padding: 10px 16px calc(14px + env(safe-area-inset-bottom));
  pointer-events: none;
}
.touch-fire {
  pointer-events: auto;
  position: relative;
  width: 104px;
  height: 104px;
  display: grid;
  place-items: center;
  border: 3px solid var(--danger);
  border-radius: 50%;
  background: radial-gradient(circle at 36% 30%, rgba(255, 140, 110, 0.5), rgba(130, 24, 12, 0.6));
  box-shadow: 0 0 0 2px #000, 0 6px 18px rgba(0, 0, 0, 0.5);
  color: #fff;
  font-family: var(--font-pixel);
  font-size: 13px;
  text-shadow: 1px 1px 0 #000;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  transition: transform 0.05s;
}
.touch-fire.held { transform: scale(0.94); background: radial-gradient(circle at 36% 30%, rgba(255, 200, 150, 0.7), rgba(200, 50, 20, 0.7)); }
/* The ring fills over the one-second hold that toggles auto fire. */
.fire-ring {
  position: absolute;
  inset: -10px;
  width: calc(100% + 20px);
  height: calc(100% + 20px);
  transform: rotate(-90deg);
  pointer-events: none;
}
.fire-ring circle {
  fill: none;
  stroke: var(--accent);
  stroke-width: 5;
  stroke-linecap: round;
  stroke-dasharray: 289;
  stroke-dashoffset: 289;
  opacity: 0;
}
.touch-fire.charging .fire-ring circle { opacity: 1; animation: fire-charge 1s linear forwards; }
@keyframes fire-charge { to { stroke-dashoffset: 0; } }
.fire-auto {
  position: absolute;
  top: 18px;
  font-size: 8px;
  color: var(--accent);
  opacity: 0;
}
.touch-fire.auto {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px #000, 0 0 22px rgba(255, 216, 74, 0.75);
  animation: fire-auto 0.5s ease-in-out infinite alternate;
}
.touch-fire.auto .fire-auto { opacity: 1; }
@keyframes fire-auto { to { box-shadow: 0 0 0 2px #000, 0 0 8px rgba(255, 216, 74, 0.35); } }

.touch-status {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 8px 10px;
  border: 1px solid var(--edge-dim);
  border-radius: 10px;
  background: rgba(5, 12, 22, 0.72);
}
.steer-ind { display: flex; gap: 10px; }
.steer-ind svg { width: 18px; height: 18px; color: rgba(233, 243, 241, 0.22); }
.steer-ind svg.on { color: var(--accent); filter: drop-shadow(0 0 4px rgba(255, 216, 74, 0.85)); }
.throttle { display: flex; flex-direction: column-reverse; gap: 3px; }
.throttle span { width: 34px; height: 6px; border-radius: 2px; background: rgba(76, 255, 122, 0.14); }
.throttle span.lit { background: #4cff7a; box-shadow: 0 0 6px rgba(76, 255, 122, 0.7); }
.status-label { font-family: var(--font-pixel); font-size: 7px; color: var(--dim); }

/* How the gestures work, shown on the start line of each life. */
.touch-hint {
  display: none;
  position: fixed;
  top: calc(10px + env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  width: max-content;
  max-width: calc(100vw - 32px);
  margin: 0;
  padding: 8px 12px;
  border: 1px solid var(--edge-dim);
  border-radius: 8px;
  background: rgba(5, 12, 22, 0.85);
  font-family: var(--font-pixel);
  font-size: 8px;
  line-height: 1.8;
  text-align: center;
  color: var(--ink);
}
.touch-hint b { color: var(--accent); font-weight: 400; }
body[data-phase="ready"] .touch-hint { display: block; }

.r90 { transform: rotate(90deg); }
.r180 { transform: rotate(180deg); }
.r270 { transform: rotate(270deg); }

/* Keyboard help on the title screen, or touch help on touch devices. */
.help-touch { display: none; }
body.touch .help-keys { display: none; }
body.touch .help-touch { display: grid; grid-template-columns: minmax(0, 1fr); }

/* Leave room for the touch controls beside or below the playfield. */
body.touch #foot { display: none; }
body.touch { --foot-h: 0px; }
@media (orientation: portrait) {
  body.touch #stage-wrap { padding-bottom: 140px; }
  body.touch #stage { width: min(100%, calc((100dvh - 156px) * 1.25)); }
}
/* Landscape: FIRE in the left margin, the readout in the right one. */
@media (orientation: landscape) {
  body.touch #stage-wrap { padding-left: 140px; padding-right: 96px; }
  body.touch .touch-fire { width: 96px; height: 96px; }
}

/* ---------- footer ---------- */
#foot {
  height: var(--foot-h);
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 4px 18px;
  padding: 0 16px 6px;
  font-family: var(--font-pixel);
  font-size: 8px;
  color: var(--dim);
  overflow: hidden;
}
#foot span { display: inline-flex; align-items: center; gap: 4px; }
#foot kbd { height: 18px; min-width: 18px; font-size: 10px; }
#foot kbd.wide { min-width: 46px; font-size: 8px; }
.foot-note { color: rgba(138, 166, 180, 0.6); }

/* ---------- small screens ---------- */
@media (max-width: 640px) {
  .panel { padding: 16px; }
  .help { grid-template-columns: minmax(0, 1fr); }
  .big-btn { font-size: 10px; padding: 10px 14px; }
  .tagline { font-size: 14px; }
  #foot .foot-note { display: none; }
}
@media (max-height: 560px) {
  .help, .points, body.touch .help-touch { display: none; }
  .tagline { margin: 10px 0; }
}
