/* ── Three.js Guide — studio shell ──
   Matches the /js-libraries/ hub: open contained layout aligned with the
   navbar content box (max-w-7xl + px-4/6/8), sticky sidebar with a tapered
   separator, studio theme tokens (static/css/theme/tokens.css). */

.threejs-app {
  /* Local palette re-pointed to the studio tokens. Declared on the app root
     (not :root) so they win over any ambient definitions. */
  --sidebar-w: 248px;
  --bg: var(--surface, #fffef7);
  --bg2: var(--surface-2, #faf8f5);
  --bg3: #f0ece6;
  --bg-canvas: #f3f0ea;
  --accent: var(--c-indigo, #6366f1);
  --accent-light: rgba(99, 102, 241, 0.1);
  --accent-dim: var(--c-indigo-strong, #4f46e5);
  --magenta: #c0399a;
  --mag-light: rgba(217, 38, 169, 0.1);
  --amber: #a8851a;
  --amb-light: rgba(245, 215, 110, 0.2);
  --green: #2e8d7f;
  --grn-light: rgba(77, 184, 168, 0.14);
  --purple: #7a5fa8;
  --purple-light: rgba(124, 58, 237, 0.1);
  --text: var(--c-ink, #1a1a2e);
  --text2: #494960;
  --muted: var(--c-muted, #6b6b7b);
  --border: rgba(26, 26, 46, 0.12);
  --border2: rgba(26, 26, 46, 0.22);
  --panel: var(--surface-2, #faf8f5);
  --radius: 14px;
  --shadow-sm: 0 1px 2px rgba(26,26,46,.06), 0 2px 8px rgba(26,26,46,.06);
  --shadow-md: 0 1px 2px rgba(26,26,46,.06), 0 8px 24px rgba(26,26,46,.08);
  --shadow-lg: 0 1px 2px rgba(26,26,46,.06), 0 8px 24px rgba(26,26,46,.08);
  --font: var(--font-body-studio, 'Inter', system-ui, sans-serif);
  --font-display: var(--font-display-studio, 'Space Grotesk', system-ui, sans-serif);
  --mono: var(--font-mono, 'JetBrains Mono', ui-monospace, monospace);

  /* Shell — matches the navbar content box (max-w-7xl + px-4/6/8) */
  display: flex;
  max-width: 80rem;
  margin: 0 auto;
  padding: 0 1rem;
  font-family: var(--font);
  color: var(--text);
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
}
@media (min-width: 640px)  { .threejs-app { padding: 0 1.5rem; } }
@media (min-width: 1024px) { .threejs-app { padding: 0 2rem; } }

/* Sidebar — sticky rail below the navbar, tapered separator (jsl pattern) */
.threejs-sidebar {
  background: var(--bg);
  display: flex;
  flex-direction: column;
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  position: sticky;
  top: var(--threejs-nav-h, 4rem);
  height: calc(100vh - var(--threejs-nav-h, 4rem));
}

@media (min-width: 1024px) {
  .threejs-sidebar::after {
    content: "";
    position: absolute;
    top: 2rem; right: 0; bottom: 2rem;
    width: 1px;
    background: linear-gradient(180deg, transparent 0%, var(--border) 12%, var(--border) 88%, transparent 100%);
    pointer-events: none;
  }
}

.sidebar-header {
  padding: 1.75rem 1.5rem 1rem 0.25rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.brand {
  font-weight: 700;
  font-size: 0.88rem;
  color: var(--text);
  letter-spacing: 0.04em;
  white-space: nowrap;
  font-family: var(--font-display);
}

.brand-accent { color: var(--accent); }

.menu-close {
  display: none;
  background: none;
  border: none;
  font-size: 1.5rem;
  color: var(--muted);
  cursor: pointer;
  line-height: 1;
}

.threejs-app .nav-list {
  list-style: none;
  padding: 0.75rem 1.25rem 2rem 0;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  margin: 0;
  /* Hide the scrollbar until hovered (jsl pattern) */
  scrollbar-width: none;
}
.threejs-app .nav-list:hover { scrollbar-width: thin; scrollbar-color: var(--border) transparent; }

.threejs-app .nav-link {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.55rem 0.75rem;
  color: var(--muted);
  text-decoration: none;
  font-size: 0.84rem;
  font-weight: 500;
  transition: all 0.15s;
  border-left: 2px solid var(--border);
  font-family: var(--font);
}

.threejs-app .nav-link:hover {
  color: var(--text);
  border-left-color: var(--muted);
}

.threejs-app .nav-link.active {
  color: var(--accent-dim);
  font-weight: 600;
  background: color-mix(in srgb, var(--accent) 7%, transparent);
  border-left-color: var(--accent);
}

.nav-num {
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--border2);
  font-family: var(--mono);
  min-width: 1.6rem;
}

.threejs-app .nav-link.active .nav-num { color: var(--accent); }

/* Main Content — flex child */
.threejs-content {
  flex: 1;
  padding: 1.5rem 0 3rem 2.5rem;
  min-width: 0;
}

/* Start page renders as a rounded dark "screen" block inside the shell */
.threejs-content:has(.start-page:not([hidden])) {
  padding-bottom: 2rem;
}

/* Mobile hamburger */
.menu-toggle {
  display: none;
  position: fixed;
  top: calc(var(--threejs-nav-h, 4rem) + 0.75rem);
  left: 1rem;
  z-index: 45;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.6rem;
  cursor: pointer;
  flex-direction: column;
  gap: 4px;
  box-shadow: var(--shadow-sm);
}

.menu-toggle span {
  display: block;
  width: 18px;
  height: 2px;
  background: var(--text);
  border-radius: 1px;
  transition: all 0.2s;
}

/* Mobile overlay */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(26, 26, 46, 0.35);
  backdrop-filter: blur(2px);
  z-index: 65;
}

.sidebar-overlay.visible { display: block; }

/* Responsive */
@media (max-width: 1023px) {
  .threejs-sidebar {
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    z-index: 70;
    background: var(--bg);
    border-right: 1px solid var(--border);
    box-shadow: var(--shadow-md);
    transform: translateX(-100%);
    transition: transform 0.3s ease;
    padding-left: 1.25rem;
  }

  .threejs-sidebar.open {
    transform: translateX(0);
  }

  .menu-close { display: block; }
  .menu-toggle { display: flex; }

  .threejs-content {
    padding: 3.25rem 0 2rem;
  }
}

/* Scrollbar (scoped to nav list) */
.threejs-app .nav-list::-webkit-scrollbar { width: 0; }
.threejs-app .nav-list:hover::-webkit-scrollbar { width: 6px; }
.threejs-app .nav-list::-webkit-scrollbar-track { background: transparent; }
.threejs-app .nav-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 999px; }
