:root {
  /* The panel floats over a live 3D scene, so its tint is deliberately thin:
     just enough to hold text contrast, with a heavy blur so the model stays
     readable through it. */
  --panel-bg: rgba(14, 21, 29, .5);
  --panel-blur: blur(18px) saturate(140%);
  --panel-border: rgba(255, 255, 255, .1);

  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
}

/* Without a backdrop filter the tint alone has to carry the contrast. */
@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  :root { --panel-bg: rgba(14, 21, 29, .88); }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;          /* no pull-to-refresh over the canvas */
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  background: radial-gradient(circle at 50% 26%, #3d5c78 0%, #223444 55%, #10171f 100%);
  color: #e8eef3;
  -webkit-tap-highlight-color: transparent;
}

#app { position: fixed; inset: 0; touch-action: none; }
canvas { display: block; }

button { font-family: inherit; touch-action: manipulation; }

/* ---- Title ---- */
#titlebar {
  position: fixed;
  top: calc(18px + var(--safe-t));
  left: calc(22px + var(--safe-l));
  z-index: 10;
  pointer-events: none;
  transition: opacity .4s;
}
#titlebar h1 {
  margin: 0;
  font-size: 26px;
  font-weight: 700;
  letter-spacing: .5px;
  color: #f4d9a6;
  text-shadow: 0 2px 12px rgba(0,0,0,.6);
}
#titlebar h1 span {
  margin-left: 8px;
  font-size: 18px;
  font-weight: 500;
  color: #c9a771;
}
#titlebar p {
  margin: 4px 0 0;
  font-size: 13px;
  color: #9fb2c2;
}

/* ---- Control panel ---- */
#panel {
  position: fixed;
  top: calc(92px + var(--safe-t));
  left: calc(22px + var(--safe-l));
  bottom: 22px;
  z-index: 30;
  width: 250px;
  display: flex;
  flex-direction: column;
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: 14px;
  backdrop-filter: var(--panel-blur);
  -webkit-backdrop-filter: var(--panel-blur);
  box-shadow: 0 12px 40px rgba(0,0,0,.45);
  transition: opacity .25s, transform .25s, visibility .25s;
}
body.panel-hidden #panel {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: translateX(-16px);
}

/* The header carries the panel's name and its always-visible close control. */
#panelHead {
  flex: none;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 11px 11px 10px 18px;
  border-bottom: 1px solid rgba(255,255,255,.07);
}
.panelTitle {
  margin: 0;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: #cfe0ee;
}
#panelGrip { display: none; }

#panelClose {
  flex: none;
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  font-size: 21px;
  line-height: 1;
  color: #dbe6ef;
  background: rgba(255,255,255,.07);
  border: 1px solid rgba(255,255,255,.14);
  border-radius: 9px;
  cursor: pointer;
  transition: background .15s, color .15s;
}
#panelClose:hover { background: rgba(255,255,255,.18); color: #fff; }

#panelBody {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;       /* scrolling the panel never drags the page */
  -webkit-overflow-scrolling: touch;
  padding: 14px 18px 16px;
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,.18) transparent;
}
#panelBody h2 {
  margin: 16px 0 8px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 1.4px;
  color: #7fa6c9;
}
#panelBody h2:first-child { margin-top: 0; }

/* The footer close only earns its space on a phone, where the panel is a sheet
   you have to dismiss to see the model at all. */
#panelDone { display: none; }

.row {
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: 14px;
  padding: 5px 0;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
}
.row input[type="checkbox"] { width: 16px; height: 16px; accent-color: #f0a94b; cursor: pointer; }
.row.slider { flex-direction: column; align-items: stretch; gap: 4px; }
.row.slider span { font-size: 13px; color: #b9c8d6; }
.row.slider input { width: 100%; accent-color: #ef7d3b; }

/* ---- Panel toggle ---- */
#panelToggle {
  position: fixed;
  top: calc(92px + var(--safe-t));
  left: calc(22px + var(--safe-l));
  z-index: 25;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 44px;
  height: 44px;
  font-size: 20px;
  line-height: 1;
  color: #f4d9a6;
  background: rgba(16,24,33,.7);
  border: 1px solid rgba(255,255,255,.14);
  border-radius: 11px;
  cursor: pointer;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  box-shadow: 0 8px 24px rgba(0,0,0,.4);
  transition: opacity .2s, background .15s;
}
#panelToggle:hover { background: rgba(240,169,75,.24); }
#panelToggle .btnLabel { display: none; font-size: 14px; font-weight: 600; }
body:not(.panel-hidden) #panelToggle { opacity: 0; pointer-events: none; }

/* ---- Dedicated "Play guided tour" button, outside the panel ----
   The tour is the headline feature, so it gets a control that is reachable
   without opening the panel first. It hides itself while a tour is running —
   the caption bar carries the stop/pause controls then. */
#tourFab {
  position: fixed;
  top: calc(20px + var(--safe-t));
  left: 50%;
  transform: translateX(-50%);
  z-index: 24;
  display: flex;
  align-items: center;
  gap: 8px;
  height: 44px;
  padding: 0 20px;
  font-size: 14px;
  font-weight: 600;
  color: #1a1206;
  background: linear-gradient(180deg, #f5c67d, #efb14e);
  border: 1px solid rgba(255,255,255,.35);
  border-radius: 24px;
  cursor: pointer;
  box-shadow: 0 8px 26px rgba(0,0,0,.4), 0 0 0 1px rgba(0,0,0,.15);
  transition: opacity .25s, transform .15s, box-shadow .15s;
}
#tourFab:hover { box-shadow: 0 10px 30px rgba(240,169,75,.45), 0 0 0 1px rgba(0,0,0,.15); }
#tourFab:active { transform: translateX(-50%) scale(.96); }
#tourFab span[aria-hidden] { font-size: 12px; }
body.touring #tourFab { opacity: 0; pointer-events: none; }

/* ---- Scrim. Phones only: there, the panel is modal. ---- */
#scrim {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 28;
  background: rgba(4,8,12,.45);
  opacity: 0;
  visibility: hidden;
  transition: opacity .25s, visibility .25s;
}

/* ---- Segmented buttons (material / language) ---- */
.seg { display: flex; gap: 6px; }
.seg button {
  flex: 1;
  min-height: 36px;
  padding: 7px 4px;
  font-size: 13px;
  color: #cfe0ee;
  background: rgba(255,255,255,.06);
  border: 1px solid rgba(255,255,255,.12);
  border-radius: 8px;
  cursor: pointer;
  transition: background .15s;
}
.seg button:hover { background: rgba(255,255,255,.14); }
.seg button.active {
  color: #1a1206;
  background: #f0b968;
  border-color: #f0b968;
  font-weight: 700;
}

#playTour, #resetView {
  width: 100%;
  min-height: 38px;
  padding: 9px;
  margin-bottom: 4px;
  font-size: 13px;
  color: #e8eef3;
  background: rgba(240,169,75,.16);
  border: 1px solid rgba(240,169,75,.45);
  border-radius: 8px;
  cursor: pointer;
  transition: background .15s;
}
#playTour:hover, #resetView:hover { background: rgba(240,169,75,.3); }
#resetView {
  margin-top: 8px;
  background: rgba(255,255,255,.05);
  border-color: rgba(255,255,255,.14);
}
#resetView:hover { background: rgba(255,255,255,.12); }

/* ---- Legend. A <details> so it can be folded away where height is scarce. ---- */
#legend {
  margin-top: 16px;
  padding-top: 12px;
  border-top: 1px solid rgba(255,255,255,.08);
  font-size: 12px;
  color: #a9bccb;
}
#legend > summary {
  margin-bottom: 8px;
  color: #cfe0ee;
  font-weight: 700;
  cursor: pointer;
  list-style: none;
  user-select: none;
  -webkit-user-select: none;
}
#legend > summary::-webkit-details-marker { display: none; }
#legend > summary::after {
  content: "▾";
  float: right;
  color: #7fa6c9;
}
#legend[open] > summary::after { content: "▴"; }
#legend ol { margin: 0; padding-left: 18px; line-height: 1.55; }
#legend i { color: #f4d9a6; font-style: normal; }
#legend .tip { margin: 10px 0 0; font-style: italic; color: #7f93a4; }

/* ---- Part inspector ---- */
#info {
  position: fixed;
  top: calc(92px + var(--safe-t));
  right: calc(22px + var(--safe-r));
  z-index: 20;
  width: 292px;
  max-height: calc(100vh - 130px);
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 18px 20px 20px;
  background: rgba(16,24,33,.7);
  border: 1px solid rgba(159,208,238,.22);
  border-radius: 14px;
  backdrop-filter: var(--panel-blur);
  -webkit-backdrop-filter: var(--panel-blur);
  box-shadow: 0 12px 40px rgba(0,0,0,.5);
  opacity: 0;
  transform: translateX(14px);
  pointer-events: none;
  transition: opacity .22s, transform .22s;
}
#info.show { opacity: 1; transform: none; pointer-events: auto; }
#info h3 {
  margin: 0;
  padding-right: 34px;              /* clear of the close button */
  font-size: 19px;
  color: #cfe6ff;
}
#info .alt { margin: 2px 0 0; font-size: 14px; color: #8fa8bd; }
#info .dim {
  display: inline-block;
  margin: 10px 0 0;
  padding: 3px 9px;
  font-size: 12px;
  color: #ffe4b0;
  background: rgba(240,169,75,.14);
  border: 1px solid rgba(240,169,75,.35);
  border-radius: 20px;
}
#info .desc {
  margin: 12px 0 0;
  font-size: 13.5px;
  line-height: 1.62;
  color: #b9cbd9;
}
#infoClose {
  position: absolute;
  top: 10px;
  right: 10px;
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  font-size: 20px;
  line-height: 1;
  color: #cbd8e4;
  background: rgba(255,255,255,.06);
  border: 1px solid rgba(255,255,255,.12);
  border-radius: 8px;
  cursor: pointer;
}
#infoClose:hover { background: rgba(255,255,255,.18); color: #fff; }

/* ---- Guided-tour caption bar ---- */
#caption {
  position: fixed;
  left: 50%;
  bottom: calc(26px + var(--safe-b));
  z-index: 22;
  width: min(760px, calc(100vw - 340px));
  padding: 0 0 16px;
  background: rgba(12,18,25,.8);
  border: 1px solid rgba(255,255,255,.1);
  border-radius: 14px;
  backdrop-filter: var(--panel-blur);
  -webkit-backdrop-filter: var(--panel-blur);
  box-shadow: 0 14px 44px rgba(0,0,0,.55);
  opacity: 0;
  transform: translate(-50%, 16px);
  pointer-events: none;
  transition: opacity .3s, transform .3s;
  overflow: hidden;
}
#caption.show { opacity: 1; transform: translate(-50%, 0); }

#capBar { height: 3px; background: rgba(255,255,255,.08); }
#capFill {
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, #ef7d3b, #f0b968);
  transition: width .2s linear;
}
#capHead {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 12px 0 20px;
  font-size: 11px;
  letter-spacing: 1.3px;
  text-transform: uppercase;
  color: #7fa6c9;
  font-variant-numeric: tabular-nums;
}
/* Clock, speaker and close sit together at the right of the caption's head row. */
#capTools {
  display: flex;
  align-items: center;
  gap: 6px;
  pointer-events: auto;
}
/* `font: inherit` here would out-specify the per-button font-size below
   (#capTools button beats #capClose), so the family is set without it. */
#capTools button {
  padding: 0;
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  font-family: inherit;
  line-height: 1;
  color: #9dc0dc;
  background: none;
  border: 0;
  border-radius: 10px;
  cursor: pointer;
  transition: color .15s, background .15s, opacity .15s;
}
#capTools button:hover { color: #fff; background: rgba(255,255,255,.1); }
#capTools #capClose { font-size: 34px; }
#capTools #capMute { font-size: 22px; }
#capMute.muted { opacity: .45; }

/* Collapse control: only useful on a phone, where the card is docked over the
   model. On desktop the caption sits off to the side, so it stays hidden. */
#capCollapse { display: none; font-size: 20px; }
#caption.collapsed #capText,
#caption.collapsed #capNav { display: none; }
#caption.collapsed { padding-bottom: 0; }

#capText {
  margin: 7px 0 0;
  padding: 0 20px;
  font-size: 16px;
  line-height: 1.6;
  color: #e9f1f7;
}

/* The caption bar is click-through; only its buttons take the pointer back. */
#capNav {
  display: flex;
  gap: 8px;
  padding: 12px 20px 0;
  pointer-events: auto;
}
#capNav button {
  flex: 1;
  min-height: 36px;
  padding: 7px 10px;
  font-size: 12px;
  letter-spacing: .6px;
  color: #cfe2f1;
  background: rgba(255,255,255,.06);
  border: 1px solid rgba(255,255,255,.12);
  border-radius: 8px;
  cursor: pointer;
  transition: background .15s, color .15s;
}
#capNav button:hover { background: rgba(239,125,59,.22); color: #fff; }
#capNav button:disabled { opacity: .35; cursor: default; background: rgba(255,255,255,.04); color: #cfe2f1; }

/* Get the chrome out of the way while presenting. */
body.touring #titlebar { opacity: .25; }
body.touring #hint { opacity: 0; }

/* ---- Hint ---- */
#hint {
  position: fixed;
  bottom: calc(16px + var(--safe-b));
  left: 50%;
  transform: translateX(-50%);
  z-index: 10;
  font-size: 12px;
  color: #8095a6;
  background: rgba(12,17,23,.6);
  padding: 6px 14px;
  border-radius: 20px;
  pointer-events: none;
  transition: opacity .6s;
}
#hint b { color: #c9a771; font-weight: 600; }
#hint.fade { opacity: 0; }        /* it has been read; stop covering the model */
#hint .touchHint { display: none; }

/* ---- 3D labels (CSS2D) ---- */
.label {
  font-size: 14px;
  font-weight: 600;
  color: #f2f6fa;
  background: rgba(20,28,38,.82);
  padding: 4px 10px;
  border-radius: 7px;
  border: 1px solid rgba(255,255,255,.12);
  white-space: nowrap;
  text-shadow: 0 1px 3px rgba(0,0,0,.7);
  pointer-events: none;
  transition: color .2s, background .2s, border-color .2s;
}
.label.part { color: #cfe6ff; }
.label.part.active {
  color: #10171f;
  background: #9fd0ee;
  border-color: #cfe6ff;
  box-shadow: 0 0 18px rgba(159,208,238,.5);
}
.label.dim {
  color: #ffe4b0;
  background: rgba(58,40,16,.75);
  border-color: rgba(240,169,75,.35);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

/* ===========================================================================
   Tablet — the model wants the middle of the screen, so the two side cards
   narrow before they are allowed to crowd it.
   =========================================================================== */
@media (max-width: 1024px) {
  #panel { width: 226px; }
  #info { width: 266px; }
  #caption { width: calc(100vw - 300px); }
}

/* ===========================================================================
   Phone — the panel becomes a dismissable bottom sheet, the inspector docks to
   the bottom edge, and the caption moves to the top, so no two surfaces ever
   stack on one another. Controls clear a 44px touch target.
   =========================================================================== */
@media (max-width: 780px) {
  #titlebar {
    top: calc(12px + var(--safe-t));
    left: calc(14px + var(--safe-l));
    right: calc(14px + var(--safe-r));
  }
  #titlebar h1 { font-size: 18px; }
  #titlebar h1 span { margin-left: 6px; font-size: 13px; }
  #titlebar p { margin-top: 2px; font-size: 11px; }
  body.touring #titlebar { opacity: 0; }   /* the caption takes the top instead */

  /* The sheet. */
  #panel {
    top: auto;
    left: 0;
    right: 0;
    bottom: 0;
    width: auto;
    max-height: min(74vh, 620px);
    padding-bottom: var(--safe-b);
    background: rgba(14, 21, 29, .56);
    border-radius: 20px 20px 0 0;
    border-left: 0;
    border-right: 0;
    border-bottom: 0;
    box-shadow: 0 -14px 50px rgba(0,0,0,.55);
  }
  body.panel-hidden #panel {
    opacity: 1;                     /* it slides out rather than fading */
    transform: translateY(100%);
  }

  #panelHead { padding: 18px 12px 10px 18px; }
  #panelGrip {                      /* drag it down to dismiss */
    display: block;
    position: absolute;
    top: 7px;
    left: 50%;
    transform: translateX(-50%);
    width: 42px;
    height: 5px;
    border-radius: 3px;
    background: rgba(255,255,255,.28);
  }
  #panelClose { width: 42px; height: 42px; font-size: 24px; }

  #panelBody { padding: 14px 18px 8px; }
  #panelBody h2 { margin-top: 18px; }

  #panelDone {
    display: block;
    flex: none;
    margin: 8px 18px 14px;
    min-height: 46px;
    font-size: 14px;
    font-weight: 600;
    color: #e8eef3;
    background: rgba(255,255,255,.08);
    border: 1px solid rgba(255,255,255,.18);
    border-radius: 12px;
    cursor: pointer;
  }

  /* Touch targets. */
  .row { min-height: 44px; padding: 9px 0; font-size: 15px; }
  .row input[type="checkbox"] { width: 20px; height: 20px; }
  .row.slider { padding: 6px 0; }
  .row.slider input { height: 30px; }
  .seg { gap: 8px; }
  .seg button { min-height: 44px; font-size: 14px; }
  #playTour, #resetView { min-height: 46px; font-size: 14px; }

  #scrim { display: block; }
  body:not(.panel-hidden) #scrim { opacity: 1; visibility: visible; }

  /* The toggle becomes a thumb-reachable, labelled pill. */
  #panelToggle {
    top: auto;
    left: auto;
    right: calc(14px + var(--safe-r));
    bottom: calc(14px + var(--safe-b));
    width: auto;
    height: 48px;
    padding: 0 18px 0 15px;
    border-radius: 24px;
    background: rgba(16,24,33,.8);
  }
  #panelToggle .btnLabel { display: inline; }

  /* The inspector docks to the bottom, clear of the toggle pill and the hint. */
  #info {
    top: auto;
    left: calc(12px + var(--safe-l));
    right: calc(12px + var(--safe-r));
    bottom: calc(74px + var(--safe-b));
    width: auto;
    max-height: 46vh;
    padding: 16px 16px 18px;
    background: rgba(16,24,33,.76);
    transform: translateY(14px);
  }
  #info.show { transform: none; }
  #info h3 { padding-right: 44px; font-size: 17px; }
  #info .desc { font-size: 13px; }
  #infoClose { top: 8px; right: 8px; width: 42px; height: 42px; }

  /* The caption goes to the top: the bottom belongs to the inspector and the
     toggle, and the titlebar is out of the way while touring anyway. */
  #caption {
    left: 10px;
    right: 10px;
    top: calc(10px + var(--safe-t));
    bottom: auto;
    width: auto;
    padding-bottom: 12px;
    transform: translateY(-14px);
  }
  #caption.show { transform: none; }
  #capHead { padding: 2px 6px 0 14px; }
  #capTools #capCollapse { display: grid; }
  #caption.collapsed #capHead { padding-bottom: 6px; }
  #capText {
    padding: 0 14px;
    font-size: 13.5px;
    line-height: 1.5;
    max-height: 26vh;
    overflow-y: auto;
    overscroll-behavior: contain;
  }
  #capNav { padding: 10px 14px 0; }
  #capNav button { min-height: 44px; }

  /* The tour button leaves the crowded top and takes the bottom-left thumb
     corner, mirroring the Controls pill on the right. */
  #tourFab {
    top: auto;
    left: calc(14px + var(--safe-l));
    bottom: calc(14px + var(--safe-b));
    transform: none;
    height: 48px;
    border-radius: 24px;
  }
  #tourFab:active { transform: scale(.96); }

  /* Hint sits centred above the two corner pills; it fades after a few seconds. */
  #hint {
    left: 50%;
    right: auto;
    bottom: calc(74px + var(--safe-b));
    max-width: calc(100vw - 28px);
    transform: translateX(-50%);
    font-size: 11px;
    padding: 6px 11px;
  }
  #hint .desktopHint { display: none; }
  #hint .touchHint { display: inline; }

  .label { font-size: 12px; padding: 3px 8px; }
  .label.dim { font-size: 11px; }
}

/* A phone held sideways has no vertical room for a bottom sheet, so the panel
   becomes a side drawer instead. */
@media (max-height: 520px) and (max-width: 950px) {
  #panel {
    top: 0;
    bottom: 0;
    left: 0;
    right: auto;
    width: min(320px, 78vw);
    max-height: none;
    padding-bottom: 0;
    padding-left: var(--safe-l);
    border-radius: 0 18px 18px 0;
    border-left: 0;
    box-shadow: 14px 0 50px rgba(0,0,0,.55);
  }
  body.panel-hidden #panel { transform: translateX(-100%); }
  #panelGrip { display: none; }
  #panelHead { padding: 12px 12px 10px 18px; }
  #panelToggle { height: 44px; }

  #info {
    left: auto;
    width: min(320px, 58vw);
    max-height: 62vh;
    bottom: calc(12px + var(--safe-b));
  }
  #caption {
    left: 50%;
    right: auto;
    width: min(640px, calc(100vw - 24px));
    transform: translate(-50%, -14px);
  }
  #caption.show { transform: translate(-50%, 0); }
  #capText { max-height: 20vh; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: .01ms !important; }
}
