/* Atlante del corpo
   Il campo verde è quello dei teli operatori: il rosso degli organi ci risalta sopra
   (è il motivo per cui le sale operatorie sono verdi). La scheda è il telo chiaro. */

@font-face {
  font-family: "Instrument Sans";
  src: url("../fonts/InstrumentSans.woff") format("woff");
  font-weight: 400 700;
  font-stretch: 75% 100%;
  font-display: swap;
}
@font-face {
  font-family: "Instrument Serif";
  src: url("../fonts/InstrumentSerif-Italic.woff") format("woff");
  font-style: italic;
  font-display: swap;
}
@font-face {
  font-family: "Instrument Serif";
  src: url("../fonts/InstrumentSerif-Regular.woff") format("woff");
  font-style: normal;
  font-display: swap;
}

:root {
  --campo: #2b554d;
  --campo-chiaro: #417767;
  --campo-scuro: #183631;
  --telo: #e3ebe6;
  --telo-ombra: #cfdbd4;
  --inchiostro: #12302a;
  --inchiostro-tenue: #4b665f;
  --lampada: #f3d088;
  --lampada-viva: #ffe2a3;
  --su-campo: #e8f1ec;
  --su-campo-tenue: #a9c4ba;
  --sans: "Instrument Sans", "Helvetica Neue", Arial, sans-serif;
  --serif: "Instrument Serif", "Iowan Old Style", Georgia, serif;
  --scheda-larghezza: clamp(320px, 27vw, 420px);
  --indice-larghezza: 210px;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--campo-scuro);
  color: var(--su-campo);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}
button { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--lampada-viva); outline-offset: 3px; }

.atlante {
  height: 100vh;
  height: 100dvh;
  display: grid;
  grid-template-columns: var(--indice-larghezza) 1fr var(--scheda-larghezza);
  grid-template-rows: auto 1fr auto;
  grid-template-areas:
    "testata tavolo scheda"
    "indice  tavolo scheda"
    "piede   tavolo scheda";
  background:
    radial-gradient(ellipse 60% 55% at 52% 46%, var(--campo-chiaro) 0%, var(--campo) 48%, var(--campo-scuro) 100%);
  overflow: hidden;
}

/* --- testata e indice ------------------------------------------------------ */
.testata { grid-area: testata; padding: 28px 22px 10px 28px; position: relative; z-index: 2; }
.testata h1 {
  margin: 0;
  font-family: var(--serif);
  font-weight: 400;
  font-size: 2.35rem;
  line-height: 0.95;
  letter-spacing: -0.01em;
}
.testata p { margin: 10px 0 0; font-size: 0.84rem; color: var(--su-campo-tenue); max-width: 30ch; }

.indice { grid-area: indice; padding: 10px 14px 10px 18px; overflow-y: auto; position: relative; z-index: 2; }
.indice ul { list-style: none; margin: 0; padding: 0; }
.indice li + li { margin-top: 2px; }
.organo-btn {
  display: grid;
  grid-template-columns: 1fr;
  width: 100%;
  text-align: left;
  background: none;
  border: 0;
  border-radius: 10px;
  padding: 5px 10px 6px;
  cursor: pointer;
  color: var(--su-campo);
  transition: background-color 0.18s;
}
.organo-btn .nome { font-size: 1.02rem; font-weight: 550; }
.organo-btn .lat { font-family: var(--serif); font-style: italic; font-size: 0.9rem; color: var(--su-campo-tenue); line-height: 1.1; }
.organo-btn:hover { background: rgb(255 255 255 / 0.07); }
.organo-btn[aria-current="true"] { background: var(--telo); color: var(--inchiostro); }
.organo-btn[aria-current="true"] .lat { color: var(--inchiostro-tenue); }

.piede { grid-area: piede; padding: 10px 22px 22px 28px; font-size: 0.74rem; color: var(--su-campo-tenue); position: relative; z-index: 2; }
.piede p { margin: 0; max-width: 32ch; }

/* --- tavolo con la scena 3D --------------------------------------------------- */
.tavolo { grid-area: tavolo; position: relative; min-height: 0; overflow: hidden; }
#scena { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; cursor: grab; }
#scena:active { cursor: grabbing; }

.latino-grande {
  position: absolute;
  left: 4%;
  bottom: 2%;
  margin: 0;
  font-family: var(--serif);
  font-style: italic;
  font-size: clamp(5rem, 15vw, 15rem);
  line-height: 0.8;
  color: rgb(232 241 236 / 0.085);
  white-space: nowrap;
  pointer-events: none;
  user-select: none;
  letter-spacing: -0.02em;
}

.caricamento {
  position: absolute;
  left: 50%;
  top: 50%;
  translate: -50% -50%;
  font-size: 0.9rem;
  color: var(--su-campo-tenue);
  opacity: 0;
  transition: opacity 0.2s;
  pointer-events: none;
}
.caricamento.attivo { opacity: 1; }

.comandi {
  position: absolute;
  left: 50%;
  bottom: 18px;
  translate: -50% 0;
  display: flex;
  gap: 6px;
  padding: 5px;
  border-radius: 999px;
  background: rgb(16 40 35 / 0.55);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 3;
  max-width: calc(100% - 24px);
  overflow-x: auto;
  scrollbar-width: none;
}
.comandi button {
  border: 0;
  background: none;
  border-radius: 999px;
  padding: 7px 13px;
  font-size: 0.82rem;
  white-space: nowrap;
  cursor: pointer;
  color: var(--su-campo);
}
.comandi button:hover { background: rgb(255 255 255 / 0.08); }
.comandi button[aria-pressed="true"] { background: var(--lampada); color: var(--inchiostro); }
.comandi .breve { display: none; }

/* punti cliccabili proiettati sopra il canvas */
.punti { position: absolute; inset: 0; pointer-events: none; z-index: 2; }
.punto {
  position: absolute;
  left: 0; top: 0;
  width: 28px; height: 28px;
  margin: -14px 0 0 -14px;
  padding: 0;
  border: 0;
  background: none;
  pointer-events: auto;
  cursor: pointer;
  transition: opacity 0.25s;
}
.punto::before {
  content: "";
  position: absolute;
  inset: 7px;
  border-radius: 50%;
  background: rgb(255 248 230 / 0.92);
  box-shadow: 0 0 0 2px rgb(20 48 42 / 0.55), 0 0 0 7px rgb(255 240 200 / 0.18);
  transition: inset 0.2s, background-color 0.2s;
}
.punto:hover::before, .punto:focus-visible::before { inset: 5px; background: var(--lampada-viva); }
.punto.attivo::before { inset: 4px; background: var(--lampada); box-shadow: 0 0 0 2px var(--inchiostro), 0 0 0 9px rgb(243 208 136 / 0.3); }
.punto.dietro { opacity: 0.32; }
.punto.dietro::before { box-shadow: 0 0 0 2px rgb(20 48 42 / 0.3); }
.punto .etichetta {
  position: absolute;
  left: 26px;
  top: 50%;
  translate: 0 -50%;
  white-space: nowrap;
  padding: 3px 9px 4px;
  border-radius: 6px;
  background: var(--telo);
  color: var(--inchiostro);
  font-size: 0.8rem;
  font-weight: 550;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s;
  box-shadow: 0 2px 10px rgb(0 0 0 / 0.18);
}
.punto.sinistra .etichetta { left: auto; right: 26px; }
.punto:hover .etichetta, .punto:focus-visible .etichetta, .punto.attivo .etichetta, .punti.tutti .punto .etichetta { opacity: 1; }
.punti.tutti .punto.dietro .etichetta { opacity: 0; }

/* --- scheda ------------------------------------------------------------------- */
.scheda {
  grid-area: scheda;
  background: var(--telo);
  color: var(--inchiostro);
  overflow-y: auto;
  padding: 34px 32px 40px;
  position: relative;
  z-index: 2;
  box-shadow: -18px 0 40px rgb(0 0 0 / 0.18);
}
.scheda h2 {
  margin: 0;
  font-family: var(--serif);
  font-weight: 400;
  font-size: 3.3rem;
  line-height: 0.95;
  letter-spacing: -0.015em;
}
.s-latino { margin: 6px 0 0; font-family: var(--serif); font-style: italic; font-size: 1.45rem; color: var(--inchiostro-tenue); line-height: 1.1; }
.s-sistema { margin: 14px 0 0; font-size: 0.85rem; color: var(--inchiostro-tenue); }
.s-intro { margin: 18px 0 0; font-size: 1.04rem; line-height: 1.55; }
.s-dati { margin: 22px 0 0; display: grid; gap: 14px; }
.s-dati div { padding-top: 12px; border-top: 1px solid var(--telo-ombra); }
.s-dati dt { font-weight: 650; font-size: 0.86rem; }
.s-dati dd { margin: 3px 0 0; font-size: 0.95rem; line-height: 1.5; color: #24423b; }
.scheda h3 { margin: 30px 0 10px; font-family: var(--serif); font-weight: 400; font-size: 1.7rem; line-height: 1; }

.strutture { list-style: none; margin: 0; padding: 0; }
.strutture li { border-top: 1px solid var(--telo-ombra); }
.strutture li:last-child { border-bottom: 1px solid var(--telo-ombra); }
.struttura-btn {
  display: flex;
  align-items: baseline;
  gap: 10px;
  width: 100%;
  text-align: left;
  border: 0;
  background: none;
  padding: 10px 4px 10px 0;
  cursor: pointer;
  color: var(--inchiostro);
}
.struttura-btn::before {
  content: "";
  flex: none;
  width: 9px; height: 9px;
  border-radius: 50%;
  border: 2px solid var(--inchiostro-tenue);
  translate: 0 -1px;
}
.struttura-btn .nome { font-weight: 600; font-size: 0.96rem; }
.struttura-btn .lat { margin-left: auto; font-family: var(--serif); font-style: italic; color: var(--inchiostro-tenue); font-size: 0.98rem; text-align: right; }
.struttura-btn:hover .nome { text-decoration: underline; text-underline-offset: 3px; }
.struttura-btn[aria-expanded="true"]::before { background: var(--lampada); border-color: var(--inchiostro); }
.struttura-testo { margin: 0 0 14px 19px; font-size: 0.93rem; line-height: 1.55; color: #24423b; }
.struttura-testo[hidden] { display: none; }

.senza-js { position: fixed; inset: auto 0 0; margin: 0; padding: 12px; background: var(--telo); color: var(--inchiostro); text-align: center; }

/* --- schermi medi: indice sopra, in riga ------------------------------------- */
@media (max-width: 1100px) {
  :root { --indice-larghezza: 0px; }
  .atlante {
    grid-template-columns: 1fr var(--scheda-larghezza);
    grid-template-rows: auto auto 1fr auto;
    grid-template-areas: "testata scheda" "indice scheda" "tavolo scheda" "piede scheda";
  }
  .testata { padding: 22px 24px 4px; }
  .testata p { max-width: 60ch; }
  .indice { padding: 8px 16px; overflow-x: auto; overflow-y: hidden; scrollbar-width: none; }
  .indice ul { display: flex; gap: 4px; }
  .indice li + li { margin-top: 0; }
  .organo-btn { white-space: nowrap; padding: 6px 12px 7px; }
  .piede { padding: 4px 24px 14px; }
  .piede p { max-width: none; }
}

/* --- telefono: tutto in colonna, la scheda scorre sotto la scena --------------- */
@media (max-width: 760px) {
  .atlante {
    height: auto;
    min-height: 100dvh;
    overflow: visible;
    display: flex;
    flex-direction: column;
    background: var(--campo);
  }
  .testata { padding: 18px 16px 2px; }
  .testata h1 { font-size: 1.9rem; }
  .testata p { font-size: 0.82rem; margin-top: 8px; }
  .indice { padding: 8px 10px; order: 2; }
  .tavolo {
    order: 3;
    height: 64vh;
    height: 64svh;
    min-height: 360px;
    background: radial-gradient(ellipse 75% 60% at 50% 45%, var(--campo-chiaro) 0%, var(--campo) 55%, var(--campo-scuro) 100%);
  }
  .scheda { order: 4; overflow: visible; padding: 26px 16px 30px; box-shadow: none; }
  .scheda h2 { font-size: 2.6rem; }
  .piede { order: 5; padding: 14px 16px 24px; background: var(--telo); color: var(--inchiostro-tenue); }
  .comandi { bottom: 10px; }
  .comandi button { padding: 7px 12px; font-size: 0.8rem; }
  .comandi .lungo { display: none; }
  .comandi .breve { display: inline; }
  .latino-grande { font-size: 6.5rem; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition-duration: 0.01ms !important; }
}

/* modalità vetrina (?vetrina): solo la scena, per anteprime e incorporamenti minimi */
.vetrina .testata, .vetrina .indice, .vetrina .piede, .vetrina .scheda, .vetrina .comandi, .vetrina .punti { display: none; }
.vetrina .atlante { grid-template-columns: 1fr; grid-template-areas: "tavolo"; grid-template-rows: 1fr; }
