:root {
  --bg: #0d1117;
  --panel: #161b22;
  --panel-border: #2a3140;
  --text: #e6edf3;
  --muted: #8b949e;
  --accent: #58a6ff;
  --cell: #1c2330;
  --grid: #232b3a;
  --danger: #f64d4d;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, Helvetica, Arial, sans-serif;
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

body {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  min-height: 100dvh;
  padding: 8px;
}

#app {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  justify-content: center;
}

.panel-box {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
  min-width: 92px;
}

.panel-box h2 {
  font-size: 11px;
  letter-spacing: 2px;
  color: var(--muted);
  font-weight: 600;
}

.panel-box canvas {
  background: var(--cell);
  border-radius: 4px;
  image-rendering: pixelated;
}

.stats {
  min-width: 110px;
  justify-content: flex-start;
}

.stat {
  display: flex;
  flex-direction: column;
  gap: 2px;
  width: 100%;
}

.stat span:first-child {
  font-size: 10px;
  letter-spacing: 1.5px;
  color: var(--muted);
}

.stat span:last-child {
  font-size: 18px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.sound-row {
  cursor: pointer;
  margin-top: 4px;
  border-top: 1px solid var(--panel-border);
  padding-top: 8px;
}

#board-wrap {
  display: flex;
  justify-content: center;
}

#board-frame {
  position: relative;
  background: var(--cell);
  border: 2px solid var(--panel-border);
  border-radius: 6px;
  overflow: hidden;
  touch-action: none;
}

#board {
  display: block;
}

#overlay {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  background: rgba(13, 17, 23, 0.88);
  backdrop-filter: blur(2px);
  text-align: center;
  padding: 16px;
}

#overlay.visible { display: flex; }

#overlay h1 {
  font-size: 28px;
  letter-spacing: 3px;
  color: var(--accent);
}

#overlay p {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.6;
}

#overlay .big-score {
  font-size: 22px;
  font-weight: 700;
  color: var(--text);
}

#overlay button {
  background: var(--accent);
  color: #0d1117;
  border: none;
  border-radius: 6px;
  padding: 10px 22px;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  letter-spacing: 1px;
}

#overlay button:active { transform: scale(0.97); }

#touch-controls {
  display: none;
  margin-top: 12px;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
  width: 100%;
  max-width: 420px;
}

#touch-controls button {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  color: var(--text);
  font-size: 20px;
  padding: 14px 0;
  cursor: pointer;
  touch-action: manipulation;
}

#touch-controls button:active {
  background: var(--accent);
  color: #0d1117;
}

/* ---------- Mobile layout ---------- */
@media (max-width: 640px) {
  body {
    justify-content: flex-start;
    padding: 6px;
    gap: 8px;
  }

  #app {
    flex-wrap: wrap;
    justify-content: center;
    gap: 8px;
    width: 100%;
  }

  #board-wrap {
    order: 1;
    width: 100%;
  }

  #board-frame {
    width: 100%;
    max-width: 340px;
  }

  #hold-box {
    order: 2;
    min-width: 72px;
    padding: 6px;
  }

  #next-box {
    order: 3;
    min-width: 72px;
    padding: 6px;
  }

  #stats-box {
    order: 4;
    flex-direction: row;
    flex-wrap: wrap;
    gap: 4px 10px;
    width: 100%;
    max-width: 340px;
    min-width: 0;
    padding: 6px 8px;
  }

  #stats-box .stat {
    width: auto;
    flex: 1 1 40%;
  }

  #stats-box .stat span:last-child { font-size: 14px; }

  #stats-box .sound-row {
    flex: 1 1 40%;
    border-top: none;
    padding-top: 0;
    margin-top: 0;
  }

  #touch-controls {
    display: grid;
    order: 5;
  }
}

/* Very short screens: keep everything visible without scroll */
@media (max-height: 700px) and (max-width: 640px) {
  #touch-controls button { padding: 10px 0; font-size: 17px; }
}
