* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --bg: #101014;
  --panel: #1a1a21;
  --panel-edge: #2c2c36;
  --text: #e8e6e0;
  --muted: #8f8d95;
  --accent: #ffb454;
}

body {
  background: var(--bg);
  background-size: cover;
  background-position: center;
  color: var(--text);
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}

.wrap { padding: 12px 16px; width: 100%; }

header { text-align: center; margin-bottom: 10px; }
h1 {
  font-size: 24px;
  letter-spacing: 10px;
  font-weight: 600;
  color: var(--accent);
  text-shadow: 0 0 24px rgba(255, 180, 84, 0.35);
}
.sub {
  color: var(--muted);
  font-size: 13px;
  letter-spacing: 3px;
  text-transform: uppercase;
  margin-top: 4px;
}

.layout {
  display: flex;
  gap: 16px;
  align-items: flex-start;
  justify-content: center;
}

.side { display: flex; flex-direction: column; gap: 16px; width: 152px; }

.card {
  background: var(--panel);
  border: 1px solid var(--panel-edge);
  border-radius: 10px;
  padding: 12px 14px;
}
.card h2 {
  font-size: 11px;
  letter-spacing: 3px;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 600;
  margin-bottom: 6px;
}
.card canvas { display: block; margin: 0 auto; }

.stats .big {
  font-size: 22px;
  font-variant-numeric: tabular-nums;
  color: var(--text);
  margin-bottom: 12px;
}
.stats .big:last-child { margin-bottom: 0; }

.keys ul { list-style: none; font-size: 12px; color: var(--muted); line-height: 1.9; }
.keys b { color: var(--text); font-weight: 600; display: inline-block; min-width: 52px; }

.board-frame {
  position: relative;
  border: 1px solid var(--panel-edge);
  border-radius: 12px;
  padding: 10px;
  background: rgba(16, 16, 20, 0.85);
  box-shadow: 0 12px 48px rgba(0, 0, 0, 0.6);
}
#board { display: block; border-radius: 6px; background: #7c7c80; }

.overlay {
  position: absolute;
  inset: 10px;
  border-radius: 6px;
  background: rgba(10, 10, 13, 0.88);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  text-align: center;
  padding: 20px;
}
.overlay.hidden { display: none; }
#overlay-title {
  font-size: 22px;
  letter-spacing: 6px;
  color: var(--accent);
  font-weight: 600;
}
#overlay-text { font-size: 14px; color: var(--text); line-height: 1.7; }
.build { color: var(--muted); font-size: 10px; letter-spacing: 1px; }

@media (max-width: 720px) {
  .layout { flex-wrap: wrap; }
  .side { flex-direction: row; width: auto; }
}

/* ================= touch layout ================= */
html, body { overscroll-behavior: none; }
.controls, .pause-btn, .music-btn { display: none; }

.music-btn {
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--panel-edge);
  border-radius: 10px;
  padding: 10px 18px;
  font-size: 14px;
}

body.touch { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
body.touch { display: block; }
body.touch .music-btn { display: inline-block; }
body.touch { min-height: 0; height: 100%; overflow: hidden; }
html { height: 100%; }
body.touch .wrap {
  padding: 0 10px;
  height: 100vh;
  height: 100svh;  /* smallest viewport = bar fully expanded; static, unspoofable */
  display: flex;
  flex-direction: column;
}
body.touch header { display: none; }
body.touch .layout {
  flex: 1;
  min-height: 0;
  display: grid;
  align-items: stretch;
  justify-content: stretch;
  grid-template-columns: auto 1fr auto auto;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 8px;
  padding-top: max(8px, env(safe-area-inset-top));
}
body.touch .side { display: contents; }
body.touch .card { padding: 5px 8px; border-radius: 8px; margin: 0; }
body.touch .card h2 { font-size: 9px; letter-spacing: 2px; margin-bottom: 2px; }
body.touch .card-hold { grid-area: 1 / 1; }
body.touch .card-stats {
  grid-area: 1 / 2;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 2px 8px;
}
body.touch .card-stats h2, body.touch .card-stats .big { margin: 0; }
body.touch .card-stats .big { font-size: 15px; }
body.touch .card-next { grid-area: 1 / 3; }
body.touch .pause-btn {
  display: block;
  grid-area: 1 / 4;
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--panel-edge);
  border-radius: 8px;
  min-width: 48px;
  font-size: 14px;
}
body.touch .card-keys { display: none; }
body.touch .layout { overflow: hidden; }
body.touch .board-frame {
  grid-area: 2 / 1 / 3 / 5;
  min-height: 0;
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 6px;
  touch-action: none;
  overflow: hidden;
}
body.touch #board {
  touch-action: none;
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;  /* last-resort clamp keeps aspect if JS sizing is ever stale */
}

body.touch .controls {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  padding: 10px max(14px, env(safe-area-inset-right))
           max(28px, calc(env(safe-area-inset-bottom) + 14px))
           max(14px, env(safe-area-inset-left));
  touch-action: none;
}
.cluster { display: flex; gap: 10px; }
body.touch .controls .cluster:first-of-type { justify-self: start; }
body.touch .controls #btn-down { justify-self: center; }
body.touch .controls .cluster:last-of-type { justify-self: end; }
.controls button {
  /* shrink fluidly on narrow screens so the row never overflows off-center */
  width: min(62px, calc((100vw - 72px) / 5));
  aspect-ratio: 1;
  height: auto;
  padding: 0;
  line-height: 1;
  text-align: center;
  font-size: 22px;
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--panel-edge);
  border-radius: 14px;
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
}
.controls button:active {
  background: #2a2a33;
  border-color: var(--accent);
  color: var(--accent);
}
