:root {
  /* Editorial "carta calda" */
  --ink: #14110d;
  --paper: #f4ede0;
  --paper-2: #ebe1cf;
  --surface: #f6efe2;        /* superficie chiara per card */
  --surface-2: #efe6d4;      /* hover/superficie più calda */
  --line: #d6c9b3;
  --line-soft: #e0d4bf;

  --text: #14110d;
  --text-dim: #42392c;
  --text-faint: #78716c;

  --accent: #c2410c;         /* arancio bruciato */
  --accent-2: #7c2d12;       /* rust scuro */
  --gold: #a16207;
  --green: #3f6212;          /* oliva */
  --blue: #1d4ed8;

  --ev-forte: #3f6212;
  --ev-moderata: #a16207;
  --ev-debole: #78716c;
  --ev-contesa: #9a3412;
  --ev-nulla: #7c2d12;

  --new: #1d4ed8;
  --radius: 10px;
  --radius-sm: 8px;
  --shadow: rgba(40, 30, 15, 0.16);

  --font-display: "Fraunces", Georgia, "Times New Roman", serif;
  --font-body: "Newsreader", Georgia, serif;
  --font-mono: "Spline Sans Mono", ui-monospace, "SFMono-Regular", monospace;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  background: var(--paper);
  background-image:
    radial-gradient(circle at 12% 14%, rgba(193, 65, 12, 0.05), transparent 45%),
    radial-gradient(circle at 88% 86%, rgba(161, 98, 7, 0.06), transparent 40%);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 18px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

.wrap { max-width: 1060px; margin: 0 auto; padding: 0 20px; }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0;
}

/* Header */
.site-header { padding: 48px 0 26px; border-bottom: 3px solid var(--ink); margin-bottom: 14px; }
.site-header .wrap { border: 0; }
.site-header h1 {
  margin: 0 0 12px;
  font-family: var(--font-display);
  font-size: clamp(2rem, 5vw, 3.4rem);
  font-weight: 600;
  line-height: 0.98;
  letter-spacing: -0.02em;
  color: var(--ink);
}
.site-header .sub {
  margin: 0 0 14px;
  font-family: var(--font-body);
  font-style: italic;
  color: #3d362b;
  font-size: clamp(1.05rem, 2.2vw, 1.25rem);
  max-width: 66ch;
}
.site-header .nota {
  margin: 0;
  background: var(--paper-2);
  border-left: 4px solid var(--gold);
  padding: 14px 18px;
  font-family: var(--font-mono);
  font-size: 0.78rem;
  line-height: 1.6;
  letter-spacing: 0.01em;
  color: var(--text-dim);
  max-width: 94ch;
}

/* Chart */
.chart-section { padding: 6px 0 8px; }
.chart-section details {
  background: var(--paper-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 18px;
}
.chart-section summary {
  cursor: pointer;
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: 0.8rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--accent-2);
  list-style: none;
  user-select: none;
}
.chart-section summary::-webkit-details-marker { display: none; }
.chart-section summary::before { content: "▸ "; color: var(--accent); }
.chart-section details[open] summary::before { content: "▾ "; }
.chart { margin-top: 14px; display: grid; gap: 7px; }
.chart-row { display: grid; grid-template-columns: 200px 1fr 56px; align-items: center; gap: 10px; font-family: var(--font-mono); font-size: 0.74rem; }
.chart-row .cr-label { color: var(--text-dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chart-row .cr-bar { height: 13px; background: var(--line-soft); border-radius: 6px; overflow: hidden; }
.chart-row .cr-fill { display: block; height: 100%; border-radius: 6px; background: linear-gradient(90deg, #3f6212, #84cc16); }
.chart-row .cr-val { text-align: right; color: var(--text-faint); font-variant-numeric: tabular-nums; }

/* Switch tipo di grafico (Barre / Torta) */
.chart-toolbar { margin-top: 14px; display: flex; }
.chart-toggle { display: inline-flex; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 2px; }
.ct-btn {
  border: 0; background: transparent; color: var(--text-faint);
  padding: 4px 14px; border-radius: 6px; cursor: pointer;
  font-family: var(--font-mono); font-size: 0.72rem; font-weight: 600; letter-spacing: 0.04em;
}
.ct-btn.is-active { background: var(--accent); color: #fff; }

/* Grafico a torta (ciambella) + legenda */
.pie-wrap { margin-top: 18px; display: grid; grid-template-columns: 300px 1fr; gap: 26px; align-items: center; }
.pie-figure { position: relative; width: 300px; max-width: 100%; aspect-ratio: 1; justify-self: center; }
.pie-svg { width: 100%; height: 100%; display: block; }
.pie-slice { stroke: var(--paper-2); stroke-width: 1.5; cursor: pointer; transition: opacity 0.15s ease, transform 0.18s ease, filter 0.15s ease, stroke-width 0.15s ease; }
.pie-slice.is-hi { stroke: var(--paper); stroke-width: 3; filter: drop-shadow(0 5px 9px rgba(40, 30, 15, 0.45)); }
.pie-center {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center; text-align: center;
  padding: 0 24%; pointer-events: none;
}
.pc-val { font-family: var(--font-display); font-weight: 700; font-size: 1.7rem; line-height: 1.05; color: var(--ink); font-variant-numeric: tabular-nums; }
.pc-lab { font-family: var(--font-mono); font-size: 0.6rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-faint); margin-top: 7px; line-height: 1.35; }
.pie-legend { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 3px 18px; align-content: center; }
.pie-leg {
  display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 8px;
  border: 0; background: transparent; text-align: left; cursor: pointer;
  padding: 3px 7px; border-radius: 6px;
  font-family: var(--font-mono); font-size: 0.7rem; color: var(--text-dim);
}
.pie-leg:hover { background: var(--surface-2); }
.pie-leg.is-hi { background: var(--ink); box-shadow: 0 2px 8px var(--shadow); }
.pie-leg.is-hi .pl-name { color: var(--paper); font-weight: 700; }
.pie-leg.is-hi .pl-val { color: var(--paper-2); }
.pie-leg.is-hi .pl-dot { box-shadow: 0 0 0 2px var(--paper); }
.pl-dot { width: 11px; height: 11px; border-radius: 3px; flex: none; }
.pl-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pl-val { color: var(--text-faint); font-variant-numeric: tabular-nums; }

/* Controls */
.controls {
  position: sticky; top: 0; z-index: 20;
  background: rgba(244, 237, 224, 0.9);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
  margin-top: 16px;
}
.controls-inner { padding: 8px 20px; display: grid; gap: 6px; }
.control-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

.view-toggle { display: inline-flex; background: var(--paper-2); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 2px; }
.vt-btn {
  border: 0; background: transparent; color: var(--text-faint);
  padding: 4px 12px; border-radius: 6px; cursor: pointer;
  font-family: var(--font-mono); font-size: 0.74rem; font-weight: 600;
  letter-spacing: 0.04em;
}
.vt-btn.is-active { background: var(--accent); color: #fff; }

.search {
  flex: 1 1 220px; min-width: 160px;
  background: var(--paper-2); border: 1px solid var(--line); color: var(--text);
  border-radius: var(--radius-sm); padding: 7px 12px;
  font-family: var(--font-body); font-size: 0.95rem;
}
.search::placeholder { color: var(--text-faint); }
.search:focus { outline: none; border-color: var(--accent); }

.sort { display: inline-flex; gap: 5px; }
.sort select {
  background: var(--paper-2); border: 1px solid var(--line); color: var(--text);
  border-radius: var(--radius-sm); padding: 6px 9px;
  font-family: var(--font-mono); font-size: 0.74rem; cursor: pointer;
}
.dir-btn {
  width: 32px; background: var(--paper-2); border: 1px solid var(--line); color: var(--text);
  border-radius: var(--radius-sm); cursor: pointer; font-size: 0.92rem;
}
.dir-btn:hover, .sort select:hover { border-color: var(--accent); }

.filters { gap: 12px; }
.filter-group { display: inline-flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.fg-label { font-family: var(--font-mono); font-size: 0.62rem; text-transform: uppercase; letter-spacing: 0.1em; color: var(--text-faint); }
.pill {
  border: 1px solid var(--line); background: var(--paper-2); color: var(--text-dim);
  padding: 4px 10px; border-radius: 999px; cursor: pointer;
  font-family: var(--font-mono); font-size: 0.68rem; letter-spacing: 0.02em;
}
.pill.is-on { background: var(--paper); color: var(--ink); border-color: var(--accent); }
.pill .dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; vertical-align: middle; }

.flags { gap: 12px; margin-left: auto; }
.chk { display: inline-flex; align-items: center; gap: 5px; font-family: var(--font-mono); font-size: 0.7rem; color: var(--text-dim); cursor: pointer; }
.chk input { accent-color: var(--accent); }
.reset-btn {
  border: 1px solid var(--line); background: transparent; color: var(--text-faint);
  padding: 4px 11px; border-radius: var(--radius-sm); cursor: pointer;
  font-family: var(--font-mono); font-size: 0.7rem; letter-spacing: 0.03em;
}
.reset-btn:hover { color: var(--accent); border-color: var(--accent); }

.count { font-family: var(--font-mono); font-size: 0.68rem; color: var(--text-faint); white-space: nowrap; }

/* Results */
main.wrap { padding: 38px 20px 64px; }
.empty { text-align: center; color: var(--text-faint); font-style: italic; padding: 50px 0; }

/* Flat list rows */
.row {
  display: grid;
  grid-template-columns: 34px 1fr auto;
  gap: 12px;
  align-items: start;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: linear-gradient(180deg, #fbf6ec, #f1e8d8);
  margin-bottom: 12px;
  cursor: pointer;
  box-shadow: 0 1px 0 var(--shadow);
  transition: transform 0.18s ease, box-shadow 0.18s ease, border-color 0.18s ease;
}
.row:hover { transform: translateY(-2px); box-shadow: 0 10px 28px var(--shadow); border-color: var(--accent); }
.row .rank { font-family: var(--font-display); font-weight: 600; color: var(--accent-2); font-variant-numeric: tabular-nums; font-size: 1.25rem; padding-top: 1px; }
.row .main { min-width: 0; }
.row .name { font-family: var(--font-display); font-weight: 600; font-size: 1.18rem; letter-spacing: -0.01em; }
.row .badges { display: inline-flex; gap: 6px; margin-left: 8px; vertical-align: middle; }
.row .es { font-family: var(--font-mono); color: var(--text-faint); font-size: 0.74rem; margin-top: 4px; }
.row .desc { color: var(--text-dim); font-size: 0.92rem; margin-top: 8px; display: none; max-width: 66ch; }
.row.open .desc { display: block; }
.row .right { text-align: right; white-space: nowrap; }
.row .imp-num { font-family: var(--font-display); font-weight: 700; font-size: 1.2rem; font-variant-numeric: tabular-nums; color: var(--ink); }
.row .var-num { font-family: var(--font-mono); font-size: 0.7rem; color: var(--text-faint); }
.row .impbar { width: 90px; height: 8px; background: var(--line-soft); border-radius: 5px; overflow: hidden; margin: 6px 0 0 auto; }
.row .impbar > span { display: block; height: 100%; border-radius: 5px; background: linear-gradient(90deg, #3f6212, #84cc16); }

/* Block cards */
.block {
  border: 1.5px solid var(--ink);
  border-radius: var(--radius);
  background: linear-gradient(180deg, #fbf6ec, #f1e8d8);
  margin-bottom: 14px;
  overflow: hidden;
  box-shadow: 0 1px 0 var(--shadow);
}
.block > .block-head {
  display: grid; grid-template-columns: 1fr auto; gap: 12px; align-items: center;
  padding: 16px 18px; cursor: pointer; user-select: none;
}
.block > .block-head:hover { background: var(--surface-2); }
.block-head .bh-title { font-family: var(--font-display); font-weight: 600; font-size: 1.28rem; letter-spacing: -0.01em; }
.block-head .bh-cat { font-family: var(--font-mono); font-size: 0.66rem; color: var(--text-faint); text-transform: uppercase; letter-spacing: 0.1em; margin-left: 8px; }
.block-head .bh-note { color: var(--text-dim); font-size: 0.9rem; margin-top: 6px; max-width: 70ch; }
.block-head .bh-right { text-align: right; }
.block-head .bh-imp { font-family: var(--font-display); font-weight: 800; font-size: 1.4rem; font-variant-numeric: tabular-nums; color: var(--ink); }
.block-head .bh-var { font-family: var(--font-mono); font-size: 0.7rem; color: var(--text-faint); }
.block-head .caret { color: var(--accent); margin-right: 6px; }

.subleve { border-top: 1px solid var(--line); padding: 6px 12px 12px; display: none; }
.block.open .subleve { display: block; }
.sub {
  display: grid; grid-template-columns: auto 1fr auto; gap: 10px; align-items: start;
  padding: 12px 8px 12px 14px; border-bottom: 1px dashed var(--line);
  border-left: 3px solid var(--accent);
}
.sub:last-child { border-bottom: 0; }
.sub .sid { font-family: var(--font-mono); color: var(--text-faint); font-size: 0.72rem; font-variant-numeric: tabular-nums; padding-top: 4px; }
.sub .sname { font-family: var(--font-display); font-weight: 600; font-size: 1.02rem; }
.sub .ses { font-family: var(--font-mono); color: var(--text-faint); font-size: 0.72rem; margin-top: 3px; }
.sub .sdesc { color: var(--text-dim); font-size: 0.88rem; margin-top: 6px; max-width: 62ch; }
.sub .sright { text-align: right; white-space: nowrap; }
.sub .imp-num { font-family: var(--font-display); font-weight: 700; font-variant-numeric: tabular-nums; font-size: 1.02rem; color: var(--ink); }
.sub .var-num { font-family: var(--font-mono); font-size: 0.68rem; color: var(--text-faint); }

/* Single (leaf) card in block view */
.leaf {
  border: 1px solid var(--line); border-radius: var(--radius);
  background: linear-gradient(180deg, #fbf6ec, #f1e8d8); margin-bottom: 14px; padding: 16px 18px;
  display: grid; grid-template-columns: 1fr auto; gap: 12px; align-items: start;
  box-shadow: 0 1px 0 var(--shadow);
}
.leaf .lf-title { font-family: var(--font-display); font-weight: 600; font-size: 1.2rem; letter-spacing: -0.01em; }
.leaf .lf-cat { font-family: var(--font-mono); font-size: 0.66rem; color: var(--text-faint); text-transform: uppercase; letter-spacing: 0.1em; margin-left: 8px; }
.leaf .lf-es { font-family: var(--font-mono); color: var(--text-faint); font-size: 0.74rem; margin-top: 4px; }
.leaf .lf-desc { color: var(--text-dim); font-size: 0.92rem; margin-top: 8px; max-width: 75ch; }
.leaf .lf-right { text-align: right; }
.leaf .lf-imp { font-family: var(--font-display); font-weight: 800; font-size: 1.3rem; font-variant-numeric: tabular-nums; color: var(--ink); }
.leaf .lf-var { font-family: var(--font-mono); font-size: 0.7rem; color: var(--text-faint); }

/* Badges — tag squadrati mono */
.badge {
  display: inline-block; padding: 3px 8px; border-radius: 4px;
  font-family: var(--font-mono); font-size: 0.6rem; font-weight: 600;
  letter-spacing: 0.07em; line-height: 1.5;
  text-transform: uppercase; white-space: nowrap;
}
.badge.ev { color: #fff; }
.badge.ev-forte { background: var(--ev-forte); }
.badge.ev-moderata { background: var(--ev-moderata); }
.badge.ev-debole { background: var(--ev-debole); }
.badge.ev-contesa { background: var(--ev-contesa); }
.badge.ev-nulla { background: var(--ev-nulla); }
.badge.new { background: var(--blue); color: #fff; }
.badge.contesa { background: transparent; color: var(--accent-2); border: 1px solid var(--accent-2); }
/* Robustezza — outline colorato (forma diversa dai badge evidenza, che sono pieni) */
.badge.rb { background: transparent; border: 1px solid currentColor; }
.badge.rb-meta { color: var(--ev-forte); }
.badge.rb-cont { color: var(--gold); }
.badge.rb-proxy { color: var(--text-faint); }
/* Proxy — tag sobrio tratteggiato */
.badge.proxy { background: transparent; color: var(--text-faint); border: 1px dashed var(--text-faint); }

/* Nota sotto al grafico: fattori fuori dalla ripartizione di varianza */
.chart-note { margin: 12px 0 0; font-family: var(--font-mono); font-size: 0.68rem; color: var(--text-faint); font-style: normal; }

/* Footer */
.site-footer { border-top: 3px solid var(--ink); padding: 24px 0; color: var(--text-faint); font-size: 0.88rem; line-height: 1.6; }
.site-footer code { font-family: var(--font-mono); background: var(--paper-2); padding: 2px 6px; border-radius: 5px; color: var(--ink); font-size: 0.82rem; }

@media (max-width: 720px) {
  .chart-row { grid-template-columns: 120px 1fr 44px; }
  .pie-wrap { grid-template-columns: 1fr; gap: 18px; }
  .row { grid-template-columns: 26px 1fr; }
  .row .right { grid-column: 2; text-align: left; display: flex; gap: 12px; align-items: center; }
  .row .impbar { margin: 0; }
  .leaf, .block-head { grid-template-columns: 1fr; }
  .leaf .lf-right, .block-head .bh-right { text-align: left; }
  .flags { margin-left: 0; }
}
