/* ---------------------------------------------------------------
   Studio Tecnico ABA — tema chiaro, beige + accento burgundy
   Priorità al layout orizzontale (tablet/desktop), degrada su mobile
----------------------------------------------------------------*/
:root {
  --bg: #faf6ef;
  --bg-soft: #f3ece1;
  --card: #fffdfa;
  --line: #e7dccd;
  --line-strong: #d8c9b5;
  --ink: #2b2521;
  --ink-soft: #6d6257;
  --ink-faint: #9b8f83;
  --accent: #7d2b3b;
  --accent-ink: #5e1e2c;
  --accent-soft: #f4e6e9;
  --ok: #2f6a4f;
  --ok-soft: #e7f1ea;
  --no: #a03434;
  --no-soft: #f8e8e6;
  --radius: 14px;
  --sidebar-w: 320px;
  --topbar-h: 56px;
  --serif: Georgia, "Iowan Old Style", "Times New Roman", serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  --shadow: 0 1px 2px rgba(43, 37, 33, .06), 0 10px 28px rgba(43, 37, 33, .05);
}

*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.65 var(--sans);
  -webkit-text-size-adjust: 100%;
}
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
.skip {
  position: absolute; left: -9999px; top: 0;
  background: var(--accent); color: #fff; padding: .5rem .9rem; z-index: 100;
}
.skip:focus { left: .5rem; top: .5rem; }

/* ---------------- topbar ---------------- */
.topbar {
  flex: 0 0 auto;
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: 0 1rem;
  background: var(--card);
  border-bottom: 1px solid var(--line);
  z-index: 40;
}
.brand {
  display: inline-flex; align-items: center; gap: .5rem;
  font-family: var(--serif); font-size: 1.05rem; font-weight: 600;
  color: var(--ink); text-decoration: none; letter-spacing: .01em;
}
.brand-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--accent); }
.topbar-meta { margin: 0; color: var(--ink-faint); font-size: .82rem; letter-spacing: .02em; }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: .6rem; min-width: 0; }
.topbar-nav { display: flex; gap: .35rem; }
.topbar-nav .icon-btn { color: var(--ink-soft); }
.topbar-nav .icon-btn:not([disabled]):hover { color: var(--accent-ink); }
.topbar-nav .icon-btn[disabled] { opacity: .35; cursor: default; }
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 38px; height: 38px;
  border: 1px solid var(--line); background: var(--bg-soft);
  border-radius: 10px; font-size: 1.05rem; line-height: 1; color: var(--ink); cursor: pointer;
}
.icon-btn:hover { background: #fffaf2; border-color: var(--accent); color: var(--accent-ink); }

/* ---------------- impaginazione ---------------- */
.layout { flex: 1 1 auto; display: grid; grid-template-columns: var(--sidebar-w) 1fr; min-height: 0; }

/* barra laterale chiusa: la colonna sparisce e il contenuto prende tutto lo spazio */
@media (min-width: 981px) {
  body.nav-hidden .layout { grid-template-columns: 0 1fr; }
  body.nav-hidden .sidebar { visibility: hidden; overflow: hidden; padding: 0; border-right: 0; }
}
.sidebar {
  display: flex; flex-direction: column;
  overflow: hidden;
  background: var(--bg-soft);
  border-right: 1px solid var(--line);
  padding: 1.1rem .8rem 1rem;
}
#nav { flex: 1 1 auto; min-height: 0; overflow-y: auto; padding-right: 2px; }
.sidebar-foot { flex: 0 0 auto; border-top: 1px solid var(--line); margin-top: .7rem; padding-top: .5rem; }
.nav-label {
  margin: 1.1rem .6rem .45rem;
  font-size: .7rem; text-transform: uppercase; letter-spacing: .12em;
  color: var(--ink-faint); font-weight: 700;
}
.nav-label:first-child { margin-top: 0; }
.nav-item {
  display: flex; gap: .6rem; align-items: baseline;
  padding: .55rem .7rem;
  margin-bottom: 2px;
  border-radius: 10px;
  border-left: 3px solid transparent;
  color: var(--ink-soft); text-decoration: none;
  font-size: .92rem; line-height: 1.35;
}
.nav-item:hover { background: #fffaf2; color: var(--ink); }
.nav-item .num { font-variant-numeric: tabular-nums; font-size: .78rem; color: var(--ink-faint); min-width: 1.4em; }
.nav-item.active {
  background: var(--card);
  border-left-color: var(--accent);
  color: var(--accent-ink); font-weight: 600; box-shadow: var(--shadow);
}
.nav-item.active .num { color: var(--accent); }
.nav-item.exam .num { color: var(--accent); }
.nav-foot { margin: .35rem .6rem 0; color: var(--ink-faint); font-size: .78rem; }

.content { overflow-y: auto; padding: 2.4rem clamp(1rem, 5vw, 4rem) 5rem; }
.scrim { display: none; }

/* ---------------- lezione ---------------- */
.lesson { max-width: 76ch; margin: 0 auto; }
.eyebrow {
  margin: 0 0 .35rem;
  font-size: .72rem; text-transform: uppercase; letter-spacing: .14em;
  color: var(--accent); font-weight: 700;
}
h1 { font-family: var(--serif); font-size: clamp(1.65rem, 2.4vw, 2.05rem); line-height: 1.2; margin: 0 0 .6rem; }
.lede { margin: 0 0 1.6rem; color: var(--ink-soft); font-size: 1.02rem; }
h2 {
  font-family: var(--serif); font-size: 1.3rem; line-height: 1.3;
  margin: 2.4rem 0 .9rem; padding-bottom: .35rem; border-bottom: 1px solid var(--line);
}
.lesson-body p { margin: 0 0 1rem; }
.lesson-body p code, .def code, .feedback code {
  background: var(--bg-soft); border: 1px solid var(--line); border-radius: 5px;
  padding: .05em .3em; font-size: .9em;
}
strong { color: var(--ink); }

.bullets { margin: 0 0 1.1rem; padding-left: 1.1rem; }
.bullets li { margin-bottom: .4rem; }
.bullets li::marker { color: var(--accent); }

/* tabelle */
.tw { overflow-x: auto; margin: 0 0 1.3rem; border: 1px solid var(--line); border-radius: var(--radius); background: var(--card); }
/* tabelle: prima colonna stretta e che va a capo, colonne leggibili */
table {
  border-collapse: collapse; width: 100%; table-layout: fixed;
  font-size: .93rem;
}
th, td {
  text-align: left; padding: .6rem .8rem; border-bottom: 1px solid var(--line);
  vertical-align: top; overflow-wrap: break-word;
}
th:first-child, td:first-child { width: 21%; }
/* la prima colonna si adatta al numero di colonne: più larga nelle tabelle a due */
table.c2 th:first-child, table.c2 td:first-child { width: 34%; }
table.c3 th:first-child, table.c3 td:first-child { width: 24%; }
table.c4 th:first-child, table.c4 td:first-child { width: 18%; }
thead th { background: var(--bg-soft); font-size: .72rem; text-transform: uppercase; letter-spacing: .08em; color: var(--ink-soft); }
tbody tr:last-child td { border-bottom: 0; }
tbody td:first-child { font-weight: 600; }

/* definizioni */
.def {
  display: grid; grid-template-columns: minmax(9rem, 14rem) 1fr; gap: .3rem 1rem;
  padding: .8rem 0; border-bottom: 1px dashed var(--line-strong);
}
.def p { margin: 0; }
.def-term { font-weight: 700; color: var(--accent-ink); }
.def-body { color: var(--ink-soft); }

/* callout */
.callout {
  margin: 0 0 1.3rem; padding: .85rem 1.1rem;
  border-left: 3px solid var(--line-strong); border-radius: 0 var(--radius) var(--radius) 0;
  background: var(--card);
}
.callout-title { margin: 0 0 .25rem; font-size: .74rem; text-transform: uppercase; letter-spacing: .1em; font-weight: 700; color: var(--ink-soft); }
.callout-body > p { margin: 0 0 .5rem; }
.callout-body > p:last-child { margin-bottom: 0; }
.callout.key { border-left-color: var(--accent); background: #f8eee1; }
.callout.key .callout-title { color: var(--accent-ink); }
.callout.key .callout-body { color: var(--ink); }
.callout.key .callout-body strong { color: var(--accent-ink); }
.callout.example { border-left-color: var(--accent); background: var(--card); box-shadow: var(--shadow); }
.callout.warn { border-left-color: var(--no); background: var(--no-soft); }
.callout.warn .callout-title { color: var(--no); }

/* ---------------- quiz ---------------- */
.quiz-slot { margin-top: 3rem; }
.quiz-title { margin-bottom: 1rem; }
.quiz-card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 1.2rem 1.3rem 1.1rem; box-shadow: var(--shadow);
}
.quiz-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: .3rem 1rem; margin-bottom: .5rem; }
.quiz-head-title { display: flex; flex-wrap: wrap; align-items: baseline; gap: .6rem; min-width: 0; }
.quiz-head h3 { margin: 0; font-family: var(--serif); font-size: 1.05rem; }
.quiz-count { margin-left: auto; color: var(--ink-faint); font-size: .8rem; white-space: nowrap; }

/* avanzamento: puntini per i quiz brevi, barra per l'esame lungo */
.progress { height: 5px; border-radius: 3px; background: var(--line); overflow: hidden; margin: 0 0 1.1rem; }
.progress > span { display: block; height: 100%; background: var(--accent); border-radius: 3px; transition: width .18s ease; }
.dots { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 1rem; }
.dot { width: 100%; max-width: 22px; height: 3px; flex: 1 1 14px; border-radius: 2px; background: var(--line); }
.dot.ok { background: var(--ok); }
.dot.no { background: var(--no); }
.dot.current { background: var(--accent); }
.q-text { margin: 0 0 1rem; font-size: 1.05rem; font-weight: 600; }
.opts { list-style: none; margin: 0 0 1rem; padding: 0; display: grid; gap: .5rem; }
.opt {
  width: 100%; display: flex; align-items: flex-start; gap: .7rem; text-align: left;
  padding: .65rem .8rem;
  background: #fff; border: 1px solid var(--line); border-radius: 11px;
  font: inherit; font-size: .95rem; color: var(--ink); cursor: pointer;
  transition: background .12s, border-color .12s, transform .08s;
}
.opt:not([disabled]):hover { border-color: var(--accent); background: #fffaf3; }
.opt:not([disabled]):active { transform: scale(.995); }
.opt .letter {
  flex: 0 0 auto; width: 22px; height: 22px; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--bg-soft); color: var(--ink-soft);
  font-size: .74rem; font-weight: 700;
}
.opt .otext { flex: 1 1 auto; }
.opt .mark { font-weight: 700; }
.opt.is-correct { background: var(--ok-soft); border-color: #a9cdb8; }
.opt.is-correct .letter { background: var(--ok); color: #fff; }
.opt.is-correct .mark { color: var(--ok); }
.opt.is-wrong { background: var(--no-soft); border-color: #d8a9a4; }
.opt.is-wrong .letter { background: var(--no); color: #fff; }
.opt.is-wrong .mark { color: var(--no); }
.opt.is-faded { opacity: .6; }
.opt[disabled] { cursor: default; }

.feedback { border-left: 3px solid var(--line-strong); border-radius: 0 11px 11px 0; padding: .7rem .9rem; margin-bottom: 1rem; background: var(--bg-soft); }
.feedback.ok { border-left-color: var(--ok); background: var(--ok-soft); }
.feedback.no { border-left-color: var(--no); background: var(--no-soft); }
.feedback p { margin: 0 0 .35rem; font-size: .92rem; }
.feedback p:last-child { margin-bottom: 0; }
.feedback .verdict { font-weight: 700; }
.feedback.ok .verdict { color: var(--ok); }
.feedback.no .verdict { color: var(--no); }
.feedback .why { color: var(--ink-soft); }
.feedback .why.right { color: var(--ink); }

.quiz-nav { display: flex; justify-content: space-between; gap: .6rem; flex-wrap: wrap; margin-top: 1rem; }
.quiz-aux { margin: .7rem 0 0; text-align: center; }
.quiz-aux .link-btn { font-size: .8rem; color: var(--ink-soft); font-weight: 500; }
.quiz-aux .link-btn:hover { color: var(--accent); }
.btn {
  display: inline-block;
  padding: .55rem .95rem;
  background: var(--accent); color: #fff; border: 1px solid var(--accent);
  border-radius: 10px; font: inherit; font-size: .9rem; font-weight: 600;
  text-decoration: none; cursor: pointer;
}
.btn:hover { background: var(--accent-ink); border-color: var(--accent-ink); }
.btn.ghost { background: transparent; color: var(--accent-ink); border-color: var(--line-strong); }
.btn.ghost:hover { background: var(--accent-soft); border-color: var(--accent); }
.btn[disabled] { opacity: .45; cursor: default; }
.btn[disabled]:hover { background: var(--accent); border-color: var(--accent); }
.btn.ghost[disabled]:hover { background: transparent; }

.summary .score { font-size: 1.05rem; margin: .2rem 0 .4rem; }
.summary .score strong { font-family: var(--serif); font-size: 2rem; color: var(--accent); }
.summary .score span { color: var(--ink-faint); }
.verdict.ok { color: var(--ok); }
.verdict.mid { color: var(--accent-ink); }
.verdict.no { color: var(--no); }

.lesson-nav { display: flex; justify-content: space-between; gap: .6rem; margin-top: 2.4rem; }
.lesson-nav .btn { max-width: 46%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.src { margin: 1rem 0 0; color: var(--ink-faint); font-size: .78rem; letter-spacing: .02em; }
.lesson-actions { display: flex; flex-wrap: wrap; gap: .5rem; margin: 0 0 1.5rem; }
.btn.small { padding: .4rem .75rem; font-size: .82rem; }
.link-btn {
  background: none; border: 0; padding: .1rem .35rem; margin: 0;
  font: inherit; font-size: .82rem; font-weight: 600; color: var(--accent);
  border-radius: 7px; cursor: pointer; white-space: nowrap;
}
.link-btn:hover { background: var(--accent-soft); }
.muted { color: var(--ink-faint); }

/* ---------------- mobile / ritratto ---------------- */
@media (max-width: 980px) {
  .topbar-meta { display: none; }
  .table-wrap, .tw { -webkit-overflow-scrolling: touch; }
  .layout { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; top: var(--topbar-h); bottom: 0; left: 0;
    width: min(86vw, 340px);
    transform: translateX(-102%);
    transition: transform .22s ease;
    z-index: 35;
    box-shadow: var(--shadow);
  }
  body.nav-open .sidebar { transform: none; }
  .scrim {
    display: block; position: fixed; inset: var(--topbar-h) 0 0 0;
    background: rgba(43, 37, 33, .35); opacity: 0; pointer-events: none;
    transition: opacity .2s; z-index: 30;
  }
  body.nav-open .scrim { opacity: 1; pointer-events: auto; }
  .content { padding: 1.4rem 1.1rem 4rem; }
  th, td { padding: .45rem .45rem; font-size: .86rem; }
  thead th { font-size: .68rem; letter-spacing: .05em; }
  .def { grid-template-columns: 1fr; }
  .def-term { margin-bottom: .15rem; }
  .lesson-nav { flex-direction: column; }
  .lesson-nav .btn { max-width: none; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; scroll-behavior: auto !important; }
}

@media print {
  .topbar, .sidebar, .scrim, .quiz-nav, .lesson-nav { display: none !important; }
  .content { overflow: visible; padding: 0; }
  .quiz-card, .callout, .tw { break-inside: avoid; }
}
