/* ── Design tokens ── */
:root {
  --bg: 250 250 250;
  --surface: 255 255 255;
  --border: 229 231 235;
  --text: 17 24 39;
  --muted: 107 114 128;
  --brand: #6366f1;
  --brand-dark: #4f46e5;
  --bullish: #22c55e;
  --bearish: #ef4444;
  --radius: 12px;
  --radius-sm: 8px;
}
.dark {
  --bg: 9 11 17;
  --surface: 15 18 28;
  --border: 30 35 50;
  --text: 241 245 249;
  --muted: 148 163 184;
}

/* ── Reset ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: rgb(var(--bg));
  color: rgb(var(--text));
  transition: background 0.2s, color 0.2s;
  min-height: 100vh;
}
a { color: inherit; text-decoration: none; }
button { cursor: pointer; font-family: inherit; border: none; background: transparent; color: inherit; }
input, select { font-family: inherit; }
svg { display: block; }

/* ── Navbar ── */
#navbar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 100;
  height: 64px;
  border-bottom: 1px solid rgb(var(--border));
  background: rgba(var(--bg), 0.9);
  backdrop-filter: blur(8px);
}
#navbar .inner {
  max-width: 1280px; margin: 0 auto; padding: 0 16px;
  height: 100%; display: flex; align-items: center; justify-content: space-between; gap: 16px;
}
.nav-logo {
  font-size: 20px; font-weight: 700; color: var(--brand);
  transition: color 0.15s;
}
.nav-logo:hover { color: var(--brand-dark); }
.nav-links { display: flex; gap: 4px; align-items: center; }
.nav-link {
  padding: 8px 16px; border-radius: var(--radius-sm);
  font-size: 14px; font-weight: 500;
  color: rgb(var(--muted));
  transition: color 0.15s, background 0.15s;
  border: none; background: transparent;
}
.nav-link:hover { color: rgb(var(--text)); background: rgb(var(--surface)); }
.nav-link.active { color: var(--brand); background: rgba(99,102,241,0.1); }
.theme-btn {
  width: 36px; height: 36px; border-radius: 50%;
  border: 1px solid rgb(var(--border));
  background: rgb(var(--surface));
  display: flex; align-items: center; justify-content: center;
  font-size: 16px; transition: background 0.15s;
}
.theme-btn:hover { background: rgb(var(--bg)); }

/* ── Main ── */
#main { padding-top: 64px; min-height: 100vh; }
.page { max-width: 1280px; margin: 0 auto; padding: 40px 16px; display: none; }
.page.active { display: block; }

/* ── Typography ── */
h1 { font-size: clamp(28px, 5vw, 52px); font-weight: 700; line-height: 1.15; }
h2 { font-size: 24px; font-weight: 700; }
h3 { font-size: 18px; font-weight: 600; }
p { line-height: 1.65; }

/* ── Surface card ── */
.card {
  background: rgb(var(--surface));
  border: 1px solid rgb(var(--border));
  border-radius: var(--radius);
  padding: 24px;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.card:hover { border-color: rgba(99,102,241,0.4); }
.card-sm { padding: 16px; }
.card-link { display: block; cursor: pointer; }
.card-link:hover h3 { color: var(--brand); }

/* ── Badges ── */
.badge {
  display: inline-block; padding: 2px 10px; border-radius: 999px;
  font-size: 11px; font-weight: 600; text-transform: capitalize; letter-spacing: 0.03em;
}
.badge-bullish   { background: rgba(34,197,94,0.15);  color: #16a34a; }
.badge-bearish   { background: rgba(239,68,68,0.15);  color: #dc2626; }
.badge-neutral   { background: rgba(99,102,241,0.15); color: var(--brand); }
.badge-beginner  { background: rgba(59,130,246,0.15); color: #2563eb; }
.badge-intermediate { background: rgba(234,179,8,0.15); color: #ca8a04; }
.badge-advanced  { background: rgba(168,85,247,0.15); color: #9333ea; }

/* ── Stars ── */
.stars { display: flex; gap: 2px; }
.star { font-size: 14px; }
.star-full { color: #f59e0b; }
.star-empty { color: rgb(var(--border)); }

/* ── Grid layouts ── */
.grid-3 { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 20px; }
.grid-4 { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 20px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid-23 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 16px; }
@media (max-width: 720px) {
  .grid-2, .grid-23 { grid-template-columns: 1fr; }
}

/* ── Flex utils ── */
.flex { display: flex; }
.flex-wrap { flex-wrap: wrap; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.gap-4 { gap: 16px; }

/* ── Spacing ── */
.space-y > * + * { margin-top: 24px; }
.space-y-sm > * + * { margin-top: 12px; }
.space-y-lg > * + * { margin-top: 40px; }
.mt-1 { margin-top: 4px; }
.mt-2 { margin-top: 8px; }
.mt-3 { margin-top: 12px; }
.mt-4 { margin-top: 16px; }
.mt-6 { margin-top: 24px; }
.mb-1 { margin-bottom: 4px; }
.mb-2 { margin-bottom: 8px; }
.mb-4 { margin-bottom: 16px; }
.mb-6 { margin-bottom: 24px; }
.mb-8 { margin-bottom: 32px; }

/* ── Text utils ── */
.text-muted { color: rgb(var(--muted)); }
.text-brand { color: var(--brand); }
.text-bullish { color: var(--bullish); }
.text-bearish { color: var(--bearish); }
.text-sm { font-size: 14px; }
.text-xs { font-size: 12px; }
.text-lg { font-size: 18px; }
.font-bold { font-weight: 700; }
.font-semibold { font-weight: 600; }
.font-medium { font-weight: 500; }
.leading-relaxed { line-height: 1.7; }
.truncate-2 { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.uppercase { text-transform: uppercase; }
.tracking-wide { letter-spacing: 0.08em; }
.text-center { text-align: center; }

/* ── Inputs ── */
.search-wrap { position: relative; }
.search-wrap svg { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); pointer-events: none; }
.search-input {
  width: 100%; padding: 10px 12px 10px 38px;
  border: 1px solid rgb(var(--border)); border-radius: var(--radius-sm);
  background: rgb(var(--surface)); color: rgb(var(--text));
  font-size: 14px; outline: none; transition: border-color 0.15s;
}
.search-input:focus { border-color: var(--brand); }
select.filter-select {
  padding: 8px 12px; border: 1px solid rgb(var(--border)); border-radius: var(--radius-sm);
  background: rgb(var(--surface)); color: rgb(var(--text));
  font-size: 14px; outline: none; cursor: pointer; transition: border-color 0.15s;
}
select.filter-select:focus { border-color: var(--brand); }

/* ── Pills / tag buttons ── */
.pill-btn {
  padding: 6px 14px; border-radius: 8px; border: 1px solid rgb(var(--border));
  background: transparent; color: rgb(var(--muted));
  font-size: 13px; font-weight: 500; transition: all 0.15s;
}
.pill-btn:hover { border-color: rgba(99,102,241,0.4); color: rgb(var(--text)); }
.pill-btn.active { background: var(--brand); color: #fff; border-color: var(--brand); }
.tag {
  display: inline-block; padding: 3px 10px;
  border: 1px solid rgb(var(--border)); border-radius: 6px;
  font-size: 12px; color: rgb(var(--muted));
}

/* ── Primary button ── */
.btn-primary {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 12px 24px; background: var(--brand); color: #fff;
  border-radius: var(--radius); font-weight: 600; font-size: 15px;
  border: none; transition: background 0.15s, opacity 0.15s;
}
.btn-primary:hover { background: var(--brand-dark); }
.btn-outline {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 12px 24px; border: 1px solid rgb(var(--border));
  background: transparent; color: rgb(var(--text));
  border-radius: var(--radius); font-weight: 600; font-size: 15px;
  transition: background 0.15s;
}
.btn-outline:hover { background: rgb(var(--surface)); }

/* ── Accordion (glossary) ── */
.accordion-item {
  border: 1px solid rgb(var(--border)); border-radius: var(--radius);
  background: rgb(var(--surface)); overflow: hidden;
}
.accordion-trigger {
  width: 100%; display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px; background: transparent; border: none;
  text-align: left; cursor: pointer; transition: background 0.15s;
}
.accordion-trigger:hover { background: rgba(var(--bg), 0.5); }
.accordion-body { display: none; border-top: 1px solid rgb(var(--border)); padding: 16px; }
.accordion-body.open { display: block; }
.chevron { transition: transform 0.2s; flex-shrink: 0; }
.chevron.open { transform: rotate(180deg); }

/* ── Section label ── */
.section-label {
  font-size: 11px; font-weight: 600; text-transform: uppercase;
  letter-spacing: 0.1em; color: rgb(var(--muted)); margin-bottom: 8px;
}

/* ── Detail sections ── */
.detail-section { margin-bottom: 16px; }
.detail-section-inner {
  padding: 16px; border-radius: var(--radius-sm);
  background: rgb(var(--surface)); border: 1px solid rgb(var(--border));
}

/* ── Hero ── */
.hero { display: flex; flex-wrap: wrap; align-items: center; gap: 48px; margin-bottom: 80px; }
.hero-text { flex: 1; min-width: 280px; }
.hero-chart { flex-shrink: 0; padding: 24px; border-radius: 20px; }
.hero h1 span { color: var(--bullish); }

/* ── Feature cards ── */
.feature-icon { font-size: 36px; margin-bottom: 12px; }

/* ── Learn module card ── */
.module-card-beginner     { border-color: rgba(59,130,246,0.3); background: rgba(59,130,246,0.04); }
.module-card-intermediate { border-color: rgba(234,179,8,0.3);  background: rgba(234,179,8,0.04); }
.module-card-advanced     { border-color: rgba(168,85,247,0.3); background: rgba(168,85,247,0.04); }
.module-card { padding: 24px; border-radius: 20px; border: 1px solid; cursor: pointer; transition: border-color 0.15s; }
.module-card:hover { border-color: rgba(99,102,241,0.5); }
.module-card-icon { font-size: 40px; margin-right: 16px; flex-shrink: 0; }

/* ── Module prev/next nav ── */
.module-nav { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 24px; }
.module-nav-card {
  display: block; padding: 16px 20px; text-align: left;
  background: rgb(var(--surface)); border: 1px solid rgb(var(--border));
  border-radius: var(--radius); cursor: pointer; color: inherit;
  font: inherit; transition: border-color 0.15s;
}
.module-nav-card:hover { border-color: rgba(99,102,241,0.5); }
.module-nav-card:hover .module-nav-title { color: var(--brand); }
.module-nav-next { text-align: right; grid-column: 2; }
.module-nav-label { font-size: 12px; color: rgb(var(--muted)); margin-bottom: 4px; }
.module-nav-title { font-size: 15px; font-weight: 600; transition: color 0.15s; }
@media (max-width: 640px) {
  .module-nav { grid-template-columns: 1fr; }
  .module-nav-next { grid-column: auto; }
}

/* ── Progress bars ── */
.progress-track { height: 6px; border-radius: 999px; background: rgb(var(--border)); overflow: hidden; }
.progress-fill { height: 100%; background: var(--bullish); border-radius: 999px; transition: width 0.3s; }

/* ── Section complete toggle ── */
.section-complete-btn {
  display: inline-flex; align-items: center; gap: 6px; flex-shrink: 0;
  font-size: 13px; font-weight: 500; padding: 6px 12px; border-radius: 999px;
  border: 1px solid rgb(var(--border)); background: transparent;
  color: rgb(var(--muted)); cursor: pointer; transition: all 0.15s;
}
.section-complete-btn:hover { border-color: rgba(34,197,94,0.5); color: rgb(var(--text)); }
.section-complete-btn.done { background: rgba(34,197,94,0.12); border-color: rgba(34,197,94,0.4); color: #16a34a; }
.dark .section-complete-btn.done { color: #4ade80; }

/* ── Mastery chips ── */
.mastery-chip {
  display: inline-block; padding: 2px 10px; border-radius: 999px;
  font-size: 11px; font-weight: 600; letter-spacing: 0.03em;
}
.mastery-good { background: rgba(34,197,94,0.15); color: #16a34a; }
.mastery-weak { background: rgba(239,68,68,0.15); color: #dc2626; }
.dark .mastery-good { color: #4ade80; }
.dark .mastery-weak { color: #f87171; }

/* ── Practice quiz ── */
.quiz-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 16px; }
.quiz-stat {
  text-align: center; padding: 16px 12px;
  background: rgb(var(--surface)); border: 1px solid rgb(var(--border)); border-radius: var(--radius);
}
.quiz-stat-value { font-size: 26px; font-weight: 700; }
.quiz-stat-label { font-size: 12px; color: rgb(var(--muted)); margin-top: 4px; }
.quiz-chart-box {
  display: flex; justify-content: center; padding: 24px;
  background: rgb(var(--surface)); border: 1px solid rgb(var(--border)); border-radius: var(--radius);
}
.quiz-choices { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 640px) { .quiz-choices { grid-template-columns: 1fr; } }
.quiz-choice {
  padding: 14px 18px; text-align: left; font-size: 15px; font-weight: 500;
  background: rgb(var(--surface)); border: 1px solid rgb(var(--border));
  border-radius: var(--radius-sm); cursor: pointer; color: inherit; font-family: inherit;
  transition: border-color 0.15s, background 0.15s;
}
.quiz-choice:hover:not(:disabled) { border-color: rgba(99,102,241,0.5); }
.quiz-choice:disabled { cursor: default; }
.quiz-choice.correct { border-color: var(--bullish); background: rgba(34,197,94,0.12); }
.quiz-choice.wrong { border-color: var(--bearish); background: rgba(239,68,68,0.12); }
.quiz-feedback {
  padding: 16px; border-radius: var(--radius-sm);
  background: rgb(var(--surface)); border: 1px solid rgb(var(--border));
}

/* ── Save / bookmark buttons ── */
.save-btn {
  position: absolute; top: 10px; right: 10px; z-index: 2;
  width: 30px; height: 30px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 15px; color: rgb(var(--muted));
  background: rgb(var(--surface)); border: 1px solid rgb(var(--border));
  transition: all 0.15s;
}
.save-btn:hover { color: #f59e0b; border-color: rgba(245,158,11,0.5); }
.save-btn.saved { color: #f59e0b; border-color: rgba(245,158,11,0.4); background: rgba(245,158,11,0.1); }
.save-btn-lg {
  position: static; width: auto; height: auto;
  padding: 5px 14px; border-radius: 999px;
  font-size: 13px; font-weight: 600; gap: 4px;
}
.save-star-inline { cursor: pointer; font-size: 15px; color: rgb(var(--muted)); transition: color 0.15s; }
.save-star-inline:hover, .save-star-inline.saved { color: #f59e0b; }

/* ── Global search overlay ── */
.search-overlay {
  position: fixed; inset: 0; z-index: 200; display: none;
  background: rgba(0,0,0,0.4); backdrop-filter: blur(2px);
  padding: 80px 16px 16px;
}
.search-overlay.open { display: block; }
.search-panel {
  max-width: 560px; margin: 0 auto; overflow: hidden;
  background: rgb(var(--bg)); border: 1px solid rgb(var(--border));
  border-radius: var(--radius); box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}
.search-panel .search-input {
  border: none; border-bottom: 1px solid rgb(var(--border)); border-radius: 0;
  padding: 14px 16px 14px 42px; font-size: 15px; background: transparent;
}
.search-panel .search-input:focus { border-color: rgb(var(--border)); }
.search-results { max-height: 60vh; overflow-y: auto; padding: 8px; }
.search-group-label {
  font-size: 11px; font-weight: 600; text-transform: uppercase;
  letter-spacing: 0.1em; color: rgb(var(--muted)); padding: 10px 12px 4px;
}
.search-result {
  display: flex; width: 100%; align-items: center; justify-content: space-between;
  gap: 12px; padding: 10px 12px; border-radius: var(--radius-sm);
  font-size: 14px; text-align: left; transition: background 0.15s;
}
.search-result:hover { background: rgb(var(--surface)); }

/* ── Pattern comparison ── */
.compare-scroll { overflow-x: auto; padding-bottom: 8px; }
.compare-row { margin-bottom: 16px; }
.compare-cells { display: grid; gap: 16px; }
.compare-cell {
  padding: 14px 16px; border-radius: var(--radius-sm); font-size: 14px;
  background: rgb(var(--surface)); border: 1px solid rgb(var(--border));
}
.compare-head { text-align: center; }

/* ── Glossary term links + popover ── */
.term-link { border-bottom: 1px dashed var(--brand); cursor: pointer; transition: color 0.15s; }
.term-link:hover { color: var(--brand); }
.term-popover {
  position: absolute; z-index: 150;
  background: rgb(var(--surface)); border: 1px solid rgb(var(--border));
  border-radius: var(--radius-sm); padding: 14px;
  box-shadow: 0 12px 40px rgba(0,0,0,0.25);
}

/* ── Bullet list ── */
.bullet-list { list-style: none; }
.bullet-list li { display: flex; gap: 8px; font-size: 14px; margin-bottom: 6px; }
.bullet-dot { color: var(--brand); flex-shrink: 0; margin-top: 2px; }
.check-dot { color: var(--bullish); flex-shrink: 0; margin-top: 1px; }

/* ── Related pattern chips ── */
.related-chip {
  display: inline-block; padding: 6px 14px;
  border: 1px solid rgb(var(--border)); border-radius: 8px;
  font-size: 13px; cursor: pointer; transition: all 0.15s;
}
.related-chip:hover { border-color: rgba(99,102,241,0.5); color: var(--brand); }

/* ── Back link ── */
.back-link {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 14px; color: rgb(var(--muted)); cursor: pointer;
  transition: color 0.15s; border: none; background: none;
  margin-bottom: 24px;
}
.back-link:hover { color: rgb(var(--text)); }

/* ── Timeframe chip ── */
.tf-chip {
  padding: 4px 12px; border-radius: 8px;
  background: rgba(99,102,241,0.1); color: var(--brand);
  font-size: 13px; font-weight: 500;
}

/* ── Success ring ── */
.stat-row { display: flex; flex-wrap: wrap; align-items: center; gap: 16px; }

/* ── Section step circle ── */
.step-circle {
  width: 32px; height: 32px; border-radius: 50%;
  background: rgba(99,102,241,0.1); color: var(--brand);
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 700; flex-shrink: 0;
}

/* ── Section topic chips (learn page) ── */
.topic-chip {
  font-size: 11px; padding: 4px 10px;
  border: 1px solid rgb(var(--border)); border-radius: 6px;
  color: rgb(var(--muted));
}

/* ── Cat badge colors ── */
.cat-candlestick    { background: rgba(34,197,94,0.15);  color: #16a34a; }
.cat-technical-analysis { background: rgba(59,130,246,0.15); color: #2563eb; }
.cat-market         { background: rgba(234,179,8,0.15);  color: #ca8a04; }
.cat-indicator      { background: rgba(168,85,247,0.15); color: #9333ea; }
.cat-strategy       { background: rgba(249,115,22,0.15); color: #ea580c; }

/* ── Dark-theme badge/chip legibility (lighter 400-shades on dark surfaces) ── */
.dark .badge-bullish, .dark .cat-candlestick { color: #4ade80; }
.dark .badge-bearish { color: #f87171; }
.dark .badge-neutral { color: #a5b4fc; }
.dark .badge-beginner, .dark .cat-technical-analysis { color: #60a5fa; }
.dark .badge-intermediate, .dark .cat-market { color: #facc15; }
.dark .badge-advanced, .dark .cat-indicator { color: #c084fc; }
.dark .cat-strategy { color: #fb923c; }

/* ── Animations ── */
@keyframes fadeIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }
.animate-in { animation: fadeIn 0.3s ease-out; }

/* ── Candlestick chart wrapper ── */
.chart-box { display: flex; justify-content: center; }

/* ── Empty state ── */
.empty-state { text-align: center; padding: 80px 0; color: rgb(var(--muted)); }

/* ── Anatomy / scene visual wrappers ── */
.anatomy-wrap { max-width: 340px; margin: 0 auto 24px; }
.visual-wrap { max-width: 440px; margin: 0 auto 24px; }

/* ── HR ── */
hr { border: none; border-top: 1px solid rgb(var(--border)); margin: 24px 0; }

/* ── Responsive ── */
.nav-short { display: none; }
@media (max-width: 640px) {
  #navbar .inner { gap: 8px; padding: 0 10px; }
  .nav-full { display: none; }
  .nav-short { display: inline; }
  .nav-logo { font-size: 17px; }
  .nav-links { gap: 0; overflow-x: auto; }
  .nav-link { padding: 6px 8px; font-size: 12px; }
  .theme-btn { width: 32px; height: 32px; flex-shrink: 0; }
  .hero { flex-direction: column; }
  .hero-chart { width: 100%; }
  .grid-4 { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); }
}

/* ── Accessibility ── */
.card-link:focus-visible, .module-card:focus-visible, .term-link:focus-visible,
.save-star-inline:focus-visible, button:focus-visible, [role="button"]:focus-visible {
  outline: 2px solid var(--brand); outline-offset: 2px;
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}
