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

:root {
  --bg:         #080818;
  --bg2:        #0d0d24;
  --bg3:        #12122e;
  --surface:    #161630;
  --surface2:   #1e1e42;
  --border:     rgba(99, 102, 241, 0.15);
  --border2:    rgba(99, 102, 241, 0.3);
  --text:       #e2e8f0;
  --text-muted: #94a3b8;
  --indigo:     #6366f1;
  --indigo2:    #818cf8;
  --pink:       #ec4899;
  --cyan:       #22d3ee;
  --green:      #4ade80;
  --yellow:     #fbbf24;
  --sidebar-w:  260px;
  --radius:     12px;
}

html { scroll-behavior: smooth; font-size: 16px; }

body {
  font-family: 'Inter', 'Noto Sans JP', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  overflow-x: hidden;
}

/* ===== Three.js Background Canvas ===== */
#bg-canvas {
  position: fixed;
  top: 0; left: 0;
  width: 100%; height: 100%;
  z-index: 0;
  pointer-events: none;
}

/* ===== Sidebar ===== */
#sidebar {
  position: fixed;
  top: 0; left: 0;
  width: var(--sidebar-w);
  height: 100vh;
  background: rgba(8, 8, 24, 0.9);
  backdrop-filter: blur(20px);
  border-right: 1px solid var(--border);
  z-index: 100;
  display: flex;
  flex-direction: column;
  padding: 24px 0;
  overflow-y: auto;
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 20px 20px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 12px;
}

.logo-icon {
  font-size: 22px;
  color: var(--indigo2);
  filter: drop-shadow(0 0 8px var(--indigo));
}

.logo-text {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.05em;
  color: var(--text);
}

.sidebar-search {
  position: relative;
  padding: 0 16px 16px;
}

.sidebar-search input {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 36px 8px 12px;
  color: var(--text);
  font-size: 13px;
  font-family: inherit;
  outline: none;
  transition: border-color 0.2s;
}

.sidebar-search input:focus {
  border-color: var(--indigo);
  box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.15);
}

.search-icon {
  position: absolute;
  right: 28px;
  top: 50%;
  transform: translateY(-60%);
  font-size: 13px;
  color: var(--text-muted);
  pointer-events: none;
}

.nav-chapters {
  list-style: none;
  padding: 0 8px;
  flex: 1;
}

.nav-group-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.12em;
  color: var(--text-muted);
  text-transform: uppercase;
  padding: 12px 12px 4px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 13px;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.2s;
  margin: 1px 0;
}

.nav-item:hover {
  background: var(--surface);
  color: var(--text);
}

.nav-item.active {
  background: rgba(99, 102, 241, 0.15);
  color: var(--indigo2);
}

.nav-dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--border2);
  flex-shrink: 0;
  transition: background 0.2s;
}

.nav-item.active .nav-dot {
  background: var(--indigo);
  box-shadow: 0 0 6px var(--indigo);
}

/* ===== Main Content ===== */
#main-content {
  margin-left: var(--sidebar-w);
  position: relative;
  z-index: 1;
  min-height: 100vh;
}

/* ===== Hero Section ===== */
.hero-section {
  min-height: 100vh;
  display: flex;
  align-items: center;
  padding: 80px 60px 80px;
  position: relative;
  overflow: hidden;
}

.hero-section::before {
  content: '';
  position: absolute;
  top: -200px; left: -200px;
  width: 600px; height: 600px;
  background: radial-gradient(circle, rgba(99,102,241,0.12) 0%, transparent 70%);
  pointer-events: none;
}

.hero-inner {
  max-width: 640px;
  z-index: 1;
}

.hero-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 14px;
  border: 1px solid var(--border2);
  border-radius: 100px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--indigo2);
  margin-bottom: 28px;
  background: rgba(99, 102, 241, 0.08);
}

.hero-title {
  font-size: clamp(40px, 5vw, 68px);
  font-weight: 700;
  line-height: 1.1;
  margin-bottom: 20px;
  letter-spacing: -0.02em;
  word-break: keep-all;
}

.gradient-text {
  background: linear-gradient(135deg, var(--indigo2), var(--cyan));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.gradient-text-2 {
  background: linear-gradient(135deg, var(--pink), var(--yellow));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.hero-sub {
  font-size: 17px;
  color: var(--text-muted);
  line-height: 1.7;
  margin-bottom: 36px;
  max-width: 480px;
}

.hero-stats {
  display: flex;
  gap: 36px;
  margin-bottom: 40px;
}

.stat {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.stat-num {
  font-size: 32px;
  font-weight: 700;
  font-family: 'JetBrains Mono', monospace;
  color: var(--indigo2);
  line-height: 1;
}

.stat-label {
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.hero-btn {
  background: linear-gradient(135deg, var(--indigo), #7c3aed);
  border: none;
  border-radius: 12px;
  padding: 14px 32px;
  font-size: 15px;
  font-weight: 600;
  color: white;
  cursor: pointer;
  transition: all 0.3s;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-family: inherit;
}

.hero-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 12px 32px rgba(99, 102, 241, 0.4);
}

.hero-btn span {
  display: inline-block;
  animation: bounce 1.5s infinite;
}

@keyframes bounce {
  0%, 100% { transform: translateY(0); }
  50%       { transform: translateY(4px); }
}

.hero-3d-demo {
  position: absolute;
  right: 60px;
  top: 50%;
  transform: translateY(-50%);
  width: 380px;
  height: 380px;
}

/* ===== Chapter Header ===== */
.chapter-header {
  padding: 60px 60px 0;
  margin-bottom: 8px;
  border-top: 1px solid var(--border);
}

.chapter-num {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--indigo2);
  display: block;
  margin-bottom: 8px;
  font-family: 'JetBrains Mono', monospace;
}

.chapter-header h2 {
  font-size: 38px;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin-bottom: 8px;
}

.chapter-header p {
  color: var(--text-muted);
  font-size: 15px;
}

/* ===== Topic Section ===== */
.topic-section {
  padding: 40px 60px;
  border-bottom: 1px solid var(--border);
}

.topic-header {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 28px;
}

.topic-icon {
  width: 44px; height: 44px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 700;
  font-family: 'JetBrains Mono', monospace;
  flex-shrink: 0;
}

.js-icon    { background: rgba(251,191,36,0.15); color: var(--yellow); border: 1px solid rgba(251,191,36,0.3); }
.html-icon  { background: rgba(34,211,238,0.15); color: var(--cyan);   border: 1px solid rgba(34,211,238,0.3); }
.three-icon { background: rgba(74,222,128,0.15); color: var(--green);  border: 1px solid rgba(74,222,128,0.3); }
.css-icon   { background: rgba(236,72,153,0.15); color: var(--pink);   border: 1px solid rgba(236,72,153,0.3); }
.ts-icon    { background: rgba(96,165,250,0.15); color: #60a5fa;       border: 1px solid rgba(96,165,250,0.3); }

.topic-title {
  font-size: 20px;
  font-weight: 700;
  margin-bottom: 4px;
}

.topic-desc {
  font-size: 13px;
  color: var(--text-muted);
}

.topic-level {
  margin-left: auto;
  padding: 4px 12px;
  border-radius: 100px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.beginner     { background: rgba(74,222,128,0.12); color: var(--green); border: 1px solid rgba(74,222,128,0.25); }
.intermediate { background: rgba(251,191,36,0.12); color: var(--yellow); border: 1px solid rgba(251,191,36,0.25); }
.advanced     { background: rgba(236,72,153,0.12); color: var(--pink);  border: 1px solid rgba(236,72,153,0.25); }

/* ===== Topic Overview ===== */
.topic-overview {
  font-size: 13.5px;
  color: var(--text-muted);
  line-height: 1.85;
  margin-bottom: 24px;
  padding: 14px 18px;
  background: rgba(99, 102, 241, 0.05);
  border-radius: 8px;
  border-left: 3px solid var(--border2);
}

.topic-overview code {
  background: rgba(99, 102, 241, 0.15);
  color: var(--indigo2);
  padding: 1px 5px;
  border-radius: 4px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 12px;
}

/* ===== Cards Grid ===== */
.cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 20px;
}

/* ===== Card ===== */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  transition: all 0.3s;
  position: relative;
  overflow: hidden;
}

.card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 2px;
  background: linear-gradient(90deg, var(--indigo), var(--pink));
  opacity: 0;
  transition: opacity 0.3s;
}

.card:hover {
  border-color: var(--border2);
  transform: translateY(-2px);
  box-shadow: 0 8px 32px rgba(0,0,0,0.3);
}

.card:hover::before {
  opacity: 1;
}

.card-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--indigo2);
  margin-bottom: 12px;
}

.card pre {
  margin: 0;
  border-radius: 8px;
  overflow-x: auto;
  font-size: 12.5px;
  line-height: 1.6;
}

.card code {
  font-family: 'JetBrains Mono', monospace;
  font-size: 12.5px;
}

.card-note {
  margin-top: 12px;
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.6;
  padding: 10px 12px;
  background: rgba(255,255,255,0.03);
  border-radius: 6px;
  border-left: 2px solid var(--border2);
}

.card-note code {
  background: rgba(99,102,241,0.15);
  color: var(--indigo2);
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 11.5px;
}

.card-note strong {
  color: var(--text);
}

/* ===== Run Button & Output Panel ===== */
.code-block-wrap {
  position: relative;
}

.code-toolbar {
  display: flex;
  justify-content: flex-end;
  margin-top: 6px;
}

.run-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: rgba(99, 102, 241, 0.12);
  border: 1px solid var(--border2);
  border-radius: 6px;
  color: var(--indigo2);
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  font-weight: 600;
  padding: 4px 12px;
  cursor: pointer;
  transition: all 0.2s;
  letter-spacing: 0.04em;
}

.run-btn:hover {
  background: rgba(99, 102, 241, 0.28);
  border-color: var(--indigo2);
  color: #fff;
}

.run-btn:active { transform: scale(0.97); }
.run-btn[data-running] { opacity: 0.6; cursor: default; }

.code-output {
  margin-top: 8px;
  background: #03030e;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  font-family: 'JetBrains Mono', monospace;
  font-size: 12px;
  animation: fadeIn 0.2s ease;
}

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

.code-output-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 5px 12px;
  background: rgba(99, 102, 241, 0.07);
  border-bottom: 1px solid var(--border);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--indigo2);
}

.code-output-clear {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 13px;
  padding: 0 2px;
  line-height: 1;
  transition: color 0.2s;
  font-family: inherit;
}

.code-output-clear:hover { color: var(--text); }

.out-body {
  padding: 10px 14px;
  line-height: 1.85;
  max-height: 220px;
  overflow-y: auto;
}

.out-line {
  display: flex;
  gap: 8px;
  word-break: break-all;
}

.out-prompt { flex-shrink: 0; -webkit-user-select: none; user-select: none; }

.out-log   .out-prompt { color: var(--indigo2); }
.out-error .out-prompt { color: #f87171; }
.out-warn  .out-prompt { color: var(--yellow); }

.out-log   span:last-child { color: var(--text); }
.out-error span:last-child { color: #f87171; }
.out-warn  span:last-child { color: var(--yellow); }
.out-empty { color: var(--text-muted); font-style: italic; }

/* ===== Canvas Demo Card ===== */
.canvas-demo-card #demo-canvas {
  width: 100%;
  height: 160px;
  border-radius: 8px;
  background: var(--bg);
  display: block;
}

/* ===== Three.js Demo ===== */
.threejs-demo-container {
  width: 100%;
  height: 220px;
  border-radius: 8px;
  overflow: hidden;
  background: var(--bg);
}

/* ===== Reveal Animations ===== */
.reveal, .reveal-card {
  opacity: 0;
  transform: translateY(30px);
  transition: opacity 0.7s ease, transform 0.7s ease;
}

.reveal-card {
  transition-delay: calc(var(--card-index, 0) * 0.08s);
}

.reveal.visible, .reveal-card.visible {
  opacity: 1;
  transform: translateY(0);
}

/* ===== Search Highlight ===== */
.search-highlight {
  background: rgba(251,191,36,0.25);
  color: var(--yellow);
  border-radius: 2px;
  padding: 0 2px;
}

.topic-section.search-hidden {
  display: none;
}

/* ===== Prism Theme Override ===== */
pre[class*="language-"],
code[class*="language-"] {
  background: var(--bg) !important;
  font-family: 'JetBrains Mono', monospace !important;
}

.token.comment   { color: #506680 !important; }
.token.keyword   { color: #c792ea !important; }
.token.string    { color: #c3e88d !important; }
.token.function  { color: #82aaff !important; }
.token.number    { color: var(--yellow) !important; }
.token.operator  { color: var(--cyan) !important; }
.token.class-name { color: var(--cyan) !important; }

/* ===== Footer ===== */
.site-footer {
  text-align: center;
  padding: 48px 60px;
  color: var(--text-muted);
  font-size: 13px;
  border-top: 1px solid var(--border);
}

.footer-sub {
  font-size: 11px;
  margin-top: 4px;
  opacity: 0.6;
}

/* ===== Scrollbar ===== */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--surface2); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--indigo); }
