/**
 * SceneWeaver — Illustrated Storybook Reader Styles
 * Owns: reader layout, panel display, choice navigation, 3D toggle.
 * Does NOT own: Three.js or WebXR rendering.
 */

/* ─── Layout ──────────────────────────────────────────────────────────────── */

.storybook {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  background: var(--bg);
}

/* ─── Header ────────────────────────────────────────────────────────────────── */

.sb-header {
  position: sticky;
  top: 0;
  z-index: 40;
  background: rgba(5, 8, 16, 0.85);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  padding: 0 24px;
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.sb-header-left {
  display: flex;
  align-items: center;
  gap: 14px;
  flex: 1;
  min-width: 0;
}

.sb-eyebrow {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--accent);
  white-space: nowrap;
  flex-shrink: 0;
}

.sb-story-title {
  font-family: 'Playfair Display', serif;
  font-size: 16px;
  font-weight: 700;
  color: var(--fg);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}

.sb-progress {
  font-size: 12px;
  color: var(--fg-dim);
  white-space: nowrap;
  flex-shrink: 0;
}

.sb-header-right {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.sb-btn-icon {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 6px;
  color: var(--fg-muted);
  font-size: 13px;
  padding: 7px 12px;
  cursor: pointer;
  transition: color 0.2s, border-color 0.2s, background 0.2s;
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: 6px;
  font-family: 'DM Sans', sans-serif;
}

.sb-btn-icon:hover {
  color: var(--fg);
  border-color: rgba(255, 255, 255, 0.18);
  background: rgba(255, 255, 255, 0.08);
}

.sb-btn-icon.active {
  background: rgba(245, 166, 35, 0.12);
  border-color: rgba(245, 166, 35, 0.35);
  color: var(--accent);
}

.sb-btn-icon:disabled {
  opacity: 0.4;
  cursor: default;
}

/* ─── Content scroll area ───────────────────────────────────────────────────── */

.sb-content {
  flex: 1;
  overflow-y: auto;
  padding: 0 0 120px;
  /* Visible loading state — shown before the first scene renders.
     Replaced by navigateTo() once the narrative boots. */
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding-top: 80px;
}

/* Override the flex centering once scene content is injected */
.sb-content:not(:empty) {
  display: block;
  padding-top: 0;
}

.sb-content-loading {
  text-align: center;
  color: var(--fg-dim);
  font-size: 14px;
  letter-spacing: 0.06em;
  padding: 20px;
}

/* ─── Scene card ──────────────────────────────────────────────────────────────── */

.sb-scene {
  padding: 40px 24px 0;
  max-width: 760px;
  margin: 0 auto;
}

.sb-scene-inner {
  opacity: 0;
  transform: translateY(16px);
  transition: opacity 0.4s ease, transform 0.4s ease;
}

.sb-scene-inner.visible {
  opacity: 1;
  transform: translateY(0);
}

/* ─── Illustrated panel ──────────────────────────────────────────────────────── */

.sb-panel {
  position: relative;
  width: 100%;
  aspect-ratio: 4 / 3;
  border-radius: 10px;
  overflow: hidden;
  margin-bottom: 28px;
  background: var(--surface);
}

.sb-panel-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  opacity: 0;
  transition: opacity 0.6s ease;
}

.sb-panel-img.loaded {
  opacity: 1;
}

.sb-panel-shimmer {
  position: absolute;
  inset: 0;
  background: linear-gradient(
    90deg,
    transparent 0%,
    rgba(255, 255, 255, 0.04) 50%,
    transparent 100%
  );
  background-size: 200% 100%;
  animation: shimmer 1.6s infinite;
  transition: opacity 0.3s;
}

.sb-panel-img.loaded + .sb-panel-shimmer,
.sb-panel.has-image .sb-panel-shimmer {
  opacity: 0;
  pointer-events: none;
}

.sb-panel.has-image .sb-panel-img {
  opacity: 1;
}

@keyframes shimmer {
  0%   { background-position: -200% 0; }
  100% { background-position:  200% 0; }
}

.sb-panel-caption {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 40px 20px 16px;
  background: linear-gradient(to top, rgba(5, 8, 16, 0.75) 0%, transparent 100%);
  font-size: 11px;
  color: rgba(255, 255, 255, 0.5);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.sb-panel-noimage {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 10px;
  color: var(--fg-dim);
}

.sb-panel-noimage svg {
  width: 36px;
  height: 36px;
  opacity: 0.4;
}

.sb-panel-noimage span {
  font-size: 12px;
  letter-spacing: 0.06em;
  opacity: 0.5;
}

/* ─── Scene metadata ─────────────────────────────────────────────────────────── */

.sb-genre {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 10px;
}

.sb-scene-title {
  font-family: 'Playfair Display', serif;
  font-size: clamp(22px, 4vw, 32px);
  font-weight: 700;
  color: var(--fg);
  line-height: 1.2;
  margin-bottom: 20px;
  letter-spacing: -0.01em;
}

.sb-scene-desc {
  font-size: 16px;
  line-height: 1.8;
  color: var(--fg-muted);
  margin-bottom: 36px;
  font-weight: 300;
}

/* ─── Choices ────────────────────────────────────────────────────────────────── */

.sb-choices {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.sb-choices-label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--fg-dim);
  margin-bottom: 6px;
}

.sb-choice-btn {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 16px 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--fg);
  font-size: 14px;
  font-family: 'DM Sans', sans-serif;
  cursor: pointer;
  text-align: left;
  transition: background 0.18s, border-color 0.18s, transform 0.12s, box-shadow 0.18s;
  animation: choiceFadeIn 0.35s ease both;
}

.sb-choice-btn:hover {
  background: var(--surface-2);
  border-color: rgba(245, 166, 35, 0.3);
  transform: translateX(3px);
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}

.sb-choice-btn:active {
  transform: translateX(1px);
}

.sb-choice-icon {
  font-size: 16px;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: rgba(245, 166, 35, 0.1);
  border: 1px solid rgba(245, 166, 35, 0.2);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  color: var(--accent);
}

.sb-choice-text {
  flex: 1;
  line-height: 1.45;
}

@keyframes choiceFadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* Stagger animation delays for choice buttons */
.sb-choice-btn:nth-child(1) { animation-delay: 0.05s; }
.sb-choice-btn:nth-child(2) { animation-delay: 0.12s; }
.sb-choice-btn:nth-child(3) { animation-delay: 0.19s; }
.sb-choice-btn:nth-child(4) { animation-delay: 0.26s; }

/* ─── End-of-story panel ─────────────────────────────────────────────────────── */

.sb-end-panel {
  padding: 36px 0 16px;
  text-align: center;
}

.sb-end-divider {
  width: 40px;
  height: 2px;
  background: var(--accent);
  opacity: 0.4;
  border-radius: 1px;
  margin: 0 auto 24px;
}

.sb-end-title {
  font-family: 'Playfair Display', serif;
  font-size: 24px;
  font-weight: 700;
  color: var(--fg);
  margin-bottom: 10px;
}

.sb-end-body {
  font-size: 14px;
  color: var(--fg-muted);
  line-height: 1.6;
  margin-bottom: 28px;
}

.sb-remix-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: rgba(245, 166, 35, 0.12);
  border: 1px solid rgba(245, 166, 35, 0.4);
  border-radius: 8px;
  color: var(--accent);
  font-size: 15px;
  font-family: 'DM Sans', sans-serif;
  font-weight: 500;
  padding: 12px 28px;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.2s, border-color 0.2s;
}

.sb-remix-btn:hover {
  background: rgba(245, 166, 35, 0.2);
  border-color: rgba(245, 166, 35, 0.6);
}

/* ─── 3D viewer overlay ──────────────────────────────────────────────────────── */

#vr-screen {
  display: none;
}

/* When viewer mode is active, hide the storybook reader */
.storybook.viewer-mode .sb-content,
.storybook.viewer-mode .sb-header {
  display: none;
}

.storybook.viewer-mode #vr-screen {
  display: block;
}

/* ─── Back button (storybook nav) ────────────────────────────────────────────── */

.sb-back-btn {
  display: none;
  align-items: center;
  gap: 6px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 6px;
  color: var(--fg-muted);
  font-size: 13px;
  font-family: 'DM Sans', sans-serif;
  padding: 7px 12px;
  cursor: pointer;
  transition: color 0.2s, border-color 0.2s, background 0.2s;
}

.sb-back-btn:hover {
  color: var(--fg);
  border-color: rgba(255, 255, 255, 0.18);
}

.sb-back-btn.visible {
  display: flex;
}

/* ─── 3D loading (when WebXR is loading on top of reader) ───────────────────── */

.sb-loading-3d {
  position: fixed;
  inset: 0;
  background: rgba(5, 8, 16, 0.9);
  z-index: 200;
  display: none;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 16px;
  backdrop-filter: blur(8px);
}

.sb-loading-3d.visible {
  display: flex;
}

.sb-loading-3d p {
  font-size: 14px;
  color: var(--fg-muted);
  letter-spacing: 0.04em;
}

.sb-spinner {
  width: 32px;
  height: 32px;
  border: 2px solid rgba(245, 166, 35, 0.2);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

/* ─── Responsive ──────────────────────────────────────────────────────────────── */

@media (max-width: 600px) {
  .sb-scene {
    padding: 28px 16px 0;
  }

  .sb-story-title {
    font-size: 14px;
  }

  .sb-eyebrow {
    display: none;
  }

  .sb-scene-title {
    font-size: 22px;
  }

  .sb-scene-desc {
    font-size: 15px;
  }

  .sb-choice-btn {
    padding: 13px 16px;
  }
}