:root {
  --teal: #1f6f78;
  --teal-dark: #15545c;
  --teal-soft: #e6f2f2;
  --ink: #23313a;
  --muted: #6b7c84;
  --line: #dce5e6;
  --bg: #f4f7f7;
  --paper: #ffffff;
  --sidebar-w: 310px;
  --topbar-h: 58px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  -webkit-text-size-adjust: 100%;
}

body {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

button { font-family: inherit; cursor: pointer; }

/* 顶栏 */
.topbar {
  height: var(--topbar-h);
  flex: 0 0 var(--topbar-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 18px;
  background: var(--paper);
  border-bottom: 1px solid var(--line);
  z-index: 30;
}

.topbar-left, .topbar-right { display: flex; align-items: center; gap: 10px; }

.brand { display: flex; align-items: center; gap: 10px; }

.brand-mark {
  width: 34px; height: 34px;
  display: grid; place-items: center;
  border-radius: 8px;
  background: var(--teal);
  color: #fff;
  font-size: 18px;
  font-weight: 700;
}

.brand-text { display: flex; flex-direction: column; line-height: 1.25; }
.brand-text strong { font-size: 15px; letter-spacing: .5px; }
.brand-text span { font-size: 11px; color: var(--muted); }

.icon-btn {
  width: 36px; height: 36px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  color: var(--ink);
  font-size: 20px;
  line-height: 1;
}
.icon-btn:active { background: var(--teal-soft); }
.menu-btn { display: none; }

.text-btn {
  border: 0;
  background: transparent;
  color: var(--teal);
  font-size: 14px;
  padding: 8px 10px;
  border-radius: 6px;
}
.text-btn:hover { background: var(--teal-soft); }

/* 主布局 */
.layout {
  flex: 1 1 auto;
  display: flex;
  min-height: 0;
}

.sidebar {
  width: var(--sidebar-w);
  flex: 0 0 var(--sidebar-w);
  background: var(--paper);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  min-height: 0;
  z-index: 20;
}

.sidebar-head {
  height: 52px;
  flex: 0 0 52px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  border-bottom: 1px solid var(--line);
}
.sidebar-head h2 { margin: 0; font-size: 15px; letter-spacing: 4px; }
.sidebar-head .icon-btn { display: none; }

.toc-list {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 10px 8px 16px;
}

.toc-item {
  display: block;
  width: 100%;
  text-align: left;
  border: 0;
  background: transparent;
  padding: 9px 12px;
  border-radius: 7px;
  color: var(--ink);
  font-size: 13px;
  line-height: 1.45;
  border-left: 3px solid transparent;
}
.toc-item:hover { background: var(--teal-soft); }
.toc-item.level-1 {
  font-weight: 700;
  color: var(--teal-dark);
  margin-top: 10px;
  background: #f3f8f8;
}
.toc-item.level-2 { padding-left: 18px; }
.toc-item.level-3 { padding-left: 32px; color: var(--muted); font-size: 12.5px; }
.toc-item.active {
  background: var(--teal-soft);
  color: var(--teal-dark);
  border-left-color: var(--teal);
  font-weight: 600;
}
.toc-item .pg { float: right; color: #9aa9ae; font-size: 11px; margin-left: 8px; }

.sidebar-foot {
  flex: 0 0 auto;
  padding: 10px 16px;
  border-top: 1px solid var(--line);
  font-size: 11px;
  color: var(--muted);
}

/* 阅读区 */
.reader {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.reader-toolbar {
  height: 50px;
  flex: 0 0 50px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 18px;
  background: var(--paper);
  border-bottom: 1px solid var(--line);
}

.nav-btn {
  width: 34px; height: 34px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--paper);
  color: var(--teal);
  font-size: 24px;
  line-height: 1;
  padding: 0;
}
.nav-btn:disabled { opacity: .35; cursor: default; }
.nav-btn:not(:disabled):hover { background: var(--teal-soft); }

.page-info { display: flex; flex-direction: column; line-height: 1.2; min-width: 130px; }
#pageLabel { font-size: 13px; font-weight: 600; }
.section-label { font-size: 11px; color: var(--muted); max-width: 240px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.toolbar-spacer { flex: 1 1 auto; }

.zoom-group {
  display: flex; align-items: center; gap: 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 2px 4px;
}
.zoom-btn {
  width: 28px; height: 28px;
  border: 0; background: transparent;
  color: var(--teal); font-size: 18px; border-radius: 5px;
}
.zoom-btn:hover { background: var(--teal-soft); }
#zoomLabel { font-size: 11px; color: var(--muted); min-width: 38px; text-align: center; }

.progress { height: 3px; background: #e8eeee; flex: 0 0 3px; }
.progress-bar { height: 100%; width: 0; background: var(--teal); transition: width .15s ease; }

.page-stage {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 22px 18px 30px;
  background: #eef2f2;
}

.page-wrap {
  position: relative;
  display: inline-block;
  max-width: 100%;
  transform: scale(var(--zoom, 1));
  transform-origin: top center;
  transition: transform .12s ease;
}

#pageImg {
  display: block;
  max-width: 100%;
  max-height: calc(100vh - 190px);
  width: auto;
  height: auto;
  object-fit: contain;
  background: #fff;
  box-shadow: 0 6px 24px rgba(25, 58, 62, .16);
  user-select: none;
  -webkit-user-drag: none;
}

#pageImg.lowres {
  filter: blur(2px);
  image-rendering: auto;
}

.hotspots {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.hotspot {
  position: absolute;
  pointer-events: auto;
  cursor: pointer;
  border-radius: 4px;
  background: rgba(31, 111, 120, 0);
  transition: background .12s ease;
}

.hotspot:hover {
  background: rgba(31, 111, 120, .16);
  outline: 1px solid rgba(31, 111, 120, .45);
}

.toc-note {
  position: absolute;
  top: 6px;
  right: 6px;
  background: rgba(31, 111, 120, .88);
  color: #fff;
  font-size: 11px;
  padding: 4px 8px;
  border-radius: 4px;
  pointer-events: none;
}

.reader-hint {
  flex: 0 0 auto;
  text-align: center;
  padding: 8px 10px 10px;
  font-size: 11px;
  color: var(--muted);
  background: var(--paper);
  border-top: 1px solid var(--line);
}

.mask {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(20, 40, 44, .4);
  z-index: 15;
}

/* 移动端 */
@media (max-width: 900px) {
  .menu-btn { display: inline-grid; place-items: center; }
  .sidebar {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    width: min(84vw, 340px);
    transform: translateX(-102%);
    transition: transform .22s ease;
    box-shadow: 8px 0 24px rgba(0,0,0,.12);
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-head .icon-btn { display: inline-grid; place-items: center; }
  .mask.show { display: block; }
  .brand-text span { display: none; }
  .brand-text strong { font-size: 14px; }
  .reader-toolbar { padding: 0 10px; gap: 6px; }
  .page-info { min-width: 96px; }
  .section-label { max-width: 110px; }
  .zoom-group { display: none; }
  .page-stage { padding: 12px 10px 20px; }
  #pageImg { max-height: calc(100vh - 170px); }
  .reader-hint { font-size: 10.5px; }
}
