/* Layout: tre colonne — lista organi, palco 3D, pannello di studio. Su telefono la lista diventa un cassetto e il pannello scende sotto il palco. */
:root {
  --bg: #e5e9ed; --stage: #d8dee4; --stage-glow: #f5f7f9; --panel: #f7f8fa; --ink: #1b222a; --muted: #56616d;
  --line: #d1d8de; --chip: #eaeef1; --accent: #9b2d38; --accent-soft: #f4e2e4; --ok: #2c7749; --bad: #ad3e2c;
  --f-display: "Literata", Georgia, "Times New Roman", serif;
  --f-body: "Public Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --f-mono: "IBM Plex Mono", ui-monospace, Consolas, monospace;
  --nav-w: 272px; --panel-w: 360px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #12171c; --stage: #141a20; --stage-glow: #222b34; --panel: #181e25; --ink: #e3e7eb; --muted: #99a4af;
    --line: #2a333c; --chip: #212931; --accent: #e27782; --accent-soft: #3b2428; --ok: #5ec088; --bad: #e67a62;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #12171c; --stage: #141a20; --stage-glow: #222b34; --panel: #181e25; --ink: #e3e7eb; --muted: #99a4af;
  --line: #2a333c; --chip: #212931; --accent: #e27782; --accent-soft: #3b2428; --ok: #5ec088; --bad: #e67a62;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--ink); font-family: var(--f-body); font-size: 14px; line-height: 1.5; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
[hidden] { display: none !important; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.eyebrow { margin: 0; font-family: var(--f-mono); font-size: 11px; font-weight: 500; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.hint { font-size: 12.5px; color: var(--muted); margin: 0; }

.app { display: grid; grid-template-columns: var(--nav-w) minmax(0, 1fr) var(--panel-w); height: 100%; }
.app.nav-closed { grid-template-columns: 0 minmax(0, 1fr) var(--panel-w); }
.app.nav-closed .nav { visibility: hidden; }

/* ---------- lista organi ---------- */
.nav { min-width: 0; background: var(--panel); border-right: 1px solid var(--line); display: flex; flex-direction: column; overflow: hidden; }
.nav-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 14px 12px 10px 16px; }
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; min-width: 0; }
.brand b { display: block; font-family: var(--f-display); font-weight: 600; font-size: 18px; line-height: 1.1; }
.brand small { display: block; color: var(--muted); font-size: 11.5px; }
.mark { width: 26px; height: 26px; border-radius: 50%; background: var(--accent); flex: none; position: relative; }
.mark::after { content: ""; position: absolute; inset: 7px; border: 2px solid var(--panel); border-radius: 50%; }
.icon-btn { border: 0; background: transparent; width: 32px; height: 32px; border-radius: 8px; display: grid; place-items: center; color: var(--muted); flex: none; }
.icon-btn:hover { background: var(--chip); color: var(--ink); }
.icon-btn svg { width: 18px; height: 18px; }
.icon-btn.solid { background: var(--panel); border: 1px solid var(--line); }
.nav-tools { padding: 0 16px 10px; display: flex; flex-direction: column; gap: 8px; border-bottom: 1px solid var(--line); }
.search input { width: 100%; border: 1px solid var(--line); background: var(--bg); border-radius: 8px; padding: 7px 10px; }
.search.small input { padding: 5px 9px; font-size: 13px; }
.switch { display: flex; align-items: center; gap: 8px; font-size: 12.5px; color: var(--muted); cursor: pointer; }
.switch input { accent-color: var(--accent); margin: 0; }
.nav-list { overflow-y: auto; padding: 8px 8px 16px; flex: 1; }
.app-group { margin-top: 6px; }
.app-group > button { width: 100%; display: flex; align-items: center; gap: 8px; border: 0; background: transparent; padding: 7px 8px; border-radius: 8px; font-weight: 600; font-size: 13px; text-align: left; }
.app-group > button:hover { background: var(--chip); }
.app-group > button .chev { width: 12px; transition: transform .15s; color: var(--muted); flex: none; }
.app-group.closed > button .chev { transform: rotate(-90deg); }
.app-group > button .n { margin-left: auto; font-family: var(--f-mono); font-size: 11px; color: var(--muted); font-weight: 400; font-variant-numeric: tabular-nums; }
.app-group ul { list-style: none; margin: 0; padding: 0 0 4px 20px; }
.app-group.closed ul { display: none; }
.organ { display: flex; align-items: center; gap: 8px; width: 100%; border: 0; background: transparent; padding: 5px 8px; border-radius: 7px; text-align: left; font-size: 13px; text-decoration: none; }
.organ:hover { background: var(--chip); }
.organ[aria-current="page"] { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.organ .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); flex: none; }
.organ.soon { color: var(--muted); cursor: default; }
.organ.soon:hover { background: transparent; }
.organ.soon .dot { background: transparent; border: 1px solid var(--line); }
.organ .tag { margin-left: auto; font-family: var(--f-mono); font-size: 10px; letter-spacing: .04em; color: var(--muted); }
.credits { padding: 10px 16px 14px; border-top: 1px solid var(--line); font-size: 11.5px; color: var(--muted); }

/* ---------- palco ---------- */
.stage { position: relative; min-width: 0; overflow: hidden; background: radial-gradient(ellipse 70% 60% at 50% 42%, var(--stage-glow), var(--stage)); }
#gl { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; cursor: grab; }
#gl.dragging { cursor: grabbing; }
#gl.over { cursor: pointer; }
.top-left { position: absolute; top: 14px; left: 16px; display: flex; gap: 10px; align-items: flex-start; max-width: 50%; pointer-events: none; }
.top-left > * { pointer-events: auto; }
.app:not(.nav-closed) #navOpen { display: none; }
.title h1 { margin: 0; font-family: var(--f-display); font-weight: 600; font-size: clamp(20px, 2.2vw, 28px); line-height: 1.1; text-wrap: balance; letter-spacing: -.01em; }
.top-right { position: absolute; top: 14px; right: 16px; display: flex; flex-direction: column; align-items: flex-end; gap: 8px; }
.seg { display: inline-flex; background: var(--panel); border: 1px solid var(--line); border-radius: 999px; padding: 3px; gap: 2px; box-shadow: 0 1px 2px rgb(0 0 0 / .06); }
.seg button { border: 0; background: transparent; padding: 5px 12px; border-radius: 999px; font-size: 12.5px; font-weight: 500; color: var(--muted); }
.seg.small button { padding: 4px 10px; font-size: 12px; }
.seg button[aria-pressed="true"] { background: var(--ink); color: var(--panel); }
.seg button:hover:not([aria-pressed="true"]) { color: var(--ink); }
.floating { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 8px 10px; }
.floating label { font-size: 11.5px; color: var(--muted); font-family: var(--f-mono); }
.floating input[type=range] { width: 200px; accent-color: var(--accent); }
.bottom-left { position: absolute; left: 16px; bottom: 14px; display: flex; flex-wrap: wrap; gap: 6px; align-items: center; max-width: calc(100% - 120px); }
.bottom-left .lbl { font-family: var(--f-mono); font-size: 11px; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); margin-right: 2px; }
.chipbtn { border: 1px solid var(--line); background: var(--panel); border-radius: 999px; padding: 4px 10px; font-size: 12px; }
.chipbtn:hover { border-color: var(--ink); }
.gizmo { position: absolute; right: 12px; bottom: 10px; width: 84px; height: 84px; pointer-events: none; }
.gizmo text { font-family: var(--f-mono); font-size: 10px; fill: var(--ink); }
.labels { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.lab { position: absolute; left: 0; top: 0; font-family: var(--f-mono); font-size: 11px; line-height: 1.2; white-space: nowrap; padding: 2px 6px; border-radius: 4px; background: color-mix(in srgb, var(--panel) 85%, transparent); border: 1px solid color-mix(in srgb, var(--line) 80%, transparent); }
.lab::before { content: ""; position: absolute; left: 50%; top: 100%; width: 1px; height: 10px; background: color-mix(in srgb, var(--ink) 45%, transparent); }
.tip { position: absolute; pointer-events: none; background: var(--ink); color: var(--panel); font-size: 12px; padding: 3px 8px; border-radius: 6px; white-space: nowrap; transform: translate(12px, -130%); }
.loader { position: absolute; inset: 0; display: grid; place-items: center; background: color-mix(in srgb, var(--stage) 55%, transparent); }
.loader-card { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 16px 18px; width: min(320px, 90%); display: flex; flex-direction: column; gap: 6px; }
.loader-card strong { font-family: var(--f-display); font-size: 18px; }
.bar { height: 6px; background: var(--chip); border-radius: 999px; overflow: hidden; }
.bar i { display: block; height: 100%; width: 0; background: var(--accent); transition: width .2s; }
.fallback { position: absolute; inset: 0; display: grid; place-items: center; padding: 24px; text-align: center; color: var(--muted); }

/* ---------- pannello ---------- */
.panel { min-width: 0; background: var(--panel); border-left: 1px solid var(--line); overflow-y: auto; }
.tabs { display: flex; gap: 2px; padding: 12px 16px 0; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--panel); z-index: 2; }
.tabs button { border: 0; background: transparent; padding: 8px 10px 10px; font-weight: 500; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs button[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--accent); }
.tabpanel { padding: 16px; display: flex; flex-direction: column; gap: 18px; }
.info { border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; background: var(--bg); display: flex; flex-direction: column; gap: 8px;
  position: sticky; top: 58px; z-index: 1; max-height: 52vh; overflow-y: auto; box-shadow: 0 6px 16px -10px rgb(0 0 0 / .35); }
.info .top { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.kind { font-family: var(--f-mono); font-size: 10.5px; letter-spacing: .06em; text-transform: uppercase; padding: 2px 7px; border-radius: 999px; background: var(--chip); color: var(--muted); display: inline-flex; align-items: center; gap: 6px; }
.kind i { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.info h2 { margin: 0; font-family: var(--f-display); font-weight: 600; font-size: 21px; line-height: 1.2; text-wrap: balance; }
.info .en { font-family: var(--f-mono); font-size: 11.5px; color: var(--muted); margin-top: -4px; }
.info ul { margin: 0; padding-left: 18px; display: flex; flex-direction: column; gap: 6px; }
.info li::marker { color: var(--accent); }
.info .ref { font-family: var(--f-mono); font-size: 11.5px; color: var(--muted); border-top: 1px dashed var(--line); padding-top: 8px; }
.info p { margin: 0; }
.info .actions { display: flex; gap: 8px; flex-wrap: wrap; }
.x { border: 0; background: transparent; font-size: 18px; line-height: 1; color: var(--muted); padding: 2px 6px; border-radius: 6px; }
.x:hover { background: var(--chip); color: var(--ink); }
.linkbtn { border: 0; background: transparent; color: var(--accent); font-size: 12.5px; padding: 2px 4px; border-radius: 6px; }
.linkbtn:hover { text-decoration: underline; }
.index { display: flex; flex-direction: column; gap: 8px; }
.index-head { display: flex; align-items: baseline; gap: 8px; }
.index-head .count { font-family: var(--f-mono); font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; }
.index-head .linkbtn { margin-left: auto; }
.grp { border-top: 1px solid var(--line); }
.grp-head { display: flex; align-items: center; gap: 4px; padding: 6px 0; }
.grp-head .toggle { flex: 1; display: flex; align-items: center; gap: 8px; border: 0; background: transparent; padding: 3px 4px; border-radius: 6px; font-weight: 600; font-size: 13px; text-align: left; min-width: 0; }
.grp-head .toggle:hover { background: var(--chip); }
.grp-head .chev { width: 12px; color: var(--muted); transition: transform .15s; flex: none; }
.grp.closed .chev { transform: rotate(-90deg); }
.grp.closed .rows { display: none; }
.grp-head .ctx { font-family: var(--f-mono); font-size: 10px; color: var(--muted); font-weight: 400; letter-spacing: .04em; }
.rows { list-style: none; margin: 0 0 6px; padding: 0; }
.row { display: flex; align-items: center; gap: 2px; border-radius: 6px; }
.row:hover { background: var(--chip); }
.row .name { flex: 1; min-width: 0; border: 0; background: transparent; text-align: left; padding: 4px 6px; font-size: 13px; border-radius: 6px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .name i { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 7px; vertical-align: 0; }
.row.on .name { color: var(--accent); font-weight: 600; }
.row.off .name { color: var(--muted); text-decoration: line-through; text-decoration-color: color-mix(in srgb, var(--muted) 50%, transparent); }
.eye { border: 0; background: transparent; width: 28px; height: 26px; border-radius: 6px; display: grid; place-items: center; color: var(--muted); flex: none; }
.eye:hover { color: var(--ink); background: color-mix(in srgb, var(--chip) 60%, var(--line)); }
.eye svg { width: 16px; height: 16px; }
.note { font-size: 12.5px; color: var(--muted); border-left: 3px solid var(--line); padding-left: 10px; margin: 0; }

.qcard { border: 1px solid var(--line); border-radius: 12px; padding: 16px; background: var(--bg); display: flex; flex-direction: column; gap: 10px; }
.qcard .ask { font-size: 13px; color: var(--muted); }
.qcard .target { font-family: var(--f-display); font-size: 23px; font-weight: 600; line-height: 1.15; }
.fb { font-size: 13.5px; min-height: 1.5em; }
.fb.ok { color: var(--ok); } .fb.bad { color: var(--bad); }
.score { font-family: var(--f-mono); font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.btnline { display: flex; gap: 8px; flex-wrap: wrap; }
.primary { border: 0; background: var(--accent); color: #fff; border-radius: 999px; padding: 7px 16px; font-weight: 600; }
.ghostbtn { border: 1px solid var(--line); background: transparent; border-radius: 999px; padding: 6px 14px; font-weight: 500; }
.ghostbtn:hover { border-color: var(--ink); }
.qs { margin: 8px 0 0; padding-left: 20px; display: flex; flex-direction: column; gap: 6px; font-size: 13px; }

/* ---------- controlli aggiunti ---------- */
.mobile-only { display: none !important; }
.chipbtn.toggle { display: inline-flex; align-items: center; gap: 6px; }
.chipbtn.toggle svg { width: 14px; height: 14px; }
.chipbtn.toggle[aria-pressed="false"] { color: var(--muted); text-decoration: line-through; text-decoration-color: color-mix(in srgb, var(--muted) 60%, transparent); }
.view-select select { border: 1px solid var(--line); background: var(--panel); border-radius: 999px; padding: 4px 10px; font-size: 12px; }
.selchip { position: absolute; left: 50%; top: 64px; transform: translateX(-50%); display: flex; align-items: center; gap: 8px; max-width: calc(100% - 32px);
  background: var(--panel); border: 1px solid var(--line); border-radius: 999px; padding: 5px 8px 5px 14px; font-weight: 600; font-size: 13px; box-shadow: 0 4px 14px -8px rgb(0 0 0 / .4); }
.selchip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* didascalia dell'animazione sul palco */
.caption { position: absolute; left: 50%; bottom: 52px; transform: translateX(-50%); width: min(560px, calc(100% - 32px));
  background: color-mix(in srgb, var(--panel) 94%, transparent); border: 1px solid var(--line); border-radius: 14px; padding: 10px 10px 0 14px;
  display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 4px 10px; box-shadow: 0 10px 24px -14px rgb(0 0 0 / .5); overflow: hidden; }
.cap-text { min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.cap-text strong { font-family: var(--f-display); font-size: 17px; line-height: 1.2; }
.cap-text p { margin: 0; font-size: 13px; color: var(--muted); display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.cap-ctrl { display: flex; align-items: flex-start; gap: 2px; }
.cap-ctrl .play { background: var(--accent); color: #fff; }
.cap-ctrl .play:hover { background: var(--accent); color: #fff; filter: brightness(1.08); }
.play .i-play { display: none; }
.play.paused .i-play { display: inline; }
.play.paused .i-pause { display: none; }
.cap-bar { grid-column: 1 / -1; height: 3px; margin: 8px -10px 0 -14px; background: var(--chip); }
.cap-bar i { display: block; height: 100%; width: 0; background: var(--accent); }

/* scheda animazioni */
.anim-list { display: flex; flex-direction: column; gap: 8px; }
.anim-card { text-align: left; border: 1px solid var(--line); background: var(--bg); border-radius: 12px; padding: 12px 14px; display: flex; flex-direction: column; gap: 3px; }
.anim-card:hover { border-color: var(--ink); }
.anim-card[aria-pressed="true"] { border-color: var(--accent); box-shadow: inset 3px 0 0 var(--accent); }
.anim-card strong { font-family: var(--f-display); font-size: 16px; }
.anim-card span { font-size: 12.5px; color: var(--muted); }
.anim-card .kind { align-self: flex-start; margin-bottom: 2px; }
.anim-detail { display: flex; flex-direction: column; gap: 10px; border-top: 1px solid var(--line); padding-top: 14px; }
.phase { border-left: 3px solid var(--accent); padding: 2px 0 2px 12px; display: flex; flex-direction: column; gap: 4px; }
.phase .tag { font-family: var(--f-mono); font-size: 11px; color: var(--muted); letter-spacing: .04em; }
.phase h3 { margin: 0; font-family: var(--f-display); font-size: 19px; font-weight: 600; }
.phase p { margin: 0; }
#ecg { width: 100%; height: 92px; display: block; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); }
#animScrub { width: 100%; accent-color: var(--accent); }
.ctrl { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.phase-list { margin: 0; padding-left: 20px; display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.phase-list li { cursor: pointer; }
.phase-list li.on { color: var(--accent); font-weight: 600; }

/* ---------- telefono e tablet ---------- */
@media (max-width: 960px) {
  :root { --panel-w: 320px; }
}
@media (max-width: 820px) {
  html, body { height: auto; }
  .app, .app.nav-closed { display: block; height: auto; }
  .nav { position: fixed; inset: 0 auto 0 0; width: min(86vw, 320px); z-index: 30; box-shadow: 0 0 0 100vmax rgb(0 0 0 / .4);
    padding-top: env(safe-area-inset-top, 0px); padding-bottom: env(safe-area-inset-bottom, 0px); }
  .app.nav-closed .nav { display: none; }
  .mobile-only { display: revert !important; }
  label.mobile-only { display: inline-flex !important; }
  .desktop-only { display: none !important; }

  .stage { height: 68svh; min-height: 420px; }
  /* striscia del titolo sopra al modello */
  .top-left { top: 0; left: 0; right: 0; max-width: none; padding: 8px 12px; gap: 10px; align-items: center;
    background: color-mix(in srgb, var(--panel) 92%, transparent); border-bottom: 1px solid var(--line); }
  .app:not(.nav-closed) #navOpen { display: grid; }
  .title { min-width: 0; }
  .title .eyebrow { display: none; }
  .title h1 { font-size: 19px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .top-right { top: 58px; right: 12px; left: 12px; align-items: stretch; }
  .top-right > .seg { align-self: flex-end; }
  #paletteSeg { display: none; }
  .floating { align-items: stretch; }
  .floating .seg { align-self: flex-end; }
  .floating input[type=range] { width: 100%; }
  .seg button { padding: 6px 12px; }
  .bottom-left { left: 12px; right: 84px; bottom: 12px; max-width: none; gap: 6px; flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }
  .chipbtn, .view-select select { padding: 7px 12px; font-size: 13px; white-space: nowrap; }
  .gizmo { width: 66px; height: 66px; right: 10px; bottom: 8px; }
  .lab { font-size: 10px; padding: 1px 5px; }
  .selchip { top: 104px; }
  .caption { bottom: 58px; padding: 8px 6px 0 12px; }
  .cap-text strong { font-size: 15px; }
  .cap-text p { -webkit-line-clamp: 2; font-size: 12.5px; }
  .cap-ctrl .icon-btn { width: 36px; height: 36px; }

  .panel { border-left: 0; border-top: 1px solid var(--line); overflow: visible; }
  .tabs { padding: 8px 12px 0; }
  .tabs button { padding: 10px 12px 12px; }
  .tabpanel { padding: 14px 12px calc(24px + env(safe-area-inset-bottom, 0px)); }
  .info { position: static; max-height: none; box-shadow: none; }
  .row .name { padding: 8px 6px; font-size: 14px; }
  .eye { width: 40px; height: 36px; }
  .grp-head .toggle { padding: 8px 4px; }
  .organ { padding: 9px 8px; font-size: 14px; }
  .app-group > button { padding: 10px 8px; }
}
@media (max-width: 380px) {
  .seg button { padding: 6px 9px; font-size: 12px; }
}
