/* Colore del corso: cambia da solo quando selezioni un corso o apri una nota.
   Lo imposta script.js (applyTheme); qui sotto c'è il valore di partenza. */
@property --c {
  syntax: "<color>";
  inherits: true;
  initial-value: #818cf8;
}
:root {
  --c: #818cf8;
  transition: --c 0.4s ease;
}

html,
body {
  height: 100%;
}
body {
  background: #07080c;
  color: #e2e8f0;
  font-feature-settings: "cv11", "ss01";
  -webkit-font-smoothing: antialiased;
}
body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  background:
    radial-gradient(
      900px 500px at 85% -10%,
      rgba(99, 102, 241, 0.1),
      transparent 60%
    ),
    radial-gradient(
      700px 500px at -10% 110%,
      rgba(20, 184, 166, 0.07),
      transparent 60%
    );
}

/* ---------- Evidenziazione del testo (colore del corso) ---------- */
::selection {
  background: color-mix(in srgb, var(--c) 40%, transparent);
  color: #fff;
}

/* ---------- Barra di scorrimento (colore del corso) ---------- */
.scroll::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}
.scroll::-webkit-scrollbar-thumb {
  background: color-mix(in srgb, var(--c) 45%, #0b0d13);
  border-radius: 99px;
  border: 3px solid transparent;
  background-clip: content-box;
}
.scroll::-webkit-scrollbar-thumb:hover {
  background: var(--c);
  background-clip: content-box;
  border: 3px solid transparent;
}
/* Firefox */
@supports (-moz-appearance: none) {
  .scroll {
    scrollbar-width: thin;
    scrollbar-color: color-mix(in srgb, var(--c) 55%, #0b0d13) transparent;
  }
}

.card {
  position: relative;
  background: linear-gradient(
    180deg,
    rgba(28, 33, 48, 0.55),
    rgba(15, 18, 24, 0.7)
  );
  transition:
    transform 0.25s cubic-bezier(0.2, 0.7, 0.2, 1),
    border-color 0.25s,
    box-shadow 0.25s;
}
.card::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  opacity: 0;
  transition: opacity 0.3s;
  background: radial-gradient(
    400px circle at var(--mx, 50%) var(--my, 0%),
    var(--glow, rgba(129, 140, 248, 0.14)),
    transparent 55%
  );
  pointer-events: none;
}
.card:hover {
  transform: translateY(-3px);
  border-color: rgba(148, 163, 184, 0.28);
  box-shadow: 0 20px 40px -20px rgba(0, 0, 0, 0.7);
}
.card:hover::before {
  opacity: 1;
}
.skeleton {
  position: relative;
  overflow: hidden;
  background: #141821;
}
.skeleton::after {
  content: "";
  position: absolute;
  inset: 0;
  transform: translateX(-100%);
  background: linear-gradient(
    90deg,
    transparent,
    rgba(148, 163, 184, 0.08),
    transparent
  );
  animation: shimmer 1.4s infinite;
}

/* ---------- Contenuto Notion ---------- */
.nt h1 {
  font-size: 1.75rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin: 2rem 0 0.75rem;
  color: #f8fafc;
}
.nt h2 {
  font-size: 1.35rem;
  font-weight: 650;
  letter-spacing: -0.015em;
  margin: 1.75rem 0 0.6rem;
  color: #f1f5f9;
}
.nt h3 {
  font-size: 1.1rem;
  font-weight: 600;
  margin: 1.4rem 0 0.5rem;
  color: #e2e8f0;
}
/* quando clicchi un titolo nell'indice, lascia un po' d'aria sopra */
.nt h1,
.nt h2,
.nt h3 {
  scroll-margin-top: 1.5rem;
}
.nt p {
  line-height: 1.8;
  color: #cbd5e1;
  margin: 0.65rem 0;
}
.nt ul,
.nt ol {
  margin: 0.6rem 0;
  padding-left: 1.4rem;
  color: #cbd5e1;
  line-height: 1.75;
}
.nt ul {
  list-style: none;
  padding-left: 0;
}
.nt ul > li {
  position: relative;
  padding-left: 1.4rem;
  margin: 0.25rem 0;
}
.nt ul > li::before {
  content: "";
  position: absolute;
  left: 0.35rem;
  top: 0.7em;
  width: 6px;
  height: 6px;
  border-radius: 99px;
  background: var(--accent, #818cf8);
}
.nt ol {
  list-style: decimal;
}
.nt ol > li {
  margin: 0.25rem 0;
  padding-left: 0.3rem;
}
.nt ol > li::marker {
  color: var(--accent, #818cf8);
  font-weight: 600;
}
.nt code.inline {
  font-family: "JetBrains Mono", monospace;
  font-size: 0.85em;
  background: #1c2130;
  border: 1px solid #272d3f;
  padding: 0.12em 0.4em;
  border-radius: 6px;
  color: #fda4af;
}
.nt pre {
  background: #07080c;
  border: 1px solid #1c2130;
  border-radius: 12px;
  padding: 1rem 1.2rem;
  overflow-x: auto;
  margin: 1rem 0;
  font-family: "JetBrains Mono", monospace;
  font-size: 0.85rem;
  line-height: 1.65;
  color: #cbd5e1;
}
.nt blockquote {
  border-left: 3px solid var(--accent, #818cf8);
  padding: 0.2rem 0 0.2rem 1rem;
  margin: 1rem 0;
  color: #94a3b8;
  font-style: italic;
}
.nt .callout {
  display: flex;
  gap: 0.75rem;
  background: rgba(129, 140, 248, 0.07);
  border: 1px solid rgba(129, 140, 248, 0.2);
  border-radius: 12px;
  padding: 0.9rem 1rem;
  margin: 1rem 0;
  color: #cbd5e1;
  line-height: 1.7;
}
.nt hr {
  border: 0;
  height: 1px;
  background: #1c2130;
  margin: 1.75rem 0;
}
.nt .todo {
  display: flex;
  gap: 0.6rem;
  align-items: flex-start;
  margin: 0.3rem 0;
  color: #cbd5e1;
  line-height: 1.7;
}
.nt .todo .box {
  width: 18px;
  height: 18px;
  margin-top: 0.25rem;
  border-radius: 6px;
  border: 1.5px solid #3a425b;
  display: grid;
  place-items: center;
  flex: none;
}
.nt .todo.done .box {
  background: var(--accent, #818cf8);
  border-color: var(--accent, #818cf8);
}
.nt .todo.done span.t {
  text-decoration: line-through;
  color: #64748b;
}
.nt a {
  color: #a5b4fc;
  text-decoration: underline;
  text-underline-offset: 3px;
}
.nt mark {
  background: rgba(250, 204, 21, 0.18);
  color: #fde68a;
  padding: 0 0.2em;
  border-radius: 4px;
}
.nt figure {
  margin: 1.5rem 0;
}
.nt figure img {
  display: block;
  max-width: 100%;
  height: auto;
  margin: 0 auto;
  border-radius: 14px;
  border: 1px solid #1c2130;
  background: #0f1218;
  min-height: 80px;
  transition: border-color 0.2s;
}
.nt figure a:hover img {
  border-color: rgba(129, 140, 248, 0.5);
}
.nt figcaption {
  text-align: center;
  font-size: 0.85rem;
  color: #64748b;
  margin-top: 0.6rem;
}

/* Evidenziazione dei risultati di ricerca (colore del corso) */
mark.hl {
  background: color-mix(in srgb, var(--c) 30%, transparent);
  color: #fff;
  border-radius: 4px;
  padding: 0 2px;
}

/* ---------- Indice laterale della nota ---------- */
.toc {
  max-height: calc(100vh - 3rem);
  overflow-y: auto;
  border-left: 1px solid #1c2130;
}
.toc-label {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: #64748b;
  margin: 0 0 0.6rem 12px;
}
.toc a {
  display: block;
  font-size: 13px;
  line-height: 1.35;
  padding: 0.35rem 0.5rem 0.35rem 12px;
  margin-left: -1px;
  color: #8b94a7;
  border-left: 2px solid transparent;
  transition:
    color 0.15s,
    border-color 0.15s;
}
.toc a:hover {
  color: #e2e8f0;
}
.toc a.active {
  color: var(--c);
  border-left-color: var(--c);
  font-weight: 600;
}

/* ---------- Formule matematiche (KaTeX, lo stesso motore che usa Notion) ---------- */
.nt .katex {
  font-size: 1.1em;
}
/* Formula a blocco: riquadro centrato, scorre in orizzontale se è molto larga */
.nt .eq-block {
  margin: 1.25rem 0;
  padding: 0.9rem 1.1rem;
  overflow-x: auto;
  overflow-y: hidden;
  border-radius: 12px;
  border: 1px solid #1c2130;
  background: color-mix(in srgb, var(--c) 5%, #0b0d13);
  color: #f1f5f9;
}
.nt .eq-block .katex-display {
  margin: 0;
}
.nt .eq-block .katex {
  font-size: 1.25em;
}
/* Formula con errori di sintassi: KaTeX mostra il testo LaTeX (di default in rosso scuro, illeggibile sul nero) */
.nt .katex-error {
  color: #fda4af !important;
  font-family: "JetBrains Mono", monospace;
  font-size: 0.85em;
}

/* ---------- Tabelle ---------- */
.nt .tbl-wrap {
  margin: 1.25rem 0;
  overflow-x: auto;
  border: 1px solid #1c2130;
  border-radius: 12px;
  background: rgba(7, 8, 12, 0.35);
}
.nt .nt-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
  line-height: 1.6;
}
.nt .nt-table th,
.nt .nt-table td {
  min-width: 6.5rem;
  padding: 0.65rem 0.95rem;
  text-align: left;
  vertical-align: top;
  color: #cbd5e1;
  border-right: 1px solid #1c2130;
  border-bottom: 1px solid #1c2130;
}
.nt .nt-table tr > :last-child {
  border-right: 0;
}
.nt .nt-table tr:last-child > * {
  border-bottom: 0;
}
.nt .nt-table th {
  background: color-mix(in srgb, var(--c) 11%, #0f1218);
  color: #f1f5f9;
  font-weight: 600;
}

/* ---------- Stampa: "Scarica" salva la nota in PDF (carta chiara, solo la nota) ---------- */
@page {
  size: A4;
  margin: 16mm 15mm;
}
@media print {
  html,
  body.printing {
    height: auto !important;
    overflow: visible !important;
    background: #fff !important;
    color: #0f172a !important;
  }
  body.printing::before {
    display: none !important;
  }
  /* i colori di sfondo (intestazione tabelle, badge, riquadri) vanno stampati */
  body.printing,
  body.printing * {
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }
  /* niente app: solo la nota */
  body.printing > div:not(#modal) {
    display: none !important;
  }
  body.printing #modal {
    position: static !important;
    inset: auto !important;
    display: block !important;
  }
  body.printing #backdrop,
  body.printing #close,
  body.printing #dl,
  body.printing #toc {
    display: none !important;
  }
  body.printing #modalScroll {
    position: static !important;
    inset: auto !important;
    height: auto !important;
    overflow: visible !important;
  }
  body.printing #modalScroll > div {
    display: block !important;
    padding: 0 !important;
    min-height: 0 !important;
  }
  body.printing #sheet {
    max-width: none !important;
    width: 100% !important;
    min-height: 0 !important;
    margin: 0 !important;
    background: #fff !important;
    border: 0 !important;
    border-radius: 0 !important;
    box-shadow: none !important;
    overflow: visible !important;
    animation: none !important;
  }
  body.printing #sheetHead {
    padding: 0.5rem 0 1rem !important;
    border-bottom: 1px solid #cbd5e1 !important;
  }
  body.printing #sheetHead,
  body.printing #sheetHead div {
    color: #475569 !important;
  }
  body.printing #sheetHead h2 {
    color: #0f172a !important;
    padding-right: 0 !important;
  }
  body.printing .pr-badge {
    color: #334155 !important;
    background: #f1f5f9 !important;
    box-shadow: inset 0 0 0 1px #cbd5e1 !important;
  }
  body.printing #sheetBody {
    width: 100% !important;
    padding: 1rem 0 0 !important;
    font-size: 11pt !important;
  }

  /* contenuto: colori da carta chiara */
  body.printing .nt p,
  body.printing .nt li,
  body.printing .nt .todo,
  body.printing .nt .callout,
  body.printing .nt td {
    color: #1f2937 !important;
  }
  body.printing .nt h1,
  body.printing .nt h2,
  body.printing .nt h3,
  body.printing .nt strong,
  body.printing .nt th {
    color: #0f172a !important;
  }
  body.printing .nt a {
    color: #4338ca !important;
  }
  body.printing .nt blockquote {
    color: #475569 !important;
  }
  body.printing .nt code.inline {
    background: #f1f5f9 !important;
    border-color: #e2e8f0 !important;
    color: #be123c !important;
  }
  body.printing .nt pre {
    background: #f8fafc !important;
    border-color: #e2e8f0 !important;
    color: #1e293b !important;
    overflow: visible !important;
    white-space: pre-wrap !important;
    word-break: break-word !important;
  }
  body.printing .nt .callout {
    background: #eef2ff !important;
    border-color: #c7d2fe !important;
  }
  body.printing .nt hr {
    background: #e2e8f0 !important;
  }
  body.printing .nt .todo .box {
    border-color: #94a3b8 !important;
  }
  body.printing .nt .todo.done span.t {
    color: #64748b !important;
  }
  body.printing .nt figure img {
    border-color: #e2e8f0 !important;
    background: #fff !important;
    max-height: 240mm;
    width: auto;
    object-fit: contain;
  }
  body.printing .nt figcaption {
    color: #64748b !important;
  }
  /* formule e tabelle */
  body.printing .nt .katex {
    color: #0f172a !important;
  }
  body.printing .nt .eq-block {
    background: #f8fafc !important;
    border-color: #e2e8f0 !important;
    color: #0f172a !important;
    overflow: visible !important;
  }
  body.printing .nt .katex-error {
    color: #be123c !important;
  }
  body.printing .nt .tbl-wrap {
    background: transparent !important;
    border-color: #cbd5e1 !important;
    overflow: visible !important;
  }
  body.printing .nt .nt-table th,
  body.printing .nt .nt-table td {
    border-color: #cbd5e1 !important;
  }
  body.printing .nt .nt-table th {
    background: color-mix(in srgb, var(--c) 14%, #fff) !important;
  }

  /* niente spezzature brutte */
  body.printing .nt h1,
  body.printing .nt h2,
  body.printing .nt h3 {
    break-after: avoid;
  }
  body.printing .nt figure,
  body.printing .nt pre,
  body.printing .nt .eq-block,
  body.printing .nt .callout,
  body.printing .nt .nt-table tr {
    break-inside: avoid;
  }
}
