:root {
  color-scheme: dark;
  --bg: #0b0e14;
  --panel: #151a24;
  --panel-2: #1d2430;
  --grid: #202838;
  --text: #f6f7fb;
  --muted: #aab2c0;
  --accent: #34d399;
  --danger: #fb7185;
  --shadow: rgba(0, 0, 0, 0.35);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  background:
    radial-gradient(circle at 25% 20%, rgba(52, 211, 153, 0.14), transparent 28rem),
    linear-gradient(135deg, #0b0e14 0%, #101522 52%, #141018 100%);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button {
  border: 0;
  color: var(--text);
  font: inherit;
  cursor: pointer;
  touch-action: manipulation;
}

.app {
  width: min(100%, 860px);
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0 auto;
  padding: 24px;
  display: grid;
  align-content: center;
  gap: 18px;
}

.game-area {
  display: grid;
  grid-template-columns: minmax(260px, 360px) minmax(180px, 240px);
  justify-content: center;
  gap: 18px;
}

.board-wrap {
  position: relative;
  width: min(100%, 360px);
  aspect-ratio: 1 / 2;
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: #090c12;
  box-shadow: 0 24px 70px var(--shadow);
  overflow: hidden;
}

#board {
  display: block;
  width: 100%;
  height: 100%;
}

.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 18px;
  background: rgba(7, 10, 16, 0.72);
  backdrop-filter: blur(3px);
}

.overlay.hidden {
  display: none;
}

.overlay h1 {
  margin: 0;
  font-size: clamp(2.4rem, 8vw, 4.8rem);
  line-height: 1;
}

.panel {
  display: grid;
  gap: 12px;
  align-content: start;
  padding: 16px;
  background: rgba(21, 26, 36, 0.9);
  border: 1px solid rgba(255, 255, 255, 0.09);
  box-shadow: 0 18px 60px var(--shadow);
}

.stat,
.next {
  display: grid;
  gap: 6px;
  padding: 12px;
  background: var(--panel-2);
  border-radius: 8px;
}

.stat span,
.next span,
.keys span {
  color: var(--muted);
  font-size: 0.82rem;
}

.stat strong {
  font-size: 1.7rem;
  line-height: 1;
}

#next {
  width: 120px;
  height: 120px;
  justify-self: center;
}

.primary,
.secondary {
  min-height: 44px;
  border-radius: 8px;
  font-weight: 750;
}

.primary {
  padding: 0 26px;
  background: var(--accent);
  color: #06100c;
}

.secondary {
  width: 100%;
  background: #2f394a;
}

.secondary.paused {
  background: var(--danger);
}

.keys {
  display: grid;
  gap: 4px;
  padding-top: 4px;
}

.touch-controls {
  display: none;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
}

.touch-controls button {
  min-height: 48px;
  border-radius: 8px;
  background: #263044;
  font-weight: 800;
}

@media (max-width: 680px) {
  .app {
    min-height: 100dvh;
    padding: 10px;
    align-content: start;
    grid-template-rows: minmax(0, 1fr) auto;
    gap: 10px;
  }

  .game-area {
    min-height: 0;
    grid-template-columns: minmax(0, 1fr) minmax(92px, 112px);
    align-items: start;
    justify-content: center;
    gap: 8px;
  }

  .panel {
    width: 100%;
    gap: 8px;
    padding: 8px;
  }

  .board-wrap {
    width: min(100%, calc((100dvh - 88px) / 2));
    max-height: calc(100dvh - 88px);
    justify-self: end;
  }

  .stat,
  .next {
    gap: 4px;
    padding: 8px;
  }

  .stat span,
  .next span {
    font-size: 0.72rem;
  }

  .stat strong {
    font-size: 1.12rem;
  }

  #next {
    width: 76px;
    height: 76px;
  }

  .keys {
    display: none;
  }

  .secondary {
    min-height: 40px;
    font-size: 0.9rem;
  }

  .touch-controls {
    display: grid;
    position: sticky;
    bottom: max(10px, env(safe-area-inset-bottom));
    padding-bottom: env(safe-area-inset-bottom);
  }

  .touch-controls button {
    min-height: 54px;
    font-size: 1rem;
  }
}

@media (max-width: 360px) {
  .app {
    padding: 8px;
  }

  .game-area {
    grid-template-columns: minmax(0, 1fr) 86px;
    gap: 6px;
  }

  .panel {
    gap: 6px;
    padding: 6px;
  }

  .stat,
  .next {
    padding: 6px;
  }

  #next {
    width: 68px;
    height: 68px;
  }

  .touch-controls {
    gap: 6px;
  }

  .touch-controls button {
    min-height: 50px;
    font-size: 0.94rem;
  }
}
