* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
:root {
  --ui-bg: #1c1c1e;
  --ui-bg-2: #2c2c2e;
  --ui-fg: #f2f2f7;
  --ui-muted: #98989f;
  --accent: #0a84ff;
  --danger: #ff453a;
  --radius: 14px;
}
html, body {
  height: 100%;
  overflow: hidden;
  background: #000;
  color: var(--ui-fg);
  font-family: system-ui, -apple-system, sans-serif;
  overscroll-behavior: none;
  touch-action: manipulation;
}

/* ---- Palcoscenico teleprompter ---- */
.stage {
  position: fixed;
  inset: 0;
  background: #000;
  overflow: hidden;
}
.viewport {
  position: absolute;
  inset: 0;
  overflow: hidden;
  transform-origin: center center;
  will-change: transform;
}
.content {
  position: absolute;
  top: 0; left: 0; right: 0;
  white-space: pre-wrap;
  word-break: break-word;
  will-change: transform;
}
.tp-spacer-top { height: 50vh; }
.tp-spacer-bottom { height: 60vh; }
.tp-pause {
  display: inline-block;
  width: 0; height: 0;
  overflow: hidden;
}
.reading-line {
  position: absolute;
  left: 0; right: 0;
  height: 0;
  border-top: 2px solid rgba(255, 59, 48, 0.65);
  pointer-events: none;
  z-index: 5;
}
.reading-line::before,
.reading-line::after {
  content: '';
  position: absolute;
  top: -7px;
  border: 8px solid transparent;
}
.reading-line::before { left: 0; border-left-color: rgba(255, 59, 48, 0.8); }
.reading-line::after { right: 0; border-right-color: rgba(255, 59, 48, 0.8); }

/* Popup pausa: ancorato appena sopra la riga di lettura (la frase appena finita).
   La posizione verticale (top) viene impostata via JS = posizione riga di lettura. */
/* Ancora = posizione + flip (impostato via JS); badge interno = aspetto +
   pulse (solo scale, così non sovrascrive il flip). */
.pause-anchor {
  position: absolute;
  left: 50%;
  top: 40%;
  transform: translate(-50%, calc(-100% - 18px));
  z-index: 30;
}
.pause-anchor[hidden] { display: none; }
.pause-badge {
  display: flex;
  align-items: center;
  gap: 10px;
  background: rgba(255, 159, 10, 0.97);
  color: #1a1200;
  font-weight: 700;
  padding: 12px 22px;
  border-radius: 999px;
  white-space: nowrap;
  box-shadow: 0 10px 34px rgba(255, 159, 10, 0.5), 0 0 0 3px rgba(255, 159, 10, 0.28);
  animation: pausePulse 1s ease-in-out infinite;
}
.pause-ico { font-size: 22px; line-height: 1; }
.pause-lbl { text-transform: uppercase; letter-spacing: .05em; font-size: 17px; }
.pause-num { font-size: 32px; font-variant-numeric: tabular-nums; line-height: 1; }
.pause-s { font-size: 18px; opacity: .75; }
@keyframes pausePulse {
  0%, 100% { transform: scale(1); }
  50%      { transform: scale(1.06); }
}

/* ---- Dock comandi ---- */
.dock {
  position: fixed;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom, 0px) + 16px);
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  background: rgba(28, 28, 30, 0.82);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-radius: 999px;
  z-index: 20;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.5);
  transition: opacity .3s;
  max-width: min(720px, 92vw);
}
.dock.hidden { opacity: 0; pointer-events: none; }
.dock-btn {
  border: none;
  background: var(--ui-bg-2);
  color: var(--ui-fg);
  width: 48px; height: 48px;
  border-radius: 50%;
  font-size: 20px;
  cursor: pointer;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
}
.dock-btn:active { transform: scale(0.92); }
.dock-btn.primary { background: var(--accent); width: 56px; height: 56px; font-size: 24px; }
.seek {
  flex: 1 1 120px;
  min-width: 80px;
  accent-color: var(--accent);
  height: 6px;
}
.progress-label {
  font-variant-numeric: tabular-nums;
  color: var(--ui-muted);
  min-width: 42px;
  text-align: right;
  font-size: 14px;
}

/* ---- Indicatore connessione ---- */
.conn {
  position: fixed;
  top: calc(env(safe-area-inset-top, 0px) + 12px);
  right: 16px;
  display: flex; align-items: center; gap: 8px;
  background: rgba(28, 28, 30, 0.7);
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 13px;
  color: var(--ui-muted);
  z-index: 20;
  backdrop-filter: blur(10px);
}
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--ui-muted); }
.dot.online { background: #30d158; box-shadow: 0 0 8px #30d158; }
.dot.remote { background: var(--accent); box-shadow: 0 0 8px var(--accent); }

/* Pulsante "Riconnetti" di sicurezza dentro il badge connessione. */
.conn-reconnect {
  background: var(--accent); border: 0; color: #fff;
  font-size: 13px; font-weight: 600; padding: 4px 10px;
  border-radius: 999px; cursor: pointer; -webkit-appearance: none;
}

.timer {
  position: fixed;
  top: calc(env(safe-area-inset-top, 0px) + 12px);
  left: 16px;
  display: flex; align-items: center; gap: 6px;
  background: rgba(28, 28, 30, 0.7);
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 14px;
  font-variant-numeric: tabular-nums;
  color: var(--ui-fg);
  z-index: 20;
  backdrop-filter: blur(10px);
}
.timer-sep { color: var(--ui-muted); }
#timeTotal { color: var(--ui-muted); }

/* ---- Drawer impostazioni ---- */
.drawer {
  position: fixed;
  top: 0; right: 0; bottom: 0;
  width: min(420px, 90vw);
  background: var(--ui-bg);
  z-index: 40;
  transform: translateX(100%);
  transition: transform .3s ease;
  display: flex;
  flex-direction: column;
  box-shadow: -10px 0 40px rgba(0, 0, 0, 0.5);
}
.drawer.open { transform: translateX(0); }
.drawer-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(env(safe-area-inset-top, 0px) + 16px) 20px 16px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}
.drawer-head h1 { font-size: 20px; }
.close {
  background: var(--ui-bg-2); color: var(--ui-fg);
  border: none; width: 36px; height: 36px; border-radius: 50%;
  font-size: 16px; cursor: pointer;
}
.drawer-body {
  overflow-y: auto;
  padding: 8px 20px calc(env(safe-area-inset-bottom, 0px) + 40px);
  -webkit-overflow-scrolling: touch;
}
.drawer-body section {
  padding: 18px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}
.drawer-body h2 {
  font-size: 13px; text-transform: uppercase; letter-spacing: .06em;
  color: var(--ui-muted); margin-bottom: 12px;
}
label {
  display: block;
  font-size: 15px;
  margin-bottom: 14px;
}
label output { color: var(--accent); font-variant-numeric: tabular-nums; float: right; }
input[type="range"] { width: 100%; margin-top: 8px; accent-color: var(--accent); }
select, textarea {
  width: 100%;
  background: var(--ui-bg-2);
  color: var(--ui-fg);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 10px;
  padding: 12px;
  font-size: 15px;
  margin-top: 8px;
  font-family: inherit;
}
textarea { resize: vertical; line-height: 1.4; }
.row { display: flex; gap: 12px; margin-top: 10px; align-items: center; flex-wrap: wrap; }
.color { flex: 1; display: flex; align-items: center; justify-content: space-between; margin: 0; }
input[type="color"] {
  width: 52px; height: 36px; border: none; background: none; border-radius: 8px; cursor: pointer;
}
.switch { display: flex; align-items: center; justify-content: space-between; }
.switch input { width: auto; transform: scale(1.4); accent-color: var(--accent); }
.file-btn {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--ui-bg-2); border-radius: 10px; padding: 10px 14px;
  cursor: pointer; margin: 0; font-size: 14px;
}
.mini {
  background: var(--ui-bg-2); color: var(--ui-fg); border: none;
  border-radius: 10px; padding: 10px 14px; cursor: pointer; font-size: 14px;
}
.mini.danger { color: var(--danger); }
.presets { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.preset {
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 8px; padding: 6px 10px; cursor: pointer; font-size: 12px;
}
.hint { color: var(--ui-muted); font-size: 13px; line-height: 1.4; margin-top: 6px; }
.hint code { background: var(--ui-bg-2); padding: 2px 6px; border-radius: 5px; }

.scrim {
  position: fixed; inset: 0; background: rgba(0, 0, 0, 0.4); z-index: 35;
}

/* ---- Overlay d'ingresso stanza (PIN + password) ---- */
.join-overlay { position: fixed; inset: 0; z-index: 2000; display: flex; align-items: center; justify-content: center;
  background: #000; }
.join-overlay[hidden] { display: none; }
.join-card { width: min(90vw, 380px); text-align: center; color: #fff; padding: 24px; }
.join-card h1 { margin: 0 0 8px; font-size: 26px; }
.join-sub { margin: 0 0 24px; color: #9a9aa0; font-size: 15px; line-height: 1.4; }
.join-pin, .join-pass { display: block; width: 100%; box-sizing: border-box; margin-bottom: 14px;
  padding: 16px 18px; font-size: 20px; border-radius: 12px; border: 1px solid #48484a;
  background: #1c1c1e; color: #fff; text-align: center; }
.join-pin { letter-spacing: .3em; font-weight: 700; font-variant-numeric: tabular-nums; }
.join-error { min-height: 20px; margin: 0 0 12px; color: #ff6b6b; font-size: 14px; }
.join-card .primary.big { width: 100%; padding: 16px; font-size: 18px; font-weight: 700; border: 0;
  border-radius: 12px; background: #0a84ff; color: #fff; cursor: pointer; margin-bottom: 10px; }
.join-card .primary.big:disabled { opacity: .5; }
.join-card .linkbtn { background: none; border: 0; color: #0a84ff; font-size: 15px; padding: 8px; cursor: pointer; }
.join-card .ghost.big { width: 100%; padding: 15px; font-size: 17px; font-weight: 600; cursor: pointer;
  border-radius: 12px; border: 1px solid #48484a; background: transparent; color: #fff; margin-bottom: 10px; }
.join-card .ghost.big:disabled { opacity: .5; }
.join-or { display: flex; align-items: center; gap: 12px; margin: 4px 0 16px; color: #6a6a70; font-size: 13px; }
.join-or::before, .join-or::after { content: ''; flex: 1; height: 1px; background: #3a3a3c; }

/* Scanner QR a schermo intero */
.scan-overlay { position: fixed; inset: 0; z-index: 3000; background: #000; overflow: hidden; }
.scan-overlay[hidden] { display: none; }
.scan-overlay video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.scan-mask { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; }
.scan-frame { width: min(70vw, 70vh); height: min(70vw, 70vh); border: 3px solid rgba(255,255,255,.9);
  border-radius: 20px; box-shadow: 0 0 0 100vmax rgba(0,0,0,.45); }
.scan-hint { position: absolute; left: 0; right: 0; bottom: 120px; text-align: center; color: #fff;
  font-size: 16px; padding: 0 24px; text-shadow: 0 1px 3px rgba(0,0,0,.8); }
.scan-cancel { position: absolute; left: 50%; transform: translateX(-50%); bottom: 48px;
  padding: 13px 28px; font-size: 16px; font-weight: 600; border: 0; border-radius: 12px;
  background: rgba(255,255,255,.16); color: #fff; -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px); cursor: pointer; }
