/* ==========================================================================
   Banco Ottico — design system HUD
   Scena scura, pannelli in vetro, accento ciano + ottone.
   ========================================================================== */

:root {
  --bg: #07090d;
  --panel: rgba(11, 15, 21, 0.62);
  --panel-strong: rgba(11, 15, 21, 0.82);
  --panel-border: rgba(255, 255, 255, 0.09);
  --panel-inner: rgba(255, 255, 255, 0.045);
  --text: #e9eef4;
  --text-dim: #aab5c3;
  --muted: #74808f;
  --accent: #5ad8ff;
  --accent-soft: rgba(90, 216, 255, 0.16);
  --brass: #e39a4a;
  --brass-soft: rgba(227, 154, 74, 0.18);
  --ok: #6ee7a8;

  --font-display: "Inter Tight", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-body: "Inter Tight", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, "SFMono-Regular", Consolas, monospace;

  --radius: 12px;
  --radius-sm: 7px;
  --gutter: 18px;
  --blur: blur(14px) saturate(140%);
  --shadow: 0 10px 40px rgba(0, 0, 0, 0.45);
  --ease: cubic-bezier(0.2, 0.7, 0.2, 1);

  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

#stage {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  outline: none;
}

/* --- Barra superiore ---------------------------------------------------- */

.topbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px var(--gutter);
  padding-top: max(12px, env(safe-area-inset-top));
  pointer-events: none;
}
.topbar > * { pointer-events: auto; }

.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  color: var(--text);
  text-decoration: none;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}
.brand-mark {
  width: 16px; height: 16px;
  border-radius: 50%;
  border: 2px solid var(--accent);
  box-shadow: inset 0 0 0 3px var(--bg), inset 0 0 0 8px var(--brass);
}

.tabs {
  display: flex;
  gap: 2px;
  padding: 3px;
  border-radius: 999px;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  backdrop-filter: var(--blur);
  -webkit-backdrop-filter: var(--blur);
}
.tab {
  display: flex;
  align-items: baseline;
  gap: 6px;
  padding: 6px 13px;
  border-radius: 999px;
  color: var(--text-dim);
  text-decoration: none;
  font-weight: 600;
  font-size: 13px;
  transition: background 0.2s var(--ease), color 0.2s var(--ease);
}
.tab:hover { color: var(--text); background: var(--panel-inner); }
.tab[aria-current="page"] { color: var(--bg); background: var(--text); }
.tab-n {
  font-family: var(--font-mono);
  font-size: 10px;
  opacity: 0.6;
}

/* --- Livello HUD -------------------------------------------------------- */

.hud {
  position: fixed;
  inset: 0;
  z-index: 10;
  pointer-events: none;
}
.hud .panel,
.hud .filmstrip,
.hud .hint-bar { pointer-events: auto; }

.panel {
  position: absolute;
  width: 300px;
  padding: 16px;
  border-radius: var(--radius);
  background: var(--panel);
  border: 1px solid var(--panel-border);
  backdrop-filter: var(--blur);
  -webkit-backdrop-filter: var(--blur);
  box-shadow: var(--shadow);
}
.panel--info { top: 64px; left: var(--gutter); }
.panel--controls { top: 64px; right: var(--gutter); width: 316px; }

/* Scheda informativa */

.kicker {
  margin: 0 0 2px;
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--text-dim);
}
.title {
  margin: 0 0 10px;
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 30px;
  line-height: 0.95;
  letter-spacing: -0.01em;
  text-transform: uppercase;
  color: var(--accent);
}
.lead {
  margin: 0 0 14px;
  font-size: 12.5px;
  color: var(--text-dim);
}

.stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  margin-bottom: 12px;
}
.stat {
  padding: 7px 8px 6px;
  border-radius: var(--radius-sm);
  background: var(--panel-inner);
  border: 1px solid var(--panel-border);
  min-width: 0;
}
.stat-label {
  display: block;
  font-family: var(--font-mono);
  font-size: 9px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.stat-value {
  display: block;
  margin-top: 2px;
  font-family: var(--font-mono);
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.stat-value.is-flash { animation: flash 0.5s var(--ease); }
@keyframes flash {
  from { color: var(--accent); }
  to   { color: var(--text); }
}

.note {
  margin: 0;
  padding: 9px 10px;
  border-radius: var(--radius-sm);
  background: var(--panel-inner);
  border-left: 2px solid var(--accent);
  font-size: 12px;
  color: var(--text-dim);
}
.hl { color: var(--accent); font-weight: 600; }
.hl--brass { color: var(--brass); font-weight: 600; }

/* Pannello controlli */

.ctrl + .ctrl { margin-top: 13px; }
.ctrl-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 6px;
}
.ctrl-label {
  font-family: var(--font-mono);
  font-size: 9.5px;
  font-weight: 600;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--text-dim);
}
.ctrl-hint,
.ctrl-value {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.ctrl-value { color: var(--text); }
kbd {
  display: inline-block;
  min-width: 15px;
  padding: 0 3px;
  border-radius: 3px;
  border: 1px solid var(--panel-border);
  background: var(--panel-inner);
  font-family: var(--font-mono);
  font-size: 9.5px;
  text-align: center;
  color: var(--text-dim);
}

.seg {
  display: flex;
  gap: 2px;
  padding: 2px;
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid var(--panel-border);
}
.seg-btn {
  flex: 1 1 0;
  min-width: 0;
  padding: 6px 6px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--text-dim);
  font: 600 12px var(--font-body);
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.18s var(--ease), color 0.18s var(--ease);
}
.seg-btn:hover { color: var(--text); background: var(--panel-inner); }
.seg-btn[aria-pressed="true"] {
  color: var(--bg);
  background: var(--text);
}
.seg-btn.mono { font-family: var(--font-mono); font-size: 11.5px; }
.seg-btn:focus-visible,
.icon-btn:focus-visible,
.tab:focus-visible,
.range:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.range {
  width: 100%;
  height: 18px;
  margin: 0;
  background: transparent;
  -webkit-appearance: none;
  appearance: none;
  cursor: pointer;
}
.range::-webkit-slider-runnable-track {
  height: 3px;
  border-radius: 3px;
  background: linear-gradient(to right, var(--accent) var(--fill, 50%), rgba(255, 255, 255, 0.14) var(--fill, 50%));
}
.range::-moz-range-track {
  height: 3px;
  border-radius: 3px;
  background: rgba(255, 255, 255, 0.14);
}
.range::-moz-range-progress { height: 3px; border-radius: 3px; background: var(--accent); }
.range::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px; height: 14px;
  margin-top: -5.5px;
  border-radius: 50%;
  background: var(--text);
  border: 3px solid var(--bg);
  box-shadow: 0 0 0 1px var(--accent);
}
.range::-moz-range-thumb {
  width: 10px; height: 10px;
  border-radius: 50%;
  background: var(--text);
  border: 3px solid var(--bg);
  box-shadow: 0 0 0 1px var(--accent);
}

.ctrl-row {
  display: flex;
  align-items: center;
  gap: 8px;
}
.ctrl-row .seg { flex: 1 1 auto; }

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 30px; height: 30px;
  flex: 0 0 auto;
  padding: 0;
  border-radius: 8px;
  border: 1px solid var(--panel-border);
  background: rgba(0, 0, 0, 0.35);
  color: var(--text-dim);
  cursor: pointer;
}
.icon-btn:hover { color: var(--text); background: var(--panel-inner); }
.icon-btn svg { width: 14px; height: 14px; }

.panel-toggle { display: none; }

/* --- Callout agganciati alla scena 3D ---------------------------------- */

.callouts { position: absolute; inset: 0; overflow: hidden; }
.callout {
  position: absolute;
  top: 0; left: 0;
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 2px 7px 2px 5px;
  border-radius: 4px;
  background: rgba(8, 11, 16, 0.78);
  border: 1px solid var(--panel-border);
  font-family: var(--font-mono);
  font-size: 9.5px;
  color: var(--text);
  white-space: nowrap;
  transform: translate(-50%, -50%);
  transition: opacity 0.25s var(--ease);
  will-change: transform;
}
.callout::before {
  content: "";
  width: 5px; height: 5px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 6px var(--accent);
}
.callout.is-brass::before { background: var(--brass); box-shadow: 0 0 6px var(--brass); }
.callout.is-hidden { opacity: 0; }

/* --- Pellicola degli scatti -------------------------------------------- */

.filmstrip {
  position: absolute;
  left: 50%;
  bottom: max(var(--gutter), env(safe-area-inset-bottom));
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 8px;
  max-width: min(720px, calc(100vw - 2 * var(--gutter)));
  padding: 8px;
  border-radius: var(--radius);
  background: var(--panel);
  border: 1px solid var(--panel-border);
  backdrop-filter: var(--blur);
  -webkit-backdrop-filter: var(--blur);
  box-shadow: var(--shadow);
}
.filmstrip-track {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  scroll-behavior: smooth;
  scrollbar-width: none;
  min-width: 0;
}
.filmstrip-track::-webkit-scrollbar { display: none; }
.frame {
  position: relative;
  flex: 0 0 auto;
  width: 96px;
  aspect-ratio: 3 / 2;
  margin: 0;
  border-radius: 5px;
  overflow: hidden;
  border: 1px solid var(--panel-border);
  background: #000;
}
.frame img { width: 100%; height: 100%; object-fit: cover; display: block; }
.frame figcaption {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  padding: 1px 4px;
  background: linear-gradient(transparent, rgba(0, 0, 0, 0.85));
  font-family: var(--font-mono);
  font-size: 8.5px;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.frame.is-new { box-shadow: 0 0 0 2px var(--accent); }
.filmstrip-empty {
  padding: 0 8px;
  font-family: var(--font-mono);
  font-size: 10.5px;
  color: var(--muted);
  white-space: nowrap;
}

/* --- Stato "in costruzione" ------------------------------------------- */

.wip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 12px;
  padding: 4px 8px;
  border-radius: 999px;
  background: var(--brass-soft);
  color: var(--brass);
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

/* --- Loader e fallback ------------------------------------------------- */

.loader {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 14px;
  background: var(--bg);
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-dim);
  transition: opacity 0.5s var(--ease);
}
.loader.is-done { opacity: 0; pointer-events: none; }
.loader-ring {
  width: 34px; height: 34px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.1);
  border-top-color: var(--accent);
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.fallback {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-content: center;
  padding: 24px;
  text-align: center;
  background: var(--bg);
}
.fallback[hidden] { display: none; }
.fallback h1 { font-family: var(--font-display); color: var(--accent); }
.fallback p { color: var(--text-dim); max-width: 42ch; }

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

/* --- Mobile ------------------------------------------------------------ */

@media (max-width: 760px) {
  :root { --gutter: 12px; }

  .topbar { flex-direction: column; align-items: stretch; gap: 8px; }
  .brand { justify-content: center; }
  .tabs { justify-content: space-between; }
  .tab { flex: 1 1 0; justify-content: center; padding: 6px 4px; font-size: 12px; }
  .tab-n { display: none; }

  .panel { width: auto; left: var(--gutter); right: var(--gutter); }
  .panel--info { top: 100px; padding: 12px; }
  .panel--info .lead { display: none; }
  .title { font-size: 22px; margin-bottom: 8px; }

  /* Pannello controlli → bottom sheet richiudibile */
  .panel--controls {
    top: auto;
    bottom: max(var(--gutter), env(safe-area-inset-bottom));
    width: auto;
    max-height: 55vh;
    overflow-y: auto;
    padding-top: 10px;
  }
  .panel--controls.is-collapsed .ctrl { display: none; }
  .panel-toggle {
    display: flex;
    width: 100%;
    align-items: center;
    justify-content: space-between;
    padding: 0 0 8px;
    border: 0;
    background: none;
    color: var(--text-dim);
    font-family: var(--font-mono);
    font-size: 10px;
    letter-spacing: 0.16em;
    text-transform: uppercase;
    cursor: pointer;
  }
  .panel--controls.is-collapsed .panel-toggle { padding-bottom: 0; }

  .filmstrip { display: none; }
  .callout { font-size: 8.5px; }
}

/* --- Vista dal sensore (inset WebGL) ----------------------------------- */

/* Nessun backdrop-filter né sfondo sopra l'area immagine: sfocherebbero e
   scurirebbero il canvas WebGL disegnato sotto. Intestazione e didascalia
   sono strisce solide attaccate alla finestra trasparente. */
.sensor-inset {
  --inset-w: 288px;
  position: absolute;
  left: var(--gutter);
  bottom: max(var(--gutter), env(safe-area-inset-bottom));
  width: var(--inset-w);
  filter: drop-shadow(0 10px 30px rgba(0, 0, 0, 0.45));
}
.sensor-inset-head,
.sensor-inset-meta {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  padding: 7px 10px;
  background: var(--panel-strong);
  border: 1px solid var(--panel-border);
  font-family: var(--font-mono);
  font-size: 9.5px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-dim);
}
.sensor-inset-head { border-radius: var(--radius) var(--radius) 0 0; border-bottom: 0; }
.sensor-inset-meta {
  border-radius: 0 0 var(--radius) var(--radius);
  border-top: 0;
  text-transform: none;
  letter-spacing: 0.02em;
  color: var(--muted);
}
.sensor-inset-view {
  width: var(--inset-w);
  aspect-ratio: 3 / 2;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.14);
  background: transparent;
}
.rec-dot {
  display: inline-block;
  width: 6px; height: 6px;
  margin-right: 5px;
  border-radius: 50%;
  background: #ff5a5a;
  box-shadow: 0 0 6px #ff5a5a;
  vertical-align: 1px;
}

/* la pellicola si affianca all'inset invece di centrarsi */
.filmstrip--beside {
  left: calc(var(--gutter) * 2 + 288px);
  transform: none;
  max-width: calc(100vw - 288px - var(--gutter) * 3);
}

canvas.is-grab { cursor: grab; }
canvas.is-grabbing { cursor: grabbing; }
canvas.is-pointer { cursor: pointer; }

@media (max-width: 760px) {
  .sensor-inset {
    --inset-w: 150px;
    bottom: calc(max(var(--gutter), env(safe-area-inset-bottom)) + 52px);
  }
  .sensor-inset-head { padding: 5px 7px; font-size: 8.5px; }
  .sensor-inset-head span:last-child { display: none; }
  .sensor-inset-meta { display: none; }
}

/* Vista all'oculare: finestra quadrata con canvas 2D */
.sensor-inset--round { --inset-w: 232px; }
.sensor-inset--round .sensor-inset-view {
  aspect-ratio: 1;
  background: #020305;
  box-shadow: none;
  border-left: 1px solid var(--panel-border);
  border-right: 1px solid var(--panel-border);
}
.eyepiece-canvas { display: block; width: 100%; height: 100%; }
.rec-dot--eye { background: var(--accent); box-shadow: 0 0 6px var(--accent); }

@media (max-width: 760px) {
  .sensor-inset--round { --inset-w: 140px; }
}

/* Sensore: luce in arrivo | immagine digitale */
.sensor-inset--pair { --inset-w: 320px; }
.sensor-inset--pair .sensor-inset-head span { flex: 1 1 0; }
.sensor-inset--pair .sensor-inset-view {
  aspect-ratio: auto;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  padding: 6px;
  background: var(--panel-strong);
  box-shadow: none;
  border-left: 1px solid var(--panel-border);
  border-right: 1px solid var(--panel-border);
}
.pair-canvas {
  display: block;
  width: 100%;
  aspect-ratio: 3 / 2;
  border-radius: 3px;
  image-rendering: pixelated;
  background: #05070b;
}

@media (max-width: 760px) {
  .sensor-inset--pair { --inset-w: 220px; }
  .sensor-inset--pair .sensor-inset-head span:last-child { display: inline; }
}

/* Immagine finale: ritaglio 1:1 + mappa del campo */
.sensor-inset--photo { --inset-w: 420px; }
.sensor-inset--photo .sensor-inset-view {
  position: relative;
  aspect-ratio: 3 / 2;
  background: #000;
  box-shadow: none;
  border-left: 1px solid var(--panel-border);
  border-right: 1px solid var(--panel-border);
}
.photo-canvas {
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
}
.photo-map {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 26%;
  aspect-ratio: 1;
  border-radius: 4px;
  outline: 1px solid rgba(255, 255, 255, 0.14);
}

@media (max-width: 1100px) {
  .sensor-inset--photo { --inset-w: 320px; }
}
@media (max-width: 760px) {
  .sensor-inset--photo { --inset-w: 230px; }
}
