/* Riptide v2 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: #061014;
  --depth: #0e2c30;
  --trench: #03080c;
  --foam: #e8f6f3;
  --mist: #93b0b4;
  --tide: #2ee6c7;
  --flare: #ff5d3a;
  --sand: #f0c14d;
  --panel: rgba(12, 30, 33, 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: #040b0e;
  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(14, 58, 60, 0.55), transparent 60%),
    radial-gradient(80% 60% at 50% -10%, rgba(14, 44, 48, 0.35), transparent 70%),
    #040b0e;
}

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; }

.remove-ads-row { display: grid; gap: 4px; justify-items: center; text-align: center; }
.remove-ads-btn {
  min-height: 40px;
  padding: 8px 18px;
  border-radius: 999px;
  border: 1px solid rgba(240, 193, 77, 0.55);
  background: rgba(240, 193, 77, 0.08);
  color: var(--sand);
  font-weight: 600;
  font-size: 14px;
}
.remove-ads-btn:hover { background: rgba(240, 193, 77, 0.14); }
.ads-removed { text-align: center; color: var(--tide); font-weight: 600; font-size: 14px; }
.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; }

.offer {
  display: grid;
  gap: 6px;
  padding: 12px;
  border-radius: 14px;
  border: 1px dashed rgba(46, 230, 199, 0.4);
  background: rgba(46, 230, 199, 0.05);
}
.offer-title { font-weight: 700; font-size: 15px; }
.offer-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 4px; }
.offer-btn {
  min-height: 44px;
  border-radius: 999px;
  border: 1px solid rgba(232, 246, 243, 0.25);
  background: rgba(6, 16, 20, 0.5);
  font-weight: 600;
  font-size: 14px;
}

/* ---------- 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; }
}

/* ---------- Placeholder ad panel ---------- */

.ad-break {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 14px 14px 18px;
  background: rgba(3, 8, 12, 0.94);
}
.ad-creative {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 12px;
  padding: 14px;
  border-radius: 18px;
  border: 1px solid rgba(46, 230, 199, 0.25);
  background: repeating-linear-gradient(90deg, #0f3a37 0 14px, #0a2a28 14px 28px);
}
.ad-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.ad-kicker {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--mist);
  background: rgba(3, 8, 12, 0.65);
  padding: 4px 8px;
  border-radius: 6px;
}
.ad-count {
  font-family: var(--display);
  font-weight: 800;
  font-size: 30px;
  line-height: 1;
  min-width: 2ch;
  text-align: right;
  background: rgba(3, 8, 12, 0.65);
  padding: 4px 8px;
  border-radius: 8px;
}
.ad-slot {
  align-self: center;
  width: 86%;
  padding: 22px 16px;
  border-radius: 14px;
  border: 2px dashed rgba(232, 246, 243, 0.35);
  background: rgba(3, 8, 12, 0.72);
  text-align: center;
  display: grid;
  gap: 8px;
}
.ad-slot-title { font-family: var(--display); font-weight: 800; font-size: 22px; letter-spacing: 0.08em; text-transform: uppercase; }
.ad-slot-copy { font-size: 13.5px; line-height: 1.45; color: var(--mist); }
.ad-copy {
  font-size: 14.5px;
  line-height: 1.45;
  font-weight: 500;
  background: rgba(3, 8, 12, 0.72);
  padding: 10px 12px;
  border-radius: 10px;
}
/* Secondary on purpose: quiet outline, full 44px touch height, and kept
   20px (12px gap + 8px margin) below "Dive into Tide 3" so a child
   reaching for Continue can't hit it by accident. */
.ad-unlock {
  align-self: center;
  min-height: 44px;
  margin-top: 8px;
  padding: 0 18px;
  border: 1px solid rgba(232, 246, 243, 0.22);
  border-radius: 999px;
  background: transparent;
  color: var(--mist);
  font-size: 13px;
  font-weight: 500;
}
.ad-unlock:focus-visible { outline: 2px solid var(--sand); outline-offset: 2px; }
.ad-count.done { font-size: 16px; letter-spacing: 0.04em; padding: 8px 10px; }

/* ---------- Remove-ads card ---------- */

.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; }
}

/* ---------- Ready card (after the Tide 2 break) ---------- */

.card.ready { text-align: center; justify-items: center; border-color: rgba(46, 230, 199, 0.35); }
.card.ready .launch { margin-top: 4px; }

/* ---------- Paid "No ads" card + grown-up check ---------- */

.modal { overflow-y: auto; overflow-x: hidden; align-items: safe center; }
.modal > .card { min-width: 0; max-width: 100%; }
.card.pay { gap: 10px; max-height: 100%; overflow-y: auto; overflow-wrap: anywhere; }
.pay-parent {
  font-size: 14.5px;
  line-height: 1.45;
  padding: 10px 12px;
  border-radius: 12px;
  background: rgba(240, 193, 77, 0.1);
  border: 1px solid rgba(240, 193, 77, 0.4);
  color: var(--foam);
}
.pay-parent strong { color: var(--sand); }
.pay-test { font-size: 12px; font-weight: 600; color: var(--tide); }
.gate { display: grid; gap: 6px; font-size: 14px; line-height: 1.45; }
.gate-q strong { color: var(--foam); }
.gate-input {
  width: 100%;
  min-height: 44px;
  padding: 8px 12px;
  border-radius: 12px;
  border: 1px solid rgba(232, 246, 243, 0.3);
  background: rgba(3, 8, 12, 0.6);
  color: var(--foam);
  font: 600 18px/1 var(--text);
  letter-spacing: 0.08em;
}
.gate-input:focus-visible { outline: 2px solid var(--sand); outline-offset: 2px; }
.gate-error { font-size: 13px; color: var(--flare); font-weight: 600; }
.pay-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.pay-btn {
  min-height: 46px;
  border-radius: 999px;
  font-weight: 700;
  font-size: 15px;
  padding: 0 10px;
}
.pay-no { border: 1px solid rgba(232, 246, 243, 0.35); background: rgba(6, 16, 20, 0.35); color: var(--foam); }
.pay-yes { border: 1px solid var(--tide); background: rgba(46, 230, 199, 0.14); color: var(--foam); }
.pay-btn:disabled { opacity: 0.6; cursor: default; }

.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);
}

/* Restore code after a paid return: big, plain, easy to copy or photograph */
.card.code { gap: 10px; grid-template-columns: minmax(0, 1fr); max-height: 100%; overflow-y: auto; overflow-wrap: anywhere; }
.card.code .launch { letter-spacing: 0.08em; padding: 0 10px; }
.card.code .restore-code {
  margin: 6px 0 2px;
  font: 800 clamp(16px, 5vmin, 26px) / 1.25 ui-monospace, 'SFMono-Regular', Menlo, Consolas, monospace;
  letter-spacing: 0.06em;
  text-align: center;
  user-select: all;
  -webkit-user-select: all;
  word-break: break-all;
  padding: 10px 12px;
  border: 2px dashed currentColor;
  border-radius: 10px;
}
