/* Tidal Defense styles. Same family as Rock Pool and Riptide: fonts, colours and
   building blocks (cards, pill buttons, sheets). Fonts are self-hosted (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;
  --foam: #e8f6f3;
  --mist: #93b0b4;
  --tide: #2ee6c7;
  --flare: #ff5d3a;
  --sand: #f0c14d;
  --leaf: #8fce5c;
  --panel: rgba(12, 30, 33, 0.96);
  --line: rgba(232, 246, 243, 0.14);
  /* Reserved band at the top (as in Riptide and Rock Pool) so a ~44px platform
     badge can never cover the game. Short landscape phones use the side layout. */
  --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;
  --pad: 12px;
  --display: 'Syne', 'Outfit', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --text: 'Outfit', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
}
@media (max-width: 359px) {
  :root { --gutter: 6px; }
}

* { 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, h1, h2, ol, dl { 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; }
.noscript { position: fixed; inset: auto 0 20px; text-align: center; }

/* ---------- Layout (sizes set by js/app.js, layout()) ---------- */

.app {
  height: 100vh;
  height: 100dvh;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  align-items: center;
  justify-items: center;
  padding: var(--safe-top) max(var(--gutter), env(safe-area-inset-right, 0px)) var(--safe-bottom) max(var(--gutter), env(safe-area-inset-left, 0px));
}
.app.wide { grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); column-gap: clamp(24px, 3vw, 64px); }
.app.wide .stage { grid-column: 2; }
.app.split {
  padding-top: max(10px, env(safe-area-inset-top, 0px));
  padding-bottom: max(10px, env(safe-area-inset-bottom, 0px));
}
.rail { min-width: 0; display: none; }
.app.wide .rail { display: block; }
.rail-left { justify-self: end; }
.rail-right { justify-self: start; }
.rail-copy, .rail .rules { width: min(300px, 100%); }
.rail-left .rail-copy { margin-left: auto; }
.rail-title { margin: 10px 0 14px; font-family: var(--display); font-weight: 800; line-height: 1; }
.rail .lede { 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); }

.stage {
  position: relative;
  width: min(420px, 100%);
  height: 100%;
  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);
  user-select: none;
  -webkit-user-select: none;
  container-type: inline-size;
}
.stage.compact { border-radius: 20px; }

.fit { white-space: nowrap; overflow: visible; }
.fit > span { display: inline-block; white-space: nowrap; }

/* ---------- Shared text + buttons ---------- */

.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; }
.fine-print { font-size: 11.5px; line-height: 1.4; color: var(--mist); }

.icon-btn {
  width: 44px; height: 44px; 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; padding: 0;
}
.icon-btn svg { width: 20px; height: 20px; }
.icon-btn:hover { background: rgba(232, 246, 243, 0.06); }

.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:active { transform: scale(0.98); }
.launch .btn-main { display: block; line-height: 1.1; }
.launch .btn-sub { display: block; margin-top: 2px; font-family: var(--text); font-weight: 600; font-size: 12px; letter-spacing: 0.06em; text-transform: none; opacity: 0.85; }
.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; padding: 0 8px;
}
.ghost:hover { background: rgba(232, 246, 243, 0.05); }
.pair { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

/* ---------- Game screen ---------- */

.play {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: 44px 30px minmax(0, 1fr) 34px;
  grid-template-areas: "hud" "tide" "map" "status";
  row-gap: 8px;
  padding: var(--pad);
}
.hud { grid-area: hud; display: flex; align-items: center; gap: 10px; min-width: 0; }
.hud-stats { flex: 1; min-width: 0; display: flex; justify-content: center; align-items: center; gap: 18px; }
.stat { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--mist); white-space: nowrap; }
/* numbers use Outfit: Syne's extra-bold 0 reads like a ring and its 9 like a g */
.stat strong { color: var(--foam); font-family: var(--text); font-weight: 700; font-size: 21px; line-height: 1; min-width: 1.4ch; }
.stat-safe strong { color: var(--leaf); }
.stat-stolen strong { color: #ffb59e; }
.stat-icon { width: 22px; height: 22px; flex: none; }
.stat.bump strong { animation: bump 0.35s ease; }
@keyframes bump { 40% { transform: scale(1.35); } }

.tide { grid-area: tide; display: grid; grid-template-columns: auto minmax(0, 1fr); align-items: center; column-gap: 10px; min-width: 0; }
.tide-label { font-size: 12.5px; color: var(--mist); white-space: nowrap; min-width: 0; }
.tide-name { font-weight: 700; letter-spacing: 0.12em; text-transform: uppercase; font-size: 10.5px; color: #7fd8e6; margin-right: 4px; }
#tide-text { color: var(--foam); font-weight: 600; }
.tide.soon #tide-text, .tide.surging #tide-text { color: #9fe9ff; }
.tide-bar { position: relative; height: 12px; border-radius: 999px; background: rgba(3, 8, 12, 0.6); border: 1px solid rgba(127, 216, 230, 0.35); overflow: hidden; }
.tide-fill { position: absolute; inset: 0 auto 0 0; width: 0; border-radius: inherit; background: linear-gradient(90deg, #1d6a76, #3ea3a6 70%, #a9eef2); }
.tide.surging .tide-fill { animation: surgepulse 0.9s ease-in-out infinite alternate; }
@keyframes surgepulse { to { filter: brightness(1.35); } }
.tide-tick { position: absolute; top: 1px; bottom: 1px; width: 3px; margin-left: -1.5px; border-radius: 2px; background: rgba(232, 246, 243, 0.75); }
.tide-tick.done { background: rgba(3, 8, 12, 0.6); }

.map-wrap { grid-area: map; position: relative; min-width: 0; min-height: 0; border-radius: 16px; overflow: hidden; background: #0b1d20; }
.map-wrap canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; cursor: pointer; }
.status { grid-area: status; font-size: 13px; line-height: 17px; color: var(--mist); text-align: center; display: grid; align-items: center; overflow: hidden; }
.status.good { color: var(--leaf); font-weight: 600; }
.status.warn { color: var(--sand); font-weight: 600; }
.play.behind { visibility: hidden; }

/* Side layout (short landscape phones): the map on the left, a slim panel on the right. */
.app.split .play {
  grid-template-columns: var(--map-w, 60%) minmax(0, 1fr);
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  grid-template-areas: "map hud" "map tide" "map ." "map status";
  column-gap: 12px;
  row-gap: 10px;
  padding: 8px;
}
.app.split .hud { flex-wrap: wrap; justify-content: space-between; row-gap: 8px; }
.app.split .hud-stats { order: 3; flex: 1 1 100%; flex-direction: column; align-items: flex-start; gap: 6px; }
.app.split .tide { grid-template-columns: minmax(0, 1fr); row-gap: 6px; }
.app.split .tide-label { white-space: normal; line-height: 1.3; }
.app.split .status { white-space: normal; line-height: 1.35; text-align: left; align-self: end; }

/* ---------- Sheets (title, end) ---------- */

.sheet {
  position: absolute; left: 0; right: 0; bottom: 0;
  display: flex; flex-direction: column; gap: 12px;
  padding: 18px 18px 20px;
  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.cover { top: 0; border-top: 0; }
.sheet-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.sheet-title { font-family: var(--display); font-weight: 800; font-size: 24px; line-height: 1.15; margin-top: 2px; }
.title-head { display: flex; flex-direction: column; gap: 8px; flex: 1 0 auto; min-height: 0; }
.title-head .hero { min-height: 0; }
.title-actions { display: grid; gap: 10px; }
.wordmark { margin: 2px 0 0; font-family: var(--display); font-weight: 800; line-height: 1; }
.hero { flex: 1 1 0; min-height: 0; position: relative; }
.hero canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.tips { list-style: none; padding: 0; display: grid; gap: 8px; }
.tips li { display: grid; grid-template-columns: 44px minmax(0, 1fr); gap: 10px; align-items: center; font-size: 13px; line-height: 1.35; color: var(--mist); }
.tips strong { color: var(--foam); font-weight: 700; margin-right: 3px; }
.tip-art { width: 44px; height: 44px; border-radius: 12px; background: #6f5238; display: block; }
.title-row { min-height: 44px; }
.keys-note { flex: 1; min-width: 0; }
.sheet-foot { text-align: center; font-size: 11.5px; color: var(--mist); opacity: 0.9; line-height: 1.2; margin: -6px 0; white-space: nowrap; }
.foot-link {
  font-size: inherit; color: var(--mist); text-decoration: underline; text-underline-offset: 3px;
  display: inline-flex; align-items: center; justify-content: center; min-height: 44px; min-width: 44px; padding: 0 3px;
}
.foot-link:hover, .foot-link:focus-visible { color: var(--foam); }
.foot-link:focus-visible { outline: 2px solid var(--sand); outline-offset: 2px; }

/* End of round */
.end { justify-content: center; align-items: center; }
.end-main, .end .actions { width: 100%; max-width: 440px; }
.end-main { display: flex; flex-direction: column; gap: 12px; text-align: center; }
.actions { display: grid; gap: 10px; }
.stars { display: flex; justify-content: center; gap: 10px; }
.stars svg { width: 48px; height: 48px; }
.star-on { fill: var(--sand); stroke: #7a5a12; }
.star-off { fill: none; stroke: rgba(232, 246, 243, 0.4); stroke-dasharray: 3 3; }
.stars .pop { animation: starpop 0.4s cubic-bezier(0.34, 1.56, 0.64, 1) both; }
.stars .pop:nth-child(1) { animation-delay: 0.15s; }
.stars .pop:nth-child(2) { animation-delay: 0.45s; }
.stars .pop:nth-child(3) { animation-delay: 0.75s; }
@keyframes starpop { from { transform: scale(0.3) rotate(-30deg); opacity: 0; } to { transform: scale(1) rotate(0); opacity: 1; } }
.sheet.end.enter { animation: sheetup 0.32s ease-out both; }
@keyframes sheetup { from { transform: translateY(28px); opacity: 0; } to { transform: none; opacity: 1; } }
.mark { font-family: var(--display); font-weight: 800; font-size: 14px; letter-spacing: 0.1em; text-transform: uppercase; color: var(--sand); }
.stats { 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); }
.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(--text); font-weight: 700; font-size: 22px; line-height: 1.2; }
#end-safe { color: var(--leaf); }

/* Wide stages (landscape tablets and desktops) and the side layout: sheets in two columns. */
.app.landscape #title-sheet, .app.split #title-sheet {
  display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); column-gap: 22px; align-items: center;
}
.app.landscape #title-sheet { padding: 28px 32px; column-gap: 36px; }
.app.landscape #title-sheet[hidden], .app.split #title-sheet[hidden] { display: none !important; }
.app.landscape .title-head, .app.split .title-head { height: 100%; }
.app.split .sheet { padding: 10px 14px; gap: 8px; }
.app.split .title-head { gap: 4px; }
.app.split .title-actions { gap: 6px; }
.app.split .lede { font-size: 13px; line-height: 1.35; }
.app.split .tips { gap: 4px; }
.app.split .tips li { font-size: 11.5px; line-height: 1.25; grid-template-columns: 44px minmax(0, 1fr); gap: 8px; }
.app.split .launch { min-height: 46px; }
.app.split .launch .btn-sub { display: none; }
.app.split .keys-note { display: none; }
.app.split .title-row { display: none; }
.app.split .sheet-foot { font-size: 11px; }
.app.split .sheet-foot .foot-link { padding: 0 1px; }
.app.split .end { display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr); column-gap: 18px; align-items: center; }
.app.split .end[hidden] { display: none !important; }
.app.split .end-main { gap: 6px; }
.app.split .stars svg { width: 36px; height: 36px; }
.app.split .stats > div { padding: 5px 6px; }
.app.split .stats dd { font-size: 17px; margin-top: 1px; }
.app.split .sheet-title { font-size: 20px; }

/* ---------- Modal (pause) ---------- */

.modal {
  position: absolute; inset: 0; z-index: 6; display: grid; place-items: center; align-items: safe center;
  padding: 14px; overflow-y: auto; background: rgba(3, 8, 12, 0.72); backdrop-filter: blur(3px);
}
.card {
  width: 100%; max-width: 360px; display: grid; gap: 12px; padding: 20px 18px; border-radius: 20px;
  background: var(--panel); border: 1px solid rgba(46, 230, 199, 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; }

.toast {
  position: absolute; left: 50%; top: 104px; transform: translateX(-50%); z-index: 4; pointer-events: none;
  width: max-content; max-width: calc(100% - 28px); padding: 10px 16px; border-radius: 14px;
  background: rgba(9, 24, 27, 0.94); border: 1px solid rgba(46, 230, 199, 0.5); color: var(--foam);
  font-size: 15px; font-weight: 700; text-align: center; box-shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
  animation: toastin 0.25s ease-out both;
}
.toast.tide-toast { border-color: rgba(127, 216, 230, 0.8); color: #c9f4ff; }
.toast.mate-toast { border-color: rgba(255, 143, 180, 0.8); color: #ffe0ea; }
.app.split .toast { top: 14px; }
@keyframes toastin { from { opacity: 0; transform: translate(-50%, -8px); } to { opacity: 1; transform: translate(-50%, 0); } }

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

@container (max-width: 340px) {
  .hud-stats { gap: 12px; }
  .stat-label { display: none; }
  .sheet { padding: 14px 12px 16px; gap: 10px; }
  .lede { font-size: 13.5px; line-height: 1.4; }
  .tips li { font-size: 12px; line-height: 1.3; }
  .tide-label { font-size: 11.5px; }
}
@media (max-height: 700px) {
  .sheet { gap: 9px; padding: 14px 14px 16px; }
  .launch { min-height: 50px; }
}
/* Keyboard keys only matter with a keyboard and mouse */
@media (pointer: coarse) {
  .keys-note { visibility: hidden; }
}
@media (max-height: 620px) and (orientation: portrait) {
  .title-head .lede { display: none; }
  .launch .btn-sub { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .launch { transition: none; }
  .stars .pop, .sheet.end.enter, .stat.bump strong, .tide.surging .tide-fill, .toast { animation: none; }
}
