:root {
  --bg: #0b0b14;
  --panel: #141424;
  --panel-soft: #1c1c2e;
  --grid: #1f2033;
  --ink: #f2f3ff;
  --muted: #9b9db8;
  --accent: #ffd447;
  --I: #00e5ff;
  --O: #ffd447;
  --T: #bf5af2;
  --S: #32d74b;
  --Z: #ff453a;
  --L: #ff9f0a;
  --J: #0a84ff;
  --border: rgba(255, 255, 255, 0.08);
  --shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: radial-gradient(ellipse at top, #1a1a2e 0%, var(--bg) 60%);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  min-height: 100dvh;
  overscroll-behavior: contain;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
}

body {
  display: flex;
  justify-content: center;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

.shell {
  width: 100%;
  max-width: 460px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px 12px max(12px, env(safe-area-inset-bottom));
  min-height: 100dvh;
}

.brand h1 {
  margin: 0;
  font-size: clamp(16px, 4.6vw, 22px);
  font-weight: 800;
  text-align: center;
  letter-spacing: 0.02em;
  background: linear-gradient(90deg, var(--I), var(--T), var(--L), var(--S));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.hud {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
}
.stat {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 6px 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  line-height: 1.1;
}
.stat .label {
  font-size: 10px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
.stat strong {
  font-size: clamp(16px, 4.4vw, 20px);
  font-variant-numeric: tabular-nums;
}

.play {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: start;
}

#board {
  width: 100%;
  aspect-ratio: 10 / 20;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
  display: block;
  touch-action: none;
}

.side {
  width: 100px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.side-label {
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  text-align: center;
}
#next {
  width: 100px;
  height: 100px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  display: block;
}
.btn-ghost {
  background: var(--panel-soft);
  color: var(--ink);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.05s;
}
.btn-ghost:active { transform: scale(0.97); }

.controls {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
  margin-top: auto;
}
.ctl {
  background: var(--panel);
  color: var(--ink);
  border: 1px solid var(--border);
  border-radius: 14px;
  font-size: clamp(22px, 6vw, 28px);
  font-weight: 700;
  aspect-ratio: 1 / 1;
  min-height: 56px;
  cursor: pointer;
  touch-action: manipulation;
  transition: transform 0.05s, background 0.12s;
}
.ctl:active {
  transform: scale(0.95);
  background: var(--panel-soft);
}
.ctl.primary {
  background: linear-gradient(135deg, var(--accent), #ffab1a);
  color: #1a1200;
  border-color: transparent;
}

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(5, 5, 15, 0.72);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 10;
}
.overlay.hidden { display: none; }
.overlay-inner {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 24px 20px;
  max-width: 360px;
  width: 100%;
  text-align: center;
  box-shadow: var(--shadow);
}
.overlay-inner h2 {
  margin: 0 0 8px;
  font-size: 22px;
  background: linear-gradient(90deg, var(--I), var(--T), var(--L));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.overlay-inner p {
  margin: 0 0 18px;
  color: var(--muted);
  line-height: 1.45;
  font-size: 14px;
}
.overlay-inner p.keys {
  font-size: 11px;
  margin-top: 14px;
  margin-bottom: 0;
  opacity: 0.6;
}
.btn-primary {
  width: 100%;
  background: linear-gradient(135deg, var(--accent), #ffab1a);
  color: #1a1200;
  border: none;
  border-radius: 12px;
  padding: 14px;
  font-size: 17px;
  font-weight: 700;
  cursor: pointer;
}
.btn-primary:active { transform: scale(0.98); }

@media (min-width: 600px) {
  .shell { max-width: 520px; }
  .controls { display: none; }
  body::before {
    content: "← → bewegen · ↑ drehen · ↓ weich · Space hart · P pause";
    position: fixed;
    bottom: 10px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 11px;
    color: var(--muted);
    letter-spacing: 0.02em;
  }
}

@media (pointer: fine) and (min-width: 600px) {
  .ctl { display: none; }
}
