:root {
  color-scheme: light;
  --ink: #102a43;
  --muted: #627d98;
  --line: #d9e2ec;
  --surface: #ffffff;
  --canvas: #eef2f6;
  --accent: #1f8a70;
  --accent-soft: #dff4ed;
  --shadow: 0 18px 45px rgba(16, 42, 67, 0.14);
}

* { box-sizing: border-box; }

html, body { height: 100%; margin: 0; }

body {
  background: var(--canvas);
  color: var(--ink);
  font-family: "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", sans-serif;
  overflow: hidden;
}

button, input { font: inherit; }
button { cursor: pointer; }

.topbar {
  height: 76px;
  padding: 0 26px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.brand, .top-actions, .sidebar-heading, .toolbar-group, .reader-footer { display: flex; align-items: center; }
.brand { gap: 12px; }
.brand-mark {
  display: grid;
  width: 40px;
  height: 40px;
  place-items: center;
  border-radius: 12px;
  background: var(--ink);
  color: #f9d66b;
  font-size: 20px;
  font-weight: 800;
}
.eyebrow { margin: 0 0 2px; color: var(--muted); font-size: 11px; font-weight: 800; letter-spacing: .14em; }
h1, h2, p { margin: 0; }
h1 { font-size: 19px; letter-spacing: .04em; }
h2 { font-size: 17px; }
.top-actions { gap: 14px; }
.text-link { color: var(--accent); font-size: 13px; font-weight: 700; text-decoration: none; }
.text-link:hover { text-decoration: underline; }
.icon-button, .toolbar-button {
  min-width: 36px;
  height: 36px;
  padding: 0 11px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--surface);
  color: var(--ink);
  font-weight: 700;
}
.icon-button { font-size: 21px; line-height: 1; }
.icon-button:hover, .toolbar-button:hover { border-color: #9fb3c8; background: #f7fafc; }

.app-shell { height: calc(100vh - 76px); display: grid; grid-template-columns: 270px minmax(0, 1fr); }
.sidebar { min-height: 0; overflow: hidden; padding: 22px 16px 16px; background: #f8fafc; border-right: 1px solid var(--line); }
.sidebar-heading { justify-content: space-between; padding: 0 6px 15px; }
.page-count { color: var(--muted); font-size: 11px; font-weight: 700; }
.search-box {
  height: 40px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 11px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  color: var(--muted);
}
.search-box input { width: 100%; border: 0; outline: 0; color: var(--ink); background: transparent; font-size: 13px; }
.thumbnail-list { height: calc(100% - 112px); overflow-y: auto; display: grid; align-content: start; gap: 12px; padding: 16px 4px 24px; scrollbar-width: thin; }
.thumbnail {
  position: relative;
  padding: 5px 5px 8px;
  border: 1px solid transparent;
  border-radius: 9px;
  background: transparent;
  color: var(--muted);
  text-align: left;
}
.thumbnail:hover { border-color: #b9c7d6; background: #fff; }
.thumbnail.active { border-color: var(--accent); background: var(--accent-soft); color: var(--ink); }
.thumbnail img { display: block; width: 100%; aspect-ratio: 595 / 842; object-fit: cover; border: 1px solid #dfe7ef; border-radius: 5px; background: #fff; }
.thumbnail-label { display: flex; justify-content: space-between; padding: 7px 2px 0; font-size: 11px; font-weight: 700; }

.reader { min-width: 0; min-height: 0; display: grid; grid-template-rows: 60px minmax(0, 1fr) 36px; }
.reader-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 0 22px; background: var(--surface); border-bottom: 1px solid var(--line); }
.toolbar-group { gap: 8px; }
.page-control { gap: 6px; }
.page-input-wrap { display: flex; align-items: center; gap: 7px; color: var(--muted); font-size: 12px; font-weight: 700; }
.page-input-wrap input { width: 62px; height: 34px; padding: 0 8px; border: 1px solid var(--line); border-radius: 8px; color: var(--ink); text-align: center; outline: none; }
.page-input-wrap input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(31, 138, 112, .12); }
.zoom-control { color: var(--muted); font-size: 12px; font-weight: 800; }
.zoom-control .toolbar-button { min-width: 32px; padding: 0 8px; }
.zoom-control #fitButton { margin-left: 4px; font-size: 11px; }
.copy-button { margin-left: auto; color: var(--accent); border-color: #b7ded2; background: #f4fbf8; font-size: 11px; }
.copy-button:hover { border-color: var(--accent); background: var(--accent-soft); }
.canvas { position: relative; min-height: 0; overflow: auto; display: flex; justify-content: center; align-items: flex-start; padding: 34px; background: var(--canvas); }
.document-frame { display: block; width: min(100%, 880px); min-width: 300px; padding: 12px; background: #fff; box-shadow: var(--shadow); transform-origin: top center; transition: transform .18s ease; }
.document-frame img { display: block; width: 100%; height: auto; user-select: none; }
.loading { position: absolute; inset: 50% auto auto 50%; transform: translate(-50%, -50%); padding: 12px 16px; border-radius: 10px; background: rgba(16, 42, 67, .9); color: white; font-size: 13px; }
.reader-footer { justify-content: space-between; padding: 0 22px; background: var(--surface); color: var(--muted); font-size: 11px; }
#statusText { color: var(--ink); font-weight: 800; }

@media (max-width: 760px) {
  body { overflow: auto; }
  .topbar { height: 64px; padding: 0 14px; }
  .brand-mark { width: 34px; height: 34px; font-size: 17px; }
  h1 { font-size: 16px; }
  .text-link { display: none; }
  .app-shell { height: calc(100vh - 64px); grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .reader { grid-template-rows: auto minmax(0, 1fr) 36px; }
  .reader-toolbar { min-height: 60px; flex-wrap: wrap; padding: 10px 12px; }
  .copy-button { margin-left: 0; }
  .zoom-control .toolbar-button:not(#fitButton) { display: none; }
  .canvas { padding: 18px 10px; }
  .document-frame { min-width: 0; width: 100%; padding: 6px; }
  .reader-footer { padding: 0 12px; }
  .reader-footer span:last-child { display: none; }
}

.nav-tabs { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; margin: 14px 4px 0; padding: 4px; border-radius: 9px; background: #e9eff5; }
.nav-tab { padding: 8px 4px; border: 0; border-radius: 7px; background: transparent; color: var(--muted); font-size: 12px; font-weight: 800; }
.nav-tab.active { background: #fff; color: var(--ink); box-shadow: 0 1px 4px rgba(16, 42, 67, .1); }
.search-hint { padding: 9px 6px 0; color: var(--muted); font-size: 10px; line-height: 1.5; }
.search-results, .toc-list { height: calc(100% - 153px); min-height: 0; overflow-y: auto; padding: 12px 4px 24px; scrollbar-width: thin; }
.result-item, .toc-item { display: block; width: 100%; margin-bottom: 7px; padding: 10px; border: 1px solid var(--line); border-radius: 9px; background: #fff; color: var(--ink); text-align: left; }
.result-item:hover, .toc-item:hover { border-color: var(--accent); background: var(--accent-soft); }
.result-page { display: block; margin-bottom: 3px; color: var(--accent); font-size: 10px; font-weight: 800; }
.result-text { display: block; overflow: hidden; color: var(--ink); font-size: 11px; line-height: 1.5; text-overflow: ellipsis; white-space: nowrap; }
.toc-item { display: flex; align-items: baseline; gap: 8px; font-size: 12px; font-weight: 700; }
.toc-item.level-1 { margin-left: 12px; width: calc(100% - 12px); color: var(--muted); font-size: 11px; font-weight: 600; }
.toc-page { margin-left: auto; color: var(--muted); font-size: 10px; font-weight: 700; white-space: nowrap; }
.empty-state { padding: 18px 8px; color: var(--muted); font-size: 12px; line-height: 1.6; text-align: center; }
