:root {
  color-scheme: dark;
  --bg: #0f172a;
  --panel: #182235;
  --panel-2: #202b41;
  --ink: #f8fafc;
  --muted: #a9b4c6;
  --line: #35435b;
  --cyan: #24d7e8;
  --green: #58d68d;
  --yellow: #ffd166;
  --red: #ff6b6b;
  --purple: #b48cff;
  --radius: 8px;
  --shadow: 0 22px 60px rgb(0 0 0 / .32);
  font-family: "Microsoft YaHei", "PingFang SC", "Noto Sans CJK SC", Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

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

body {
  color: var(--ink);
  background:
    linear-gradient(135deg, rgb(15 23 42), rgb(20 32 49) 42%, rgb(21 26 39));
}

button {
  border: 0;
  color: inherit;
  font: inherit;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.app {
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.game-shell {
  width: min(100%, 980px);
  background: rgb(24 34 53 / .92);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
}

.topbar,
.play-layout,
.metric-grid,
.actions,
.touch-controls {
  display: grid;
  gap: 14px;
}

.topbar {
  grid-template-columns: 1fr auto;
  align-items: end;
  margin-bottom: 16px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--cyan);
  font-size: 13px;
  line-height: 1.2;
}

h1 {
  margin: 0;
  font-size: clamp(30px, 5vw, 52px);
  line-height: 1;
  letter-spacing: 0;
}

.status-pill {
  min-width: 92px;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel-2);
  color: var(--muted);
  text-align: center;
  white-space: nowrap;
}

.play-layout {
  grid-template-columns: minmax(280px, 360px) minmax(260px, 1fr);
  align-items: start;
}

.board-panel {
  position: relative;
  width: min(100%, 360px);
  aspect-ratio: 1 / 2;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #0a1020;
  overflow: hidden;
}

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

.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  gap: 8px;
  text-align: center;
  background: rgb(10 16 32 / .68);
  transition: opacity .18s ease;
}

.overlay.hidden {
  opacity: 0;
  pointer-events: none;
}

.overlay strong {
  font-size: 28px;
}

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

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

.metric-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.metric,
.next-box,
.keys {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel-2);
}

.metric {
  min-height: 92px;
  display: grid;
  align-content: center;
  gap: 7px;
  padding: 14px;
}

.metric span,
.next-box span {
  color: var(--muted);
  font-size: 14px;
}

.metric strong {
  font-size: 30px;
  line-height: 1;
}

.next-box {
  display: grid;
  gap: 10px;
  justify-items: center;
  padding: 14px;
}

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

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

.actions button,
.touch-controls button {
  min-height: 46px;
  border-radius: var(--radius);
  background: #334155;
  color: var(--ink);
  transition: transform .12s ease, background .12s ease;
}

.actions button:hover,
.touch-controls button:hover {
  background: #41516b;
}

.actions button:active,
.touch-controls button:active {
  transform: translateY(1px);
}

.actions .primary {
  background: #0f9fb1;
}

.actions .primary:hover {
  background: #13b5c9;
}

.keys {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 12px;
  color: var(--muted);
}

.keys span {
  padding: 6px 9px;
  border-radius: 6px;
  background: rgb(15 23 42 / .82);
}

.touch-controls {
  grid-template-columns: repeat(5, 1fr);
  margin-top: 14px;
}

.touch-controls button {
  font-size: 20px;
  user-select: none;
}

.touch-controls .wide {
  font-size: 16px;
}

@media (max-width: 760px) {
  .app {
    padding: 12px;
    align-items: start;
  }

  .game-shell {
    padding: 14px;
  }

  .topbar {
    grid-template-columns: 1fr;
    align-items: start;
  }

  .status-pill {
    justify-self: start;
  }

  .play-layout {
    grid-template-columns: 1fr;
  }

  .board-panel {
    justify-self: center;
    width: min(100%, 330px);
  }

  .metric-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .metric {
    min-height: 74px;
    padding: 10px;
  }

  .metric strong {
    font-size: 22px;
  }

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

@media (max-width: 460px) {
  .metric-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

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

  .touch-controls {
    grid-template-columns: repeat(4, 1fr);
  }

  .touch-controls .wide {
    grid-column: span 4;
  }
}
