@import url('https://fonts.googleapis.com/css2?family=IBM+Plex+Mono:wght@300;400;500;600;700&family=Space+Grotesk:wght@400;500;600;700&display=swap');

* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --mesh: #0a84ff;
  --mesh-light: #4da6ff;
  --mesh-faint: rgba(10,132,255,0.06);
  --mesh-glow: rgba(10,132,255,0.15);
  --bg: #fafafa;
  --text: #111111;
  --text-secondary: #444444;
  --text-muted: #777777;
  --border: #e0e0e0;
  --nav-width: 280px;
}

html { scroll-behavior: smooth; }

body {
  font-family: 'IBM Plex Mono', monospace;
  color: var(--text);
  background: var(--bg);
  line-height: 1.7;
  font-size: 16px;
  overflow-x: hidden;
}

/* ── PDF Download Button — outline with handwritten double border ── */
.pdf-download-btn {
  position: fixed; top: 16px; right: 16px; z-index: 300;
  display: flex; align-items: center; gap: 6px;
  padding: 8px 16px;
  background: transparent; color: var(--mesh);
  font-family: 'IBM Plex Mono', monospace; font-size: 12px; font-weight: 600;
  letter-spacing: 0.5px; border: none; cursor: pointer;
  transition: all 0.2s ease; text-decoration: none;
  /* handwritten double-border illusion */
  outline: 2px solid var(--mesh);
  outline-offset: 2px;
  border: 1.5px solid var(--mesh);
  border-radius: 3px;
  transform: rotate(-0.8deg);
}
.pdf-download-btn::before {
  content: '';
  position: absolute; inset: -4px;
  border: 1.5px solid rgba(10,132,255,0.35);
  border-radius: 5px;
  transform: rotate(1.2deg);
  pointer-events: none;
}
.pdf-download-btn:hover {
  background: var(--mesh-faint);
  transform: rotate(0deg);
}
.pdf-download-btn:active { transform: scale(0.97); }
.pdf-download-btn.loading { opacity: 0.6; pointer-events: none; }

/* ── Admin logout (next to PDF button) ── */
.admin-logout {
  position: fixed; top: 20px; right: 100px; z-index: 300;
  font-family: 'IBM Plex Mono', monospace; font-size: 12px;
  color: var(--mesh); cursor: pointer;
  text-decoration: underline; text-underline-offset: 3px;
  transition: opacity 0.2s;
}
.admin-logout:hover { opacity: 0.6; }
.pdf-download-btn svg { width: 14px; height: 14px; fill: currentColor; }

/* ── Desktop Nav Sidebar ── */
.nav-sidebar {
  position: fixed; top: 0; left: 0;
  width: var(--nav-width); height: 100vh;
  background: #ffffff;
  border-right: 1px solid var(--border);
  overflow-y: auto; z-index: 100; padding: 32px 0;
}
.nav-sidebar::-webkit-scrollbar { width: 4px; }
.nav-sidebar::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.nav-title {
  display: flex; align-items: center; gap: 14px;
  font-family: 'Space Grotesk', sans-serif;
  font-size: 16px; font-weight: 700;
  letter-spacing: -0.3px; text-transform: none;
  color: var(--mesh); padding: 0 24px 24px;
  border-bottom: 1px solid var(--border); margin-bottom: 16px;
}
.nav-logo {
  width: 36px; height: 36px; flex-shrink: 0;
}
.nav-title span {
  display: block; font-size: 11px; color: var(--text-muted);
  font-weight: 400; text-transform: none; letter-spacing: 0;
}

.nav-section-label {
  font-size: 10px; font-weight: 600; text-transform: uppercase;
  letter-spacing: 1.2px; color: var(--text-muted); padding: 16px 24px 8px;
}

.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 24px; color: var(--text-secondary);
  text-decoration: none; font-size: 14px; font-weight: 400;
  transition: all 0.2s ease;
  border-left: 3px solid transparent; cursor: pointer;
}
.nav-item:hover { color: var(--text); background: var(--mesh-faint); }
.nav-item.active {
  color: var(--mesh); background: var(--mesh-faint);
  border-left-color: var(--mesh); font-weight: 500;
}
.nav-item .nav-number {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 11px; color: var(--text-muted); min-width: 20px;
}
.nav-item.active .nav-number { color: var(--mesh); }

/* ── Locked nav items ── */
.nav-item .nav-lock {
  margin-left: auto;
  width: 14px; height: 14px;
  opacity: 0.35;
  flex-shrink: 0;
}
.nav-item.active .nav-lock { opacity: 0.5; }

/* ── Content Area ── */
.content-area { margin-left: var(--nav-width); min-height: 100vh; }

.section {
  display: none; padding: 48px 64px 80px; max-width: 920px; margin: 0 auto;
  animation: fadeInSection 0.4s ease;
}
.section.active { display: block; }
@keyframes fadeInSection {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ── Locked section gate ── */
.section.locked {
  position: relative;
  max-height: 100vh;
  overflow: hidden;
}
.section-gate {
  display: none;
}
.section.locked .section-gate {
  display: flex;
  position: absolute;
  bottom: 0; left: 0; right: 0;
  height: 70vh;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 10;
  /* gradient from transparent at top to solid bg at bottom */
  background: linear-gradient(
    to bottom,
    rgba(250,250,250,0) 0%,
    rgba(250,250,250,0.6) 15%,
    rgba(250,250,250,0.92) 35%,
    rgba(250,250,250,1) 50%,
    rgba(250,250,250,1) 100%
  );
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  padding: 0 24px;
}

/* ── Gate form ── */
.gate-form {
  display: flex; flex-direction: column; align-items: center;
  gap: 20px; width: 100%; max-width: 380px;
  margin-top: 40px;
}
.gate-lock-icon {
  width: 36px; height: 36px; color: var(--mesh); opacity: 0.5;
}
.gate-title {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 20px; font-weight: 700; color: var(--text);
  text-align: center;
}
.gate-subtitle {
  font-size: 13px; color: var(--text-muted);
  text-align: center; line-height: 1.6; margin-top: -8px;
}
.gate-input {
  width: 100%; padding: 10px 0;
  font-family: 'IBM Plex Mono', monospace; font-size: 14px;
  color: var(--text); background: transparent;
  border: none; border-bottom: 1.5px solid var(--mesh);
  outline: none; transition: border-color 0.2s;
}
.gate-input::placeholder { color: var(--text-muted); font-weight: 300; }
.gate-input:focus { border-bottom-color: var(--mesh-light); }
.gate-input.invalid { border-bottom-color: #cc3333; }
.gate-input.invalid::placeholder { color: #cc3333; opacity: 0.6; }
.gate-error {
  font-family: 'IBM Plex Mono', monospace; font-size: 11px;
  color: #cc3333; margin-top: -6px; margin-bottom: 8px;
  min-height: 16px;
}

.gate-submit {
  position: relative;
  padding: 10px 32px;
  font-family: 'IBM Plex Mono', monospace; font-size: 13px; font-weight: 600;
  color: var(--mesh); background: transparent;
  cursor: pointer; letter-spacing: 0.5px;
  border: none;
  /* handwritten double-border */
  outline: 2px solid var(--mesh);
  outline-offset: 2px;
  border: 1.5px solid var(--mesh);
  border-radius: 3px;
  transform: rotate(-0.6deg);
  transition: all 0.2s ease;
  margin-top: 4px;
}
.gate-submit::before {
  content: '';
  position: absolute; inset: -4px;
  border: 1.5px solid rgba(10,132,255,0.3);
  border-radius: 5px;
  transform: rotate(1deg);
  pointer-events: none;
}
.gate-submit:hover {
  background: var(--mesh-faint);
  transform: rotate(0deg);
}

/* ── Support the project link + tooltip ── */
.gate-support {
  position: relative; margin-top: 8px; text-align: center;
}
.gate-support-link {
  font-size: 13px; color: var(--mesh); cursor: pointer;
  text-decoration: underline; text-underline-offset: 3px;
  transition: opacity 0.2s;
}
.gate-support-link:hover { opacity: 0.7; }
.gate-support-tooltip {
  position: absolute; bottom: calc(100% + 10px); left: 50%;
  transform: translateX(-50%) scale(0.95); opacity: 0;
  pointer-events: none;
  background: #fff; border: 1px solid var(--border);
  border-radius: 8px; padding: 12px 20px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.1);
  text-align: center; white-space: nowrap;
  transition: all 0.2s ease;
}
.gate-support-tooltip::after {
  content: ''; position: absolute; top: 100%; left: 50%;
  transform: translateX(-50%);
  border: 6px solid transparent; border-top-color: #fff;
}
.gate-support-tooltip::before {
  content: ''; position: absolute; top: 100%; left: 50%;
  transform: translateX(-50%);
  border: 7px solid transparent; border-top-color: var(--border);
}
.gate-support-link:hover + .gate-support-tooltip,
.gate-support-tooltip.visible {
  opacity: 1; transform: translateX(-50%) scale(1);
  pointer-events: auto;
}
.gate-tooltip-title {
  font-size: 11px; color: var(--text-muted); font-weight: 600;
  text-transform: uppercase; letter-spacing: 1px; margin-bottom: 4px;
}
.gate-tooltip-number {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 16px; font-weight: 700; color: var(--mesh);
  letter-spacing: 1px;
}

/* ── Credit badge (non-admin, replaces PDF button) ── */
.credit-badge {
  position: fixed; top: 16px; right: 16px; z-index: 300;
  font-family: 'IBM Plex Mono', monospace; font-size: 12px;
  color: var(--text-muted); text-decoration: none;
  padding: 0; background: none; border: none;
  transition: opacity 0.2s ease;
}
.credit-badge span {
  color: var(--mesh); font-weight: 600;
  text-decoration: underline; text-underline-offset: 2px;
}
.credit-badge:hover { opacity: 0.7; }

.section-number {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 12px; color: var(--mesh);
  letter-spacing: 1px; text-transform: uppercase; margin-bottom: 8px;
}
.section h1 { font-size: 32px; font-weight: 700; color: var(--text); margin-bottom: 8px; line-height: 1.3; }
.section h2 { font-size: 22px; font-weight: 600; color: var(--text); margin: 40px 0 16px; }
.section h3 { font-size: 17px; font-weight: 600; color: var(--text); margin: 28px 0 12px; }
.section-subtitle { font-size: 17px; color: var(--text-secondary); margin-bottom: 32px; line-height: 1.6; }
.section p { margin-bottom: 16px; color: var(--text-secondary); line-height: 1.8; }

/* ── Illustrations ── */
.illustration-container {
  position: relative; background: transparent; border-radius: 12px;
  margin: 32px 0; overflow: visible; border: 1px solid var(--border);
}
.illustration-label {
  position: absolute; top: 16px; left: 20px;
  font-family: 'IBM Plex Mono', monospace; font-size: 11px;
  color: var(--mesh); letter-spacing: 0.5px; z-index: 2; opacity: 0.7;
}

.illustration-controls {
  display: flex; gap: 8px; padding: 12px 20px;
  background: transparent; border-top: 1px solid var(--border); flex-wrap: wrap;
}

.btn-action {
  font-family: 'IBM Plex Mono', monospace; font-size: 12px;
  padding: 6px 16px; background: transparent;
  color: var(--mesh); border: 1px solid var(--mesh);
  border-radius: 6px; cursor: pointer; transition: all 0.2s ease; user-select: none;
}
.btn-action:hover { background: rgba(10, 132, 255, 0.08); }
.btn-action.active { background: var(--mesh); color: #fff; }

/* ── Cards & Takeaways ── */
.concept-card {
  background: #fff; border: 1px solid var(--border);
  border-radius: 10px; padding: 24px; margin: 24px 0;
}
.concept-card.blue { border-color: rgba(10,132,255,0.2); background: var(--mesh-faint); }
.concept-card h4 { font-size: 15px; font-weight: 600; margin-bottom: 8px; }
.concept-card p { font-size: 14px; margin-bottom: 0; }

.key-takeaway {
  border-left: 3px solid var(--mesh); padding: 16px 20px; margin: 28px 0;
  background: var(--mesh-faint); border-radius: 0 8px 8px 0;
}
.key-takeaway p { margin: 0; font-size: 14px; color: var(--text-secondary); }
.key-takeaway strong { color: var(--text); }

.step-list { list-style: none; margin: 20px 0; }
.step-list li {
  position: relative; padding: 12px 0 12px 48px;
  color: var(--text-secondary); border-bottom: 1px solid var(--mesh-faint);
}
.step-list li:last-child { border-bottom: none; }
.step-list li::before {
  content: attr(data-step); position: absolute; left: 0; top: 12px;
  width: 28px; height: 28px; background: var(--mesh); color: #fff;
  border-radius: 50%; display: flex; align-items: center; justify-content: center;
  font-family: 'IBM Plex Mono', monospace; font-size: 12px; font-weight: 600;
}

.inline-code {
  font-family: 'IBM Plex Mono', monospace; font-size: 14px;
  background: #f5f5f5; padding: 2px 7px; border-radius: 4px; color: var(--text);
}

.spec-table { width: 100%; border-collapse: collapse; margin: 20px 0; font-size: 14px; }
.spec-table th { text-align: left; padding: 8px 12px; border-bottom: 2px solid var(--border); color: var(--mesh); font-family: 'IBM Plex Mono', monospace; font-size: 12px; letter-spacing: 0.5px; }
.spec-table td { padding: 8px 12px; border-bottom: 1px solid var(--mesh-faint); color: var(--text-secondary); }
.spec-table td:first-child { font-weight: 600; color: var(--text); }

/* ── Mobile Top Bar (hidden on desktop) ── */
.mobile-topbar {
  display: none;
  position: fixed; top: 0; left: 0; right: 0; z-index: 200;
  height: 56px; background: #fff; border-bottom: 1px solid var(--border);
  align-items: center; padding: 0 16px;
}
.mobile-topbar-title {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 15px; font-weight: 700; color: var(--mesh);
  flex: 1; text-align: center;
}
.mobile-menu-btn {
  width: 40px; height: 40px; border: none; background: none; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  border-radius: 8px; transition: background 0.2s;
}
.mobile-menu-btn:hover { background: var(--mesh-faint); }
.mobile-menu-btn svg { width: 22px; height: 22px; stroke: var(--mesh); fill: none; stroke-width: 2; }
.mobile-topbar-spacer { width: 40px; }

/* ── Mobile Bottom Drawer ── */
.drawer-overlay {
  display: none; position: fixed; inset: 0; z-index: 400;
  background: rgba(0,0,0,0.4); opacity: 0;
  transition: opacity 0.3s ease;
  -webkit-backdrop-filter: blur(2px); backdrop-filter: blur(2px);
}
.drawer-overlay.visible { opacity: 1; }

.mobile-drawer {
  display: none; position: fixed; bottom: 0; left: 0; right: 0; z-index: 500;
  background: #fff; border-radius: 20px 20px 0 0;
  box-shadow: 0 -4px 30px rgba(0,0,0,0.15);
  max-height: 85vh; overflow: hidden;
  transform: translateY(100%);
  transition: transform 0.35s cubic-bezier(0.32, 0.72, 0, 1);
}
.mobile-drawer.open { transform: translateY(0); }

.drawer-handle {
  display: flex; justify-content: center; padding: 12px 0 8px;
  cursor: grab; touch-action: none;
}
.drawer-handle::after {
  content: ''; width: 36px; height: 4px; border-radius: 2px;
  background: var(--border);
}

.drawer-header {
  padding: 0 20px 12px; border-bottom: 1px solid var(--border);
}
.drawer-header-title {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 16px; font-weight: 700; color: var(--mesh);
}
.drawer-header-sub {
  font-size: 11px; color: var(--text-muted); margin-top: 2px;
}

.drawer-content {
  overflow-y: auto; -webkit-overflow-scrolling: touch;
  max-height: calc(85vh - 80px); padding: 8px 0 env(safe-area-inset-bottom, 20px);
}

.drawer-section-label {
  font-size: 10px; font-weight: 600; text-transform: uppercase;
  letter-spacing: 1.2px; color: var(--text-muted); padding: 14px 20px 6px;
}

.drawer-item {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 20px; color: var(--text-secondary);
  font-size: 15px; font-weight: 400; cursor: pointer;
  transition: all 0.15s ease; border-left: 3px solid transparent;
}
.drawer-item:active { background: var(--mesh-faint); }
.drawer-item.active {
  color: var(--mesh); background: var(--mesh-faint);
  border-left-color: var(--mesh); font-weight: 500;
}
.drawer-item .drawer-number {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 12px; color: var(--text-muted); min-width: 22px;
  font-weight: 500;
}
.drawer-item.active .drawer-number { color: var(--mesh); }

/* ── Locked drawer items ── */
.drawer-item .drawer-lock {
  margin-left: auto;
  width: 14px; height: 14px;
  opacity: 0.3;
  flex-shrink: 0;
}

/* ── PDF Progress Overlay ── */
.pdf-progress-overlay {
  display: none; position: fixed; inset: 0; z-index: 9999;
  background: rgba(250,250,250,0.95); align-items: center; justify-content: center;
  flex-direction: column; gap: 16px;
}
.pdf-progress-overlay.visible { display: flex; }
.pdf-progress-text {
  font-family: 'IBM Plex Mono', monospace; font-size: 14px;
  color: var(--text-secondary);
}
.pdf-progress-bar {
  width: 240px; height: 4px; background: var(--border); border-radius: 2px; overflow: hidden;
}
.pdf-progress-fill {
  height: 100%; width: 0; background: var(--mesh); border-radius: 2px;
  transition: width 0.3s ease;
}

/* ── Tablet (1024px) ── */
@media (max-width: 1024px) {
  .nav-sidebar { width: 240px; }
  .content-area { margin-left: 240px; }
  .section { padding: 32px 32px 64px; }
}

/* ── Mobile (768px) ── */
@media (max-width: 768px) {
  .nav-sidebar { display: none; }
  .content-area { margin-left: 0; padding-top: 56px; }

  .mobile-topbar { display: flex; }
  .mobile-drawer { display: block; }
  .drawer-overlay { display: block; pointer-events: none; }
  .drawer-overlay.visible { pointer-events: auto; }

  .section {
    padding: 20px 16px 100px; max-width: 100%;
  }
  .section h1 { font-size: 24px; }
  .section h2 { font-size: 18px; margin: 28px 0 12px; }
  .section h3 { font-size: 15px; margin: 20px 0 10px; }
  .section-subtitle { font-size: 14px; margin-bottom: 20px; }
  .section p { font-size: 14px; line-height: 1.7; margin-bottom: 12px; }
  .section-number { font-size: 11px; }

  .illustration-container {
    margin: 20px -16px; border-radius: 0; border-left: none; border-right: none;
  }

  .concept-card { padding: 16px; margin: 16px 0; }
  .key-takeaway { padding: 12px 16px; margin: 20px 0; }
  .key-takeaway p { font-size: 13px; }

  .step-list li { padding: 10px 0 10px 40px; font-size: 14px; }
  .step-list li::before { width: 24px; height: 24px; font-size: 11px; }

  .spec-table { font-size: 12px; }
  .spec-table th, .spec-table td { padding: 6px 8px; }

  .illustration-controls { padding: 10px 16px; }

  .pdf-download-btn { top: 10px; right: 56px; padding: 6px 12px; font-size: 11px; }
  .pdf-download-btn span.pdf-label { display: none; }
  .admin-logout { top: 14px; right: 116px; font-size: 11px; }

  .credit-badge { top: 10px; right: 10px; font-size: 11px; }

  .gate-form { max-width: 320px; }
  .gate-title { font-size: 18px; }
}

/* ── Small phones (400px) ── */
@media (max-width: 400px) {
  .section { padding: 16px 12px 100px; }
  .section h1 { font-size: 20px; }
  .illustration-container { margin: 16px -12px; }
}

/* safe area for notched phones */
@supports (padding: env(safe-area-inset-bottom)) {
  .mobile-drawer { padding-bottom: env(safe-area-inset-bottom); }
  .mobile-topbar { padding-top: env(safe-area-inset-top); }
}

/* ── Custom dialog ── */
.cd-dialog-overlay {
  display: none; position: fixed; inset: 0; z-index: 9999;
  background: rgba(0,0,0,0.25); backdrop-filter: blur(4px);
  align-items: center; justify-content: center;
}
.cd-dialog-overlay.visible { display: flex; }
.cd-dialog {
  width: 90%; max-width: 400px; padding: 32px 28px 24px;
  background: #fff; border: 1px solid var(--border); border-radius: 12px;
  box-shadow: 0 8px 40px rgba(0,0,0,0.12);
  animation: cdDialogIn 0.2s ease;
}
@keyframes cdDialogIn {
  from { opacity: 0; transform: scale(0.95) translateY(8px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}
.cd-dialog-title {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 16px; font-weight: 700; color: var(--mesh);
  margin-bottom: 8px;
}
.cd-dialog-message {
  font-family: 'IBM Plex Mono', monospace; font-size: 13px;
  color: var(--text-secondary); line-height: 1.6; margin-bottom: 24px;
}
.cd-dialog-actions {
  display: flex; gap: 10px; justify-content: flex-end;
}
.cd-dialog-btn {
  font-family: 'IBM Plex Mono', monospace; font-size: 12px;
  padding: 8px 20px; border-radius: 4px; cursor: pointer;
  transition: all 0.15s ease; border: 1px solid var(--border);
  background: transparent; color: var(--text-secondary);
}
.cd-dialog-btn:hover { background: var(--mesh-faint); }
.cd-dialog-btn.primary {
  color: var(--mesh); border-color: var(--mesh); font-weight: 600;
}
.cd-dialog-btn.primary:hover { background: rgba(10,132,255,0.08); }
