:root {
  color-scheme: dark;
  --bg: #161a2a;
  --panel: rgba(255, 255, 255, 0.09);
  --line: rgba(255, 255, 255, 0.16);
  --text: #f8f4df;
  --muted: #c6bdd4;
  --accent: #ffcf5a;
  --danger: #ff6b7a;
}

* { box-sizing: border-box; }

html, body {
  width: 100%;
  min-height: 100%;
  margin: 0;
  overscroll-behavior: none;
  touch-action: manipulation;
}

body {
  font-family: ui-rounded, "Hiragino Maru Gothic ProN", "Yu Gothic", system-ui, sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at 20% 10%, rgba(255, 207, 90, 0.24), transparent 30%),
    radial-gradient(circle at 85% 25%, rgba(108, 155, 255, 0.24), transparent 28%),
    linear-gradient(145deg, #111524, #252038 60%, #19192a);
}

.app {
  width: min(96vw, 560px);
  min-height: 100svh;
  margin: 0 auto;
  display: grid;
  grid-template-rows: auto 1fr auto auto;
  gap: 12px;
  padding: max(10px, env(safe-area-inset-top)) 12px max(12px, env(safe-area-inset-bottom));
}

.hud, .controls {
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  align-items: center;
  gap: 10px;
}

.hud > div, .controls button {
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: 18px;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.22);
}

.hud > div {
  min-height: 74px;
  padding: 12px 14px;
}

.label {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 12px;
  letter-spacing: 0.16em;
}

strong {
  font-size: clamp(22px, 5vw, 34px);
  line-height: 1;
}

.next-wrap {
  display: grid;
  place-items: center;
  min-width: 96px;
}

.next-wrap .label { justify-self: start; }

#nextCanvas {
  width: 54px;
  height: 54px;
}

.board-wrap {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 0;
}

#game {
  width: min(100%, calc((100svh - 190px) * 0.617));
  max-width: 420px;
  height: auto;
  max-height: calc(100svh - 190px);
  aspect-ratio: 420 / 680;
  border-radius: 24px;
  border: 2px solid rgba(255, 255, 255, 0.22);
  background: linear-gradient(#f8d994, #eeb86e 58%, #d9894d);
  box-shadow: inset 0 -12px 0 rgba(85, 43, 25, 0.12), 0 24px 60px rgba(0, 0, 0, 0.35);
  touch-action: none;
}

.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  gap: 12px;
  text-align: center;
  border-radius: 24px;
  background: rgba(13, 14, 24, 0.74);
  backdrop-filter: blur(5px);
}

.overlay.hidden { display: none; }

.overlay h1 {
  margin: 0;
  font-size: clamp(36px, 12vw, 68px);
  color: var(--danger);
  text-shadow: 0 5px 0 rgba(0, 0, 0, 0.18);
}

.overlay p { margin: 0; font-size: 22px; }

button {
  cursor: pointer;
  border: 0;
  color: #24180b;
  font-weight: 800;
  font-size: 18px;
  transition: transform 120ms ease, filter 120ms ease;
}

button:active { transform: translateY(2px) scale(0.98); }

.controls {
  grid-template-columns: 1fr 1fr;
}

.controls button, #restartButton {
  min-height: 52px;
  padding: 12px 18px;
  background: linear-gradient(#ffe37c, #ffb83f);
}

#resetButton {
  color: var(--text);
  background: rgba(255, 255, 255, 0.13);
}

.hint {
  margin: 0;
  color: var(--muted);
  text-align: center;
  font-size: 13px;
}

@media (max-width: 430px) {
  .app { gap: 8px; padding-inline: 8px; }
  .hud { grid-template-columns: 1fr 1fr 78px; gap: 6px; }
  .hud > div { min-height: 62px; padding: 9px 10px; border-radius: 14px; }
  .label { font-size: 10px; }
  .hint { font-size: 11px; }
}
