/* Lumafield Foundation Model — battery embeddings interactive module */

@font-face {
  font-family: "Monument Grotesk";
  src: url("fonts/MonumentGrotesk-Regular.woff2") format("woff2");
  font-weight: 400;
  font-display: swap;
}
@font-face {
  font-family: "Monument Grotesk";
  src: url("fonts/MonumentGrotesk-Medium.woff2") format("woff2");
  font-weight: 500;
  font-display: swap;
}
@font-face {
  font-family: "Monument Grotesk Semi-Mono";
  src: url("fonts/MonumentGroteskSemiMono-Regular.woff2") format("woff2");
  font-weight: 400;
  font-display: swap;
}

.lf-battery-module {
  position: relative;
  width: 100%;
  max-width: 1350px;
  height: 500px;
  background: #000;
  overflow: hidden;
  font-family: "Monument Grotesk", -apple-system, "Segoe UI", Helvetica, Arial, sans-serif;
  color: #fff;
  user-select: none;
  -webkit-user-select: none;
}

.lf-battery-module canvas {
  position: absolute;
  inset: 0;
  display: block;
  cursor: grab;
}
.lf-battery-module canvas.lf-dragging { cursor: grabbing; }
.lf-battery-module canvas.lf-hovering { cursor: pointer; }

/* ---- Story text overlay: left column on desktop ---- */
.lf-story {
  position: absolute;
  left: 40px;
  top: 50%;
  transform: translateY(-50%);
  width: 340px;
  font-size: 21px;
  line-height: 1.35;
  font-weight: 500;
  letter-spacing: -0.01em;
  text-shadow: 0 1px 12px rgba(0, 0, 0, 0.8);
  opacity: 0;
  transition: opacity 0.45s ease;
  pointer-events: none;
  z-index: 3;
}
.lf-story.lf-visible { opacity: 1; }
.lf-story-text { display: block; }

/* Prominent replay button, shown under the caption on the story's last beat */
.lf-replay {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-top: 22px;
  padding: 10px 20px;
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 0.01em;
  color: #000;
  background: #fce03d;
  border: none;
  cursor: pointer;
  opacity: 0;
  visibility: hidden;
  transform: translateY(4px);
  transition: opacity 0.45s ease, transform 0.45s ease, visibility 0s linear 0.45s, background 0.15s;
  pointer-events: auto;
}
.lf-replay.lf-visible {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
  transition: opacity 0.45s ease, transform 0.45s ease, visibility 0s, background 0.15s;
}
.lf-replay:hover { background: #fff; }
.lf-replay svg { display: block; }

/* ---- Scan flipbook: full-frame CT slice cycling (story beat 1) ---- */
.lf-flipbook {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 400px; /* clear of the narration column */
  right: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  background: #000;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.6s ease, visibility 0s linear 0.6s;
  pointer-events: none;
  z-index: 2;
}
.lf-flipbook.lf-visible {
  opacity: 1;
  visibility: visible;
  transition: opacity 0.6s ease, visibility 0s;
}
.lf-flipbook img {
  max-height: 72%;
  max-width: 80%;
  object-fit: contain;
}
.lf-flipbook-caption {
  display: flex;
  align-items: center;
  gap: 8px;
  /* Fixed width + fixed brand column: the caption's left edge and the sample
     number's start both stay put as brand names of different lengths flip by. */
  width: 300px;
  font-family: "Monument Grotesk Semi-Mono", ui-monospace, "SF Mono", Consolas, monospace;
  font-size: 13px;
  color: #c9c9c9;
}
.lf-flipbook-caption .lf-flip-brand {
  color: #fff;
  width: 13ch; /* fits the longest brand, "Treasurecase" */
  flex: none;
}

/* ---- Floating cluster labels (track the 3D clusters) ---- */
.lf-labels {
  position: absolute;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
  z-index: 2;
}
.lf-cluster-label {
  position: absolute;
  left: -9999px;
  top: -9999px;
  transform: translate(-50%, -100%);
  white-space: nowrap;
  font-size: 13px;
  font-weight: 500;
  text-shadow: 0 1px 6px rgba(0, 0, 0, 0.9);
  opacity: 0;
  transition: opacity 0.7s ease;
}
.lf-cluster-label.lf-visible { opacity: 1; }

/* ---- Legend ---- */
.lf-legend {
  position: absolute;
  left: 40px;
  bottom: 20px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px 16px;
  max-width: 700px;
  opacity: 0;
  transition: opacity 0.8s ease;
  pointer-events: none;
  z-index: 3;
}
.lf-legend.lf-visible { opacity: 1; }
.lf-legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: #c9c9c9;
}
.lf-legend-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  flex: none;
}

/* ---- Inspector sidebar ---- */
.lf-sidebar {
  position: absolute;
  right: 16px;
  top: 16px;
  bottom: 16px;
  width: 280px;
  background: rgba(12, 12, 12, 0.88);
  border: 1px solid #2a2a2a;
  padding: 20px;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  gap: 14px;
  opacity: 0;
  transform: translateX(12px);
  transition: opacity 0.25s ease, transform 0.25s ease;
  pointer-events: none;
  z-index: 4;
  backdrop-filter: blur(4px);
}
.lf-sidebar.lf-visible {
  opacity: 1;
  transform: translateX(0);
  pointer-events: auto;
}
.lf-sidebar-img-wrap {
  width: 100%;
  aspect-ratio: 1 / 1;
  background: #060606;
  border: 1px solid #222;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  flex: none;
}
.lf-sidebar-img-wrap img {
  /* Explicit box + object-fit so host-page img rules (e.g. width:100%)
     can never distort the slice, however the module is embedded. */
  width: 100%;
  height: 100%;
  object-fit: contain;
  image-rendering: auto;
}
.lf-sidebar-text {
  display: flex;
  flex-direction: column;
  gap: 12px;
  flex: 1;
  min-width: 0;
}
.lf-sidebar-brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 18px;
  font-weight: 500;
}
.lf-sidebar-brand .lf-legend-dot { width: 11px; height: 11px; }
.lf-sidebar-meta {
  font-family: "Monument Grotesk Semi-Mono", ui-monospace, "SF Mono", Consolas, monospace;
  font-size: 13px;
  color: #9d9d9d;
  line-height: 1.7;
}
.lf-sidebar-meta strong { color: #fff; font-weight: 400; }
.lf-sidebar-caption {
  margin-top: auto;
  font-size: 11px;
  color: #6f6f6f;
  line-height: 1.5;
}

/* ---- Storyboard transport (back / play-pause / forward) ---- */
.lf-transport {
  position: absolute;
  top: 16px;
  left: 16px;
  display: flex;
  gap: 6px;
  z-index: 5;
}
.lf-transport .lf-btn {
  width: 32px;
  height: 32px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}
.lf-transport svg { display: block; }

/* ---- Controls ---- */
.lf-controls {
  position: absolute;
  right: 16px;
  bottom: 16px;
  display: flex;
  gap: 8px;
  z-index: 5;
}
.lf-btn {
  font-family: inherit;
  font-size: 12px;
  color: #c9c9c9;
  background: rgba(20, 20, 20, 0.85);
  border: 1px solid #333;
  padding: 6px 14px;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
}
.lf-btn:hover { color: #fff; border-color: #666; }
.lf-btn.lf-hidden { display: none; }

/* When the sidebar is open, keep controls clear of it */
.lf-sidebar.lf-visible ~ .lf-controls { right: 312px; }

/* ---- Hover hint ---- */
.lf-hint {
  position: absolute;
  right: 16px;
  top: 16px;
  font-size: 12px;
  color: #7a7a7a;
  opacity: 0;
  transition: opacity 0.8s ease;
  pointer-events: none;
  z-index: 2;
}
.lf-hint.lf-visible { opacity: 1; }

/* ---- Loading / error ---- */
.lf-status {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  color: #7a7a7a;
  text-align: center;
  padding: 0 60px;
  z-index: 6;
  background: #000;
}
.lf-status.lf-hidden { display: none; }

/* ---- Narrow screens: narration on top, cloud below ---- */
@media (max-width: 760px) {
  .lf-transport { top: 12px; left: 12px; }
  .lf-flipbook { left: 0; top: 150px; gap: 10px; } /* below the narration */
  .lf-flipbook img { max-height: 60%; }
  .lf-flipbook-caption { font-size: 11px; }
  .lf-story {
    left: 16px;
    right: 16px;
    top: 56px;
    transform: none;
    width: auto;
    font-size: 16px;
    line-height: 1.4;
  }
  .lf-legend { left: 16px; bottom: 12px; max-width: none; right: 116px; gap: 4px 12px; }
  .lf-legend-item { font-size: 11px; }
  .lf-hint { display: none; }

  /* Inspector becomes a bottom sheet */
  .lf-sidebar {
    top: auto;
    left: 12px;
    right: 12px;
    bottom: 12px;
    width: auto;
    height: 152px;
    flex-direction: row;
    padding: 12px;
    gap: 12px;
    transform: translateY(12px);
  }
  .lf-sidebar.lf-visible { transform: translateY(0); }
  .lf-sidebar-img-wrap { width: 126px; height: 126px; aspect-ratio: auto; }
  .lf-sidebar-brand { font-size: 15px; }
  .lf-sidebar-meta { font-size: 12px; }
  .lf-sidebar-caption { font-size: 10px; }
  .lf-sidebar.lf-visible ~ .lf-controls { right: 16px; bottom: 176px; }
}


/* ---- Light theme: mount with <div id="lf-battery-module" data-theme="light"> ----
   The JS adds .lf-light and paints the canvas white; these rules re-ink the DOM. */

.lf-battery-module.lf-light {
  background: #fff;
  color: #111;
}
.lf-battery-module.lf-light .lf-story-text,
.lf-battery-module.lf-light .lf-cluster-label { color: #111; }
.lf-battery-module.lf-light .lf-legend-item,
.lf-battery-module.lf-light .lf-sidebar-caption { color: #444; }
.lf-battery-module.lf-light .lf-sidebar {
  background: rgba(250, 250, 250, 0.92);
  border-color: #ddd;
}
.lf-battery-module.lf-light .lf-sidebar-meta { color: #555; }
.lf-battery-module.lf-light .lf-sidebar-meta strong { color: #111; }
.lf-battery-module.lf-light .lf-sidebar-img-wrap { background: #000; }
.lf-battery-module.lf-light .lf-btn {
  color: #444;
  background: rgba(245, 245, 245, 0.9);
  border-color: #ccc;
}
.lf-battery-module.lf-light .lf-btn:hover { color: #000; border-color: #888; }
.lf-battery-module.lf-light .lf-hint,
.lf-battery-module.lf-light .lf-status { color: #666; }
.lf-battery-module.lf-light .lf-replay:hover { background: #fce03d; }


/* ---- Ambient mode: cluster + sample callouts only, square panel ---- */

.lf-battery-module.lf-ambient {
  aspect-ratio: 1 / 1;
  height: auto;
}
.lf-battery-module.lf-ambient .lf-story,
.lf-battery-module.lf-ambient .lf-controls,
.lf-battery-module.lf-ambient .lf-transport,
.lf-battery-module.lf-ambient .lf-legend,
.lf-battery-module.lf-ambient .lf-hint,
.lf-battery-module.lf-ambient .lf-flipbook,
.lf-battery-module.lf-ambient .lf-replay { display: none; }


/* ---- Ambient callout: compact card that floats beside the highlighted dot,
   with a thin connector line (positioned by JS). ---- */

.lf-battery-module.lf-ambient .lf-sidebar {
  right: auto;
  top: 0;
  bottom: auto;
  width: 150px;
  padding: 9px;
  gap: 6px;
  transform: none;
  transition: opacity 0.25s ease;
}
.lf-battery-module.lf-ambient .lf-sidebar.lf-visible { transform: none; }
.lf-battery-module.lf-ambient .lf-sidebar-caption { display: none; }
.lf-battery-module.lf-ambient .lf-sidebar-brand { font-size: 12px; }
.lf-battery-module.lf-ambient .lf-sidebar-brand .lf-legend-dot { width: 8px; height: 8px; }
.lf-battery-module.lf-ambient .lf-sidebar-meta { font-size: 10px; line-height: 1.55; }
.lf-battery-module.lf-ambient .lf-ambient-line {
  position: absolute;
  height: 1px;
  background: currentColor;
  opacity: 0;
  transition: opacity 0.25s ease;
  transform-origin: 0 50%;
  pointer-events: none;
  z-index: 3;
}
