:root {
  --bg-color: #0f172a;
  --bg-card: #1e293b;
  --accent: #02d8ff;
  --accent-soft: rgba(2, 216, 255, 0.15);
  --accent-secondary: #7af58b;
  --text-main: #f5f7ff;
  --text-muted: #a1a7c4;
  --border-subtle: #232743;
  --shadow-soft: 0 18px 40px rgba(0, 0, 0, 0.55);
  --radius-lg: 14px;
  --radius-pill: 999px;
  --font-main: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --max-width: 960px;
}

* {
  box-sizing: border-box;
}

.back-to-index {
  margin-top: 10px;
  font-size: 0.9rem;
}

.back-to-index a {
  color: #16a34a; /* verde più scuro e leggibile */
  font-weight: 600;
  text-decoration: none;
}

.back-to-index a:hover {
  text-decoration: underline;
}

body {
  margin: 0;
  padding: 0;
  font-family: var(--font-main);
  background:
    radial-gradient(circle at 0 0, #6d8fc7 0, #374d83 45%, #1934a8 100%),
    radial-gradient(circle at 110% 0, #6d8fc7 0, #374d83 45%, #1934a8 100%),
    repeating-linear-gradient(
      135deg,
      rgba(255, 255, 255, 0.05) 0,
      rgba(255, 255, 255, 0.05) 1px,
      transparent 1px,
      transparent 7px
    );
  color: var(--text-main);
  line-height: 1.7;
  position: relative;
  overflow-x: hidden;
}

/* “Formule” sullo sfondo: righe diagonali e simboli pseudo-matematici */
body::before {
  content: "f(x)=w·x+b   Σ μ(A,x)   ∂L/∂w   argmin L(w)   P(y|x)   ∑ w_i x_i   μ(A∩B,x)   ∫ μ(A,x)dx   inf_x μ(x)";
  position: fixed;
  left: 55%;
  top: 10%;
  transform: translateX(-50%) rotate(-12deg);
  font-size: 0.8rem;
  letter-spacing: 0.32em;
  color: rgba(180, 220, 255, 0.18);
  white-space: nowrap;
  pointer-events: none;
  z-index: 0;
}

body::after {
  content: "∫ e^{-x²}dx   ⊕   max-min   grad L   λ→∞   argmax P(y|x)   sup_x μ(x)   t-norma(a,b)   t-conorma(a,b)";
  position: fixed;
  right: -8%;
  bottom: 8%;
  transform: rotate(18deg);
  font-size: 0.75rem;
  letter-spacing: 0.26em;
  color: rgba(140, 230, 190, 0.15);
  white-space: nowrap;
  pointer-events: none;
  z-index: 0;
}

/* Terzo livello di formule sul lato sinistro */
.fp-formulas-left {
  position: fixed;
  left: 2%;
  top: 55%;
  transform: rotate(-32deg);
  font-size: 0.78rem;
  letter-spacing: 0.24em;
  color: rgba(190, 207, 240, 0.16);
  white-space: nowrap;
  pointer-events: none;
  z-index: 0;
}

.page-shell {
  min-height: 100vh;
  padding: 32px 16px 40px;
  display: flex;
  justify-content: center;
  position: relative;
  z-index: 1;
}

.page {
  width: 100%;
  max-width: var(--max-width);
}

header {
  background: linear-gradient(135deg, rgba(2, 216, 255, 0.22), rgba(122, 245, 139, 0.12));
  border-radius: var(--radius-lg);
  padding: 24px 24px 20px;
  border: 1px solid rgba(2, 216, 255, 0.4);
  box-shadow: var(--shadow-soft);
  position: relative;
  overflow: hidden;
}

header::before {
  content: "";
  position: absolute;
  inset: 0;
  background:
    radial-gradient(circle at 10% -10%, rgba(2, 216, 255, 0.22) 0, transparent 55%),
    radial-gradient(circle at 80% 120%, rgba(122, 245, 139, 0.16) 0, transparent 55%);
  opacity: 0.9;
  pointer-events: none;
}

header > * {
  position: relative;
  z-index: 1;
}

h1 {
  margin: 0 0 6px;
  font-size: 1.9rem;
  letter-spacing: 0.02em;
}

header p {
  margin: 0;
  color: var(--text-muted);
  max-width: 760px;
}

.tagline-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 14px;
  border-radius: var(--radius-pill);
  background: rgba(5, 10, 35, 0.9);
  border: 1px solid rgba(2, 216, 255, 0.55);
  color: var(--accent);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 10px;
}

.tagline-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent-secondary);
  box-shadow: 0 0 10px rgba(122, 245, 139, 0.9);
}

nav {
  margin: 22px 0 18px;
  background: rgba(30, 41, 59, 0.96);
  border-radius: var(--radius-lg);
  padding: 10px 14px;
  border: 1px solid rgba(35, 39, 67, 0.9);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.75);
}

nav ul {
  margin: 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

nav a {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 999px;
  background: radial-gradient(circle at 0 0, rgba(2, 216, 255, 0.22), rgba(6, 15, 40, 0.98));
  border: 1px solid rgba(2, 216, 255, 0.55);
  color: var(--text-main);
  font-size: 0.78rem;
  text-decoration: none;
  transition: background 0.18s ease, transform 0.12s ease, box-shadow 0.18s ease;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.65);
}

nav a span {
  font-size: 0.85em;
  color: var(--accent-secondary);
}

nav a:hover {
  background: radial-gradient(circle at 0 0, rgba(2, 216, 255, 0.3), rgba(8, 20, 55, 1));
  transform: translateY(-1px);
  box-shadow: 0 10px 26px rgba(0, 0, 0, 0.85);
}

main {
  display: grid;
  gap: 18px;
  margin-bottom: 18px;
}

section {
  background: radial-gradient(circle at 0 -20%, rgba(2, 216, 255, 0.24), rgba(30, 41, 59, 0.96));
  border-radius: var(--radius-lg);
  padding: 18px 20px 16px;
  border: 1px solid var(--border-subtle);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.8);
  position: relative;
  overflow: hidden;
}

section::before {
  content: "";
  position: absolute;
  inset: 0;
  background:
    radial-gradient(circle at 110% 10%, rgba(122, 245, 139, 0.2) 0, transparent 65%);
  opacity: 0.5;
  pointer-events: none;
}

section > * {
  position: relative;
  z-index: 1;
}

section h2 {
  margin-top: 0;
  margin-bottom: 6px;
  font-size: 1.25rem;
  color: var(--accent);
}

section h2::before {
  content: "";
  display: inline-block;
  width: 18px;
  height: 2px;
  margin-right: 6px;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--accent), var(--accent-secondary));
  vertical-align: middle;
}

h3 {
  margin-top: 14px;
  margin-bottom: 6px;
  font-size: 1rem;
  color: var(--accent-secondary);
}

p {
  margin: 6px 0;
  color: var(--text-main);
}

/* Link testuali generici (es. indice generale, note) più leggibili su sfondi chiari */
a {
  color: #020617;
  font-weight: 600;
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

ul {
  margin: 6px 0 8px 18px;
  padding-left: 0;
  color: var(--text-muted);
}

li {
  margin-bottom: 3px;
}

strong {
  color: inherit;
  font-weight: 600;
}

em {
  color: inherit;
  font-style: italic;
}

blockquote {
  margin: 8px 0;
  padding: 10px 14px;
  border-left: 3px solid var(--accent);
  background: rgba(5, 7, 18, 0.9);
  border-radius: 0 10px 10px 0;
  color: var(--text-muted);
  font-size: 0.95rem;
}

.steps-list {
  counter-reset: step-counter;
  list-style: none;
  margin: 8px 0 4px;
  padding-left: 0;
}

.steps-list li {
  counter-increment: step-counter;
  margin-bottom: 6px;
  position: relative;
  padding-left: 32px;
}

.steps-list li::before {
  content: counter(step-counter);
  position: absolute;
  left: 0;
  top: 2px;
  width: 22px;
  height: 22px;
  border-radius: 999px;
  border: 1px solid rgba(2, 216, 255, 0.9);
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  background: radial-gradient(circle at 30% 0, rgba(2, 216, 255, 0.3), rgba(5, 7, 18, 1));
  box-shadow: 0 0 12px rgba(2, 216, 255, 0.45);
}

footer {
  font-size: 0.78rem;
  color: var(--text-muted);
  text-align: right;
  padding: 6px 4px 0;
  border-top: 1px solid rgba(35, 39, 67, 0.8);
  margin-top: 8px;
}

/* ====================== */
/* Pagine matematica      */
/* ====================== */

.math-page-shell {
  min-height: 100vh;
  padding: 32px 16px 40px;
  display: flex;
  justify-content: center;
  position: relative;
  z-index: 1;
}

.math-page {
  width: 100%;
  max-width: 980px;
}

.math-header {
  background: linear-gradient(135deg, rgba(248, 250, 252, 1), rgba(229, 231, 235, 1));
  border-radius: var(--radius-lg);
  padding: 22px 26px 18px;
  border: 1px solid rgba(148, 163, 184, 0.8);
  box-shadow: 0 18px 40px rgba(15, 23, 42, 0.6);
  position: relative;
  overflow: hidden;
  color: #0f172a;
}

.math-header::before {
  content: "";
  position: absolute;
  inset: 0;
  background:
    radial-gradient(circle at 8% -10%, rgba(59, 130, 246, 0.35) 0, transparent 55%),
    radial-gradient(circle at 85% 110%, rgba(16, 185, 129, 0.25) 0, transparent 60%);
  opacity: 0.9;
  pointer-events: none;
}

.math-header > * {
  position: relative;
  z-index: 1;
}

.math-tagline {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 13px;
  border-radius: var(--radius-pill);
  background: rgba(15, 23, 42, 0.04);
  border: 1px solid rgba(59, 130, 246, 0.55);
  color: #0f172a;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 10px;
}

.math-tagline-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #22c55e;
  box-shadow: 0 0 8px rgba(34, 197, 94, 0.9);
}

.math-header h1 {
  margin: 0 0 8px;
  font-size: 2rem;
  letter-spacing: 0.01em;
  color: #020617;
}

.math-header p {
  margin: 0;
  max-width: 760px;
  color: #1f2933;
}

.math-nav-inner {
  margin: 18px 0 20px;
  background: rgba(15, 23, 42, 0.95);
  border-radius: var(--radius-lg);
  padding: 10px 16px;
  border: 1px solid rgba(55, 65, 81, 0.9);
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.75);
}

.math-nav-inner h2 {
  margin: 0 0 6px;
  font-size: 0.9rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: rgba(226, 232, 240, 0.9);
}

.math-nav-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.math-nav-list a {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 11px;
  border-radius: 999px;
  background: radial-gradient(circle at 0 0, rgba(59, 130, 246, 0.35), rgba(15, 23, 42, 1));
  border: 1px solid rgba(59, 130, 246, 0.8);
  color: rgba(248, 250, 252, 0.96);
  font-size: 0.8rem;
  text-decoration: none;
  box-shadow: 0 10px 26px rgba(0, 0, 0, 0.8);
  transition: background 0.18s ease, transform 0.12s ease, box-shadow 0.18s ease;
}

.math-nav-list a span {
  font-size: 0.78em;
  color: #bbf7d0;
}

.math-nav-list a:hover {
  background: radial-gradient(circle at 0 0, rgba(59, 130, 246, 0.45), rgba(15, 23, 42, 1));
  transform: translateY(-1px);
  box-shadow: 0 14px 32px rgba(0, 0, 0, 0.9);
}

.math-main {
  margin-top: 18px;
  margin-bottom: 20px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.math-section {
  background: rgba(248, 250, 252, 0.96);
  border-radius: var(--radius-lg);
  padding: 18px 22px 16px;
  border: 1px solid rgba(203, 213, 225, 0.9);
  box-shadow: 0 18px 40px rgba(15, 23, 42, 0.8);
  color: #020617;
}

.math-section h2 {
  margin-top: 0;
  margin-bottom: 6px;
  font-size: 1.25rem;
  color: #020617;
}

.math-section h2::before {
  content: "";
  display: inline-block;
  width: 18px;
  height: 2px;
  margin-right: 6px;
  border-radius: 999px;
  background: linear-gradient(90deg, #1d4ed8, #22c55e);
  vertical-align: middle;
}

.math-section h3 {
  margin-top: 14px;
  margin-bottom: 6px;
  font-size: 1rem;
  color: #020617;
  font-weight: 600;
}

.math-section p {
  margin: 6px 0;
  color: #111827;
}

.math-section ul {
  margin: 6px 0 8px 20px;
  padding-left: 0;
  color: #1f2937;
}

.math-section li {
  margin-bottom: 4px;
}

.math-formula-box {
  margin: 10px 0 8px;
  padding: 10px 14px;
  border-radius: 12px;
  border: 1px dashed rgba(59, 130, 246, 0.6);
  background: linear-gradient(135deg, rgba(219, 234, 254, 0.95), rgba(240, 253, 250, 0.96));
  color: #020617;
  font-size: 0.95rem;
}

.math-note {
  font-size: 0.86rem;
  color: #020617;
}

.math-footer {
  font-size: 0.78rem;
  color: rgba(209, 213, 219, 0.9);
  text-align: right;
  padding: 6px 4px 0;
  border-top: 1px solid rgba(55, 65, 81, 0.9);
  margin-top: 8px;
}

@media (max-width: 640px) {
  .math-page-shell {
    padding: 18px 10px 24px;
  }

  .math-header {
    padding: 18px 16px 16px;
  }

  .math-section {
    padding: 14px 14px 12px;
  }
}

/* Card e gallery immagini riutilizzabili */
.gallery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1.5rem;
  margin-top: 1.5rem;
}

.gallery-card {
  background: rgba(12, 18, 40, 0.9);
  border-radius: var(--radius-lg);
  border: 1px solid rgba(120, 190, 255, 0.25);
  box-shadow: 0 18px 45px rgba(0, 0, 0, 0.6);
  overflow: visible;
  display: flex;
  flex-direction: column;
}

.gallery-image-wrapper {
  width: 100%;
  height: 150px;
  background: #020617;
  overflow: visible;
  display: flex;
  align-items: center;
  justify-content: center;
}

.gallery-image-wrapper img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  transform-origin: center center;
}

.gallery-image-wrapper img {
  transition: transform 0.25s ease-out;
}

.gallery-card:hover .gallery-image-wrapper img {
  transform: scale(2.0);
}

/* (Lightbox rimosso: ingrandimento solo on-hover) */

.gallery-card-body {
  padding: 1rem 1.3rem 1.3rem;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.gallery-tag {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: rgba(173, 197, 255, 0.9);
}

.gallery-tag-dot {
  width: 7px;
  height: 7px;
  border-radius: 999px;
  background: linear-gradient(135deg, #7dd3fc, #a855f7);
}

.gallery-card h3 {
  font-size: 1rem;
  margin: 0.2rem 0 0.1rem;
}

.gallery-card p {
  font-size: 0.9rem;
  color: rgba(211, 225, 255, 0.95);
}

.gallery-links {
  margin-top: 0.4rem;
  font-size: 0.8rem;
  color: rgba(230, 240, 255, 0.9);
}

.gallery-links a {
  color: #7dd3fc;
  text-decoration: none;
  font-weight: 500;
}

.gallery-links a:hover {
  text-decoration: underline;
}

@media (max-width: 640px) {
  .page-shell {
    padding: 18px 10px 24px;
  }

  header {
    padding: 18px 16px 16px;
  }

  nav {
    padding: 8px 10px;
  }

  section {
    padding: 14px 14px 12px;
  }

  h1 {
    font-size: 1.5rem;
  }
}