:root {
  --bg: #08131c;
  --ink: #e8edf4;
  --dim: #7d8794;
  --line: #3a4350;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  overflow: hidden;
  overscroll-behavior: none;
}

#shell {
  /* Height taken by title + hint + padding + gaps. The playfield sizes
     itself against whatever is left, so it always fits without scrolling. */
  --chrome: 88px;
  --gutter: 24px;

  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 100dvh;
  padding: 8px 12px calc(8px + env(safe-area-inset-bottom));
}

#title {
  margin: 0;
  flex: 0 0 auto;
  font-size: clamp(1rem, 4vw, 1.3rem);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

/* The one and only playfield: always 9:16, never wider than 420px, always
   fully visible. Wide screens get outer margin, not more game.
   Height is driven by min() of the three real limits — leaving it to
   aspect-ratio + max-width lets max-width win and stretches the canvas. */
#playfield {
  position: relative;
  flex: 0 0 auto;
  aspect-ratio: 9 / 16;
  height: min(
    calc(100dvh - var(--chrome)),
    calc((100vw - var(--gutter)) * 16 / 9),
    calc(420px * 16 / 9)
  );
  border: 2px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
}

#game {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 20px;
  text-align: center;
  background: rgba(8, 19, 28, 0.9);
}

.overlay .logo {
  width: min(60%, 220px);
  height: auto;
  margin-bottom: -6px;
}

.overlay.hidden {
  display: none;
}

.overlay h2 {
  margin: 0;
  font-size: clamp(1.1rem, 5vw, 1.5rem);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.overlay .rules {
  margin: 0;
  font-size: 0.82rem;
  color: var(--dim);
  max-width: 28ch;
}

.overlay .score {
  margin: 0;
  font-size: 1.1rem;
  font-variant-numeric: tabular-nums;
}

.overlay .controls {
  margin: 0;
  padding: 0;
  list-style: none;
  font-size: 0.82rem;
  line-height: 1.7;
}

.overlay button {
  margin-top: 6px;
  padding: 12px 28px;
  font: inherit;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--bg);
  background: var(--ink);
  border: 0;
  border-radius: 8px;
  cursor: pointer;
  touch-action: manipulation;
}

.overlay button:disabled {
  opacity: 0.5;
  cursor: wait;
}

.overlay button:focus-visible {
  outline: 3px solid var(--dim);
  outline-offset: 3px;
}

/* Game over: share link styled as a second, quieter button in WhatsApp green. */
.overlay .share {
  margin-top: 2px;
  padding: 10px 22px;
  font-size: 0.85rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: #fff;
  background: #25d366;
  border-radius: 8px;
  text-decoration: none;
  touch-action: manipulation;
}

.overlay .share:hover,
.overlay .share:focus-visible {
  background: #1ebe5b;
  outline: none;
}

/* Sound settings: a cog in the HUD corner and a panel with two sliders. */
#btn-settings {
  position: absolute;
  top: 1.2%;
  right: 2%;
  width: 9%;
  aspect-ratio: 1;
  padding: 0;
  font-size: clamp(1rem, 5.5vmin, 1.5rem);
  line-height: 1;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.12);
  border: 0;
  border-radius: 50%;
  cursor: pointer;
  touch-action: manipulation;
}

#btn-settings:hover,
#btn-settings:focus-visible {
  background: rgba(255, 255, 255, 0.28);
  outline: none;
}

.overlay .slider {
  display: flex;
  flex-direction: column;
  gap: 6px;
  width: min(70%, 240px);
  font-size: 0.95rem;
  font-weight: 700;
}

.overlay .slider output {
  font-variant-numeric: tabular-nums;
}

.overlay .slider input {
  width: 100%;
  margin: 0;
  accent-color: #7ed957;
  touch-action: manipulation;
}

#hint {
  margin: 0;
  flex: 0 0 auto;
  font-size: 0.75rem;
  color: var(--dim);
  text-align: center;
}

/* Short screens: drop the chrome so the pond always fits. */
@media (max-height: 560px) {
  #shell {
    --chrome: 20px;
  }

  #title,
  #hint {
    display: none;
  }
}
