/* ============ Tetris — colorful, offline, responsive ============ */
:root {
  --text: #eef3ff;
  --muted: #9fb0d8;
  --panel: rgba(255, 255, 255, 0.055);
  --border: rgba(255, 255, 255, 0.14);
  --radius: 16px;
}

*, *::before, *::after { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
  min-height: 100vh;
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--text);
  background:
    radial-gradient(900px 520px at 12% -8%, rgba(124, 77, 255, 0.38), transparent 60%),
    radial-gradient(820px 520px at 108% 12%, rgba(0, 190, 255, 0.30), transparent 58%),
    radial-gradient(760px 620px at 50% 118%, rgba(255, 77, 141, 0.25), transparent 62%),
    linear-gradient(165deg, #170a38 0%, #0c1636 55%, #071022 100%);
  background-attachment: fixed;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
}

.game {
  width: min(100%, 980px);
  margin: 0 auto;
  padding: 10px 12px calc(20px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

/* ---------- title ---------- */
.title {
  margin: 2px 0 0;
  font-size: clamp(26px, 6vw, 42px);
  font-weight: 800;
  letter-spacing: 0.32em;
  text-indent: 0.32em;
  text-align: center;
  background: linear-gradient(90deg, #ff4d8d, #ff9f1a, #ffd60a, #2eea62, #00e5ff, #3d7bff, #b14cff, #ff4d8d);
  background-size: 200% 100%;
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  animation: shine 7s linear infinite;
}
@keyframes shine { to { background-position: 200% 0; } }

/* ---------- top bar ---------- */
.topbar {
  display: flex;
  justify-content: center;
  align-items: stretch;
  flex-wrap: wrap;
  gap: 10px;
  width: 100%;
}
.slot {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 8px 10px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.slot h2 {
  margin: 0;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.22em;
  text-indent: 0.22em;
  text-transform: uppercase;
  color: var(--muted);
}
#hold { width: clamp(54px, 15vw, 84px); aspect-ratio: 1 / 1; display: block; }
#next { width: clamp(54px, 15vw, 84px); aspect-ratio: 1 / 3; display: block; }

.stats-box {
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 8px 14px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.stats { display: grid; grid-template-columns: auto auto; gap: 2px 18px; }
.stat { display: flex; flex-direction: column; align-items: center; min-width: 64px; }
.stat .label {
  font-size: 9.5px;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}
.stat .value {
  font-size: clamp(15px, 3.6vw, 20px);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: #fff;
}

/* ---------- board ---------- */
.board-wrap {
  width: min(100%, 39vh, 330px);
  aspect-ratio: 1 / 2;
  padding: 5px;
  border-radius: 20px;
  background: linear-gradient(140deg, #ff4d8d, #b14cff 28%, #3d7bff 52%, #00e5ff 76%, #2eea62);
  background-size: 280% 280%;
  animation: borderflow 9s ease infinite;
  box-shadow: 0 12px 44px rgba(0, 0, 0, 0.5), 0 0 26px rgba(99, 102, 241, 0.22);
}
@keyframes borderflow {
  0%, 100% { background-position: 0% 50%; }
  50% { background-position: 100% 50%; }
}
.board-frame {
  position: relative;
  width: 100%;
  height: 100%;
  border-radius: 15px;
  overflow: hidden;
  background: #0a0e26;
  box-shadow: inset 0 0 30px rgba(0, 0, 0, 0.55);
}
#board { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }

/* ---------- overlay ---------- */
.overlay {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 18px;
  text-align: center;
  background: rgba(8, 10, 26, 0.78);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}
.overlay.hidden { display: none; }
.overlay h2 {
  margin: 0;
  font-size: clamp(24px, 7vw, 36px);
  letter-spacing: 0.16em;
  text-indent: 0.16em;
  background: linear-gradient(90deg, #ffd60a, #ff9f1a, #ff4d8d);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.overlay p { margin: 0; color: var(--muted); font-size: 14px; line-height: 1.55; max-width: 300px; }
.overlay b { color: #fff; }
.overlay-btn {
  border: none;
  cursor: pointer;
  font: inherit;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 0.05em;
  color: #071022;
  padding: 12px 32px;
  border-radius: 999px;
  background: linear-gradient(90deg, #2eea62, #00e5ff);
  box-shadow: 0 8px 22px rgba(0, 229, 255, 0.35);
  transition: transform 0.08s ease;
}
.overlay-btn:active { transform: scale(0.95); }

/* ---------- touch pad ---------- */
.pad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 9px;
  width: min(100%, 430px);
}
.btn {
  border: 1px solid var(--border);
  border-radius: 14px;
  min-height: 56px;
  font: inherit;
  font-size: 20px;
  font-weight: 700;
  line-height: 1;
  color: #fff;
  background: rgba(255, 255, 255, 0.07);
  touch-action: none;
  cursor: pointer;
  transition: transform 0.06s ease, filter 0.15s ease;
}
.btn:active { transform: scale(0.94); filter: brightness(1.3); }
.btn.small { min-height: 46px; font-size: 14px; }
.btn.left, .btn.right { background: linear-gradient(150deg, rgba(61, 123, 255, 0.5), rgba(61, 123, 255, 0.16)); }
.btn.rotate { background: linear-gradient(150deg, rgba(177, 76, 255, 0.5), rgba(177, 76, 255, 0.16)); }
.btn.soft { background: linear-gradient(150deg, rgba(46, 234, 98, 0.45), rgba(46, 234, 98, 0.14)); }
.btn.hard { grid-column: span 2; background: linear-gradient(150deg, rgba(255, 61, 90, 0.5), rgba(255, 61, 90, 0.16)); }
.btn.holdb { background: linear-gradient(150deg, rgba(255, 159, 26, 0.45), rgba(255, 159, 26, 0.14)); }

/* hide the touch pad on desktop (mouse + keyboard) */
@media (hover: hover) and (pointer: fine) and (min-width: 720px) {
  .pad { display: none; }
}

.hints {
  margin: 0;
  color: var(--muted);
  font-size: 12.5px;
  text-align: center;
}
@media (hover: none), (max-width: 719px) {
  .hints { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .title, .board-wrap { animation: none; }
}
