:root {
  --bg: #06080c;
  --bg-elevated: #0d1117;
  --bg-panel: #11161f;
  --bg-input: #0a0e14;
  --border: #232c3a;
  --border-strong: #334155;
  --text: #e8eef7;
  --text-muted: #94a3b8;
  --text-dim: #64748b;
  --accent: #e31937;
  --accent-hover: #ff2b49;
  --accent-soft: rgba(227, 25, 55, 0.14);
  --ok: #22c55e;
  --warn: #f59e0b;
  --danger: #ef4444;
  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 18px 60px rgba(0, 0, 0, 0.55);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

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

body {
  background:
    radial-gradient(1100px 500px at 50% -180px, rgba(227, 25, 55, 0.13), transparent 65%),
    var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: #7dd3fc; text-decoration: none; }
a:hover { text-decoration: underline; }

h1, h2, h3 { line-height: 1.2; margin: 0 0 0.5em; }
h1 { font-size: 1.75rem; letter-spacing: -0.01em; }
h2 { font-size: 1.2rem; }
p { margin: 0 0 1em; }

.muted { color: var(--text-muted); }
.dim { color: var(--text-dim); }
.small { font-size: 0.85rem; }
.hidden { display: none !important; }

/* ── Brand ─────────────────────────────────────────────────────────────── */
.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-weight: 800;
  letter-spacing: 0.14em;
  font-size: 0.95rem;
  color: var(--text);
  text-transform: uppercase;
}
.brand .brand-mark {
  width: 10px;
  height: 22px;
  border-radius: 2px;
  background: linear-gradient(180deg, var(--accent), #7f0d1e);
  box-shadow: 0 0 18px rgba(227, 25, 55, 0.55);
}
.brand span.sub {
  color: var(--text-dim);
  font-weight: 500;
  letter-spacing: 0.02em;
  text-transform: none;
}

/* ── Layout ────────────────────────────────────────────────────────────── */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 22px;
  border-bottom: 1px solid var(--border);
  background: rgba(6, 8, 12, 0.82);
  backdrop-filter: blur(12px);
  position: sticky;
  top: 0;
  z-index: 20;
}
.topbar-right {
  display: flex;
  align-items: center;
  gap: 14px;
  font-size: 0.88rem;
  color: var(--text-muted);
  min-width: 0;
}
#userEmail {
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

main.container {
  width: min(1080px, 100%);
  margin: 0 auto;
  padding: 22px 18px 60px;
}

/* ── Disclaimer ────────────────────────────────────────────────────────── */
.disclaimer {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  padding: 12px 16px;
  margin-bottom: 20px;
  border: 1px solid rgba(245, 158, 11, 0.42);
  background: rgba(245, 158, 11, 0.08);
  color: #fcd34d;
  border-radius: var(--radius-sm);
  font-size: 0.88rem;
}
.disclaimer strong { color: #fde68a; }
.disclaimer .icon { font-size: 1.15rem; line-height: 1.2; }

/* ── Panels ────────────────────────────────────────────────────────────── */
.panel {
  background: linear-gradient(180deg, rgba(17, 22, 31, 0.92), rgba(9, 13, 19, 0.92));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 26px;
}

.setup-panel { max-width: 720px; margin: 0 auto; }
.setup-panel .lead { color: var(--text-muted); max-width: 60ch; }

/* ── Forms ─────────────────────────────────────────────────────────────── */
label.field {
  display: block;
  margin: 18px 0;
}
label.field > span.label-text {
  display: block;
  font-size: 0.86rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 7px;
  letter-spacing: 0.02em;
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="url"] {
  width: 100%;
  padding: 13px 14px;
  color: var(--text);
  background: var(--bg-input);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  font-size: 1rem;
  font-family: var(--font);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
input::placeholder { color: #4b5a6e; }

.password-wrap { position: relative; }
.password-wrap input { padding-right: 84px; }
.password-wrap .toggle-visibility {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  background: transparent;
  border: 0;
  color: var(--text-muted);
  font-size: 0.8rem;
  cursor: pointer;
  padding: 8px 10px;
  border-radius: 6px;
}
.password-wrap .toggle-visibility:hover { color: var(--text); background: rgba(255,255,255,0.06); }

button {
  font-family: var(--font);
  font-size: 0.95rem;
  cursor: pointer;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 11px 18px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: #151c27;
  color: var(--text);
  font-weight: 600;
  transition: background 0.15s, border-color 0.15s, transform 0.05s;
  min-height: 44px;
}
.btn:hover { background: #1b2432; border-color: #475569; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn.primary {
  background: linear-gradient(180deg, var(--accent), #b3122a);
  border-color: #ff415c;
  color: #fff;
}
.btn.primary:hover { background: linear-gradient(180deg, var(--accent-hover), #c41530); }
.btn.ghost { background: transparent; }
.btn.block { width: 100%; }
.btn.danger { color: #fecaca; border-color: rgba(239, 68, 68, 0.45); background: rgba(239, 68, 68, 0.1); }

.btn .spinner {
  width: 15px;
  height: 15px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.35);
  border-top-color: #fff;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Mode cards ────────────────────────────────────────────────────────── */
.mode-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin: 6px 0 4px;
}
.mode-card {
  position: relative;
  display: block;
  padding: 15px 15px 15px 44px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.mode-card:hover { border-color: #475569; }
.mode-card input {
  position: absolute;
  left: 15px;
  top: 18px;
  accent-color: var(--accent);
  width: 17px;
  height: 17px;
  margin: 0;
}
.mode-card .mode-title { font-weight: 700; display: block; margin-bottom: 3px; }
.mode-card .mode-desc { color: var(--text-muted); font-size: 0.82rem; display: block; }
.mode-card .mode-tag {
  display: inline-block;
  margin-top: 7px;
  font-size: 0.7rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-dim);
  border: 1px solid var(--border);
  padding: 1px 7px;
  border-radius: 99px;
}
.mode-card:has(input:checked) {
  border-color: var(--accent);
  background: var(--accent-soft);
}
.mode-card input:checked ~ .mode-title { color: #fff; }

/* Fallback per browser senza :has() */
.mode-card.selected {
  border-color: var(--accent);
  background: var(--accent-soft);
}

/* ── Alerts ────────────────────────────────────────────────────────────── */
.error, .notice {
  border-radius: var(--radius-sm);
  padding: 11px 14px;
  font-size: 0.9rem;
  margin: 14px 0 0;
}
.error {
  color: #fecaca;
  background: rgba(239, 68, 68, 0.12);
  border: 1px solid rgba(239, 68, 68, 0.4);
}
.notice {
  color: #bae6fd;
  background: rgba(14, 165, 233, 0.1);
  border: 1px solid rgba(14, 165, 233, 0.35);
}

/* ── Player ────────────────────────────────────────────────────────────── */
.player-panel { padding: 0; overflow: hidden; }
.player-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 13px 18px;
  border-bottom: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.02);
}
.player-title {
  font-weight: 600;
  font-size: 0.95rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.player-badge {
  flex: none;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #fecdd3;
  background: var(--accent-soft);
  border: 1px solid rgba(227, 25, 55, 0.4);
  padding: 3px 9px;
  border-radius: 99px;
}

.stage {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  background: #000;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}
@supports not (aspect-ratio: 1) {
  .stage { height: 0; padding-bottom: 56.25%; }
  .stage > * { position: absolute; }
}
.stage canvas {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
  background: #000;
}
.stage-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 24px;
  text-align: center;
  background: rgba(3, 6, 10, 0.72);
  color: var(--text-muted);
  z-index: 5;
}
.stage-overlay .spinner-lg {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 3px solid rgba(255, 255, 255, 0.16);
  border-top-color: var(--accent);
  animation: spin 0.9s linear infinite;
}
.stage-overlay strong { color: var(--text); font-size: 1.05rem; }
.stage-overlay .btn { margin-top: 6px; }

.audio-unlock {
  position: absolute;
  left: 50%;
  bottom: 18px;
  transform: translateX(-50%);
  z-index: 8;
}
.audio-unlock button {
  background: rgba(227, 25, 55, 0.92);
  border: 1px solid #ff415c;
  color: #fff;
  font-weight: 700;
  padding: 12px 20px;
  border-radius: 99px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
}

.controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  padding: 14px 18px;
  border-top: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.02);
}
.controls .spacer { flex: 1; }
.volume-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-muted);
}
.volume-wrap input[type="range"] {
  width: 92px;
  accent-color: var(--accent);
  cursor: pointer;
}

.status-line {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 18px;
  padding: 10px 18px 14px;
  font-size: 0.8rem;
  color: var(--text-dim);
  border-top: 1px solid rgba(35, 44, 58, 0.55);
}
.status-line b { color: var(--text-muted); font-weight: 600; }
.status-dot {
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-dim);
  margin-right: 6px;
  vertical-align: 1px;
}
.status-dot.live { background: var(--ok); box-shadow: 0 0 8px rgba(34, 197, 94, 0.8); animation: pulse 1.6s infinite; }
.status-dot.error { background: var(--danger); }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.35; } }

/* ── Tips ──────────────────────────────────────────────────────────────── */
.tips {
  margin-top: 22px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: 14px;
}
.tip {
  border: 1px solid var(--border);
  background: rgba(13, 17, 23, 0.7);
  border-radius: var(--radius-sm);
  padding: 15px 16px;
  font-size: 0.88rem;
  color: var(--text-muted);
}
.tip h3 {
  font-size: 0.82rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-dim);
  margin-bottom: 7px;
}

/* ── Auth pages ────────────────────────────────────────────────────────── */
.auth-body {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 28px 16px;
}
.auth-wrap { width: min(420px, 100%); }
.auth-brand { margin-bottom: 22px; justify-content: center; display: flex; }
.card {
  background: linear-gradient(180deg, rgba(17, 22, 31, 0.95), rgba(9, 13, 19, 0.95));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 28px 26px;
}
.card h1 { font-size: 1.5rem; }
.card .muted { font-size: 0.9rem; }
.card form { margin-top: 18px; }
.card .btn.block { margin-top: 22px; }
.switch { text-align: center; font-size: 0.88rem; color: var(--text-muted); margin: 20px 0 0; }
.legal {
  margin-top: 22px;
  text-align: center;
  font-size: 0.76rem;
  color: var(--text-dim);
  line-height: 1.5;
}
.password-hint { font-size: 0.76rem; color: var(--text-dim); margin-top: 6px; }

/* ── Fullscreen ────────────────────────────────────────────────────────── */
.stage:fullscreen,
.stage:-webkit-full-screen {
  aspect-ratio: auto;
  width: 100vw;
  height: 100vh;
  background: #000;
}
.stage:fullscreen canvas,
.stage:-webkit-full-screen canvas { width: 100vw; height: 100vh; }

/* ── Responsive ────────────────────────────────────────────────────────── */
@media (max-width: 640px) {
  main.container { padding: 16px 12px 46px; }
  .panel { padding: 20px 16px; }
  .mode-grid { grid-template-columns: 1fr; }
  .topbar { padding: 12px 14px; }
  #userEmail { display: none; }
  h1 { font-size: 1.45rem; }
  .controls { gap: 8px; }
  .controls .btn { padding: 10px 12px; font-size: 0.86rem; }
  .volume-wrap input[type="range"] { width: 64px; }
}

/* ── Fullscreen del pannello player (comandi sempre accessibili) ───────── */
.player-panel:fullscreen,
.player-panel:-webkit-full-screen {
  width: 100vw;
  height: 100vh;
  border: 0;
  border-radius: 0;
  display: flex;
  flex-direction: column;
  background: #000;
  box-shadow: none;
}
.player-panel:fullscreen .stage,
.player-panel:-webkit-full-screen .stage {
  flex: 1;
  aspect-ratio: auto;
  min-height: 0;
}
.player-panel:fullscreen .stage canvas,
.player-panel:-webkit-full-screen .stage canvas {
  width: 100%;
  height: 100%;
}
