/* ---------------------------------------------------------------------------
   Consensive GLoD WebGL demo — front-end styling.
   Works full-bleed on desktop, smartphone (portrait + landscape) and tablet.
   All GUI is HTML/CSS here; Unity only renders the 3D canvas.
--------------------------------------------------------------------------- */
:root {
  --bg: #0e0f12;
  --panel-bg: rgba(18, 20, 24, 0.92);
  --panel-border: #2a2d34;
  --text: #e7e9ee;
  --muted: #9aa0ab;
  --accent: #3aa0ff;
  --accent-2: #1b6fc0;
  --brand: #004b70;            /* corporate blue (slider handle, pivot toggle) */
  --danger: #e0584f;
  --ok: #4bd07a;
  --row-gap: 10px;
  --radius: 10px;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  width: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior: none;
}

/* --- Stage / canvas ------------------------------------------------------ */
#stage {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
}

#unity-canvas {
  display: block;
  width: 100%;
  height: 100%;
  background: var(--bg);
  /* Stop the browser from interpreting touch as scroll/zoom on the canvas. */
  touch-action: none;
}

/* Transparent layer that captures all camera gestures above the canvas. */
#gesture-layer {
  position: fixed;
  inset: 0;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

/* --- Loading overlay ----------------------------------------------------- */
#loader-overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  z-index: 50;
  transition: opacity 0.4s ease;
}
#loader-overlay.hidden { opacity: 0; pointer-events: none; }

.loader-box { width: min(320px, 70vw); text-align: center; }
.loader-box .brand {
  font-weight: 600;
  letter-spacing: 0.04em;
  margin-bottom: 14px;
  color: var(--text);
}
.bar {
  height: 6px;
  border-radius: 3px;
  background: #23262d;
  overflow: hidden;
}
#loader-bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--accent-2), var(--accent));
  transition: width 0.2s ease;
}
#loader-text { margin-top: 10px; color: var(--muted); font-size: 13px; }

/* --- Stacked floating controls (hamburger above gear) + hint labels ------ */
.fab {
  position: fixed;
  left: calc(12px + var(--safe-l));
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 10px;
  /* The wrapper is just layout (icon + hint label). Only its button is
     interactive, so the wide label box never swallows taps meant for panels
     underneath (e.g. the settings card's close button on the right). */
  pointer-events: none;
  transition: top 0.28s cubic-bezier(0.22, 0.61, 0.36, 1),
              transform 0.28s cubic-bezier(0.22, 0.61, 0.36, 1),
              opacity 0.2s ease;
}
.fab-menu { top: calc(12px + var(--safe-t)); }
.fab-gear { top: calc(64px + var(--safe-t)); }

/* Pivot-mode toggle lives top-right, mirroring the left-hand FABs. */
.fab-pivot {
  left: auto;
  right: calc(12px + var(--safe-r));
  top: calc(12px + var(--safe-t));
}

/* While the settings card is open: the hamburger drops to just below the card
   (stays reachable), and the gear slides up out of the way — the card's × closes it.
   --settings-h is set from the card's measured height in ui.js. */
body.settings-open .fab-menu {
  top: calc(12px + var(--safe-t) + var(--settings-h, 170px) + 10px);
}
body.settings-open .fab-gear {
  transform: translateY(-160px);
  opacity: 0;
  pointer-events: none;
}

.fab-label {
  pointer-events: none;          /* a hint, not a control — let gestures pass */
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
  backdrop-filter: blur(8px);
  transition: opacity 0.6s ease;
}
/* Intro hints fade out once and stay gone — same on desktop and touch. */
.fab-label.faded { opacity: 0; pointer-events: none; }

.menu-toggle, .gear-toggle, .pivot-toggle {
  flex: 0 0 auto;
  pointer-events: auto;        /* re-enable taps on the button itself */
  width: 44px;
  height: 44px;
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  background: var(--panel-bg);
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  backdrop-filter: blur(8px);
}
.menu-toggle { flex-direction: column; gap: 5px; }
.menu-toggle span {
  display: block;
  width: 20px;
  height: 2px;
  background: var(--text);
  border-radius: 2px;
}
/* Hide the hamburger and its label while the drawer is open. */
.menu-toggle.active,
.menu-toggle.active + .fab-label { opacity: 0; pointer-events: none; }

.gear-toggle.active { border-color: var(--accent); color: var(--accent); }

/* The nav-mode toggle is always an active tool (pivot or depth cursor), so it
   stays filled corporate blue; the icon indicates which mode is current. */
.pivot-toggle { background: var(--brand); border-color: var(--brand); color: #fff; }
.pivot-toggle .nav-ico { display: none; }
.pivot-toggle[data-mode="pivot"] .nav-ico-pivot { display: block; }
.pivot-toggle[data-mode="depthCursor"] .nav-ico-cursor { display: block; }

/* --- Floating detail/stats card over the canvas ------------------------- */
.settings {
  position: fixed;
  top: calc(12px + var(--safe-t));   /* takes the top spot once icons slide away */
  left: calc(12px + var(--safe-l));
  /* Never grow under the top-right nav toggle (44px wide, 12px inset): leave a
     10px gap to it, so on narrow phones the card shrinks instead of colliding. */
  width: min(320px, calc(100vw - 78px - var(--safe-l) - var(--safe-r)));
  z-index: 25;
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  backdrop-filter: blur(10px);
  padding: 14px;
  opacity: 0;
  transform: translateY(-8px);
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
}
.settings.open { opacity: 1; transform: translateY(0); pointer-events: auto; }
.settings-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}
.settings-head-right { display: flex; align-items: center; gap: 8px; }
#settings-close { width: 28px; height: 28px; font-size: 22px; }

/* --- Panel --------------------------------------------------------------- */
.panel {
  position: fixed;
  top: 0;
  left: 0;
  height: 100%;
  width: min(320px, 86vw);
  background: var(--panel-bg);
  border-right: 1px solid var(--panel-border);
  backdrop-filter: blur(10px);
  z-index: 40;
  display: flex;
  flex-direction: column;
  padding: calc(14px + var(--safe-t)) 14px calc(14px + var(--safe-b)) calc(14px + var(--safe-l));
  transform: translateX(-105%);
  transition: transform 0.28s cubic-bezier(0.22, 0.61, 0.36, 1);
  overflow-y: auto;
}
.panel.open { transform: translateX(0); }

/* Dark scrollbar to match the GUI (Firefox + WebKit/Blink). */
.panel { scrollbar-width: thin; scrollbar-color: #3a3f47 transparent; }
.panel::-webkit-scrollbar { width: 10px; }
.panel::-webkit-scrollbar-track { background: transparent; }
.panel::-webkit-scrollbar-thumb {
  background: #3a3f47;
  border-radius: 6px;
  border: 2px solid transparent;
  background-clip: padding-box;
}
.panel::-webkit-scrollbar-thumb:hover { background: #4a515c; }

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}
.panel-header h1 { font-size: 18px; margin: 0; font-weight: 600; }
.header-actions { display: flex; align-items: center; gap: 8px; }

.lang-switch { display: flex; border: 1px solid var(--panel-border); border-radius: 8px; overflow: hidden; }
.lang-btn {
  background: #1b1e24;
  color: var(--muted);
  border: none;
  padding: 6px 9px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}
.lang-btn + .lang-btn { border-left: 1px solid var(--panel-border); }
.lang-btn.active { background: var(--accent); color: #fff; }

.slider-head { justify-content: space-between; margin-bottom: 6px; }
.slider-head label { flex: 1; color: var(--muted); font-size: 13px; }
.tri-value { font-variant-numeric: tabular-nums; font-size: 13px; color: var(--text); text-transform: none; }
/* Dark, custom-styled range slider (no white native track/thumb on desktop). */
.slider {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 6px;
  border-radius: 3px;
  background: #23262d;
  outline: none;
  cursor: pointer;
}
.slider::-webkit-slider-runnable-track {
  height: 6px;
  border-radius: 3px;
  background: #23262d;
}
.slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 24px;
  height: 24px;
  margin-top: -9px;            /* centre the 24px thumb on the 6px track */
  border: none;
  border-radius: 50%;
  background: var(--brand);
  cursor: pointer;
}
.slider::-moz-range-track {
  height: 6px;
  border-radius: 3px;
  background: #23262d;
}
.slider::-moz-range-thumb {
  width: 24px;
  height: 24px;
  border: none;
  border-radius: 50%;
  background: var(--brand);
  cursor: pointer;
}
.slider:focus-visible { box-shadow: 0 0 0 2px rgba(58, 160, 255, 0.4); }

.stats { margin-top: 12px; }
.stat-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  font-size: 13px;
  color: var(--muted);
  padding: 3px 0;
}
.stat-val { color: var(--text); font-variant-numeric: tabular-nums; }
.stat-attrib {
  margin-top: 8px;
  font-size: 12px;
  line-height: 1.4;
  font-style: italic;
}

/* Persistent attribution footer over the canvas (hidden until it has text). */
.attrib-footer {
  position: fixed;
  left: 50%;
  bottom: calc(10px + var(--safe-b));
  transform: translateX(-50%);
  display: inline-block;          /* hug the text so the pill isn't full-width */
  max-width: min(92vw, 720px);
  text-align: center;
  font-size: 11px;
  line-height: 1.35;
  color: var(--text);
  pointer-events: none;
  z-index: 20;
  background: rgba(14, 15, 18, 0.75);   /* 75% opaque dark pill */
  padding: 5px 12px;
  border-radius: 999px;
  backdrop-filter: blur(4px);
  transition: opacity 0.45s ease, transform 0.45s ease;
}
.attrib-footer:empty { display: none; }
/* Collapsed: fade + settle down, then the "i" button below takes over. */
.attrib-footer.collapsed {
  opacity: 0;
  transform: translateX(-50%) translateY(8px);
}

/* Small "i" info button in the lower-right corner — the collapsed attribution.
   Hidden (scaled down) until the pill folds away; tapping it re-expands. */
.attrib-info {
  position: fixed;
  right: calc(12px + var(--safe-r));
  bottom: calc(12px + var(--safe-b));
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 1px solid var(--panel-border);
  background: rgba(14, 15, 18, 0.75);
  color: var(--text);
  font-family: Georgia, "Times New Roman", serif;
  font-style: italic;
  font-size: 16px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  backdrop-filter: blur(4px);
  z-index: 20;
  opacity: 0;
  transform: scale(0.6);
  pointer-events: none;
  transition: opacity 0.4s ease, transform 0.4s ease;
}
.attrib-info.show { opacity: 1; transform: scale(1); pointer-events: auto; }

.hint-list { list-style: none; margin: 0; padding: 0; }
.hint-list li {
  font-size: 13px;
  color: var(--muted);
  padding: 4px 0;
  border-bottom: 1px dashed #23262d;
}
.hint-list li:last-child { border-bottom: none; }

.panel-section { margin: 14px 0; }
.panel-section h2 {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin: 0 0 8px;
}

.row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: var(--row-gap);
}
.row label { flex: 0 0 96px; font-size: 13px; color: var(--muted); }
.row select, .row input[type="color"] { flex: 1; }

select {
  background: #1b1e24;
  color: var(--text);
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  padding: 8px;
  font-size: 14px;
}
input[type="color"] {
  height: 34px;
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  background: #1b1e24;
  padding: 2px;
}

/* --- Background swatches -------------------------------------------------- */
.bg-block { margin-bottom: var(--row-gap); }
.bg-block > label {
  display: block;
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 8px;
}
.swatches { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.swatch {
  width: 30px;
  height: 30px;
  padding: 0;
  border-radius: 7px;
  border: 1px solid var(--panel-border);
  background-color: currentColor;   /* unused; color set inline per button */
  cursor: pointer;
}
/* Paint each preset from its data-color via a small inline-free approach. */
#bg-swatches .swatch[data-color="#a9b8c4"] { background: #a9b8c4; }
#bg-swatches .swatch[data-color="#7c828a"] { background: #7c828a; }
#bg-swatches .swatch[data-color="#33403a"] { background: #33403a; }
#bg-swatches .swatch[data-color="#2b3442"] { background: #2b3442; }
.swatch.active { box-shadow: 0 0 0 2px var(--accent); border-color: var(--accent); }
/* Custom picker sits inline with the swatches, same size. */
#bg-color { width: 34px; height: 30px; flex: 0 0 auto; }

.btn {
  flex: 1;
  background: #1b1e24;
  color: var(--text);
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  padding: 10px;
  font-size: 14px;
  cursor: pointer;
}
.btn:hover { border-color: var(--accent); }
.btn:active { background: #23262d; }

.icon-btn {
  background: transparent;
  border: none;
  color: var(--muted);
  font-size: 24px;
  line-height: 1;
  cursor: pointer;
  width: 32px;
  height: 32px;
}

/* --- Scene list ---------------------------------------------------------- */
.scene-list { list-style: none; margin: 0; padding: 0; }
.scene-list li {
  padding: 11px 12px;
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  margin-bottom: 8px;
  cursor: pointer;
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.scene-list li:hover { border-color: var(--accent); }
.scene-list li.active {
  border-color: var(--accent);
  background: rgba(58, 160, 255, 0.12);
}
.scene-list li .spinner { display: none; }
.scene-list li.loading .spinner {
  display: inline-block;
  width: 14px; height: 14px;
  border: 2px solid var(--muted);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.muted { color: var(--muted); font-size: 13px; }

/* --- Footer / status ----------------------------------------------------- */
.panel-footer {
  margin-top: auto;
  display: flex;
  align-items: center;
  gap: 8px;
  padding-top: 12px;
  border-top: 1px solid var(--panel-border);
}
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.dot.ok { background: var(--ok); }
.dot.err { background: var(--danger); }

/* --- Toast --------------------------------------------------------------- */
.toast {
  position: fixed;
  bottom: calc(18px + var(--safe-b));
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  color: var(--text);
  padding: 10px 16px;
  border-radius: 10px;
  font-size: 14px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 60;
  max-width: 86vw;
  text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.error { border-color: var(--danger); }

/* --- Landscape phones: keep the panel from covering everything ----------- */
@media (orientation: landscape) and (max-height: 500px) {
  .panel { width: min(300px, 70vw); }
  .panel-section { margin: 10px 0; }
}
