:root {
  color-scheme: dark;
  --bg: #0b0e1a;
  --panel: #151a2e;
  --panel-light: #1d2440;
  --text: #f5f7ff;
  --muted: #9da6c7;
  --accent: #7c5cff;
  --accent-light: #9c87ff;
  --border: rgba(255, 255, 255, 0.1);
  --shadow: 0 24px 70px rgba(0, 0, 0, 0.35);
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--bg);
}

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  color: var(--text);
  background:
    radial-gradient(circle at 15% 15%, rgba(124, 92, 255, 0.22), transparent 30rem),
    radial-gradient(circle at 85% 80%, rgba(0, 210, 255, 0.12), transparent 28rem),
    var(--bg);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button {
  color: inherit;
  font: inherit;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.game-shell {
  width: min(100% - 28px, 820px);
  margin: 0 auto;
  padding: 28px 0 36px;
}

.game-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 18px;
}

.eyebrow {
  margin: 0 0 2px;
  color: var(--accent-light);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: clamp(2rem, 6vw, 3.4rem);
  line-height: 1;
  letter-spacing: -0.05em;
}

.game-layout {
  display: grid;
  grid-template-columns: minmax(260px, 360px) minmax(230px, 1fr);
  gap: 20px;
  align-items: start;
}

.board-wrap {
  position: relative;
  width: 100%;
  max-width: 360px;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 18px;
  background: #080b14;
  box-shadow: var(--shadow);
}

#gameCanvas {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 1 / 2;
}

.sidebar {
  display: grid;
  gap: 14px;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}

.stat-card,
.next-card,
.keyboard-help {
  border: 1px solid var(--border);
  border-radius: 16px;
  background: rgba(21, 26, 46, 0.9);
  box-shadow: 0 14px 35px rgba(0, 0, 0, 0.18);
}

.stat-card {
  padding: 14px;
}

.stat-card span,
.next-card > span {
  display: block;
  margin-bottom: 5px;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.stat-card strong {
  font-size: 1.55rem;
  font-variant-numeric: tabular-nums;
}

.next-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 138px;
  padding: 12px 14px;
}

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

.keyboard-help {
  padding: 16px;
}

.keyboard-help h2 {
  margin: 0 0 10px;
  font-size: 0.9rem;
}

.keyboard-help p {
  margin: 7px 0;
  color: var(--muted);
  font-size: 0.83rem;
}

kbd {
  display: inline-block;
  min-width: 25px;
  margin-right: 4px;
  padding: 3px 6px;
  border: 1px solid var(--border);
  border-bottom-width: 2px;
  border-radius: 5px;
  color: var(--text);
  background: var(--panel-light);
  font-family: inherit;
  font-size: 0.72rem;
  text-align: center;
}

.primary-button,
.secondary-button,
.touch-controls button {
  border: 1px solid var(--border);
  border-radius: 11px;
  font-weight: 800;
  cursor: pointer;
}

.primary-button {
  padding: 11px 18px;
  border-color: transparent;
  background: var(--accent);
}

.secondary-button {
  padding: 10px 15px;
  background: var(--panel-light);
}

button:focus-visible {
  outline: 3px solid rgba(156, 135, 255, 0.7);
  outline-offset: 3px;
}

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

.game-overlay {
  position: absolute;
  inset: 0;
  display: none;
  place-items: center;
  padding: 22px;
  background: rgba(5, 7, 13, 0.78);
  backdrop-filter: blur(4px);
}

.game-overlay.visible {
  display: grid;
}

.overlay-card {
  width: 100%;
  padding: 24px 18px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: rgba(21, 26, 46, 0.96);
  text-align: center;
}

.overlay-label {
  margin: 0 0 6px;
  color: var(--accent-light);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.overlay-card h2 {
  margin: 0;
  font-size: 2rem;
}

.overlay-card p:not(.overlay-label) {
  margin: 10px 0 18px;
  color: var(--muted);
  font-size: 0.85rem;
}

.touch-controls {
  display: none;
  grid-template-columns: repeat(4, 1fr);
  gap: 9px;
  margin-top: 18px;
}

.touch-controls button {
  min-height: 52px;
  background: var(--panel-light);
  font-size: 1.35rem;
  user-select: none;
}

.touch-controls .wide-control {
  grid-column: span 2;
  font-size: 0.86rem;
  text-transform: uppercase;
}

@media (hover: none), (pointer: coarse) {
  .touch-controls {
    display: grid;
  }
}

@media (max-width: 640px) {
  .game-shell {
    width: min(100% - 20px, 440px);
    padding-top: 18px;
  }

  .touch-controls {
    display: grid;
  }

  .game-layout {
    grid-template-columns: minmax(0, 1fr);
  }

  .board-wrap {
    width: min(100%, calc((100vh - 310px) / 2));
    min-width: 240px;
    margin: 0 auto;
  }

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

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

  .stat-card {
    padding: 10px 7px;
    text-align: center;
  }

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

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

  .next-card {
    min-height: 112px;
  }

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

  .keyboard-help {
    display: none;
  }
}

@media (max-width: 380px) {
  .game-header {
    margin-bottom: 12px;
  }

  .board-wrap {
    min-width: 220px;
  }
}
