:root {
  color-scheme: dark;
  --bg: #060911;
  --panel: rgba(255, 255, 255, 0.045);
  --border: rgba(255, 255, 255, 0.09);
  --text: #e8eef8;
  --muted: #8592a8;
  --cyan: #38e1ff;
  --violet: #8b5cf6;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  color: var(--text);
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background:
    radial-gradient(120% 80% at 50% -10%, rgba(56, 225, 255, 0.12), transparent 55%),
    radial-gradient(100% 70% at 100% 110%, rgba(139, 92, 246, 0.14), transparent 60%),
    var(--bg);
}

.app {
  height: 100vh;
  height: 100dvh;
  max-width: 520px;
  margin: 0 auto;
  padding: max(8px, env(safe-area-inset-top)) 12px max(8px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.hud {
  flex: none;
  display: grid;
  grid-template-columns: 1fr auto auto;
  align-items: center;
  gap: 10px;
}

.hud-main {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.score {
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.label {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.14em;
  color: var(--muted);
}

.score strong {
  font-size: clamp(20px, 6vw, 28px);
  line-height: 1;
  font-weight: 800;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}

.meta {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 12px;
}

.meta span {
  font-size: 10px;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.meta b {
  margin-left: 3px;
  font-size: 11px;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.next {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
}

#next {
  display: block;
  width: 52px;
  height: 52px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--panel);
}

.pause-btn {
  width: 38px;
  height: 38px;
  padding: 0;
  -webkit-appearance: none;
  appearance: none;
  display: grid;
  place-items: center;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  font: inherit;
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.06em;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.06s ease;
}

.pause-btn:active {
  transform: scale(0.94);
  background: rgba(56, 225, 255, 0.16);
}

.pause-btn:disabled {
  opacity: 0.35;
  cursor: default;
}

.stage {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  touch-action: none;
}

#board {
  display: block;
  border-radius: 12px;
  background: #080c15;
  touch-action: none;
  box-shadow:
    0 0 0 1px rgba(120, 200, 255, 0.16),
    0 14px 40px rgba(0, 0, 0, 0.55),
    0 0 70px rgba(56, 225, 255, 0.05);
}

.overlay {
  position: absolute;
  inset: 0;
  z-index: 3;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  border-radius: 12px;
  background: rgba(4, 7, 13, 0.66);
  -webkit-backdrop-filter: blur(7px);
  backdrop-filter: blur(7px);
}

.hidden {
  display: none !important;
}

.card {
  width: min(100%, 300px);
  padding: 22px 20px;
  text-align: center;
  border-radius: 18px;
  border: 1px solid var(--border);
  background: rgba(14, 20, 33, 0.94);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6);
}

.card h1 {
  margin: 0 0 8px;
  font-size: 24px;
  font-weight: 800;
  letter-spacing: 0.16em;
}

.card p {
  min-height: 0;
  margin: 0 0 18px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
  white-space: pre-line;
}

.card p:empty {
  display: none;
}

.card-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.card button {
  height: 46px;
  border-radius: 12px;
  font: inherit;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
  transition: transform 0.06s ease, filter 0.15s ease;
}

.card button:active {
  transform: scale(0.98);
}

.primary {
  border: 0;
  color: #04121a;
  background: linear-gradient(180deg, #4ee8ff, #1fb6d8);
  box-shadow: 0 8px 24px rgba(56, 225, 255, 0.25);
}

.secondary {
  border: 1px solid var(--border);
  color: var(--text);
  background: var(--panel);
}

.controls {
  flex: none;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: 1fr 1fr;
  gap: 8px;
}

.ctrl {
  height: clamp(46px, 8vh, 58px);
  padding: 0;
  -webkit-appearance: none;
  appearance: none;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.09), rgba(255, 255, 255, 0.03));
  color: var(--text);
  font: inherit;
  font-size: 20px;
  cursor: pointer;
  touch-action: none;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08), 0 4px 14px rgba(0, 0, 0, 0.25);
  transition: transform 0.06s ease, background 0.12s ease;
}

.ctrl:active {
  transform: scale(0.96);
  background: rgba(56, 225, 255, 0.18);
}

#btnLeft {
  grid-area: 1 / 1;
}

#btnRotate {
  grid-area: 1 / 2;
}

#btnRight {
  grid-area: 1 / 3;
}

#btnDown {
  grid-area: 2 / 1;
}

#btnDrop {
  grid-area: 2 / 2 / 3 / 4;
  border-color: transparent;
  color: #03121a;
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.12em;
  background: linear-gradient(180deg, #4ee8ff, #1fb6d8);
}

#btnDrop:active {
  background: linear-gradient(180deg, #7df0ff, #35c6e8);
}

@media (max-height: 600px) {
  .app {
    gap: 7px;
    padding-left: 10px;
    padding-right: 10px;
  }

  .controls {
    gap: 6px;
  }

  .ctrl {
    height: clamp(42px, 8vh, 52px);
  }

  #next {
    width: 44px;
    height: 44px;
  }

  .card {
    padding: 16px;
  }

  .card h1 {
    font-size: 20px;
  }

  .card button {
    height: 42px;
  }
}
