:root {
  --bg: #0b1220;
  --bg-soft: #0f1a2d;
  --panel: #111c33;
  --line: #22314d;
  --text: #e8eef8;
  --muted: #94a6c4;
  --accent: #ff9900;
  --accent-soft: rgba(255, 153, 0, 0.14);
  --ok: #34d399;
  --danger: #f87171;
  --radius: 14px;
  --sidebar: 310px;
  --shadow: 0 18px 40px rgba(0, 0, 0, 0.45);
  --topbar: rgba(11, 18, 32, 0.86);
  --stripe: rgba(255, 255, 255, 0.025);
  color-scheme: dark;
}

:root[data-theme="light"] {
  --bg: #f4f6fb;
  --bg-soft: #ffffff;
  --panel: #ffffff;
  --line: #e1e7f0;
  --text: #101827;
  --muted: #5a6b85;
  --accent: #d97706;
  --accent-soft: rgba(217, 119, 6, 0.12);
  --ok: #059669;
  --danger: #dc2626;
  --shadow: 0 12px 30px rgba(16, 24, 39, 0.12);
  --topbar: rgba(244, 246, 251, 0.88);
  --stripe: rgba(16, 24, 39, 0.03);
  color-scheme: light;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 17px/1.65 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  gap: 12px;
  height: 58px;
  padding: 0 14px;
  padding-top: env(safe-area-inset-top);
  background: var(--topbar);
  backdrop-filter: saturate(160%) blur(14px);
  -webkit-backdrop-filter: saturate(160%) blur(14px);
  border-bottom: 1px solid var(--line);
}

.iconbtn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: var(--panel);
  color: var(--text);
  font-size: 17px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.iconbtn:active { transform: scale(0.96); }
#menuBtn { display: none; }

.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  min-width: 0;
  font-weight: 650;
  letter-spacing: -0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text);
}
.brand img { width: 24px; height: 24px; border-radius: 6px; }
.brand small { color: var(--muted); font-weight: 500; font-size: 12px; }

.spacer { flex: 1; }

.pill {
  font-size: 12px;
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 3px 9px;
  white-space: nowrap;
}

.progressline {
  position: absolute;
  left: 0; right: 0; bottom: -1px;
  height: 2px;
  background: transparent;
}
.progressline span {
  display: block;
  height: 100%;
  width: 0;
  background: var(--accent);
  transition: width 0.15s linear;
}

/* ---------- shell ---------- */
.shell { display: flex; min-height: calc(100vh - 58px); }

.sidebar {
  width: var(--sidebar);
  flex: 0 0 var(--sidebar);
  border-right: 1px solid var(--line);
  background: var(--bg-soft);
  height: calc(100vh - 58px);
  height: calc(100dvh - 58px);
  position: sticky;
  top: 58px;
  overflow-y: auto;
  padding: 14px 12px 40px;
  -webkit-overflow-scrolling: touch;
}

.search {
  position: relative;
  margin-bottom: 14px;
}
.search input {
  width: 100%;
  padding: 10px 12px 10px 34px;
  border-radius: 11px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  font-size: 15px;
}
.search input::placeholder { color: var(--muted); }
.search svg {
  position: absolute; left: 11px; top: 50%; transform: translateY(-50%);
  width: 15px; height: 15px; stroke: var(--muted);
}

.navgroup { margin-bottom: 18px; }
.navgroup > h3 {
  margin: 0 0 6px;
  padding: 0 8px;
  font-size: 11px;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 700;
}
.navgroup ul { list-style: none; margin: 0; padding: 0; }
.navgroup li a {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 8px 9px;
  border-radius: 9px;
  color: var(--text);
  font-size: 14.5px;
  line-height: 1.35;
  text-decoration: none;
}
.navgroup li a:hover { background: var(--accent-soft); }
.navgroup li a.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.navgroup li a .num {
  flex: 0 0 auto;
  font-variant-numeric: tabular-nums;
  font-size: 11px;
  color: var(--muted);
  min-width: 16px;
}
.navgroup li a.active .num { color: var(--accent); }
.navgroup li.hidden { display: none; }

.docprog {
  display: flex; align-items: center; gap: 8px;
  padding: 4px 9px 10px;
  font-size: 12px;
  color: var(--muted);
}
.docprog .bar { flex: 1; height: 4px; border-radius: 99px; background: var(--line); overflow: hidden; }
.docprog .bar i { display: block; height: 100%; width: 0; background: var(--accent); }

/* ---------- content ---------- */
main { flex: 1; min-width: 0; }

.wrap {
  max-width: 860px;
  margin: 0 auto;
  padding: 26px 22px 120px;
}

.crumbs {
  display: flex; gap: 6px; align-items: center;
  font-size: 12.5px; color: var(--muted); margin-bottom: 10px; flex-wrap: wrap;
}
.crumbs a { color: var(--muted); }
.crumbs a:hover { color: var(--accent); }

article h1 {
  font-size: 30px;
  line-height: 1.2;
  letter-spacing: -0.02em;
  margin: 4px 0 18px;
}
article h2 {
  font-size: 23px;
  line-height: 1.25;
  letter-spacing: -0.015em;
  margin: 34px 0 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--line);
}
article h3 { font-size: 18.5px; margin: 26px 0 8px; }
article h4 { font-size: 16px; margin: 20px 0 6px; color: var(--muted); }
article p { margin: 0 0 14px; }
article ul, article ol { margin: 0 0 16px; padding-left: 22px; }
article li { margin: 4px 0; }
article li > ul, article li > ol { margin: 6px 0; }
article strong { font-weight: 680; }
article hr { border: 0; border-top: 1px solid var(--line); margin: 30px 0; }

article code {
  font: 0.88em/1.5 ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  background: var(--accent-soft);
  border-radius: 6px;
  padding: 1px 6px;
}
article pre {
  overflow-x: auto;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px 16px;
  margin: 0 0 16px;
}
article pre code { background: none; padding: 0; }

article blockquote {
  margin: 18px 0;
  padding: 12px 16px;
  border-left: 3px solid var(--accent);
  background: var(--accent-soft);
  border-radius: 0 12px 12px 0;
  color: var(--text);
}
article blockquote p:last-child { margin-bottom: 0; }

.table-wrap {
  overflow-x: auto;
  margin: 0 0 18px;
  border: 1px solid var(--line);
  border-radius: 12px;
  -webkit-overflow-scrolling: touch;
}
table { border-collapse: collapse; width: 100%; font-size: 15px; }
th, td {
  padding: 9px 12px;
  text-align: left;
  vertical-align: top;
  border-bottom: 1px solid var(--line);
}
th {
  background: var(--panel);
  font-size: 12.5px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 700;
  white-space: nowrap;
}
tbody tr:last-child td { border-bottom: 0; }
tbody tr:nth-child(even) { background: var(--stripe); }

/* task list */
li.task { list-style: none; margin-left: -22px; }
li.task label { display: flex; gap: 10px; align-items: flex-start; cursor: pointer; }
li.task input {
  appearance: none; -webkit-appearance: none;
  flex: 0 0 auto;
  width: 19px; height: 19px; margin-top: 3px;
  border: 1.5px solid var(--line);
  border-radius: 6px;
  background: var(--panel);
  cursor: pointer;
  position: relative;
}
li.task input:checked { background: var(--accent); border-color: var(--accent); }
li.task input:checked::after {
  content: "";
  position: absolute; left: 5px; top: 1.5px;
  width: 5px; height: 10px;
  border: solid #101827;
  border-width: 0 2.5px 2.5px 0;
  transform: rotate(45deg);
}
li.task.done span { color: var(--muted); text-decoration: line-through; text-decoration-color: var(--muted); }

/* pager */
.pager {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-top: 44px;
  padding-top: 20px;
  border-top: 1px solid var(--line);
}
.pager a {
  display: block;
  padding: 13px 15px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel);
  color: var(--text);
  text-decoration: none;
}
.pager a:hover { border-color: var(--accent); text-decoration: none; }
.pager a span { display: block; font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); margin-bottom: 3px; }
.pager a.next { text-align: right; grid-column: 2; }
.pager a.prev { grid-column: 1; }
.pager .empty { visibility: hidden; }

/* home */
.hero {
  padding: 10px 0 26px;
}
.hero h1 { font-size: 34px; margin-bottom: 8px; }
.hero p { color: var(--muted); max-width: 60ch; margin: 0; }

.cards { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(255px, 1fr)); margin-top: 8px; }
.card {
  display: block;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--text);
  text-decoration: none;
  transition: transform 0.12s ease, border-color 0.12s ease;
}
.card:hover { transform: translateY(-2px); border-color: var(--accent); text-decoration: none; }
.card h2 { font-size: 17px; margin: 0 0 6px; border: 0; padding: 0; }
.card p { margin: 0; color: var(--muted); font-size: 13.5px; }
.card .meta { display: flex; align-items: center; gap: 8px; margin-top: 14px; font-size: 12px; color: var(--muted); }
.card .meta .bar { flex: 1; height: 5px; border-radius: 99px; background: var(--line); overflow: hidden; }
.card .meta .bar i { display: block; height: 100%; width: 0; background: var(--accent); }
.card .tag {
  display: inline-block;
  font-size: 10.5px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--accent);
  background: var(--accent-soft);
  border-radius: 999px;
  padding: 2px 8px;
  margin-bottom: 10px;
  font-weight: 700;
}

.list-sections { list-style: none; padding: 0; margin: 0; }
.list-sections li { border-bottom: 1px solid var(--line); }
.list-sections a { display: flex; gap: 12px; align-items: baseline; padding: 13px 4px; color: var(--text); }
.list-sections a:hover { color: var(--accent); text-decoration: none; }
.list-sections .n { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; min-width: 20px; }

.resume {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 16px;
  margin-bottom: 26px;
  border: 1px solid var(--accent);
  background: var(--accent-soft);
  border-radius: 12px;
  color: var(--text);
}
.resume strong { display: block; font-size: 14px; }
.resume small { color: var(--muted); }
.resume a { margin-left: auto; font-size: 13px; font-weight: 650; white-space: nowrap; }

.scrim {
  position: fixed; inset: 0;
  background: rgba(0, 0, 0, 0.5);
  opacity: 0; pointer-events: none;
  transition: opacity 0.2s;
  z-index: 45;
}

.offline-note {
  display: none;
  padding: 8px 22px;
  background: var(--danger);
  color: #fff;
  font-size: 13px;
  text-align: center;
}
body.offline .offline-note { display: block; }

/* ---------- responsive ---------- */
@media (max-width: 1024px) {
  #menuBtn { display: inline-flex; }
  .sidebar {
    position: fixed;
    top: 0; bottom: 0; left: 0;
    height: 100vh;
    height: 100dvh;
    z-index: 50;
    padding-top: calc(14px + env(safe-area-inset-top));
    transform: translateX(-102%);
    transition: transform 0.22s ease;
    box-shadow: var(--shadow);
    width: min(340px, 86vw);
    flex-basis: auto;
  }
  body.nav-open .sidebar { transform: translateX(0); }
  body.nav-open .scrim { opacity: 1; pointer-events: auto; }
  .wrap { padding: 20px 18px 110px; }
}

@media (max-width: 560px) {
  body { font-size: 16.5px; }
  article h1 { font-size: 26px; }
  article h2 { font-size: 21px; }
  .wrap { padding: 16px 14px 100px; }
  .pager { grid-template-columns: 1fr; }
  .pager a.next { grid-column: 1; }
  .brand small { display: none; }
}

@media print {
  .topbar, .sidebar, .pager, .scrim { display: none !important; }
  body { background: #fff; color: #000; }
  .wrap { max-width: none; padding: 0; }
}
