@counter-style paren-alpha { system: extends lower-alpha; prefix: "("; suffix: ") "; }

:root {
  --font: 'WebCM Serif 10', 'Latin Modern Roman', 'CMU Serif', Georgia, 'Times New Roman', serif;
  --mono: 'WebCM Typewriter 10', 'Computer Modern Typewriter', 'Latin Modern Mono', 'Courier New', monospace;

  --size: 19px;          /* corpo del testo */
  --leading: 1.38;       /* interlinea */
  --measure: 35em;       /* larghezza della colonna di testo */
  --indent: 1.5em;       /* rientro della prima riga dei paragrafi */

  --paper: #ffffff;
  --ink: #111111;
  --muted: #666666;
  --link: #1f3f99;
  --rule: #111111;
  --menu-bg: #f4f4f2;
  --menu-line: #cfcfca;
}

/* ---------- base ---------- */
html { font-size: var(--size); height: 100%; -webkit-text-size-adjust: 100%; }
body {
  margin: 0; height: 100%; box-sizing: border-box;
  background: var(--paper); color: var(--ink);
  font-family: var(--font); line-height: var(--leading);
  font-kerning: normal; font-variant-ligatures: common-ligatures;
  text-rendering: optimizeLegibility;
}
a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; }
strong { font-weight: 700; }
em { font-style: italic; }

/* ---------- layout ---------- */
table#tlayout { width: 100%; height: 100%; border: none; border-collapse: separate; border-spacing: 0; background: var(--paper); }
#tlayout td { vertical-align: top; }

#tlayout td#layout-menu {
  background: var(--menu-bg);
  border-right: 1px solid var(--menu-line);
  padding: 0.9em 18px 1.2em 16px; min-width: 164px;
  width: 1%; text-align: left;
}
#menu { position: sticky; top: 0.9em; max-width: 230px; max-height: calc(100vh - 1.8em); overflow-y: auto; }

#tlayout td#layout-content { padding: 0 2.4em 2.5em; background: var(--paper); }
.page { max-width: var(--measure); margin: 0 auto; }

/* ---------- menu ---------- */
div.menu-category {
  margin: 1.4em 0 0.3em; padding-bottom: 0.2em;
  border-bottom: 1px solid #9a9a95;
  font-size: 1.05em; font-weight: 700; font-variant: small-caps; letter-spacing: 0.03em;
}
div.menu-category:first-child { margin-top: 0.1em; }
div.menu-category a:link, div.menu-category a:visited { color: var(--ink); }
div.menu-item { padding-left: 1em; text-indent: -0.6em; margin: 1px 0; }
div.menu-item a { font-size: 0.88em; line-height: 1.75; }
div.menu-item a.current { color: var(--ink); font-weight: 700; }

/* ---------- titolo ---------- */
#toptitle { text-align: center; margin: 2.3em 0 1.8em; }
#toptitle h1 {
  margin: 0; font-size: 1.95em; font-weight: 400; line-height: 1.2; hyphens: manual;
}
#subtitle { margin-top: 0.7em; font-style: italic; font-size: 1.02em; }
#subtitle:empty { display: none; }

/* ---------- corpo ---------- */
#content {
  text-align: justify; hyphens: auto; -webkit-hyphens: auto;
  counter-reset: sec sub subsub fig;
  overflow-wrap: break-word;
}
#content p { margin: 0; text-indent: var(--indent); }

#content p:first-child,
#content h1 + p, #content h2 + p, #content h3 + p, #content h4 + p,
#content h5 + p, #content h6 + p { text-indent: 0; }
#content li > p { text-indent: 0; }

/* ---------- sezioni numerate (\section, \subsection, ...) ---------- */
#content h1, #content h2, #content h3, #content h4, #content h5, #content h6 {
  text-align: left; hyphens: manual; line-height: 1.2; font-weight: 700; break-after: avoid;
}
#content h1, #content h2 { font-size: 1.45em; margin: 1.9em 0 0.7em; counter-increment: sec; counter-reset: sub subsub; }
#content h3 { font-size: 1.18em; margin: 1.55em 0 0.55em; counter-increment: sub; counter-reset: subsub; }
#content h4 { font-size: 1em; margin: 1.3em 0 0.45em; counter-increment: subsub; }
#content h5, #content h6 { font-size: 1em; font-style: italic; margin: 1.1em 0 0.3em; }

#content h1::before, #content h2::before { content: counter(sec) "\2003"; }
#content h3::before { content: counter(sec) "." counter(sub) "\2003"; }
#content h4::before { content: counter(sec) "." counter(sub) "." counter(subsub) "\2003"; }
#content > h1:first-child, #content > h2:first-child { margin-top: 0.4em; }

/* ---------- liste (itemize / enumerate) ---------- */
#content ul, #content ol { margin: 0.5em 0; padding-left: 2em; text-indent: 0; }
#content li { margin: 0.18em 0; }
#content ul { list-style-type: disc; }
#content ul ul { list-style-type: "\2013\00a0\00a0"; }
#content ul ul ul { list-style-type: "\2217\00a0\00a0"; }
#content ol { list-style-type: decimal; }
#content ol ol { list-style-type: paren-alpha; }
#content ol ol ol { list-style-type: lower-roman; }
#content ol ol ol ol { list-style-type: upper-alpha; }
#content dl { margin: 0.5em 0; }
#content dt { font-weight: 700; }
#content dd { margin-left: 2em; }

/* ---------- ambienti: teoremi, definizioni, dimostrazioni ---------- */
.env { margin: 1em 0; }
.env.thm { font-style: italic; }
.env.thm strong, .env.thm tt, .env.thm code { font-style: normal; }
.env.proof > p:first-child > strong:first-child { font-weight: 400; font-style: italic; }
.env.proof > :last-child::after {
  content: ""; float: right; width: 0.55em; height: 0.55em;
  border: 1px solid currentColor; margin: 0.35em 0 0 1em;
}

/* quotes */
#content blockquote { margin: 0.9em 2em; }

/* ---------- tabelle ---------- */
#content table {
  border-collapse: collapse; margin: 1.2em auto; font-size: 0.96em;
  border-top: 1.5px solid var(--rule); border-bottom: 1.5px solid var(--rule);
}
#content th, #content td { padding: 0.28em 0.9em; border: none; text-align: left; }
#content thead th { font-weight: 400; border-bottom: 1px solid var(--rule); }
#content tbody tr:first-child td { padding-top: 0.4em; }

/* ---------- codice ---------- */

/* Blocco di codice */
#content pre {
  font-family: var(--mono);
  font-size: 0.85em;
  line-height: 1.4;
  background: transparent;
  border: none;
  border-top: 1px solid var(--rule);
  border-bottom: 1px solid var(--rule);
  margin: 1.4em 0;
  padding: 0.6em 0;
  overflow-x: auto;
  text-align: left;
  hyphens: none;
  text-indent: 0;
}

#content pre code {
  font-size: inherit;
  font-family: inherit;
  background: none;
  padding: 0;
}

/* Codice in-line */
#content code, #content tt {
  font-family: var(--mono);
  font-size: 0.86em;
  background: transparent;
  hyphens: none;
}

/* ---------- figure ---------- */
#content figure { margin: 1.3em 0; text-align: center; }
#content figure img { max-width: 100%; height: auto; }
#content figcaption { margin-top: 0.5em; font-size: 0.93em; counter-increment: fig; }
#content figcaption::before { content: "Figura " counter(fig) ": "; font-weight: 700; }
#content img { max-width: 100%; }

#content hr { border: 0; border-top: 1px solid var(--rule); width: 40%; margin: 1.8em auto; }

/* ---------- formule ---------- */
mjx-container[display="true"] { overflow-x: auto; overflow-y: hidden; max-width: 100%; }

/* ---------- piè di pagina ---------- */
#footer {
  margin-top: 3.5em; padding-top: 0.5em; border-top: 1px solid #c4c4c0;
  font-size: 0.8em; font-style: italic; color: var(--muted); text-align: center;
}

/* ---------- schermi stretti ---------- */
@media (max-width: 700px) {
  html { font-size: 17px; }
  table#tlayout, #tlayout > tbody, #tlayout > tbody > tr, #tlayout > tbody > tr > td { display: block; width: auto; }
  table#tlayout { height: auto; }
  #tlayout td#layout-menu { border-right: none; border-bottom: 1px solid var(--menu-line); }
  #menu { position: static; max-width: none; max-height: none; }
  #tlayout td#layout-content { padding: 0 1.2em 2em; }
  #content blockquote { margin-left: 1em; margin-right: 1em; }
}

/* ---------- opzione di stampa ---------- */
@media print {
  #layout-menu { display: none; }
  html { font-size: 11pt; }
  #tlayout td#layout-content { padding: 0; }
  .page { max-width: none; }
  #footer { display: none; }
}
