
:root {
  --bg: #eef1f4;
  --panel: #ffffff;
  --ink: #17202a;
  --muted: #66727e;
  --line: #d7dde3;
  --accent: #174a7e;
  --accent-soft: #e7f0f8;
  --shadow: 0 10px 30px rgba(15, 23, 42, .14);
  --header-h: 72px;
  --footer-h: 58px;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: Arial, Helvetica, sans-serif;
  background: var(--bg);
  color: var(--ink);
  overflow: hidden;
}
button, input { font: inherit; }
button { cursor: pointer; }
.app { height: 100%; display: grid; grid-template-rows: var(--header-h) 1fr var(--footer-h); }
.topbar {
  position: relative;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 10px 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.book-title { font-weight: 700; font-size: 18px; white-space: nowrap; }
.chapter-title {
  color: var(--muted);
  font-size: 13px;
  margin-top: 3px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 44vw;
}
.toolbar { display: flex; align-items: center; gap: 8px; }
.tool-btn, .icon-btn, .chapter-nav {
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  border-radius: 8px;
  min-height: 38px;
}
.tool-btn, .chapter-nav { padding: 8px 12px; }
.icon-btn { min-width: 38px; padding: 6px 10px; font-size: 20px; line-height: 1; }
.tool-btn:hover, .icon-btn:hover, .chapter-nav:hover { background: #f7f9fb; }
.compact { padding-inline: 10px; }
.menu-btn { color: var(--accent); font-size: 22px; }
.page-control { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 14px; }
.page-control input {
  width: 64px;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 8px 6px;
  text-align: center;
  color: var(--ink);
  background: #fff;
}
.reader {
  min-height: 0;
  position: relative;
  display: grid;
  place-items: center;
  padding: 16px;
  overflow: auto;
}
.page-stage {
  display: grid;
  place-items: center;
  min-width: 100%;
  min-height: 100%;
}
#pdfCanvas {
  display: block;
  background: #fff;
  box-shadow: var(--shadow);
  max-width: none;
}
.loading {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--muted);
}
.spinner {
  width: 22px; height: 22px;
  border: 3px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.footer {
  display: grid;
  grid-template-columns: minmax(150px, 1fr) auto minmax(150px, 1fr);
  align-items: center;
  gap: 12px;
  padding: 9px 16px;
  background: var(--panel);
  border-top: 1px solid var(--line);
  font-size: 13px;
}
.footer-center { color: var(--muted); text-align: center; white-space: nowrap; }
.dot { padding: 0 6px; }
.chapter-nav:first-child { justify-self: start; }
.chapter-nav:last-child { justify-self: end; }

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 40;
  width: min(390px, 90vw);
  background: var(--panel);
  border-right: 1px solid var(--line);
  box-shadow: var(--shadow);
  transform: translateX(-102%);
  transition: transform .2s ease;
  display: grid;
  grid-template-rows: auto 1fr;
}
.sidebar.open { transform: translateX(0); }
.sidebar-head {
  display: flex;
  justify-content: space-between;
  align-items: start;
  gap: 12px;
  padding: 18px;
  border-bottom: 1px solid var(--line);
}
.sidebar-title { font-size: 20px; font-weight: 700; }
.sidebar-subtitle { color: var(--muted); font-size: 13px; margin-top: 4px; }
.toc { overflow-y: auto; padding: 10px; }
.toc-item {
  display: block;
  width: 100%;
  text-align: left;
  border: 0;
  border-radius: 8px;
  padding: 10px 12px;
  margin: 2px 0;
  background: transparent;
  color: var(--ink);
  line-height: 1.25;
}
.toc-item:hover { background: #f5f7f9; }
.toc-item.active { background: var(--accent-soft); color: var(--accent); font-weight: 700; }
.toc-page { float: right; color: var(--muted); margin-left: 12px; font-weight: 400; }
.scrim {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 30;
  border: 0;
  background: rgba(0,0,0,.32);
}
.scrim.show { display: block; }

@media (max-width: 900px) {
  :root { --header-h: auto; --footer-h: auto; }
  body { overflow: auto; }
  .app { min-height: 100dvh; height: 100dvh; grid-template-rows: auto 1fr auto; }
  .topbar { align-items: flex-start; flex-direction: column; gap: 8px; padding: 9px 10px; }
  .book-title { font-size: 16px; }
  .chapter-title { max-width: 76vw; }
  .toolbar { width: 100%; justify-content: space-between; gap: 5px; }
  .tool-btn { padding: 7px 8px; font-size: 13px; }
  .icon-btn { min-width: 34px; min-height: 34px; }
  .page-control label { display: none; }
  .page-control input { width: 54px; padding: 7px 4px; }
  .reader { padding: 8px; }
  .footer {
    grid-template-columns: 1fr 1fr;
    padding: 8px;
  }
  .footer-center { display: none; }
  .chapter-nav { font-size: 12px; padding: 7px 9px; }
}

@media (max-width: 520px) {
  .toolbar #zoomOutBtn, .toolbar #zoomInBtn { display: none; }
  .book-title { max-width: 76vw; overflow: hidden; text-overflow: ellipsis; }
}


.sidebar-tools {
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
}
.sidebar-tools label {
  display: block;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 6px;
}
.chapter-select, .search-row input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 10px;
  background: #fff;
  color: var(--ink);
}
.progress-wrap { margin-top: 12px; }
.progress-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 6px;
}
.progress-track {
  height: 8px;
  border-radius: 999px;
  background: #e8edf2;
  overflow: hidden;
}
.progress-bar {
  height: 100%;
  width: 0%;
  background: var(--accent);
  transition: width .2s ease;
}

.side-panel {
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 45;
  width: min(430px, 92vw);
  background: var(--panel);
  border-right: 1px solid var(--line);
  box-shadow: var(--shadow);
  transform: translateX(-102%);
  transition: transform .2s ease;
  display: grid;
  grid-template-rows: auto 1fr;
}
.side-panel.open { transform: translateX(0); }
.right-panel {
  inset: 0 0 0 auto;
  border-right: 0;
  border-left: 1px solid var(--line);
  transform: translateX(102%);
}
.right-panel.open { transform: translateX(0); }
.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: start;
  gap: 12px;
  padding: 18px;
  border-bottom: 1px solid var(--line);
}
.panel-body { overflow-y: auto; padding: 14px; }
.search-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
}
.search-status {
  color: var(--muted);
  font-size: 13px;
  margin: 12px 0;
}
.search-results, .bookmark-list {
  display: grid;
  gap: 8px;
}
.search-result, .bookmark-item {
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 10px;
  background: #fff;
}
.search-result button, .bookmark-main {
  border: 0;
  background: transparent;
  padding: 0;
  text-align: left;
  width: 100%;
  color: var(--ink);
}
.result-title, .bookmark-title { font-weight: 700; }
.result-snippet {
  color: var(--muted);
  font-size: 13px;
  margin-top: 5px;
  line-height: 1.35;
}
.result-page, .bookmark-meta {
  color: var(--muted);
  font-size: 12px;
  margin-top: 5px;
}
.bookmark-actions {
  display: flex;
  justify-content: flex-end;
  margin-top: 8px;
}
.remove-bookmark {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 7px;
  padding: 5px 8px;
  font-size: 12px;
}
.link-btn {
  border: 0;
  background: transparent;
  color: var(--accent);
  padding: 0 0 0 8px;
  font-size: 13px;
}
#bookmarkBtn.active {
  background: var(--accent-soft);
  color: var(--accent);
  border-color: var(--accent);
}

@media (max-width: 900px) {
  #bookmarkBtn, #searchBtn { font-size: 12px; padding: 7px 8px; }
}
@media (max-width: 640px) {
  #bookmarkBtn { display: none; }
  .search-row { grid-template-columns: 1fr; }
}


.show-controls-btn {
  position: fixed;
  top: 10px;
  right: 10px;
  z-index: 80;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  border-radius: 8px;
  padding: 8px 12px;
  box-shadow: var(--shadow);
}

body.controls-hidden .topbar,
body.controls-hidden .footer {
  display: none;
}

body.controls-hidden .app {
  grid-template-rows: 1fr;
}

body.controls-hidden .reader {
  grid-row: 1;
}

body.controls-hidden .show-controls-btn {
  display: block;
}

body.controls-hidden .sidebar,
body.controls-hidden .side-panel,
body.controls-hidden .scrim {
  display: none !important;
}


/* Spinner fix: author CSS previously overrode the HTML hidden attribute. */
.loading[hidden] {
  display: none !important;
}
