/* 前台版面 */
.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--ink); min-width: 0; }
.brand-mark {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 12px;
  background: var(--accent-soft);
  font-size: 20px;
  flex: none;
}
.brand-text { display: flex; flex-direction: column; line-height: 1.2; min-width: 0; }
.brand-text strong { font-family: var(--font-display); font-size: 1.15em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand-text small { color: var(--muted); font-size: 0.75em; }
.icon-btn {
  flex: none;
  width: 38px;
  height: 38px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--surface);
  cursor: pointer;
  font-size: 17px;
}
.icon-btn:hover { border-color: var(--accent); }
.menu-btn { display: none; }

.search { position: relative; flex: 1; max-width: 460px; margin-left: auto; }
.search input {
  width: 100%;
  padding: 8px 14px 8px 36px;
  border-radius: 999px;
  border: 1px solid var(--line-strong);
  background: var(--surface) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%238d7463' stroke-width='2.2' stroke-linecap='round'%3E%3Ccircle cx='11' cy='11' r='7'/%3E%3Cpath d='m20 20-3.5-3.5'/%3E%3C/svg%3E") no-repeat 12px center;
  outline: none;
}
.search input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.search-results {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  max-height: 70vh;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 6px;
}
.search-results a {
  display: block;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  text-decoration: none;
  color: var(--ink);
}
.search-results a:hover, .search-results a.active { background: var(--accent-softer); }
.search-results .sr-path { font-size: 0.78em; color: var(--muted); }
.search-results .sr-title { font-weight: 700; }
.search-results .sr-snippet { font-size: 0.85em; color: var(--ink-soft); line-height: 1.5; }
.search-results mark { background: #ffe08a; color: #3b2a20; border-radius: 3px; }
.search-results .sr-empty { padding: 12px; color: var(--muted); text-align: center; }

.layout { display: grid; grid-template-columns: 280px minmax(0, 1fr); max-width: 1320px; margin: 0 auto; }
.sidebar {
  position: sticky;
  top: 59px;
  height: calc(100vh - 59px);
  overflow-y: auto;
  padding: 18px 12px 40px 16px;
  border-right: 1px dashed var(--line);
}
.toc-home, .toc-ch {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  border-radius: var(--radius-sm);
  text-decoration: none;
  color: var(--ink-soft);
  line-height: 1.4;
  font-size: 0.95em;
}
.toc-ch .ico { width: 1.4em; text-align: center; flex: none; }
.toc-home:hover, .toc-ch:hover { background: var(--accent-softer); color: var(--ink); }
.toc-ch.active, .toc-home.active { background: var(--accent-soft); color: var(--ink); font-weight: 700; }
.toc-subs { margin: 2px 0 8px 2.2em; padding: 0; list-style: none; border-left: 2px solid var(--line); }
.toc-subs a {
  display: block;
  padding: 3px 10px;
  font-size: 0.85em;
  color: var(--muted);
  text-decoration: none;
  line-height: 1.45;
}
.toc-subs a.lv4 { padding-left: 22px; font-size: 0.8em; }
.toc-subs a:hover { color: var(--accent); }
.toc-subs a.current { color: var(--accent); font-weight: 700; }
.toc-sep { margin: 10px 10px; border-top: 1px dashed var(--line); }

.main { padding: 28px 32px 80px; min-width: 0; outline: none; }
.loading { padding: 60px 0; text-align: center; color: var(--muted); }
.paw-spin { display: inline-block; animation: paw 1.2s ease-in-out infinite; }
@keyframes paw { 50% { transform: translateY(-4px) rotate(-12deg); } }

/* 首頁 */
.hero {
  position: relative;
  overflow: hidden;
  background: linear-gradient(135deg, var(--accent-soft), var(--surface) 70%);
  border: 1px solid var(--line);
  border-radius: 24px;
  padding: 30px 32px;
  margin-bottom: 22px;
}
.hero::after {
  content: '🐈';
  position: absolute;
  right: 22px;
  bottom: -10px;
  font-size: 110px;
  opacity: 0.16;
  transform: scaleX(-1);
  pointer-events: none;
}
.hero h1 { font-family: var(--font-display); font-size: clamp(1.7em, 4vw, 2.4em); line-height: 1.25; margin: 0; }
.hero .ver {
  display: inline-block;
  margin-left: 10px;
  padding: 0 0.6em;
  border-radius: 999px;
  background: var(--accent);
  color: var(--accent-ink);
  font-family: var(--font-body);
  font-size: 0.42em;
  vertical-align: middle;
}
.hero .tagline { color: var(--muted); margin: 6px 0 0; }
.hero .prose { margin-top: 16px; max-width: 760px; position: relative; z-index: 1; }
.hero .prose blockquote { background: color-mix(in srgb, var(--surface) 70%, transparent); }
.section-title { font-family: var(--font-display); font-size: 1.35em; margin: 30px 0 12px; display: flex; align-items: center; gap: 8px; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 14px; }
.card {
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 18px;
  text-decoration: none;
  color: var(--ink);
  box-shadow: var(--shadow);
  transition: transform 0.15s, border-color 0.15s;
}
.card:hover { transform: translateY(-2px); border-color: var(--accent); }
.card .c-ico { font-size: 1.7em; line-height: 1; }
.card .c-title { font-family: var(--font-display); font-size: 1.15em; font-weight: 700; margin-top: 8px; line-height: 1.35; }
.card .c-subs { margin: 6px 0 0; padding: 0; list-style: none; font-size: 0.83em; color: var(--muted); line-height: 1.55; }
.card .c-subs li { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card .c-more { margin-top: auto; padding-top: 8px; font-size: 0.8em; color: var(--accent); }
.updated { margin-top: 30px; text-align: center; color: var(--muted); font-size: 0.82em; }

/* 章節頁 */
.ch-head { display: flex; align-items: center; gap: 14px; margin-bottom: 8px; }
.ch-head .ico {
  display: grid;
  place-items: center;
  width: 56px;
  height: 56px;
  border-radius: 18px;
  background: var(--accent-soft);
  font-size: 28px;
  flex: none;
}
.ch-head h1 { font-family: var(--font-display); font-size: clamp(1.5em, 3.4vw, 2.1em); margin: 0; line-height: 1.3; }
.ch-crumb { font-size: 0.82em; color: var(--muted); margin-bottom: 14px; }
.ch-crumb a { color: var(--muted); }
.block {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 22px 26px;
  margin: 16px 0;
  box-shadow: var(--shadow);
  scroll-margin-top: 76px;
}
.block.lv4 { margin-left: 22px; border-style: dashed; box-shadow: none; }
.block.flash { animation: flash 1.6s ease-out; }
@keyframes flash { 0% { box-shadow: 0 0 0 4px var(--accent); } 100% { box-shadow: var(--shadow); } }
.block > h2, .block > h3 {
  font-family: var(--font-display);
  margin: 0 0 10px;
  line-height: 1.4;
  display: flex;
  align-items: baseline;
  gap: 8px;
}
.block > h2 { font-size: 1.4em; }
.block > h3 { font-size: 1.18em; }
.block .num {
  font-family: var(--font-body);
  font-size: 0.72em;
  font-weight: 700;
  color: var(--accent);
  background: var(--accent-softer);
  padding: 0 0.5em;
  border-radius: 6px;
  flex: none;
}
.block .anchor { margin-left: auto; opacity: 0; text-decoration: none; font-size: 0.8em; color: var(--muted); }
.block:hover .anchor { opacity: 1; }
.pager { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 30px; }
.pager a {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 16px;
  text-decoration: none;
  color: var(--ink);
}
.pager a:hover { border-color: var(--accent); }
.pager small { display: block; color: var(--muted); font-size: 0.78em; }
.pager .next { text-align: right; grid-column: 2; }
.empty { text-align: center; padding: 60px 0; color: var(--muted); }
.to-top {
  position: fixed;
  right: 18px;
  bottom: 18px;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1px solid var(--line-strong);
  background: var(--surface);
  box-shadow: var(--shadow);
  cursor: pointer;
  font-size: 18px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}
.to-top.show { opacity: 1; pointer-events: auto; }

.scrim { display: none; }

@media (max-width: 900px) {
  .menu-btn { display: block; }
  .layout { grid-template-columns: minmax(0, 1fr); }
  .sidebar {
    position: fixed;
    z-index: 40;
    top: 0;
    left: 0;
    height: 100vh;
    width: min(300px, 84vw);
    background: var(--bg);
    border-right: 1px solid var(--line);
    transform: translateX(-102%);
    transition: transform 0.22s ease;
    padding-top: 20px;
  }
  body.nav-open .sidebar { transform: none; box-shadow: var(--shadow); }
  body.nav-open .scrim { display: block; position: fixed; inset: 0; z-index: 35; background: rgba(30, 20, 12, 0.35); }
  .main { padding: 18px 16px 70px; }
  .block { padding: 16px; border-radius: 14px; }
  .block.lv4 { margin-left: 0; }
  .hero { padding: 22px 18px; border-radius: 18px; }
  .brand-text small { display: none; }
}
@media (max-width: 560px) {
  .topbar { gap: 8px; padding: 8px 12px; flex-wrap: wrap; }
  .search { order: 5; flex-basis: 100%; max-width: none; }
  .brand { flex: 1; }
  .sidebar { top: 0; }
  .block { scroll-margin-top: 120px; }
  .pager { grid-template-columns: 1fr; }
  .pager .next { grid-column: 1; }
}
