/* Laboratorio Opus — un unico mondo scuro, pensato per i canvas. */
:root {
  color-scheme: dark;
  --ink: #0b0c11;
  --ink-2: #111319;
  --ink-3: #181b24;
  --ink-4: #242836;
  --line: #22262f;
  --text: #e9ebf2;
  --text-2: #b7bbc9;
  --muted: #7f8599;
  --accent: #7cc8ff;
  --on-accent: #0b0c11;

  --display: "Bricolage Grotesque", "Segoe UI Variable Display", "Segoe UI", system-ui, sans-serif;
  --mono: "JetBrains Mono", "Cascadia Mono", Consolas, ui-monospace, monospace;
  --math: "STIX Two Text", "Cambria Math", Cambria, "Times New Roman", serif;

  --panel-w: 380px;
  --bar-h: 58px;
  --r: 10px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--ink);
  color: var(--text);
  font: 400 15px/1.5 var(--display);
  -webkit-font-smoothing: antialiased;
}
button, input, select { font: inherit; color: inherit; }
[hidden] { display: none !important; }

/* ---------- struttura ---------- */
.app {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto minmax(0, 1fr);
  height: 100%;
}
.main {
  display: grid;
  grid-template-columns: minmax(0, 1fr) var(--panel-w);
  min-height: 0;
}

/* ---------- barra superiore ---------- */
.bar {
  display: flex;
  align-items: center;
  gap: 28px;
  height: var(--bar-h);
  padding: 0 20px;
  border-bottom: 1px solid var(--line);
  background: var(--ink);
  position: relative;
  z-index: 2;
}
.brand { display: flex; align-items: baseline; gap: 10px; white-space: nowrap; }
.brand-name {
  font-weight: 650;
  font-size: 19px;
  letter-spacing: -0.015em;
  font-variation-settings: "opsz" 48;
}
.brand-sub {
  font: 500 10.5px/1 var(--mono);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}
.tabs { display: flex; align-self: stretch; gap: 2px; }
.tab {
  position: relative;
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 0 14px;
  border: 0;
  background: none;
  color: var(--muted);
  font-size: 14.5px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: color .15s;
}
.tab:hover { color: var(--text-2); }
.tab[aria-selected="true"] { color: var(--text); }
.tab::after {
  content: "";
  position: absolute;
  left: 14px; right: 14px; bottom: -1px;
  height: 2px;
  border-radius: 2px;
  background: var(--tab-accent);
  transform: scaleX(0);
  transition: transform .25s ease;
}
.tab[aria-selected="true"]::after { transform: scaleX(1); }
.tab .dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--tab-accent);
  opacity: .35;
  transition: opacity .2s;
}
.tab[aria-selected="true"] .dot, .tab:hover .dot { opacity: 1; }
.bar-actions { margin-left: auto; display: flex; gap: 8px; }

/* ---------- palcoscenico ---------- */
.stage {
  position: relative;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  background: #07080c;
}
.stage-canvas { position: absolute; inset: 0; }
.stage-canvas canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}
.stage-overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  pointer-events: none;
}
.stage-overlay > * { pointer-events: auto; }
.hint {
  position: absolute;
  left: 16px;
  bottom: 16px;
  margin: 0;
  max-width: calc(100% - 32px);
  padding: 7px 12px;
  border-radius: 999px;
  background: rgba(11, 12, 17, .66);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  font: 500 12px/1.4 var(--mono);
  color: var(--text-2);
  pointer-events: none;
}
.toast {
  position: absolute;
  top: 16px;
  left: 50%;
  max-width: calc(100% - 32px);
  padding: 10px 16px;
  border-radius: 999px;
  background: var(--text);
  color: var(--ink);
  font-size: 14px;
  font-weight: 550;
  opacity: 0;
  transform: translate(-50%, -10px);
  transition: opacity .3s, transform .3s;
  pointer-events: none;
  text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.fail {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  gap: 6px;
  padding: 24px;
  text-align: center;
  color: var(--text-2);
}
.fail-title { margin: 0; font-size: 20px; font-weight: 600; color: var(--text); }
.fail p { margin: 0; }
.present-exit { position: absolute; right: 16px; bottom: 16px; display: none; }

/* Avviso mentre lo shader di un organo si compila */
.organ-loading {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  font: 500 13px/1.4 var(--mono);
  color: var(--text-2);
  pointer-events: none;
}
.organ-spinner {
  width: 18px; height: 18px;
  border-radius: 50%;
  border: 2px solid var(--ink-4);
  border-top-color: var(--accent);
  animation: organ-spin .9s linear infinite;
}
@keyframes organ-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .organ-spinner { animation: none; } }

/* Etichette anatomiche agganciate ai punti 3D */
.organ-labels { position: absolute; inset: 0; overflow: hidden; pointer-events: none; }
.olabel { position: absolute; left: 0; top: 0; width: 0; height: 0; will-change: transform; }
.olabel-dot {
  position: absolute;
  left: -4px; top: -4px;
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 2px rgba(11, 12, 17, .75);
}
.olabel-text {
  position: absolute;
  left: 12px; top: 0;
  transform: translateY(calc(-50% + var(--dy, 0px)));
  padding: 3px 8px;
  border-radius: 6px;
  background: rgba(11, 12, 17, .72);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  font: 500 11.5px/1.3 var(--mono);
  color: var(--text);
  white-space: nowrap;
}
.olabel.flip .olabel-text { left: auto; right: 12px; }

/* ---------- pannello ---------- */
.panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow-y: auto;
  background: var(--ink-2);
  border-left: 1px solid var(--line);
  scrollbar-width: thin;
  scrollbar-color: var(--ink-4) transparent;
}
.panel-head {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 12px;
  padding: 26px 24px 22px;
  border-bottom: 1px solid var(--line);
}
.kicker {
  margin: 0;
  font: 500 11px/1.4 var(--mono);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent);
}
.title {
  margin: 0;
  font-size: 60px;
  line-height: .95;
  font-weight: 650;
  font-variation-settings: "opsz" 96;
  letter-spacing: -0.035em;
  text-wrap: balance;
}
.tagline {
  margin: 0;
  color: var(--text-2);
  font-size: 15px;
  line-height: 1.55;
  text-wrap: pretty;
}
.formula {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 8px;
  margin-top: 4px;
  padding: 13px 15px 12px;
  border-radius: var(--r);
  background: var(--ink-3);
}
.formula-label {
  font: 500 10px/1 var(--mono);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}
.formula-body {
  display: grid;
  gap: 4px;
  font: italic 400 17.5px/1.45 var(--math);
  color: var(--text);
  overflow-x: auto;
}
.formula-body > div { text-wrap: balance; }
.formula-body .up { font-style: normal; }
.formula-body sub, .formula-body sup { font-size: .68em; line-height: 0; }

.sec {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 16px;
  padding: 20px 24px 22px;
  border-bottom: 1px solid var(--line);
}
.sec-title {
  margin: 0;
  font: 500 10.5px/1 var(--mono);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}

/* ---------- controlli ---------- */
.controls { display: grid; gap: 18px; }
.ctl { display: grid; gap: 8px; }
.ctl-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
.ctl-head label, .ctl-label { font-size: 14px; color: var(--text-2); }
.ctl-val {
  font: 500 12px/1 var(--mono);
  color: var(--text);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

input[type="range"] {
  --p: 50%;
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 20px;
  margin: 0;
  background: transparent;
  cursor: pointer;
}
input[type="range"]::-webkit-slider-runnable-track {
  height: 4px;
  border-radius: 2px;
  background: linear-gradient(to right, var(--accent) var(--p), var(--ink-4) var(--p));
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px; height: 16px;
  margin-top: -6px;
  border-radius: 50%;
  background: var(--text);
  border: 3px solid var(--ink-2);
  box-shadow: 0 0 0 1px var(--accent);
  transition: box-shadow .15s;
}
input[type="range"]::-moz-range-track { height: 4px; border-radius: 2px; background: var(--ink-4); }
input[type="range"]::-moz-range-progress { height: 4px; border-radius: 2px; background: var(--accent); }
input[type="range"]::-moz-range-thumb {
  width: 16px; height: 16px;
  border-radius: 50%;
  background: var(--text);
  border: 3px solid var(--ink-2);
  box-shadow: 0 0 0 1px var(--accent);
}
input[type="range"]:focus { outline: none; }
input[type="range"]:focus-visible::-webkit-slider-thumb { box-shadow: 0 0 0 3px var(--accent); }
input[type="range"]:focus-visible::-moz-range-thumb { box-shadow: 0 0 0 3px var(--accent); }

.seg { display: flex; gap: 2px; padding: 3px; border-radius: 9px; background: var(--ink-3); }
.seg button {
  flex: 1;
  padding: 7px 0;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--muted);
  font: 500 12.5px/1 var(--mono);
  cursor: pointer;
  transition: color .15s, background .15s;
}
.seg button:hover { color: var(--text-2); }
.seg button[aria-checked="true"] {
  background: var(--ink-4);
  color: var(--text);
  box-shadow: inset 0 0 0 1px color-mix(in oklab, var(--accent) 55%, transparent);
}

.select {
  width: 100%;
  appearance: none;
  -webkit-appearance: none;
  padding: 9px 34px 9px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--ink-3) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M1 1l4 4 4-4' fill='none' stroke='%23b7bbc9' stroke-width='1.5'/%3E%3C/svg%3E") no-repeat right 12px center;
  font-size: 14px;
  cursor: pointer;
}
.select option { background: var(--ink-3); }

.switch { position: relative; display: flex; align-items: center; justify-content: space-between; gap: 12px; cursor: pointer; }
.switch-label { font-size: 14px; color: var(--text-2); }
.switch-input { position: absolute; right: 0; top: 50%; opacity: 0; width: 1px; height: 1px; margin: 0; }
.switch-track {
  position: relative;
  flex: none;
  width: 34px; height: 20px;
  border-radius: 999px;
  background: var(--ink-4);
  transition: background .2s;
}
.switch-track::after {
  content: "";
  position: absolute;
  top: 3px; left: 3px;
  width: 14px; height: 14px;
  border-radius: 50%;
  background: var(--text-2);
  transition: transform .2s, background .2s;
}
.switch-input:checked + .switch-track { background: var(--accent); }
.switch-input:checked + .switch-track::after { transform: translateX(14px); background: var(--on-accent); }
.switch-input:focus-visible + .switch-track { outline: 2px solid var(--accent); outline-offset: 2px; }

.actions { display: flex; flex-wrap: wrap; gap: 8px; }
.btn {
  padding: 8px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--ink-3);
  color: var(--text);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: border-color .15s, background .15s, transform .1s;
}
.btn:hover { border-color: var(--muted); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); font-weight: 600; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; color: var(--text-2); }
.btn.ghost:hover { color: var(--text); }
.btn.icon { display: grid; place-items: center; padding: 8px 9px; }
.btn.big { padding: 14px 24px; font-size: 16px; border-radius: 999px; }
.btn:focus-visible, .tab:focus-visible, .seg button:focus-visible, .select:focus-visible, .how summary:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ---------- statistiche ---------- */
.stats {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px 18px;
  margin: 0;
}
.stat { display: grid; gap: 4px; min-width: 0; }
.stat dt {
  font: 500 10px/1.2 var(--mono);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
}
.stat dd {
  margin: 0;
  font: 500 15px/1.3 var(--mono);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.extras { display: grid; gap: 18px; }
.extras:empty { display: none; }
.figure { display: grid; gap: 8px; margin: 0; }
.figure-label {
  font: 500 10px/1.2 var(--mono);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
}
.figure canvas { display: block; width: 100%; border-radius: 8px; background: var(--ink); }

/* ---------- come funziona ---------- */
.how summary {
  display: flex;
  justify-content: space-between;
  align-items: center;
  list-style: none;
  cursor: pointer;
  font-size: 15px;
  font-weight: 550;
}
.how summary::-webkit-details-marker { display: none; }
.how-sign { position: relative; width: 12px; height: 12px; }
.how-sign::before, .how-sign::after {
  content: "";
  position: absolute;
  left: 0; top: 5px;
  width: 12px; height: 2px;
  border-radius: 1px;
  background: var(--accent);
  transition: transform .2s;
}
.how-sign::after { transform: rotate(90deg); }
.how[open] .how-sign::after { transform: rotate(0); }
.how:not([open]) { gap: 0; }
.how-body { color: var(--text-2); font-size: 14.5px; line-height: 1.6; }
.how-body p { margin: 0 0 12px; }
.how-body ol { margin: 0; padding-left: 1.25em; display: grid; gap: 10px; }
.how-body li::marker { color: var(--accent); font: 500 12px var(--mono); }
.how-body strong { color: var(--text); font-weight: 600; }
.how-body em { font-family: var(--math); font-size: 1.08em; }

.colophon {
  margin-top: auto;
  padding: 18px 24px 22px;
  font: 400 11.5px/1.7 var(--mono);
  color: var(--muted);
}
.colophon strong { color: var(--text-2); font-weight: 500; }

/* ---------- modalità presentazione ---------- */
body.present .app { grid-template-rows: minmax(0, 1fr); }
body.present .bar, body.present .panel { display: none; }
body.present .main { grid-template-columns: minmax(0, 1fr); }
body.present .present-exit { display: block; opacity: .0; transition: opacity .3s; }
body.present .stage:hover .present-exit { opacity: .9; }

/* ---------- schermi stretti ---------- */
@media (max-width: 880px) {
  .app { height: auto; min-height: 100%; }
  .bar { flex-wrap: wrap; height: auto; gap: 6px 16px; padding: 10px 16px 0; }
  .brand { min-width: 0; }
  .tabs { order: 3; width: 100%; height: 44px; overflow-x: auto; scrollbar-width: none; }
  .tab { padding: 0 10px; }
  .tab::after { left: 10px; right: 10px; }
  #btn-present { display: none; }
  .main { grid-template-columns: minmax(0, 1fr); }
  .stage { height: 62svh; min-height: 340px; }
  .panel { overflow: visible; border-left: 0; border-top: 1px solid var(--line); }
  .panel-head, .sec, .colophon { padding-left: 16px; padding-right: 16px; }
  .title { font-size: 48px; }
  body.present .stage { height: 100svh; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: 0s !important; }
}
