:root {
  --bg: #101820;
  --panel: #1a2530;
  --panel-2: #223344;
  --text: #f2f7ff;
  --muted: #9fb3c8;
  --shadow: rgba(0, 0, 0, 0.35);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  overscroll-behavior: none;
}

body {
  font-family: "Trebuchet MS", "Avenir Next", "Segoe UI", sans-serif;
  background:
    radial-gradient(circle at 20% 10%, #23405a 0%, transparent 35%),
    radial-gradient(circle at 80% 90%, #27394d 0%, transparent 30%),
    linear-gradient(180deg, #0c1218 0%, var(--bg) 100%);
  color: var(--text);
  overflow: hidden;
  touch-action: manipulation;
}

.page {
  width: min(980px, 100%);
  height: 100vh;
  height: 100dvh;
  margin: 0 auto;
  padding: max(8px, env(safe-area-inset-top)) 10px max(8px, env(safe-area-inset-bottom));
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto auto;
  gap: 8px;
}

.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 0;
}

.top-bar h1 {
  margin: 0;
  font-size: 1.2rem;
  letter-spacing: 0.04em;
}

.home-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  min-width: 44px;
  min-height: 44px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.1);
  color: inherit;
  text-decoration: none;
  font-weight: 700;
  font-size: 0.92rem;
}

.home-btn:active {
  transform: scale(0.96);
  background: rgba(255, 255, 255, 0.15);
}

.home-btn .icon {
  font-size: 1.1rem;
  line-height: 1;
}

.game-layout {
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(108px, 0.78fr);
  gap: 8px;
  padding: 8px;
  border-radius: 12px;
  background: rgba(8, 12, 18, 0.72);
  border: 1px solid rgba(255, 255, 255, 0.12);
  box-shadow: 0 10px 22px var(--shadow);
}

.board-wrap {
  min-height: 0;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

#game-canvas {
  width: auto;
  max-width: 100%;
  max-height: 58dvh;
  aspect-ratio: 1 / 2;
  display: block;
  margin: 0 auto;
  background: #0c1117;
  border-radius: 8px;
  image-rendering: pixelated;
  touch-action: none;
}

.panel {
  min-height: 0;
  background: transparent;
  border: 0;
  padding: 0;
  display: grid;
  grid-template-rows: auto auto auto;
  gap: 6px;
}

.stats-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 6px;
}

.stat-card {
  border-radius: 8px;
  padding: 7px;
  background: rgba(34, 51, 68, 0.92);
}

.next-area {
  border-radius: 8px;
  padding: 7px;
  background: rgba(34, 51, 68, 0.92);
}

.stat-label {
  color: var(--muted);
  font-size: 0.66rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.stat-value {
  margin-top: 2px;
  font-size: 1rem;
  font-weight: 700;
}

.next-area h2 {
  margin: 0 0 6px;
  font-size: 0.82rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.next-list {
  display: flex;
  gap: 6px;
}

.next-canvas {
  flex: 1;
  min-width: 0;
  background: #101722;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 8px;
}

.button-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
}

button {
  border: 0;
  border-radius: 10px;
  min-width: 44px;
  min-height: 44px;
  padding: 10px 8px;
  font-size: 0.9rem;
  font-weight: 600;
  background: #2d3f53;
  color: var(--text);
  touch-action: manipulation;
}

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

#pause-btn {
  background: #3c5c7a;
}

.touch-btn[data-action="hard"] {
  background: #22536f;
}

.help-text {
  color: var(--muted);
  font-size: 0.74rem;
  margin: 0 2px;
}

@media (max-width: 420px) {
  .game-layout {
    grid-template-columns: minmax(0, 1fr) minmax(108px, 0.72fr);
  }

  .stat-value {
    font-size: 0.92rem;
  }

  .next-canvas {
    max-width: 72px;
  }
}

@media (min-width: 860px) {
  .page {
    padding: max(12px, env(safe-area-inset-top)) 16px max(12px, env(safe-area-inset-bottom));
    gap: 12px;
  }

  .top-bar h1 {
    font-size: 1.55rem;
  }

  .game-layout {
    grid-template-columns: minmax(320px, 380px) minmax(320px, 1fr);
    gap: 14px;
  }

  .help-text {
    font-size: 0.84rem;
  }
}
