/* FocusLoop — tema scuro minimale con un solo colore d'accento. */

:root {
  --bg: #0d0f14;
  --surface: #151821;
  --surface-2: #1c2030;
  --border: #262b3a;
  --text: #e7e9ee;
  --muted: #8b92a5;
  --faint: #4d5468;
  --accent: #6ef2c0;
  --accent-dim: rgba(110, 242, 192, 0.14);
  --accent-ink: #052018;
  --good: #8cb6ff;
  --warn: #ffc56b;
  --bad: #ff6b81;
  --f1-red: #ff2d1f;
  --radius: 12px;
  --font-ui: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-mono: "JetBrains Mono", "Cascadia Mono", "Fira Code", Consolas, ui-monospace, monospace;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 var(--font-ui);
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -0.01em; }
h3 { font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); margin-bottom: 12px; }
p { margin: 0; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.mono { font-family: var(--font-mono); }

kbd {
  font-family: var(--font-mono);
  font-size: 0.72em;
  padding: 1px 6px;
  border: 1px solid var(--border);
  border-bottom-width: 2px;
  border-radius: 5px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.03);
  margin-left: 6px;
  vertical-align: 1px;
}

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

/* ---------- Schermate ---------- */
.screen {
  min-height: 100vh;
  max-width: 1080px;
  margin: 0 auto;
  padding: 36px clamp(16px, 4vw, 48px) 48px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  animation: fade-in 0.25s ease;
}
@keyframes fade-in { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

.brand { display: flex; flex-direction: column; gap: 6px; margin-bottom: 6px; }
.logo { font-size: 2.6rem; font-weight: 700; letter-spacing: -0.03em; }
.logo span { color: var(--accent); }
.tagline { color: var(--muted); max-width: 60ch; }
.eyebrow { color: var(--accent); font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.12em; }

.screen-head { display: flex; align-items: center; gap: 16px; }
.screen-head h2 { font-size: 1.5rem; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* ---------- Bottoni e campi ---------- */
.btn {
  font: inherit;
  font-weight: 500;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 9px 16px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.08s;
  white-space: nowrap;
}
.btn:hover:not(:disabled) { border-color: var(--faint); background: #232838; }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn-primary:hover:not(:disabled) { background: #8af5cd; border-color: transparent; }
.btn-primary kbd { color: var(--accent-ink); border-color: rgba(5, 32, 24, 0.3); }
.btn-ghost { background: transparent; }
.btn-danger { background: transparent; color: var(--bad); border-color: rgba(255, 107, 129, 0.35); }
.btn-danger:hover:not(:disabled) { background: rgba(255, 107, 129, 0.08); border-color: var(--bad); }
.btn-lg { padding: 12px 22px; font-size: 1.05rem; }
.btn.tapped { animation: tap-flash 0.18s ease; }
@keyframes tap-flash { from { background: var(--accent-dim); border-color: var(--accent); } }

.actions { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.nav { display: flex; flex-wrap: wrap; gap: 6px; }

.field { display: flex; flex-direction: column; gap: 4px; font-size: 0.85rem; color: var(--muted); }
.field-wide { width: 100%; }
.check { display: flex; gap: 8px; align-items: center; font-size: 0.9rem; cursor: pointer; }
.label { font-size: 0.85rem; color: var(--muted); }
.field-row { display: flex; align-items: center; gap: 16px; }
.field-row.wrap { flex-wrap: wrap; align-items: flex-end; }

input[type="number"], input[type="text"], input[type="search"], input[type="password"], input:not([type]), select {
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 10px;
  min-width: 0;
}
input[type="number"] { width: 120px; }
input[type="color"] { width: 64px; height: 34px; border: 1px solid var(--border); border-radius: 8px; background: var(--bg); padding: 3px; }
input[type="range"] { accent-color: var(--accent); width: 100%; }
input[type="checkbox"], input[type="radio"] { accent-color: var(--accent); }

.segmented { display: inline-flex; flex-wrap: wrap; max-width: 100%; background: var(--bg); border: 1px solid var(--border); border-radius: 9px; padding: 3px; }
.segmented label { position: relative; }
.segmented input { position: absolute; opacity: 0; inset: 0; cursor: pointer; }
.segmented span { display: block; padding: 6px 14px; border-radius: 7px; font-size: 0.9rem; color: var(--muted); transition: background 0.15s, color 0.15s; }
.segmented input:checked + span { background: var(--surface-2); color: var(--text); }
.segmented input:focus-visible + span { outline: 2px solid var(--accent); }
.segmented input:disabled + span { opacity: 0.4; }

/* ---------- Home ---------- */
.card-head { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px; }
.card-head h3 { margin: 0; }
.card-head .spacer { flex: 1; }

.icon-btn {
  padding: 0;
  width: 32px;
  height: 32px;
  display: inline-grid;
  place-items: center;
  font-size: 0.95rem;
  line-height: 1;
}

/* Scelta del brano: griglia di schede con titolo, durata, BPM e ritmo */
.song-filter { width: 100%; max-width: 280px; }
.playlist { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 8px; }
.playlist:empty { display: none; }
.track {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  padding: 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s, transform 0.08s;
}
.track:hover { border-color: var(--faint); }
.track:active { transform: translateY(1px); }
.track.selected { border-color: var(--accent); background: var(--accent-dim); }
.track:not(.ready) { cursor: default; }
.track.error { border-color: rgba(255, 107, 129, 0.4); }
.track:has(.track-pick:focus-visible) { outline: 2px solid var(--accent); outline-offset: 2px; }
.track[hidden] { display: none; }
/* Il pulsante di scelta resta per tastiera e screen reader, ma non si vede: la scheda intera è il bersaglio */
.track-pick { position: absolute; opacity: 0; width: 1px; height: 1px; pointer-events: none; }

/* Anteprima in corso: il pulsante ▶/❚❚ si colora */
.track.playing [data-act="preview"] { color: var(--accent); }

.track-main { min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.track-name {
  font-weight: 600;
  line-height: 1.25;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
.badge {
  display: inline-block;
  font-size: 0.66rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  padding: 1px 6px;
  margin-right: 8px;
  border-radius: 5px;
  color: var(--accent);
  background: var(--accent-dim);
  vertical-align: 1px;
}
.track-meta { font-size: 0.8rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.track.error .track-meta { color: var(--bad); white-space: normal; }
.track-density { display: flex; align-items: center; gap: 3px; margin-top: 2px; }
.track-density i { width: 10px; height: 4px; border-radius: 2px; background: var(--surface-2); }
.track-density i.on { background: var(--accent); }
.track-density span { margin-left: 5px; font-size: 0.72rem; color: var(--faint); }
.track-progress { height: 3px; background: var(--surface-2); border-radius: 2px; overflow: hidden; margin-top: 5px; }
.track-progress div { height: 100%; width: 0; background: var(--accent); transition: width 0.15s; }
.track-bpm { display: flex; align-items: center; gap: 6px; font-size: 0.8rem; color: var(--muted); margin-top: 4px; }
.track-bpm input { width: 84px; padding: 4px 8px; }
.track-actions { display: flex; flex-direction: column; gap: 2px; align-self: start; }
.track-actions .icon-btn { width: 30px; height: 30px; background: transparent; border-color: transparent; }
.track-actions .icon-btn:hover:not(:disabled) { border-color: var(--border); }
/* Togliere un brano è raro: il pulsante compare passando sopra alla scheda */
.track-actions [data-act="remove"] { opacity: 0; transition: opacity 0.15s; }
.track:hover [data-act="remove"], .track [data-act="remove"]:focus-visible { opacity: 0.7; }
@media (hover: none) { .track-actions [data-act="remove"] { opacity: 0.5; } }

.dropzone {
  border: 1px dashed var(--border);
  border-radius: 10px;
  padding: 22px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-items: center;
  text-align: center;
  transition: border-color 0.15s, background 0.15s;
}
.playlist-card.drag-over { border-color: var(--accent); background: #161b22; }

.stepper { display: flex; align-items: center; gap: 8px; color: var(--text); }
.stepper output { min-width: 2ch; text-align: center; font-size: 1.3rem; }
.loops-info { align-self: center; }
#aim-options { display: flex; flex-direction: column; gap: 12px; }

/* ---------- Menu iniziale ---------- */
.mode-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
@media (max-width: 560px) { .mode-grid { grid-template-columns: 1fr; } }
.mode-card {
  font: inherit;
  color: var(--text);
  text-align: left;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 150px;
  padding: 22px 24px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s, transform 0.08s;
}
.mode-card:hover { border-color: var(--faint); background: #191d28; }
.mode-card:active { transform: translateY(1px); }
.mode-title { font-size: 1.45rem; font-weight: 650; letter-spacing: -0.01em; transition: color 0.15s; }
/* Al passaggio ogni titolo prende il colore della sua modalità */
.aim-card:is(:hover, :focus-visible) .mode-title { color: #f0c24b; } /* oro dei bersagli */
.type-card:is(:hover, :focus-visible) .mode-title { color: var(--accent); } /* verde del cursore */
.wall-card:is(:hover, :focus-visible) .mode-title { color: var(--good); }
.loop-card:is(:hover, :focus-visible) .mode-title { color: #c79bff; }
.mode-desc { color: var(--muted); }
/* Anteprime animate delle modalità: partono passandoci sopra (o con il focus da tastiera) e
   tornano a riposo di colpo quando esci. */
.mode-anim { position: relative; display: flex; align-items: center; height: 30px; margin-top: auto; }

/* Reaction time: le luci si accendono una alla volta e si spengono tutte insieme, come al via */
.mode-card.f1-card:is(:hover, :focus-visible) .mode-title { color: var(--f1-red); }
.mode-lights { gap: 6px; }
.mode-lights i { width: 12px; height: 12px; border-radius: 50%; background: #2a1215; box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.6); transition: background 0.05s, box-shadow 0.05s; }
.f1-card:is(:hover, :focus-visible) .mode-lights i { background: var(--f1-red); box-shadow: 0 0 8px rgba(255, 45, 31, 0.6); }
.f1-card:is(:hover, :focus-visible) .mode-lights i:nth-child(2) { transition-delay: 0.15s; }
.f1-card:is(:hover, :focus-visible) .mode-lights i:nth-child(3) { transition-delay: 0.3s; }
.f1-card:is(:hover, :focus-visible) .mode-lights i:nth-child(4) { transition-delay: 0.45s; }
.f1-card:is(:hover, :focus-visible) .mode-lights i:nth-child(5) { transition-delay: 0.6s; }

/* Aim training: il mirino scorre sulla fila e fa esplodere i bersagli uno dopo l'altro */
.anim-aim { gap: 10px; }
.anim-aim i {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #fff1c2, #f0c24b 45%, #9a7414);
  box-shadow: 0 0 6px rgba(240, 194, 75, 0.35);
}
.anim-aim b {
  position: absolute;
  left: 0;
  top: 50%;
  width: 14px;
  height: 14px;
  margin-top: -7px;
  z-index: 1;
  background:
    linear-gradient(var(--text), var(--text)) center / 2px 100% no-repeat,
    linear-gradient(var(--text), var(--text)) center / 100% 2px no-repeat;
  -webkit-mask: radial-gradient(circle, transparent 2px, #000 2.5px);
  mask: radial-gradient(circle, transparent 2px, #000 2.5px);
}
.mode-card:is(:hover, :focus-visible) .anim-aim b { left: 96px; transition: left 0.68s linear; }
.mode-card:is(:hover, :focus-visible) .anim-aim i { animation: aim-pop 0.26s ease-out forwards; }
.mode-card:is(:hover, :focus-visible) .anim-aim i:nth-child(2) { animation-delay: 0.17s; }
.mode-card:is(:hover, :focus-visible) .anim-aim i:nth-child(3) { animation-delay: 0.34s; }
.mode-card:is(:hover, :focus-visible) .anim-aim i:nth-child(4) { animation-delay: 0.51s; }
.mode-card:is(:hover, :focus-visible) .anim-aim i:nth-child(5) { animation-delay: 0.68s; }
@keyframes aim-pop {
  0% { transform: scale(1); opacity: 1; }
  35% { transform: scale(1.55); opacity: 1; background: #fff; box-shadow: 0 0 14px rgba(255, 255, 255, 0.8); }
  100% { transform: scale(0); opacity: 0; }
}

/* Typing test: la frase si scrive da sola sopra il testo fantasma, con il cursore che lampeggia */
.anim-type { font-size: 0.85rem; white-space: nowrap; }
.anim-type .ghost { color: var(--faint); }
.anim-type .typed {
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 0;
  overflow: hidden;
  color: var(--text);
  border-right: 2px solid var(--accent);
}
/* Larghezza e passi = numero di caratteri della frase (31); il cursore lampeggia solo qui */
.mode-card:is(:hover, :focus-visible) .anim-type .typed {
  width: 31ch;
  transition: width 1.4s steps(31, end);
  animation: blink 1.05s step-end 1.4s infinite;
}

/* 1w4ts: il mirino fa flick da un bersaglio all'altro sul muro e ognuno ricompare altrove */
.anim-wall .wall {
  position: relative;
  width: 104px;
  height: 30px;
  background: linear-gradient(#202435, #171a26);
  border: 1px solid var(--border);
  border-radius: 4px;
}
.anim-wall i, .anim-wall b { position: absolute; transform: translate(-50%, -50%); }
.anim-wall i {
  left: var(--x1);
  top: var(--y1);
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #f0c24b;
  box-shadow: 0 0 5px rgba(240, 194, 75, 0.5);
}
.anim-wall b {
  left: 12%;
  top: 30%;
  width: 11px;
  height: 11px;
  z-index: 1;
  background:
    linear-gradient(var(--text), var(--text)) center / 1.5px 100% no-repeat,
    linear-gradient(var(--text), var(--text)) center / 100% 1.5px no-repeat;
  -webkit-mask: radial-gradient(circle, transparent 1.5px, #000 2px);
  mask: radial-gradient(circle, transparent 1.5px, #000 2px);
}
.mode-card:is(:hover, :focus-visible) .anim-wall i { animation: wall-hit 0.4s ease-out both; }
.mode-card:is(:hover, :focus-visible) .anim-wall i:nth-child(2) { animation-delay: 0.18s; }
.mode-card:is(:hover, :focus-visible) .anim-wall i:nth-child(3) { animation-delay: 0.36s; }
.mode-card:is(:hover, :focus-visible) .anim-wall i:nth-child(4) { animation-delay: 0.54s; }
.mode-card:is(:hover, :focus-visible) .anim-wall b { animation: wall-flick 0.72s forwards; }
@keyframes wall-hit {
  0% { left: var(--x1); top: var(--y1); transform: translate(-50%, -50%) scale(1); opacity: 1; }
  40% { left: var(--x1); top: var(--y1); transform: translate(-50%, -50%) scale(2); opacity: 0; background: #fff; }
  41% { left: var(--x2); top: var(--y2); transform: translate(-50%, -50%) scale(0); opacity: 1; }
  100% { left: var(--x2); top: var(--y2); transform: translate(-50%, -50%) scale(1); opacity: 1; }
}
/* Le tappe sono le posizioni iniziali dei 4 bersagli (--x1/--y1 nell'HTML) */
@keyframes wall-flick {
  0% { left: 12%; top: 30%; animation-timing-function: cubic-bezier(0.2, 0.9, 0.3, 1); }
  25% { left: 40%; top: 68%; animation-timing-function: cubic-bezier(0.2, 0.9, 0.3, 1); }
  50% { left: 66%; top: 24%; animation-timing-function: cubic-bezier(0.2, 0.9, 0.3, 1); }
  75%, 100% { left: 86%; top: 66%; }
}

/* FocusLoop: i segmenti si riempiono alternando aim (verde) e typing (blu), un loop dopo l'altro */
.anim-loop { gap: 4px; height: 20px; }
.anim-loop i { width: 22px; height: 6px; border-radius: 3px; background: var(--surface-2); transition: background 0.15s; }
.mode-card:is(:hover, :focus-visible) .anim-loop i.a { background: var(--accent); }
.mode-card:is(:hover, :focus-visible) .anim-loop i.t { background: var(--good); }
.mode-card:is(:hover, :focus-visible) .anim-loop i:nth-child(2) { transition-delay: 0.12s; }
.mode-card:is(:hover, :focus-visible) .anim-loop i:nth-child(3) { transition-delay: 0.24s; }
.mode-card:is(:hover, :focus-visible) .anim-loop i:nth-child(4) { transition-delay: 0.36s; }
.mode-card:is(:hover, :focus-visible) .anim-loop i:nth-child(5) { transition-delay: 0.48s; }
.mode-card:is(:hover, :focus-visible) .anim-loop i:nth-child(6) { transition-delay: 0.6s; }

@media (prefers-reduced-motion: reduce) {
  .mode-anim *, .mode-anim *::before { animation: none !important; transition: none !important; }
}
/* Altre modalità: in secondo piano rispetto alla griglia */
.mode-extra { display: flex; flex-direction: column; gap: 8px; margin-top: 4px; }
.mode-card.minor { min-height: 0; padding: 14px 18px; gap: 4px; background: transparent; border-style: dashed; }
.mode-card.minor:hover { background: var(--surface); border-style: solid; }
.mode-card.minor .mode-title { font-size: 1.05rem; font-weight: 600; }
.mode-card.minor .mode-desc { font-size: 0.9rem; }

.key-btn { min-width: 64px; justify-content: center; }
.key-btn.listening { border-color: var(--accent); color: var(--accent); }
.donate { margin-top: 28px; text-align: center; line-height: 1.6; }
.donate-addr {
  font: inherit;
  font-family: var(--font-mono);
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 1px 6px;
  cursor: pointer;
  word-break: break-all;
}
.donate-addr:hover { border-color: var(--accent); }
body:not(.source-grid) .grid-only { display: none; }

.progress { display: flex; align-items: center; gap: 12px; }
.progress-track { flex: 1; height: 6px; background: var(--bg); border-radius: 4px; overflow: hidden; }
.progress-bar { height: 100%; width: 0; background: var(--accent); transition: width 0.15s; }
.progress-label { min-width: 160px; text-align: right; }

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translateX(-50%);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  padding: 10px 16px;
  border-radius: 9px;
  max-width: min(560px, 90vw);
  z-index: 50;
  animation: fade-in 0.2s ease;
}
.toast.error { border-left-color: var(--bad); }
.toast.warn { border-left-color: var(--warn); }

/* ---------- Schermata di gioco ---------- */
#screen-play { max-width: none; height: 100vh; padding: 0; gap: 0; position: relative; }
.hud-center { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.hud-track { color: var(--muted); text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hud {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) minmax(200px, 3fr) minmax(180px, 1fr);
  align-items: center;
  gap: 18px;
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
}
.hud-left, .hud-right { display: flex; align-items: center; gap: 10px; white-space: nowrap; }
.hud-right { justify-content: flex-end; }
.pill { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.1em; padding: 3px 10px; border-radius: 99px; background: var(--accent-dim); color: var(--accent); }
.hud-progress { height: 4px; background: var(--surface-2); border-radius: 2px; overflow: hidden; }
.hud-progress-bar { height: 100%; width: 0; background: var(--faint); }

.stage { flex: 1; position: relative; min-height: 0; }
.stage-center { display: flex; align-items: center; justify-content: center; padding: 24px; }

#aim-canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; cursor: none; touch-action: none; }
.aim-hud {
  position: absolute;
  top: 14px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 32px;
  pointer-events: none;
}
.aim-hud div { display: flex; flex-direction: column; align-items: center; }
.aim-hud .k { font-size: 0.68rem; text-transform: uppercase; letter-spacing: 0.1em; color: var(--muted); font-family: var(--font-ui); }
.aim-hud .v { font-size: 1.25rem; font-variant-numeric: tabular-nums; }
.lock-prompt {
  position: absolute;
  left: 50%;
  top: 32%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 12px 20px;
  border-radius: 12px;
  background: rgba(13, 15, 20, 0.78);
  border: 1px solid var(--border);
  pointer-events: none;
  z-index: 4;
}
.lock-prompt strong { color: var(--accent); font-size: 1.1rem; }
.lock-prompt span { color: var(--muted); font-size: 0.85rem; }
.field output { color: var(--text); margin-left: 6px; }
.sens-row { display: flex; gap: 12px; flex-wrap: wrap; }
.sens-row input { width: 130px; }
.segment-track { position: absolute; left: 0; right: 0; bottom: 0; height: 3px; background: var(--surface-2); pointer-events: none; }
.segment-bar { height: 100%; width: 0; background: var(--accent); }
.countdown {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 6rem;
  font-weight: 700;
  color: var(--accent);
  pointer-events: none;
  text-shadow: 0 0 40px rgba(110, 242, 192, 0.25);
  z-index: 5;
}
.countdown.banner { font-size: 2.6rem; letter-spacing: 0.08em; animation: banner 0.8s ease forwards; }
@keyframes banner { from { opacity: 0; transform: scale(1.15); } 25% { opacity: 1; transform: none; } to { opacity: 0; } }

/* ---------- Typing ---------- */
.typing {
  --line-h: 2.6rem;
  width: min(920px, 100%);
  display: flex;
  flex-direction: column;
  gap: 18px;
}
.typing-live { display: flex; gap: 22px; color: var(--muted); font-size: 0.95rem; }
.typing-live b { color: var(--accent); font-weight: 600; font-size: 1.15rem; font-variant-numeric: tabular-nums; }
.ty-progress { margin-left: auto; }
.typing-box { position: relative; height: calc(var(--line-h) * 3); overflow: hidden; cursor: text; }
.typing-words {
  position: relative;
  display: flex;
  flex-wrap: wrap;
  column-gap: 0.62em;
  font-family: var(--font-mono);
  font-size: 1.6rem;
  color: var(--faint);
  transition: transform 0.18s ease;
  user-select: none;
}
.word { height: var(--line-h); line-height: var(--line-h); white-space: pre; }
.l.ok { color: var(--text); }
.l.bad { color: var(--bad); }
.l.extra { color: var(--bad); opacity: 0.65; }
.word.error {
  background: linear-gradient(var(--bad), var(--bad)) no-repeat left calc(100% - 6px) / 100% 2px;
}
.caret {
  position: absolute;
  left: 0;
  top: 0;
  width: 3px;
  height: calc(var(--line-h) * 0.7);
  margin-top: calc(var(--line-h) * 0.15);
  background: var(--accent);
  border-radius: 2px;
  transition: transform 0.09s ease-out;
  animation: blink 1.05s step-end infinite;
  will-change: transform;
}
.caret.typing { animation: none; }
.caret.no-anim { transition: none; }
.caret.hidden { visibility: hidden; }
@keyframes blink { 50% { opacity: 0; } }
.typing-input { position: absolute; left: 0; top: 0; width: 1px; height: 1px; opacity: 0; border: 0; padding: 0; pointer-events: none; }
.typing-unfocused {
  position: absolute;
  inset: 0;
  display: none;
  place-items: center;
  color: var(--muted);
  background: rgba(13, 15, 20, 0.6);
  backdrop-filter: blur(3px);
}
.typing-box.unfocused .typing-unfocused { display: grid; }
.typing-box.shake { animation: shake 0.18s; }
@keyframes shake { 25% { transform: translateX(-3px); } 75% { transform: translateX(3px); } }
.typing-result { display: flex; flex-direction: column; gap: 14px; animation: fade-in 0.2s ease; }
.result-stats { display: flex; flex-wrap: wrap; gap: 28px; }
.result-stats div { display: flex; flex-direction: column; }
.result-stats .k { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.1em; color: var(--muted); font-family: var(--font-ui); }
.result-stats .v { font-size: 2rem; color: var(--accent); line-height: 1.1; }
.result-stats .v.sm { font-size: 1.3rem; color: var(--text); }
.hint { color: var(--muted); font-size: 0.85rem; }

.chart { width: 100%; height: 150px; display: block; }
.chart-tall { height: 200px; }

/* ---------- Overlay pausa ---------- */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(8, 9, 12, 0.72);
  backdrop-filter: blur(4px);
  display: grid;
  place-items: center;
  z-index: 40;
  animation: fade-in 0.15s ease;
}
.overlay-card { background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 28px 32px; display: flex; flex-direction: column; gap: 14px; min-width: 320px; }

/* ---------- Riepilogo / storico ---------- */
.summary-message { font-size: clamp(1.6rem, 3.5vw, 2.4rem); max-width: 26ch; line-height: 1.15; }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; }
.stat .k { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.1em; color: var(--muted); }
.stat .v { font-family: var(--font-mono); font-size: 1.7rem; margin-top: 2px; }
.stat .v.accent { color: var(--accent); }
.stat .sub { font-size: 0.8rem; color: var(--muted); }
.rounds { display: flex; flex-wrap: wrap; gap: 8px; }
.round-chip { font-family: var(--font-mono); font-size: 0.82rem; padding: 6px 10px; border-radius: 8px; background: var(--surface-2); border: 1px solid var(--border); }
.round-chip.best { border-color: var(--accent); color: var(--accent); }
.round-chip .t { color: var(--muted); margin-right: 6px; }

.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
.table th, .table td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.table th { color: var(--muted); font-weight: 500; font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.08em; }
.table td.num { font-family: var(--font-mono); text-align: right; }
.table th.num { text-align: right; }
.table .song { max-width: 260px; overflow: hidden; text-overflow: ellipsis; }
.table tr.me td { color: var(--accent); font-weight: 600; }
.table tr.gap td { color: var(--faint); text-align: center; padding: 2px; }
.accent-text { color: var(--accent); }

/* ---------- Impostazioni ---------- */
.settings-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 14px; }
.crosshair-row { display: flex; gap: 16px; align-items: center; }
.crosshair-fields { flex: 1; display: flex; flex-direction: column; gap: 12px; }
.crosshair-preview { width: 120px; height: 120px; border-radius: 10px; background: var(--bg); border: 1px solid var(--border); }

/* ---------- Calibrazione ---------- */
.calib-pad {
  height: 170px;
  border-radius: var(--radius);
  background: var(--bg);
  border: 1px dashed var(--border);
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 22px;
  cursor: pointer;
  user-select: none;
}
.calib-pad.active { border-style: solid; border-color: var(--faint); }
.calib-count { font-size: 1.4rem; }
.calib-scale { position: relative; width: min(520px, 80%); height: 26px; border-top: 1px solid var(--border); }
.calib-zero { position: absolute; left: 50%; top: -8px; width: 1px; height: 16px; background: var(--muted); }
.calib-label { position: absolute; top: 6px; font-size: 0.72rem; color: var(--faint); }
.calib-label.left { left: 0; }
.calib-label.right { right: 0; }
.calib-tick { position: absolute; top: -10px; width: 2px; height: 20px; background: var(--accent); border-radius: 1px; opacity: 0.8; animation: fade-in 0.15s ease; }
.calib-tick.warmup { background: var(--faint); }
/* ---------- Reaction time (semaforo F1) ---------- */
.f1-stage {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 22px;
  min-height: 400px;
  padding: clamp(24px, 5vw, 44px) 16px;
  background: radial-gradient(ellipse at 50% 0%, #1b1e29, var(--bg) 72%);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
.f1-stage:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.f1-gantry {
  position: relative;
  display: flex;
  gap: clamp(6px, 1.8vw, 16px);
  padding: clamp(10px, 2vw, 16px) clamp(10px, 2.4vw, 22px);
  background: #060709;
  border: 1px solid #1d2029;
  border-radius: 10px;
  box-shadow: 0 14px 34px rgba(0, 0, 0, 0.55);
  isolation: isolate; /* la trave (::before, z-index -1) resta dietro alle colonne ma sopra lo sfondo */
}
/* La trave che regge il semaforo */
.f1-gantry::before {
  content: "";
  position: absolute;
  left: -24px;
  right: -24px;
  top: 50%;
  height: 10px;
  transform: translateY(-50%);
  background: linear-gradient(#20232c, #121419);
  border-radius: 3px;
  z-index: -1;
}
.f1-col {
  display: flex;
  flex-direction: column;
  gap: clamp(5px, 1.1vw, 9px);
  padding: clamp(5px, 1.2vw, 9px);
  background: #111319;
  border: 1px solid #1c1f28;
  border-radius: 8px;
}
.f1-lamp {
  display: block;
  width: clamp(26px, 6.6vw, 52px);
  aspect-ratio: 1;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #2a2e38, #121419 70%);
  box-shadow: inset 0 2px 6px rgba(0, 0, 0, 0.85);
}
/* Nessuna transizione: allo spegnimento le luci devono sparire nello stesso frame */
.f1-col.on .f1-lamp.red {
  background: radial-gradient(circle at 35% 30%, #ffc2b8, var(--f1-red) 42%, #a50c04 78%);
  box-shadow: 0 0 22px 5px rgba(255, 45, 31, 0.5), inset 0 -3px 6px rgba(80, 0, 0, 0.55);
}
.f1-time {
  font-size: clamp(3rem, 11vw, 5.5rem);
  font-weight: 700;
  line-height: 1;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
  color: var(--faint);
}
.f1-stage[data-state="result"] .f1-time,
.f1-stage[data-state="done"] .f1-time { color: var(--accent); }
.f1-stage[data-state="jump"] .f1-time { color: var(--bad); }
.f1-stage[data-state="go"] .f1-time { color: var(--text); }
.f1-msg { color: var(--muted); text-align: center; max-width: 52ch; min-height: 3em; }
.f1-stage[data-state="go"] .f1-msg { color: var(--accent); font-weight: 700; letter-spacing: 0.1em; }
.f1-stage[data-state="jump"] .f1-msg { color: var(--bad); }
.round-chip.pending { color: var(--faint); }

/* Fine serie: il semaforo lascia il posto alle statistiche finché non si riparte */
.f1-stage[data-state="done"] { cursor: default; }
.f1-stage[data-state="done"] .f1-gantry { display: none; }
.f1-stage[data-state="done"] .f1-msg { min-height: 0; margin-top: -10px; }
.f1-summary {
  width: min(560px, 100%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
  animation: fade-in 0.25s ease;
}
.f1-sum-verdict { font-weight: 600; text-align: center; }
.f1-sum-grid { width: 100%; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; }
@media (max-width: 560px) { .f1-sum-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.f1-sum-stat {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 10px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
}
.f1-sum-stat .k { font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.1em; color: var(--muted); }
.f1-sum-stat .v { font-size: 1.3rem; }
.f1-sum-stat .v.accent { color: var(--accent); }
.f1-sum-stat .v.bad { color: var(--bad); }
.f1-sum-stat .sub { font-size: 0.75rem; color: var(--muted); }
.f1-bars { width: 100%; display: flex; flex-direction: column; gap: 6px; }
.f1-bar { display: grid; grid-template-columns: 1.5ch minmax(0, 1fr) 4ch; align-items: center; gap: 10px; font-size: 0.85rem; color: var(--muted); }
.f1-bar .bar { height: 8px; background: var(--surface-2); border-radius: 4px; overflow: hidden; }
.f1-bar .bar span { display: block; height: 100%; background: var(--faint); border-radius: 4px; }
.f1-bar .ms { text-align: right; color: var(--text); }
.f1-bar.best .bar span { background: var(--accent); }
.f1-bar.best .ms { color: var(--accent); }
.speed-field { flex: 1 1 240px; max-width: 360px; }
.slider-field { width: min(100%, 320px); }
.footnote { text-align: center; }
.range-row { display: flex; gap: 14px; align-items: center; }
.range-row output { min-width: 70px; text-align: right; color: var(--text); }

/* ---------- Valorant protocol ---------- */
.warn-text { color: var(--warn); }
.link-btn { background: none; border: 0; padding: 0; color: var(--accent); font: inherit; cursor: pointer; text-decoration: underline; text-underline-offset: 2px; }
.link-btn:hover { color: var(--text); }

/* Card del menu: tutta la larghezza, la rotazione A-B-C × 3 poi i due drill Valorant */
.mode-card.vct-card { grid-column: 1 / -1; }
.vct-card:is(:hover, :focus-visible) .mode-title { color: #ff5d6c; }
.vct-card .mode-desc .warn-text:not(:empty) { display: inline-block; margin-left: 4px; font-weight: 600; }
.anim-vct { gap: 5px; height: 20px; }
.anim-vct i { width: 18px; height: 6px; border-radius: 3px; background: var(--surface-2); transition: background 0.12s; }
.anim-vct i.v { width: 30px; }
.mode-card:is(:hover, :focus-visible) .anim-vct i.a { background: var(--accent); }
.mode-card:is(:hover, :focus-visible) .anim-vct i.b { background: var(--good); }
.mode-card:is(:hover, :focus-visible) .anim-vct i.c { background: var(--warn); }
.mode-card:is(:hover, :focus-visible) .anim-vct i.v { background: #ff5d6c; }
.mode-card:is(:hover, :focus-visible) .anim-vct i:nth-child(2) { transition-delay: 0.06s; }
.mode-card:is(:hover, :focus-visible) .anim-vct i:nth-child(3) { transition-delay: 0.12s; }
.mode-card:is(:hover, :focus-visible) .anim-vct i:nth-child(4) { transition-delay: 0.18s; }
.mode-card:is(:hover, :focus-visible) .anim-vct i:nth-child(5) { transition-delay: 0.24s; }
.mode-card:is(:hover, :focus-visible) .anim-vct i:nth-child(6) { transition-delay: 0.3s; }
.mode-card:is(:hover, :focus-visible) .anim-vct i:nth-child(7) { transition-delay: 0.36s; }
.mode-card:is(:hover, :focus-visible) .anim-vct i:nth-child(8) { transition-delay: 0.42s; }
.mode-card:is(:hover, :focus-visible) .anim-vct i:nth-child(9) { transition-delay: 0.48s; }
.mode-card:is(:hover, :focus-visible) .anim-vct i:nth-child(10) { transition-delay: 0.6s; }
.mode-card:is(:hover, :focus-visible) .anim-vct i:nth-child(11) { transition-delay: 0.72s; }

.vct-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 14px; }
.vct-grid .card { display: flex; flex-direction: column; gap: 10px; }
.vct-grid .card .actions { margin-top: auto; }
.vct-sub { font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.1em; color: var(--muted); font-weight: 500; margin-top: 4px; }
.vct-drills { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 10px; }
.vct-drill { display: flex; flex-direction: column; gap: 6px; padding: 12px 14px; border: 1px solid var(--border); border-radius: 10px; background: var(--bg); }
.vct-drill-head { display: flex; align-items: center; gap: 8px; }
.vct-slot { font-size: 0.75rem; padding: 2px 7px; border-radius: 6px; background: var(--surface-2); color: var(--muted); }
.vct-table td, .vct-table th { padding: 7px 9px; }
.vct-table tr.vct-future td { color: var(--faint); }
.vct-table sup { font-size: 0.65em; margin-left: 2px; color: var(--muted); }
.vct-table sup.vct-p { color: var(--good); }
.vct-diag-item { padding: 10px 12px; border-radius: 9px; border-left: 3px solid var(--faint); background: var(--bg); margin-bottom: 8px; }
.vct-diag-item.diag-ok { border-left-color: var(--accent); }
.vct-diag-item.diag-retain, .vct-diag-item.diag-lag, .vct-diag-item.diag-flat { border-left-color: var(--warn); }
.vct-diag-item.diag-easy { border-left-color: var(--good); }
.vct-runs { display: flex; gap: 3px; flex-wrap: wrap; white-space: normal !important; min-width: 180px; }
.vct-chip { font-family: var(--font-mono); font-size: 0.7rem; padding: 1px 5px; border-radius: 5px; background: var(--surface-2); color: var(--muted); }
.vct-chip.zone-learn { background: var(--accent-dim); color: var(--accent); }
.vct-chip.zone-easy { background: rgba(140, 182, 255, 0.14); color: var(--good); }
.vct-chip.zone-hard { background: rgba(255, 107, 129, 0.12); color: var(--bad); }
.round-chip.zone-border-learn { border-color: var(--accent); }
.round-chip.zone-border-easy { border-color: var(--good); }
.round-chip.zone-border-hard { border-color: var(--bad); }
.vct-rules { display: flex; flex-direction: column; gap: 6px; padding-left: 18px; font-size: 0.9rem; }
.vct-rules-card summary { cursor: pointer; list-style: none; }
.vct-rules-card summary::-webkit-details-marker { display: none; }
.vct-rules-card summary h3 { display: inline; }
.vct-rules-card summary::after { content: ' ▸'; color: var(--muted); }
.vct-rules-card[open] summary::after { content: ' ▾'; }

/* Riposo e deathmatch sopra l'arena (il mouse resta catturato durante il riposo) */
.vct-overlay { z-index: 35; }
.vct-rest-card, .vct-dm-card { max-width: 520px; width: calc(100vw - 32px); }
.vct-rest-result { display: flex; gap: 36px; flex-wrap: wrap; }
.vct-rest-result div { display: flex; flex-direction: column; }
.vct-rest-result .k { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.1em; color: var(--muted); }
.vct-rest-result .v { font-family: var(--font-mono); font-size: 2rem; color: var(--accent); line-height: 1.15; }
.vct-rest-result .sub { font-size: 0.8rem; color: var(--muted); min-height: 1em; }
.vct-zone { padding: 10px 12px; border-radius: 9px; background: var(--bg); border-left: 3px solid var(--faint); font-size: 0.92rem; }
.vct-zone.zone-learn { border-left-color: var(--accent); }
.vct-zone.zone-easy { border-left-color: var(--good); }
.vct-zone.zone-hard { border-left-color: var(--bad); }
.vct-next { display: flex; flex-direction: column; gap: 2px; padding: 10px 12px; border: 1px dashed var(--border); border-radius: 9px; }
.vct-rest-timer { display: flex; align-items: baseline; gap: 10px; }
.vct-rest-timer .mono { font-size: 2.4rem; font-variant-numeric: tabular-nums; }
