/* ============================================================
   CryptoLearn — dark terminal theme
   ============================================================ */
:root {
  --bg: #0a0e14;
  --bg-panel: #11161f;
  --bg-panel-2: #161d29;
  --border: #1f2937;
  --text: #c9d4e3;
  --text-dim: #7d8aa0;
  --accent: #00e07f;      /* terminal green */
  --accent-2: #38d9f5;    /* cyan */
  --warn: #ffb454;
  --danger: #ff6b6b;
  --mono: "Cascadia Code", "JetBrains Mono", "Fira Code", Consolas, monospace;
  --sans: "Segoe UI", system-ui, -apple-system, sans-serif;
  --sidebar-w: 280px;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

/* ---------- Themed scrollbars ---------- */
/* Firefox */
* {
  scrollbar-width: thin;
  scrollbar-color: var(--border) var(--bg);
}
/* Chrome / Edge / Safari */
::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}
::-webkit-scrollbar-track {
  background: var(--bg);
}
::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 6px;
  border: 2px solid var(--bg);
}
::-webkit-scrollbar-thumb:hover {
  background: var(--accent);
}
::-webkit-scrollbar-corner {
  background: var(--bg);
}
/* thinner bars inside panels (sidebar, tables, code blocks) */
#sidebar::-webkit-scrollbar,
.table-scroll::-webkit-scrollbar,
pre::-webkit-scrollbar,
.output::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
#sidebar::-webkit-scrollbar-thumb,
.table-scroll::-webkit-scrollbar-thumb,
pre::-webkit-scrollbar-thumb,
.output::-webkit-scrollbar-thumb {
  border-width: 1px;
  border-color: var(--bg-panel);
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.7;
}

/* ---------- Layout ---------- */
.layout { display: flex; min-height: 100vh; }

#sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--bg-panel);
  border-right: 1px solid var(--border);
  padding: 1.2rem 0.9rem 3rem;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  font-size: 0.92rem;
}

main {
  flex: 1;
  min-width: 0;
  width: 100%;
  padding: 2.5rem clamp(1.2rem, 4vw, 4.5rem) 5rem;
}

/* ---------- Mobile top bar (injected by main.js) ---------- */
#mobile-topbar { display: none; }
#sidebar-overlay { display: none; }

@media (max-width: 900px) {
  #mobile-topbar {
    display: flex;
    align-items: center;
    gap: 0.8rem;
    position: sticky;
    top: 0;
    z-index: 60;
    background: var(--bg-panel);
    border-bottom: 1px solid var(--border);
    padding: 0.55rem 1rem;
  }
  #mobile-topbar .site-title { margin: 0; font-size: 1rem; }
  #menu-toggle {
    margin: 0;
    padding: 0.35rem 0.7rem;
    font-size: 1.05rem;
    line-height: 1;
  }

  #sidebar {
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    height: 100dvh;
    width: min(82vw, 300px);
    transform: translateX(-102%);
    transition: transform 0.22s ease;
    z-index: 80;
    box-shadow: 4px 0 24px rgba(0, 0, 0, 0.5);
  }
  #sidebar.open { transform: none; }

  #sidebar-overlay.show {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
    z-index: 70;
  }

  main { padding: 1.3rem 1rem 4rem; }
  body { font-size: 15px; }
  h1 { font-size: 1.45rem; }
  h2 { font-size: 1.18rem; }

  /* wide content scrolls instead of breaking the layout */
  .table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .table-scroll > table { min-width: 560px; margin: 0; }
  pre { padding: 0.8rem 0.9rem; font-size: 0.82rem; }
  .widget, .quiz { padding: 1rem 1rem; }

  .page-nav { flex-direction: column; }
  .page-nav a { max-width: 100%; }
  .hero { padding: 1.6rem 0.5rem 1rem; }
  .hero h1 { font-size: 1.7rem; }
}

/* ---------- Desktop collapsible sidebar ---------- */
#desktop-collapse { display: none; }

@media (min-width: 901px) {
  #sidebar {
    transition: margin-left 0.22s ease, visibility 0s;
  }
  body.nav-collapsed #sidebar {
    margin-left: calc(-1 * var(--sidebar-w));
    visibility: hidden;
    transition: margin-left 0.22s ease, visibility 0s 0.22s;
  }

  #desktop-collapse {
    display: block;
    position: fixed;
    top: 1rem;
    left: var(--sidebar-w);
    transform: translateX(-50%);
    z-index: 85;
    margin: 0;
    padding: 0.32rem 0.55rem;
    font-size: 0.75rem;
    line-height: 1;
    border-radius: 999px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.45);
    transition: left 0.22s ease;
  }
  body.nav-collapsed #desktop-collapse { left: 1.6rem; }
}

/* comfortable tap targets on touch devices */
@media (pointer: coarse) {
  button, .btn { padding: 0.6rem 1.1rem; }
  #sidebar a { padding: 0.55rem 0.6rem; }
}

/* ---------- Sidebar nav ---------- */
.site-title {
  font-family: var(--mono);
  font-size: 1.15rem;
  color: var(--accent);
  text-decoration: none;
  display: block;
  margin: 0 0.4rem 1.2rem;
}
.site-title::before { content: "> "; color: var(--accent-2); }

#sidebar .nav-section { margin-bottom: 0.35rem; }
#sidebar .nav-row { display: flex; align-items: center; gap: 0.2rem; }
#sidebar .nav-row > a { flex: 1; min-width: 0; }
#sidebar a {
  display: block;
  color: var(--text-dim);
  text-decoration: none;
  padding: 0.3rem 0.6rem;
  border-radius: 6px;
  border-left: 2px solid transparent;
}
#sidebar a:hover { color: var(--text); background: var(--bg-panel-2); }
#sidebar a.active {
  color: var(--accent);
  border-left-color: var(--accent);
  background: var(--bg-panel-2);
  font-weight: 600;
}
#sidebar .nav-num { font-family: var(--mono); color: var(--accent-2); font-size: 0.8rem; margin-right: 0.4rem; }

/* expand/collapse toggle for topic details */
#sidebar .nav-expand {
  flex-shrink: 0;
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 0.85rem;
  padding: 0.2rem 0.45rem;
  margin: 0;
  cursor: pointer;
  border-radius: 4px;
  transition: transform 0.18s ease, color 0.15s;
}
#sidebar .nav-expand:hover { color: var(--accent); background: var(--bg-panel-2); }
#sidebar .nav-expand.rot { transform: rotate(90deg); }

/* topic detail list */
#sidebar .nav-topics {
  display: none;
  margin: 0.15rem 0 0.3rem 1.1rem;
  border-left: 1px solid var(--border);
}
#sidebar .nav-topics.open { display: block; }
#sidebar .nav-topics a {
  font-size: 0.8rem;
  padding: 0.22rem 0.6rem;
  border-left: 2px solid transparent;
  color: var(--text-dim);
}
#sidebar .nav-topics a::before { content: "\2937  "; color: var(--accent-2); opacity: 0.6; }
#sidebar .nav-topics a:hover { color: var(--accent-2); }

/* ---------- Typography ---------- */
h1, h2, h3, h4 { font-family: var(--mono); line-height: 1.3; color: #eaf1fb; }
h1 { font-size: 1.9rem; margin-top: 0; border-bottom: 1px solid var(--border); padding-bottom: 0.6rem; }
h1::before { content: "# "; color: var(--accent); }
h2 { font-size: 1.35rem; margin-top: 2.5rem; }
h2::before { content: "## "; color: var(--accent-2); }
h3 { font-size: 1.1rem; margin-top: 1.8rem; }
h3::before { content: "### "; color: var(--text-dim); }

a { color: var(--accent-2); }
a:hover { color: var(--accent); }

strong { color: #eaf1fb; }

/* ---------- Code ---------- */
code {
  font-family: var(--mono);
  background: var(--bg-panel-2);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.1em 0.4em;
  font-size: 0.88em;
  color: var(--accent);
}
pre {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1rem 1.2rem;
  overflow-x: auto;
  line-height: 1.55;
}
pre code { background: none; border: none; padding: 0; color: var(--text); }

/* ---------- Tables ---------- */
table { border-collapse: collapse; width: 100%; margin: 1.2rem 0; font-size: 0.92rem; }
th, td { border: 1px solid var(--border); padding: 0.5rem 0.8rem; text-align: left; }
th { background: var(--bg-panel-2); font-family: var(--mono); color: var(--accent-2); font-size: 0.85rem; }
tr:nth-child(even) td { background: var(--bg-panel); }

/* ---------- Boxes ---------- */
.box {
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent-2);
  background: var(--bg-panel);
  border-radius: 8px;
  padding: 1rem 1.3rem;
  margin: 1.4rem 0;
}
.box-title { font-family: var(--mono); font-weight: 700; color: var(--accent-2); margin-bottom: 0.4rem; }
.box.warn { border-left-color: var(--warn); }
.box.warn .box-title { color: var(--warn); }
.box.danger { border-left-color: var(--danger); }
.box.danger .box-title { color: var(--danger); }
.box.tip { border-left-color: var(--accent); }
.box.tip .box-title { color: var(--accent); }

/* ---------- Interactive widget panel ---------- */
.widget {
  background: var(--bg-panel);
  border: 1px solid var(--accent);
  border-radius: 10px;
  padding: 1.3rem 1.5rem;
  margin: 1.8rem 0;
  box-shadow: 0 0 24px rgba(0, 224, 127, 0.06);
}
.widget-title {
  font-family: var(--mono);
  color: var(--accent);
  font-weight: 700;
  margin-bottom: 0.9rem;
}
.widget-title::before { content: "[~] "; color: var(--accent-2); }
.widget label { display: block; font-size: 0.85rem; color: var(--text-dim); margin: 0.7rem 0 0.25rem; font-family: var(--mono); }
.widget input[type="text"], .widget input[type="number"], .widget textarea, .widget select {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-family: var(--mono);
  font-size: 0.92rem;
  padding: 0.5rem 0.7rem;
}
.widget input:focus, .widget textarea:focus, .widget select:focus {
  outline: none;
  border-color: var(--accent);
}
.widget input[type="range"] { width: 100%; accent-color: var(--accent); }
.widget .output {
  background: var(--bg);
  border: 1px dashed var(--accent-2);
  border-radius: 6px;
  padding: 0.6rem 0.8rem;
  font-family: var(--mono);
  min-height: 2.2rem;
  margin-top: 0.7rem;
  word-break: break-all;
  white-space: pre-wrap;
  color: var(--accent-2);
}

button, .btn {
  background: var(--bg-panel-2);
  border: 1px solid var(--accent);
  color: var(--accent);
  font-family: var(--mono);
  font-size: 0.9rem;
  padding: 0.45rem 1rem;
  border-radius: 6px;
  cursor: pointer;
  margin-top: 0.6rem;
  transition: background 0.15s, color 0.15s;
}
button:hover, .btn:hover { background: var(--accent); color: var(--bg); }

/* ---------- Quiz ---------- */
.quiz {
  background: var(--bg-panel);
  border: 1px solid var(--accent-2);
  border-radius: 10px;
  padding: 1.3rem 1.5rem;
  margin: 1.8rem 0;
}
.quiz-header { font-family: var(--mono); color: var(--accent-2); font-weight: 700; margin-bottom: 0.8rem; }
.quiz-header::before { content: "[?] "; color: var(--accent); }
.quiz-q { margin-bottom: 1.2rem; }
.quiz-q p { margin: 0 0 0.5rem; font-weight: 600; }
.quiz-q button {
  display: block;
  width: 100%;
  text-align: left;
  margin: 0.35rem 0 0;
  border-color: var(--border);
  color: var(--text);
  font-family: var(--sans);
}
.quiz-q button:hover { background: var(--bg-panel-2); color: var(--text); border-color: var(--accent-2); }
.quiz-q button.correct { border-color: var(--accent); color: var(--accent); background: rgba(0, 224, 127, 0.08); }
.quiz-q button.incorrect { border-color: var(--danger); color: var(--danger); background: rgba(255, 107, 107, 0.08); }
.quiz-q .explain {
  display: none;
  font-size: 0.88rem;
  color: var(--text-dim);
  border-left: 2px solid var(--accent);
  padding-left: 0.8rem;
  margin-top: 0.6rem;
}
.quiz-q.answered .explain { display: block; }

/* ---------- Diagrams ---------- */
.diagram {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1.2rem;
  margin: 1.6rem 0;
  overflow-x: auto;
  text-align: center;
}
.diagram svg { max-width: 100%; height: auto; }
.diagram-caption { font-size: 0.85rem; color: var(--text-dim); font-family: var(--mono); margin-top: 0.6rem; text-align: center; }
pre.ascii-diagram {
  text-align: left;
  line-height: 1.35;
  font-size: 0.82rem;
  color: var(--accent-2);
  border-color: var(--accent-2);
}

/* ---------- Resources ---------- */
.resources { margin: 1.5rem 0; }
.resource-card {
  display: flex;
  gap: 0.9rem;
  align-items: baseline;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.7rem 1rem;
  margin: 0.5rem 0;
}
.resource-card .rtype {
  font-family: var(--mono);
  font-size: 0.72rem;
  padding: 0.1rem 0.5rem;
  border-radius: 4px;
  border: 1px solid var(--accent-2);
  color: var(--accent-2);
  white-space: nowrap;
  text-transform: uppercase;
}
.resource-card .rtype.video { border-color: var(--danger); color: var(--danger); }
.resource-card .rtype.book, .resource-card .rtype.pdf { border-color: var(--warn); color: var(--warn); }
.resource-card .rtype.course { border-color: var(--accent); color: var(--accent); }
.resource-card .rdesc { font-size: 0.85rem; color: var(--text-dim); }

/* ---------- Prev / Next ---------- */
.page-nav {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  margin-top: 4rem;
  border-top: 1px solid var(--border);
  padding-top: 1.5rem;
  font-family: var(--mono);
  font-size: 0.9rem;
}
.page-nav a {
  text-decoration: none;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.7rem 1.1rem;
  max-width: 48%;
}
.page-nav a:hover { border-color: var(--accent); }
.page-nav .nav-label { display: block; font-size: 0.72rem; color: var(--text-dim); }

/* ---------- Homepage ---------- */
.hero { text-align: center; padding: 3rem 1rem 2rem; }
.hero h1 { border: none; font-size: 2.4rem; }
.hero h1::before { content: "$ "; }
.hero .tagline { color: var(--text-dim); font-size: 1.1rem; max-width: 620px; margin: 0.5rem auto 0; }
.hero .cursor { display: inline-block; width: 0.6em; height: 1.1em; background: var(--accent); vertical-align: text-bottom; animation: blink 1.1s steps(1) infinite; }
@keyframes blink { 50% { opacity: 0; } }

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: 1rem;
  margin-top: 2rem;
}
.card {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1.2rem 1.3rem;
  text-decoration: none;
  color: var(--text);
  transition: border-color 0.15s, transform 0.15s;
  display: block;
}
.card:hover { border-color: var(--accent); transform: translateY(-2px); color: var(--text); }
.card .card-num { font-family: var(--mono); color: var(--accent); font-size: 0.8rem; }
.card h3 { margin: 0.3rem 0 0.4rem; font-size: 1.02rem; }
.card h3::before { content: ""; }
.card p { font-size: 0.85rem; color: var(--text-dim); margin: 0; }

/* ---------- Misc ---------- */
.glossary dt { font-family: var(--mono); color: var(--accent); font-weight: 700; margin-top: 1rem; }
.glossary dd { margin: 0.2rem 0 0 1.2rem; color: var(--text); }

.timeline { list-style: none; padding-left: 0; border-left: 2px solid var(--accent-2); margin-left: 0.5rem; }
.timeline li { padding: 0.4rem 0 0.4rem 1.3rem; position: relative; }
.timeline li::before {
  content: "";
  position: absolute; left: -6px; top: 0.95em;
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--bg); border: 2px solid var(--accent);
}
.timeline .t-date { font-family: var(--mono); color: var(--accent); font-weight: 700; margin-right: 0.5rem; }

footer {
  text-align: center;
  color: var(--text-dim);
  font-family: var(--mono);
  font-size: 0.8rem;
  padding: 2rem 0 0;
}

/* ---------- Select-to-lookup ---------- */
#lookup-fab {
  position: fixed;
  z-index: 90;
  display: none;
  transform: translateX(-50%);
  background: var(--bg-panel-2);
  border: 1px solid var(--accent);
  color: var(--accent);
  font-family: var(--mono);
  font-size: 0.78rem;
  padding: 0.28rem 0.65rem;
  border-radius: 999px;
  margin: 0;
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.5);
}
#lookup-fab.show { display: block; }
#lookup-fab:hover { background: var(--accent); color: var(--bg); }

#lookup-pop {
  position: fixed;
  z-index: 95;
  display: none;
  background: var(--bg-panel);
  border: 1px solid var(--accent-2);
  border-radius: 12px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.65);
  max-height: min(70vh, 420px);
  overflow: hidden;
  flex-direction: column;
}
#lookup-pop.show { display: flex; }

#lookup-pop .lp-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
  padding: 0.6rem 0.9rem;
  border-bottom: 1px solid var(--border);
  background: var(--bg-panel-2);
}
#lookup-pop .lp-term {
  font-family: var(--mono);
  color: var(--accent);
  font-weight: 700;
  font-size: 0.9rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
#lookup-pop .lp-close {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 1.2rem;
  line-height: 1;
  padding: 0.1rem 0.4rem;
  margin: 0;
  cursor: pointer;
  border-radius: 4px;
}
#lookup-pop .lp-close:hover { color: var(--danger); background: var(--bg); }

#lookup-pop .lp-tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
}
#lookup-pop .lp-tab {
  flex: 1;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  border-radius: 0;
  color: var(--text-dim);
  font-family: var(--mono);
  font-size: 0.8rem;
  padding: 0.5rem 0;
  margin: 0;
  cursor: pointer;
}
#lookup-pop .lp-tab:hover { color: var(--text); background: var(--bg-panel-2); }
#lookup-pop .lp-tab.active { color: var(--accent-2); border-bottom-color: var(--accent-2); }

#lookup-pop .lp-body {
  padding: 0.8rem 1rem 1rem;
  overflow-y: auto;
  font-size: 0.86rem;
  line-height: 1.55;
}
#lookup-pop .lp-loading, #lookup-pop .lp-none {
  color: var(--text-dim);
  font-family: var(--mono);
  font-size: 0.8rem;
  padding: 0.6rem 0;
}
#lookup-pop .lp-thumb {
  float: right;
  max-width: 90px;
  max-height: 90px;
  border-radius: 8px;
  border: 1px solid var(--border);
  margin: 0 0 0.5rem 0.7rem;
}
#lookup-pop .lp-wtitle { font-family: var(--mono); font-weight: 700; color: #eaf1fb; }
#lookup-pop .lp-wdesc { color: var(--text-dim); font-size: 0.78rem; margin-bottom: 0.4rem; }
#lookup-pop .lp-extract { margin: 0.3rem 0 0.6rem; }
#lookup-pop .lp-more {
  font-family: var(--mono);
  font-size: 0.78rem;
  text-decoration: none;
}

#lookup-pop .lp-lang-label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-family: var(--mono);
  font-size: 0.78rem;
  color: var(--text-dim);
  margin-bottom: 0.7rem;
}
#lookup-pop .lp-lang {
  flex: 1;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-family: var(--mono);
  font-size: 0.82rem;
  padding: 0.3rem 0.5rem;
}
#lookup-pop .lp-trans-src { color: var(--text-dim); }
#lookup-pop .lp-trans-arrow { color: var(--accent-2); font-family: var(--mono); margin: 0.2rem 0; }
#lookup-pop .lp-trans-res {
  color: var(--accent);
  font-size: 1.05rem;
  font-weight: 600;
}
#lookup-pop .lp-src-note {
  font-family: var(--mono);
  font-size: 0.7rem;
  color: var(--text-dim);
  border-top: 1px dashed var(--border);
  margin-top: 0.6rem;
  padding-top: 0.4rem;
}
