@import url('https://fonts.googleapis.com/css2?family=IBM+Plex+Sans:wght@300;400;500;600;700&family=IBM+Plex+Mono:wght@400;500&display=swap');

/* ===================== THEME TOKENS ===================== */
:root {
  --bg: #0d1117;
  --bg2: #161b22;
  --bg3: #21262d;
  --border: #30363d;
  --border-strong: #484f57;
  --text: #e6edf3;
  --muted: #7d8590;
  --shadow: rgba(1, 4, 9, 0.5);

  --blue: #388bfd;   --blue-dim: #1f3a6e;
  --green: #3fb950;  --green-dim: #0f3020;
  --yellow: #d29922; --yellow-dim: #3a2e00;
  --purple: #a371f7; --purple-dim: #2d1b6b;
  --orange: #db6d28; --orange-dim: #3a1f00;
  --red: #f85149;    --red-dim: #3d0c0c;
  --cyan: #56d3d3;   --cyan-dim: #0a2e2e;
}

[data-theme="light"] {
  --bg: #ffffff;
  --bg2: #f6f8fa;
  --bg3: #eaeef2;
  --border: #d0d7de;
  --border-strong: #afb8c1;
  --text: #1f2328;
  --muted: #59636e;
  --shadow: rgba(140, 149, 159, 0.2);

  --blue: #0969da;   --blue-dim: #ddf4ff;
  --green: #1a7f37;  --green-dim: #dafbe1;
  --yellow: #9a6700; --yellow-dim: #fff8c5;
  --purple: #8250df; --purple-dim: #fbefff;
  --orange: #bc4c00; --orange-dim: #fff1e5;
  --red: #cf222e;    --red-dim: #ffebe9;
  --cyan: #1b7c83;   --cyan-dim: #d3f5f5;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; scroll-padding-top: 110px; }

body {
  font-family: 'IBM Plex Sans', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  transition: background 0.2s, color 0.2s;
}

a { color: var(--blue); }

/* ===================== HEADER ===================== */
header {
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  padding: 2.25rem 1.5rem 2rem;
  text-align: center;
}
.header-badge {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--blue-dim); color: var(--blue);
  border: 1px solid var(--blue);
  border-radius: 20px; padding: 3px 12px;
  font-size: 11px; font-weight: 600; letter-spacing: 1px;
  text-transform: uppercase; margin-bottom: 1rem;
}
header h1 {
  font-size: clamp(1.4rem, 3.5vw, 2.1rem);
  font-weight: 700; line-height: 1.25;
  margin-bottom: 0.6rem;
}
header p.subtitle {
  color: var(--muted); font-size: 13px;
  max-width: 640px; margin: 0 auto 1.4rem;
}
.meta-row { display: flex; justify-content: center; gap: 1.25rem; flex-wrap: wrap; }
.meta-item { display: flex; align-items: center; gap: 5px; font-size: 12px; color: var(--muted); }
.dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }

/* ===================== TOOLBAR (sticky) ===================== */
.toolbar {
  position: sticky; top: 0; z-index: 100;
  background: color-mix(in srgb, var(--bg2) 92%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
  padding: 0.65rem 1.5rem;
}
.toolbar-inner { max-width: 1100px; margin: 0 auto; display: flex; flex-direction: column; gap: 0.6rem; }

.search-row { display: flex; gap: 0.6rem; align-items: center; }
.search-box { position: relative; flex: 1; }
.search-box .search-ico {
  position: absolute; left: 11px; top: 50%; transform: translateY(-50%);
  color: var(--muted); font-size: 13px; pointer-events: none;
}
#search {
  width: 100%; background: var(--bg); color: var(--text);
  border: 1px solid var(--border); border-radius: 8px;
  padding: 9px 34px 9px 32px; font-size: 13px; font-family: inherit;
  transition: border-color 0.15s, box-shadow 0.15s;
}
#search:focus { outline: none; border-color: var(--blue); box-shadow: 0 0 0 3px var(--blue-dim); }
#search::placeholder { color: var(--muted); }
.clear-btn {
  position: absolute; right: 8px; top: 50%; transform: translateY(-50%);
  background: var(--bg3); color: var(--muted); border: none; cursor: pointer;
  width: 20px; height: 20px; border-radius: 50%; font-size: 12px; line-height: 1;
  display: none; align-items: center; justify-content: center;
}
.clear-btn:hover { color: var(--text); }
.clear-btn.show { display: flex; }

.icon-btn {
  background: var(--bg); color: var(--muted);
  border: 1px solid var(--border); border-radius: 8px;
  width: 38px; height: 38px; cursor: pointer; font-size: 16px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; transition: all 0.15s;
}
.icon-btn:hover { color: var(--text); border-color: var(--border-strong); background: var(--bg3); }

.filter-row { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.chip {
  background: var(--bg); color: var(--muted);
  border: 1px solid var(--border); border-radius: 20px;
  padding: 4px 12px; font-size: 12px; font-weight: 500;
  cursor: pointer; white-space: nowrap; transition: all 0.15s;
}
.chip:hover { color: var(--text); border-color: var(--border-strong); }
.chip.active { background: var(--blue-dim); color: var(--blue); border-color: var(--blue); }
.result-count { margin-left: auto; font-size: 12px; color: var(--muted); font-family: 'IBM Plex Mono', monospace; white-space: nowrap; }

/* ===================== MAIN ===================== */
main { max-width: 1100px; margin: 0 auto; padding: 2rem 1.5rem 4rem; }

.intro-box {
  background: var(--bg2); border: 1px solid var(--border);
  border-left: 3px solid var(--blue); border-radius: 8px;
  padding: 1.1rem 1.4rem; margin-bottom: 2.25rem;
  font-size: 13px; color: var(--muted); line-height: 1.8;
}
.intro-box strong { color: var(--text); }

/* ===================== SECTION ===================== */
.section { margin-bottom: 2.75rem; scroll-margin-top: 120px; }
.section-title {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  margin-bottom: 1rem; padding-bottom: 0.7rem;
  border-bottom: 1px solid var(--border);
}
.section-title h2 { font-size: 1.05rem; font-weight: 600; }
.section-tag {
  font-size: 10px; font-weight: 700; letter-spacing: 1px;
  text-transform: uppercase; padding: 3px 9px; border-radius: 5px;
}
.chapters-badge { font-size: 11px; color: var(--muted); margin-left: auto; font-family: 'IBM Plex Mono', monospace; }

/* ===================== RESOURCE GRID/CARD ===================== */
.res-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(310px, 1fr)); gap: 12px; }

.res-card {
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: 8px; padding: 1rem 1.2rem;
  display: flex; flex-direction: column; gap: 8px;
  transition: border-color 0.15s, transform 0.15s, box-shadow 0.15s;
}
.res-card:hover { border-color: var(--border-strong); transform: translateY(-2px); box-shadow: 0 6px 18px var(--shadow); }
.res-header { display: flex; align-items: flex-start; gap: 10px; }
.res-icon {
  width: 32px; height: 32px; border-radius: 6px;
  display: flex; align-items: center; justify-content: center;
  font-size: 14px; flex-shrink: 0;
}
.res-meta { flex: 1; min-width: 0; }
.res-type { font-size: 10px; font-weight: 700; letter-spacing: 0.8px; text-transform: uppercase; margin-bottom: 2px; }
.res-title { font-size: 13px; font-weight: 600; color: var(--text); line-height: 1.35; word-break: break-word; }
.res-author { font-size: 11px; color: var(--muted); margin-top: 3px; }
.res-desc { font-size: 12px; color: var(--muted); line-height: 1.6; }
.res-footer { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-top: auto; padding-top: 4px; }
.tag-pill { font-size: 10px; padding: 2px 7px; border-radius: 4px; font-weight: 500; white-space: nowrap; }
.res-link {
  margin-left: auto; color: var(--blue); text-decoration: none;
  font-size: 11px; font-weight: 600; white-space: nowrap;
  display: inline-flex; align-items: center; gap: 3px;
}
.res-link:hover { text-decoration: underline; }

mark {
  background: var(--yellow-dim); color: var(--text);
  border-radius: 2px; padding: 0 1px;
}

/* ===================== CHAPTER MAP TABLE ===================== */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: 8px; }
.map-table { width: 100%; border-collapse: collapse; font-size: 12px; min-width: 560px; }
.map-table th {
  background: var(--bg3); color: var(--muted);
  font-weight: 600; font-size: 10px; text-transform: uppercase; letter-spacing: 0.8px;
  padding: 9px 12px; text-align: left; border-bottom: 1px solid var(--border);
  position: sticky; top: 0;
}
.map-table td { padding: 9px 12px; border-bottom: 1px solid var(--border); vertical-align: top; }
.map-table tr:last-child td { border-bottom: none; }
.map-table tbody tr:hover td { background: var(--bg2); }
.map-table .ch-num { font-family: 'IBM Plex Mono', monospace; color: var(--blue); font-weight: 500; white-space: nowrap; }
.map-table .ch-name { color: var(--text); font-weight: 500; }
.map-table .ch-src { color: var(--muted); font-size: 11px; line-height: 1.7; }

/* ===================== EMPTY STATE ===================== */
.empty-state { text-align: center; padding: 3rem 1rem; color: var(--muted); display: none; }
.empty-state.show { display: block; }
.empty-state .big { font-size: 2rem; margin-bottom: 0.5rem; }

/* ===================== COLOR HELPERS ===================== */
.c-blue   { background: var(--blue-dim);   color: var(--blue); }
.c-green  { background: var(--green-dim);  color: var(--green); }
.c-yellow { background: var(--yellow-dim); color: var(--yellow); }
.c-purple { background: var(--purple-dim); color: var(--purple); }
.c-orange { background: var(--orange-dim); color: var(--orange); }
.c-red    { background: var(--red-dim);    color: var(--red); }
.c-cyan   { background: var(--cyan-dim);   color: var(--cyan); }

/* ===================== BACK TO TOP ===================== */
#toTop {
  position: fixed; right: 20px; bottom: 20px; z-index: 90;
  width: 42px; height: 42px; border-radius: 50%;
  background: var(--blue); color: #fff; border: none; cursor: pointer;
  font-size: 18px; box-shadow: 0 4px 14px var(--shadow);
  opacity: 0; pointer-events: none; transition: opacity 0.2s, transform 0.2s;
}
#toTop.show { opacity: 1; pointer-events: auto; }
#toTop:hover { transform: translateY(-3px); }

/* ===================== FOOTER ===================== */
footer {
  text-align: center; padding: 2rem 1.5rem;
  border-top: 1px solid var(--border);
  color: var(--muted); font-size: 11px; line-height: 1.9;
}
footer strong { color: var(--text); }
.disclaimer {
  max-width: 720px; margin: 1rem auto 0; padding-top: 1rem;
  border-top: 1px dashed var(--border); color: var(--muted); font-size: 10.5px;
}

/* ===================== RESPONSIVE ===================== */
@media (max-width: 600px) {
  header { padding: 1.6rem 1rem 1.4rem; }
  main { padding: 1.5rem 1rem 3rem; }
  .toolbar { padding: 0.55rem 1rem; }
  .res-grid { grid-template-columns: 1fr; }
  .chapters-badge { margin-left: 0; width: 100%; }
  .result-count { display: none; }
  #toTop { right: 14px; bottom: 14px; }
}
