:root {
  --bg: #13110e;
  --panel: rgba(19, 16, 13, 0.9);
  --border: rgba(212, 184, 132, 0.28);
  --text: #eee7d7;
  --muted: #b5a78e;
  --accent: #e0be72;

  /* Structural clearances & responsive geometry tokens */
  --hud-edge-x: 14px;
  --hud-edge-y: 12px;
  --hud-right-idle: 160px;
  --hud-card-clearance: 276px;
  --ticker-max-w: min(74vw, 960px);
  --icon-sz: 15px;
  --dot-sz: 7px;
  --card-w: 248px;
  --card-img-h: 235px;
  --overlay-bottom: 78px;
  --overlay-max-w: min(440px, 44vw);
  --scale-row-h: 13px;
  --intro-w: min(440px, calc(100% - 28px));
}

/* YouTube / 16:9 Video Mode: root rem scaling + structural clearances */
html.video-mode {
  font-size: 19px;
  --hud-edge-x: 18px;
  --hud-edge-y: 16px;
  --hud-right-idle: 24px;
  --hud-card-clearance: 328px;
  --ticker-max-w: 68vw;
  --icon-sz: 18px;
  --dot-sz: 9px;
  --card-w: 296px;
  --card-img-h: 252px;
  --overlay-bottom: 84px;
  --overlay-max-w: 500px;
  --scale-row-h: 15px;
  --intro-w: min(500px, calc(100% - 36px));
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100dvh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font-family: "Inter", system-ui, -apple-system, sans-serif;
}

#workspace {
  position: relative;
  display: flex;
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
  overflow: hidden;
}

#stage {
  position: relative;
  flex: 1 1 auto;
  min-width: 0;
  min-height: 0;
  height: 100%;
  overflow: hidden;
}

#map,
#tactical-canvas,
#backdrop,
#edge-pointers {
  position: absolute;
  inset: 0;
}

#tactical-canvas {
  width: 100%;
  height: 100%;
  z-index: 2;
  pointer-events: none;
}

#edge-pointers {
  z-index: 4;
  pointer-events: none;
  overflow: hidden;
}

/* Shared crossfade surfaces */
#backdrop,
#chapter-intro,
#chapter-outro,
#video-caption {
  opacity: 0;
  pointer-events: none;
}

#backdrop.visible,
#chapter-intro.visible,
#chapter-outro.visible,
#video-caption.visible {
  opacity: 1;
}

/* Period image backdrop */
#backdrop {
  z-index: 6;
  overflow: hidden;
  background: #14110d;
  transition: opacity 1.2s ease;
}

#backdrop-bg {
  position: absolute;
  inset: -24px;
  background: center / cover no-repeat;
  filter: blur(26px) sepia(0.18) brightness(0.38) saturate(0.85);
  transform: scale(1.06);
  opacity: 0.92;
  pointer-events: none;
}

#backdrop img {
  position: relative;
  z-index: 1;
  width: 100%;
  height: 100%;
  object-fit: contain;
  filter: sepia(0.14) contrast(1.03);
}

#backdrop-credit {
  z-index: 2;
  position: absolute;
  right: 12px;
  bottom: 10px;
  font-size: 0.66rem;
  color: rgba(243, 229, 195, 0.7);
  pointer-events: auto;
}

#backdrop-credit a {
  color: inherit;
}

html.video-mode #backdrop-credit {
  right: 18px;
  bottom: 14px;
  padding: 3px 8px;
  border-radius: 6px;
  background: rgba(17, 14, 11, 0.68);
}

/* Top HUD: Story Clock + Compass + Narrative Focus Ticker */
#hud-top {
  position: absolute;
  top: calc(var(--hud-edge-y) + env(safe-area-inset-top, 0px));
  left: calc(var(--hud-edge-x) + env(safe-area-inset-left, 0px));
  right: calc(var(--hud-right-idle) + env(safe-area-inset-right, 0px));
  z-index: 9;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  pointer-events: none;
}

#stage.has-card #hud-top {
  right: calc(var(--hud-card-clearance) + env(safe-area-inset-right, 0px));
}

.hud-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.32rem 0.78rem;
  font-size: 0.78rem;
  backdrop-filter: blur(8px);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.42);
}

#story-clock {
  font-weight: 700;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
}

.daylight-icon,
.compass-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: var(--icon-sz);
  height: var(--icon-sz);
  flex-shrink: 0;
}

.daylight-icon svg,
.compass-needle {
  width: var(--icon-sz);
  height: var(--icon-sz);
  display: block;
}

.compass-badge {
  pointer-events: auto;
  cursor: pointer;
}

.compass-needle {
  transition: transform 0.15s linear;
}

#clock-pill[data-daylight="night"] {
  border-color: rgba(129, 156, 214, 0.45);
}

#clock-pill[data-daylight="dawn"] {
  border-color: rgba(235, 152, 114, 0.45);
}

#clock-pill[data-daylight="dusk"] {
  border-color: rgba(224, 134, 72, 0.48);
}

/* Shared inline HUD/glossary chips */
.scale-tag,
.focus-chip,
.card-faction,
.sym-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.32rem;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 999px;
}

.scale-tag {
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #dfd5be;
  padding: 0.08rem 0.45rem;
}

#focus-ticker {
  gap: 0.38rem;
  max-width: var(--ticker-max-w);
  overflow: hidden;
  white-space: nowrap;
}

.ticker-caption {
  color: #dfd5be;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

.focus-chip {
  padding: 0.13rem 0.52rem;
  font-size: 0.73rem;
  font-weight: 600;
  color: #f4eee0;
}

.focus-dot {
  width: var(--dot-sz);
  height: var(--dot-sz);
  border-radius: 50%;
  flex-shrink: 0;
}

.panel {
  position: absolute;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  backdrop-filter: blur(10px);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.52);
  z-index: 10;
}

.hidden,
.sr-audio,
#workspace .hidden,
#stage .hidden,
#dock .hidden {
  display: none;
}

#btn-resync {
  position: absolute;
  top: var(--hud-edge-y);
  right: var(--hud-edge-x);
  z-index: 12;
  background: rgba(168, 120, 38, 0.94);
  color: #161108;
  border-color: rgba(255, 224, 150, 0.65);
  font-weight: 700;
}

/* Pluggable Scene Overlay (infographic / dispatch / historical explainer) */
#scene-overlay {
  left: var(--hud-edge-x);
  bottom: var(--overlay-bottom);
  max-width: var(--overlay-max-w);
  padding: 0.82rem 1rem;
  font-size: 0.81rem;
  line-height: 1.44;
}

.doc-title {
  font-weight: 700;
  color: var(--accent);
  font-size: 0.86rem;
  margin-bottom: 6px;
  letter-spacing: 0.01em;
}

.doc-body {
  color: #f3e5c3;
  margin-bottom: 6px;
}

.doc-bullets {
  margin: 4px 0 6px 16px;
  padding: 0;
  color: #f3e5c3;
}

.doc-bullets li {
  margin-bottom: 4px;
}

.doc-quote {
  font-style: italic;
  color: #f3e5c3;
}

.doc-footer {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 10px;
  margin-top: 6px;
  font-size: 0.72rem;
  color: var(--muted);
}

.doc-hint {
  font-size: 0.66rem;
  color: rgba(224, 190, 114, 0.78);
  white-space: nowrap;
}

/* Opening & Closing Chapter Notices (top-left so map & visualization stay unobstructed) */
#chapter-intro,
#chapter-outro {
  position: absolute;
  top: var(--hud-edge-y);
  left: var(--hud-edge-x);
  z-index: 13;
  max-width: var(--intro-w);
  padding: 0.9rem 1.15rem;
  border-radius: 12px;
  background: rgba(17, 14, 11, 0.86);
  border: 1px solid rgba(224, 190, 114, 0.42);
  border-left: 3px solid var(--accent);
  backdrop-filter: blur(12px);
  box-shadow: 0 14px 36px rgba(0, 0, 0, 0.52);
  text-align: left;
  cursor: pointer;
  transition: opacity 0.7s ease;
}

.has-card > #chapter-intro,
.has-card > #chapter-outro {
  max-width: min(var(--intro-w), calc(100% - var(--hud-card-clearance) - var(--hud-edge-x)));
}

#chapter-intro.visible,
#chapter-outro.visible {
  pointer-events: auto;
}

.outro-actions {
  margin-top: 12px;
  display: flex;
  justify-content: flex-start;
}

.outro-next-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 7px 15px;
  border-radius: 999px;
  background: rgba(212, 169, 86, 0.94);
  color: #161108;
  font-weight: 700;
  font-size: 0.8rem;
  text-decoration: none;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.42);
  transition:
    transform 0.15s ease,
    background 0.15s ease;
}

.outro-next-btn:hover {
  background: #ebd08c;
  transform: translateY(-1px);
}

.intro-eyebrow {
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.13em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 4px;
}

.intro-title {
  margin: 0;
  font-size: clamp(1.05rem, 1.7vw, 1.32rem);
  line-height: 1.24;
  color: var(--accent);
  font-weight: 700;
}

.intro-meta {
  display: inline-flex;
  flex-wrap: wrap;
  justify-content: flex-start;
  align-items: center;
  gap: 6px;
  margin-top: 8px;
  padding: 0.2rem 0.65rem;
  border-radius: 999px;
  background: rgba(224, 190, 114, 0.14);
  border: 1px solid rgba(224, 190, 114, 0.34);
  font-size: 0.74rem;
  font-weight: 600;
  color: #f6ebd0;
}

.intro-eyebrow:empty,
.intro-meta:empty {
  display: none;
}

/* Unified Dual km / miles Cartographic Scale Bar */
#dual-scale {
  left: var(--hud-edge-x);
  bottom: var(--hud-edge-y);
  padding: 0.38rem 0.88rem 0.32rem;
  pointer-events: none;
  z-index: 9;
  font-size: 0.69rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: #f3e6c8;
  line-height: 1;
}

.scale-track {
  position: relative;
  user-select: none;
}

.scale-row {
  position: relative;
  height: var(--scale-row-h);
}

.scale-row-bottom {
  margin-top: 2px;
}

.scale-lbl {
  position: absolute;
  top: 0;
  white-space: nowrap;
  transform: translateX(-50%);
}

.scale-lbl-zero {
  left: 0;
  transform: none;
}

.scale-lbl-end {
  color: var(--accent);
}

.scale-spine-wrap {
  position: relative;
  height: 12px;
}

.scale-spine {
  position: absolute;
  left: 0;
  top: 5px;
  height: 2px;
  background: var(--accent);
}

.scale-tick {
  position: absolute;
  width: 2px;
  height: 6px;
  background: var(--accent);
  transform: translateX(-1px);
}

.scale-tick-top {
  top: 0;
}

.scale-tick-bottom {
  top: 6px;
}

.scale-seg {
  position: absolute;
  height: 3px;
  background: rgba(224, 190, 114, 0.45);
}

.scale-seg-top {
  top: 2px;
}

.scale-seg-bottom {
  top: 7px;
  background: rgba(243, 230, 200, 0.35);
}

.force-bar-row {
  margin-top: 6px;
}

.force-bar-label {
  display: flex;
  justify-content: space-between;
  font-size: 0.74rem;
  color: #e4dac5;
  margin-bottom: 3px;
}

.force-bar-track {
  height: 7px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.1);
  overflow: hidden;
}

.force-bar-fill {
  height: 100%;
  border-radius: 999px;
}

/* Calm Portrait Card */
#media-card {
  top: var(--hud-edge-y);
  right: var(--hud-edge-x);
  width: var(--card-w);
  overflow: hidden;
  cursor: pointer;
  z-index: 11;
}

#media-card img {
  width: 100%;
  height: var(--card-img-h);
  object-fit: cover;
  object-position: top center;
  display: block;
  background: #1c1814;
}

#media-card .body {
  padding: 0.65rem 0.76rem;
}

.card-faction {
  font-size: 0.66rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #f4eee0;
  padding: 0.12rem 0.45rem;
  margin-bottom: 5px;
}

#media-card h2 {
  margin: 0;
  font-size: 0.96rem;
  color: var(--accent);
}

#media-card .role {
  font-size: 0.74rem;
  color: var(--muted);
  margin-top: 2px;
}

#media-card .note {
  font-size: 0.76rem;
  margin-top: 6px;
  line-height: 1.38;
  color: #dfd5be;
}

#media-card .credit {
  margin-top: 7px;
  font-size: 0.64rem;
  color: #8f8470;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  padding-top: 5px;
  line-height: 1.3;
}

#media-card .credit a {
  color: #b79c68;
  text-decoration: none;
}

/* Glossary & Scene Jump Drawer */
#glossary,
#beats-panel {
  right: var(--hud-edge-x);
  bottom: var(--hud-edge-y);
  max-height: min(64vh, 460px);
  overflow-y: auto;
}

#glossary {
  width: 300px;
  padding: 12px 14px;
  font-size: 0.76rem;
  line-height: 1.48;
  color: #ddd3be;
}

#glossary .sym-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 8px;
  padding-bottom: 8px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.sym-chip {
  border-color: transparent;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 0.71rem;
  font-weight: 600;
}

#beats-panel {
  width: 340px;
  padding: 6px;
}

.has-card > #beats-panel,
.has-card > #glossary {
  max-height: max(160px, calc(100% - 390px));
}

.beat-item {
  display: flex;
  gap: 8px;
  padding: 7px 9px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.78rem;
  line-height: 1.34;
  color: #ddd2be;
  transition: background 0.12s ease;
}

.beat-item:hover {
  background: rgba(255, 255, 255, 0.08);
}

.beat-item.active {
  background: rgba(224, 190, 114, 0.2);
  color: #fff;
}

.beat-time {
  font-family: ui-monospace, monospace;
  font-size: 0.72rem;
  color: var(--accent);
  min-width: 40px;
  flex-shrink: 0;
}

.beat-body {
  flex: 1;
  min-width: 0;
}

.beat-context {
  margin-top: 4px;
  font-size: 0.72rem;
  color: #b8ab92;
}

.beat-context summary {
  cursor: pointer;
  color: var(--accent);
  opacity: 0.88;
  user-select: none;
  list-style: none;
}

.beat-context summary::-webkit-details-marker {
  display: none;
}

.beat-context summary::before {
  content: "▸ ";
  font-size: 0.68rem;
}

.beat-context[open] summary::before {
  content: "▾ ";
}

.beat-context p {
  margin: 4px 0 2px;
  padding-left: 8px;
  border-left: 2px solid rgba(224, 190, 114, 0.35);
  line-height: 1.4;
  color: #cfc4ad;
}

.beat-scale {
  font-size: 0.62rem;
  text-transform: uppercase;
  color: #a49880;
  margin-right: 4px;
}

/* Edge Off-Map Context Pills */
.edge-pill {
  position: absolute;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: rgba(20, 17, 13, 0.9);
  border: 1px solid rgba(224, 190, 114, 0.55);
  color: #f3e4bd;
  font-size: 0.72rem;
  font-weight: 600;
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
  white-space: nowrap;
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.45);
  transform: translate(-50%, -50%);
}

/* Bottom Audio & Chapter Dock */
#dock {
  flex: 0 0 auto;
  background: #15120f;
  border-top: 1px solid var(--border);
  padding: 7px max(14px, env(safe-area-inset-right, 0px)) max(7px, env(safe-area-inset-bottom, 0px))
    max(14px, env(safe-area-inset-left, 0px));
  z-index: 20;
}

#player-bar {
  display: flex;
  align-items: center;
  gap: 9px;
}

#brand {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 2px 10px 2px 2px;
  margin-right: 2px;
  background: none;
  border: none;
  border-right: 1px solid var(--border);
  color: inherit;
  font: inherit;
  cursor: pointer;
  flex-shrink: 0;
  user-select: none;
  transition: opacity 0.14s ease;
}

#brand:hover {
  opacity: 0.82;
}

#brand img {
  display: block;
  width: 26px;
  height: 26px;
}

.brand-name {
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--accent);
}

#ch-title {
  background: none;
  border: none;
  padding: 4px 6px;
  border-radius: 6px;
  font: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--accent);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 280px;
  cursor: pointer;
  text-align: left;
  transition: background 0.14s ease;
}

#ch-title:hover {
  background: rgba(224, 190, 114, 0.12);
}

/* Custom Dark-Atlas Audio Transport */
#transport {
  flex: 1 1 auto;
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 220px;
  background: rgba(255, 255, 255, 0.035);
  border: 1px solid rgba(212, 184, 132, 0.2);
  border-radius: 8px;
  padding: 3px 8px;
}

.transport-btn {
  background: transparent;
  border: 1px solid transparent;
  color: var(--text);
  border-radius: 5px;
  padding: 3px 6px;
  font-size: 0.74rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
  flex-shrink: 0;
  line-height: 1.2;
}

.transport-btn:hover {
  background: rgba(224, 190, 114, 0.18);
  border-color: rgba(224, 190, 114, 0.35);
}

.transport-play {
  background: rgba(224, 190, 114, 0.2);
  border-color: rgba(224, 190, 114, 0.45);
  color: var(--accent);
  min-width: 28px;
}

.transport-rate {
  color: var(--accent);
  min-width: 38px;
}

.transport-btn.muted {
  opacity: 0.55;
}

.scrub-track {
  position: relative;
  flex: 1 1 auto;
  height: 14px;
  display: flex;
  align-items: center;
  cursor: pointer;
  touch-action: none;
  min-width: 80px;
}

.scrub-track::before {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  height: 4px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.14);
}

.scrub-ticks {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.scrub-tick {
  position: absolute;
  top: 4px;
  width: 1px;
  height: 6px;
  background: rgba(224, 190, 114, 0.45);
}

.scrub-fill {
  position: relative;
  height: 4px;
  width: 0%;
  border-radius: 999px;
  background: var(--accent);
  pointer-events: none;
}

.scrub-fill::after {
  content: "";
  position: absolute;
  right: -5px;
  top: -3px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #f5deb3;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.65);
}

.time-readout {
  font-family: ui-monospace, monospace;
  font-size: 0.72rem;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  white-space: nowrap;
  flex-shrink: 0;
}

#dock-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

.pill-btn {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 5px 10px;
  border-radius: 6px;
  font-size: 0.76rem;
  cursor: pointer;
}

.pill-btn:hover {
  background: rgba(224, 190, 114, 0.22);
}

/* MapLibre Popups */
#stage .maplibregl-popup {
  z-index: 14;
}

#stage .maplibregl-popup-content {
  background: rgba(18, 15, 12, 0.96);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 26px 10px 12px;
  max-width: 290px;
  font-size: 0.78rem;
  line-height: 1.42;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.62);
}

#stage .maplibregl-popup-close-button {
  color: var(--muted);
  font-size: 0.95rem;
  line-height: 1;
  padding: 5px 7px;
  border-radius: 0 7px 0 4px;
}

#stage .maplibregl-popup-close-button:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.08);
}

#stage .maplibregl-popup-anchor-top .maplibregl-popup-tip,
#stage .maplibregl-popup-anchor-top-left .maplibregl-popup-tip,
#stage .maplibregl-popup-anchor-top-right .maplibregl-popup-tip {
  border-bottom-color: rgba(18, 15, 12, 0.96);
}

#stage .maplibregl-popup-anchor-bottom .maplibregl-popup-tip,
#stage .maplibregl-popup-anchor-bottom-left .maplibregl-popup-tip,
#stage .maplibregl-popup-anchor-bottom-right .maplibregl-popup-tip {
  border-top-color: rgba(18, 15, 12, 0.96);
}

#stage .maplibregl-popup-anchor-left .maplibregl-popup-tip {
  border-right-color: rgba(18, 15, 12, 0.96);
}

#stage .maplibregl-popup-anchor-right .maplibregl-popup-tip {
  border-left-color: rgba(18, 15, 12, 0.96);
}

.popup-badges {
  margin: 4px 0;
}

.popup-note {
  color: #c4b69c;
}

.popup-src {
  font-size: 11px;
  color: #9ca3af;
  margin-top: 3px;
}

#stage .popup-src a {
  color: #93c5fd;
}

.popup-action {
  margin: 5px 0 6px;
  padding: 5px 7px;
  border-left: 2px solid var(--accent);
  background: rgba(224, 190, 114, 0.1);
  color: #f3e5c3;
  font-size: 0.78rem;
  line-height: 1.38;
  border-radius: 0 4px 4px 0;
}

.badge {
  display: inline-block;
  font-size: 0.65rem;
  padding: 2px 6px;
  border-radius: 4px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-weight: 700;
}

.badge.verified {
  background: rgba(34, 197, 94, 0.2);
  color: #86efac;
}

.badge.schematic {
  background: rgba(96, 165, 250, 0.22);
  color: #bfdbfe;
}

/* Video-Mode Specific Visibility & Caption Bar */
#video-caption {
  left: 50%;
  bottom: 18px;
  transform: translateX(-50%);
  width: max-content;
  max-width: 580px;
  padding: 10px 18px;
  border-radius: 12px;
  background: rgba(17, 14, 11, 0.9);
  border: 1px solid rgba(224, 190, 114, 0.42);
  color: #f6ecd4;
  font-size: 0.88rem;
  font-weight: 600;
  line-height: 1.38;
  text-align: center;
  z-index: 11;
  transition: opacity 0.5s ease;
}

#video-attribution {
  position: absolute;
  right: 16px;
  bottom: 10px;
  z-index: 8;
  padding: 3px 8px;
  border-radius: 6px;
  background: rgba(17, 14, 11, 0.68);
  color: rgba(238, 231, 215, 0.72);
  font-size: 0.6rem;
  letter-spacing: 0.01em;
  pointer-events: none;
}

html.deterministic-mode #backdrop,
html.deterministic-mode #chapter-intro,
html.deterministic-mode #chapter-outro,
html.deterministic-mode #video-caption {
  transition: none;
}

html.deterministic-mode .hud-pill,
html.deterministic-mode .panel {
  backdrop-filter: none;
  background: rgba(19, 16, 13, 0.94);
}

html.deterministic-mode #chapter-intro,
html.deterministic-mode #chapter-outro {
  backdrop-filter: none;
  background: rgba(17, 14, 11, 0.92);
}

html.library-mode #workspace,
html.library-mode #dock,
html.video-mode #dock,
html.video-mode #btn-resync,
html.video-mode #glossary,
html.video-mode #beats-panel,
html.video-mode .outro-actions,
html.video-mode .doc-hint,
html.video-mode .maplibregl-ctrl-attrib,
html.video-mode .maplibregl-ctrl-bottom-right,
html.video-mode .maplibregl-ctrl-bottom-left {
  display: none;
}

/* Narrow / Tablet & Mobile Viewport Adaptations */
@media (max-width: 860px) {
  .brand-name {
    display: none;
  }
}

@media (max-width: 760px) {
  :root {
    --card-w: min(210px, 48vw);
    --card-img-h: 170px;
    --hud-card-clearance: calc(min(210px, 48vw) + 22px);
    --overlay-max-w: calc(100vw - 28px);
  }

  #player-bar {
    flex-wrap: wrap;
    gap: 6px;
  }

  #transport {
    order: 10;
    flex: 1 1 100%;
    min-width: 0;
  }

  #dock-actions {
    margin-left: auto;
  }
}

/* Short landscape viewports (phones in landscape): keep dock on one slim row */
@media (max-height: 520px) {
  #dock {
    padding: 4px max(10px, env(safe-area-inset-right, 0px)) max(4px, env(safe-area-inset-bottom, 0px))
      max(10px, env(safe-area-inset-left, 0px));
  }

  #player-bar {
    flex-wrap: nowrap;
    gap: 6px;
  }

  .brand-name,
  #ch-title {
    display: none;
  }

  #transport {
    order: 0;
    flex: 1 1 auto;
    min-width: 140px;
  }
}

/* No-JS Fallback Overlay (ignored completely when JavaScript is enabled) */
.noscript-gate {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: radial-gradient(circle at 50% 0%, rgba(224, 190, 114, 0.08), transparent 60%), var(--bg);
  color: var(--text);
}

.noscript-card {
  max-width: 440px;
  width: 100%;
  padding: 28px 26px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--panel);
  text-align: center;
  line-height: 1.55;
}

.noscript-logo {
  display: block;
  margin: 0 auto 14px;
}

.noscript-title {
  margin: 0 0 10px;
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--accent);
}

.noscript-copy {
  margin: 0 0 10px;
  font-size: 0.9rem;
  color: var(--text);
}

.noscript-note {
  margin: 0;
  font-size: 0.8rem;
  color: var(--muted);
}
