:root {
  color-scheme: dark;
  --bg: #130d24;
  --bg-deep: #0c0717;
  --panel: rgba(33, 20, 52, 0.9);
  --panel-soft: rgba(51, 29, 72, 0.72);
  --line: #633b78;
  --line-soft: rgba(255, 220, 160, 0.16);
  --text: #fff5e8;
  --muted: #d4b8c9;
  --gold: #ffd166;
  --orange: #ff8a3d;
  --coral: #ff5d8f;
  --mint: #8ef0d2;
  --mint-deep: #38c9a4;
}

* { box-sizing: border-box; }

html { min-height: 100%; background: var(--bg-deep); }

body {
  min-height: 100vh;
  min-height: 100svh;
  min-height: 100dvh;
  margin: 0;
  display: grid;
  place-items: center;
  padding: max(10px, env(safe-area-inset-top)) max(10px, env(safe-area-inset-right)) max(10px, env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left));
  overflow: hidden;
  overscroll-behavior: none;
  background:
    radial-gradient(circle at 50% -12%, rgba(255, 138, 61, 0.25), transparent 38%),
    radial-gradient(circle at 5% 92%, rgba(142, 240, 210, 0.12), transparent 28%),
    linear-gradient(145deg, var(--bg-deep), var(--bg));
  color: var(--text);
  font: 16px/1.4 Inter, ui-sans-serif, system-ui, sans-serif;
}

body::before {
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  content: "";
  opacity: 0.24;
  background-image: linear-gradient(rgba(255, 255, 255, 0.035) 1px, transparent 1px), linear-gradient(90deg, rgba(255, 255, 255, 0.035) 1px, transparent 1px);
  background-size: 34px 34px;
  mask-image: linear-gradient(to bottom, black, transparent 82%);
}

.game-shell {
  position: relative;
  width: min(100%, 680px);
  max-height: calc(100dvh - 20px);
  overflow: visible;
  padding: clamp(16px, 4vw, 36px);
  border: 1px solid var(--line);
  border-radius: 30px;
  background: linear-gradient(145deg, rgba(49, 28, 67, 0.92), var(--panel));
  box-shadow: 0 28px 90px rgba(4, 1, 12, 0.52), 0 0 0 1px rgba(255, 209, 102, 0.04) inset;
  backdrop-filter: blur(16px);
}

.game-shell::before {
  position: absolute;
  top: -1px;
  left: 12%;
  right: 12%;
  height: 2px;
  content: "";
  border-radius: 999px;
  background: linear-gradient(90deg, transparent, var(--gold), var(--coral), transparent);
  box-shadow: 0 0 18px rgba(255, 138, 61, 0.7);
}

.game-header, .actions, .scoreboard, .controls > div {
  display: flex;
  align-items: center;
}

.game-header { justify-content: space-between; gap: 16px; margin-bottom: 18px; }
.eyebrow { margin: 0 0 5px; color: var(--gold); font-size: 11px; font-weight: 900; letter-spacing: .2em; }
h1 { margin: 0; color: var(--text); font-size: clamp(40px, 8vw, 64px); line-height: .9; letter-spacing: -.07em; text-shadow: 0 5px 22px rgba(255, 138, 61, 0.18); }
.tagline { margin: 9px 0 0; color: var(--muted); font-size: 13px; }
.scoreboard { gap: 8px; }
.scoreboard span { min-width: 64px; padding: 8px 9px 7px; border: 1px solid var(--line-soft); border-radius: 13px; background: rgba(12, 7, 23, 0.35); text-align: right; }
.scoreboard small { display: block; color: var(--muted); font-size: 10px; font-weight: 800; letter-spacing: .12em; text-transform: uppercase; }
.scoreboard strong { display: block; margin-top: 1px; color: var(--gold); font-size: 24px; line-height: 1; }
.text-button { min-height: 32px; padding: 5px 7px; border-color: transparent; background: transparent; color: var(--muted); font-size: 11px; }
.text-button:hover { border-color: var(--line-soft); background: rgba(255, 255, 255, .05); color: var(--gold); box-shadow: none; }

.play-panel {
  display: flex;
  flex-direction: column;
  width: 100%;
  min-width: 0;
  overflow: visible;
  padding: clamp(10px, 2vw, 16px);
  border: 1px solid var(--line-soft);
  border-radius: 24px;
  background: rgba(12, 7, 23, .32);
  box-shadow: 0 12px 30px rgba(7, 2, 16, .2) inset;
}

.board-wrap {
  position: relative;
  overflow: hidden;
  width: min(100%, 600px, calc(100dvh - 455px));
  max-width: 600px;
  margin-inline: auto;
  aspect-ratio: 1;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: #160d26;
  box-shadow: 0 0 0 5px rgba(255, 209, 102, 0.025), 0 18px 45px rgba(7, 2, 16, 0.45), 0 0 30px rgba(142, 240, 210, 0.07) inset;
  touch-action: none;
}

.board-wrap::after {
  position: absolute;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  content: "";
  background: linear-gradient(to bottom, transparent 50%, rgba(255, 255, 255, 0.025) 50%);
  background-size: 100% 6px;
  mix-blend-mode: screen;
  opacity: .35;
}

canvas { display: block; width: 100%; height: 100%; }
.status {
  position: absolute;
  z-index: 2;
  top: 12px;
  right: 12px;
  left: 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  min-height: 48px;
  padding: 10px 14px;
  border: 1px solid var(--line-soft);
  border-radius: 14px;
  background: rgba(12, 7, 23, .76);
  color: var(--muted);
  font-size: 14px;
  font-weight: 800;
  letter-spacing: .02em;
  pointer-events: none;
  text-align: center;
  text-shadow: 0 2px 12px rgba(12, 7, 23, 0.8);
  backdrop-filter: blur(8px);
  transition: opacity .18s ease, transform .18s ease;
}
.status.playing { opacity: 0; transform: translateY(-8px); }
.status.game-over { color: var(--coral); }
.status-action { pointer-events: auto; border-color: var(--orange); background: linear-gradient(135deg, var(--orange), var(--coral)); color: #29101b; box-shadow: 0 8px 22px rgba(255, 93, 143, 0.2); }

.control-dock {
  display: grid;
  justify-items: center;
  gap: 6px;
  width: min(100%, 300px);
  margin: 12px auto 0;
  padding: 10px 12px 12px;
  border: 1px solid var(--line-soft);
  border-radius: 18px;
  background: rgba(33, 20, 52, .66);
}
.control-label { margin: 0; color: var(--muted); font-size: 10px; font-weight: 900; letter-spacing: .18em; text-transform: uppercase; }

.actions { flex-wrap: wrap; gap: 8px; margin: 18px 0 10px; }
button {
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 13px;
  padding: 10px 14px;
  background: var(--panel-soft);
  color: var(--text);
  font: inherit;
  font-weight: 800;
  cursor: pointer;
  touch-action: manipulation;
  transition: transform .15s ease, border-color .15s ease, background .15s ease, box-shadow .15s ease;
}
button:hover { border-color: var(--gold); background: rgba(91, 48, 103, 0.86); box-shadow: 0 6px 18px rgba(255, 138, 61, 0.12); }
button:active { transform: translateY(1px) scale(.99); }
button:focus-visible { outline: 3px solid rgba(255, 209, 102, .45); outline-offset: 3px; }
button.primary { border-color: var(--orange); background: linear-gradient(135deg, var(--orange), var(--coral)); color: #29101b; box-shadow: 0 8px 22px rgba(255, 93, 143, 0.2); }
.notice { min-height: 19px; margin: 0 0 3px; color: var(--gold); font-size: 12px; text-align: center; }
.notice[hidden] { display: block; visibility: hidden; }

.controls { display: grid; justify-items: center; gap: 7px; width: max-content; max-width: 100%; }
.controls button { width: clamp(50px, 14vw, 64px); height: clamp(48px, 12vw, 58px); flex: 0 0 auto; padding: 0; border-color: rgba(142, 240, 210, 0.35); color: var(--mint); background: rgba(20, 45, 50, 0.5); font-size: 18px; -webkit-user-select: none; user-select: none; }
.controls button:hover, .controls button:active { border-color: var(--mint); background: rgba(43, 107, 101, 0.5); box-shadow: 0 0 20px rgba(56, 201, 164, 0.16); }
.controls > div { width: max-content; gap: 7px; }
.hint { margin: 16px 0 0; color: var(--muted); text-align: center; font-size: 12px; }

:fullscreen { background: var(--bg-deep); }
:fullscreen .game-shell { width: min(100%, 760px); max-height: 100dvh; border-radius: 0; }
:-webkit-full-screen { background: var(--bg-deep); }
:-webkit-full-screen .game-shell { width: min(100%, 760px); max-height: 100dvh; border-radius: 0; }

@media (orientation: landscape) and (max-height: 900px) and (min-width: 700px) {
  .game-shell { width: min(100%, 820px); padding: 14px; }
  .game-header { margin-bottom: 10px; }
  .play-panel { display: grid; grid-template-columns: minmax(0, 1fr) 180px; align-items: center; gap: 14px; }
  .board-wrap { width: min(100%, calc(100dvh - 180px)); }
  .control-dock { width: 100%; margin: 0; padding-inline: 4px; }
  .controls button { width: 48px; height: 48px; }
  .actions { margin: 12px 0 8px; }
  .hint { margin-top: 0; }
}

@media (max-width: 460px) {
  body { padding: max(8px, env(safe-area-inset-top)) max(8px, env(safe-area-inset-right)) max(8px, env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left)); }
  .game-shell { border-radius: 22px; padding: 16px; }
  .game-header { align-items: flex-end; gap: 9px; }
  .scoreboard { gap: 4px; }
  .scoreboard span { min-width: 55px; padding-inline: 7px; }
  .scoreboard strong { font-size: 21px; }
  .text-button { padding-inline: 4px; }
  .play-panel { padding: 10px; border-radius: 20px; }
  .board-wrap { width: min(100%, calc(100dvh - 420px)); }
  .control-dock { width: min(100%, 280px); margin-top: 10px; }
  .actions { flex-wrap: nowrap; gap: 5px; }
  .actions button { min-width: 0; flex: 1 1 auto; padding-inline: 5px; font-size: 12px; }
  .hint { margin-top: 13px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: .01ms !important; }
}
