/* ============================================================
   Archivio Didattico — Stylesheet condiviso (textbook pages)
   Dark editorial · sticky sidebar · code blocks · cards
   ============================================================ */

:root {
  --bg: #0d0f14;
  --surface: #131620;
  --surface-2: #181c28;
  --surface-3: #1e2330;
  --border: #1e2435;
  --border-strong: #2a3147;
  --text: #eef0f7;
  --text-dim: #a8b2c4;
  --text-faint: #828ca1;
  --accent: #3B82F6;
  --radius: 10px;
  --radius-lg: 14px;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  --max-width: 1280px;
  --sidebar-width: 264px;
  --shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
}

/* Per-subject accent colours (set on <body data-subject="..."> via attr selector) */
body[data-subject="tepsit"]            { --accent: #3B82F6; } /* blue */
body[data-subject="sistemi"]           { --accent: #F59E0B; } /* amber */
body[data-subject="telecomunicazioni"] { --accent: #14B8A6; } /* teal */
body[data-subject="informatica"]       { --accent: #8B5CF6; } /* violet */
body[data-subject="italiano"]          { --accent: #F43F5E; } /* rose */
body[data-subject="inglese"]           { --accent: #10B981; } /* emerald */
body[data-subject="matematica"]        { --accent: #F97316; } /* orange */
body[data-subject="organizzazione"]    { --accent: #06B6D4; } /* cyan */

* { box-sizing: border-box; margin: 0; padding: 0; }

html { scroll-behavior: smooth; scroll-padding-top: 80px; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: "IBM Plex Sans", system-ui, -apple-system, sans-serif;
  font-size: 16px;
  line-height: 1.65;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

h1, h2, h3, h4, h5, h6 {
  font-family: "Sora", "IBM Plex Sans", system-ui, sans-serif;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--text);
}

h1 { font-size: clamp(2rem, 4vw, 2.8rem); line-height: 1.15; letter-spacing: -0.02em; }
h2 { font-size: 1.75rem; line-height: 1.25; margin-top: 0; }
h3 { font-size: 1.25rem; line-height: 1.3; }
h4 { font-size: 1.05rem; line-height: 1.4; }

p { color: var(--text-dim); margin: 0 0 1em; }
p strong, li strong { color: var(--text); font-weight: 600; }

a {
  color: var(--accent);
  text-decoration: none;
  border-bottom: 1px dotted transparent;
  transition: color 0.2s var(--ease), border-color 0.2s var(--ease);
}
a:hover { border-bottom-color: var(--accent); }

ul, ol { padding-left: 1.3em; margin: 0 0 1em; color: var(--text-dim); }
li { margin-bottom: 0.35em; }
li::marker { color: var(--text-faint); }

::selection { background: rgba(59, 130, 246, 0.3); color: var(--text); }

/* Scrollbar */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 5px; border: 2px solid var(--bg); }
::-webkit-scrollbar-thumb:hover { background: var(--border-strong); }
* { scrollbar-width: thin; scrollbar-color: var(--border) var(--bg); }

/* ============================================================
   TOP NAV
   ============================================================ */
.top-nav {
  position: sticky;
  top: 0;
  z-index: 100;
  background: rgba(13, 15, 20, 0.82);
  backdrop-filter: saturate(160%) blur(14px);
  -webkit-backdrop-filter: saturate(160%) blur(14px);
  border-bottom: 1px solid var(--border);
}

.top-nav-inner {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 14px 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
}

.brand {
  font-family: "Sora", sans-serif;
  font-weight: 600;
  font-size: 1rem;
  color: var(--text);
  border: none;
  display: inline-flex;
  align-items: center;
  gap: 10px;
}
.brand-mark {
  display: inline-block;
  width: 8px;
  height: 8px;
  background: var(--accent);
  border-radius: 2px;
}

.top-nav-links {
  list-style: none;
  display: flex;
  gap: 6px;
  padding: 0;
  margin: 0;
  flex-wrap: wrap;
  justify-content: flex-end;
}
.top-nav-links a {
  font-family: "JetBrains Mono", monospace;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-dim);
  padding: 6px 10px;
  border-radius: 4px;
  border: none;
  transition: color 0.2s var(--ease), background 0.2s var(--ease);
}
.top-nav-links a:hover { color: var(--text); background: var(--surface); }
.top-nav-links a.active { color: var(--accent); background: var(--surface); }

/* ============================================================
   PAGE LAYOUT (sidebar + content)
   ============================================================ */
.page {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 0 28px;
  display: grid;
  grid-template-columns: var(--sidebar-width) 1fr;
  gap: 56px;
  align-items: start;
}

.sidebar {
  position: sticky;
  top: 72px;
  align-self: start;
  padding: 40px 0;
  max-height: calc(100vh - 72px);
  overflow-y: auto;
}

.sidebar-eyebrow {
  font-family: "JetBrains Mono", monospace;
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  color: var(--text-faint);
  margin-bottom: 10px;
}
.sidebar-title {
  font-family: "Sora", sans-serif;
  font-size: 1.05rem;
  color: var(--text);
  margin-bottom: 22px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
}

.toc { list-style: none; padding: 0; margin: 0; }
.toc li { margin: 0; }
.toc a {
  display: block;
  padding: 8px 12px;
  margin: 2px 0;
  font-size: 0.88rem;
  color: var(--text-dim);
  border-left: 2px solid var(--border);
  border-bottom: none;
  border-radius: 0 4px 4px 0;
  transition: color 0.2s var(--ease), border-color 0.2s var(--ease), background 0.2s var(--ease);
}
.toc a:hover {
  color: var(--text);
  border-left-color: var(--text-faint);
  background: var(--surface);
}
.toc a.active {
  color: var(--accent);
  border-left-color: var(--accent);
  background: var(--surface);
}
.toc-sub {
  list-style: none;
  padding: 0 0 0 12px;
  margin: 2px 0 4px;
  border-left: 1px solid var(--border);
}
.toc-sub a {
  font-size: 0.82rem;
  padding: 5px 10px;
  border-left: none;
  color: var(--text-faint);
}
.toc-sub a:hover { color: var(--text-dim); background: transparent; }
.toc-sub a.active { color: var(--accent); background: transparent; }

.content { padding: 40px 0 80px; min-width: 0; }

/* ============================================================
   HERO (subject page top)
   ============================================================ */
.hero { padding-bottom: 40px; border-bottom: 1px solid var(--border); margin-bottom: 48px; }
.hero .eyebrow {
  font-family: "JetBrains Mono", monospace;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  color: var(--accent);
  margin-bottom: 18px;
}
.hero h1 { margin-bottom: 20px; max-width: 22ch; }
.hero .lead { font-size: 1.1rem; color: var(--text-dim); max-width: 64ch; }
.hero .hero-meta {
  margin-top: 30px;
  display: flex;
  flex-wrap: wrap;
  gap: 14px 28px;
  font-family: "JetBrains Mono", monospace;
  font-size: 0.78rem;
  color: var(--text-faint);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
.hero .hero-meta strong { color: var(--text); font-weight: 500; }

/* ============================================================
   SECTIONS
   ============================================================ */
section { padding: 36px 0; border-bottom: 1px solid var(--border); }
section:last-of-type { border-bottom: none; }

section > h2 {
  position: relative;
  padding-left: 18px;
  margin-bottom: 18px;
}
section > h2::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0.18em;
  bottom: 0.18em;
  width: 4px;
  background: var(--accent);
  border-radius: 2px;
}

section h3 { margin: 28px 0 12px; color: var(--text); }
section h4 { margin: 20px 0 8px; color: var(--text); }

section p, section ul, section ol { max-width: 72ch; }

.subsection { margin-bottom: 18px; }

.section-intro {
  font-size: 1.02rem;
  color: var(--text-dim);
  max-width: 70ch;
  margin-bottom: 24px;
}

/* ============================================================
   CARDS / BOXES
   ============================================================ */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius);
  padding: 22px 24px;
  margin: 24px 0;
}
.card h3, .card h4 { margin-top: 0; }
.card p:last-child, .card ul:last-child, .card ol:last-child { margin-bottom: 0; }

.card-title {
  font-family: "JetBrains Mono", monospace;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--accent);
  margin-bottom: 10px;
}

.note {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--text-faint);
  border-radius: var(--radius);
  padding: 16px 20px;
  margin: 20px 0;
  font-size: 0.95rem;
}
.note .tag {
  display: inline-block;
  font-family: "JetBrains Mono", monospace;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--text-faint);
  margin-right: 8px;
}

.summary {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px 26px;
  margin: 32px 0;
  position: relative;
}
.summary::before {
  content: "RIEPILOGO";
  position: absolute;
  top: -10px;
  left: 22px;
  background: var(--bg);
  padding: 0 10px;
  font-family: "JetBrains Mono", monospace;
  font-size: 0.7rem;
  letter-spacing: 0.18em;
  color: var(--accent);
}
.summary h3 { margin-top: 6px; font-size: 1.05rem; }
.summary ul, .summary ol { margin-bottom: 0; }
.summary p:last-child { margin-bottom: 0; }

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
  margin: 24px 0;
}
.grid-3 {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 18px;
  margin: 24px 0;
}

/* ============================================================
   DEFINITION LIST
   ============================================================ */
dl.definitions {
  display: grid;
  grid-template-columns: 1fr;
  gap: 14px;
  margin: 20px 0;
}
dl.definitions > div {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 20px;
  display: grid;
  grid-template-columns: minmax(160px, 220px) 1fr;
  gap: 18px;
  align-items: baseline;
}
dl.definitions dt {
  font-family: "JetBrains Mono", monospace;
  font-size: 0.85rem;
  color: var(--accent);
  font-weight: 500;
}
dl.definitions dd {
  margin: 0;
  color: var(--text-dim);
  font-size: 0.96rem;
}

/* ============================================================
   TABLES
   ============================================================ */
.table-wrap { overflow-x: auto; margin: 22px 0; }
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.94rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
th, td {
  text-align: left;
  padding: 11px 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
th {
  background: var(--surface-2);
  font-family: "JetBrains Mono", monospace;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--accent);
  font-weight: 500;
}
tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--surface-2); }

/* ============================================================
   INLINE CODE & PRE BLOCKS (highlight.js compatible)
   ============================================================ */
code {
  font-family: "JetBrains Mono", "Fira Code", monospace;
  font-size: 0.9em;
  padding: 1px 6px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text);
}

pre {
  position: relative;
  background: #0a0c12;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0;
  margin: 22px 0;
  overflow: hidden;
}
pre > code,
pre > code.hljs {
  display: block;
  padding: 20px 22px;
  background: transparent;
  border: none;
  font-size: 0.86rem;
  line-height: 1.6;
  overflow-x: auto;
  border-radius: 0;
  color: #e8eaf2;
}
pre .code-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 14px 8px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  font-family: "JetBrains Mono", monospace;
  font-size: 0.7rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-faint);
}
pre .code-head .lang { color: var(--accent); }
pre .copy-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-faint);
  font-family: "JetBrains Mono", monospace;
  font-size: 0.66rem;
  padding: 4px 9px;
  border-radius: 4px;
  cursor: pointer;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  transition: all 0.2s var(--ease);
}
pre .copy-btn:hover { color: var(--accent); border-color: var(--accent); }
pre .copy-btn.copied { color: #10B981; border-color: #10B981; }

/* Override hljs theme background so it blends with our pre */
.hljs { background: transparent !important; padding: 0 !important; }

/* ============================================================
   FORMULAS (math/inline)
   ============================================================ */
.formula {
  display: block;
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius);
  padding: 14px 20px;
  margin: 16px 0;
  font-family: "JetBrains Mono", monospace;
  font-size: 0.96rem;
  color: var(--text);
  overflow-x: auto;
}
.formula-inline {
  font-family: "JetBrains Mono", monospace;
  font-size: 0.92em;
  color: var(--text);
  padding: 1px 5px;
  background: var(--surface);
  border-radius: 3px;
  border: 1px solid var(--border);
}

/* ============================================================
   HOMEPAGE GRID (subject cards)
   ============================================================ */
.home-wrap { max-width: var(--max-width); margin: 0 auto; padding: 0 28px; }

.home-hero {
  padding: 96px 0 60px;
  border-bottom: 1px solid var(--border);
  position: relative;
  overflow: hidden;
}
.home-hero .eyebrow {
  font-family: "JetBrains Mono", monospace;
  font-size: 0.74rem;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  color: var(--text-faint);
  margin-bottom: 18px;
  opacity: 0;
  animation: fadeUp 0.7s var(--ease) 0.05s forwards;
}
.home-hero h1 {
  font-size: clamp(2.4rem, 5.4vw, 3.6rem);
  max-width: 18ch;
  margin-bottom: 20px;
  opacity: 0;
  animation: fadeUp 0.7s var(--ease) 0.15s forwards;
}
.home-hero .lead {
  font-size: 1.1rem;
  color: var(--text-dim);
  max-width: 62ch;
  opacity: 0;
  animation: fadeUp 0.7s var(--ease) 0.25s forwards;
}

.home-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(290px, 1fr));
  gap: 20px;
}

.materie-section {
  padding: 64px 0;
}
.materie-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 30px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
}
.materie-head h2 {
  font-size: 1.55rem;
  margin: 0;
}
.materie-meta {
  font-family: "JetBrains Mono", monospace;
  font-size: 0.74rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--text-faint);
}
@media (max-width: 600px) {
  .materie-head { flex-direction: column; align-items: flex-start; gap: 6px; }
}

.home-card {
  --card-accent: var(--accent);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 26px 26px 24px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  position: relative;
  overflow: hidden;
  transition: transform 0.3s var(--ease), border-color 0.3s var(--ease), background 0.3s var(--ease);
  opacity: 0;
  transform: translateY(8px);
  animation: fadeUp 0.6s var(--ease) forwards;
}
.home-card::before {
  content: "";
  position: absolute;
  top: 0; left: 0; width: 100%; height: 2px;
  background: var(--card-accent);
  transform: scaleX(0);
  transform-origin: left;
  transition: transform 0.4s var(--ease);
}
.home-card:hover {
  transform: translateY(-2px);
  border-color: var(--card-accent);
  background: var(--surface-2);
}
.home-card:hover::before { transform: scaleX(1); }

.home-card-tag {
  font-family: "JetBrains Mono", monospace;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  color: var(--card-accent);
}
.home-card h3 { font-size: 1.35rem; line-height: 1.2; }
.home-card p { font-size: 0.94rem; color: var(--text-dim); flex: 1; }
.home-card .arrow {
  color: var(--card-accent);
  font-size: 1.05rem;
  align-self: flex-end;
  transition: transform 0.3s var(--ease);
}
.home-card:hover .arrow { transform: translateX(4px); }
.home-card .home-card-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-top: 14px;
  border-top: 1px solid var(--border);
  font-family: "JetBrains Mono", monospace;
  font-size: 0.74rem;
  color: var(--text-faint);
  letter-spacing: 0.04em;
}

/* ============================================================
   FOOTER
   ============================================================ */
.footer {
  border-top: 1px solid var(--border);
  padding: 36px 28px;
  margin-top: 40px;
}
.footer-inner {
  max-width: var(--max-width);
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  font-family: "JetBrains Mono", monospace;
  font-size: 0.76rem;
  color: var(--text-faint);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
.footer a { color: var(--text-dim); border: none; }
.footer a:hover { color: var(--text); }

/* ============================================================
   ANIMATIONS
   ============================================================ */
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 980px) {
  .page {
    grid-template-columns: 1fr;
    gap: 0;
  }
  .sidebar {
    position: relative;
    top: 0;
    max-height: none;
    padding: 24px 0 0;
    border-bottom: 1px solid var(--border);
  }
  .sidebar .toc {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
  }
  .sidebar .toc a {
    border-left: none;
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 6px 12px;
    font-size: 0.78rem;
  }
  .sidebar .toc a.active { border-color: var(--accent); }
  .toc-sub { display: none; }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
}

@media (max-width: 720px) {
  .top-nav-inner { padding: 12px 18px; }
  .top-nav-links { gap: 4px; }
  .top-nav-links a { font-size: 0.66rem; padding: 5px 8px; }
  .page { padding: 0 18px; }
  .content { padding: 28px 0 60px; }
  .hero { padding-bottom: 28px; margin-bottom: 32px; }
  section { padding: 28px 0; }
  dl.definitions > div { grid-template-columns: 1fr; gap: 6px; }
  pre > code { font-size: 0.78rem; }
  .home-hero { padding: 56px 0 40px; }
  .home-grid { padding: 44px 0; }
  .footer-inner { flex-direction: column; align-items: flex-start; gap: 8px; }
}

/* ============================================================
   CLASSE TERZA BADGE + DATE STAMPS
   ============================================================ */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 5px 12px;
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid var(--accent);
  border-radius: 999px;
  font-family: "JetBrains Mono", monospace;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--accent);
  margin-right: 8px;
}
.badge::before {
  content: "";
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
}
.badge-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 20px;
}
.badge-neutral {
  background: var(--surface);
  border-color: var(--border);
  color: var(--text-dim);
}
.badge-neutral::before { background: var(--text-faint); }

.date-stamp {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-family: "JetBrains Mono", monospace;
  font-size: 0.72rem;
  color: var(--text-faint);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  margin-bottom: 14px;
}
.date-stamp::before {
  content: "";
  display: inline-block;
  width: 8px;
  height: 1px;
  background: var(--accent);
}

/* ============================================================
   QUIZ BLOCKS
   ============================================================ */
.quiz {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius);
  padding: 22px 24px;
  margin: 28px 0;
  position: relative;
}
.quiz-tag {
  display: inline-block;
  font-family: "JetBrains Mono", monospace;
  font-size: 0.66rem;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  color: var(--accent);
  padding: 3px 9px;
  border: 1px solid var(--accent);
  border-radius: 4px;
  margin-bottom: 12px;
}
.quiz-tag.exercise { color: var(--text-faint); border-color: var(--border-strong); }
.quiz-q {
  font-family: "Sora", sans-serif;
  font-size: 1.05rem;
  color: var(--text);
  margin-bottom: 16px;
  line-height: 1.45;
}
.quiz-q strong { color: var(--accent); }

.quiz-options {
  list-style: none;
  padding: 0;
  margin: 0 0 14px;
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
}
.quiz-options li { margin: 0; }
.quiz-option {
  width: 100%;
  text-align: left;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 11px 16px 11px 44px;
  color: var(--text);
  font-family: inherit;
  font-size: 0.95rem;
  cursor: pointer;
  position: relative;
  transition: border-color 0.2s var(--ease), background 0.2s var(--ease), color 0.2s var(--ease);
}
.quiz-option::before {
  content: attr(data-letter);
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  width: 22px;
  height: 22px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--surface-3);
  border: 1px solid var(--border);
  border-radius: 4px;
  font-family: "JetBrains Mono", monospace;
  font-size: 0.7rem;
  color: var(--text-faint);
}
.quiz-option:hover:not(:disabled) {
  border-color: var(--accent);
  background: var(--surface-3);
}
.quiz-option:hover:not(:disabled)::before { color: var(--accent); border-color: var(--accent); }
.quiz-option:disabled { cursor: default; opacity: 0.65; }
.quiz-option.correct {
  border-color: #10B981;
  background: rgba(16, 185, 129, 0.08);
  color: #d1fae5;
  opacity: 1;
}
.quiz-option.correct::before {
  background: #10B981;
  border-color: #10B981;
  color: #0a3b29;
}
.quiz-option.incorrect {
  border-color: #ef4444;
  background: rgba(239, 68, 68, 0.08);
  color: #fecaca;
  opacity: 1;
}
.quiz-option.incorrect::before {
  background: #ef4444;
  border-color: #ef4444;
  color: #441010;
}
.quiz-option.reveal {
  border-color: #10B981;
  border-style: dashed;
  background: rgba(16, 185, 129, 0.04);
  opacity: 1;
}

.quiz-feedback {
  display: none;
  margin-top: 14px;
  padding: 14px 18px;
  background: var(--surface-2);
  border-radius: 6px;
  border-left: 3px solid var(--text-faint);
  font-size: 0.94rem;
  color: var(--text-dim);
  line-height: 1.55;
}
.quiz-feedback.show { display: block; animation: fadeIn 0.3s var(--ease); }
.quiz-feedback.is-correct { border-left-color: #10B981; }
.quiz-feedback.is-incorrect { border-left-color: #ef4444; }
.quiz-feedback-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: "JetBrains Mono", monospace;
  font-size: 0.74rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  margin-bottom: 8px;
  color: var(--text);
}
.quiz-feedback.is-correct .quiz-feedback-title { color: #10B981; }
.quiz-feedback.is-incorrect .quiz-feedback-title { color: #ef4444; }
.quiz-feedback p { margin: 0; color: var(--text-dim); }
.quiz-feedback p + p { margin-top: 8px; }

.quiz-actions {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}
.quiz-reset {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-faint);
  font-family: "JetBrains Mono", monospace;
  font-size: 0.7rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 6px 12px;
  border-radius: 4px;
  cursor: pointer;
  display: none;
  transition: color 0.2s var(--ease), border-color 0.2s var(--ease);
}
.quiz.answered .quiz-reset { display: inline-block; }
.quiz-reset:hover { color: var(--accent); border-color: var(--accent); }

/* Open-ended exercise (text answer with reveal) */
.exercise-open {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--text-faint);
  border-radius: var(--radius);
  padding: 20px 22px;
  margin: 24px 0;
}
.exercise-open .quiz-q { margin-bottom: 12px; }
.exercise-reveal {
  background: transparent;
  border: 1px solid var(--accent);
  color: var(--accent);
  font-family: "JetBrains Mono", monospace;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  padding: 8px 14px;
  border-radius: 4px;
  cursor: pointer;
  transition: background 0.2s var(--ease), color 0.2s var(--ease);
}
.exercise-reveal:hover { background: var(--accent); color: #0d0f14; }
.exercise-solution {
  display: none;
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px dashed var(--border);
  color: var(--text-dim);
  font-size: 0.95rem;
}
.exercise-solution.show { display: block; animation: fadeIn 0.3s var(--ease); }
.exercise-solution h4 {
  font-family: "JetBrains Mono", monospace;
  font-size: 0.74rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--accent);
  margin: 0 0 8px;
}

/* ============================================================
   CONTACT FORM
   ============================================================ */
.contact-section {
  padding: 64px 0;
  border-top: 1px solid var(--border);
  margin-top: 32px;
}
.contact-section .container,
.contact-section .home-wrap {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 0 28px;
}
.contact-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 26px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--border);
}
.contact-head h2 { font-size: 1.55rem; }
.contact-head .meta {
  font-family: "JetBrains Mono", monospace;
  font-size: 0.74rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--text-faint);
}
.contact-grid {
  display: grid;
  grid-template-columns: 1fr 1.4fr;
  gap: 36px;
  align-items: start;
}
.contact-intro p {
  color: var(--text-dim);
  max-width: 40ch;
  margin-bottom: 14px;
}
.contact-intro ul {
  list-style: none;
  padding: 0;
  margin: 18px 0 0;
}
.contact-intro li {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  margin-bottom: 10px;
  font-size: 0.92rem;
  color: var(--text-dim);
}
.contact-intro li::before {
  content: "→";
  color: var(--accent);
  flex-shrink: 0;
}

.contact-form {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px 26px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.contact-form .field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.contact-form label {
  font-family: "JetBrains Mono", monospace;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-faint);
}
.contact-form input,
.contact-form select,
.contact-form textarea {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px 12px;
  color: var(--text);
  font-family: inherit;
  font-size: 0.94rem;
  transition: border-color 0.2s var(--ease), background 0.2s var(--ease);
  width: 100%;
}
.contact-form input:focus,
.contact-form select:focus,
.contact-form textarea:focus {
  outline: none;
  border-color: var(--accent);
  background: var(--surface-3);
}
.contact-form textarea {
  resize: vertical;
  min-height: 110px;
  font-family: inherit;
  line-height: 1.5;
}
.contact-form .field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}
.contact-submit {
  background: var(--accent);
  color: #0d0f14;
  border: 1px solid var(--accent);
  border-radius: 6px;
  padding: 11px 18px;
  font-family: "JetBrains Mono", monospace;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  cursor: pointer;
  transition: background 0.2s var(--ease), color 0.2s var(--ease);
}
.contact-submit:hover {
  background: transparent;
  color: var(--accent);
}
.contact-status {
  display: none;
  margin-top: 8px;
  font-size: 0.88rem;
  padding: 10px 14px;
  border-radius: 6px;
  border: 1px solid var(--border);
}
.contact-status.show { display: block; }
.contact-status.ok { color: #10B981; border-color: #10B981; background: rgba(16, 185, 129, 0.06); }
.contact-status.err { color: #ef4444; border-color: #ef4444; background: rgba(239, 68, 68, 0.06); }

@media (max-width: 860px) {
  .contact-grid { grid-template-columns: 1fr; }
  .contact-form .field-row { grid-template-columns: 1fr; }
}

/* ============================================================
   YEAR MARKER (divider between Classe Terza and Classe Quarta)
   ============================================================ */
.year-marker {
  margin: 64px 0 36px;
  padding: 32px 36px;
  background: linear-gradient(135deg, var(--surface-2), var(--surface));
  border: 1px solid var(--accent);
  border-radius: var(--radius-lg);
  text-align: center;
  position: relative;
  scroll-margin-top: 80px;
}
.year-marker::before {
  content: attr(data-label);
  position: absolute;
  top: -10px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg);
  padding: 0 14px;
  font-family: "JetBrains Mono", monospace;
  font-size: 0.7rem;
  letter-spacing: 0.18em;
  color: var(--accent);
  white-space: nowrap;
}
.year-marker h2 {
  font-size: 1.5rem;
  padding-left: 0 !important;
  margin: 4px 0 8px !important;
  border: none;
}
.year-marker h2::before { display: none !important; }
.year-marker p {
  margin: 0;
  font-family: "JetBrains Mono", monospace;
  font-size: 0.84rem;
  letter-spacing: 0.08em;
  color: var(--text-faint);
}

/* TOC subheadings */
.toc-section-title {
  font-family: "JetBrains Mono", monospace;
  font-size: 0.66rem;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  color: var(--accent);
  margin: 22px 0 8px;
  padding-left: 12px;
  list-style: none;
}
.toc-section-title:first-child { margin-top: 0; }

/* ============================================================
   HERO ILLUSTRATION + INLINE DIAGRAMS
   ============================================================ */
.hero-illustration {
  margin-top: 32px;
  max-width: 640px;
  color: var(--accent);
  opacity: 0;
  animation: fadeUp 0.7s var(--ease) 0.45s forwards;
}
.hero-illustration svg {
  width: 100%;
  height: auto;
  display: block;
}

.diagram {
  margin: 32px 0;
  padding: 26px 24px 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  text-align: center;
  position: relative;
}
.diagram::before {
  content: "DIAGRAMMA";
  position: absolute;
  top: -9px;
  left: 22px;
  background: var(--bg);
  padding: 0 10px;
  font-family: "JetBrains Mono", monospace;
  font-size: 0.68rem;
  letter-spacing: 0.16em;
  color: var(--accent);
}
.diagram svg {
  max-width: 100%;
  height: auto;
  color: var(--accent);
}
.diagram svg text {
  fill: var(--text);
  font-family: "JetBrains Mono", monospace;
  font-size: 12px;
}
.diagram svg .muted {
  fill: var(--text-faint);
}
.diagram figcaption {
  margin-top: 16px;
  font-size: 0.86rem;
  color: var(--text-faint);
  font-family: "JetBrains Mono", monospace;
  letter-spacing: 0.04em;
  text-align: center;
}

/* ============================================================
   HOMEPAGE — costellazione decorativa nell'hero
   ============================================================ */
.home-hero {
  position: relative;
}
.hero-constellation {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
}
.hero-constellation .dot {
  position: absolute;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--c, #fff);
  box-shadow:
    0 0 0 4px rgba(255,255,255,0.02),
    0 0 18px var(--c, #fff),
    0 0 40px color-mix(in srgb, var(--c, #fff) 50%, transparent);
  opacity: 0.65;
  animation: bob 7s ease-in-out infinite alternate;
}
@keyframes bob {
  0%   { transform: translateY(0) scale(1); }
  100% { transform: translateY(-12px) scale(1.08); }
}
.hero-constellation .dot:nth-child(1) { top:  12%; left:  6%; --c: #3B82F6; animation-delay: -0.5s; }
.hero-constellation .dot:nth-child(2) { top:   8%; left: 86%; --c: #F59E0B; animation-delay: -1.2s; }
.hero-constellation .dot:nth-child(3) { top:  72%; left: 92%; --c: #14B8A6; animation-delay: -2.0s; }
.hero-constellation .dot:nth-child(4) { top:  84%; left:  4%; --c: #8B5CF6; animation-delay: -2.8s; }
.hero-constellation .dot:nth-child(5) { top:  32%; left: 96%; --c: #F43F5E; animation-delay: -3.5s; }
.hero-constellation .dot:nth-child(6) { top:  54%; left:  2%; --c: #10B981; animation-delay: -4.2s; }
.hero-constellation .dot:nth-child(7) { top:   4%; left: 48%; --c: #F97316; animation-delay: -5.0s; }
.hero-constellation .dot:nth-child(8) { top:  92%; left: 60%; --c: #06B6D4; animation-delay: -5.8s; }
@media (prefers-reduced-motion: reduce) {
  .hero-constellation .dot { animation: none; }
}
@media (max-width: 720px) {
  .hero-constellation .dot { width: 7px; height: 7px; }
}

/* Striscia arcobaleno opzionale: linea sottile colorata */
.rainbow-strip {
  height: 3px;
  width: 100%;
  background: linear-gradient(
    90deg,
    #8B5CF6 0%,
    #3B82F6 14%,
    #06B6D4 28%,
    #14B8A6 42%,
    #10B981 56%,
    #F59E0B 70%,
    #F97316 84%,
    #F43F5E 100%
  );
  border-radius: 2px;
  margin: 36px 0 0;
  opacity: 0.85;
}

/* ============================================================
   HOMEPAGE STATS BAR (animated counters)
   ============================================================ */
.stats-bar {
  margin-top: 38px;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 14px;
  opacity: 0;
  animation: fadeUp 0.7s var(--ease) 0.5s forwards;
}
.stats-bar .stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 14px 14px;
  text-align: left;
  position: relative;
  overflow: hidden;
  transition: border-color 0.2s var(--ease), transform 0.2s var(--ease);
}
.stats-bar .stat::after {
  content: "";
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 1px;
  background: linear-gradient(90deg, transparent, var(--accent), transparent);
  opacity: 0.6;
}
.stats-bar .stat:hover {
  transform: translateY(-2px);
  border-color: var(--accent);
}
.stats-bar .stat-value {
  font-family: "Sora", sans-serif;
  font-size: 1.85rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1;
  margin-bottom: 6px;
  background: linear-gradient(135deg, var(--stat-color, var(--text)), var(--text));
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  color: var(--stat-color, var(--text));
}

/* Una tonalità per ogni stat (riprende i colori delle materie) */
.stats-bar .stat:nth-child(1) { --stat-color: #8B5CF6; }
.stats-bar .stat:nth-child(2) { --stat-color: #3B82F6; }
.stats-bar .stat:nth-child(3) { --stat-color: #14B8A6; }
.stats-bar .stat:nth-child(4) { --stat-color: #F59E0B; }
.stats-bar .stat:nth-child(5) { --stat-color: #F43F5E; }
.stats-bar .stat::after {
  background: linear-gradient(90deg, transparent, var(--stat-color, var(--accent)), transparent);
}
.stats-bar .stat:hover { border-color: var(--stat-color, var(--accent)); }
.stats-bar .stat-label {
  font-family: "JetBrains Mono", monospace;
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--text-faint);
}

@media (max-width: 860px) {
  .stats-bar { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 480px) {
  .stats-bar { grid-template-columns: 1fr 1fr; gap: 10px; }
  .stats-bar .stat { padding: 14px 12px 12px; }
  .stats-bar .stat-value { font-size: 1.5rem; }
}

/* ============================================================
   READING PROGRESS BAR (top of subject pages)
   ============================================================ */
.reading-progress {
  position: fixed;
  top: 0;
  left: 0;
  height: 3px;
  width: 0%;
  background: linear-gradient(90deg, var(--accent), var(--accent) 60%, rgba(232,234,242,0.5));
  z-index: 200;
  transition: width 0.08s linear;
  box-shadow: 0 0 12px rgba(59, 130, 246, 0.35);
}

/* ============================================================
   BACK TO TOP BUTTON
   ============================================================ */
.back-to-top {
  position: fixed;
  right: 22px;
  bottom: 22px;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-dim);
  font-size: 1.2rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  visibility: hidden;
  transform: translateY(10px);
  transition: opacity 0.25s var(--ease), transform 0.25s var(--ease), color 0.2s var(--ease), border-color 0.2s var(--ease), background 0.2s var(--ease);
  z-index: 90;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}
.back-to-top.show {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}
.back-to-top:hover {
  color: var(--accent);
  border-color: var(--accent);
  background: var(--surface-2);
  transform: translateY(-2px);
}

@media (max-width: 720px) {
  .back-to-top {
    right: 16px;
    bottom: 16px;
    width: 40px;
    height: 40px;
  }
}

/* ============================================================
   SECTION COMPLETION (toggle accanto al titolo + TOC marks)
   ============================================================ */
.section-head-row {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 18px;
}
.section-head-row > h2 {
  margin: 0 !important;
  flex: 1;
}

.section-done-toggle {
  width: 32px;
  height: 32px;
  flex-shrink: 0;
  border-radius: 50%;
  border: 1.5px solid var(--border);
  background: var(--surface);
  color: var(--text-faint);
  font-size: 0.95rem;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s var(--ease);
}
.section-done-toggle .sdt-icon {
  opacity: 0.35;
  transition: opacity 0.2s var(--ease), transform 0.2s var(--ease);
}
.section-done-toggle:hover {
  border-color: var(--accent);
  color: var(--accent);
}
.section-done-toggle:hover .sdt-icon { opacity: 1; }
.section-done-toggle.is-done {
  background: var(--accent);
  border-color: var(--accent);
  color: #0d0f14;
}
.section-done-toggle.is-done .sdt-icon {
  opacity: 1;
  color: #0d0f14;
  font-weight: 700;
  transform: scale(1.05);
}

section.is-done > h2,
section.is-done .section-head-row > h2 {
  opacity: 0.7;
}
section.is-done .date-stamp {
  color: var(--accent);
}

.toc a.toc-done {
  color: var(--accent);
  position: relative;
}
.toc a.toc-done::after {
  content: "✓";
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 0.8em;
  color: var(--accent);
  opacity: 0.9;
}

/* Sidebar completion summary widget */
.completion-summary {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 14px 12px;
  margin: 0 0 20px;
  position: relative;
}
.completion-summary.is-complete {
  border-color: var(--accent);
  background: linear-gradient(135deg, var(--surface), rgba(59, 130, 246, 0.04));
}
.completion-summary .cs-label {
  font-family: "JetBrains Mono", monospace;
  font-size: 0.66rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--text-faint);
  margin-bottom: 8px;
}
.completion-summary .cs-bar {
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  overflow: hidden;
  margin-bottom: 8px;
}
.completion-summary .cs-bar-fill {
  height: 100%;
  width: 0;
  background: var(--accent);
  border-radius: 2px;
  transition: width 0.4s var(--ease);
}
.completion-summary .cs-text {
  font-family: "JetBrains Mono", monospace;
  font-size: 0.78rem;
  color: var(--text-dim);
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.completion-summary .cs-reset {
  background: none;
  border: none;
  color: var(--text-faint);
  font-family: "JetBrains Mono", monospace;
  font-size: 0.62rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  cursor: pointer;
  padding: 4px 0;
  transition: color 0.2s var(--ease);
}
.completion-summary .cs-reset:hover { color: var(--accent); }

/* ============================================================
   REVEAL-ON-SCROLL (sezioni, quiz, card)
   ============================================================ */
.reveal {
  opacity: 0;
  transform: translateY(14px);
  transition: opacity 0.55s var(--ease), transform 0.55s var(--ease);
}
.reveal.is-visible {
  opacity: 1;
  transform: translateY(0);
}
@media (prefers-reduced-motion: reduce) {
  .reveal { opacity: 1; transform: none; transition: none; }
}

/* ============================================================
   HONEYPOT (form anti-bot)
   ============================================================ */
.hp-field {
  position: absolute !important;
  left: -10000px !important;
  top: auto !important;
  width: 1px !important;
  height: 1px !important;
  overflow: hidden !important;
  opacity: 0 !important;
  pointer-events: none !important;
}

/* Submit button busy state */
.contact-submit[aria-busy="true"] {
  cursor: progress;
  opacity: 0.7;
}

/* ============================================================
   AUTH GATE — blur + overlay login
   ============================================================ */
body.is-locked {
  overflow: hidden;
}

/* Default per pagine MATERIA: blur forte sul contenuto + grayscale */
body.is-locked main,
body.is-locked nav,
body.is-locked footer,
body.is-locked .top-nav,
body.is-locked .reading-progress,
body.is-locked .back-to-top,
body.is-locked .auth-userbadge {
  filter: blur(14px) saturate(0.4) brightness(0.65);
  pointer-events: none;
  user-select: none;
  -webkit-user-select: none;
}

/* HOME (data-subject vuoto) → NESSUN blur, contenuto visibile (è la "preview") */
body.is-locked[data-subject=""] main,
body.is-locked[data-subject=""] nav,
body.is-locked[data-subject=""] footer,
body.is-locked[data-subject=""] .top-nav,
body.is-locked[data-subject=""] .reading-progress,
body.is-locked[data-subject=""] .back-to-top {
  filter: none;
  pointer-events: auto;
}

.auth-gate {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  /* Margini responsivi: ampi su desktop, comodi su mobile */
  padding: clamp(24px, 6vh, 80px) clamp(20px, 5vw, 60px);
  background:
    radial-gradient(ellipse 60% 50% at 50% 40%, rgba(59, 130, 246, 0.12), transparent 70%),
    radial-gradient(ellipse 50% 40% at 20% 80%, rgba(139, 92, 246, 0.10), transparent 70%),
    radial-gradient(ellipse 60% 40% at 80% 80%, rgba(245, 158, 11, 0.08), transparent 70%),
    rgba(8, 10, 16, 0.88);
  backdrop-filter: blur(10px) saturate(0.9);
  -webkit-backdrop-filter: blur(10px) saturate(0.9);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s var(--ease);
  overflow-y: auto;
  box-sizing: border-box;
}
.auth-gate.show {
  opacity: 1;
  pointer-events: auto;
}

/* Variante "dismissibile" (su home): backdrop più leggero */
.auth-gate.dismissible {
  background:
    radial-gradient(ellipse 60% 50% at 50% 40%, rgba(59, 130, 246, 0.10), transparent 70%),
    rgba(8, 10, 16, 0.65);
}

.auth-card {
  width: 100%;
  max-width: 460px;
  margin: auto;
  background:
    linear-gradient(180deg, rgba(255,255,255,0.015), transparent 30%),
    var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 0;
  box-shadow:
    0 30px 90px rgba(0, 0, 0, 0.65),
    0 0 0 1px rgba(255, 255, 255, 0.04) inset,
    0 0 60px rgba(59, 130, 246, 0.06);
  position: relative;
  overflow: hidden;
  animation: authIn 0.4s cubic-bezier(0.22, 1, 0.36, 1) both;
}
@keyframes authIn {
  from { opacity: 0; transform: translateY(14px) scale(0.97); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

.auth-card::before {
  content: "";
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
  background: linear-gradient(90deg, #8B5CF6, #3B82F6, #14B8A6, #10B981, #F59E0B, #F97316, #F43F5E, #06B6D4);
  background-size: 250% 100%;
  animation: rainbowShift 8s linear infinite;
}
@keyframes rainbowShift {
  to { background-position: -250% 0; }
}

/* Bottone X chiusura (solo su modal dismissibile) */
.auth-close {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-faint);
  font-size: 1.1rem;
  line-height: 1;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: color 0.2s var(--ease), border-color 0.2s var(--ease), background 0.2s var(--ease);
  z-index: 2;
}
.auth-close:hover {
  color: var(--text);
  border-color: var(--text-dim);
  background: var(--surface-3);
}

.auth-card-inner {
  padding: 36px 36px 28px;
}

/* Icona chiave decorativa */
.auth-icon {
  width: 56px;
  height: 56px;
  border-radius: 14px;
  background:
    linear-gradient(135deg, rgba(59, 130, 246, 0.15), rgba(139, 92, 246, 0.1));
  border: 1px solid rgba(59, 130, 246, 0.3);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 20px;
  position: relative;
  box-shadow: 0 8px 24px rgba(59, 130, 246, 0.15);
}
.auth-icon svg {
  width: 26px;
  height: 26px;
  color: #3B82F6;
}
.auth-icon::after {
  content: "";
  position: absolute;
  inset: -4px;
  border-radius: 18px;
  background: radial-gradient(circle, rgba(59, 130, 246, 0.2), transparent 70%);
  z-index: -1;
  opacity: 0.6;
}

.auth-eyebrow {
  font-family: "JetBrains Mono", monospace;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  color: var(--text-faint);
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.auth-eyebrow::before {
  content: "";
  width: 18px;
  height: 1px;
  background: var(--accent);
}

.auth-card h2 {
  font-size: 1.7rem;
  margin: 0 0 10px;
  letter-spacing: -0.02em;
  color: var(--text);
}

.auth-sub {
  font-size: 0.94rem;
  color: var(--text-dim);
  margin: 0 0 26px;
  line-height: 1.55;
  max-width: 38ch;
}

.auth-field {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 16px;
}
.auth-field label {
  font-family: "JetBrains Mono", monospace;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--text-dim);
}
.auth-field input {
  background: var(--surface-2);
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  padding: 14px 16px;
  color: var(--text);
  font-family: "JetBrains Mono", monospace;
  font-size: 1rem;
  letter-spacing: 0.03em;
  transition: border-color 0.2s var(--ease), background 0.2s var(--ease), box-shadow 0.2s var(--ease);
  user-select: text !important;
  -webkit-user-select: text !important;
  width: 100%;
  box-sizing: border-box;
}
.auth-field input::placeholder {
  color: var(--text-faint);
  opacity: 0.7;
  letter-spacing: 0.05em;
}
.auth-field input:hover { border-color: var(--text-faint); }
.auth-field input:focus {
  outline: none;
  border-color: #3B82F6;
  background: var(--surface-3);
  box-shadow: 0 0 0 4px rgba(59, 130, 246, 0.18);
}
/* La chiave: stile più "codice" */
.auth-field#auth-key-wrap input,
.auth-field input[name="key"] {
  font-size: 1.05rem;
  letter-spacing: 0.12em;
  text-align: center;
  font-weight: 500;
}

.auth-submit {
  width: 100%;
  background: linear-gradient(135deg, #3B82F6, #2563eb);
  color: #fff;
  border: none;
  border-radius: 10px;
  padding: 14px 20px;
  font-family: "JetBrains Mono", monospace;
  font-size: 0.86rem;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  font-weight: 600;
  cursor: pointer;
  margin-top: 10px;
  transition: transform 0.1s var(--ease), box-shadow 0.2s var(--ease), filter 0.2s var(--ease);
  box-shadow: 0 8px 24px rgba(59, 130, 246, 0.3), 0 0 0 1px rgba(255,255,255,0.08) inset;
  position: relative;
  overflow: hidden;
}
.auth-submit:hover:not(:disabled) {
  filter: brightness(1.08);
  box-shadow: 0 12px 32px rgba(59, 130, 246, 0.45), 0 0 0 1px rgba(255,255,255,0.12) inset;
}
.auth-submit:active:not(:disabled) { transform: translateY(1px); }
.auth-submit:disabled { opacity: 0.55; cursor: progress; }

.auth-status {
  display: none;
  margin-top: 14px;
  padding: 12px 16px;
  border-radius: 8px;
  font-size: 0.88rem;
  line-height: 1.45;
  border: 1px solid var(--border);
  background: var(--surface-2);
}
.auth-status.show { display: block; animation: fadeIn 0.22s var(--ease); }
.auth-status.err {
  color: #fecaca;
  border-color: rgba(239, 68, 68, 0.5);
  background: rgba(239, 68, 68, 0.08);
}
.auth-status.ok {
  color: #d1fae5;
  border-color: rgba(16, 185, 129, 0.5);
  background: rgba(16, 185, 129, 0.08);
}

.auth-foot {
  margin: 24px 36px 0;
  padding: 18px 0 24px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  font-family: "JetBrains Mono", monospace;
  font-size: 0.74rem;
  color: var(--text-faint);
}
.auth-foot a {
  color: var(--accent);
  border-bottom: none;
  text-decoration: none;
}
.auth-foot a:hover { color: #5ea0fa; }

/* Bottone "Accedi" nella top-nav — pill outline → fill su hover, con icona chiave */
.nav-auth-li { display: flex; align-items: center; }
.nav-auth-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-family: "JetBrains Mono", monospace;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-weight: 500;
  color: #82a8f1;
  background:
    linear-gradient(135deg, rgba(59, 130, 246, 0.10), rgba(59, 130, 246, 0.04));
  border: 1px solid rgba(59, 130, 246, 0.35);
  padding: 7px 14px 7px 12px;
  border-radius: 999px;
  cursor: pointer;
  position: relative;
  transition: color 0.22s var(--ease), border-color 0.22s var(--ease),
              background 0.22s var(--ease), box-shadow 0.22s var(--ease),
              transform 0.12s var(--ease);
}
.nav-auth-btn::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  box-shadow: 0 0 0 0 rgba(59, 130, 246, 0.0);
  transition: box-shadow 0.22s var(--ease);
}
.nav-auth-icon {
  width: 13px;
  height: 13px;
  flex-shrink: 0;
  transition: transform 0.22s var(--ease);
}
.nav-auth-btn:hover {
  color: #fff;
  background: linear-gradient(135deg, #3B82F6, #2563eb);
  border-color: transparent;
}
.nav-auth-btn:hover::before {
  box-shadow: 0 0 24px 4px rgba(59, 130, 246, 0.35);
}
.nav-auth-btn:hover .nav-auth-icon {
  transform: rotate(-12deg);
}
.nav-auth-btn:active { transform: translateY(1px); }
.nav-auth-btn:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.35);
}

/* Auth wall — pagina minimal mostrata quando middleware blocca */
body.locked-wall {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}
.locked-home {
  position: fixed;
  top: 22px;
  left: 22px;
  z-index: 100;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px 8px 11px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  font-family: "JetBrains Mono", monospace;
  font-size: 0.74rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-dim);
  text-decoration: none;
  transition: color 0.2s, border-color 0.2s, background 0.2s;
}
.locked-home:hover {
  color: var(--text);
  border-color: var(--text-dim);
  background: var(--surface-2);
}
.locked-home svg { flex-shrink: 0; }

@media (max-width: 600px) {
  .locked-home { top: 12px; left: 12px; padding: 6px 12px 6px 10px; font-size: 0.7rem; }
}

@media (max-width: 480px) {
  .auth-card-inner { padding: 28px 22px 20px; }
  .auth-foot { margin: 16px 22px 0; padding: 14px 0 18px; }
  .auth-card h2 { font-size: 1.35rem; }
  .auth-sub { font-size: 0.88rem; margin-bottom: 22px; }
  .auth-icon { width: 46px; height: 46px; margin-bottom: 14px; border-radius: 12px; }
  .auth-icon svg { width: 22px; height: 22px; }
}

/* badge utente in basso quando autenticati */
.auth-userbadge {
  position: fixed;
  bottom: 22px;
  left: 22px;
  z-index: 90;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 7px 8px 7px 14px;
  font-family: "JetBrains Mono", monospace;
  font-size: 0.74rem;
  color: var(--text-dim);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  box-shadow: 0 4px 16px rgba(0,0,0,0.35);
}
.auth-userbadge .aub-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #10B981;
  box-shadow: 0 0 8px rgba(16, 185, 129, 0.7);
}
.auth-userbadge .aub-name { color: var(--text); }
.auth-userbadge .aub-logout {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-faint);
  font-family: inherit;
  font-size: 0.7rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 4px 10px;
  border-radius: 999px;
  cursor: pointer;
  transition: color 0.2s var(--ease), border-color 0.2s var(--ease);
}
.auth-userbadge .aub-logout:hover { color: var(--accent); border-color: var(--accent); }
@media (max-width: 720px) {
  .auth-userbadge { bottom: 12px; left: 12px; font-size: 0.7rem; }
  .auth-card { padding: 26px 22px 22px; }
}

/* ============================================================
   ANTI-COPY (site-wide) — input rimangono editabili
   ============================================================ */
body {
  user-select: none;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
}
input, textarea, select, .admin-page * {
  user-select: text !important;
  -webkit-user-select: text !important;
}
img { -webkit-user-drag: none; user-drag: none; pointer-events: none; }
img.allow-drag, .home-card img, .auth-card img { pointer-events: auto; }

/* ============================================================
   BACKGROUND: aurora blobs + grid pattern
   ============================================================ */
body::before {
  /* Grid pattern */
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  background-image:
    linear-gradient(rgba(232, 234, 242, 0.028) 1px, transparent 1px),
    linear-gradient(90deg, rgba(232, 234, 242, 0.028) 1px, transparent 1px);
  background-size: 48px 48px;
  mask-image: radial-gradient(ellipse 80% 60% at 50% 35%, #000 0%, #000 50%, transparent 100%);
  -webkit-mask-image: radial-gradient(ellipse 80% 60% at 50% 35%, #000 0%, #000 50%, transparent 100%);
}

body::after {
  /* Aurora colored blobs */
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  background-image:
    radial-gradient(circle 700px at 8% 12%,  rgba(59, 130, 246, 0.13), transparent 55%),
    radial-gradient(circle 600px at 92% 8%,  rgba(245, 158, 11, 0.10), transparent 55%),
    radial-gradient(circle 800px at 78% 78%, rgba(139, 92, 246, 0.12), transparent 55%),
    radial-gradient(circle 600px at 12% 92%, rgba(20, 184, 166, 0.10), transparent 55%),
    radial-gradient(circle 500px at 50% 50%, rgba(244, 63, 94, 0.06), transparent 60%);
  animation: auroraFloat 20s ease-in-out infinite alternate;
}

@keyframes auroraFloat {
  0%   { transform: translate3d(0, 0, 0) scale(1); }
  50%  { transform: translate3d(-2%, 1.5%, 0) scale(1.03); }
  100% { transform: translate3d(2%, -1%, 0) scale(1); }
}

@media (prefers-reduced-motion: reduce) {
  body::after { animation: none; }
}

body > * { position: relative; z-index: 1; }
.top-nav { z-index: 100; }

/* ============================================================
   COPYRIGHT (footer bottom row)
   ============================================================ */
.copyright {
  border-top: 1px solid var(--border);
  padding: 18px 28px;
  text-align: center;
  font-family: "JetBrains Mono", monospace;
  font-size: 0.7rem;
  color: var(--text-faint);
  letter-spacing: 0.08em;
}
.copyright a { color: var(--text-dim); border: none; }
.copyright a:hover { color: var(--accent); }
