/* ==========================================================================
   NEOTRIS — styles
   ========================================================================== */

:root {
  --bg: #05060c;
  --bg-2: #0a0d19;
  --panel: rgba(255, 255, 255, .045);
  --panel-strong: rgba(255, 255, 255, .075);
  --stroke: rgba(255, 255, 255, .22);
  --stroke-strong: rgba(255, 255, 255, .30);
  --stroke-soft: rgba(255, 255, 255, .10);
  --text: #e9eefb;
  /* Both muted tones clear 4.5:1 on every surface in the app; the previous
     values sat between 2.5:1 and 3.8:1. */
  --muted: #a3aec5;
  --muted-2: #9aa6bf;
  --accent: #22d3ee;
  --accent-2: #a78bfa;
  --accent-3: #f472b6;
  --gold: #fbbf24;
  --danger: #f87171;
  --radius: 16px;
  --radius-sm: 11px;
  --shadow: 0 18px 48px -18px rgba(0, 0, 0, .85);
  --font-display: 'Orbitron', 'Inter', system-ui, sans-serif;
  --font-ui: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, 'SF Mono', Menlo, monospace;
  --rail-w: 186px;
  --shell-w: min(1440px, 100%);
}

* { box-sizing: border-box; }

/* The layout sets `display` on several elements that also toggle [hidden];
   without this the attribute would be silently ignored. */
[hidden] { display: none !important; }

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

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

kbd {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.55em;
  padding: .18em .42em;
  border-radius: 6px;
  border: 1px solid var(--stroke);
  border-bottom-width: 2px;
  background: rgba(255, 255, 255, .07);
  font-family: var(--font-ui);
  font-size: .74em;
  font-weight: 600;
  color: #cfd8ea;
  line-height: 1;
}

button { font-family: inherit; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 6px;
}

/* ---------- background ---------------------------------------------------- */

.aurora {
  position: fixed;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
  z-index: 0;
  background:
    radial-gradient(120% 80% at 50% -10%, #131a33 0%, transparent 60%),
    linear-gradient(180deg, #070a14 0%, #05060c 100%);
}

.aurora__blob {
  position: absolute;
  border-radius: 50%;
  filter: blur(90px);
  opacity: .34;
  animation: drift 26s ease-in-out infinite alternate;
}
.aurora__blob--a { width: 46vmax; height: 46vmax; left: -12vmax; top: -14vmax; background: #0e7490; }
.aurora__blob--b { width: 40vmax; height: 40vmax; right: -10vmax; top: 6vmax; background: #6d28d9; animation-delay: -8s; }
.aurora__blob--c { width: 36vmax; height: 36vmax; left: 30vmax; bottom: -18vmax; background: #be185d; opacity: .22; animation-delay: -15s; }

.aurora__grid {
  position: absolute;
  inset: -2px;
  background-image:
    linear-gradient(rgba(148, 163, 184, .05) 1px, transparent 1px),
    linear-gradient(90deg, rgba(148, 163, 184, .05) 1px, transparent 1px);
  background-size: 46px 46px;
  mask-image: radial-gradient(75% 60% at 50% 40%, #000 20%, transparent 100%);
  -webkit-mask-image: radial-gradient(75% 60% at 50% 40%, #000 20%, transparent 100%);
}

@keyframes drift {
  from { transform: translate3d(0, 0, 0) scale(1); }
  to   { transform: translate3d(4vmax, 3vmax, 0) scale(1.12); }
}

/* ---------- app shell ----------------------------------------------------- */

.app {
  position: relative;
  z-index: 1;
  height: 100dvh;
  display: grid;
  grid-template-rows: auto 1fr auto;
  padding:
    max(clamp(8px, 1.4vh, 18px), env(safe-area-inset-top, 0px))
    max(clamp(10px, 2vw, 28px), env(safe-area-inset-right, 0px))
    max(clamp(8px, 1.4vh, 16px), env(safe-area-inset-bottom, 0px))
    max(clamp(10px, 2vw, 28px), env(safe-area-inset-left, 0px));
  gap: clamp(6px, 1.2vh, 14px);
}

.app.is-levelup::after {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(60% 50% at 50% 50%, rgba(34, 211, 238, .16), transparent 70%);
  animation: levelflash .7s ease-out forwards;
  z-index: 5;
}
@keyframes levelflash { from { opacity: 1; } to { opacity: 0; } }

/* ---------- topbar -------------------------------------------------------- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-width: 0;
  width: 100%;
  max-width: var(--shell-w);
  margin: 0 auto;
}

.brand { display: flex; align-items: center; gap: 12px; min-width: 0; flex: 0 1 auto; overflow: hidden; }
.brand__text { min-width: 0; }
.brand__text h1 { white-space: nowrap; overflow: hidden; }

.brand__mark {
  width: 34px;
  height: 34px;
  flex: none;
  filter: drop-shadow(0 0 14px rgba(34, 211, 238, .45));
}
.brand__mark rect:nth-child(1) { fill: #22d3ee; }
.brand__mark rect:nth-child(2) { fill: #818cf8; }
.brand__mark rect:nth-child(3) { fill: #f472b6; }
.brand__mark rect:nth-child(4) { fill: #34d399; }

.brand__text h1 {
  margin: 0;
  font-family: var(--font-display);
  font-size: clamp(16px, 2.1vw, 23px);
  font-weight: 900;
  letter-spacing: .16em;
  background: linear-gradient(92deg, #e9eefb, #7dd3fc 42%, #c4b5fd 78%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.brand__text p {
  margin: 1px 0 0;
  font-size: 10.5px;
  letter-spacing: .22em;
  text-transform: uppercase;
  color: var(--muted-2);
}

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

.iconbtn {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border-radius: 11px;
  border: 1px solid var(--stroke-strong);
  background: var(--panel);
  color: #b9c4da;
  cursor: pointer;
  transition: background .16s, color .16s, transform .12s, border-color .16s;
  backdrop-filter: blur(10px);
}
.iconbtn:hover { background: var(--panel-strong); color: #fff; border-color: rgba(255, 255, 255, .2); }
.iconbtn:active { transform: scale(.94); }
.iconbtn svg { width: 19px; height: 19px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.iconbtn svg .cross { opacity: 0; }
.iconbtn.is-muted { color: var(--danger); border-color: rgba(248, 113, 113, .35); }
.iconbtn.is-muted svg .wave { opacity: 0; }
.iconbtn.is-muted svg .cross { opacity: 1; }
.iconbtn--pause { display: none; }

/* ---------- stage --------------------------------------------------------- */

.stage {
  display: grid;
  grid-template-columns: var(--rail-w) minmax(0, 1fr) var(--rail-w);
  align-items: stretch;
  gap: clamp(10px, 1.6vw, 22px);
  min-height: 0;
  width: 100%;
  max-width: var(--shell-w);
  margin: 0 auto;
}

.rail {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-width: 0;
}
.rail--left, .rail--right { justify-content: flex-start; }
.card--goals { margin-top: auto; }

/* ---------- cards --------------------------------------------------------- */

.card {
  position: relative;
  border-radius: var(--radius);
  border: 1px solid var(--stroke);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, .055), rgba(255, 255, 255, .015)),
    rgba(10, 13, 25, .6);
  backdrop-filter: blur(14px);
  box-shadow: var(--shadow);
  padding: 12px;
  overflow: hidden;
}
.card::before {
  content: '';
  position: absolute;
  inset: 0 0 auto 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, .28), transparent);
}

.card__title {
  margin: 0 0 8px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .2em;
  text-transform: uppercase;
  color: var(--muted-2);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}
.card__title kbd { font-size: 9px; }

.card--next { flex: 0 1 auto; display: flex; flex-direction: column; min-height: 0; }
.card--next canvas { flex: none; width: 100%; height: clamp(210px, 32vh, 360px); display: block; }

.minicanvas-wrap { position: relative; }
.card--hold canvas { width: 100%; height: 78px; display: block; }

.hold-lock {
  position: absolute;
  right: 0;
  bottom: -2px;
  font-size: 8.5px;
  letter-spacing: .18em;
  text-transform: uppercase;
  color: var(--danger);
  opacity: .8;
}

/* ---------- stats --------------------------------------------------------- */

.card--stats { display: flex; flex-direction: column; gap: 10px; }

.stat { display: flex; flex-direction: column; gap: 2px; min-width: 0; }

.stat__label {
  font-size: 10.5px;
  letter-spacing: .2em;
  text-transform: uppercase;
  color: var(--muted-2);
  font-weight: 600;
}

.stat__value {
  font-family: var(--font-mono);
  font-size: 26px;
  font-weight: 700;
  line-height: 1.05;
  letter-spacing: -.02em;
  color: #f2f6ff;
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}
.stat__value--sm { font-size: 19px; }
.stat__value--xs { font-size: 14px; color: #c3cddf; white-space: nowrap; overflow-wrap: normal; }

.stat--score { position: relative; }
.stat__delta {
  position: absolute;
  right: 0;
  top: 12px;
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 700;
  color: var(--accent);
  opacity: 0;
  pointer-events: none;
}
.stat__delta.is-pop { animation: deltaPop 1s ease-out forwards; }
@keyframes deltaPop {
  0%   { opacity: 0; transform: translateY(6px); }
  18%  { opacity: 1; transform: translateY(0); }
  100% { opacity: 0; transform: translateY(-16px); }
}

.stat-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.stat-row--muted .stat__label { color: var(--muted-2); }

.level-progress {
  height: 4px;
  border-radius: 3px;
  background: rgba(255, 255, 255, .07);
  overflow: hidden;
}
.level-progress__bar {
  height: 100%;
  width: 0;
  border-radius: 3px;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  box-shadow: 0 0 12px rgba(34, 211, 238, .55);
  transition: width .25s ease;
}

.stat-row--three { grid-template-columns: auto auto minmax(0, 1fr); gap: 12px; }
.stat__value--best { color: var(--gold); white-space: nowrap; overflow-wrap: normal; }

.goals { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 7px; }
.goals li {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  font-size: 11.5px;
  color: var(--muted);
}
.goals b { font-family: var(--font-mono); font-size: 13px; color: #dbe4f5; font-variant-numeric: tabular-nums; }

/* ---------- playfield ----------------------------------------------------- */

.playfield {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
  min-height: 0;
}

.playfield__frame {
  position: relative;
  border-radius: 14px;
  background: #06080f;
  box-shadow:
    0 0 0 1px rgba(255, 255, 255, .10),
    0 0 0 6px rgba(10, 14, 26, .85),
    0 0 44px -6px rgba(34, 211, 238, .28),
    0 30px 70px -30px rgba(0, 0, 0, .95),
    inset 0 0 60px -20px rgba(34, 211, 238, .18);
  overflow: hidden;
  touch-action: none;
  transition: box-shadow .3s ease;
}

.playfield__frame.is-danger {
  box-shadow:
    0 0 0 3px rgba(248, 113, 113, .85),
    0 0 0 8px rgba(26, 10, 14, .9),
    0 0 72px -2px rgba(248, 113, 113, .65),
    0 30px 70px -30px rgba(0, 0, 0, .95),
    inset 0 0 90px -30px rgba(248, 113, 113, .45);
  animation: dangerPulse 1.1s ease-in-out infinite;
}
@keyframes dangerPulse { 50% { filter: brightness(1.08); } }

#board-canvas { display: block; border-radius: 14px; }
.playfield__frame:focus { outline: none; }
.playfield__frame:focus-visible { outline: 2px solid var(--accent); outline-offset: 4px; }

/* ---------- toasts -------------------------------------------------------- */

.toasts {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  gap: 6px;
  pointer-events: none;
  padding: 30% 8px 0;
}

/* Each toast carries its own scrim: it has to stay readable when it lands on
   top of the stack, which is most of the game. */
.toast {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
  padding: 5px 14px 6px;
  border-radius: 12px;
  background: rgba(4, 6, 12, .78);
  box-shadow: 0 0 0 1px rgba(255, 255, 255, .12), 0 12px 30px -14px #000;
  backdrop-filter: blur(6px);
  animation: toastIn .34s cubic-bezier(.2, 1.4, .4, 1) both;
  text-align: center;
}
.toast.is-out { animation: toastOut .4s ease-in forwards; }

.toast__main {
  font-family: var(--font-display);
  font-weight: 900;
  font-size: clamp(15px, 4.2vmin, 30px);
  letter-spacing: .1em;
  color: #fff;
  text-shadow: 0 0 22px rgba(255, 255, 255, .45), 0 4px 18px rgba(0, 0, 0, .8);
}
.toast__sub {
  font-size: clamp(10px, 1.8vmin, 12px);
  font-weight: 700;
  letter-spacing: .16em;
  color: #fde68a;                 /* 9.4:1 on the toast scrim */
}

/* Solid fills, not background-clip text: gradient text has no fill of its own
   and disappears over minos. */
.toast--tetris .toast__main { color: #a5f3fc; text-shadow: 0 0 20px rgba(103, 232, 249, .8), 0 2px 10px #000; }
.toast--tspin .toast__main  { color: #e9d5ff; text-shadow: 0 0 20px rgba(216, 180, 254, .8), 0 2px 10px #000; }
.toast--perfect .toast__main { color: #fde68a; text-shadow: 0 0 22px rgba(251, 191, 36, .9), 0 2px 10px #000; }
.toast--level .toast__main { color: #7dd3fc; }
.toast--spin .toast__main { color: #e9d5ff; font-size: clamp(13px, 3.2vmin, 22px); }
.toast--line .toast__main { font-size: clamp(13px, 3.2vmin, 22px); color: #dbeafe; }

@keyframes toastIn {
  from { opacity: 0; transform: translateY(14px) scale(.86); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}
@keyframes toastOut {
  to { opacity: 0; transform: translateY(-22px) scale(1.04); }
}

.combo-rail {
  position: absolute;
  left: 8px;
  top: 10px;
  display: flex;
  align-items: baseline;
  gap: 5px;
  padding: 3px 9px;
  border-radius: 999px;
  background: rgba(4, 6, 12, .8);
  border: 1px solid rgba(167, 139, 250, .45);
  pointer-events: none;
  transform-origin: left center;
}
.combo-rail__num {
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 13px;
  line-height: 1;
  color: #ddd6fe;
}
.combo-rail__label {
  font-size: 9px;
  letter-spacing: .2em;
  color: #c4b5fd;
  font-weight: 700;
}
.combo-rail.is-pop { animation: comboPop .45s cubic-bezier(.2, 1.5, .4, 1); }
@keyframes comboPop {
  0% { transform: scale(1.28); }
  100% { transform: scale(1); }
}

.b2b-flag {
  position: absolute;
  right: 8px;
  top: 10px;
  font-size: 9px;
  font-weight: 800;
  letter-spacing: .2em;
  color: var(--gold);
  background: rgba(251, 191, 36, .12);
  border: 1px solid rgba(251, 191, 36, .38);
  border-radius: 999px;
  padding: 3px 8px;
  pointer-events: none;
  text-shadow: 0 0 12px rgba(251, 191, 36, .6);
}
.b2b-flag b { font-family: var(--font-mono); }

/* ---------- misc components ----------------------------------------------- */

.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  margin: -1px; padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

.hold-empty {
  position: absolute;
  inset: 0;
  margin: 0;
  display: grid;
  place-items: center;
  text-align: center;
  font-size: 10.5px;
  line-height: 1.5;
  color: var(--muted-2);
  padding: 0 6px;
  pointer-events: none;
}
.hold-empty kbd { font-size: 9.5px; }
.minicanvas-wrap.has-piece .hold-empty { display: none; }

.touch-coach {
  position: fixed;
  flex-direction: column;
  /* Centred with auto margins, not translateX: the entry animation sets its
     own transform and would otherwise wipe the centring out. */
  left: 0;
  right: 0;
  margin: 0 auto;
  bottom: calc(env(safe-area-inset-bottom, 0px) + 96px);
  z-index: 30;
  display: flex;
  gap: 12px;
  width: min(340px, calc(100vw - 24px));
  padding: 12px 14px;
  border-radius: 16px;
  border: 1px solid var(--stroke);
  background: rgba(9, 12, 22, .94);
  box-shadow: 0 24px 60px -22px #000;
  font-size: 11.5px;
  color: var(--muted);
  animation: toastIn .3s ease both;
}
.touch-coach__title {
  margin: 0;
  font-family: var(--font-display);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: #a5f3fc;
  text-align: center;
}
.touch-coach__list { margin: 0; padding: 0; list-style: none; display: grid; gap: 7px; }
.touch-coach__list li { display: grid; grid-template-columns: 20px 1fr; align-items: center; gap: 8px; }
.touch-coach b { color: var(--accent); font-size: 15px; text-align: center; }
.touch-coach__actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 2px; }
.touch-coach__actions .btn { padding: 12px 10px; font-size: 13px; }
.touch-coach__note { margin: 0; text-align: center; font-size: 10.5px; color: var(--muted-2); }

/* ---------- overlay ------------------------------------------------------- */

.overlay {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(4, 6, 12, .72);
  backdrop-filter: blur(14px);
  opacity: 0;
  transition: opacity .2s ease;
  overflow-y: auto;
}
.overlay.is-open { opacity: 1; }
.overlay.is-closing { opacity: 0; }

.overlay__panel {
  width: min(430px, 100%);
  max-height: calc(100dvh - 36px);
  overflow-y: auto;
  border-radius: 22px;
  border: 1px solid var(--stroke);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, .07), rgba(255, 255, 255, .02)),
    rgba(9, 12, 22, .92);
  box-shadow: 0 40px 90px -30px rgba(0, 0, 0, .95), 0 0 0 1px rgba(255, 255, 255, .04);
  padding: clamp(20px, 4vw, 30px);
  text-align: center;
  animation: panelIn .3s cubic-bezier(.2, 1.2, .4, 1) both;
  scrollbar-width: thin;
}
.overlay__panel--settings, .overlay__panel--help { width: min(520px, 100%); text-align: left; }

@keyframes panelIn {
  from { opacity: 0; transform: translateY(18px) scale(.96); }
  to   { opacity: 1; transform: none; }
}

.ov-badge {
  display: inline-block;
  font-size: 9.5px;
  font-weight: 700;
  letter-spacing: .22em;
  text-transform: uppercase;
  color: var(--muted);
  border: 1px solid var(--stroke);
  background: rgba(255, 255, 255, .04);
  border-radius: 999px;
  padding: 4px 12px;
  margin-bottom: 12px;
}
.ov-badge--gold {
  color: #1a1204;
  background: linear-gradient(92deg, #fde68a, #fbbf24);
  border-color: transparent;
  box-shadow: 0 0 24px rgba(251, 191, 36, .5);
}

.ov-title {
  margin: 0 0 6px;
  font-family: var(--font-display);
  font-weight: 900;
  font-size: clamp(30px, 7vw, 46px);
  letter-spacing: .14em;
  background: linear-gradient(92deg, #e9eefb, #67e8f9 45%, #c4b5fd 85%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.ov-title--sm { font-size: clamp(20px, 4.4vw, 27px); letter-spacing: .1em; }

.ov-sub {
  margin: 0 0 18px;
  font-size: 12px;
  color: var(--muted);
  line-height: 1.6;
}

.ov-score {
  font-family: var(--font-mono);
  font-size: clamp(38px, 9vw, 56px);
  font-weight: 700;
  line-height: 1;
  margin: 6px 0 18px;
  color: #fff;
  text-shadow: 0 0 30px rgba(34, 211, 238, .45);
  font-variant-numeric: tabular-nums;
}

.ov-best {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  border-radius: 12px;
  border: 1px solid var(--stroke-soft);
  background: rgba(255, 255, 255, .03);
  margin-bottom: 14px;
}
.ov-best span { font-size: 10px; letter-spacing: .2em; text-transform: uppercase; color: var(--muted-2); }
.ov-best b { font-family: var(--font-mono); font-size: 17px; color: var(--gold); }

.ov-stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-bottom: 20px;
}
.ov-stats--grid { grid-template-columns: repeat(4, 1fr); }
.ov-stats > div {
  padding: 9px 7px;
  min-height: 58px;
  justify-content: flex-end;
  border-radius: 11px;
  border: 1px solid var(--stroke-soft);
  background: rgba(255, 255, 255, .03);
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
}
.ov-stats span { font-size: 10px; letter-spacing: .1em; text-transform: uppercase; color: var(--muted-2); line-height: 1.3; }
.ov-stats b { font-family: var(--font-mono); font-size: 15px; color: #e8eefc; }

.ov-field {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 14px;
  border-radius: 12px;
  border: 1px solid var(--stroke-soft);
  background: rgba(255, 255, 255, .03);
  margin-bottom: 16px;
}
.ov-field span { font-size: 12px; color: var(--muted); }
.ov-field select {
  appearance: none;
  background: rgba(255, 255, 255, .07);
  border: 1px solid var(--stroke);
  color: var(--text);
  border-radius: 9px;
  padding: 7px 30px 7px 12px;
  font-family: var(--font-mono);
  font-size: 14px;
  cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12'%3E%3Cpath d='M2 4.5L6 8.5L10 4.5' stroke='%238e9ab4' stroke-width='1.6' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 9px center;
  background-size: 12px;
}
.ov-field select option { background: #0b0f1c; }

.ov-links {
  display: flex;
  gap: 8px;
  justify-content: center;
  margin-top: 12px;
  flex-wrap: wrap;
}
.ov-links--split { justify-content: space-between; }

.ov-tip {
  margin: 16px 0 0;
  font-size: 11px;
  color: var(--muted-2);
  line-height: 1.6;
}
.ov-tip span { color: var(--muted); }

/* ---------- buttons ------------------------------------------------------- */

.btn {
  appearance: none;
  border: 1px solid var(--stroke-strong);
  background: rgba(255, 255, 255, .05);
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  padding: 10px 18px;
  border-radius: 11px;
  cursor: pointer;
  transition: transform .12s, background .16s, border-color .16s, box-shadow .16s;
}
.btn:hover { background: rgba(255, 255, 255, .1); border-color: rgba(255, 255, 255, .22); }
.btn:active { transform: translateY(1px) scale(.99); }

.btn--primary {
  border: none;
  background: linear-gradient(92deg, #22d3ee, #818cf8 55%, #c084fc);
  color: #05070f;
  font-weight: 800;
  letter-spacing: .06em;
  box-shadow: 0 12px 34px -12px rgba(34, 211, 238, .9), inset 0 1px 0 rgba(255, 255, 255, .5);
}
.btn--primary:hover { filter: brightness(1.08); background: linear-gradient(92deg, #22d3ee, #818cf8 55%, #c084fc); }

.btn--lg { width: 100%; padding: 14px 22px; font-size: 15px; border-radius: 13px; }

.btn--ghost { background: transparent; color: var(--muted); font-size: 12px; padding: 8px 13px; }
.btn--ghost:hover { color: var(--text); background: rgba(255, 255, 255, .06); }
.btn--danger { color: #fca5a5; }
.btn--danger:hover { color: #fff; background: rgba(248, 113, 113, .18); border-color: rgba(248, 113, 113, .4); }

/* ---------- help & settings ---------------------------------------------- */

.keytable { display: flex; flex-direction: column; gap: 2px; margin-bottom: 18px; }
.keytable__row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 7px 10px;
  border-radius: 9px;
  font-size: 12.5px;
  color: var(--muted);
}
.keytable__row:nth-child(odd) { background: rgba(255, 255, 255, .028); }
.keytable__row span:last-child { display: flex; gap: 4px; flex: none; }

.help-touch h3, .help-scoring h3 {
  margin: 0 0 8px;
  font-size: 10px;
  letter-spacing: .2em;
  text-transform: uppercase;
  color: var(--muted-2);
}
.help-touch { margin-bottom: 18px; }
.help-touch ul { margin: 0; padding-left: 16px; color: var(--muted); font-size: 12px; line-height: 1.8; }

.scoretable { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 12px; }
.scoretable > div {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  font-size: 12px;
  color: var(--muted);
  padding: 4px 0;
  border-bottom: 1px solid rgba(255, 255, 255, .04);
}
.scoretable b { font-family: var(--font-mono); color: #dbe4f5; }
.fineprint { font-size: 10.5px; color: var(--muted-2); margin: 12px 0 18px; }

.settings { display: flex; flex-direction: column; gap: 4px; margin-bottom: 8px; }

.setrow {
  display: grid;
  grid-template-columns: 1fr 168px;
  align-items: center;
  gap: 12px;
  padding: 9px 4px;
  border-bottom: 1px solid rgba(255, 255, 255, .045);
}
.setrow label { display: flex; flex-direction: column; gap: 2px; cursor: pointer; }
.setrow label span { font-size: 13px; color: var(--text); font-weight: 500; }
.setrow label em { font-style: normal; font-size: 10.5px; color: var(--muted-2); line-height: 1.4; }
.setrow--toggle { grid-template-columns: 1fr auto; }

.setrow__control { display: flex; align-items: center; gap: 10px; }
.setrow__control output {
  font-family: var(--font-mono);
  font-size: 11.5px;
  color: var(--accent);
  min-width: 44px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

input[type=range] {
  appearance: none;
  -webkit-appearance: none;
  width: 100%;
  height: 22px;
  background: transparent;
  cursor: pointer;
}
input[type=range]::-webkit-slider-runnable-track {
  height: 4px;
  border-radius: 3px;
  background: rgba(255, 255, 255, .12);
}
input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  margin-top: -6px;
  border-radius: 50%;
  background: linear-gradient(180deg, #e7f9ff, #22d3ee);
  box-shadow: 0 0 12px rgba(34, 211, 238, .8);
  border: none;
}
input[type=range]::-moz-range-track { height: 4px; border-radius: 3px; background: rgba(255, 255, 255, .12); }
input[type=range]::-moz-range-thumb {
  width: 16px; height: 16px; border: none; border-radius: 50%;
  background: linear-gradient(180deg, #e7f9ff, #22d3ee);
  box-shadow: 0 0 12px rgba(34, 211, 238, .8);
}

.switch {
  position: relative;
  width: 46px;
  height: 26px;
  border-radius: 999px;
  border: 1px solid var(--stroke-strong);
  background: rgba(255, 255, 255, .06);
  cursor: pointer;
  transition: background .2s, border-color .2s;
  padding: 0;
  flex: none;
}
.switch i {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #8e9ab4;
  transition: transform .2s cubic-bezier(.2, 1.3, .4, 1), background .2s;
}
.switch.is-on { background: linear-gradient(92deg, rgba(34, 211, 238, .35), rgba(167, 139, 250, .35)); border-color: rgba(34, 211, 238, .55); }
.switch.is-on i { transform: translateX(20px); background: linear-gradient(180deg, #e7f9ff, #22d3ee); box-shadow: 0 0 12px rgba(34, 211, 238, .8); }

/* ---------- touch pad ----------------------------------------------------- */

.touchpad { display: none; }

.tbtn {
  position: relative;
  display: grid;
  place-items: center;
  gap: 2px;
  border-radius: 14px;
  border: 1px solid var(--stroke);
  background: linear-gradient(180deg, rgba(255, 255, 255, .075), rgba(255, 255, 255, .02));
  color: #cdd8ec;
  height: 56px;
  cursor: pointer;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  transition: background .12s, transform .08s;
}
.tbtn svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
.tbtn i { font-style: normal; font-size: 11px; letter-spacing: .14em; text-transform: uppercase; color: var(--muted-2); }
.tbtn.is-down { background: rgba(34, 211, 238, .22); transform: scale(.96); color: #fff; }
.tbtn--accent {
  background: linear-gradient(180deg, rgba(34, 211, 238, .28), rgba(129, 140, 248, .18));
  border-color: rgba(34, 211, 238, .4);
  color: #eafcff;
}
.tbtn--accent i { color: rgba(234, 252, 255, .75); }

/* ---------- hint bar ------------------------------------------------------ */

.hintbar {
  width: 100%;
  max-width: var(--shell-w);
  margin: 0 auto;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 6px 16px;
  font-size: 11px;
  color: var(--muted-2);
}
.hintbar span { display: inline-flex; align-items: center; gap: 4px; }

/* ---------- responsive ---------------------------------------------------- */

/* ---------- start screen ---------------------------------------------------
   The title screen is deliberately NOT a dialog: no card, no border, no
   shadow. It sits directly on a deeper backdrop so it reads as a screen you
   arrived at rather than a panel that interrupted you.
   -------------------------------------------------------------------------- */

.overlay[data-kind="start"] {
  background: radial-gradient(120% 90% at 50% 0%, rgba(14, 22, 46, .82), rgba(3, 5, 11, .93) 70%);
  backdrop-filter: blur(22px);
}

.overlay[data-kind="start"] .overlay__panel {
  width: min(760px, 100%);
  background: none;
  border: none;
  box-shadow: none;
  padding: clamp(12px, 3vh, 28px) clamp(12px, 3vw, 24px);
  text-align: center;
}

.start { display: flex; flex-direction: column; gap: clamp(16px, 3.2vh, 30px); }

/* hero -------------------------------------------------------------------- */

.start__hero { display: flex; flex-direction: column; align-items: center; gap: 10px; }

.start__mark {
  width: clamp(44px, 8vh, 62px);
  height: clamp(44px, 8vh, 62px);
  filter: drop-shadow(0 0 26px rgba(34, 211, 238, .55));
  animation: markIn .6s cubic-bezier(.2, 1.3, .4, 1) both;
}
.start__mark rect:nth-child(1) { fill: #22d3ee; }
.start__mark rect:nth-child(2) { fill: #818cf8; }
.start__mark rect:nth-child(3) { fill: #f472b6; }
.start__mark rect:nth-child(4) { fill: #34d399; }

@keyframes markIn {
  from { opacity: 0; transform: translateY(-10px) scale(.86); }
  to   { opacity: 1; transform: none; }
}

.start__title {
  margin: 0;
  font-size: clamp(38px, 9vw, 68px);
  letter-spacing: .17em;
  text-indent: .17em;                       /* balance the tracking on the right */
  line-height: 1;
}

.start__tagline {
  margin: 0;
  max-width: 44ch;
  font-size: clamp(12px, 1.5vw, 14px);
  line-height: 1.6;
  color: var(--muted);
}

/* mode choice ------------------------------------------------------------- */

.start__modes {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.modecard {
  position: relative;
  display: grid;
  grid-template-columns: auto 1fr;
  grid-template-rows: auto auto;
  align-items: center;
  gap: 2px 12px;
  text-align: left;
  padding: 16px 18px;
  border-radius: 16px;
  border: 1px solid var(--stroke);
  background: linear-gradient(180deg, rgba(255, 255, 255, .05), rgba(255, 255, 255, .015));
  color: var(--text);
  cursor: pointer;
  transition: border-color .16s, background .16s, transform .12s;
}
.modecard:hover { background: rgba(255, 255, 255, .08); transform: translateY(-1px); }
.modecard:active { transform: translateY(0); }

.modecard__icon {
  grid-row: 1 / span 2;
  width: 30px;
  height: 30px;
  fill: none;
  stroke: var(--muted);
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
  transition: stroke .16s;
}

.modecard b { font-size: 15px; font-weight: 700; align-self: end; }
.modecard em {
  font-style: normal;
  font-size: 11.5px;
  color: var(--muted);
  line-height: 1.45;
  align-self: start;
}

.modecard__tick {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 1.5px solid var(--stroke-strong);
  transition: border-color .16s, background .16s;
}

.modecard.is-on {
  border-color: rgba(34, 211, 238, .7);
  background: linear-gradient(150deg, rgba(34, 211, 238, .16), rgba(167, 139, 250, .10));
  box-shadow: 0 0 0 1px rgba(34, 211, 238, .3), 0 16px 40px -22px rgba(34, 211, 238, .9);
}
.modecard.is-on b { color: #a5f3fc; }
.modecard.is-on .modecard__icon { stroke: #67e8f9; }
.modecard.is-on .modecard__tick {
  border-color: transparent;
  background: linear-gradient(140deg, #67e8f9, #a78bfa);
}
.modecard.is-on .modecard__tick::after {
  content: '';
  position: absolute;
  left: 5px;
  top: 3px;
  width: 4px;
  height: 8px;
  border-right: 2px solid #05070f;
  border-bottom: 2px solid #05070f;
  transform: rotate(42deg);
}

/* play row ---------------------------------------------------------------- */

.start__go {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: stretch;
  gap: 12px;
}

.start__level {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 16px;
  border-radius: 13px;
  border: 1px solid var(--stroke);
  background: rgba(255, 255, 255, .03);
  white-space: nowrap;
}
.start__level span { font-size: 12px; color: var(--muted); }
.start__level select {
  appearance: none;
  background: rgba(255, 255, 255, .08);
  border: 1px solid var(--stroke-strong);
  color: var(--text);
  border-radius: 9px;
  padding: 7px 30px 7px 12px;
  font-family: var(--font-mono);
  font-size: 14px;
  cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12'%3E%3Cpath d='M2 4.5L6 8.5L10 4.5' stroke='%23a3aec5' stroke-width='1.6' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 9px center;
  background-size: 12px;
}
.start__level select option { background: #0b0f1c; }

.start__play {
  padding: 16px 24px;
  font-size: 16px;
  border-radius: 13px;
  letter-spacing: .08em;
}

/* records ----------------------------------------------------------------- */

.start__records {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  padding-top: clamp(4px, 1.5vh, 12px);
  border-top: 1px solid var(--stroke-soft);
}

.rec {
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 11px 12px;
  border-radius: 13px;
  background: rgba(255, 255, 255, .035);
  text-align: left;
  min-width: 0;
}
.rec__k {
  font-size: 9.5px;
  letter-spacing: .18em;
  text-transform: uppercase;
  color: var(--muted-2);
  font-weight: 700;
}
.rec__v {
  font-family: var(--font-mono);
  font-size: 19px;
  line-height: 1.1;
  color: var(--gold);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.rec__s {
  font-style: normal;
  font-size: 10.5px;
  color: var(--muted-2);
  line-height: 1.35;
}
.rec:last-child .rec__v { color: #cfe1ff; }

.start__links { margin-top: 0; }

@media (max-width: 620px) {
  .start__modes { grid-template-columns: 1fr; }
  .start__go { grid-template-columns: 1fr; }
  .start__level { justify-content: space-between; padding: 10px 14px; }
  .start__records { grid-template-columns: 1fr; gap: 6px; }
  .rec { flex-direction: row; align-items: baseline; gap: 10px; padding: 9px 12px; }
  .rec__k { flex: 0 0 96px; }
  .rec__v { font-size: 15px; flex: 0 0 auto; }
  .rec__s { flex: 1 1 auto; text-align: right; }
}

@media (max-height: 700px) {
  .start { gap: 14px; }
  .start__tagline { display: none; }
}

/* ---------- game over extras ---------------------------------------------- */

.ov-heroLabel {
  margin: -12px 0 10px;
  font-size: 10.5px;
  letter-spacing: .2em;
  text-transform: uppercase;
  color: var(--muted-2);
}
.ov-compare {
  margin: 0 0 6px;
  font-size: 12.5px;
  color: var(--gold);
}
.ov-reason {
  margin: 0 0 16px;
  font-size: 12px;
  color: var(--muted);
}

/* ---------- help ----------------------------------------------------------- */

.help-h {
  margin: 20px 0 8px;
  font-size: 10.5px;
  letter-spacing: .2em;
  text-transform: uppercase;
  color: var(--muted-2);
}
.help-h:first-of-type { margin-top: 8px; }

.basics { margin: 0 0 4px; padding-left: 18px; }
.basics li { font-size: 12.5px; line-height: 1.65; color: var(--muted); margin-bottom: 7px; }
.basics b { color: var(--text); font-weight: 600; }

.glossary { margin: 14px 0 0; font-size: 12px; }
.glossary dt { color: var(--text); font-weight: 600; margin-top: 9px; }
.glossary dt b { color: var(--gold); font-family: var(--font-mono); font-weight: 700; }
.glossary dd { margin: 2px 0 0; color: var(--muted); line-height: 1.55; }

/* ---------- segmented control ---------------------------------------------- */

.setrow--seg { grid-template-columns: 1fr; gap: 10px; }

.seg {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  padding: 4px;
  border-radius: 12px;
  border: 1px solid var(--stroke);
  background: rgba(255, 255, 255, .04);
}
.seg__btn {
  appearance: none;
  border: none;
  background: none;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
  padding: 11px 10px;
  border-radius: 9px;
  cursor: pointer;
  transition: background .16s, color .16s;
}
.seg__btn:hover { color: var(--text); }
.seg__btn.is-on {
  background: linear-gradient(92deg, rgba(34, 211, 238, .9), rgba(129, 140, 248, .9));
  color: #05070f;
  font-weight: 800;
}

/* ---------- settings groups ------------------------------------------------ */

.set-group {
  margin: 18px 0 4px;
  font-size: 10.5px;
  letter-spacing: .2em;
  text-transform: uppercase;
  color: var(--muted-2);
}
.set-group:first-of-type { margin-top: 14px; }

.setrow.is-disabled { opacity: .42; }
.setrow.is-disabled label { cursor: default; }

.setselect {
  appearance: none;
  width: 100%;
  background: rgba(255, 255, 255, .07);
  border: 1px solid var(--stroke-strong);
  color: var(--text);
  border-radius: 9px;
  padding: 8px 30px 8px 12px;
  font-family: var(--font-mono);
  font-size: 13px;
  cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12'%3E%3Cpath d='M2 4.5L6 8.5L10 4.5' stroke='%23a3aec5' stroke-width='1.6' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 9px center;
  background-size: 12px;
}
.setselect option { background: #0b0f1c; }

.set-adv {
  margin-top: 18px;
  border-top: 1px solid var(--stroke-soft);
  padding-top: 6px;
}
.set-adv summary {
  cursor: pointer;
  list-style: none;
  padding: 10px 2px;
  font-size: 10.5px;
  letter-spacing: .2em;
  text-transform: uppercase;
  color: var(--muted-2);
  display: flex;
  align-items: center;
  gap: 10px;
}
.set-adv summary::-webkit-details-marker { display: none; }
.set-adv summary::before {
  content: '';
  width: 7px; height: 7px;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: rotate(-45deg);
  transition: transform .18s;
}
.set-adv[open] summary::before { transform: rotate(45deg); }
.set-adv summary em {
  font-style: normal;
  letter-spacing: .02em;
  text-transform: none;
  font-size: 11px;
  color: var(--muted-2);
  opacity: .8;
}

@media (max-width: 1180px) {
  :root { --rail-w: 156px; }
  .stat--pps { display: none; }
  .stat-row--three { grid-template-columns: auto minmax(0, 1fr); }
  .stat__value { font-size: 22px; }
  .card--next canvas { height: clamp(190px, 28vh, 300px); }
}

/* ---------- touch: bigger hit areas everywhere ---------------------------- */

@media (pointer: coarse) {
  .iconbtn { width: 44px; height: 44px; }
  .iconbtn--pause { display: grid; }
  .switch { width: 52px; height: 32px; }
  .switch i { width: 26px; height: 26px; }
  .switch.is-on i { transform: translateX(20px); }
  input[type=range] { height: 44px; }
  input[type=range]::-webkit-slider-thumb { width: 22px; height: 22px; margin-top: -9px; }
  input[type=range]::-moz-range-thumb { width: 22px; height: 22px; }
  .btn--ghost { padding: 13px 18px; font-size: 14px; }
  .ov-field select { padding: 13px 34px 13px 14px; }
  .tbtn { min-height: 44px; }
}

/* ---------- tablet: keep the three-column layout, add a pad --------------- */

@media (pointer: coarse) and (min-width: 761px) and (max-width: 1180px) {
  .hintbar { display: none; }
  .touchpad {
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    gap: 10px;
    width: 100%;
    max-width: 760px;
    margin: 0 auto;
  }
}

/* ---------- phone portrait: stacked ------------------------------------- */

@media (max-width: 760px), (pointer: coarse) and (max-width: 760px) {
  .app { gap: 8px; }

  .stage {
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-width: none;
  }

  .rail { flex-direction: row; gap: 8px; flex: 0 0 auto; align-items: stretch; }
  .rail--left { order: 1; }
  .rail--right { order: 2; }
  .playfield { order: 3; flex: 1 1 auto; min-height: 0; }

  .card { padding: 7px 10px; border-radius: 13px; }
  .card__title { margin-bottom: 3px; font-size: 9.5px; }

  .card--hold { flex: 0 0 84px; padding: 6px 8px; }
  .card--hold canvas { height: 40px; }
  .hold-empty { font-size: 9px; letter-spacing: 0; }
  .hold-empty kbd { display: none; }
  .hold-lock { bottom: -4px; font-size: 8px; }

  .card--stats {
    flex: 1 1 auto;
    flex-direction: row;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    padding: 7px 12px;
  }
  .card--stats .stat--score { flex: 1 1 84px; }
  .card--stats .stat-row { flex: 0 0 auto; grid-template-columns: auto auto; gap: 14px; }
  .card--stats .level-progress { flex: 1 0 100%; order: 9; }
  .stat__value { font-size: 19px; }
  .stat__value--sm { font-size: 15px; }
  .stat__value--xs { font-size: 13px; }
  .stat__delta { top: 10px; font-size: 11px; }

  .stat--pps { display: none; }
  .card--goals { display: none; }

  .card--next { flex: 1 1 auto; padding: 5px 8px 7px; }
  /* flex-basis wins over `height` in a column flex box, so pin the basis too */
  .card--next canvas { flex: 0 0 44px; height: 44px; width: 100%; }

  .brand__text p { display: none; }
  .brand__mark { width: 28px; height: 28px; }
  .hintbar { display: none; }

  .toasts { padding-top: 12%; }
  .toast__main { font-size: clamp(15px, 5.5vmin, 26px); }

  /* Movement under the left thumb, rotation and hold under the right, drop
     across the bottom for either. Splitting left/right across the pad — as
     the first cut did — is the one arrangement thumbs cannot work. */
  .touchpad {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    grid-template-areas:
      "left soft right ccw  cw   hold"
      "hard hard hard  hard hard hard";
    gap: 7px;
  }
  .tbtn[data-act="left"]  { grid-area: left; }
  .tbtn[data-act="soft"]  { grid-area: soft; }
  .tbtn[data-act="right"] { grid-area: right; }
  .tbtn[data-act="ccw"]   { grid-area: ccw; }
  .tbtn[data-act="cw"]    { grid-area: cw; }
  .tbtn[data-act="hold"]  { grid-area: hold; }
  .tbtn[data-act="hard"]  { grid-area: hard; }

  /* a hair of breathing room between the two thumb clusters */
  .tbtn[data-act="right"] { margin-right: 5px; }
  .tbtn[data-act="ccw"]   { margin-left: 5px; }
}

@media (max-height: 700px) and (pointer: coarse) {
  .app { gap: 6px; }
  .tbtn { height: 46px; }
  .touchpad { gap: 6px; }
  .card--hold canvas { height: 34px; }
  .card--next canvas { flex: 0 0 36px; height: 36px; }
  .card--next { padding: 4px 8px 5px; }
  .card__title { margin-bottom: 2px; }
}

@media (max-width: 380px) {
  .brand__text { display: none; }
  .card--hold { flex: 0 0 70px; }
  .stat__value { font-size: 17px; }
  .touchpad { gap: 5px; }
}

/* ---------- phone landscape ---------------------------------------------- */

@media (orientation: landscape) and (max-height: 620px) and (pointer: coarse),
       (orientation: landscape) and (max-height: 480px) {
  .app { grid-template-rows: 1fr auto; gap: 6px; }
  .hintbar { display: none; }

  /* The header floats over the rail instead of being removed: in landscape
     it is the only way to reach pause, mute, settings and help. */
  .topbar {
    position: absolute;
    top: max(6px, env(safe-area-inset-top, 0px));
    right: max(8px, env(safe-area-inset-right, 0px));
    width: auto;
    max-width: none;
    margin: 0;
    z-index: 6;
  }
  .topbar .brand { display: none; }
  .topbar__actions { gap: 6px; }

  .stage {
    display: flex;
    flex-direction: row;
    gap: 8px;
    max-width: none;
    align-items: stretch;
  }

  .rail { flex: 0 0 132px; flex-direction: column; gap: 6px; }
  .rail--left { order: 0; }
  .playfield { order: 1; flex: 1 1 auto; min-width: 0; }
  /* the header floats over this column, so keep its row clear */
  .rail--right { order: 2; justify-content: flex-start; padding-top: 46px; }

  .card { padding: 6px 8px; border-radius: 11px; }
  .card--hold { flex: 0 0 auto; }
  .card--hold canvas { height: 34px; }
  .hold-empty { font-size: 9px; }
  .hold-empty kbd { display: none; }
  .card--stats { flex: 0 0 auto; flex-direction: column; align-items: stretch; gap: 5px; }
  .card--stats .stat-row--muted { display: none; }
  .stat__value { font-size: 16px; }
  .stat__value--sm { font-size: 13px; }
  .stat--pps { display: none; }
  .card--goals { display: none; }
  .card--next { flex: 1 1 auto; min-height: 0; }
  .card--next canvas { flex: 1 1 0; height: auto; min-height: 0; }

  .toasts { padding-top: 8%; }

  .touchpad {
    display: grid;
    grid-template-areas: none;            /* undo the portrait two-row pad */
    grid-template-columns: repeat(7, 1fr);
    gap: 6px;
  }
  .touchpad .tbtn { grid-area: auto; margin: 0; }
  .tbtn[data-act="hard"] { grid-column: span 2; }
  .tbtn { height: 44px; min-height: 44px; }
  .tbtn i { display: none; }
  .tbtn svg { width: 18px; height: 18px; }

  .touch-coach { bottom: calc(env(safe-area-inset-bottom, 0px) + 58px); }
}

/* Gestures-only: the pad is removed from the layout entirely, so the board
   gets its height back. */
.app.is-gestures .touchpad { display: none !important; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
  .aurora__blob { animation: none; }
}
