/* ------------------------------------------------------------------
   Prism Tetris — styles
   ------------------------------------------------------------------ */

@property --accent-h {
  syntax: '<number>';
  inherits: true;
  initial-value: 196;
}

:root {
  --accent-h: 196;
  --accent: hsl(var(--accent-h) 95% 64%);
  --accent-deep: hsl(var(--accent-h) 90% 50%);
  --accent-soft: hsl(var(--accent-h) 90% 64% / 0.28);
  --accent-glow: hsl(var(--accent-h) 95% 62% / 0.5);
  --bg: #06060d;
  --ink: #eef0ff;
  --muted: rgba(238, 240, 255, 0.55);
  --faint: rgba(238, 240, 255, 0.32);
  --glass: rgba(255, 255, 255, 0.045);
  --glass-strong: rgba(255, 255, 255, 0.08);
  --glass-border: rgba(255, 255, 255, 0.09);
  --radius: 20px;
  --font-display: 'Unbounded', 'Outfit', system-ui, sans-serif;
  --font-ui: 'Outfit', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --touch-h: 0px;
  transition: --accent-h 900ms ease;
}

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

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
}

body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 15px;
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
  overscroll-behavior: none;
}

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
  border: 0;
  background: none;
  padding: 0;
  touch-action: manipulation;
}
button:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }

canvas { display: block; }

[hidden] { display: none !important; }

/* ---------- Background ---------- */

.bg {
  position: fixed;
  inset: 0;
  z-index: 0;
  overflow: hidden;
  background:
    radial-gradient(120% 80% at 50% 110%, hsl(var(--accent-h) 60% 12% / 0.9), transparent 60%),
    linear-gradient(180deg, #08080f 0%, #05050b 100%);
}

.bg__blob {
  position: absolute;
  width: 62vmax;
  height: 62vmax;
  border-radius: 50%;
  filter: blur(70px);
  opacity: 0.45;
  mix-blend-mode: screen;
  will-change: transform;
  animation: drift 46s ease-in-out infinite alternate;
}
.bg__blob--1 {
  left: -18vmax; top: -22vmax;
  background: radial-gradient(circle, hsl(var(--accent-h) 90% 55% / 0.55), transparent 68%);
}
.bg__blob--2 {
  right: -22vmax; top: 10vmax;
  background: radial-gradient(circle, hsl(calc(var(--accent-h) + 70) 90% 55% / 0.45), transparent 68%);
  animation-duration: 58s;
  animation-delay: -20s;
}
.bg__blob--3 {
  left: 20vmax; bottom: -30vmax;
  background: radial-gradient(circle, hsl(calc(var(--accent-h) - 60) 90% 55% / 0.4), transparent 68%);
  animation-duration: 52s;
  animation-delay: -35s;
}
@keyframes drift {
  0%   { transform: translate3d(0, 0, 0) scale(1); }
  50%  { transform: translate3d(8vmax, 6vmax, 0) scale(1.15); }
  100% { transform: translate3d(-6vmax, 10vmax, 0) scale(0.95); }
}

.bg__grid {
  position: absolute;
  inset: -10%;
  background-image:
    linear-gradient(rgba(255,255,255,0.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,0.035) 1px, transparent 1px);
  background-size: 56px 56px;
  mask-image: radial-gradient(ellipse 70% 70% at 50% 45%, #000 20%, transparent 75%);
  -webkit-mask-image: radial-gradient(ellipse 70% 70% at 50% 45%, #000 20%, transparent 75%);
}

.bg__noise {
  position: absolute;
  inset: 0;
  opacity: 0.06;
  mix-blend-mode: overlay;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='200' height='200'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

.fx {
  position: fixed;
  inset: 0;
  z-index: 40;
  pointer-events: none;
}

/* ---------- App shell ---------- */

.app {
  position: relative;
  z-index: 1;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  padding:
    max(8px, env(safe-area-inset-top))
    max(14px, env(safe-area-inset-right))
    max(10px, env(safe-area-inset-bottom))
    max(14px, env(safe-area-inset-left));
  gap: 6px;
}

.topbar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 2px 4px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
}
.brand__mark {
  width: 14px; height: 14px;
  border-radius: 4px;
  background: linear-gradient(135deg, #fff, var(--accent) 60%, var(--accent-deep));
  box-shadow: 0 0 18px var(--accent-glow);
  transform: rotate(45deg);
}
.brand__name {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 12px;
  letter-spacing: 0.32em;
  color: var(--ink);
}
.brand__name span { color: var(--accent); margin-left: 0.32em; }

.topbar__actions { display: flex; gap: 8px; }

.icon-btn {
  width: 38px; height: 38px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--glass);
  border: 1px solid var(--glass-border);
  color: var(--ink);
  transition: background 200ms, transform 200ms, opacity 200ms, color 200ms;
}
.icon-btn:hover { background: var(--glass-strong); transform: translateY(-1px); }
.icon-btn:active { transform: scale(0.94); }
.icon-btn[aria-pressed="false"] { opacity: 0.4; color: var(--muted); }
.icon-btn[aria-pressed="false"]::after {
  content: '';
  position: absolute;
  width: 20px; height: 2px;
  background: currentColor;
  transform: rotate(-45deg);
  border-radius: 2px;
}
.icon-btn { position: relative; }

/* ---------- Stage grid ---------- */

.stage {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(150px, 196px) minmax(0, 1fr) minmax(150px, 196px);
  grid-template-rows: auto minmax(0, 1fr);
  grid-template-areas:
    "hold  board next"
    "stats board keys";
  gap: 14px 18px;
  align-items: start;
  padding: 4px 0 6px;
}

.card {
  background: var(--glass);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius);
  padding: 14px 16px 16px;
  backdrop-filter: blur(18px) saturate(1.3);
  -webkit-backdrop-filter: blur(18px) saturate(1.3);
  box-shadow:
    0 10px 40px rgba(0, 0, 0, 0.35),
    inset 0 1px 0 rgba(255, 255, 255, 0.06);
  min-width: 0;
}

.card__title {
  margin: 0 0 10px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.3em;
  text-transform: uppercase;
  color: var(--muted);
}

.card--hold  { grid-area: hold; }
.card--next  { grid-area: next; }
.card--stats { grid-area: stats; }
.card--keys  { grid-area: keys; }

.card--hold canvas,
.card--next canvas { margin: 0 auto; }

.card--hold.is-locked canvas { opacity: 0.45; filter: grayscale(1); transition: opacity 250ms, filter 250ms; }
.card--hold canvas { transition: opacity 250ms, filter 250ms; }

.stat {
  display: flex;
  flex-direction: column;
  gap: 1px;
  margin-bottom: 12px;
}
.stat:last-child { margin-bottom: 0; }
.stat__label {
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.28em;
  text-transform: uppercase;
  color: var(--faint);
}
.stat__value {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 21px;
  letter-spacing: 0.02em;
  font-variant-numeric: tabular-nums;
  line-height: 1.15;
  display: inline-block;
  transform-origin: left center;
}
.stat--score .stat__value {
  font-size: 27px;
  font-weight: 900;
  background: linear-gradient(120deg, #fff 0%, var(--accent) 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 0 14px var(--accent-soft));
}
.stat__value.pulse { animation: statPulse 380ms cubic-bezier(.2,.9,.3,1.4); }
@keyframes statPulse {
  0%   { transform: scale(1); }
  35%  { transform: scale(1.14); }
  100% { transform: scale(1); }
}

.keys {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-size: 12.5px;
  color: var(--muted);
}
.keys li { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.keys li span:last-child { display: inline-flex; gap: 4px; }

kbd {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 22px;
  height: 22px;
  padding: 0 6px;
  border-radius: 6px;
  font-family: var(--font-ui);
  font-size: 11px;
  font-weight: 600;
  color: var(--ink);
  background: rgba(255,255,255,0.07);
  border: 1px solid rgba(255,255,255,0.12);
  box-shadow: inset 0 -2px 0 rgba(0,0,0,0.35);
}

/* ---------- Board ---------- */

.board-wrap {
  grid-area: board;
  position: relative;
  align-self: stretch;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.board-frame {
  position: relative;
  padding: 10px;
  border-radius: 22px;
  container-type: inline-size;
  background: linear-gradient(160deg, rgba(255,255,255,0.09), rgba(255,255,255,0.02) 55%, rgba(255,255,255,0.05));
  border: 1px solid rgba(255,255,255,0.14);
  box-shadow:
    0 0 0 1px rgba(0,0,0,0.5),
    0 30px 80px rgba(0,0,0,0.6),
    0 0 70px var(--accent-glow),
    inset 0 0 0 1px rgba(255,255,255,0.03);
  transition: box-shadow 700ms ease;
  will-change: transform;
}
.board-frame::before {
  /* thin accent halo line */
  content: '';
  position: absolute;
  inset: -1px;
  border-radius: inherit;
  padding: 1px;
  background: linear-gradient(160deg, var(--accent) 0%, transparent 40%, transparent 60%, var(--accent) 100%);
  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  -webkit-mask-composite: xor;
  mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  mask-composite: exclude;
  opacity: 0.55;
  pointer-events: none;
  transition: opacity 400ms;
}
.board-frame.is-danger {
  animation: dangerPulse 900ms ease-in-out infinite;
}
@keyframes dangerPulse {
  0%, 100% { box-shadow: 0 0 0 1px rgba(0,0,0,0.5), 0 30px 80px rgba(0,0,0,0.6), 0 0 60px rgba(255, 60, 90, 0.35); }
  50%      { box-shadow: 0 0 0 1px rgba(0,0,0,0.5), 0 30px 80px rgba(0,0,0,0.6), 0 0 110px rgba(255, 60, 90, 0.7); }
}
.board-frame.is-levelup::before { animation: haloFlash 1100ms ease-out; }
@keyframes haloFlash {
  0%   { opacity: 1; filter: brightness(2.2); }
  100% { opacity: 0.55; filter: brightness(1); }
}
.board-frame.is-blur #board { filter: blur(7px) brightness(0.55) saturate(0.6); }
#board {
  border-radius: 13px;
  transition: filter 350ms ease;
  cursor: pointer;
}

.level-progress {
  position: absolute;
  left: 14px; right: 14px; bottom: 4px;
  height: 3px;
  border-radius: 3px;
  background: rgba(255,255,255,0.06);
  overflow: hidden;
}
.level-progress__bar {
  height: 100%;
  width: 0%;
  border-radius: 3px;
  background: linear-gradient(90deg, var(--accent-deep), #fff);
  box-shadow: 0 0 10px var(--accent-glow);
  transition: width 350ms cubic-bezier(.2,.8,.2,1);
}

/* ---------- Popups over the board ---------- */

.popups {
  position: absolute;
  inset: 10px;
  pointer-events: none;
  overflow: hidden;
  border-radius: 13px;
}
.popup {
  position: absolute;
  left: 0; right: 0;
  text-align: center;
  white-space: nowrap;
}
.popup__text { display: inline-block; will-change: transform, opacity; }

.popup--big { top: 36%; }
.popup--big .popup__text {
  font-family: var(--font-display);
  font-weight: 900;
  font-size: clamp(20px, 9.5cqw, 46px);
  letter-spacing: 0.02em;
  line-height: 1;
  background: linear-gradient(180deg, #fff 20%, var(--popup-color, var(--accent)) 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 0 22px var(--popup-color, var(--accent))) drop-shadow(0 4px 14px rgba(0,0,0,0.6));
  animation: popBig 1200ms cubic-bezier(.2,.7,.2,1) forwards;
}
@keyframes popBig {
  0%   { opacity: 0; transform: scale(0.35) translateY(30px); filter: blur(10px); }
  16%  { opacity: 1; transform: scale(1.14) translateY(0); filter: blur(0); }
  28%  { transform: scale(1); }
  74%  { opacity: 1; transform: scale(1) translateY(-8px); }
  100% { opacity: 0; transform: scale(1.06) translateY(-46px); filter: blur(4px); }
}

.popup--sub { top: 52%; }
.popup--sub .popup__text {
  font-weight: 700;
  font-size: clamp(11px, 3.9cqw, 17px);
  letter-spacing: 0.26em;
  text-transform: uppercase;
  color: rgba(255,255,255,0.9);
  text-shadow: 0 0 14px var(--popup-color, var(--accent)), 0 2px 8px rgba(0,0,0,0.7);
  animation: popSub 1100ms cubic-bezier(.2,.7,.2,1) forwards;
}
@keyframes popSub {
  0%   { opacity: 0; transform: translateY(14px) scale(0.9); letter-spacing: 0.1em; }
  20%  { opacity: 1; transform: translateY(0) scale(1); letter-spacing: 0.26em; }
  75%  { opacity: 1; }
  100% { opacity: 0; transform: translateY(-24px); }
}

.popup--level { top: 62%; }
.popup--level .popup__text {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: clamp(11px, 4.4cqw, 18px);
  letter-spacing: 0.22em;
  padding: 8px 18px;
  border-radius: 999px;
  color: #08080f;
  background: linear-gradient(90deg, #fff, var(--accent));
  box-shadow: 0 0 30px var(--accent-glow), 0 8px 30px rgba(0,0,0,0.5);
  animation: popLevel 1600ms cubic-bezier(.2,.7,.2,1) forwards;
}
@keyframes popLevel {
  0%   { opacity: 0; transform: scale(0.6) translateY(20px); }
  15%  { opacity: 1; transform: scale(1.06) translateY(0); }
  25%  { transform: scale(1); }
  80%  { opacity: 1; }
  100% { opacity: 0; transform: translateY(-20px) scale(0.96); }
}

.popup--ready { top: 44%; }
.popup--ready .popup__text {
  font-family: var(--font-display);
  font-weight: 900;
  font-size: clamp(24px, 12cqw, 58px);
  letter-spacing: 0.08em;
  color: #fff;
  text-shadow: 0 0 30px var(--accent), 0 6px 20px rgba(0,0,0,0.7);
  animation: popReady 700ms cubic-bezier(.2,.8,.2,1) forwards;
}
@keyframes popReady {
  0%   { opacity: 0; transform: scale(1.6); filter: blur(8px); }
  25%  { opacity: 1; transform: scale(1); filter: blur(0); }
  75%  { opacity: 1; transform: scale(1); }
  100% { opacity: 0; transform: scale(0.8); }
}

.popup--score {
  top: auto;
  left: auto; right: auto;
}
.popup--score .popup__text {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: clamp(11px, 4cqw, 16px);
  color: #fff;
  text-shadow: 0 0 12px var(--popup-color, var(--accent)), 0 2px 6px rgba(0,0,0,0.6);
  animation: popScore 900ms ease-out forwards;
}
@keyframes popScore {
  0%   { opacity: 0; transform: translateY(6px) scale(0.8); }
  20%  { opacity: 1; transform: translateY(0) scale(1); }
  100% { opacity: 0; transform: translateY(-40px) scale(1); }
}

/* ---------- Touch controls ---------- */

.touch {
  display: none;
  flex: 0 0 auto;
  justify-content: space-between;
  align-items: flex-end;
  gap: 12px;
  padding: 4px 2px 2px;
}
.touch__cluster {
  display: grid;
  gap: 10px;
}
.touch__cluster--left {
  grid-template-columns: repeat(2, 1fr);
  grid-template-areas: "left right" "soft hard";
}
.touch__cluster--left [data-action="left"]  { grid-area: left; }
.touch__cluster--left [data-action="right"] { grid-area: right; }
.touch__cluster--left [data-action="soft"]  { grid-area: soft; }
.touch__cluster--left [data-action="hard"]  { grid-area: hard; }
.touch__cluster--right {
  grid-template-columns: repeat(2, 1fr);
  grid-template-areas: "hold ccw" "cw cw";
  justify-items: end;
}
.touch__cluster--right [data-action="hold"] { grid-area: hold; }
.touch__cluster--right [data-action="ccw"]  { grid-area: ccw; }
.touch__cluster--right [data-action="cw"]   { grid-area: cw; justify-self: stretch; }

.touch-btn {
  width: 60px; height: 60px;
  border-radius: 20px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--ink);
  background: var(--glass-strong);
  border: 1px solid rgba(255,255,255,0.14);
  box-shadow: 0 8px 24px rgba(0,0,0,0.35), inset 0 1px 0 rgba(255,255,255,0.1);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  transition: transform 90ms ease, background 120ms ease, box-shadow 120ms ease;
  touch-action: none;
}
.touch-btn--big { width: auto; height: 60px; border-radius: 20px; }
.touch-btn__text {
  font-family: var(--font-display);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.16em;
}
.touch-btn--accent { color: #08080f; background: linear-gradient(135deg, #fff, var(--accent)); }
.touch-btn.is-active,
.touch-btn:active {
  transform: scale(0.92);
  background: var(--accent);
  color: #08080f;
  box-shadow: 0 0 24px var(--accent-glow), inset 0 1px 0 rgba(255,255,255,0.3);
}

/* ---------- Overlays ---------- */

.overlay {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(4, 4, 10, 0.55);
  backdrop-filter: blur(16px) saturate(1.2);
  -webkit-backdrop-filter: blur(16px) saturate(1.2);
  opacity: 0;
  visibility: hidden;
  transition: opacity 380ms ease, visibility 0s linear 380ms;
  overflow: hidden;
}
.overlay.is-active {
  opacity: 1;
  visibility: visible;
  transition: opacity 380ms ease, visibility 0s;
}
.overlay__card {
  position: relative;
  z-index: 1;
  width: min(92vw, 520px);
  max-height: 100%;
  overflow: auto;
  padding: 34px 34px 30px;
  border-radius: 28px;
  text-align: center;
  background: linear-gradient(160deg, rgba(255,255,255,0.09), rgba(255,255,255,0.03));
  border: 1px solid rgba(255,255,255,0.14);
  box-shadow: 0 40px 100px rgba(0,0,0,0.6), 0 0 80px var(--accent-soft), inset 0 1px 0 rgba(255,255,255,0.08);
  transform: translateY(24px) scale(0.96);
  transition: transform 480ms cubic-bezier(.2,.8,.2,1);
  scrollbar-width: none;
}
.overlay__card::-webkit-scrollbar { display: none; }
.overlay.is-active .overlay__card { transform: translateY(0) scale(1); }

.eyebrow {
  margin: 0 0 8px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.34em;
  text-transform: uppercase;
  color: var(--accent);
}

.title {
  margin: 0 0 14px;
  font-family: var(--font-display);
  font-weight: 900;
  font-size: clamp(38px, 9vw, 64px);
  line-height: 0.98;
  letter-spacing: 0.02em;
  display: flex;
  flex-direction: column;
  align-items: center;
}
.title__line {
  background: linear-gradient(120deg, #fff 0%, #cdd6ff 50%, #fff 100%);
  background-size: 200% 100%;
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  animation: shimmer 5s linear infinite;
}
.title__line--accent {
  background: linear-gradient(120deg, var(--accent) 0%, #fff 45%, var(--accent) 100%);
  background-size: 200% 100%;
  -webkit-background-clip: text;
  background-clip: text;
  filter: drop-shadow(0 0 24px var(--accent-glow));
  animation-delay: -1.2s;
}
@keyframes shimmer {
  0% { background-position: 0% 0; }
  100% { background-position: -200% 0; }
}

.tagline {
  margin: 0 auto 22px;
  max-width: 400px;
  color: var(--muted);
  font-size: 14.5px;
}

.heading {
  margin: 0 0 18px;
  font-family: var(--font-display);
  font-weight: 900;
  font-size: clamp(30px, 7vw, 46px);
  letter-spacing: 0.02em;
  line-height: 1;
}
.heading--over {
  background: linear-gradient(120deg, #fff, #ff7a9a);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 0 24px rgba(255, 90, 120, 0.5));
}

.level-select {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  margin: 0 0 20px;
}
.level-select__label {
  font-size: 11px;
  letter-spacing: 0.28em;
  text-transform: uppercase;
  color: var(--faint);
  font-weight: 600;
}
.level-select__controls {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 4px;
  border-radius: 999px;
  background: rgba(255,255,255,0.05);
  border: 1px solid var(--glass-border);
}
.level-select__value {
  min-width: 34px;
  text-align: center;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 16px;
}
.chip-btn {
  width: 32px; height: 32px;
  border-radius: 50%;
  background: rgba(255,255,255,0.08);
  font-size: 18px;
  line-height: 1;
  transition: background 150ms, transform 150ms;
}
.chip-btn:hover { background: rgba(255,255,255,0.16); }
.chip-btn:active { transform: scale(0.9); }

.btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-width: 160px;
  height: 52px;
  padding: 0 26px;
  border-radius: 999px;
  font-weight: 700;
  font-size: 15px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink);
  background: rgba(255,255,255,0.07);
  border: 1px solid rgba(255,255,255,0.14);
  transition: transform 180ms cubic-bezier(.2,.8,.2,1), background 180ms, box-shadow 180ms;
}
.btn:hover { transform: translateY(-2px); background: rgba(255,255,255,0.12); }
.btn:active { transform: translateY(0) scale(0.98); }
.btn--primary {
  color: #08080f;
  background: linear-gradient(120deg, #fff 0%, var(--accent) 100%);
  border-color: transparent;
  box-shadow: 0 10px 40px var(--accent-soft), 0 0 0 1px rgba(255,255,255,0.2) inset;
}
.btn--primary:hover { box-shadow: 0 14px 50px var(--accent-glow); background: linear-gradient(120deg, #fff 0%, var(--accent) 100%); }
.btn__hint {
  font-size: 10px;
  letter-spacing: 0.12em;
  opacity: 0.6;
  padding: 3px 7px;
  border-radius: 6px;
  border: 1px solid currentColor;
}
.btn-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 12px;
}

.legend {
  display: grid;
  grid-template-columns: repeat(3, auto);
  justify-content: center;
  gap: 8px 20px;
  margin: 26px 0 8px;
  font-size: 12.5px;
  color: var(--muted);
}
.legend div { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.legend--touch { grid-template-columns: 1fr; gap: 6px; }

.best-line {
  margin: 12px 0 0;
  font-size: 12px;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--faint);
}
.best-line strong { color: var(--ink); font-family: var(--font-display); margin-left: 6px; }

.badge {
  display: inline-block;
  margin: -6px 0 16px;
  padding: 6px 14px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.24em;
  text-transform: uppercase;
  color: #08080f;
  background: linear-gradient(90deg, #ffd66b, #ff9f43);
  box-shadow: 0 0 30px rgba(255, 180, 80, 0.5);
  animation: badgeIn 700ms cubic-bezier(.2,.9,.3,1.4) both;
}
@keyframes badgeIn {
  0%   { transform: scale(0.4); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}

.results {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin: 0 0 24px;
}
.result {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 12px 8px;
  border-radius: 14px;
  background: rgba(255,255,255,0.045);
  border: 1px solid rgba(255,255,255,0.07);
}
.result--score { grid-column: 1 / -1; padding: 14px; }
.result__label {
  font-size: 10px;
  letter-spacing: 0.24em;
  text-transform: uppercase;
  color: var(--faint);
  font-weight: 600;
}
.result__value {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 18px;
  font-variant-numeric: tabular-nums;
}
.result--score .result__value {
  font-size: 34px;
  font-weight: 900;
  background: linear-gradient(120deg, #fff, var(--accent));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

/* Floating tetromino decorations on the title screen — one div, box-shadow paints the other cells */
.overlay__decor {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
}
.mino {
  --c: var(--accent);
  position: absolute;
  width: 22px; height: 22px;
  border-radius: 5px;
  background: var(--c);
  opacity: 0.55;
  filter: blur(0.3px) drop-shadow(0 0 16px var(--c));
  animation: floatMino 18s ease-in-out infinite;
}
.mino--t { --c: #c77dff; left: 8%;  top: 18%; box-shadow: -24px 0 var(--c), 24px 0 var(--c), 0 -24px var(--c); animation-delay: -2s; }
.mino--i { --c: #3ee6ff; left: 82%; top: 12%; box-shadow: 0 24px var(--c), 0 48px var(--c), 0 72px var(--c); animation-delay: -7s; animation-duration: 22s; }
.mino--l { --c: #ff9f43; left: 14%; top: 70%; box-shadow: 0 -24px var(--c), 0 -48px var(--c), 24px 0 var(--c); animation-delay: -11s; }
.mino--s { --c: #4ade80; left: 76%; top: 74%; box-shadow: 24px 0 var(--c), 24px -24px var(--c), 48px -24px var(--c); animation-delay: -5s; animation-duration: 20s; }
.mino--o { --c: #ffd166; left: 90%; top: 46%; box-shadow: 24px 0 var(--c), 0 24px var(--c), 24px 24px var(--c); animation-delay: -14s; }
.mino--z { --c: #ff5c7a; left: 4%;  top: 44%; box-shadow: 24px 0 var(--c), 24px 24px var(--c), 48px 24px var(--c); animation-delay: -9s; animation-duration: 24s; }
.mino--j { --c: #5b8cff; left: 60%; top: 88%; box-shadow: 24px 0 var(--c), 48px 0 var(--c), 0 -24px var(--c); animation-delay: -17s; }
@keyframes floatMino {
  0%   { transform: translate3d(0, 0, 0) rotate(0deg); }
  33%  { transform: translate3d(30px, -40px, 0) rotate(90deg); }
  66%  { transform: translate3d(-20px, -70px, 0) rotate(180deg); }
  100% { transform: translate3d(0, 0, 0) rotate(360deg); }
}

/* ---------- Screen shake driver ---------- */

.board-frame.shake { animation: none; }

/* ---------- Responsive ---------- */

[data-touch] { display: none; }
body.has-touch [data-touch] { display: grid; }
body.has-touch [data-desktop] { display: none; }
body.has-touch .card--keys { display: none; }

@media (pointer: coarse) {
  .touch { display: flex; }
  .card--keys { display: none; }
  .stage { grid-template-areas: "hold board next" "stats board next"; }
}
body.has-touch .touch { display: flex; }

@media (max-width: 760px), (max-height: 540px) {
  .app { gap: 4px; padding-left: max(10px, env(safe-area-inset-left)); padding-right: max(10px, env(safe-area-inset-right)); }
  .brand__name { font-size: 10.5px; }
  .icon-btn { width: 34px; height: 34px; }
  .stage {
    grid-template-columns: auto minmax(0, 1fr) auto;
    grid-template-rows: auto minmax(0, 1fr);
    grid-template-areas:
      "hold  stats next"
      "board board board";
    gap: 8px;
    padding: 2px 0 4px;
  }
  .card { padding: 8px 10px 9px; border-radius: 14px; }
  .card__title { font-size: 9px; margin-bottom: 6px; letter-spacing: 0.24em; }
  .card--keys { display: none; }
  .card--stats {
    display: grid;
    grid-template-columns: 1fr auto auto;
    align-items: center;
    gap: 0 14px;
    padding: 8px 14px;
  }
  .card--stats .stat { margin: 0; }
  .card--stats .stat--time,
  .card--stats .stat--best { display: none; }
  .stat__label { font-size: 9px; letter-spacing: 0.2em; }
  .stat__value { font-size: 16px; }
  .stat--score .stat__value { font-size: 21px; }
  .touch { padding-bottom: 0; }
  .touch-btn { width: 54px; height: 54px; border-radius: 17px; }
  .touch-btn--big { height: 54px; }
  .overlay__card { padding: 26px 22px 24px; border-radius: 22px; }
  .results { grid-template-columns: repeat(4, 1fr); gap: 8px; }
  .result { padding: 9px 6px; }
  .result__value { font-size: 15px; }
  .result--score .result__value { font-size: 28px; }
  .legend { grid-template-columns: repeat(2, auto); }
}

@media (max-width: 400px) {
  .card--stats { gap: 0 8px; padding: 8px 10px; }
  .card--stats .stat--lines { display: none; }
  .touch__cluster { gap: 8px; }
  .touch-btn { width: 50px; height: 50px; }
  .touch-btn--big { height: 50px; }
}

/* Landscape phones: float the touch clusters over the side panels */
@media (pointer: coarse) and (orientation: landscape) and (max-height: 540px) {
  .stage {
    grid-template-columns: minmax(120px, 160px) minmax(0, 1fr) minmax(120px, 160px);
    grid-template-rows: auto minmax(0, 1fr);
    grid-template-areas: "hold board next" "stats board next";
  }
  .card--stats { display: block; }
  .card--stats .stat { margin-bottom: 6px; }
  .card--stats .stat--time, .card--stats .stat--best { display: none; }
  .touch {
    position: fixed;
    left: max(10px, env(safe-area-inset-left));
    right: max(10px, env(safe-area-inset-right));
    bottom: max(10px, env(safe-area-inset-bottom));
    pointer-events: none;
    z-index: 5;
  }
  .touch__cluster { pointer-events: auto; }
  .touch-btn { width: 46px; height: 46px; border-radius: 14px; }
  .touch-btn--big { height: 46px; }
}

@media (prefers-reduced-motion: reduce) {
  .bg__blob, .mino, .title__line { animation: none; }
}
