:root {
  color-scheme: light;
  --bg: #eef2f4;
  --panel: #ffffff;
  --text: #17202b;
  --muted: #667488;
  --line: #d8dee7;
  --board: #101820;
  --accent: #0f766e;
  --accent-dark: #0a5d57;
  --yellow: #f2b705;
  --shadow: 0 20px 52px rgba(23, 32, 43, 0.14);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background:
    linear-gradient(120deg, rgba(15, 118, 110, 0.12), transparent 34%),
    linear-gradient(300deg, rgba(242, 183, 5, 0.14), transparent 38%),
    var(--bg);
  color: var(--text);
}

button,
a {
  font: inherit;
}

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

.game-shell {
  width: min(980px, 100%);
  padding: 26px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: var(--shadow);
}

.topbar,
.game-layout,
.actions {
  display: flex;
  gap: 16px;
}

.topbar {
  align-items: start;
  justify-content: space-between;
  margin-bottom: 20px;
}

.eyebrow,
.panel-label {
  margin: 0 0 6px;
  color: var(--accent);
  font-size: 13px;
  font-weight: 800;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: clamp(28px, 5vw, 42px);
  line-height: 1.1;
  letter-spacing: 0;
}

.game-layout {
  align-items: stretch;
  justify-content: center;
}

.board-wrap {
  position: relative;
  width: min(100%, 360px);
  aspect-ratio: 1 / 2;
  border-radius: 8px;
  overflow: hidden;
  background: var(--board);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.08);
}

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

.overlay {
  position: absolute;
  inset: 0;
  display: none;
  place-items: center;
  align-content: center;
  gap: 8px;
  background: rgba(16, 24, 32, 0.72);
  color: #ffffff;
  text-align: center;
}

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

.overlay strong {
  font-size: 34px;
  line-height: 1;
}

.overlay span {
  color: rgba(255, 255, 255, 0.82);
}

.side-panel {
  width: min(300px, 100%);
  display: grid;
  grid-template-rows: auto auto auto 1fr;
  gap: 14px;
}

.next-box,
.stats-grid div,
.keys {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fbfd;
}

.next-box {
  padding: 14px;
}

#next {
  width: 120px;
  height: 120px;
  display: block;
  margin: 0 auto;
  border-radius: 6px;
  background: #111b24;
}

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

.stats-grid div {
  min-height: 82px;
  padding: 12px;
  display: grid;
  align-content: center;
  gap: 4px;
}

.stats-grid span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.stats-grid strong {
  font-size: 24px;
}

.primary-button,
.secondary-button {
  min-height: 42px;
  border: 0;
  border-radius: 6px;
  padding: 0 16px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  white-space: nowrap;
  text-decoration: none;
}

.primary-button {
  background: var(--accent);
  color: #ffffff;
  font-weight: 800;
}

.primary-button:hover {
  background: var(--accent-dark);
}

.secondary-button {
  background: #e9eef4;
  color: var(--text);
}

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

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

.keys {
  padding: 14px;
}

.keys dl {
  margin: 0;
  display: grid;
  gap: 9px;
}

.keys div {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid var(--line);
  padding-bottom: 8px;
}

.keys div:last-child {
  border-bottom: 0;
  padding-bottom: 0;
}

.keys dt,
.keys dd {
  margin: 0;
}

.keys dt {
  font-weight: 800;
}

.keys dd {
  color: var(--muted);
}

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

.touch-controls button {
  min-height: 48px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #ffffff;
  color: var(--text);
  font-weight: 800;
}

@media (max-width: 760px) {
  .game-shell {
    padding: 18px;
  }

  .topbar,
  .game-layout {
    flex-direction: column;
  }

  .board-wrap,
  .side-panel {
    width: 100%;
  }

  .side-panel {
    grid-template-rows: auto;
  }

  .touch-controls {
    display: grid;
  }
}

@media (max-width: 420px) {
  .stats-grid,
  .actions {
    grid-template-columns: 1fr;
  }

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