:root {
  color-scheme: dark;
  --bg: #10131b;
  --panel: #1b2130;
  --panel-strong: #222a3c;
  --line: #3c465e;
  --text: #f5f7fb;
  --muted: #aab4c8;
  --accent: #50d6a3;
  --accent-2: #61b3ff;
  --danger: #ff6d75;
  --shadow: rgba(0, 0, 0, 0.28);
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  background:
    radial-gradient(circle at top left, rgba(80, 214, 163, 0.16), transparent 34rem),
    radial-gradient(circle at bottom right, rgba(97, 179, 255, 0.13), transparent 32rem),
    var(--bg);
  color: var(--text);
  font-family: "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
  overflow-x: hidden;
}

button {
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-strong);
  color: var(--text);
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 10px 24px var(--shadow);
}

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

button:active {
  transform: translateY(1px);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.game-shell {
  width: min(100%, 980px);
  min-height: 100svh;
  margin: 0 auto;
  padding: 20px;
  display: grid;
  gap: 16px;
  align-content: center;
}

.score-strip {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}

.stat-card,
.side-panel,
.controls,
.touch-pad {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(27, 33, 48, 0.84);
  box-shadow: 0 18px 34px var(--shadow);
}

.stat-card {
  min-height: 72px;
  padding: 12px 14px;
  display: grid;
  gap: 4px;
  align-content: center;
}

.stat-card span,
.preview-box span {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.08em;
}

.stat-card strong {
  font-size: clamp(1.45rem, 5vw, 2rem);
  line-height: 1;
}

.play-area {
  display: grid;
  grid-template-columns: minmax(126px, 160px) minmax(260px, 360px) minmax(126px, 160px);
  gap: 16px;
  align-items: start;
  justify-content: center;
}

.side-panel {
  padding: 14px;
  display: grid;
  gap: 12px;
}

.preview-box {
  display: grid;
  gap: 8px;
  justify-items: center;
}

.preview-box canvas {
  width: 120px;
  height: 120px;
  border-radius: 8px;
  background: #121722;
  border: 1px solid var(--line);
}

.mini-help {
  display: grid;
  gap: 8px;
  color: var(--muted);
  font-size: 0.88rem;
}

.board-wrap {
  position: relative;
  width: min(100%, 360px);
  aspect-ratio: 1 / 2;
  border-radius: 8px;
  border: 2px solid var(--line);
  background: #0c1018;
  overflow: hidden;
  box-shadow: 0 24px 48px var(--shadow);
}

#gameCanvas {
  width: 100%;
  height: 100%;
  display: block;
  image-rendering: crisp-edges;
}

.music-toggle {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 8;
  width: 42px;
  min-height: 42px;
  padding: 0;
  display: grid;
  place-items: center;
  border-color: rgba(170, 180, 200, 0.36);
  background: rgba(27, 33, 48, 0.78);
  color: var(--text);
  backdrop-filter: blur(6px);
}

.music-toggle svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.music-toggle .sound-off,
.music-toggle.is-muted .sound-on {
  display: none;
}

.music-toggle.is-muted .sound-off {
  display: block;
}

.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  gap: 8px;
  padding: 24px;
  text-align: center;
  background: rgba(10, 14, 22, 0.72);
  backdrop-filter: blur(3px);
}

.overlay.is-hidden {
  display: none;
}

.overlay strong {
  font-size: clamp(1.8rem, 7vw, 3.2rem);
}

.overlay span {
  color: var(--muted);
  font-weight: 700;
}

.overlay-start {
  width: min(180px, 58vw);
  margin: 12px auto 0;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #071018;
}

.controls,
.touch-pad {
  padding: 12px;
  display: grid;
  gap: 10px;
}

.controls {
  grid-template-columns: minmax(120px, 180px);
  justify-content: center;
}

.controls.is-hidden {
  display: none;
}

.controls button:first-child {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #071018;
}

.touch-pad {
  grid-template-columns: repeat(5, minmax(0, 1fr));
  display: none;
}

@media (max-width: 760px) {
  .game-shell {
    padding: 8px;
    padding-bottom: calc(82px + env(safe-area-inset-bottom));
    align-content: start;
  }

  .play-area {
    grid-template-columns: minmax(0, 1fr) minmax(220px, 320px) minmax(0, 1fr);
    gap: 10px;
  }

  .side-panel {
    padding: 10px;
  }

  .preview-box canvas {
    width: 82px;
    height: 82px;
  }

  .mini-help {
    display: none;
  }

  .touch-pad {
    display: grid;
    position: fixed;
    left: 8px;
    right: 8px;
    bottom: calc(8px + env(safe-area-inset-bottom));
    z-index: 20;
    max-width: 720px;
    margin: 0 auto;
    background: rgba(27, 33, 48, 0.94);
    backdrop-filter: blur(8px);
  }
}

@media (max-width: 560px) {
  .game-shell {
    gap: 6px;
  }

  .score-strip {
    gap: 8px;
  }

  .stat-card {
    min-height: 46px;
    padding: 7px 8px;
  }

  .stat-card span {
    font-size: 0.66rem;
  }

  .stat-card strong {
    font-size: 1.16rem;
  }

  .play-area {
    grid-template-columns: minmax(0, var(--mobile-board-width, calc(100vw - 16px)));
    grid-template-areas:
      "board";
    align-items: center;
    justify-items: center;
    gap: 8px;
  }

  .side-panel {
    display: none;
  }

  .left-panel {
    grid-area: hold;
  }

  .right-panel {
    grid-area: next;
  }

  .board-wrap {
    grid-area: board;
    justify-self: center;
    width: var(--mobile-board-width, calc(100vw - 16px));
  }

  .controls {
    grid-template-columns: minmax(110px, 160px);
    justify-content: center;
    padding: 6px;
    gap: 6px;
  }

  .controls button,
  .touch-pad button {
    min-height: 34px;
    font-size: 0.86rem;
    box-shadow: 0 6px 14px var(--shadow);
  }

  .touch-pad {
    padding: 7px;
    gap: 6px;
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  #dropButton {
    grid-column: span 2;
  }
}
