/* lab-extras.css — stile delle funzioni aggiunte al laboratorio bytebeat.
   Palette ripresa dalla pagina esistente: fondo chiaro, verde-petrolio,
   accento ambra. */

:root {
  --bb-ink:    #17434a;
  --bb-soft:   #5b7d78;
  --bb-line:   #cddbd7;
  --bb-paper:  #ffffff;
  --bb-wash:   #eef3f1;
  --bb-amber:  #c8811f;
  --bb-teal:   #0d9488;
}

/* ── Termini illuminati nell'overlay ──────────────────────────────────────
   Regola ferrea: NESSUNA proprietà che cambi le dimensioni del testo.
   L'overlay è sovrapposto carattere per carattere a una textarea trasparente:
   un solo pixel di padding o un letter-spacing diverso e il codice scritto non
   coinciderebbe più con quello illuminato. Si toccano solo colore e sfondo. */
.bb-term {
  --a: 0;
  border-radius: 3px;
  transition: background-color 90ms linear, color 90ms linear;
  background-color: rgba(200, 129, 31, calc(var(--a) * 0.30));
  color: color-mix(in srgb, #365c56 calc((1 - var(--a)) * 100%), #8a3b06);
}
.bb-term.live {
  text-shadow: 0 0 calc(var(--a) * 7px) rgba(200, 129, 31, calc(var(--a) * 0.65));
}

/* ── Finestra flottante (usata da "Codice vivo") ───────────────────────────
   Stessa impostazione della finestra delle montagne: barra per spostare,
   angolo per ridimensionare. Sta sopra la pagina invece che dentro il flusso,
   cosi' la si accosta all'editor e ci resta mentre si scrive. */
.bb-fl {
  position: fixed; z-index: 185;
  left: auto; right: 20px; top: 96px;
  width: 300px; height: 340px;
  min-width: 240px; min-height: 160px;
  background: var(--bb-paper);
  border: 1px solid var(--bb-line);
  border-radius: 11px;
  box-shadow: 0 14px 38px rgba(23, 67, 74, 0.20);
  display: flex; flex-direction: column; overflow: hidden;
}
.bb-fl.hidden { display: none; }
.bb-fl.moving { user-select: none; transition: none; }

.bb-fl-head {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 8px 10px; border-bottom: 1px solid var(--bb-line);
  background: linear-gradient(#fbfdfc, #f2f7f5);
  cursor: grab; touch-action: none; user-select: none;
  font-size: 12px; font-weight: 700; color: var(--bb-ink);
  text-transform: uppercase; letter-spacing: 0.07em;
}
.bb-fl-head:active { cursor: grabbing; }
.bb-fl-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bb-fl-tools { display: flex; align-items: center; gap: 1px; flex-shrink: 0; }
.bb-fl-tool, .bb-fl-close {
  background: none; border: 0; cursor: pointer; line-height: 1;
  font-size: 13px; color: var(--bb-soft); padding: 4px 6px; border-radius: 5px;
  font-family: inherit;
}
.bb-fl-tool:hover, .bb-fl-close:hover { color: var(--bb-amber); background: var(--bb-wash); }
.bb-fl-body { flex: 1 1 auto; overflow-y: auto; padding: 10px 12px; }

.bb-fl-grip {
  position: absolute; right: 0; bottom: 0; width: 18px; height: 18px;
  cursor: nwse-resize; touch-action: none;
  background:
    linear-gradient(135deg, transparent 0 46%, var(--bb-line) 46% 54%, transparent 54% 100%),
    linear-gradient(135deg, transparent 0 70%, var(--bb-line) 70% 78%, transparent 78% 100%);
}
.bb-fl-grip:hover { background-color: var(--bb-wash); }

.bb-info { display: none; margin: 10px 0 4px; }
.bb-info.open { display: block; }
.bb-info p { margin: 0 0 8px; font-size: 12px; line-height: 1.6; color: var(--bb-soft); }

.bb-legend { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.bb-chip {
  --a: 0;
  font-family: ui-monospace, Menlo, monospace; font-size: 11px;
  padding: 3px 9px; border-radius: 20px; cursor: pointer;
  border: 1px solid color-mix(in srgb, var(--bb-line) calc((1 - var(--a)) * 100%), var(--bb-amber));
  background: rgba(200, 129, 31, calc(var(--a) * 0.22));
  color: color-mix(in srgb, var(--bb-soft) calc((1 - var(--a)) * 100%), #8a3b06);
  transition: background-color 90ms linear, border-color 90ms linear, color 90ms linear;
}
.bb-legend-empty { font-size: 11px; color: var(--bb-soft); }
.bb-status { margin-top: 9px; font-size: 11px; color: var(--bb-soft); }

/* ── Pulsanti flottanti ───────────────────────────────────────────────── */
/* I pulsanti si impilano SOPRA quello del toroide, che sta gia' fisso in basso
   a destra (right:20px, bottom:20px). Affiancarli lo coprirebbe. */
.bb-fab {
  position: fixed; right: 20px; z-index: 190;
  background: var(--bb-paper); color: var(--bb-ink);
  border: 1px solid var(--bb-line); border-radius: 22px;
  padding: 9px 16px; font-family: inherit; font-size: 12px; font-weight: 600;
  cursor: pointer; box-shadow: 0 6px 20px rgba(23, 67, 74, 0.14);
}
.bb-fab:hover { border-color: var(--bb-amber); color: var(--bb-amber); }
.bb-fab.hidden { display: none; }
.bb-fab-guide { bottom: 68px; }
.bb-fab-mt    { bottom: 116px; }
.bb-fab-hl    { bottom: 164px; }

/* ── Cassetto della guida ─────────────────────────────────────────────── */
.bb-backdrop {
  position: fixed; inset: 0; background: rgba(15, 40, 44, 0.32);
  opacity: 0; pointer-events: none; transition: opacity 0.2s; z-index: 215;
}
.bb-backdrop.open { opacity: 1; pointer-events: auto; }

.bb-drawer {
  position: fixed; top: 0; right: 0; height: 100%; width: min(560px, 94vw);
  background: var(--bb-paper); border-left: 1px solid var(--bb-line);
  /* Sopra il pulsante "Libreria Song" della pagina (z-index 210): a 80 quel
     pulsante restava a galleggiare sulla testata del cassetto, coprendo la ✕
     di chiusura e il selettore di lingua e rendendoli non cliccabili. */
  z-index: 220; display: flex; flex-direction: column;
  transform: translateX(102%); transition: transform 0.24s ease;
  box-shadow: -12px 0 34px rgba(23, 67, 74, 0.16);
}
.bb-drawer.open { transform: translateX(0); }
.bb-drawer-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px; border-bottom: 1px solid var(--bb-line);
}
.bb-drawer-head h3 { margin: 0; font-size: 15px; color: var(--bb-ink); }
.bb-close {
  background: none; border: 0; font-size: 17px; color: var(--bb-soft);
  cursor: pointer; line-height: 1; padding: 4px 6px;
}
.bb-close:hover { color: var(--bb-amber); }

/* Selettore di lingua della guida, accanto alla X di chiusura. */
.bb-guide-head-right { display: flex; align-items: center; gap: 10px; }
.bb-guide-lang { display: flex; gap: 3px; }
.bb-guide-lang-btn {
  border: 1px solid var(--bb-line); background: transparent;
  color: var(--bb-soft); font-family: inherit; font-size: 11px;
  font-weight: 600; letter-spacing: 0.04em; line-height: 1.4;
  padding: 3px 8px; border-radius: 6px; cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.bb-guide-lang-btn:hover { color: var(--bb-amber); border-color: var(--bb-amber); }
.bb-guide-lang-btn.active {
  background: var(--bb-amber); border-color: var(--bb-amber); color: #ffffff;
}

.bb-guide-search {
  margin: 12px 16px; padding: 9px 12px;
  border: 1px solid var(--bb-line); border-radius: 8px;
  font-family: inherit; font-size: 13px; color: var(--bb-ink);
  background: var(--bb-wash);
}
.bb-guide-body { flex: 1; overflow-y: auto; padding: 0 16px 26px; }
.bb-guide-sec { margin-bottom: 20px; }
.bb-guide-sec h4 {
  margin: 14px 0 6px; font-size: 14px; color: var(--bb-amber);
  border-bottom: 1px solid var(--bb-line); padding-bottom: 5px;
}
.bb-guide-intro { font-size: 12.5px; line-height: 1.65; color: var(--bb-soft); margin: 0 0 10px; }
.bb-guide-count, .bb-guide-none { font-size: 12px; color: var(--bb-soft); }

.bb-qa { border: 1px solid var(--bb-line); border-radius: 8px; margin-bottom: 7px; background: var(--bb-wash); }
.bb-qa[open] { background: var(--bb-paper); }
.bb-qa summary {
  cursor: pointer; padding: 9px 12px; font-size: 13px; font-weight: 600;
  color: var(--bb-ink); list-style: none;
}
.bb-qa summary::-webkit-details-marker { display: none; }
.bb-qa summary::before { content: "› "; color: var(--bb-amber); font-weight: 700; }
.bb-qa[open] summary::before { content: "⌄ "; }
.bb-qa-sec {
  display: block; font-size: 10px; font-weight: 500; color: var(--bb-soft);
  text-transform: uppercase; letter-spacing: 0.06em; margin-bottom: 2px;
}
.bb-qa-body { padding: 0 12px 12px; }
.bb-qa-body p { font-size: 12.5px; line-height: 1.68; color: #365c56; margin: 0 0 9px; }
.bb-qa-body code {
  background: var(--bb-wash); border: 1px solid var(--bb-line); border-radius: 4px;
  padding: 1px 4px; font-family: ui-monospace, Menlo, monospace; font-size: 11.5px;
  color: #8a3b06;
}
.bb-qa-code {
  background: #f7faf9; border: 1px solid var(--bb-line); border-radius: 7px;
  padding: 10px 12px; font-family: ui-monospace, Menlo, monospace;
  font-size: 11.5px; line-height: 1.55; color: #365c56;
  overflow-x: auto; white-space: pre; margin: 0 0 9px;
}
.bb-try {
  background: var(--bb-teal); color: #fff; border: 0; border-radius: 7px;
  padding: 8px 15px; font-family: inherit; font-size: 12px; font-weight: 600; cursor: pointer;
}
.bb-try:hover { filter: brightness(1.08); }

/* ── Montagne spettrali ───────────────────────────────────────────────── */
/* z-index sopra il pulsante del toroide (195), altrimenti quello resterebbe
   a galleggiare in mezzo alla vista 3D. */
.bb-mt-popup {
  position: fixed; right: 16px; bottom: 16px; z-index: 200;
  width: min(620px, calc(100vw - 32px)); height: min(470px, 66vh);
  min-width: 320px; min-height: 240px;
  background: var(--bb-paper); border: 1px solid var(--bb-line);
  border-radius: 12px; box-shadow: 0 18px 46px rgba(23, 67, 74, 0.22);
  display: flex; flex-direction: column; overflow: hidden;
}
.bb-mt-popup.hidden { display: none; }
/* Mentre si sposta o si ridimensiona: niente transizioni (renderebbero il
   trascinamento gommoso) e niente selezione di testo per sbaglio. */
.bb-mt-popup.moving { user-select: none; transition: none; }
.bb-mt-popup.moving .bb-mt-stage { pointer-events: none; }

.bb-mt-head {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 9px 12px; border-bottom: 1px solid var(--bb-line);
  font-size: 12px; font-weight: 600; color: var(--bb-ink);
  cursor: grab; touch-action: none; user-select: none;
  background: linear-gradient(#fbfdfc, #f2f7f5);
}
.bb-mt-head:active { cursor: grabbing; }
.bb-mt-title {
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.bb-mt-tools { display: flex; align-items: center; gap: 2px; flex-shrink: 0; }
.bb-mt-tool {
  background: none; border: 0; cursor: pointer; line-height: 1;
  font-size: 14px; color: var(--bb-soft); padding: 4px 6px; border-radius: 5px;
}
.bb-mt-tool:hover { color: var(--bb-amber); background: var(--bb-wash); }

/* Angolo di ridimensionamento: due righine diagonali, la convenzione che tutti
   riconoscono. */
.bb-mt-grip {
  position: absolute; right: 0; bottom: 0; width: 18px; height: 18px;
  cursor: nwse-resize; touch-action: none;
  background:
    linear-gradient(135deg, transparent 0 46%, var(--bb-line) 46% 54%, transparent 54% 100%),
    linear-gradient(135deg, transparent 0 70%, var(--bb-line) 70% 78%, transparent 78% 100%);
}
.bb-mt-grip:hover { background-color: var(--bb-wash); }

.bb-detached { border-color: var(--bb-teal); color: var(--bb-teal); }
.bb-mt-stage { flex: 1 1 auto; min-height: 150px; background: #fff; position: relative; }
.bb-mt-stage canvas { display: block; width: 100%; height: 100%; }
.bb-mt-axis {
  position: relative; height: 16px; margin: 0 10px;
  border-top: 1px solid var(--bb-line); font-size: 9px; color: var(--bb-soft);
}
.bb-mt-axis span { position: absolute; top: 2px; transform: translateX(-50%); }
.bb-mt-axis b { position: absolute; right: 0; top: 2px; font-weight: 600; }
.bb-mt-readout {
  display: flex; flex-wrap: wrap; gap: 10px; padding: 5px 12px;
  font-family: ui-monospace, Menlo, monospace; font-size: 10px; color: var(--bb-soft);
}
.bb-mt-help { padding: 0 12px 9px; font-size: 10.5px; color: var(--bb-soft); line-height: 1.5; }
/* Avvisi (blocco popup e simili): vuoto non occupa spazio, pieno si vede. */
.bb-mt-note:not(:empty) {
  margin: 0 12px 8px; padding: 8px 11px;
  background: #fdf6e8; border: 1px solid #e6cf9a; border-left: 3px solid var(--bb-amber);
  border-radius: 7px; font-size: 11px; line-height: 1.55; color: #7a5410;
}

/* ── Prova a tempo ────────────────────────────────────────────────────── */
.bb-timer-slot { margin-left: auto; display: flex; align-items: center; }

.bb-timer {
  font-family: ui-monospace, Menlo, monospace; font-size: 12px; font-weight: 700;
  color: var(--bb-teal); background: var(--bb-wash);
  border: 1px solid var(--bb-line); border-radius: 20px; padding: 5px 13px;
  white-space: nowrap;
}
.bb-timer.warn { color: var(--bb-amber); border-color: var(--bb-amber); }
.bb-timer.over { color: #b3261e; border-color: #b3261e; }

/* Sopra TUTTO: il toroide 3D sta a z-index 195 e i pulsanti flottanti a 190.
   Se il pannello di scadenza restasse sotto, la prova risulterebbe finita ma
   quei controlli sarebbero ancora cliccabili. */
.bb-premium {
  position: fixed; inset: 0; z-index: 9990;
  background: rgba(238, 243, 241, 0.96);
  display: flex; align-items: center; justify-content: center; padding: 20px;
  backdrop-filter: blur(3px);
}
.bb-premium.hidden { display: none; }
.bb-premium-card {
  background: var(--bb-paper); border: 1px solid var(--bb-line);
  border-radius: 14px; padding: 26px 28px; max-width: 480px; width: 100%;
  box-shadow: 0 22px 60px rgba(23, 67, 74, 0.2);
}
.bb-premium-card h2 { margin: 0 0 10px; font-size: 20px; color: var(--bb-ink); }
.bb-premium-card h3 { margin: 18px 0 6px; font-size: 15px; color: var(--bb-amber); }
.bb-premium-card p { font-size: 13px; line-height: 1.65; color: #365c56; margin: 0 0 9px; }
.bb-premium-note { font-size: 12px !important; color: var(--bb-soft) !important; }
.bb-premium-note a { color: var(--bb-amber); }
.bb-promo-row { display: flex; gap: 8px; margin-top: 14px; }
.bb-promo-input {
  flex: 1; padding: 10px 12px; border: 1px solid var(--bb-line);
  border-radius: 8px; font-family: inherit; font-size: 13px; background: var(--bb-wash);
}
.bb-promo-btn {
  background: var(--bb-amber); color: #fff; border: 0; border-radius: 8px;
  padding: 10px 18px; font-family: inherit; font-size: 13px; font-weight: 700; cursor: pointer;
}
.bb-promo-msg { min-height: 16px; font-size: 12px; margin: 8px 0 0 !important; }
.bb-promo-msg.ok { color: var(--bb-teal) !important; }
.bb-promo-msg.err { color: #b3261e !important; }
.bb-premium-actions { display: flex; gap: 10px; margin-top: 18px; flex-wrap: wrap; }
.bb-btn-ghost {
  background: none; border: 1px solid var(--bb-line); border-radius: 8px;
  padding: 8px 14px; font-family: inherit; font-size: 12px;
  color: var(--bb-soft); cursor: pointer; text-decoration: none;
}
.bb-btn-ghost:hover { border-color: var(--bb-amber); color: var(--bb-amber); }

body.bb-locked { overflow: hidden; }

@media (max-width: 720px) {
  /* Su telefono una finestra flottante coprirebbe l'editor invece di
     affiancarlo: "Codice vivo" torna a occupare la larghezza in basso. */
  .bb-fl { left: 8px; right: 8px; width: auto; top: auto; bottom: 8px; height: 44vh; }
  .bb-fab { right: 12px; padding: 8px 13px; font-size: 11px; }
  .bb-fab-guide { bottom: 62px; }
  .bb-fab-mt { bottom: 106px; }
  .bb-fab-hl { bottom: 150px; }
  .bb-mt-popup { right: 8px; left: 8px; width: auto; bottom: 8px; height: 62vh; }
  .bb-timer-slot { width: 100%; justify-content: center; margin: 6px 0 0; }
}
