:root {
  color-scheme: dark;
  --ink: #f3ead2;
  --muted: #a7b5af;
  --night: #081216;
  --frame: #111f23;
  --line: #405b5c;
  --tideglass: #70e0d0;
  --lantern: #ffd777;
  --cedar: #a66c49;
  --danger: #e85d65;
}

* { box-sizing: border-box; }

html { min-height: 100%; background: var(--night); }

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100svh;
  color: var(--ink);
  background:
    radial-gradient(ellipse at 50% -12%, rgba(82,109,129,.42), transparent 42rem),
    linear-gradient(180deg,#17233a 0,#0d1c22 42rem,#081216 100%);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  overflow-x: hidden;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: .18;
  background: radial-gradient(circle at 18% 8%, rgba(112,224,208,.15), transparent 22rem), radial-gradient(circle at 82% 28%, rgba(255,215,119,.08), transparent 26rem);
}

button { font: inherit; }

.game-shell {
  width: min(94vw, 880px);
  margin: 0 auto;
  padding: 30px 0 max(24px, env(safe-area-inset-bottom));
}

.masthead {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 14px;
}

.place-mark { width: 94px; height: 52px; object-fit: contain; flex: 0 0 auto; }
.masthead > div { margin-right: auto; }

.eyebrow, .panel-kicker {
  margin: 0 0 3px;
  color: var(--tideglass);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: .22em;
}

h1 {
  margin: 0;
  color: #f3ead2;
  font-family: Inter, ui-sans-serif, system-ui, sans-serif;
  font-size: clamp(40px, 7vw, 68px);
  font-weight: 900;
  line-height: .82;
  letter-spacing: .035em;
  text-shadow: 0 12px 32px rgba(0,0,0,.38);
}

h1::after { content: ""; display: block; width: 44%; height: 3px; margin-top: 10px; background: linear-gradient(90deg,#5cc7c0 0 58%,transparent 58% 66%,#87a6a2 66% 83%,transparent 83%); }

.tagline {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  letter-spacing: .08em;
  text-align: right;
}

.game-frame {
  position: relative;
  overflow: hidden;
  border: 1px solid rgba(167,203,198,.36);
  border-radius: 24px;
  background: #111f23;
  box-shadow: 0 30px 90px rgba(0,0,0,.58), 0 0 55px rgba(61,172,172,.1), inset 0 1px rgba(255,255,255,.08);
}

canvas {
  display: block;
  width: 100%;
  height: auto;
  image-rendering: auto;
  touch-action: none;
}

.panel {
  position: absolute;
  left: 50%;
  top: 50%;
  width: min(86%, 500px);
  transform: translate(-50%, -50%);
  padding: clamp(23px, 5vw, 42px);
  border: 1px solid rgba(180,221,212,.26);
  border-radius: 24px;
  background: linear-gradient(145deg, rgba(22,43,46,.92), rgba(8,21,25,.88));
  box-shadow: 0 28px 80px rgba(0,0,0,.62), inset 0 1px rgba(255,255,255,.1);
  text-align: center;
  backdrop-filter: blur(18px) saturate(1.25);
}

.panel::before { content: ""; position: absolute; left: 10%; right: 10%; top: 0; height: 1px; background: linear-gradient(90deg,transparent,#70e0d0,transparent); }

.panel[hidden] { display: none; }

.panel h2 {
  margin: 10px 0 16px;
  color: #f3ead2;
  font-family: Inter, ui-sans-serif, system-ui, sans-serif;
  font-size: clamp(32px, 6vw, 52px);
  font-weight: 900;
  line-height: .98;
  letter-spacing: -.035em;
  text-transform: uppercase;
}

.panel > p:not(.panel-kicker) {
  max-width: 430px;
  margin: 0 auto 23px;
  color: #b7c1b8;
  font-family: system-ui, sans-serif;
  font-size: 14px;
  line-height: 1.6;
}

.panel > .tideglass-legend { margin: -10px auto 20px !important; color: #70e0d0 !important; font-family: ui-monospace, monospace !important; font-size: 10px !important; font-weight: 800; letter-spacing: .08em; }
.tideglass-legend::before { content: ""; display: inline-block; width: 9px; height: 9px; margin-right: 8px; border-radius: 50% 50% 55% 45%; background: #70e0d0; transform: rotate(45deg); box-shadow: 0 0 14px rgba(112,224,208,.8); }

.cave-picker {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 7px;
  margin: -4px auto 18px;
}

.cave-choice {
  min-height: 48px;
  padding: 7px 4px;
  border: 1px solid rgba(157,191,185,.22);
  border-radius: 12px;
  color: #a9bbb5;
  background: rgba(6,18,21,.46);
  cursor: pointer;
  transition: background .18s ease, border-color .18s ease, transform .18s ease;
}

.cave-choice strong, .cave-choice span { display: block; }
.cave-choice strong { color: #ecf4ed; font-size: 12px; letter-spacing: .08em; }
.cave-choice span { margin-top: 3px; overflow: hidden; font-size: 7px; letter-spacing: .08em; text-overflow: ellipsis; text-transform: uppercase; white-space: nowrap; }
.cave-choice:hover:not(:disabled) { transform: translateY(-2px); border-color: rgba(112,224,208,.56); background: rgba(24,58,60,.68); }
.cave-choice.selected { border-color: #70e0d0; background: linear-gradient(145deg,rgba(32,104,103,.7),rgba(16,51,56,.8)); box-shadow: 0 0 0 1px rgba(112,224,208,.14), 0 10px 28px rgba(0,0,0,.24); }
.cave-choice:disabled { opacity: .35; cursor: not-allowed; }

.primary-button {
  min-height: 46px;
  padding: 0 22px;
  border: 0;
  border-radius: 999px;
  color: #182026;
  background: linear-gradient(#ffe091,#efb95b);
  box-shadow: 0 10px 24px rgba(239,185,91,.24), inset 0 1px rgba(255,255,255,.62);
  font-size: 12px;
  font-weight: 900;
  letter-spacing: .08em;
  text-transform: uppercase;
  cursor: pointer;
  transition: transform .12s ease, filter .12s ease;
}

.primary-button:hover { filter: brightness(1.08); transform: translateY(-1px); }
.primary-button:active { transform: translateY(1px); box-shadow: 0 4px 12px rgba(239,185,91,.18); }
.primary-button:focus-visible, button:focus-visible { outline: 3px solid #c7fff0; outline-offset: 3px; }

.mini-controls {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 10px 18px;
  margin-top: 23px;
  color: #9fb0aa;
  font-size: 10px;
}

kbd {
  display: inline-grid;
  min-width: 20px;
  height: 20px;
  margin-right: 3px;
  place-items: center;
  border: 1px solid #4e6866;
  border-radius: 3px;
  background: #172a2d;
  color: #e8e1cb;
  box-shadow: 0 2px 0 #071013;
}

.pause-badge {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: white;
  background: rgba(7,16,19,.76);
  font-size: clamp(22px, 6vw, 46px);
  font-weight: 900;
  letter-spacing: .18em;
  backdrop-filter: blur(2px);
}

.pause-badge[hidden] { display: none; }

.action-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 12px 2px 10px;
}

.status-copy { display: flex; flex-direction: column; gap: 3px; font-size: 11px; font-weight: 800; letter-spacing: .07em; }
#bestLabel { color: #718984; }
.actions { display: flex; gap: 7px; }

.icon-button {
  min-height: 34px;
  padding: 0 11px;
  border: 1px solid #405b5c;
  border-radius: 999px;
  color: #bed0c8;
  background: rgba(23,42,45,.72);
  font-size: 9px;
  font-weight: 800;
  letter-spacing: .06em;
  cursor: pointer;
}

.icon-button:hover { color: white; border-color: #64807c; }
.icon-button.danger { color: #e85d65; }

.touch-controls {
  display: none;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  padding: 4px 0 8px;
}

.touch-controls button {
  min-height: 62px;
  border: 1px solid #4e6866;
  border-radius: 18px;
  color: #e8e1cb;
  background: linear-gradient(#20383a, #132326);
  box-shadow: 0 12px 24px rgba(0,0,0,.28), inset 0 1px rgba(255,255,255,.08);
  font-size: 27px;
  font-weight: 900;
  touch-action: manipulation;
  user-select: none;
}

.touch-controls button:active { transform: translateY(3px); box-shadow: 0 1px 0 #071013; background: #29494a; color: #c7fff0; }

footer {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  border-top: 1px solid #263b3d;
  padding-top: 13px;
  color: #71817d;
  font-size: 10px;
}

footer p { margin: 0; }
footer strong { color: #a7b5af; }

@media (max-width: 680px), (pointer: coarse) {
  .game-shell { width: min(100%, 720px); padding-top: 15px; }
  .masthead, .action-row, footer { margin-inline: 13px; }
  .masthead { justify-content: flex-start; gap: 10px; }
  .game-frame { border-inline: 0; border-radius: 0; }
  .touch-controls { display: grid; margin-inline: 12px; }
  .desktop-help { display: none; }
  .tagline { display: none; }
  .actions { gap: 4px; }
  .icon-button { padding-inline: 8px; font-size: 8px; }
  footer { padding-bottom: 8px; }
  .place-mark { width: 65px; height: 38px; }
}

@media (max-width: 430px) {
  .panel { width: 90%; padding: 21px 18px; }
  .panel > p:not(.panel-kicker) { font-size: 12px; line-height: 1.5; }
  .mini-controls { display: none; }
  .status-copy { font-size: 9px; }
  .masthead { align-items: center; }
  .cave-picker { gap: 4px; }
  .cave-choice { min-height: 42px; border-radius: 10px; }
  .cave-choice span { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; }
}
