:root {
  color-scheme: dark;
  font-family: "Segoe UI", system-ui, sans-serif;
  color: #f3e9d5;
  background: #071c1d;
  --sand: #f3e9d5;
  --gold: #f5d484;
  --muted: #a2bab0;
  --border: #96bd9d35;
  --serif: Georgia, "Palatino Linotype", serif;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0;
  min-width: 280px;
  min-height: 100svh;
  background:
    radial-gradient(ellipse at 52% 29%, #19413a 0%, transparent 65%),
    radial-gradient(ellipse at 12% 95%, #183735 0%, transparent 54%),
    linear-gradient(145deg, #0a2727, #061919 72%);
}
p, h1, h2, dl, dd { margin: 0; }
button { font: inherit; color: inherit; cursor: pointer; -webkit-tap-highlight-color: transparent; }
button:focus-visible, canvas:focus-visible { outline: 2px solid #ffdfa2; outline-offset: 4px; }
canvas { display: block; }

.shell {
  width: min(calc(100% - 5rem), 85rem, calc((100svh - 8.5rem) * 1.99));
  min-height: 100svh;
  margin-inline: auto;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding-block: 1.15rem;
  gap: 0.95rem;
}
.masthead, .toolbar, .brand {
  display: flex;
  align-items: center;
}
.masthead { justify-content: space-between; min-height: 2.9rem; }
.brand { gap: 0.72rem; font: 700 1.55rem/1 var(--serif); letter-spacing: -0.045em; color: #f7e6bb; }
.brand-mark, .score-icon, .stage-icon, .dialog-mark, .result-mark {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  color: var(--gold);
  border: 1px solid #d6b87545;
  background: linear-gradient(150deg, #344838, #1c302b);
  box-shadow: inset 0 1px #ffffff12;
}
.brand-mark { width: 2.7rem; height: 2.7rem; border-radius: 0.8rem; }
.icon { flex: 0 0 auto; width: 1.25rem; height: 1.25rem; }
.brand-mark .icon { width: 1.55rem; height: 1.55rem; }
.toolbar { gap: 0.52rem; }
.icon-button {
  width: 2.7rem;
  height: 2.7rem;
  display: grid;
  place-items: center;
  background: #0c2626c9;
  border: 1px solid var(--border);
  border-radius: 0.75rem;
  color: #d8e5cf;
  transition: background 160ms ease, border-color 160ms ease, transform 160ms ease;
}
.icon-button:hover { background: #21423b; border-color: #cfb98280; }
.icon-button:active { transform: translateY(1px); }
.icon-button[aria-pressed="true"] { border-color: #bbaa6759; background: #202f27; }

.stage { position: relative; isolation: isolate; }
.hero, .game, .results {
  position: relative;
  overflow: hidden;
  border-radius: 1.45rem;
  border: 1px solid #b2ceaa55;
  box-shadow: 0 20px 60px #001514a8, 0 2px 12px #011714b8, inset 0 1px #ede9c022;
}
.hero, .results { aspect-ratio: 2 / 1; min-height: 23rem; }
.hero {
  container-type: inline-size;
  display: grid;
  align-items: center;
  background: #0b3536 url('./assets/sunset-cove.jpg') center / cover no-repeat;
}
.hero::before, .hero::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
}
.hero::before {
  background: linear-gradient(90deg, #051e25a8, #07212848 35%, transparent 60%),
    linear-gradient(0deg, #031a1ec9, transparent 28%);
}
.hero::after { inset: 0; border-radius: inherit; box-shadow: inset 0 1px #ffffe847, inset 0 -1px #b3cba41f; }
.hero-copy {
  position: relative;
  z-index: 1;
  width: fit-content;
  max-width: 100%;
  padding: clamp(2.3rem, 6.15cqw, 5.25rem);
  padding-block-end: clamp(7rem, 11.6cqw, 9.85rem);
}
.eyebrow {
  color: #f5d796;
  font-size: 0.84rem;
  font-weight: 750;
  line-height: 1.3;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}
.hero .eyebrow { display: flex; align-items: center; gap: 0.72rem; margin-block-end: 0.82rem; }
.hero .eyebrow::before { content: ""; width: 1.65rem; height: 1px; background: #fbd28fbd; }
.wordmark {
  position: relative;
  isolation: isolate;
  width: fit-content;
  font: 900 clamp(5.1rem, 13.15cqw, 11.2rem)/0.87 var(--serif);
  letter-spacing: -0.08em;
  text-transform: uppercase;
}
.wordmark-depth {
  position: absolute;
  inset: 0;
  color: #9f6233;
  transform: translateY(0.046em);
  text-shadow: 0 0.046em #392923, 0 0.08em 0.12em #001719c4;
}
.wordmark-face {
  position: relative;
  display: block;
  color: #f8d483;
  background: linear-gradient(180deg, #fff1c1 11%, #f9de9e 40%, #f4ca77 70%, #e3a74f 98%);
  background-clip: text;
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}
.hero-description {
  max-width: 32ch;
  margin-block-start: clamp(1rem, 2.05cqw, 1.65rem);
  color: #e3ead7;
  font-size: clamp(1rem, 1.55cqw, 1.25rem);
  line-height: 1.55;
  text-wrap: pretty;
  text-shadow: 0 1px 12px #071c20d9;
}
.actions { display: flex; flex-wrap: wrap; align-items: center; gap: 0.7rem; }
.hero-actions { margin-block-start: clamp(1.35rem, 2.4cqw, 2.1rem); }
.button {
  min-height: 3.15rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.56rem;
  padding: 0.72rem 1.38rem;
  border: 1px solid transparent;
  border-radius: 0.72rem;
  font-weight: 750;
  white-space: nowrap;
  transition: transform 160ms ease, background 160ms ease, border-color 160ms ease, box-shadow 160ms ease;
}
.hero-actions .button-gold { min-width: 8.45rem; }
.button-gold {
  color: #292b20;
  background: linear-gradient(180deg, #ffe8a8, #f4cd79 63%, #e9b867);
  border-color: #ffe4a5;
  box-shadow: 0 3px #987144, inset 0 1px #fff3cc, 0 8px 18px #06181288;
}
.button-gold:hover { background: linear-gradient(180deg, #fff1c4, #fbd990 70%, #efc279); }
.button-gold:active { transform: translateY(2px); box-shadow: 0 1px #987144, inset 0 1px #fff3cc; }
.button-glass {
  color: #eeead9;
  background: #0a2a29b3;
  border-color: #aec2a572;
  box-shadow: inset 0 1px #f3eacf15;
}
.button-glass:hover { background: #24433edb; border-color: #c8cfab; }
.button-glass:active { transform: translateY(1px); }
.button .icon { width: 1.12rem; height: 1.12rem; }
.personal-best {
  position: absolute;
  bottom: clamp(1.28rem, 3.05cqw, 2.55rem);
  left: clamp(2.3rem, 6.15cqw, 5.25rem);
  z-index: 1;
  display: flex;
  align-items: center;
  gap: 0.68rem;
  padding: 0.45rem 1.03rem 0.45rem 0.49rem;
  border-radius: 0.8rem;
  border: 1px solid #b3c8a13d;
  background: #082725bd;
  box-shadow: 0 3px 10px #001b1c77;
}
.score-icon { width: 2.25rem; height: 2.25rem; border-radius: 0.48rem; }
.score-icon .icon { width: 1.04rem; height: 1.04rem; }
.label {
  display: block;
  color: #b6cbb9;
  font-size: 0.78rem;
  font-weight: 750;
  letter-spacing: 0.11em;
  line-height: 1.25;
  text-transform: uppercase;
}
.personal-best strong { display: block; font-size: 1.1rem; line-height: 1.15; font-variant-numeric: tabular-nums; }

.game { background: #0b2c2c; }
.hud {
  display: grid;
  grid-template-columns: minmax(11rem, 1fr) minmax(10rem, 1.32fr) minmax(7rem, 1fr);
  gap: 1.5rem;
  align-items: center;
  min-height: 4.65rem;
  padding: 0.65rem clamp(1rem, 3vw, 2rem);
  border-bottom: 1px solid #c1cfaa3b;
  background: linear-gradient(110deg, #193932, #0d2c30 65%, #172d2b);
}
.stage-meta { display: flex; align-items: center; gap: 0.8rem; }
.stage-icon { width: 2.7rem; height: 2.7rem; border-radius: 0.65rem; }
.stage-meta h2 { margin-top: 0.13rem; font: 700 clamp(1.1rem, 2.25vw, 1.5rem)/1.05 var(--serif); white-space: nowrap; }
.danger { max-width: 27rem; width: 100%; justify-self: center; }
.danger-label { display: flex; justify-content: space-between; gap: 0.35rem; align-items: baseline; margin-bottom: 0.35rem; }
.danger-label span:last-child { color: #a6dfbd; font-size: 0.86rem; font-weight: 730; font-variant-numeric: tabular-nums; }
.danger-track {
  overflow: hidden;
  height: 0.45rem;
  border-radius: 999px;
  background: #061e22;
  box-shadow: inset 0 0 0 1px #a2c9ac2e;
}
.danger-fill {
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, #467e6d, #9ee3ae);
  border-radius: inherit;
  transform: scaleX(0);
  transform-origin: left;
}
.danger[data-risk="high"] .danger-fill { background: linear-gradient(90deg, #81967c, #ffd77e); }
.danger[data-risk="high"] .danger-label span:last-child { color: #ffd77e; }
.danger[data-risk="critical"] .danger-fill { background: linear-gradient(90deg, #dd996a, #ff846e); }
.danger[data-risk="critical"] .danger-label span:last-child { color: #ff9c87; }
.hud-score { text-align: right; }
.hud-score strong { color: #ffe5a9; font: 700 clamp(1.35rem, 2.7vw, 1.95rem)/1.08 var(--serif); font-variant-numeric: lining-nums tabular-nums; }
.pool {
  position: relative;
  aspect-ratio: 1200 / 568;
  overflow: hidden;
  background: #105354 url('./assets/lagoon.jpg') center / cover no-repeat;
}
.pool[data-layout="portrait"] { aspect-ratio: 620 / 850; }
.pool::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  box-shadow: inset 0 0 80px #051e25a5;
  background: #05312f17;
}
.pool[data-theme="moon"]::before { background: linear-gradient(140deg, #182f5849, #24234131 70%, #0c357752); }
.pool[data-theme="ember"]::before { background: linear-gradient(140deg, #652f433c, #23243d35 55%, #7c3f2f4d); }
.pool[data-theme="falls"]::before { background: linear-gradient(140deg, #214a3e2e, #03382a46); }
.pool[data-theme="mangrove"]::before { background: linear-gradient(140deg, #625b354c, #163d293e 67%, #1f4b3c7a); }
.pool[data-theme="pearl"]::before { background: linear-gradient(140deg, #0d5b6536, #0936506b); }
.pool[data-theme="hibiscus"]::before { background: linear-gradient(140deg, #38224f64, #1a425385 62%, #5e2c6269); }
.pool[data-theme="trade-wind"]::before { background: linear-gradient(140deg, #14555144, #12395331 58%, #19726c69); }
.pool[data-theme="black-sand"]::before { background: linear-gradient(140deg, #27264572, #09273d4a 60%, #382b505b); }
.pool[data-theme="caldera"]::before { background: radial-gradient(ellipse at 71% 36%, #6e3b3866, #2d27355b 63%, #532e3852); }
.pool > canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  cursor: crosshair;
  touch-action: none;
}
.pool > canvas:focus-visible { outline-offset: -4px; }
.play-hint {
  position: absolute;
  z-index: 1;
  left: 50%;
  bottom: 0.8rem;
  width: max-content;
  max-width: calc(100% - 1.4rem);
  padding: 0.45rem 0.85rem;
  transform: translateX(-50%);
  border: 1px solid #b0d7ad55;
  border-radius: 999px;
  background: #092f30e8;
  color: #e1efda;
  text-align: center;
  font-size: 0.86rem;
  pointer-events: none;
}

.control-bar {
  min-height: 2.65rem;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #acbdb1;
}
.control-hints, .control-hints > span { display: flex; align-items: center; gap: 0.5rem; }
.control-hints { gap: clamp(0.66rem, 2vw, 1.55rem); font-size: 0.88rem; }
.control-hints > span + span::before {
  content: "";
  width: 1px;
  height: 0.95rem;
  margin-right: clamp(0.18rem, 1.25vw, 0.85rem);
  background: #aac6af35;
}
.control-hints .icon { width: 1.03rem; height: 1.03rem; }
.touch-hints { display: none; }
kbd {
  padding: 0.12rem 0.38rem;
  border: 1px solid #aecbb14b;
  border-bottom-width: 2px;
  border-radius: 0.29rem;
  background: #26403a7a;
  color: #e3e4d2;
  font: 650 0.78rem/1.12 "Segoe UI", system-ui, sans-serif;
  white-space: nowrap;
}
.swap-button {
  position: absolute;
  right: 0;
  min-height: 2.55rem;
  display: inline-flex;
  align-items: center;
  gap: 0.42rem;
  padding: 0.35rem 0.72rem;
  border: 1px solid var(--border);
  border-radius: 0.56rem;
  background: #16403b69;
  color: #d4e6d6;
  font-size: 0.88rem;
  font-weight: 650;
}
.swap-button .icon { width: 1rem; height: 1rem; }
.swap-button:hover { background: #3160508a; }

.overlay {
  position: absolute;
  z-index: 5;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 0.65rem;
  border-radius: 1.45rem;
  background: #03191ad1;
  backdrop-filter: blur(5px);
}
.dialog, .result-card {
  position: relative;
  display: grid;
  justify-items: center;
  text-align: center;
  border: 1px solid #c6bc8f6a;
  border-radius: 1.24rem;
  background: radial-gradient(ellipse at 50% 0%, #2e4c3c 0%, transparent 69%), #102d2d;
  box-shadow: 0 18px 50px #041b1ad6, inset 0 1px #f6e5a62b;
}
.dialog {
  width: min(100%, 31.5rem);
  max-height: 100%;
  overflow-y: auto;
  padding: clamp(1rem, 3.5vh, 2.15rem);
}
.dialog-compact { width: min(100%, 23rem); }
.dialog-mark, .result-mark { width: 3.45rem; height: 3.45rem; border-radius: 1.02rem; margin-bottom: 0.75rem; }
.dialog-mark .icon, .result-mark .icon { width: 1.6rem; height: 1.6rem; }
.dialog h2, .result-card h2 {
  color: #ffe4a5;
  font: 700 clamp(2rem, 5.5vw, 3.15rem)/1.02 var(--serif);
  letter-spacing: -0.045em;
  text-wrap: balance;
}
.dialog .eyebrow, .result-card .eyebrow { margin-bottom: 0.38rem; font-size: 0.79rem; letter-spacing: 0.145em; }
.dialog-copy { margin-top: 0.55rem; color: #d1e1ce; line-height: 1.5; }
.close-button { position: absolute; top: 0.75rem; right: 0.75rem; }
.rules {
  display: grid;
  gap: 0.65rem;
  width: 100%;
  margin-block: 1rem 1.15rem;
  text-align: left;
}
.rules div { padding: 0.62rem 0.78rem; border-radius: 0.58rem; background: #0625258a; border: 1px solid #abc9a728; }
.rules dt { margin-bottom: 0.12rem; color: #f0e5c6; font-weight: 750; }
.rules dd { color: #c9dbce; line-height: 1.45; }
.pause-actions { display: grid; gap: 0.62rem; width: min(100%, 13.5rem); margin-top: 1.35rem; }
.text-button { background: transparent; border: 0; min-height: 2.55rem; color: #c1d0bf; font-weight: 650; }
.text-button:hover { color: #f9e1aa; }

.results {
  display: grid;
  place-items: center;
  padding: 1.15rem;
  background: linear-gradient(90deg, #051f26ac, #0421217d 48%, #09262760), url('./assets/sunset-cove.jpg') center / cover no-repeat;
}
.result-card { width: min(100%, 34rem); padding: clamp(1.18rem, 4.5vh, 2.35rem); background-color: #0a2626f5; }
.final-score { display: grid; gap: 0.08rem; margin-top: 0.95rem; }
.final-score strong {
  color: #f8d487;
  font: 700 clamp(2.9rem, 6.5vw, 4.5rem)/1 var(--serif);
  letter-spacing: -0.045em;
  font-variant-numeric: lining-nums tabular-nums;
}
.result-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  width: 100%;
  margin-block: 1.2rem 1.32rem;
  padding-block: 0.7rem;
  border-block: 1px solid #a8bc9a3f;
}
.result-stats div + div { border-left: 1px solid #a8bc9a3f; }
.result-stats dt { color: #b2caba; font-size: 0.88rem; }
.result-stats dd { margin-top: 0.12rem; font-weight: 750; font-size: 1.12rem; font-variant-numeric: tabular-nums; }
.result-card .actions { justify-content: center; }
.clear-score { margin-bottom: 1.15rem; }
.clear-score > span:last-child { color: #b3cbba; font-size: 0.91rem; }

@media (max-width: 900px) {
  .shell { width: min(calc(100% - 3rem), calc((100svh - 8rem) * 1.99)); }
  .hud { gap: 1rem; }
  .swap-button { position: static; margin-left: auto; }
  .control-bar:has(.swap-button:not([hidden])) { justify-content: flex-start; }
}

@media (max-width: 700px) and (orientation: portrait) {
  .shell { width: calc(100% - 1.5rem); min-height: 100svh; padding-block: 0.75rem; gap: 0.7rem; }
  .masthead { min-height: 2.75rem; }
  .hero, .results { min-height: clamp(34rem, calc(100svh - 7.7rem), 47rem); aspect-ratio: auto; border-radius: 1.05rem; }
  .hero { align-items: end; background-position: 61% center; }
  .hero::before {
    background: linear-gradient(0deg, #041b20 2%, #072528f2 22%, #092326ad 56%, #07252832 82%),
      linear-gradient(90deg, #05212457, transparent 72%);
  }
  .hero-copy { padding: 1.6rem 1.4rem 6.3rem; }
  .hero .eyebrow { font-size: 0.74rem; letter-spacing: 0.135em; }
  .hero .eyebrow::before { width: 1.14rem; }
  .wordmark { font-size: clamp(4.65rem, 21cqw, 8.8rem); }
  .hero-description { max-width: 29ch; }
  .hero-actions { gap: 0.55rem; }
  .hero-actions .button { min-width: 0; padding-inline: 0.93rem; }
  .personal-best { left: 1.4rem; bottom: 1.34rem; }
  .game, .overlay { border-radius: 1.05rem; }
  .hud {
    min-height: 0;
    grid-template-columns: 1fr auto;
    grid-template-rows: auto auto;
    gap: 0.55rem 0.9rem;
    padding: 0.7rem 0.84rem 0.65rem;
  }
  .hud .label { font-size: 0.72rem; }
  .stage-meta { min-width: 0; gap: 0.52rem; }
  .stage-icon { width: 2.15rem; height: 2.15rem; }
  .stage-meta h2 { font-size: 1.18rem; white-space: normal; }
  .danger { grid-row: 2; grid-column: 1 / -1; max-width: none; }
  .danger-label { margin-bottom: 0.25rem; }
  .danger-track { height: 0.34rem; }
  .danger-label span:last-child { font-size: 0.78rem; }
  .hud-score { grid-row: 1; grid-column: 2; }
  .play-hint { font-size: 0.78rem; bottom: 0.45rem; }
  .desktop-hints { display: none; }
  .touch-hints { display: flex; }
  .dialog { padding: 1.15rem; }
  .result-card { padding: 1.15rem; }
  .result-stats dt { font-size: 0.8rem; }
}

@media (max-height: 620px) and (orientation: landscape) {
  .shell { width: min(calc(100% - 2.5rem), calc((100svh - 6.4rem) * 1.99)); padding-block: 0.48rem; gap: 0.55rem; }
  .hero, .results { min-height: 18.65rem; }
  .hero-copy { padding-block: 1.35rem 5rem; }
  .hero .eyebrow { margin-bottom: 0.55rem; }
  .hero-description { margin-block-start: 0.7rem; }
  .hero-actions { margin-block-start: 0.82rem; }
  .personal-best { bottom: 0.65rem; }
  .hud { min-height: 3.7rem; }
  .result-card { padding-block: 0.85rem; }
  .result-mark { display: none; }
  .result-stats { margin-block: 0.65rem 0.8rem; }
  .final-score { margin-top: 0.55rem; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: 0.01ms !important; }
}
