:root {
  --bg: #fcf8f2;
  --surface: #ffffff;
  --ink: #253254;    /* blu */
  --muted: #3c5a91;  /* azzurro */
  --accent: #d2a367; /* ocra */
  --line: rgba(37, 50, 84, 0.16);
  --rule: rgba(210, 163, 103, 0.65); /* ocra hairline, matches the exhibition panels' dividers */

  --font-title: "Lora", Georgia, "Times New Roman", serif;
  --font-body: "Montserrat", ui-sans-serif, system-ui, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  /* Without this, mobile Safari can silently boost font sizes across an
     orientation change (its "text autosizing" heuristic re-triggers on
     reflow) — most noticeable on the panel, which re-measures its
     scrollable content on every rotation. */
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

#app {
  position: fixed;
  inset: 0;
  overflow: hidden;
}

#stage {
  position: absolute;
  inset: 0;
  touch-action: none;
  /* touch-action alone stops panning/pinch-zoom but not a long-press's
     native callout menu (iOS) or text/element selection highlight
     (Android/desktop) — both would otherwise fire on a long tap-and-hold
     over the canvas, which reads as an unwanted "selection" popup. */
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}

#stage canvas { display: block; width: 100%; height: 100%; }

.status {
  position: absolute;
  bottom: 14px;
  left: 14px;
  font-size: 11px;
  color: var(--muted);
  background: var(--surface);
  border: 1px solid var(--line);
  padding: 5px 9px;
  border-radius: 4px;
  pointer-events: none;
  max-width: calc(100% - 28px);
}
.status[hidden] { display: none; }

.loading-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  background: var(--bg);
  pointer-events: none;
  transition: opacity 250ms ease-out;
}
.loading-overlay[hidden] { display: none; }
.loading-overlay.fade-out { opacity: 0; }

.spinner {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 3px solid var(--line);
  border-top-color: var(--accent);
  animation: spin 900ms linear infinite;
}
#loadingText {
  font-size: 12.5px;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: var(--muted);
}
.loading-percent {
  font-size: 20px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
}
.loading-percent[hidden] { display: none; }

@keyframes spin {
  to { transform: rotate(360deg); }
}

@media (prefers-reduced-motion: reduce) {
  .spinner {
    animation: none;
    border-top-color: var(--line);
    opacity: 0.6;
  }
}

/* Drag-to-rotate/look-around cue: the finger-only.png icon sliding right
   then left (ease-in-out), shown briefly the first time the model
   appears and again the first time Interior mode is entered — never a
   third time in the same session (state tracked in js/main.js, not
   persisted). */
.gesture-hint {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  opacity: 0;
  transition: opacity 300ms ease-out;
}
.gesture-hint[hidden] { display: none; }
.gesture-hint.visible { opacity: 1; }

.gesture-hint-icon {
  width: 90px;
  height: auto;
  opacity: 0;
  /* The icon is white line-art — a dark contour plus a soft ambient
     shadow keeps it legible over both the light page background and
     the dark model. */
  filter:
    drop-shadow(0 0 2px rgba(37, 50, 84, 0.9))
    drop-shadow(0 4px 10px rgba(37, 50, 84, 0.35));
}
.gesture-hint.visible .gesture-hint-icon {
  animation: gestureFingerSlide 2.4s ease-in-out 2;
}

@keyframes gestureFingerSlide {
  0%   { transform: translateX(0);     opacity: 0; } /* start at center, invisible */
  8%   { transform: translateX(0);     opacity: 1; } /* fade in at center */
  40%  { transform: translateX(34px);  opacity: 1; } /* ease over to the right */
  46%  { transform: translateX(34px);  opacity: 0; } /* fade out at the right */
  54%  { transform: translateX(0);     opacity: 0; } /* reset to center, still invisible */
  62%  { transform: translateX(0);     opacity: 1; } /* fade back in at center */
  92%  { transform: translateX(-34px); opacity: 1; } /* ease over to the left */
  98%  { transform: translateX(-34px); opacity: 0; } /* fade out at the left */
  100% { transform: translateX(0);     opacity: 0; } /* reset to center for the next loop */
}

@media (prefers-reduced-motion: reduce) {
  .gesture-hint.visible .gesture-hint-icon {
    animation: none;
    opacity: 0.9;
    transform: translateX(0);
  }
}

.hint {
  position: absolute;
  top: 14px;
  left: 14px;
  font-size: 11px;
  color: var(--muted);
  background: var(--surface);
  border: 1px solid var(--line);
  padding: 5px 9px;
  border-radius: 4px;
  pointer-events: none;
  opacity: 1;
  transition: opacity 250ms ease-out;
}
.hint.hint-hidden {
  opacity: 0;
  pointer-events: none;
}

/* Sits at the same spot as .hint and cross-fades with it — shown until
   the first drag/tap, then replaced by this "HELP" button (styled like
   the language switch); pressing it brings the hint text back, which
   again hides itself on the next interaction. */
.hint-toggle {
  position: absolute;
  top: 14px;
  left: 14px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 250ms ease-out;
}
.hint-toggle.visible {
  opacity: 1;
  pointer-events: auto;
}

.hud-controls {
  position: absolute;
  top: 14px;
  right: 14px;
  display: flex;
  gap: 8px;
}

.mode-dock {
  position: absolute;
  left: 50%;
  bottom: 20px;
  transform: translateX(-50%);
  opacity: 1;
  transition: opacity 250ms ease-out;
}
.mode-dock.mode-dock-hidden {
  opacity: 0;
  pointer-events: none;
}

.segmented {
  display: flex;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 6px;
  overflow: hidden;
}

.segmented button {
  appearance: none;
  border: none;
  background: transparent;
  color: var(--muted);
  font-family: var(--font-body);
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: 0.02em;
  padding: 7px 11px;
  cursor: pointer;
}
.segmented button + button { border-left: 1px solid var(--line); }
.segmented button.active { background: var(--accent); color: var(--ink); }
.segmented button:disabled { opacity: 0.5; cursor: default; }
.segmented button:not(.active):hover:not(:disabled) { color: var(--ink); background: var(--bg); }
.segmented button:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }

.segmented--lg { border-radius: 9px; }
.segmented--lg button { font-size: 17px; padding: 10px 17px; }

@media (max-width: 480px) {
  .hint { max-width: 54%; }
}

.panel {
  position: fixed;
  top: 0;
  right: 0;
  height: 100%;
  width: 380px;
  max-width: 92vw;
  background: var(--surface);
  border-left: 1px solid var(--line);
  box-shadow: -20px 0 40px rgba(37, 50, 84, 0.16);
  transform: translateX(105%);
  transition: transform 320ms ease-out;
  display: flex;
  flex-direction: column;
}
.panel.open { transform: translateX(0); }

/* Header stays fixed in place — only .panel-scroll below it scrolls, so
   the close/play buttons and title are always reachable. */
.panel-header {
  position: relative;
  flex: none;
  padding: 26px 24px 0;
}

.panel-scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  /* Extra bottom padding so the floating "Ascolta" chip (bottom-right,
     see .listen-chip) never covers the last line of text — scrolling
     to the end clears the chip's own footprint. */
  padding: 0 24px 96px;
}

.panel-actions {
  position: absolute;
  top: 14px;
  right: 14px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.panel-close {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--muted);
  font-size: 16px;
  cursor: pointer;
}
.panel-close:hover { color: var(--ink); border-color: var(--accent); }

/* "Ascolta" chip — a pill-shaped play/stop toggle with a label and the
   narration's running time. It floats bottom-right over the scrolling
   text (same position on desktop and mobile — .panel is the containing
   block for both the side-drawer and bottom-sheet layouts), fades in
   once we know the narration actually exists (see refreshPlayAvailability
   in js/main.js), and gives itself a small periodic bounce so it isn't
   missed against the busy text behind it. */
.listen-chip {
  position: absolute;
  right: 20px;
  bottom: 20px;
  z-index: 2;
  display: flex;
  align-items: center;
  gap: 10px;
  width: fit-content;
  max-width: calc(100% - 40px);
  padding: 5px 18px 5px 5px;
  border: none;
  border-radius: 999px;
  background: var(--accent);
  box-shadow: 0 4px 14px rgba(37, 50, 84, 0.56);
  cursor: pointer;
  text-align: left;
  opacity: 0;
  transition: opacity 260ms ease-out;
}
.listen-chip[hidden] { display: none; }
/* The panel slides fully off-screen on close, but by a distance equal
   to its OWN height — since the chip is pinned near that edge, without
   this it could still peek into view during/after the slide. */
.panel:not(.open) .listen-chip { display: none; }

.listen-chip.visible {
  opacity: 1;
  animation: listenChipBounce 10s ease-in-out infinite;
}
@keyframes listenChipBounce {
  0%, 100% { transform: translateY(0); }
  2%       { transform: translateY(-9px); }
  4%       { transform: translateY(0); }
  5.5%     { transform: translateY(-4px); }
  7%       { transform: translateY(0); }
}
/* Don't nudge the user to listen while they're already listening. Named
   with both classes (rather than relying on source order against the
   .visible rule above) so it wins regardless of stylesheet order. */
.listen-chip.visible.is-playing { animation: none; }

@media (prefers-reduced-motion: reduce) {
  .listen-chip.visible { animation: none; }
}

.listen-toggle {
  position: relative;
  flex: none;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--ink);
  display: flex;
  align-items: center;
  justify-content: center;
}
.listen-toggle-progress {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  transform: rotate(-90deg);
}
.listen-toggle-progress .track {
  fill: none;
  stroke: rgba(255, 255, 255, 0.28);
  stroke-width: 2;
}
.listen-toggle-progress .fill {
  fill: none;
  stroke: #fff;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-dasharray: 97.4; /* 2*pi*15.5 */
  stroke-dashoffset: 97.4;
  transition: stroke-dashoffset 120ms linear;
}
.listen-toggle-icon {
  position: relative;
  width: 28px;
  height: 28px;
  fill: #fff;
}

.listen-text {
  display: flex;
  flex-direction: column;
  line-height: 1.25;
}
.listen-label {
  font-family: var(--font-body);
  font-size: 13.5px;
  font-weight: 700;
  color: var(--ink);
}
.listen-duration {
  font-family: var(--font-body);
  font-size: 11.5px;
  color: rgba(37, 50, 84, 0.62);
}
.listen-duration:empty { display: none; }

.listen-chip:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }
@media (hover: hover) and (pointer: fine) {
  .listen-chip:hover { box-shadow: 0 5px 16px rgba(37, 50, 84, 0.56); }
}

.panel-tag {
  font-family: var(--font-body);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--accent);
  margin-top: 6px;
  max-width: calc(100% - 50px); /* keep clear of the close button */
}

.image-placeholder {
  height: 160px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: repeating-linear-gradient(
    45deg, var(--bg), var(--bg) 10px, var(--surface) 10px, var(--surface) 20px
  );
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  font-family: var(--font-body);
  font-size: 12.5px;
}

.panel-title {
  font-family: var(--font-title);
  font-size: 23px;
  font-weight: 700;
  line-height: 1.25;
  margin: 8px 0 0;
  color: var(--ink);
}

.panel-rule {
  border: none;
  border-top: 1px solid var(--rule);
  margin: 14px 0;
}

.panel-meta {
  margin: 0 0 16px;
  padding: 12px 14px;
  background: var(--bg);
  border-left: 3px solid var(--accent);
  border-radius: 4px;
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 5px 12px;
  align-items: baseline;
}
.panel-meta[hidden] { display: none; }
.panel-meta dt {
  margin: 0;
  color: var(--muted);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-size: 10.5px;
  line-height: 1.4;
  white-space: nowrap;
}
.panel-meta dd {
  margin: 0;
  color: var(--ink);
  font-size: 12.5px;
  line-height: 1.4;
}

.panel-pullquote {
  margin: 0 0 16px;
  padding: 2px 0 2px 16px;
  border-left: 3px solid var(--rule);
  font-family: var(--font-title);
  font-style: italic;
  font-size: 15px;
  line-height: 1.5;
  color: var(--muted);
}

.panel-body {
  font-family: var(--font-body);
  font-size: 14.5px;
  line-height: 1.6;
  color: var(--ink);
}
.panel-body p { margin: 0 0 10px; }
.panel-body strong { color: var(--ink); }

.panel-figure { margin: 14px 0; }
.panel-figure-frame { border-radius: 8px; overflow: hidden; }
.panel-figure-frame img { display: block; width: 100%; height: auto; }
.panel-figure figcaption {
  margin-top: 6px;
  font-size: 11px;
  line-height: 1.4;
  font-style: italic;
  color: var(--muted);
}

@media (max-width: 680px) {
  .panel {
    top: auto;
    bottom: 0;
    left: 0;
    right: 0;
    width: auto;
    max-width: none;
    height: auto;
    max-height: 66vh;
    border-left: none;
    border-top: 1px solid var(--line);
    border-radius: 14px 14px 0 0;
    transform: translateY(100%);
  }
  .panel.open { transform: translateY(0); }
}
