/* Tidal Wave styles. Fonts are self-hosted (see fonts/). */

@font-face {
  font-family: 'Syne';
  font-style: normal;
  font-weight: 700 800;
  font-display: swap;
  src: url('../fonts/syne.woff2') format('woff2');
}
@font-face {
  font-family: 'Outfit';
  font-style: normal;
  font-weight: 400 700;
  font-display: swap;
  src: url('../fonts/outfit.woff2') format('woff2');
}

:root {
  --abyss: #05181c;
  --depth: #0a3a42;
  --trench: #021216;
  --foam: #e8f6f3;
  --mist: #93b0b4;
  --tide: #2ee6c7;
  --flare: #ff5d3a;
  --sand: #f0c14d;
  --panel: rgba(8, 38, 42, 0.96);
  --line: rgba(232, 246, 243, 0.14);

  /* Reserved band at the top so a ~44px platform badge (e.g. "Created with
     Grok / Remix") can never cover the game, score or HUD. */
  --badge-reserve: 56px;
  --safe-top: calc(var(--badge-reserve) + env(safe-area-inset-top, 0px));
  --safe-bottom: max(14px, env(safe-area-inset-bottom, 0px));
  --gutter: 16px;
  --display: 'Syne', 'Outfit', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --text: 'Outfit', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  background: #031216;
  color: var(--foam);
  font-family: var(--text);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

body {
  overflow: hidden;
  background:
    radial-gradient(120% 70% at 50% 110%, rgba(8, 80, 88, 0.58), transparent 60%),
    radial-gradient(80% 60% at 50% -10%, rgba(10, 58, 68, 0.40), transparent 70%),
    #031216;
}

p { margin: 0; }
button { font: inherit; color: inherit; cursor: pointer; }
button:focus-visible { outline: 2px solid var(--sand); outline-offset: 3px; }

.nums { font-variant-numeric: tabular-nums; }

/* ---------- Layout ---------- */

.app {
  height: 100vh;
  height: 100dvh;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  align-items: center;
  justify-items: center;
  padding: var(--safe-top) var(--gutter) var(--safe-bottom);
}
/* Wide screens: text rails either side of the play area. */
.app.wide {
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  column-gap: clamp(24px, 4vw, 72px);
}
.app.wide .stage { grid-column: 2; }
/* Short landscape phones: the play area sits to the left, clear of a
   centred top badge, so it can use the full height. */
.app.side {
  grid-template-columns: auto minmax(0, 1fr);
  column-gap: 28px;
  justify-items: start;
  padding-top: max(10px, env(safe-area-inset-top, 0px));
  padding-left: max(var(--gutter), env(safe-area-inset-left, 0px));
}
.app.side .stage { grid-column: 1; grid-row: 1; }
.app.side .rail-right { display: block; grid-column: 2; grid-row: 1; justify-self: center; }
.app.side .rail-left { display: none; }

.rail { min-width: 0; display: none; }
.app.wide .rail { display: block; }
.rail-left { justify-self: end; }
.rail-right { justify-self: start; }
.rail-copy, .rules { width: min(340px, 100%); }
.rail-left .rail-copy { margin-left: auto; }

.rail-title {
  margin: 10px 0 14px;
  font-family: var(--display);
  font-weight: 800;
  line-height: 1;
  color: var(--foam);
}
.rail .lede { color: var(--foam); opacity: 0.9; }

.rules { list-style: none; margin: 0; padding: 0; display: grid; gap: 22px; }
.rules li { display: grid; grid-template-columns: 10px 1fr; gap: 12px; align-items: start; color: var(--mist); font-size: 14px; line-height: 1.5; }
.rules strong { display: block; color: var(--foam); font-weight: 600; font-size: 15px; }
.pip { width: 9px; height: 9px; border-radius: 50%; background: var(--tide); margin-top: 6px; }
.pip.sand { background: var(--sand); }
.pip.flare { background: var(--flare); }

/* The stage is sized by JS to the 390:844 playfield; these are fallbacks. */
.stage {
  position: relative;
  height: calc(100dvh - var(--safe-top) - var(--safe-bottom));
  aspect-ratio: 390 / 844;
  max-width: calc(100vw - 2 * var(--gutter));
  border-radius: 28px;
  overflow: hidden;
  background: var(--abyss);
  border: 1px solid rgba(147, 176, 180, 0.2);
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.55), 0 0 0 6px rgba(46, 230, 199, 0.03);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  container-type: inline-size;
}
.stage.compact { border-radius: 20px; }

canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

/* ---------- Fit-to-width text (JS sets the exact size) ---------- */

.fit { white-space: nowrap; overflow: visible; container-type: inline-size; }
.fit > span { display: inline-block; white-space: nowrap; font-size: 14cqi; }

/* ---------- Shared text ---------- */

.kicker {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--mist);
}
.lede { font-size: 15px; line-height: 1.5; font-weight: 500; }
.lede.dim { color: var(--mist); font-weight: 400; font-size: 14px; }
.fine-print { font-size: 11.5px; line-height: 1.4; color: var(--mist); }

.icon-btn {
  width: 40px;
  height: 40px;
  flex: none;
  border-radius: 50%;
  border: 1px solid rgba(232, 246, 243, 0.22);
  background: rgba(6, 16, 20, 0.35);
  display: grid;
  place-items: center;
  pointer-events: auto;
}
.icon-btn svg { width: 20px; height: 20px; }

.launch {
  width: 100%;
  min-height: 54px;
  border: 0;
  border-radius: 999px;
  background: var(--tide);
  color: #03201b;
  font-family: var(--display);
  font-weight: 800;
  font-size: 16px;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  box-shadow: 0 10px 30px rgba(46, 230, 199, 0.18);
  transition: transform 0.08s ease, filter 0.15s ease;
}
.launch:hover { filter: brightness(1.06); }
.launch.long { font-size: 14px; letter-spacing: 0.08em; white-space: nowrap; padding: 0 12px; }
.launch:active { transform: scale(0.98); }

.ghost {
  width: 100%;
  min-height: 46px;
  border-radius: 999px;
  border: 1px solid rgba(232, 246, 243, 0.22);
  background: transparent;
  font-weight: 600;
  font-size: 14px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

/* ---------- Sheets (title + game over) ---------- */

.sheet {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 18px 18px calc(18px + 2px);
  background: linear-gradient(180deg, rgba(14, 34, 38, 0.97), rgba(9, 24, 27, 0.99));
  border-top: 1px solid var(--line);
  z-index: 3;
  max-height: 100%;
  overflow-y: auto;
  overscroll-behavior: contain;
}
.sheet-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }

.wordmark {
  margin: 6px 0 0;
  font-family: var(--display);
  font-weight: 800;
  line-height: 1;
  color: var(--foam);
}

.high { font-size: 13px; color: var(--mist); }
.high strong { color: var(--sand); font-weight: 700; }

.sheet-foot { text-align: center; margin-top: -4px; font-size: 11.5px; color: var(--mist); opacity: 0.85; }
.foot-link { font-size: inherit; color: var(--mist); text-decoration: underline; text-underline-offset: 3px; }
.foot-link:hover, .foot-link:focus-visible { color: var(--foam); }
.foot-link:focus-visible { outline: 2px solid var(--sand); outline-offset: 2px; }

.final {
  font-family: var(--display);
  font-weight: 800;
  line-height: 1.05;
  color: var(--foam);
}
.mark {
  font-family: var(--display);
  font-weight: 800;
  font-size: 15px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--sand);
}

.stats {
  margin: 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.stats > div {
  min-width: 0;
  padding: 9px 10px;
  border-radius: 12px;
  background: rgba(3, 8, 12, 0.55);
  border: 1px solid rgba(232, 246, 243, 0.06);
  text-align: center;
}
.stats dt {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--mist);
}
.stats dd {
  margin: 4px 0 0;
  font-family: var(--display);
  font-weight: 800;
  line-height: 1.2;
}

.actions { display: grid; gap: 10px; }

/* ---------- HUD ---------- */

.hud {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  grid-template-areas:
    "score mute"
    "info  info"
    "tide  tide"
    "chips chips";
  column-gap: 12px;
  row-gap: 4px;
  align-items: center;
  padding: 12px 14px 14px 16px;
  pointer-events: none;
  z-index: 2;
  text-shadow: 0 1px 8px rgba(0, 0, 0, 0.5);
}
/* Soft dark fade behind the HUD so it stays readable over sprites. */
.hud::before {
  content: '';
  position: absolute;
  inset: 0 0 -18px 0;
  z-index: -1;
  background: linear-gradient(180deg, rgba(3, 8, 12, 0.72), rgba(3, 8, 12, 0.45) 70%, rgba(3, 8, 12, 0));
}
.hud .score { grid-area: score; min-width: 0; }
.hud .mute-btn { grid-area: mute; }

/* Each row is a wrapping flex line: if two items don't fit side by side,
   the second drops to its own line instead of overlapping. */
.hud-info,
.tide-block {
  min-width: 0;
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  column-gap: 12px;
  row-gap: 2px;
}
.hud-info { grid-area: info; }
.tide-block { grid-area: tide; }
.hud-info > *,
.tide-block > p { white-space: nowrap; min-width: 0; }

.score {
  font-family: var(--display);
  font-weight: 800;
  line-height: 1.05;
  color: var(--foam);
}
.score.hot { color: var(--sand); }
.combo { font-weight: 700; font-size: 15px; color: var(--sand); }
.best-line {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--mist);
}
.tide-label {
  font-family: var(--display);
  font-weight: 800;
  font-size: 13px;
  letter-spacing: 0.04em;
}
.bar {
  flex: 1 0 100%;
  height: 4px;
  margin-top: 3px;
  border-radius: 4px;
  background: rgba(232, 246, 243, 0.16);
  overflow: hidden;
}
.bar > span { display: block; height: 100%; width: 0; background: var(--tide); border-radius: 4px; transition: width 0.12s linear; }
.bar.shut > span { background: var(--flare); }
.bar-caption {
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--mist);
}
.bar-caption.boss { color: var(--foam); }

/* Narrow play areas (small phones): tighten the HUD. */
@container (max-width: 300px) {
  .hud { padding: 10px 10px 12px 12px; column-gap: 8px; row-gap: 3px; }
  .combo { font-size: 12.5px; }
  .best-line, .bar-caption { font-size: 9px; letter-spacing: 0.08em; }
  .tide-label { font-size: 10.5px; }
  .icon-btn { width: 34px; height: 34px; }
  .stats > div { padding: 8px 4px; }
  .sheet { gap: 8px; padding: 12px; }
  .lede { font-size: 13px; }
  .lede.dim { font-size: 12px; }
}

.chips {
  grid-area: chips;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 2px;
}
.chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.1em;
  border: 1px solid currentColor;
  background: rgba(6, 16, 20, 0.55);
}
.chip.good { color: var(--tide); }
.chip.bad { color: var(--flare); }
.chip.score { color: var(--sand); }
.chip-time { width: 22px; height: 3px; background: rgba(232, 246, 243, 0.2); border-radius: 3px; overflow: hidden; }
.chip-time > span { display: block; height: 100%; background: currentColor; }

/* Very small play areas (e.g. a phone on its side). */
@container (max-width: 200px) {
  .hud { padding: 8px 8px 10px 9px; column-gap: 6px; }
  .combo { font-size: 11px; }
  .best-line, .bar-caption { font-size: 8px; letter-spacing: 0.06em; }
  .tide-label { font-size: 9px; letter-spacing: 0.02em; }
  .icon-btn { width: 28px; height: 28px; }
  .icon-btn svg { width: 16px; height: 16px; }
  .chip { font-size: 9px; padding: 3px 7px; gap: 5px; }
}

/* ---------- Modal cards ---------- */

.modal {
  position: absolute;
  inset: 0;
  z-index: 6;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(3, 8, 12, 0.72);
  backdrop-filter: blur(3px);
}
.card {
  width: 100%;
  display: grid;
  gap: 12px;
  padding: 20px 18px;
  border-radius: 20px;
  background: var(--panel);
  border: 1px solid rgba(240, 193, 77, 0.35);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}
.card-title { font-family: var(--display); font-weight: 800; font-size: 22px; line-height: 1.15; }
.card-copy { font-size: 14.5px; line-height: 1.5; }

/* ---------- Small / short screens ---------- */

@media (max-height: 700px) {
  .sheet { gap: 9px; padding: 14px 14px 16px; }
  .lede { font-size: 14px; }
  .lede.dim { font-size: 13px; }
  .launch { min-height: 48px; }
  .ghost { min-height: 42px; }
}

@media (prefers-reduced-motion: reduce) {
  .launch, .bar > span { transition: none; }
}

/* ---------- Modal scrolling ---------- */

.modal { overflow-y: auto; overflow-x: hidden; align-items: safe center; }
.modal > .card { min-width: 0; max-width: 100%; }
.toast {
  position: absolute;
  left: 50%;
  top: 14px; /* top of the stage: never covers Launch or the menus */
  transform: translateX(-50%);
  z-index: 8;
  pointer-events: none;
  width: max-content;
  max-width: calc(100% - 28px);
  padding: 10px 16px;
  border-radius: 14px;
  background: rgba(9, 24, 27, 0.96);
  border: 1px solid rgba(46, 230, 199, 0.5);
  color: var(--foam);
  font-size: 14px;
  font-weight: 600;
  text-align: center;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
}

/* Audio: music credit (CC-BY) on the title screen, credits card, ?audiodebug readout */
.music-credit { margin: 0; font-size: 10px; line-height: 1.35; color: rgba(255,255,255,.62); text-align: center; overflow-wrap: anywhere; }
.credits-link { background: none; border: 0; padding: 0; font: inherit; cursor: pointer; }
.card.credits .fine-print { overflow-wrap: anywhere; text-align: left; }
.audio-debug { position: absolute; left: 6px; top: 6px; z-index: 50; font: 11px/1.3 ui-monospace, monospace; color: #fff; background: rgba(0,0,0,.6); padding: 3px 6px; border-radius: 4px; pointer-events: none; }

/* ---------- Phones: full-screen play (any size, any orientation) ----------
   The stage covers the whole display edge to edge (under the notch and home
   bar). The canvas art is scaled uniformly and centred by JS, with the sea
   painted across any spare space. Only the HUD and menus are inset by the
   safe areas so nothing interactive sits under the notch or home bar. */
html.phone-full, html.phone-full body { height: 100%; }
html.phone-full .app {
  position: fixed;
  inset: 0;
  height: auto;
  padding: 0;
  display: block;
}
html.phone-full .rail { display: none !important; }
html.phone-full .stage {
  position: absolute;
  inset: 0;
  width: 100% !important;
  height: 100% !important;
  max-width: none;
  aspect-ratio: auto;
  border: 0;
  border-radius: 0;
  box-shadow: none;
  background: #062428;
}
html.phone-full .hud {
  padding-top: max(10px, env(safe-area-inset-top, 0px));
  padding-left: max(14px, env(safe-area-inset-left, 0px));
  padding-right: max(14px, env(safe-area-inset-right, 0px));
}
html.phone-full .sheet {
  padding-left: max(18px, env(safe-area-inset-left, 0px));
  padding-right: max(18px, env(safe-area-inset-right, 0px));
  padding-bottom: max(20px, env(safe-area-inset-bottom, 0px));
}
/* Landscape phones: keep menus a readable width, centred over the play column. */
@media (orientation: landscape) {
  html.phone-full .sheet { left: 50%; right: auto; width: min(520px, 100%); transform: translateX(-50%); }
}
