:root {
  color-scheme: dark;
  --bg: #0a0806;
  --ink: #f2e8d5;
  --muted: #a8760c;
  --left: #ffb000;
  --right: #f2e8d5;
  --danger: #ff6a00;
  --panel: rgba(10, 8, 6, 0.66);
  --line: rgba(168, 118, 12, 0.35);
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  background:
    radial-gradient(circle at 50% 35%, rgba(255, 176, 0, 0.12), transparent 45%),
    var(--bg);
  color: var(--ink);
  font-family:
    ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;
}

body {
  display: grid;
  place-items: center;
  padding: 12px;
}

button {
  font: inherit;
}

.shell {
  position: relative;
  width: min(calc(100vw - 24px), calc((100vh - 24px) * 16 / 9));
  height: min(calc(100vh - 24px), calc((100vw - 24px) * 9 / 16));
  min-width: 320px;
  max-width: 100vw;
  max-height: 100vh;
  aspect-ratio: 16 / 9;
  overflow: hidden;
  border: 1px solid rgba(255, 176, 0, 0.25);
  border-radius: 8px;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.38);
}

#game {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  cursor: crosshair;
  touch-action: none;
}

.hud {
  position: absolute;
  top: max(14px, env(safe-area-inset-top));
  left: max(14px, env(safe-area-inset-left));
  right: max(14px, env(safe-area-inset-right));
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: start;
  gap: 12px;
  pointer-events: none;
}

.player,
.title,
.toast {
  border: 1px solid var(--line);
  background: var(--panel);
  box-shadow: 0 12px 36px rgba(0, 0, 0, 0.26);
  backdrop-filter: blur(14px);
}

.player {
  display: flex;
  align-items: center;
  gap: 10px;
  width: fit-content;
  min-width: 112px;
  min-height: 44px;
  padding: 8px 12px;
  border-radius: 8px;
}

.player-left {
  color: var(--left);
}

.player-right {
  justify-self: end;
  color: var(--right);
}

.player strong {
  font-size: 30px;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.15em;
  text-transform: uppercase;
}

.title {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  padding: 8px 10px 8px 14px;
  border-radius: 8px;
  color: var(--ink);
  font-size: 14px;
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: 0.15em;
}

#pauseButton {
  min-width: 72px;
  min-height: 30px;
  touch-action: manipulation;
  border: 1px solid rgba(255, 176, 0, 0.35);
  border-radius: 6px;
  background: rgba(255, 176, 0, 0.08);
  color: var(--ink);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.15em;
  pointer-events: auto;
}

#pauseButton:hover {
  background: rgba(255, 176, 0, 0.16);
}

.toast {
  position: absolute;
  left: 50%;
  bottom: max(18px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  max-width: min(560px, calc(100% - 28px));
  padding: 10px 14px;
  border-radius: 8px;
  color: var(--ink);
  font-size: 14px;
  font-weight: 750;
  text-align: center;
}

.toast.hidden {
  opacity: 0;
  transform: translate(-50%, 8px);
  transition:
    opacity 180ms ease,
    transform 180ms ease;
}

@supports (height: 100dvh) {
  .shell {
    width: min(calc(100dvw - 24px), calc((100dvh - 24px) * 16 / 9));
    height: min(calc(100dvh - 24px), calc((100dvw - 24px) * 9 / 16));
  }
}

/* Small viewports (phones, compact iframes): fill the whole stage, drop the
   forced 16:9 letterbox so the playfield stays usable in portrait. */
@media (max-width: 700px), (max-height: 460px) {
  body {
    padding: 0;
  }

  .shell {
    width: 100%;
    height: 100%;
    min-width: 0;
    aspect-ratio: auto;
    border: none;
    border-radius: 0;
    box-shadow: none;
  }
}

@media (max-width: 680px) {
  .hud {
    grid-template-columns: 1fr 1fr;
  }

  .title {
    grid-column: 1 / -1;
    grid-row: 2;
    justify-self: center;
    order: 3;
  }

  .player {
    min-width: 92px;
    padding-inline: 10px;
  }

  .player strong {
    font-size: 24px;
  }

  .label {
    font-size: 11px;
  }
}
