/* ============================================================
   GHIDRA JOURNEY — CRT Phosphor Terminal Aesthetic
   ============================================================ */

/* --- CSS Variables --- */
:root {
  /* Dark theme (default) */
  --bg-deep: #0a0e0a;
  --bg-primary: #0d120d;
  --bg-surface: #131a13;
  --bg-elevated: #1a231a;
  --bg-hover: #1f2b1f;

  --text-primary: #c8d8c0;
  --text-secondary: #8a9a80;
  --text-muted: #5a6a52;

  --accent: #39ff14;
  --accent-dim: #2bcc10;
  --accent-glow: rgba(57, 255, 20, 0.15);
  --accent-glow-strong: rgba(57, 255, 20, 0.3);

  --border: #1e2b1e;
  --border-bright: #2a3d2a;

  --code-bg: #0a100a;
  --code-border: #1a261a;

  --sidebar-width: 260px;
  --header-height: 0px;

  --font-body: 'DM Sans', system-ui, sans-serif;
  --font-mono: 'IBM Plex Mono', 'Cascadia Code', 'Fira Code', monospace;

  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 12px;

  --shadow-glow: 0 0 20px rgba(57, 255, 20, 0.08);
  --shadow-card: 0 2px 8px rgba(0, 0, 0, 0.3);

  color-scheme: dark;
}

/* Light theme */
[data-theme="light"] {
  --bg-deep: #f0f2ee;
  --bg-primary: #f5f7f3;
  --bg-surface: #ffffff;
  --bg-elevated: #ffffff;
  --bg-hover: #e8ece5;

  --text-primary: #1a2e1a;
  --text-secondary: #4a5e42;
  --text-muted: #7a8e72;

  --accent: #1a8a08;
  --accent-dim: #157006;
  --accent-glow: rgba(26, 138, 8, 0.1);
  --accent-glow-strong: rgba(26, 138, 8, 0.18);

  --border: #d4ddd0;
  --border-bright: #b8c8b0;

  --code-bg: #f0f4ee;
  --code-border: #d0dac8;

  --shadow-glow: 0 0 20px rgba(26, 138, 8, 0.06);
  --shadow-card: 0 2px 8px rgba(0, 0, 0, 0.08);

  color-scheme: light;
}

/* --- Reset & Base --- */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.7;
  color: var(--text-primary);
  background: var(--bg-deep);
  min-height: 100vh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

/* --- CRT Scanline Overlay --- */
.crt-overlay {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 9999;
  background: repeating-linear-gradient(
    0deg,
    transparent,
    transparent 2px,
    rgba(0, 0, 0, 0.03) 2px,
    rgba(0, 0, 0, 0.03) 4px
  );
  opacity: 0.4;
}

[data-theme="light"] .crt-overlay {
  opacity: 0.12;
}

/* --- Sidebar --- */
#sidebar {
  position: fixed;
  top: 0;
  left: 0;
  width: var(--sidebar-width);
  height: 100vh;
  background: var(--bg-primary);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  z-index: 100;
  overflow: hidden;
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.sidebar-header {
  padding: 24px 20px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.site-title {
  font-family: var(--font-mono);
  font-size: 18px;
  font-weight: 600;
  color: var(--text-primary);
  letter-spacing: -0.02em;
}

.title-cursor {
  color: var(--accent);
  animation: blink 1.2s step-end infinite;
}

@keyframes blink {
  50% { opacity: 0; }
}

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

.site-subtitle {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 4px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

/* Theme toggle */
.theme-toggle-wrap {
  padding: 8px 20px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.theme-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 6px 12px;
  color: var(--text-secondary);
  cursor: pointer;
  font-family: var(--font-mono);
  font-size: 12px;
  width: 100%;
  transition: all 0.2s;
}

.theme-toggle:hover {
  border-color: var(--accent-dim);
  color: var(--text-primary);
  background: var(--bg-hover);
}

.icon-moon { display: none; }
[data-theme="dark"] .icon-sun { display: none; }
[data-theme="dark"] .icon-moon { display: block; }
[data-theme="light"] .icon-sun { display: block; }
[data-theme="light"] .icon-moon { display: none; }

/* Navigation links */
.nav-links {
  list-style: none;
  overflow-y: auto;
  flex: 1;
  padding: 8px 0;
  scrollbar-width: thin;
  scrollbar-color: var(--border-bright) transparent;
}

.nav-links::-webkit-scrollbar {
  width: 4px;
}

.nav-links::-webkit-scrollbar-thumb {
  background: var(--border-bright);
  border-radius: 2px;
}

.nav-links li a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 20px;
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 13px;
  font-weight: 500;
  transition: all 0.15s;
  border-left: 2px solid transparent;
  position: relative;
}

.nav-links li a:hover {
  color: var(--text-primary);
  background: var(--bg-hover);
  border-left-color: var(--border-bright);
}

.nav-links li a.active {
  color: var(--accent);
  background: var(--accent-glow);
  border-left-color: var(--accent);
}

.nav-num {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  min-width: 22px;
  opacity: 0.8;
}

.nav-links li a.active .nav-num {
  color: var(--accent);
  opacity: 1;
}

.nav-icon {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--accent-dim);
  min-width: 22px;
}

/* Nav section dividers */
.nav-divider {
  padding: 12px 20px 4px !important;
}

.nav-divider span {
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.1em;
}

/* Sidebar footer */
.sidebar-footer {
  padding: 12px 20px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.footer-meta {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-muted);
}

/* --- Hamburger --- */
.hamburger {
  display: none;
  position: fixed;
  top: 16px;
  left: 16px;
  z-index: 200;
  width: 40px;
  height: 40px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 5px;
  transition: all 0.2s;
}

.hamburger span {
  display: block;
  width: 18px;
  height: 2px;
  background: var(--accent);
  border-radius: 1px;
  transition: all 0.3s;
}

.hamburger.open span:nth-child(1) {
  transform: rotate(45deg) translate(5px, 5px);
}
.hamburger.open span:nth-child(2) {
  opacity: 0;
}
.hamburger.open span:nth-child(3) {
  transform: rotate(-45deg) translate(5px, -5px);
}

/* Sidebar backdrop */
.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  z-index: 90;
  backdrop-filter: blur(2px);
}

/* --- Main Content --- */
#main {
  margin-left: var(--sidebar-width);
  min-height: 100vh;
}

#content {
  max-width: 820px;
  margin: 0 auto;
  padding: 48px 40px 80px;
}

/* --- Landing Page --- */
.landing-hero {
  padding: 40px 0 56px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 56px;
}

.hero-badge {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--accent);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin-bottom: 24px;
  padding: 4px 12px;
  background: var(--accent-glow);
  border: 1px solid var(--accent-glow-strong);
  border-radius: var(--radius-sm);
  display: inline-block;
}

.hero-title {
  font-size: 42px;
  font-weight: 700;
  line-height: 1.15;
  margin-bottom: 24px;
  letter-spacing: -0.03em;
}

.hero-line1 { display: block; color: var(--text-primary); }
.hero-line2 { display: block; color: var(--text-secondary); }
.hero-line3 { display: block; color: var(--accent); }

.hero-desc {
  font-size: 17px;
  color: var(--text-secondary);
  line-height: 1.7;
  max-width: 560px;
  margin-bottom: 32px;
}

.hero-cta {
  display: inline-flex;
  align-items: center;
  gap: 0;
  font-family: var(--font-mono);
  font-size: 14px;
  font-weight: 500;
  color: var(--bg-deep);
  background: var(--accent);
  padding: 10px 24px;
  border-radius: var(--radius-sm);
  text-decoration: none;
  transition: all 0.2s;
  box-shadow: var(--shadow-glow);
}

.hero-cta:hover {
  background: var(--accent-dim);
  transform: translateY(-1px);
  box-shadow: 0 0 30px rgba(57, 255, 20, 0.2);
}

.cta-prompt {
  margin-right: 8px;
  opacity: 0.7;
}

/* Landing sections */
.landing-section {
  margin-bottom: 56px;
}

.section-heading {
  font-family: var(--font-mono);
  font-size: 20px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.heading-marker {
  color: var(--accent);
  font-size: 16px;
  opacity: 0.6;
}

.section-intro {
  color: var(--text-secondary);
  font-size: 15px;
  margin-bottom: 20px;
}

/* Pattern table */
.pattern-table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg-surface);
}

.pattern-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

.pattern-table th {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  padding: 12px 16px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  background: var(--bg-elevated);
}

.pattern-table td {
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  color: var(--text-secondary);
}

.pattern-table tr:last-child td {
  border-bottom: none;
}

.pattern-table tr:hover td {
  background: var(--bg-hover);
}

.pattern-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 600;
  color: var(--accent);
  background: var(--accent-glow);
  border: 1px solid var(--accent-glow-strong);
  border-radius: var(--radius-sm);
}

/* Module grid */
.module-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 12px;
}

.module-card {
  display: flex;
  gap: 16px;
  padding: 16px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  text-decoration: none;
  transition: all 0.2s;
}

.module-card:hover {
  border-color: var(--border-bright);
  background: var(--bg-elevated);
  transform: translateY(-1px);
  box-shadow: var(--shadow-card);
}

.module-card.card-accent {
  border-color: var(--accent-glow-strong);
}

.card-num {
  font-family: var(--font-mono);
  font-size: 22px;
  font-weight: 600;
  color: var(--accent);
  opacity: 0.5;
  min-width: 36px;
  line-height: 1;
  padding-top: 2px;
}

.module-card:hover .card-num {
  opacity: 0.9;
}

.card-title {
  font-weight: 600;
  font-size: 14px;
  color: var(--text-primary);
  margin-bottom: 4px;
}

.card-desc {
  font-size: 13px;
  color: var(--text-muted);
  line-height: 1.5;
}

/* Prerequisites */
.prereq-list {
  list-style: none;
  display: grid;
  gap: 8px;
}

.prereq-list li {
  padding: 10px 16px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 14px;
  color: var(--text-secondary);
  position: relative;
  padding-left: 32px;
}

.prereq-list li::before {
  content: '$';
  position: absolute;
  left: 14px;
  font-family: var(--font-mono);
  color: var(--accent);
  opacity: 0.5;
}

/* Tools grid */
.tools-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 8px;
}

.tool-item {
  padding: 12px 16px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 14px;
  color: var(--text-secondary);
}

.tool-item strong {
  color: var(--text-primary);
  font-weight: 600;
}

/* ============================================================
   MODULE CONTENT — Rendered Markdown
   ============================================================ */

.module-content {
  animation: fadeIn 0.25s ease;
}

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

/* Headings */
.module-content h1 {
  font-size: 32px;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 8px;
  padding-bottom: 16px;
  border-bottom: 2px solid var(--accent-glow-strong);
  letter-spacing: -0.02em;
  line-height: 1.2;
}

.module-content h2 {
  font-size: 22px;
  font-weight: 600;
  color: var(--text-primary);
  margin-top: 48px;
  margin-bottom: 16px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
  letter-spacing: -0.01em;
}

.module-content h3 {
  font-size: 17px;
  font-weight: 600;
  color: var(--text-primary);
  margin-top: 32px;
  margin-bottom: 12px;
}

.module-content h4 {
  font-size: 15px;
  font-weight: 600;
  color: var(--accent-dim);
  margin-top: 24px;
  margin-bottom: 8px;
  font-family: var(--font-mono);
}

/* Paragraphs and text */
.module-content p {
  margin-bottom: 16px;
  color: var(--text-primary);
  line-height: 1.75;
}

.module-content strong {
  font-weight: 600;
  color: var(--text-primary);
}

.module-content em {
  font-style: italic;
  color: var(--text-secondary);
}

/* Links */
.module-content a {
  color: var(--accent);
  text-decoration: none;
  border-bottom: 1px solid var(--accent-glow-strong);
  transition: all 0.15s;
}

.module-content a:hover {
  border-bottom-color: var(--accent);
}

/* Lists */
.module-content ul,
.module-content ol {
  margin-bottom: 16px;
  padding-left: 24px;
}

.module-content li {
  margin-bottom: 6px;
  color: var(--text-primary);
  line-height: 1.65;
}

.module-content li::marker {
  color: var(--text-muted);
}

/* Inline code */
.module-content code:not(pre code) {
  font-family: var(--font-mono);
  font-size: 0.88em;
  background: var(--code-bg);
  border: 1px solid var(--code-border);
  border-radius: 3px;
  padding: 1px 6px;
  color: var(--accent-dim);
}

/* Code blocks */
.module-content pre {
  margin-bottom: 20px;
  border-radius: var(--radius-md);
  border: 1px solid var(--code-border);
  overflow: hidden;
  background: var(--code-bg);
  position: relative;
}

.module-content pre code {
  display: block;
  padding: 20px 24px;
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.6;
  overflow-x: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--border-bright) transparent;
}

.module-content pre code::-webkit-scrollbar {
  height: 4px;
}

.module-content pre code::-webkit-scrollbar-thumb {
  background: var(--border-bright);
  border-radius: 2px;
}

/* Code block glow on left edge */
.module-content pre::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 3px;
  background: var(--accent);
  opacity: 0.3;
}

/* Tables */
.module-content table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 20px;
  font-size: 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
}

.module-content thead th {
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  background: var(--bg-elevated);
  padding: 10px 14px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

.module-content tbody td {
  padding: 9px 14px;
  border-bottom: 1px solid var(--border);
  color: var(--text-secondary);
  vertical-align: top;
}

.module-content tbody tr:last-child td {
  border-bottom: none;
}

.module-content tbody tr:hover td {
  background: var(--bg-hover);
}

/* Blockquotes */
.module-content blockquote {
  border-left: 3px solid var(--accent);
  margin: 20px 0;
  padding: 12px 20px;
  background: var(--accent-glow);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  color: var(--text-secondary);
}

.module-content blockquote p {
  margin-bottom: 0;
  color: var(--text-secondary);
}

/* Horizontal rules */
.module-content hr {
  border: none;
  height: 1px;
  background: var(--border);
  margin: 40px 0;
}

/* Images */
.module-content img {
  max-width: 100%;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
}

/* --- Module Nav (Prev/Next) --- */
.module-nav {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding-top: 40px;
  margin-top: 40px;
  border-top: 1px solid var(--border);
}

.nav-btn {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 12px 20px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  text-decoration: none;
  transition: all 0.2s;
  min-width: 0;
  max-width: 48%;
}

.nav-btn:hover {
  border-color: var(--accent-dim);
  background: var(--bg-elevated);
}

.nav-btn.nav-next {
  margin-left: auto;
  text-align: right;
  align-items: flex-end;
}

.nav-dir {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.nav-label {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.nav-btn[style*="display: none"],
.nav-btn.hidden {
  visibility: hidden;
}

/* --- Loading state --- */
.loading-indicator {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 80px 0;
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 14px;
}

.loading-indicator::after {
  content: '';
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  margin-left: 12px;
  animation: spin 0.8s linear infinite;
}

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

/* Error state */
.error-message {
  padding: 24px;
  background: rgba(255, 60, 60, 0.08);
  border: 1px solid rgba(255, 60, 60, 0.2);
  border-radius: var(--radius-md);
  color: #ff6b6b;
  font-family: var(--font-mono);
  font-size: 14px;
}

/* ============================================================
   RESPONSIVE
   ============================================================ */

@media (max-width: 900px) {
  #sidebar {
    transform: translateX(-100%);
  }

  #sidebar.open {
    transform: translateX(0);
    box-shadow: 4px 0 24px rgba(0, 0, 0, 0.4);
  }

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

  .hamburger {
    display: flex;
  }

  #main {
    margin-left: 0;
  }

  #content {
    padding: 72px 20px 60px;
  }

  .hero-title {
    font-size: 28px;
  }

  .module-grid {
    grid-template-columns: 1fr;
  }

  .module-content h1 {
    font-size: 24px;
  }

  .module-content h2 {
    font-size: 19px;
  }

  .module-nav {
    flex-direction: column;
  }

  .nav-btn {
    max-width: 100%;
  }

  .nav-btn.nav-next {
    text-align: left;
    align-items: flex-start;
  }
}

@media (max-width: 480px) {
  #content {
    padding: 64px 16px 48px;
  }

  .hero-title {
    font-size: 24px;
  }

  .module-content pre code {
    font-size: 12px;
    padding: 16px;
  }

  .pattern-table {
    font-size: 13px;
  }

  .tools-grid {
    grid-template-columns: 1fr;
  }
}

/* ============================================================
   HIGHLIGHT.JS OVERRIDE
   ============================================================ */

/* Ensure hljs backgrounds match our theme */
.hljs {
  background: var(--code-bg) !important;
  color: var(--text-primary) !important;
}

/* Smooth theme transition */
* {
  transition-property: background-color, border-color, color, box-shadow, opacity;
  transition-duration: 0s;
}

body.theme-transitioning,
body.theme-transitioning *,
body.theme-transitioning *::before,
body.theme-transitioning *::after {
  transition-duration: 0.3s !important;
  transition-timing-function: ease !important;
}

/* Selection color */
::selection {
  background: var(--accent-glow-strong);
  color: var(--text-primary);
}
