/* Crypto Explorer — dark "cipher terminal" theme */

:root {
  --bg: #0f1420;
  --bg-panel: #171e2e;
  --bg-inset: #0b101a;
  --bg-hover: #1f2940;
  --border: #2a3550;
  --text: #dce3f0;
  --text-muted: #8b96ad;
  --accent: #4dd8c0;        /* teal — a nod to the supermarket app palette */
  --accent-dim: #2a8a7c;
  --amber: #ffc857;
  --red: #ff6b6b;
  --green: #69db7c;
  --blue: #74a8ff;
  --purple: #b197fc;
  --mono: "Cascadia Code", Consolas, "Courier New", monospace;
  --sans: "Segoe UI", system-ui, sans-serif;
}

* { box-sizing: border-box; }

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

.fallback {
  background: #5c1f1f; color: #ffd7d7; padding: 12px 18px;
  font-size: 14px;
}
.fallback code { background: #00000055; padding: 1px 6px; border-radius: 4px; }

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

/* ---------- sidebar ---------- */
.sidebar {
  width: 250px; flex-shrink: 0;
  background: var(--bg-panel);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh;
}
.brand { padding: 18px 18px 12px; border-bottom: 1px solid var(--border); }
.brand-title { font-size: 19px; font-weight: 700; color: var(--accent); letter-spacing: 0.5px; }
.brand-sub { font-size: 12.5px; color: var(--text-muted); margin-top: 2px; }

#nav { flex: 1; overflow-y: auto; padding: 10px 0; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 16px; cursor: pointer; border-left: 3px solid transparent;
  color: var(--text-muted); font-size: 14px; user-select: none;
}
.nav-item:hover { background: var(--bg-hover); color: var(--text); }
.nav-item.active { border-left-color: var(--accent); color: var(--text); background: var(--bg-hover); }
.nav-num {
  width: 22px; height: 22px; border-radius: 50%; flex-shrink: 0;
  border: 1px solid var(--border); font-size: 11.5px;
  display: flex; align-items: center; justify-content: center; font-family: var(--mono);
}
.nav-item.done .nav-num { background: var(--accent-dim); border-color: var(--accent-dim); color: #fff; }
.nav-label { flex: 1; }
.nav-label small { display: block; font-size: 11px; opacity: 0.7; }

.sidebar-footer { padding: 14px 16px; border-top: 1px solid var(--border); }
.progress-label { font-size: 12px; color: var(--text-muted); margin-bottom: 5px; }
.progress-bar { height: 6px; background: var(--bg-inset); border-radius: 3px; overflow: hidden; }
.progress-fill { height: 100%; width: 0; background: var(--accent); transition: width .4s; }

/* ---------- main content ---------- */
.content { flex: 1; padding: 30px 42px 80px; max-width: 980px; }

h1 { font-size: 26px; margin: 0 0 4px; color: var(--text); }
h1 .zh { font-size: 16px; color: var(--text-muted); font-weight: 400; margin-left: 10px; }
h2 { font-size: 19px; margin: 34px 0 10px; color: var(--accent); }
h3 { font-size: 16px; margin: 22px 0 8px; }
p { margin: 10px 0; }
.lede { color: var(--text-muted); font-size: 15px; margin-bottom: 20px; }

code, .mono { font-family: var(--mono); font-size: 0.92em; }
code { background: var(--bg-inset); padding: 1px 6px; border-radius: 4px; border: 1px solid var(--border); }

/* bilingual term */
.term { color: var(--amber); font-weight: 600; }
.term .zh { color: var(--text-muted); font-weight: 400; font-size: 0.9em; }

/* ---------- cards & boxes ---------- */
.card {
  background: var(--bg-panel); border: 1px solid var(--border);
  border-radius: 10px; padding: 18px 20px; margin: 18px 0;
}
.card-title { font-weight: 700; font-size: 15.5px; margin-bottom: 10px; color: var(--text); }
.card-title .tag {
  font-size: 11px; padding: 2px 8px; border-radius: 10px; margin-left: 8px;
  background: var(--accent-dim); color: #fff; vertical-align: 2px; font-weight: 500;
}

.infobox {
  border-left: 3px solid var(--blue); background: #74a8ff14;
  padding: 10px 16px; border-radius: 0 8px 8px 0; margin: 14px 0; font-size: 14px;
}
.infobox.market { border-left-color: var(--amber); background: #ffc85712; }
.infobox.math { border-left-color: var(--purple); background: #b197fc12; }
.infobox.warn { border-left-color: var(--red); background: #ff6b6b12; }
.infobox .ib-title { font-weight: 700; margin-bottom: 4px; }

/* ---------- controls ---------- */
.btn {
  background: var(--accent-dim); color: #fff; border: none; border-radius: 6px;
  padding: 7px 16px; font-size: 14px; cursor: pointer; font-family: var(--sans);
}
.btn:hover { background: var(--accent); color: #06281f; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-ghost { background: transparent; border: 1px solid var(--border); color: var(--text-muted); }
.btn-ghost:hover { background: var(--bg-hover); color: var(--text); }
.btn-small { padding: 4px 10px; font-size: 12.5px; }
.btn-danger { background: #7c2a2a; }
.btn-danger:hover { background: var(--red); color: #2b0505; }

input[type="text"], textarea, select, input[type="number"] {
  background: var(--bg-inset); color: var(--text); border: 1px solid var(--border);
  border-radius: 6px; padding: 7px 10px; font-size: 14px; font-family: var(--mono);
}
input[type="text"]:focus, textarea:focus, select:focus { outline: none; border-color: var(--accent-dim); }
textarea { width: 100%; resize: vertical; }
input[type="range"] { accent-color: var(--accent); }
label { font-size: 13.5px; color: var(--text-muted); }

.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin: 10px 0; }
.grow { flex: 1; }

.output {
  background: var(--bg-inset); border: 1px solid var(--border); border-radius: 6px;
  padding: 10px 12px; font-family: var(--mono); font-size: 13.5px;
  white-space: pre-wrap; word-break: break-all; margin: 8px 0; min-height: 20px;
}
.output.ok { border-color: var(--green); }
.output.bad { border-color: var(--red); }
.output.wide { white-space: pre; overflow-x: auto; } /* keep monospace tables aligned; scroll if narrow */

.kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 14px; font-size: 13.5px; margin: 8px 0; }
.kv dt { color: var(--text-muted); font-family: var(--mono); text-align: right; }
.kv dd { margin: 0; font-family: var(--mono); word-break: break-all; }

table.simple { border-collapse: collapse; font-size: 13.5px; margin: 10px 0; width: 100%; }
table.simple th, table.simple td { border: 1px solid var(--border); padding: 5px 10px; text-align: left; }
table.simple th { background: var(--bg-inset); color: var(--text-muted); font-weight: 600; }

canvas { border-radius: 6px; }

/* ---------- freq chart bars ---------- */
.freq-chart { display: flex; align-items: flex-end; gap: 2px; height: 90px; margin: 8px 0; }
.freq-col { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; height: 100%; }
.freq-bar { width: 100%; background: var(--accent-dim); border-radius: 2px 2px 0 0; min-height: 1px; }
.freq-col.hot .freq-bar { background: var(--amber); }
.freq-letter { font-size: 9.5px; font-family: var(--mono); color: var(--text-muted); margin-top: 3px; }

/* ---------- XOR primer ---------- */
.xor-lab { margin: 14px 0; overflow-x: auto; }
.xor-row { display: flex; align-items: center; gap: 8px; margin: 5px 0; }
.xor-label { width: 180px; flex-shrink: 0; font-size: 13px; color: var(--text-muted); text-align: right; }
.xor-row.xor-out .xor-label { color: var(--accent); }
.xor-bits { display: inline-flex; gap: 4px; }
.xbit {
  display: inline-flex; align-items: center; justify-content: center;
  width: 26px; height: 26px; border: 1px solid var(--border); border-radius: 4px;
  background: var(--bg-inset); font-family: var(--mono); font-size: 13px; user-select: none;
}
.xbit.edit { cursor: pointer; }
.xbit.edit:hover { border-color: var(--accent); transform: translateY(-1px); }
.xbit.on { background: var(--accent-dim); color: #fff; border-color: var(--accent-dim); }
.xbit.derived { opacity: 0.9; }
.xbit.derived.on { background: var(--purple); border-color: var(--purple); color: #1a1030; }
.xor-val { font-family: var(--mono); font-size: 12.5px; color: var(--text-muted); white-space: pre; margin-left: 6px; }

/* ---------- bit grid (avalanche) ---------- */
.bitgrid { display: grid; grid-template-columns: repeat(32, 1fr); gap: 2px; margin: 8px 0; }
.bit { aspect-ratio: 1; border-radius: 2px; background: var(--bg-hover); }
.bit.same { background: #24443c; }
.bit.diff { background: var(--red); }

/* ---------- quiz ---------- */
.quiz { margin-top: 30px; }
.quiz-q { margin: 16px 0; }
.quiz-q .qtext { font-weight: 600; margin-bottom: 8px; }
.quiz-opt {
  display: block; padding: 8px 12px; margin: 5px 0; border: 1px solid var(--border);
  border-radius: 6px; cursor: pointer; font-size: 14px;
}
.quiz-opt:hover { background: var(--bg-hover); }
.quiz-opt.selected { border-color: var(--accent); background: #4dd8c015; }
.quiz-opt.correct { border-color: var(--green); background: #69db7c18; }
.quiz-opt.wrong { border-color: var(--red); background: #ff6b6b18; }
.quiz-explain { font-size: 13.5px; color: var(--text-muted); margin: 6px 0 0 12px; display: none; }
.quiz-explain.show { display: block; }
.quiz-score { font-size: 16px; font-weight: 700; margin-top: 14px; }

/* ---------- rating ---------- */
.rating { margin: 26px 0 10px; padding: 14px 18px; background: var(--bg-panel); border: 1px solid var(--border); border-radius: 10px; }
.stars { display: inline-flex; gap: 4px; margin-left: 10px; }
.star { font-size: 22px; cursor: pointer; color: var(--border); transition: color .15s; user-select: none; }
.star.lit { color: var(--amber); }

/* ---------- finder results ---------- */
.branch-bars { margin: 16px 0; }
.branch-row { display: flex; align-items: center; gap: 12px; margin: 8px 0; }
.branch-name { width: 300px; font-size: 13.5px; text-align: right; }
.branch-track { flex: 1; height: 18px; background: var(--bg-inset); border-radius: 9px; overflow: hidden; }
.branch-fill { height: 100%; border-radius: 9px; transition: width .8s; }
.branch-pct { width: 46px; font-family: var(--mono); font-size: 13px; }

.big-result {
  border: 2px solid var(--accent); border-radius: 12px; padding: 20px 24px; margin: 20px 0;
  background: linear-gradient(160deg, #4dd8c014, transparent);
}

/* misc */
.pill-row { display: flex; gap: 8px; flex-wrap: wrap; margin: 10px 0; }
.pill {
  padding: 4px 12px; border-radius: 14px; border: 1px solid var(--border);
  font-size: 13px; cursor: pointer; color: var(--text-muted);
}
.pill:hover, .pill.active { border-color: var(--accent); color: var(--accent); }
.muted { color: var(--text-muted); }
.small { font-size: 13px; }
.spacer { height: 10px; }
hr.soft { border: none; border-top: 1px solid var(--border); margin: 26px 0; }

.chapter-footer-nav { display: flex; justify-content: space-between; margin-top: 40px; }

/* ---------- glossary overlay ---------- */
.overlay {
  position: fixed; inset: 0; background: #000000aa; z-index: 100;
  display: flex; align-items: flex-start; justify-content: center; padding: 6vh 20px;
}
.overlay-panel {
  background: var(--bg-panel); border: 1px solid var(--border); border-radius: 12px;
  width: 100%; max-width: 720px; max-height: 82vh; display: flex; flex-direction: column;
  padding: 18px 20px; box-shadow: 0 20px 60px #000a;
}
.overlay-head { display: flex; align-items: center; justify-content: space-between; }
.gloss-list { overflow-y: auto; }
.gloss-item { padding: 10px 4px; border-bottom: 1px solid var(--border); }
.gloss-term { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; }
.gloss-jump { font-size: 12px; color: var(--text-muted); cursor: pointer; white-space: nowrap; }
.gloss-jump:hover { color: var(--accent); }
.gloss-def { font-size: 13.5px; color: var(--text-muted); margin-top: 3px; }

/* ---------- timeline ---------- */
.timeline { position: relative; margin: 18px 0 8px; padding-left: 4px; }
.tl-item {
  display: grid; grid-template-columns: 92px 1fr; gap: 14px; padding: 8px 0;
  cursor: pointer; border-radius: 8px;
}
.tl-item:hover { background: var(--bg-hover); }
.tl-year { font-family: var(--mono); font-size: 12.5px; color: var(--amber); text-align: right; padding-top: 2px; }
.tl-body { border-left: 2px solid var(--border); padding: 0 0 4px 16px; position: relative; }
.tl-body::before {
  content: ''; position: absolute; left: -6px; top: 5px; width: 9px; height: 9px;
  border-radius: 50%; background: var(--accent); border: 2px solid var(--bg);
}
.tl-title { font-weight: 600; font-size: 14.5px; }
.tl-title .zh { color: var(--text-muted); font-weight: 400; font-size: 0.85em; margin-left: 6px; }
.tl-note { font-size: 13px; color: var(--text-muted); }
.tl-jump { font-size: 11.5px; color: var(--accent-dim); }
.tl-item:hover .tl-jump { color: var(--accent); }
