  :root {
    --bg: #05070b;
    --fg: #eef1f6;
    --muted: #8a93a6;
    --accent: #9fb8ff;
    --panel: rgba(10, 13, 20, 0.84);
    --line: rgba(159, 184, 255, 0.22);
    --warm: #ffd38a;
    --ink: #ece4d6;
    --display: "Space Grotesk", "Inter Tight", "Helvetica Neue", Arial, sans-serif;
    box-sizing: border-box;
    padding-top: env(safe-area-inset-top, 0px);
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }
  @media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
      --bg: #05070b; --fg: #eef1f6; --muted: #8a93a6; --accent: #9fb8ff;
      --panel: rgba(10, 13, 20, 0.84); --line: rgba(159, 184, 255, 0.22); --warm: #ffd38a;
    }
  }
  :root[data-theme="dark"] {
    --bg: #05070b; --fg: #eef1f6; --muted: #8a93a6; --accent: #9fb8ff;
    --panel: rgba(10, 13, 20, 0.84); --line: rgba(159, 184, 255, 0.22); --warm: #ffd38a;
  }
  *, *::before, *::after { box-sizing: inherit; }
  html { height: 100%; scroll-padding-top: env(safe-area-inset-top, 0px); }
  body {
    margin: 0; height: 100%; overflow: hidden;
    background: var(--bg); color: var(--fg);
    font-family: "Inter Tight", "Helvetica Neue", Helvetica, Arial, sans-serif;
    -webkit-font-smoothing: antialiased;
  }
  button { font: inherit; color: inherit; }
  :focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; border-radius: 6px; }

  #scene { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }

  /* Header: logo, menu in maiuscolo distribuito sulla larghezza, pill a destra */
  .site-header {
    position: fixed; top: 0; left: 0; right: 0; z-index: 20;
    display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: clamp(20px, 4vw, 64px);
    padding: calc(26px + env(safe-area-inset-top, 0px)) clamp(18px, 3vw, 56px) 20px;
    pointer-events: none;
    transition: opacity .6s ease;
  }
  .site-header > * { pointer-events: auto; }
  .logo {
    background: none; border: 0; padding: 0; cursor: pointer;
    font-family: var(--display); font-size: clamp(1.6rem, 2.3vw, 2.2rem); line-height: 1;
    letter-spacing: 0.01em; text-transform: uppercase; color: var(--ink); white-space: nowrap;
  }
  .nav { display: flex; justify-content: space-between; align-items: center; max-width: 980px; width: 100%; justify-self: center; }
  .nav a {
    position: relative; color: var(--ink); text-decoration: none;
    font-size: 0.92rem; font-weight: 400; letter-spacing: 0.02em; text-transform: uppercase;
    opacity: .82; transition: opacity .3s;
  }
  .nav a::after {
    content: ""; position: absolute; left: 0; bottom: -6px; height: 1px; width: 0;
    background: currentColor; transition: width .35s ease;
  }
  .nav a:hover { opacity: 1; }
  .nav a:hover::after, .nav a.current::after { width: 1.4em; }
  .pill-light {
    white-space: nowrap; cursor: pointer;
    background: var(--ink); color: #0b0d12; border: 1px solid var(--ink); border-radius: 999px;
    padding: 7px 18px; font-size: 0.92rem; letter-spacing: 0.02em; text-transform: uppercase;
    transition: background .3s, color .3s;
  }
  .pill-light:hover { background: transparent; color: var(--ink); }
  .btn {
    white-space: nowrap;
    background: rgba(5,7,11,.35); border: 1px solid var(--line); border-radius: 999px;
    padding: 8px 16px; cursor: pointer; font-size: 0.85rem; letter-spacing: 0.04em; text-transform: uppercase;
    transition: border-color .3s, background .3s;
  }
  .btn:hover { border-color: var(--accent); background: rgba(159,184,255,.1); }

  /* Titolo centrale: riga in sans leggero maiuscolo + riga nel font display */
  .hero-title {
    position: fixed; z-index: 10; left: 50%; top: 50%;
    transform: translate(-50%, -46%);
    width: min(1400px, calc(100% - 32px));
    text-align: center; color: var(--ink); pointer-events: none;
    text-shadow: 0 2px 40px rgba(0,0,0,.45);
    transition: opacity .7s ease, transform .9s cubic-bezier(.2,.7,.2,1);
  }
  /* Nelle stanze il titolo passa sopra schermi luminosi: un velo scuro sfumato lo tiene leggibile */
  .hero-title::before {
    content: ""; position: absolute; left: 50%; top: 50%; z-index: -1;
    width: 120%; height: 150%; transform: translate(-50%, -50%);
    background: radial-gradient(closest-side, rgba(5,7,11,.55), rgba(5,7,11,0));
    opacity: 0; transition: opacity .8s ease;
  }
  body:not(.is-home) .hero-title::before { opacity: 1; }
  .hero-title .kicker {
    display: block; margin-bottom: clamp(10px, 2vh, 22px);
    font-family: var(--display); font-size: clamp(1rem, 1.6vw, 1.5rem); letter-spacing: 0.02em; text-transform: uppercase;
    opacity: .8;
  }
  .hero-title .kicker[hidden] { display: none; }
  .hero-title h1 { margin: 0; font-weight: 400; }
  .hero-title .l1 {
    display: block; font-family: "Inter Tight", "Helvetica Neue", Arial, sans-serif; font-weight: 300;
    font-size: clamp(2.6rem, 7.2vw, 8rem); line-height: 0.95; letter-spacing: -0.01em; text-transform: uppercase;
  }
  .hero-title .l2 {
    display: block; font-family: var(--display); font-weight: 500;
    font-size: clamp(2.6rem, 7.2vw, 8rem); line-height: 0.95; letter-spacing: -0.02em; text-transform: uppercase;
  }
  .hero-title .actions { display: flex; flex-direction: column; align-items: center; gap: 14px; margin-top: clamp(18px, 4vh, 44px); }
  .hero-title .actions[hidden] { display: none; }
  .hero-title .actions button, .hero-title .actions a { pointer-events: auto; }
  .hero-title .actions-row { display: flex; flex-wrap: wrap; justify-content: center; gap: 12px; }
  a.pill-light, a.btn { display: inline-flex; align-items: center; text-decoration: none; }
  a.btn:not(.btn-accent) { color: inherit; }
  .pill-light.pill-big { padding: 12px 34px; font-size: 0.95rem; }
  .pill-light[hidden] { display: none; }
  .panel-buttons { display: flex; gap: 10px; flex-shrink: 0; }
  .btn-accent { background: var(--accent); border-color: var(--accent); color: #0b0d12; }
  .btn-accent:hover { background: #c3d2ff; border-color: #c3d2ff; }
  .text-link {
    background: none; border: 0; cursor: pointer; color: var(--ink); opacity: .75;
    font-family: var(--display); font-size: 1.05rem; letter-spacing: 0.02em; text-transform: uppercase;
  }
  .text-link:hover { opacity: 1; }
  body.moving .hero-title, body.panel-open .hero-title { opacity: 0; transform: translate(-50%, -42%); }
  body.moving .hero-title *, body.panel-open .hero-title * { pointer-events: none !important; }

  /* Pulsanti pieni nel colore d'accento */
  .pill-accent {
    display: inline-flex; align-items: center; gap: 14px; cursor: pointer;
    background: var(--accent); color: #0b0d12; border: 1px solid #0b0d12; border-radius: 999px;
    padding: 12px 34px; font-size: 0.95rem; font-weight: 400; letter-spacing: 0.02em; text-transform: uppercase;
    transition: background .3s, transform .3s;
  }
  .pill-accent:hover { background: #c3d2ff; }
  .pill-accent svg { width: 22px; height: 12px; }

  /* Navigazione per capitoli in basso */
  .chapters {
    position: fixed; z-index: 11; left: 0; right: 0;
    bottom: calc(clamp(18px, 4vh, 44px) + env(safe-area-inset-bottom, 0px));
    padding: 0 clamp(14px, 2.4vw, 40px);
    display: grid; grid-template-columns: 1fr auto 1fr; align-items: end;
    pointer-events: none; transition: opacity .6s ease;
  }
  .chapters > * { pointer-events: auto; }
  .chapter {
    display: flex; align-items: center; gap: clamp(12px, 1.6vw, 26px);
    background: none; border: 0; padding: 0; cursor: pointer; color: var(--ink); text-align: left;
  }
  .chapter[hidden] { display: none; }
  .chapter.prev { grid-column: 1; }
  .chapter.next { grid-column: 3; justify-self: end; flex-direction: row-reverse; text-align: right; }
  .chapter .round {
    flex: none; width: clamp(48px, 4.6vw, 70px); height: clamp(48px, 4.6vw, 70px); border-radius: 50%;
    display: grid; place-items: center; background: var(--accent); color: #0b0d12;
    transition: transform .35s ease, background .3s;
  }
  .chapter .round svg { width: 40%; }
  .chapter:hover .round { transform: scale(1.06); background: #c3d2ff; }
  .chapter .cap { display: block; font-family: var(--display); font-size: clamp(0.95rem, 1.4vw, 1.35rem); text-transform: uppercase; opacity: .85; }
  .chapter .name {
    display: block; font-family: var(--display); font-size: clamp(2rem, 4.6vw, 4.6rem); line-height: 0.9;
    text-transform: uppercase; letter-spacing: -0.01em;
  }
  .chapter.next .cap { text-align: right; }
  .chapters .center { grid-column: 2; align-self: center; }
  .chapters .center[hidden] { display: none; }
  body.moving .chapters, body.panel-open .chapters { opacity: 0; pointer-events: none; }
  body.moving .chapters *, body.panel-open .chapters * { pointer-events: none; }

  /* Etichette sopra gli archi */
  .labels { position: fixed; inset: 0; z-index: 12; pointer-events: none; }
  .room-label {
    position: absolute; left: 0; top: 0; pointer-events: auto;
    background: rgba(5,7,11,.4); border: 1px solid var(--line); border-radius: 999px;
    padding: 6px 14px; cursor: pointer; white-space: nowrap; color: var(--ink);
    font-size: 0.78rem; letter-spacing: 0.08em; text-transform: uppercase;
    backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
    transition: border-color .3s, background .3s, opacity .4s;
  }
  .room-label:hover, .room-label.is-hover { border-color: var(--accent); background: rgba(159,184,255,.14); }
  body:not(.is-home) .room-label { opacity: 0; pointer-events: none; }

  /* Pannelli: a destra su desktop, dal basso su mobile */
  .panel {
    position: fixed; z-index: 15;
    top: calc(84px + env(safe-area-inset-top, 0px));
    right: clamp(16px, 3vw, 32px);
    max-height: calc(100% - 108px - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px));
    width: min(440px, calc(100% - 32px));
    overflow: auto; overscroll-behavior: contain;
    background: var(--panel); border: 1px solid var(--line); border-radius: 18px;
    padding: clamp(18px, 2.4vw, 28px);
    backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
    opacity: 0; transform: translateX(24px);
    transition: opacity .5s ease, transform .6s cubic-bezier(.2,.7,.2,1);
  }
  .panel.open { opacity: 1; transform: none; }
  .panel-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 22px; }
  .panel-head h2 { margin: 0; font-weight: 300; font-size: clamp(1.6rem, 2.6vw, 2.2rem); letter-spacing: -0.03em; }
  .panel-head p { margin: 6px 0 0; color: var(--muted); line-height: 1.45; }
  .stagger > * { opacity: 0; transform: translateY(12px); transition: opacity .6s ease, transform .6s ease; transition-delay: calc(var(--i, 0) * 70ms + 150ms); }
  .panel.open .stagger > * { opacity: 1; transform: none; }

  .placeholder {
    border: 1px solid var(--line); border-radius: 10px;
    background: repeating-linear-gradient(135deg, rgba(159,184,255,.06) 0 10px, transparent 10px 20px);
    display: grid; place-items: center; color: var(--muted); font-size: 0.82rem;
  }
  /* Scheda progetto (stanza Progetti → Scopri): a tutto schermo, video a sinistra e dati a destra */
  .panel.panel-scheda {
    top: 0; right: 0; bottom: 0; left: 0; width: auto; max-height: none;
    border: 0; border-radius: 0;
    padding: calc(108px + env(safe-area-inset-top, 0px)) clamp(20px, 5vw, 72px) calc(48px + env(safe-area-inset-bottom, 0px));
    background: rgba(5, 7, 11, 0.9);
    backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
    transform: none;
  }
  .panel-scheda [hidden] { display: none !important; }   /* i campi vuoti spariscono anche se hanno un display proprio */
  .scheda-chiudi { position: absolute; top: calc(96px + env(safe-area-inset-top, 0px)); right: clamp(20px, 5vw, 72px); z-index: 2; }
  .scheda { display: grid; grid-template-columns: minmax(0, 1.55fr) minmax(0, 1fr); gap: clamp(28px, 4vw, 64px); align-items: start; max-width: 1500px; margin: 0 auto; }
  .scheda-video { position: relative; border-radius: 14px; overflow: hidden; background: #0b0f17; box-shadow: 0 30px 80px rgba(0,0,0,.6); aspect-ratio: 16 / 9; }
  .scheda-video video { display: block; width: 100%; height: 100%; object-fit: cover; }
  .scheda-badge {
    position: absolute; left: 16px; bottom: 14px; padding: 6px 12px; border-radius: 999px;
    background: rgba(5,7,11,.6); font-size: 0.72rem; letter-spacing: 0.08em; text-transform: uppercase;
  }
  .scheda-strip { display: flex; gap: 10px; margin-top: 14px; flex-wrap: wrap; }
  .scheda-strip button {
    padding: 0; border: 0; background: none; cursor: pointer; border-radius: 7px;
    width: clamp(84px, 8vw, 120px); aspect-ratio: 16 / 9; overflow: hidden; opacity: .45;
    transition: opacity .3s, outline-color .3s; outline: 2px solid transparent; outline-offset: 2px;
  }
  .scheda-strip button:hover { opacity: .8; }
  .scheda-strip button[aria-current="true"] { opacity: 1; outline-color: var(--accent); }
  .scheda-strip img { width: 100%; height: 100%; object-fit: cover; display: block; }
  .scheda-info { display: flex; flex-direction: column; gap: 22px; min-width: 0; padding-top: 4px; }
  .scheda-num { margin: 0; color: var(--muted); font-size: 0.8rem; letter-spacing: 0.14em; text-transform: uppercase; }
  .scheda-nome {
    margin: 0; color: var(--ink); font-weight: 300; text-transform: uppercase;
    font-size: clamp(2.4rem, 4.6vw, 4.4rem); line-height: 0.95; letter-spacing: -0.02em; text-wrap: balance;
  }
  .scheda-dati { display: grid; grid-template-columns: auto 1fr; gap: 10px 22px; margin: 0; font-size: 0.95rem; }
  .scheda-dati dt { color: var(--muted); text-transform: uppercase; letter-spacing: 0.08em; font-size: 0.72rem; padding-top: 4px; }
  .scheda-dati dd { margin: 0; display: flex; flex-wrap: wrap; gap: 6px; }
  .scheda-tag { padding: 4px 11px; border: 1px solid var(--line); border-radius: 999px; font-size: 0.75rem; letter-spacing: 0.06em; text-transform: uppercase; color: #c9d4f2; }
  .scheda-citazione { margin: 0; padding-left: 16px; border-left: 2px solid var(--accent); }
  .scheda-citazione p { margin: 0; font-size: 1.08rem; line-height: 1.45; color: var(--ink); }
  .scheda-citazione cite { display: block; margin-top: 8px; font-style: normal; color: var(--muted); font-size: 0.85rem; }
  .scheda-desc { margin: 0; color: var(--muted); line-height: 1.55; max-width: 60ch; }
  .scheda-azioni { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-top: 6px; }
  .scheda-visita { text-decoration: none; }
  .scheda-visita[aria-disabled="true"] { cursor: default; }
  .scheda-freccia {
    width: 48px; height: 48px; border-radius: 50%; display: grid; place-items: center; cursor: pointer;
    background: transparent; border: 1px solid var(--line); color: var(--ink); transition: border-color .3s, background .3s;
  }
  .scheda-freccia:hover { border-color: var(--accent); background: rgba(159,184,255,.1); }
  .scheda-freccia svg { width: 20px; height: 12px; }
  @media (max-width: 900px) {
    .panel.panel-scheda { padding-top: calc(132px + env(safe-area-inset-top, 0px)); }
    .scheda { grid-template-columns: 1fr; }
    .scheda-strip { flex-wrap: nowrap; overflow-x: auto; padding: 4px; margin: 10px -4px 0; scrollbar-width: none; }
    .scheda-strip button { flex: 0 0 auto; width: 84px; }
    .scheda-chiudi { top: calc(80px + env(safe-area-inset-top, 0px)); }
  }


  .grid-phones { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
  .phone .placeholder { aspect-ratio: 9 / 19; border-radius: 20px; }
  .phone p { margin: 8px 0 0; color: var(--muted); font-size: 0.85rem; text-align: center; }

  .dash h3 { margin: 0 0 12px; font-weight: 400; font-size: 0.95rem; color: var(--muted); }
  .dash > div + div { margin-top: 24px; }
  .timeline { list-style: none; margin: 0; padding: 0; counter-reset: fase; }
  .timeline li {
    counter-increment: fase; display: grid; grid-template-columns: 30px 1fr auto; align-items: center;
    padding: 11px 0; border-bottom: 1px solid var(--line);
  }
  .timeline li::before { content: counter(fase); color: var(--muted); font-size: 0.85rem; }
  .timeline .state { font-size: 0.82rem; color: var(--muted); }
  .timeline li.done .state { color: var(--fg); }
  .timeline li.now .state { color: var(--accent); }
  .requests { list-style: none; margin: 0; padding: 0; }
  .requests li {
    display: flex; justify-content: space-between; align-items: center; gap: 12px;
    padding: 13px 14px; border: 1px solid var(--line); border-radius: 12px; margin-bottom: 10px;
  }
  .pill { font-size: 0.78rem; padding: 4px 10px; border-radius: 999px; border: 1px solid var(--line); white-space: nowrap; }
  .pill.lavorazione { border-color: var(--accent); color: var(--accent); }
  .pill.ricevuta { color: var(--warm); border-color: rgba(255, 211, 138, .4); }
  .pill.completata { color: var(--muted); }

  /* Caricamento e fallback */
  .loader {
    position: fixed; inset: 0; z-index: 30; display: grid; place-items: center;
    background: var(--bg); color: var(--muted); transition: opacity .9s ease;
  }
  .loader.gone { opacity: 0; pointer-events: none; }
  .fallback { display: none; }
  body.no-webgl #scene, body.no-webgl .labels, body.no-webgl .loader, body.no-webgl .hero-title, body.no-webgl .chapters { display: none; }
  body.no-webgl .fallback {
    display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 16px;
    position: fixed; left: 50%; top: 50%; transform: translate(-50%, -50%);
    width: min(900px, calc(100% - 32px));
  }
  .fallback button {
    text-align: left; background: rgba(159,184,255,.05); border: 1px solid var(--line);
    border-radius: 14px; padding: 22px; cursor: pointer;
  }
  .fallback strong { display: block; font-weight: 400; font-size: 1.2rem; margin-bottom: 6px; }
  .fallback span { color: var(--muted); font-size: 0.92rem; }

  @media (max-width: 980px) {
    .nav { visibility: hidden; overflow: hidden; }
  }
  @media (max-width: 760px) {
    .chapters .center { display: none; }
    .chapter { gap: 10px; }
    .chapter .round { width: 40px; height: 40px; }
    .chapter .cap { font-size: 0.8rem; }
    .chapter .name { font-size: 1.35rem; }
    .pill-light { padding: 6px 14px; font-size: 0.8rem; }
    .panel-head { flex-wrap: wrap; }
    .panel-head > div:first-child { flex: 1 1 220px; }
    .panel:not(.panel-scheda) {
      top: auto; left: 16px; right: 16px; width: auto;
      bottom: calc(16px + env(safe-area-inset-bottom, 0px));
      max-height: 58%;
      transform: translateY(24px);
    }
  }
  /* Intro d'ingresso: header e capitoli compaiono alla fine, il titolo sale riga per riga */
  .hero-title .kicker, .hero-title .l1, .hero-title .l2 {
    clip-path: inset(-0.3em -0.3em -0.3em -0.3em);
    transition: opacity 1s ease, transform 1.3s cubic-bezier(.2,.7,.2,1), clip-path 1.3s cubic-bezier(.2,.7,.2,1);
  }
  body.intro:not(.intro-title) .hero-title .kicker { opacity: 0; transform: translateY(14px); transition-duration: 0s; }
  body.intro:not(.intro-title) .hero-title .l1,
  body.intro:not(.intro-title) .hero-title .l2 { opacity: 0; transform: translateY(0.45em); clip-path: inset(100% -0.3em -0.3em -0.3em); transition-duration: 0s; }
  body.intro-title .hero-title .l1 { transition-delay: .15s; }
  body.intro-title .hero-title .l2 { transition-delay: .32s; }
  body.intro .site-header, body.intro .chapters { opacity: 0; transition-duration: 0s; }
  body.intro .room-label { transition-duration: 0s; }
  body.intro .site-header *, body.intro .chapters * { pointer-events: none !important; }
  body.intro.intro-ui .site-header, body.intro.intro-ui .chapters { opacity: 1; transition-duration: 1.2s; }
  body.intro.intro-ui .chapters { transition-delay: .25s; }
  @media (prefers-reduced-motion: reduce) {
    .panel, .stagger > *, .hero-title, .chapters, .hero-title .kicker, .hero-title .l1, .hero-title .l2 { transition-duration: .01s !important; transition-delay: 0s !important; }
  }
