:root {
  color-scheme: dark;
  --bg: #16191a;
  --panel: #24282a;
  --panel-strong: #303639;
  --text: #f4f0e7;
  --muted: #b9c0bb;
  --accent: #46d6a1;
  --accent-2: #ffcf5a;
  --danger: #ff6b5f;
  --steel: #7ba0ad;
}

* {
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0;
  color: var(--text);
  background:
    linear-gradient(135deg, rgba(70, 214, 161, 0.14), transparent 36%),
    radial-gradient(circle at 88% 12%, rgba(255, 207, 90, 0.12), transparent 28%),
    var(--bg);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
select,
input {
  font: inherit;
}

.shell {
  width: min(1180px, calc(100vw - 28px));
  min-height: 100vh;
  height: 100dvh;
  margin: 0 auto;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 290px;
  gap: 18px;
  align-items: stretch;
  padding: 24px 0;
}

.game-wrap,
.panel {
  background: rgba(36, 40, 42, 0.92);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.3);
}

.game-wrap {
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 20px;
  background: linear-gradient(90deg, rgba(48, 54, 57, 0.98), rgba(36, 40, 42, 0.98));
}

.kicker {
  margin: 0 0 4px;
  color: var(--accent);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(2rem, 4vw, 4rem);
  line-height: 0.95;
}

.stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(70px, 1fr));
  gap: 8px;
}

.stats span {
  min-width: 76px;
  padding: 9px 10px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 6px;
  text-align: center;
}

.stats strong {
  display: block;
  font-size: 1.35rem;
}

.stats small {
  color: var(--muted);
}

.stage-shell {
  position: relative;
  flex: 1 1 auto;
  min-height: 280px;
  width: 100%;
  display: grid;
  place-items: center;
  background: #111516;
}

.playfield {
  position: relative;
  width: 100%;
  height: auto;
  aspect-ratio: 720 / 520;
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  gap: 12px;
  padding: 28px;
  text-align: center;
  background: rgba(13, 16, 17, 0.76);
}

.overlay.hidden {
  display: none;
}

.overlay h2 {
  margin-bottom: 0;
  font-size: clamp(2.2rem, 5vw, 4.8rem);
}

.overlay p {
  max-width: 520px;
  color: var(--muted);
}

button,
select {
  min-height: 44px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 6px;
  color: var(--text);
  background: var(--panel-strong);
}

button {
  cursor: pointer;
  font-weight: 800;
  touch-action: manipulation;
  user-select: none;
}

button:hover {
  border-color: var(--accent);
}

#start {
  justify-self: center;
  min-width: 150px;
  background: var(--accent);
  color: #10221c;
}

.controls {
  flex: 0 0 auto;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  padding: 14px;
  background: #1d2223;
}

.controls button {
  height: 52px;
  font-size: 1.08rem;
}

.panel {
  padding: 18px;
}

.panel h2 {
  margin-bottom: 18px;
}

.panel label {
  display: grid;
  gap: 7px;
  margin-bottom: 16px;
  color: var(--muted);
  font-weight: 700;
}

.panel select {
  width: 100%;
  padding: 0 12px;
}

.toggle {
  grid-template-columns: 22px 1fr;
  align-items: center;
  color: var(--text);
}

.toggle input {
  width: 18px;
  height: 18px;
}

#reset {
  width: 100%;
}

.hint {
  margin: 14px 0 0;
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.45;
}

@media (max-width: 900px) {
  .shell {
    height: auto;
    min-height: 100dvh;
    grid-template-columns: 1fr;
    align-items: start;
  }

  .game-wrap {
    min-height: min(72dvh, 720px);
  }

  .panel {
    order: -1;
  }
}

@media (max-width: 620px) {
  .shell {
    width: min(100vw - 16px, 540px);
    padding: 8px 0;
  }

  .game-wrap {
    min-height: calc(100dvh - 260px);
  }

  .controls {
    gap: 8px;
    padding: 10px;
  }

  .controls button {
    min-height: 58px;
    font-size: 1.2rem;
  }

  .topbar {
    align-items: stretch;
    flex-direction: column;
    padding: 14px;
  }

  .stats {
    grid-template-columns: repeat(3, 1fr);
  }

  .stats span {
    min-width: 0;
    padding: 8px 6px;
  }
}
