* { box-sizing: border-box; margin: 0; padding: 0; }
:root {
  --bg: #161618;
  --panel: #1f1f22;
  --panel-2: #2a2a2e;
  --fg: #f2f2f7;
  --muted: #9a9aa0;
  --accent: #0a84ff;
  --danger: #ff453a;
  --ok: #30d158;
}
html, body {
  height: 100%;
  background: var(--bg);
  color: var(--fg);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
}
body { display: flex; flex-direction: column; height: 100vh; }

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 20px;
  background: var(--panel);
  border-bottom: 1px solid rgba(255, 255, 255, 0.07);
  flex: 0 0 auto;
}
.brand { display: flex; align-items: center; gap: 10px; font-size: 15px; }
.brand b { font-weight: 700; }
.conn { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--muted); }
.dot.online { background: var(--ok); box-shadow: 0 0 8px var(--ok); }
.dot.warn { background: #ff9f0a; }

.layout {
  flex: 1 1 auto;
  display: grid;
  grid-template-columns: minmax(340px, 1fr) minmax(320px, 420px);
  gap: 20px;
  padding: 20px;
  overflow: hidden;
  min-height: 0;
}
@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; overflow: auto; }
}

/* ---- Anteprima ---- */
.preview-col { display: flex; flex-direction: column; min-height: 0; }
.device-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 4 / 3;
  max-height: 60vh;
  border-radius: 18px;
  overflow: hidden;
  background: #000;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
  border: 2px solid #333;
}
.device {
  position: absolute;
  top: 0; left: 0;
  width: 1024px; height: 768px;   /* risoluzione logica di riferimento */
  transform-origin: top left;
}
.stage { position: absolute; inset: 0; background: #000; overflow: hidden; }
.viewport { position: absolute; inset: 0; overflow: hidden; transform-origin: 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: 384px; }
.tp-spacer-bottom { height: 460px; }
.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.7); pointer-events: none; z-index: 5;
}

/* Popup pausa nell'anteprima, ancorato appena sopra la 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% - 20px));
  z-index: 6;
}
.pause-anchor[hidden] { display: none; }
.pause-badge {
  display: flex; align-items: center; gap: 12px;
  background: rgba(255, 159, 10, 0.97); color: #1a1200; font-weight: 700;
  padding: 14px 26px; border-radius: 999px; white-space: nowrap;
  box-shadow: 0 12px 40px rgba(255, 159, 10, 0.5), 0 0 0 4px rgba(255, 159, 10, 0.28);
  animation: pausePulse 1s ease-in-out infinite;
}
.pause-ico { font-size: 26px; line-height: 1; }
.pause-lbl { text-transform: uppercase; letter-spacing: .05em; font-size: 20px; }
.pause-num { font-size: 40px; font-variant-numeric: tabular-nums; line-height: 1; }
.pause-s { font-size: 22px; opacity: .75; }
@keyframes pausePulse {
  0%, 100% { transform: scale(1); }
  50%      { transform: scale(1.06); }
}

/* ---- Trasporto ---- */
.transport {
  display: flex; justify-content: center; gap: 12px; margin: 16px 0 10px;
}
.tbtn {
  width: 52px; height: 52px; border-radius: 50%;
  border: none; background: var(--panel-2); color: var(--fg);
  font-size: 20px; cursor: pointer;
}
.tbtn:hover { background: #37373c; }
.tbtn:active { transform: scale(0.94); }
.tbtn.primary { width: 64px; height: 64px; background: var(--accent); font-size: 26px; }

.seek-row { display: flex; align-items: center; gap: 12px; }
.seek-row input { flex: 1; accent-color: var(--accent); }
.pct { font-variant-numeric: tabular-nums; color: var(--muted); min-width: 46px; text-align: right; }

.timer-bar {
  display: flex; justify-content: space-between; gap: 12px;
  margin-top: 14px; padding: 12px 16px;
  background: var(--panel); border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.05);
}
.tblock { display: flex; flex-direction: column; align-items: center; flex: 1; }
.tval { font-size: 22px; font-variant-numeric: tabular-nums; font-weight: 600; }
.tlbl { font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin-top: 2px; }
#tRemain { color: var(--accent); }

.startpoint { display: flex; align-items: center; gap: 12px; margin-top: 14px; flex-wrap: wrap; }
.ghost {
  background: transparent; border: 1px solid rgba(255, 255, 255, 0.2);
  color: var(--fg); border-radius: 10px; padding: 8px 14px; cursor: pointer; font-size: 14px;
}
.ghost:hover { border-color: var(--accent); color: var(--accent); }
.startlabel { color: var(--muted); font-size: 13px; }
.displays-note { color: var(--muted); font-size: 13px; margin-top: 10px; }

/* ---- Controlli ---- */
.controls-col { overflow-y: auto; padding-right: 6px; min-height: 0; }
.panel {
  background: var(--panel); border-radius: 14px; padding: 16px 18px; margin-bottom: 16px;
  border: 1px solid rgba(255, 255, 255, 0.05);
}
.panel h2 {
  font-size: 12px; text-transform: uppercase; letter-spacing: .06em;
  color: var(--muted); margin-bottom: 14px;
}
label { display: block; font-size: 14px; margin-bottom: 14px; }
label:last-child { margin-bottom: 0; }
label output { color: var(--accent); float: right; font-variant-numeric: tabular-nums; }
input[type="range"] { width: 100%; margin-top: 8px; accent-color: var(--accent); }
select, textarea {
  width: 100%; background: var(--panel-2); color: var(--fg);
  border: 1px solid rgba(255, 255, 255, 0.1); border-radius: 10px;
  padding: 10px; font-size: 14px; margin-top: 6px; font-family: inherit;
}
textarea { resize: vertical; line-height: 1.4; }
.row { display: flex; gap: 10px; 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: 50px; height: 34px; border: none; background: none; border-radius: 8px; cursor: pointer; }
.switch { display: flex; align-items: center; justify-content: space-between; }
.switch input { transform: scale(1.3); accent-color: var(--accent); }
.file-btn {
  display: inline-flex; align-items: center; gap: 6px; margin: 0;
  background: var(--panel-2); border-radius: 10px; padding: 9px 13px; cursor: pointer; font-size: 13px;
}
.mini {
  background: var(--panel-2); color: var(--fg); border: none;
  border-radius: 10px; padding: 9px 13px; cursor: pointer; font-size: 13px;
}
.mini:hover { background: #37373c; }
.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(--muted); font-size: 13px; margin-top: 8px; }
.hint code { background: var(--panel-2); padding: 2px 6px; border-radius: 5px; }

/* ---- Sessione: badge in topbar + overlay di avvio ---- */
.session-badge { font-size: 13px; color: var(--muted); }
.session-badge b { color: var(--fg); font-size: 15px; letter-spacing: .06em; }
.linkbtn { background: none; border: 0; color: var(--accent); cursor: pointer; font-size: 13px; padding: 2px 4px; }

.overlay { position: fixed; inset: 0; z-index: 1000; display: flex; align-items: center; justify-content: center;
  background: rgba(0,0,0,.65); }
.overlay[hidden] { display: none; }
.overlay-card { background: var(--panel); color: var(--fg); border: 1px solid #3a3a3c; border-radius: 16px;
  padding: 28px 30px; width: min(92vw, 420px); box-shadow: 0 24px 70px rgba(0,0,0,.55); text-align: center; }
.overlay-card h1 { margin: 0 0 6px; font-size: 22px; }
.overlay-sub { margin: 0 0 20px; color: var(--muted); font-size: 14px; line-height: 1.45; }
.pin-box { display: flex; align-items: center; justify-content: center; gap: 14px; margin-bottom: 18px; }
.pin-lbl { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .1em; }
.pin-num { font-size: 42px; font-weight: 800; letter-spacing: .12em; font-variant-numeric: tabular-nums; }
.overlay-field { display: block; text-align: left; color: var(--muted); font-size: 13px; margin-bottom: 14px; }
.overlay-field input { display: block; width: 100%; margin-top: 6px; padding: 12px 14px; font-size: 16px;
  border-radius: 10px; border: 1px solid #48484a; background: var(--panel-2); color: var(--fg); box-sizing: border-box; }
.overlay-error { min-height: 18px; margin: 0 0 12px; color: var(--danger); font-size: 13px; }

/* Pop-up guida al copione */
.help-card { width: min(94vw, 640px); max-height: 86vh; overflow-y: auto; text-align: left; }
.help-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.help-head h1 { margin: 0; }
.help-close { background: none; border: 0; color: var(--muted); font-size: 22px; line-height: 1; cursor: pointer; padding: 0 2px; }
.help-close:hover { color: var(--fg); }
.help-card h3 { margin: 20px 0 6px; font-size: 15px; color: var(--fg); }
.help-card p, .help-card li { color: var(--muted); font-size: 13.5px; line-height: 1.5; }
.help-card ul { margin: 0 0 10px; padding-left: 20px; }
.help-card li { margin-bottom: 4px; }
.help-card code { background: var(--panel-2); padding: 2px 6px; border-radius: 5px; }
.help-card pre { background: var(--panel-2); padding: 12px 14px; border-radius: 10px; margin: 10px 0 14px;
  overflow-x: auto; font-size: 12.5px; line-height: 1.45; color: var(--fg); white-space: pre; }
.help-key { color: var(--fg); font-weight: 600; }

/* Pop-up QR per l'iPad */
.qr-wrap { display: flex; justify-content: center; margin: 6px 0 14px; }
.qr-wrap canvas { width: 260px; height: 260px; image-rendering: pixelated; background: #fff;
  border-radius: 12px; padding: 12px; box-sizing: content-box; }
.qr-creds { text-align: center; color: var(--muted); font-size: 14px; margin: 0; }
.qr-creds b { color: var(--fg); font-variant-numeric: tabular-nums; }
.primary.big { width: 100%; padding: 13px; font-size: 16px; font-weight: 700; border: 0; border-radius: 10px;
  background: var(--accent); color: #fff; cursor: pointer; }
.primary.big:disabled { opacity: .5; cursor: default; }
