/* ==========================================================================
   Laboratorio Arduino — foglio di stile
   Layout: barra superiore fissa, navigazione dei moduli a sinistra (striscia
   orizzontale su schermi stretti), contenuto a destra. Palette ispirata al
   banco di lavoro: teal della scheda, rame dei fili, ardesia della basetta.
   ========================================================================== */

:root {
  /* colori — tema chiaro */
  --bg: #f2f5f6;
  --bg-elev: #ffffff;
  --bg-sunk: #e6ecee;
  --fg: #16232a;
  --fg-muted: #5a6b74;
  --line: #d3dce0;
  --accent: #0b8a8f;        /* teal scheda */
  --accent-fg: #ffffff;
  --accent-soft: #d9f0f1;
  --copper: #b56a2b;        /* rame */
  --copper-soft: #f6e6d7;
  --good: #2e8b57;
  --good-soft: #dcf2e4;
  --warn: #c7811a;
  --warn-soft: #fbeedb;
  --bad: #c0392b;
  --bad-soft: #f8dcd8;
  --code-bg: #1d2a31;
  --code-fg: #e7eef2;
  --code-kw: #7fd1d4;
  --code-fn: #f4c174;
  --code-str: #b5e39b;
  --code-com: #8a9aa3;
  --code-num: #f0a0a0;
  --led-off: #3a4a52;
  --pcb: #0f6e73;

  /* tipografia */
  --f-display: "Sora", "Segoe UI", system-ui, sans-serif;
  --f-body: "Source Sans 3", "Segoe UI", system-ui, sans-serif;
  --f-mono: "JetBrains Mono", "Fira Mono", Consolas, monospace;

  --r: 6px;
  --r-lg: 12px;
  --shadow: 0 1px 2px rgba(22, 35, 42, .06), 0 4px 14px rgba(22, 35, 42, .06);
  --gutter-l: max(16px, env(safe-area-inset-left, 0px));
  --gutter-r: max(16px, env(safe-area-inset-right, 0px));
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #111a1f; --bg-elev: #19242a; --bg-sunk: #0d1418;
    --fg: #e4ecef; --fg-muted: #93a4ad; --line: #2a3a42;
    --accent: #3fc1c6; --accent-fg: #07262a; --accent-soft: #163a3f;
    --copper: #e0955a; --copper-soft: #3a2a1c;
    --good: #5fc98a; --good-soft: #163a27;
    --warn: #e6a94b; --warn-soft: #3d2d12;
    --bad: #ef7a6d; --bad-soft: #42201c;
    --code-bg: #0b1317; --code-fg: #dde7ec;
    --led-off: #2a363c; --pcb: #0e5d62;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 4px 14px rgba(0,0,0,.3);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #111a1f; --bg-elev: #19242a; --bg-sunk: #0d1418;
  --fg: #e4ecef; --fg-muted: #93a4ad; --line: #2a3a42;
  --accent: #3fc1c6; --accent-fg: #07262a; --accent-soft: #163a3f;
  --copper: #e0955a; --copper-soft: #3a2a1c;
  --good: #5fc98a; --good-soft: #163a27;
  --warn: #e6a94b; --warn-soft: #3d2d12;
  --bad: #ef7a6d; --bad-soft: #42201c;
  --code-bg: #0b1317; --code-fg: #dde7ec;
  --led-off: #2a363c; --pcb: #0e5d62;
  --shadow: 0 1px 2px rgba(0,0,0,.3), 0 4px 14px rgba(0,0,0,.3);
  color-scheme: dark;
}

/* ---------- base ---------- */
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--f-body);
  font-size: 16px;
  line-height: 1.55;
}
body::before {
  content: ""; position: fixed; inset: 0 0 auto;
  height: env(safe-area-inset-top, 0px); z-index: 10; background: var(--pcb);
}
h1, h2, h3, h4 { font-family: var(--f-display); line-height: 1.2; text-wrap: balance; margin: 0; }
p { margin: 0; }
a { color: var(--accent); }
button { font: inherit; cursor: pointer; }
code, pre, kbd, .mono { font-family: var(--f-mono); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
[hidden] { display: none !important; }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }

/* ---------- barra superiore ---------- */
.barra {
  position: sticky; top: env(safe-area-inset-top, 0px); z-index: 9;
  background: var(--pcb); color: #fff;
  padding-block: 10px;
  padding-left: var(--gutter-l); padding-right: var(--gutter-r);
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
}
.barra .marchio { display: flex; align-items: center; gap: 10px; min-width: 0; }
.barra .marchio svg { width: 34px; height: 34px; flex: none; }
.barra h1 { font-size: 1.15rem; font-weight: 600; letter-spacing: .01em; }
.barra .sotto { font-size: .78rem; opacity: .8; display: block; }
.barra .spazio { flex: 1; }
.barra .stato { display: flex; align-items: center; gap: 10px; font-size: .9rem; }
.avanzamento { width: 150px; height: 8px; background: rgba(255,255,255,.25); border-radius: 99px; overflow: hidden; }
.avanzamento > i { display: block; height: 100%; background: #fff; width: 0; transition: width .4s; }
.btn-chiaro {
  background: rgba(255,255,255,.15); color: #fff; border: 1px solid rgba(255,255,255,.35);
  border-radius: var(--r); padding: 6px 12px; font-size: .9rem;
}
.btn-chiaro:hover { background: rgba(255,255,255,.25); }

/* ---------- struttura ---------- */
.cornice {
  display: grid; grid-template-columns: 260px minmax(0, 1fr);
  gap: 24px; max-width: 1280px; margin: 0 auto;
  padding-block: 20px; padding-left: var(--gutter-l); padding-right: var(--gutter-r);
}
@media (max-width: 860px) {
  .cornice { grid-template-columns: minmax(0, 1fr); gap: 14px; }
}

/* ---------- navigazione ---------- */
.nav { position: sticky; top: calc(env(safe-area-inset-top, 0px) + 70px); align-self: start; }
.nav .sez { font-size: .72rem; text-transform: uppercase; letter-spacing: .08em; color: var(--fg-muted); margin: 14px 0 6px 10px; }
.nav .sez:first-child { margin-top: 0; }
.nav ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.nav button {
  width: 100%; text-align: left; background: transparent; color: var(--fg);
  border: 1px solid transparent; border-radius: var(--r); padding: 8px 10px;
  display: grid; grid-template-columns: 30px 1fr auto; align-items: center; gap: 8px;
}
.nav button:hover { background: var(--bg-sunk); }
.nav button.attivo { background: var(--accent-soft); border-color: var(--accent); }
.nav .cod { font-family: var(--f-mono); font-size: .78rem; color: var(--fg-muted); }
.nav .tit { font-size: .92rem; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav .pallino { width: 10px; height: 10px; border-radius: 50%; background: var(--line); }
.nav .pallino.ok { background: var(--good); }
.nav .pallino.parz { background: var(--warn); }
@media (max-width: 860px) {
  .nav { position: static; overflow-x: auto; padding-bottom: 6px; }
  .nav .sez { display: none; }
  .nav ul { grid-auto-flow: column; grid-auto-columns: max-content; }
  .nav button { grid-template-columns: auto auto auto; padding: 6px 10px; border-color: var(--line); background: var(--bg-elev); }
  .nav .tit { max-width: 180px; }
}

/* ---------- contenuto ---------- */
.contenuto { min-width: 0; display: grid; gap: 18px; align-content: start; }
.pannello { background: var(--bg-elev); border: 1px solid var(--line); border-radius: var(--r-lg); padding: 22px; box-shadow: var(--shadow); min-width: 0; }
.pannello > * + * { margin-top: 14px; }
.intest { display: flex; align-items: flex-start; gap: 14px; flex-wrap: wrap; }
.intest h2 { font-size: 1.45rem; font-weight: 600; }
.intest .meta { color: var(--fg-muted); font-size: .9rem; }
.etichetta {
  display: inline-block; font-size: .72rem; text-transform: uppercase; letter-spacing: .07em;
  padding: 2px 8px; border-radius: 99px; border: 1px solid var(--line); color: var(--fg-muted); white-space: nowrap;
}
.etichetta.base { background: var(--good-soft); color: var(--good); border-color: transparent; }
.etichetta.intermedio { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.etichetta.avanzato { background: var(--bad-soft); color: var(--bad); border-color: transparent; }
.prosa { max-width: 72ch; }
.prosa > * + * { margin-top: 12px; }
.prosa h3 { font-size: 1.1rem; font-weight: 600; margin-top: 22px; color: var(--accent); }
.prosa ul { margin: 0; padding-left: 20px; display: grid; gap: 5px; }
.prosa code { background: var(--bg-sunk); padding: 1px 5px; border-radius: 4px; font-size: .9em; }
.prosa pre { margin: 0; }
pre.codice {
  background: var(--code-bg); color: var(--code-fg); border-radius: var(--r);
  padding: 14px 16px; overflow-x: auto; font-size: .84rem; line-height: 1.5; tab-size: 2;
}
pre.codice .kw { color: var(--code-kw); }
pre.codice .fn { color: var(--code-fn); }
pre.codice .str { color: var(--code-str); }
pre.codice .com { color: var(--code-com); font-style: italic; }
pre.codice .num { color: var(--code-num); }
.formula {
  font-family: var(--f-mono); background: var(--copper-soft); color: var(--fg);
  border-left: 3px solid var(--copper); padding: 10px 14px; border-radius: 0 var(--r) var(--r) 0;
  font-size: .95rem; overflow-x: auto;
}
.nota { background: var(--accent-soft); border-left: 3px solid var(--accent); padding: 10px 14px; border-radius: 0 var(--r) var(--r) 0; font-size: .95rem; }
.esempio { background: var(--bg-sunk); padding: 10px 14px; border-radius: var(--r); font-size: .95rem; }
.esempio::before, .nota::before { font-family: var(--f-display); font-size: .72rem; text-transform: uppercase; letter-spacing: .08em; display: block; margin-bottom: 4px; color: var(--fg-muted); }
.esempio::before { content: "Esempio"; }
.nota::before { content: "Nota"; }
.tabella-scroll { overflow-x: auto; }
table.tab { border-collapse: collapse; width: 100%; font-size: .92rem; font-variant-numeric: tabular-nums; }
table.tab th, table.tab td { text-align: left; padding: 7px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.tab th { font-family: var(--f-display); font-weight: 600; font-size: .8rem; text-transform: uppercase; letter-spacing: .05em; color: var(--fg-muted); }
.griglia-progetti { display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.progetto { border: 1px solid var(--line); border-radius: var(--r); padding: 12px 14px; display: grid; gap: 4px; }
.progetto .n { font-family: var(--f-mono); color: var(--copper); font-size: .8rem; }
.progetto .nome { font-family: var(--f-display); font-weight: 600; }
.progetto .riga { font-size: .88rem; color: var(--fg-muted); }
.progetto .riga b { color: var(--fg); font-weight: 600; }

/* lezioni: schede */
.schede { display: flex; gap: 6px; flex-wrap: wrap; border-bottom: 1px solid var(--line); padding-bottom: 8px; }
.schede button { background: transparent; border: 1px solid var(--line); color: var(--fg); border-radius: 99px; padding: 5px 12px; font-size: .88rem; }
.schede button.attiva { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); }
.azioni { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.btn { background: var(--accent); color: var(--accent-fg); border: 1px solid var(--accent); border-radius: var(--r); padding: 9px 16px; font-weight: 600; }
.btn:hover { filter: brightness(1.08); }
.btn.sec { background: transparent; color: var(--fg); border-color: var(--line); font-weight: 500; }
.btn.sec:hover { background: var(--bg-sunk); }
.btn.pericolo { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.piccolo { padding: 5px 10px; font-size: .85rem; }

/* ---------- home ---------- */
.riquadri { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); }
.riquadro { background: var(--bg-sunk); border-radius: var(--r); padding: 14px; display: grid; gap: 2px; }
.riquadro .val { font-family: var(--f-display); font-size: 1.6rem; font-weight: 600; font-variant-numeric: tabular-nums; }
.riquadro .lab { font-size: .8rem; color: var(--fg-muted); text-transform: uppercase; letter-spacing: .06em; }
.lista-moduli { display: grid; gap: 10px; }
.card-mod {
  display: grid; grid-template-columns: 44px 1fr auto; gap: 12px; align-items: center;
  border: 1px solid var(--line); border-radius: var(--r); padding: 12px 14px; background: var(--bg-elev);
  cursor: pointer; text-align: left; color: var(--fg); width: 100%;
}
.card-mod:hover { border-color: var(--accent); }
.card-mod .cod { font-family: var(--f-mono); font-size: 1.1rem; color: var(--copper); }
.card-mod .tit { font-family: var(--f-display); font-weight: 600; }
.card-mod .desc { font-size: .88rem; color: var(--fg-muted); }
.card-mod .punteggio { font-family: var(--f-mono); font-size: .85rem; text-align: right; color: var(--fg-muted); min-width: 60px; }
.card-mod .punteggio.ok { color: var(--good); }
@media (max-width: 560px) { .card-mod { grid-template-columns: 36px 1fr; } .card-mod .punteggio { grid-column: 2; text-align: left; } }

/* ---------- quiz ---------- */
.domanda { border: 1px solid var(--line); border-radius: var(--r); padding: 16px; display: grid; gap: 10px; }
.domanda .num { font-family: var(--f-mono); font-size: .78rem; color: var(--fg-muted); }
.domanda .testo { font-weight: 600; font-size: 1.02rem; }
.opzioni { display: grid; gap: 6px; }
.opzione { display: flex; gap: 10px; align-items: flex-start; padding: 8px 10px; border: 1px solid var(--line); border-radius: var(--r); cursor: pointer; }
.opzione:hover { background: var(--bg-sunk); }
.opzione input { margin-top: 4px; accent-color: var(--accent); }
.opzione.giusta { background: var(--good-soft); border-color: var(--good); }
.opzione.sbagliata { background: var(--bad-soft); border-color: var(--bad); }
.spieg { font-size: .92rem; color: var(--fg-muted); border-top: 1px dashed var(--line); padding-top: 8px; }
.esito { display: grid; gap: 6px; padding: 16px; border-radius: var(--r); }
.esito.ok { background: var(--good-soft); border: 1px solid var(--good); }
.esito.ko { background: var(--bad-soft); border: 1px solid var(--bad); }
.esito .grande { font-family: var(--f-display); font-size: 1.8rem; font-weight: 600; font-variant-numeric: tabular-nums; }
.timer { font-family: var(--f-mono); font-size: 1rem; padding: 4px 10px; border-radius: var(--r); background: var(--bg-sunk); }
.timer.poco { background: var(--bad-soft); color: var(--bad); }

/* ---------- simulatore ---------- */
.sim { display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr); gap: 16px; }
@media (max-width: 980px) { .sim { grid-template-columns: minmax(0, 1fr); } }
.editor { display: grid; gap: 8px; min-width: 0; }
.editor textarea {
  width: 100%; min-height: 380px; resize: vertical; font-family: var(--f-mono); font-size: .84rem; line-height: 1.5;
  background: var(--code-bg); color: var(--code-fg); border: 1px solid var(--line); border-radius: var(--r); padding: 12px; tab-size: 2;
}
.editor select, .editor input[type=text], .modulo-form input, .modulo-form select {
  font: inherit; padding: 7px 10px; border: 1px solid var(--line); border-radius: var(--r); background: var(--bg-elev); color: var(--fg); min-width: 0;
}
.banco { display: grid; gap: 12px; min-width: 0; }
.scheda-uno { background: var(--pcb); border-radius: var(--r-lg); padding: 14px; color: #fff; }
.scheda-uno .riga-pin { display: flex; gap: 6px; flex-wrap: wrap; align-items: flex-end; }
.pin { display: grid; justify-items: center; gap: 3px; width: 34px; }
.pin .led { width: 14px; height: 14px; border-radius: 50%; background: var(--led-off); box-shadow: inset 0 0 0 1px rgba(0,0,0,.35); transition: background .08s, box-shadow .08s; }
.pin .led.acceso { background: #ff5a3c; box-shadow: 0 0 10px 2px rgba(255,90,60,.8); }
.pin .lab { font-family: var(--f-mono); font-size: .68rem; opacity: .9; }
.pin .modo { font-size: .6rem; opacity: .7; height: .8em; }
.scheda-uno .titolo-scheda { font-family: var(--f-display); font-size: .8rem; letter-spacing: .12em; text-transform: uppercase; opacity: .85; margin-bottom: 8px; display: flex; justify-content: space-between; gap: 10px; }
.scheda-uno .pulsanti-sim { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.btn-fisico {
  background: #e8edf0; color: #16232a; border: 2px solid #9fb0b8; border-bottom-width: 5px; border-radius: 8px;
  padding: 6px 12px; font-family: var(--f-mono); font-size: .8rem; user-select: none; touch-action: manipulation;
}
.btn-fisico:active, .btn-fisico.premuto { border-bottom-width: 2px; transform: translateY(3px); background: #ffd36b; }
.analogici { display: grid; gap: 8px; }
.analogico { display: grid; grid-template-columns: 34px minmax(0, 1fr) 54px; align-items: center; gap: 10px; font-size: .85rem; }
.analogico .lab { font-family: var(--f-mono); }
.analogico input[type=range] { width: 100%; accent-color: var(--accent); min-width: 0; }
.analogico .val { font-family: var(--f-mono); text-align: right; font-variant-numeric: tabular-nums; }
.analogico .ruolo { grid-column: 2 / span 2; font-size: .75rem; color: var(--fg-muted); margin-top: -4px; }
.periferiche { display: grid; gap: 12px; grid-template-columns: 1fr 1fr; }
@media (max-width: 560px) { .periferiche { grid-template-columns: 1fr; } }
.perif { border: 1px solid var(--line); border-radius: var(--r); padding: 10px 12px; display: grid; gap: 6px; }
.perif .tit { font-family: var(--f-display); font-size: .78rem; text-transform: uppercase; letter-spacing: .07em; color: var(--fg-muted); display: flex; justify-content: space-between; }
.servo-vista svg { width: 100%; max-width: 180px; height: auto; display: block; margin: 0 auto; }
.lcd { background: #1f3a2a; border: 3px solid #0e1f17; border-radius: 4px; padding: 8px 10px; font-family: var(--f-mono); color: #d7f9a8; font-size: .95rem; letter-spacing: .08em; line-height: 1.35; white-space: pre; overflow-x: auto; }
.lcd.spento { color: #30503c; }
.piezo { display: flex; align-items: center; gap: 10px; font-family: var(--f-mono); font-size: .85rem; }
.piezo .onda { flex: 1; height: 28px; background: var(--bg-sunk); border-radius: 4px; position: relative; overflow: hidden; }
.piezo .onda > i { position: absolute; inset: 0; background: repeating-linear-gradient(90deg, var(--accent) 0 2px, transparent 2px 8px); opacity: 0; }
.piezo .onda.attiva > i { opacity: .8; }
.seriale { background: var(--code-bg); color: var(--code-fg); border-radius: var(--r); padding: 10px 12px; font-family: var(--f-mono); font-size: .8rem; height: 170px; overflow: auto; white-space: pre-wrap; word-break: break-word; }
.seriale .err { color: var(--code-num); }
.stato-sim { display: flex; gap: 10px; align-items: center; font-size: .85rem; color: var(--fg-muted); flex-wrap: wrap; }
.stato-sim .spia { width: 10px; height: 10px; border-radius: 50%; background: var(--line); }
.stato-sim .spia.on { background: var(--good); box-shadow: 0 0 6px var(--good); }
.esercizio { border: 1px solid var(--line); border-radius: var(--r); padding: 12px 14px; display: grid; gap: 8px; }
.esercizio .tit { font-family: var(--f-display); font-weight: 600; display: flex; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.verifica-esito { font-size: .9rem; padding: 8px 10px; border-radius: var(--r); }
.verifica-esito.ok { background: var(--good-soft); color: var(--good); }
.verifica-esito.ko { background: var(--bad-soft); color: var(--bad); }

/* ---------- registro / profilo ---------- */
.modulo-form { display: grid; gap: 10px; max-width: 420px; }
.modulo-form label { display: grid; gap: 4px; font-size: .9rem; }
.avviso { font-size: .9rem; color: var(--fg-muted); }
.avviso.errore { color: var(--bad); }
.glossario dl { margin: 0; display: grid; gap: 10px; }
.glossario dt { font-family: var(--f-display); font-weight: 600; color: var(--accent); }
.glossario dd { margin: 0; color: var(--fg); }
.cerca { width: 100%; max-width: 380px; }
.attestato { border: 2px solid var(--copper); border-radius: var(--r-lg); padding: 24px; text-align: center; background: var(--copper-soft); display: grid; gap: 8px; }
.attestato .nome { font-family: var(--f-display); font-size: 1.5rem; font-weight: 600; }
.attestato .mono { font-size: .8rem; color: var(--fg-muted); word-break: break-all; }
.piede { color: var(--fg-muted); font-size: .8rem; text-align: center; padding: 20px var(--gutter-r) 24px var(--gutter-l); }
.toast {
  position: fixed; left: 50%; bottom: calc(18px + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%);
  background: var(--fg); color: var(--bg); padding: 10px 16px; border-radius: 99px; font-size: .9rem; box-shadow: var(--shadow); z-index: 20;
  opacity: 0; transition: opacity .25s; pointer-events: none;
}
.toast.visibile { opacity: 1; }
