@font-face {
  font-family: "LXGWWenKai";
  font-weight: 400;
  font-display: swap;
  src: url("/fonts/LXGWWenKai-Regular.ttf") format("truetype");
}
@font-face {
  font-family: "LXGWWenKai";
  font-weight: 500;
  font-display: swap;
  src: url("/fonts/LXGWWenKai-Medium.ttf") format("truetype");
}

:root {
  --bg: #fefefe;
  --bg-sidebar: #f7f6f3;
  --text: #2a2a2a;
  --text-secondary: #777;
  --text-muted: #bbb;
  --border: #e8e8e8;
  --border-light: #eeece8;
  --active-bg: #ebe8e2;
  --hover-bg: #f0ede7;
  --shadow: rgba(0,0,0,0.06);
}
html.dark {
  --bg: #1a1a1d;
  --bg-sidebar: #141416;
  --text: #e8e8e8;
  --text-secondary: #aaa;
  --text-muted: #555;
  --border: #2a2a2d;
  --border-light: #222225;
  --active-bg: #25252a;
  --hover-bg: #1f1f23;
  --shadow: rgba(0,0,0,0.3);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: "LXGWWenKai", "LXGW WenKai", "Songti SC", "Noto Serif CJK SC", serif;
  font-size: 18px;
  line-height: 1.9;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }

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

/* ===== Sidebar ===== */
.sidebar {
  width: 280px;
  min-width: 280px;
  height: 100vh;
  position: sticky;
  top: 0;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border-light);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 100;
}
.sidebar-header {
  padding: 1.8em 1.2em 1em;
  border-bottom: 1px solid var(--border-light);
  flex-shrink: 0;
}
.sidebar-title {
  font-size: 1.1rem;
  font-weight: 500;
  letter-spacing: 0.08em;
  display: block;
}
.sidebar-title:hover { opacity: 0.7; }
.sidebar-author {
  font-size: 0.78rem;
  color: var(--text-secondary);
  margin-top: 0.2em;
}
.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: 0.5em 0;
}
.sidebar-nav::-webkit-scrollbar { width: 3px; }
.sidebar-nav::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
.sidebar-nav ol { list-style: none; padding: 0; counter-reset: toc; }
.sidebar-nav li { counter-increment: toc; }
.sidebar-nav li a {
  display: block;
  padding: 0.4em 1.2em;
  font-size: 0.85rem;
  color: var(--text-secondary);
  transition: background 0.15s, color 0.15s;
  line-height: 1.5;
}
.sidebar-nav li a::before {
  content: counter(toc) ". ";
  color: var(--text-muted);
  font-size: 0.78rem;
}
.sidebar-nav li a:hover { background: var(--hover-bg); color: var(--text); }
.sidebar-nav li.active a { background: var(--active-bg); color: var(--text); font-weight: 500; }
.sidebar-footer {
  padding: 1em 1.2em;
  border-top: 1px solid var(--border-light);
  flex-shrink: 0;
}
.sidebar-downloads { display: flex; gap: 0.5em; margin-bottom: 0.5em; }
.sidebar-downloads a {
  flex: 1;
  text-align: center;
  font-size: 0.72rem;
  color: var(--text-muted);
  padding: 0.4em 0;
  border: 1px solid var(--border);
  border-radius: 4px;
  transition: color 0.15s, border-color 0.15s;
}
.sidebar-downloads a:hover { color: var(--text); border-color: var(--text-muted); }
.sidebar-license { font-size: 0.68rem; color: var(--text-muted); text-align: center; }

/* ===== Content ===== */
.content {
  flex: 1;
  min-width: 0;
  max-width: 520px;
  margin: 0 auto;
  padding: 2.5em 2em 3em;
}

/* ===== Toolbar ===== */
.toolbar {
  position: fixed;
  top: 14px; right: 14px;
  z-index: 200;
  display: flex;
  gap: 4px;
  background: var(--bg-sidebar);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 3px;
}
.tool-btn {
  background: none; border: none;
  width: 32px; height: 32px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 13px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.15s, background 0.15s;
  font-family: inherit;
}
.tool-btn:hover { color: var(--text); background: var(--hover-bg); }
.menu-toggle {
  position: fixed;
  z-index: 200;
  background: var(--bg-sidebar);
  border: 1px solid var(--border);
  border-radius: 50%;
  width: 36px; height: 36px;
  cursor: pointer;
  font-size: 16px;
  color: var(--text-muted);
  display: none;
  align-items: center;
  justify-content: center;
  transition: color 0.15s, border-color 0.15s;
  top: 16px; left: 16px;
}
.menu-toggle:hover { color: var(--text); border-color: var(--text-muted); }

/* ===== Index ===== */
.cover-hero { text-align: center; padding: 2.5em 0 2em; }
.cover-hero img {
  max-width: 75%;
  max-height: 50vh;
  border-radius: 8px;
  box-shadow: 0 6px 24px var(--shadow);
  cursor: pointer;
}
.cover-hero h1 { font-size: 1.6rem; font-weight: 500; letter-spacing: 0.12em; margin-top: 1em; }
.cover-hero .author { font-size: 0.95rem; color: var(--text-secondary); margin-top: 0.3em; }
.dedication {
  text-align: center; padding: 2.5em 0;
  font-size: 1.05rem; color: var(--text-secondary);
  line-height: 2.2; letter-spacing: 0.06em;
  border-bottom: 1px solid var(--border);
}
.license-block {
  text-align: center; padding: 2em 0;
  color: var(--text-muted); font-size: 0.82rem; line-height: 2;
  border-bottom: 1px solid var(--border);
}
.license-block a { text-decoration: underline; text-underline-offset: 2px; }
.license-block .wish { font-size: 0.9rem; color: var(--text-secondary); margin-top: 1.2em; letter-spacing: 0.06em; }
.index-toc { padding: 2em 0; }
.index-toc h2 { text-align: center; font-size: 1.2rem; font-weight: 500; letter-spacing: 0.25em; margin-bottom: 1.5em; }
.index-toc ol { list-style: none; padding: 0; counter-reset: itoc; }
.index-toc li { counter-increment: itoc; border-bottom: 1px dotted var(--border); }
.index-toc li a {
  display: flex; justify-content: space-between; align-items: baseline;
  padding: 0.45em 0; font-size: 0.92rem; transition: color 0.15s;
}
.index-toc li a:hover { color: var(--text-secondary); }
.index-toc li a::before { content: counter(itoc) "."; color: var(--text-muted); font-size: 0.82rem; margin-right: 0.6em; min-width: 2em; flex-shrink: 0; }
.index-toc .date { color: var(--text-muted); font-size: 0.75rem; margin-left: 1em; white-space: nowrap; flex-shrink: 0; }

/* ===== Essay ===== */
.essay-illustration {
  margin: -2.5em -2em 1.8em -2em;
  overflow: hidden;
  cursor: pointer;
}
.essay-illustration img {
  width: 100%;
  aspect-ratio: 3/2;
  object-fit: cover;
  object-position: center center;
  display: block;
}
.essay-header { text-align: center; margin-bottom: 2em; padding-bottom: 1.2em; border-bottom: 1px solid var(--border); }
.essay-title { font-size: 1.4rem; font-weight: 500; letter-spacing: 0.06em; line-height: 1.5; margin-bottom: 0.3em; }
.essay-date { font-size: 0.8rem; color: var(--text-muted); }
.essay-body p { text-indent: 2em; margin-bottom: 0.7em; text-align: justify; }
.essay-nav {
  display: flex; justify-content: space-between; align-items: stretch;
  margin-top: 3em; padding-top: 1.5em; border-top: 1px solid var(--border); gap: 1em;
}
.essay-nav a {
  flex: 1; font-size: 0.82rem; color: var(--text-muted);
  padding: 0.8em; border: 1px solid var(--border); border-radius: 6px;
  transition: color 0.15s, border-color 0.15s;
}
.essay-nav a:hover { color: var(--text); border-color: var(--text-secondary); }
.nav-prev { text-align: left; }
.nav-next { text-align: right; }
.nav-label { display: block; font-size: 0.7rem; color: var(--text-muted); margin-bottom: 0.2em; }

/* ===== Footer ===== */
.site-footer {
  text-align: center; padding: 3em 0 1.5em; margin-top: 3em;
  color: var(--text-muted); font-size: 0.82rem; letter-spacing: 0.06em;
  border-top: 1px solid var(--border);
}

/* ===== Lightbox ===== */
.lightbox {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.92);
  z-index: 1000;
  align-items: center; justify-content: center;
  flex-direction: column;
}
.lightbox.open { display: flex; }
.lightbox img {
  max-width: 90vw; max-height: 80vh;
  object-fit: contain;
  border-radius: 6px;
}
.lightbox-close {
  position: absolute; top: 16px; right: 20px;
  color: #aaa; font-size: 28px; cursor: pointer;
  background: none; border: none; line-height: 1;
}
.lightbox-close:hover { color: #fff; }
.lightbox-nav {
  position: absolute; top: 50%; transform: translateY(-50%);
  color: #aaa; font-size: 36px; cursor: pointer;
  background: none; border: none; padding: 0 16px; line-height: 1;
  user-select: none;
}
.lightbox-nav:hover { color: #fff; }
.lightbox-prev { left: 8px; }
.lightbox-next { right: 8px; }
.lightbox-caption {
  color: #ccc; font-size: 0.85rem; margin-top: 0.8em;
  text-align: center; letter-spacing: 0.04em;
}
.lightbox-caption a { color: #ddd; text-decoration: underline; text-underline-offset: 2px; }
.lightbox-caption a:hover { color: #fff; }
.lightbox-counter {
  color: #666; font-size: 0.72rem; margin-top: 0.3em;
}

/* ===== Mobile ===== */
@media (max-width: 768px) {
  .sidebar {
    position: fixed; left: -300px; width: 280px; min-width: auto;
    transition: left 0.25s ease; box-shadow: none;
  }
  .sidebar.open { left: 0; box-shadow: 4px 0 20px var(--shadow); }
  .menu-toggle { display: flex; }
  .content { padding: 2em 1.5em; max-width: 100%; }
  .essay-illustration { margin: -2em -1.2em 1.5em -1.2em; }
  .cover-hero img { max-width: 80%; }
  .cover-hero h1 { font-size: 1.5rem; }
  .essay-title { font-size: 1.3rem; }
}
@media (max-width: 480px) {
  .content { padding: 1.5em 1.5em; font-size: 17px; }
  .essay-illustration { margin: -1.5em -1em 1.2em -1em; }
}