:root {
  --bg: #FFF8F0;
  --ink: #3E271C;
  --muted: #7A5C4A;
  --soft: #A08060;
  --line: #E8D8C8;
  --card: #FFFFFF;
  --accent: #6B3E2E;
  --accent-press: #543024;
  --chip: #F3E6D8;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang TC", "Noto Sans TC", "Helvetica Neue", sans-serif;
  -webkit-tap-highlight-color: transparent;
}
body { padding-bottom: var(--safe-bottom); }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0;
}
.screen {
  max-width: 560px;
  margin: 0 auto;
  padding: calc(16px + var(--safe-top)) 20px 28px;
}
.header { text-align: center; margin-bottom: 8px; }
.header h1 {
  margin: 8px 0 0;
  font-size: 2rem;
  font-weight: 800;
}
.subtitle { margin: 6px 0 0; color: var(--muted); font-size: 0.95rem; }
.count { margin: 4px 0 0; color: var(--soft); font-size: 0.8rem; }
.number-input, .search-input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--card);
  color: var(--ink);
  outline: none;
  box-shadow: 0 1px 2px rgba(62,39,28,0.04);
}
.number-input {
  margin-top: 20px;
  height: 64px;
  text-align: center;
  font-size: 1.75rem;
  font-weight: 700;
}
.search-input {
  margin-top: 16px;
  height: 50px;
  padding: 0 16px;
  font-size: 1rem;
}
.number-input::placeholder, .search-input::placeholder { color: #B0A090; }
.primary-btn, .ghost-btn, .back-btn {
  border: 0;
  border-radius: 14px;
  font-weight: 700;
  font-size: 1.1rem;
  cursor: pointer;
}
.primary-btn {
  width: 100%;
  margin-top: 14px;
  height: 52px;
  background: var(--accent);
  color: #fff;
}
.primary-btn:active { background: var(--accent-press); }
.ghost-btn {
  width: 100%;
  height: 44px;
  background: var(--chip);
  color: var(--ink);
  font-size: 0.95rem;
}
.results {
  list-style: none;
  margin: 10px 0 0;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 14px;
  overflow: hidden;
  background: var(--card);
  max-height: 42vh;
  overflow-y: auto;
}
.results li {
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
}
.results li:last-child { border-bottom: 0; }
.results li:active { background: #F8EEE4; }
.result-top {
  display: flex;
  gap: 8px;
  align-items: baseline;
  font-weight: 700;
}
.result-num {
  color: var(--accent);
  min-width: 2.2em;
}
.result-title { flex: 1; }
.result-snippet {
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.85rem;
  line-height: 1.35;
}
.muted { color: var(--soft); font-size: 0.9rem; }
.center { text-align: center; }
.recent { margin-top: 18px; }
.recent h2 {
  margin: 0 0 8px;
  font-size: 0.95rem;
  color: var(--muted);
  font-weight: 600;
}
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  border: 0;
  background: var(--chip);
  color: var(--ink);
  border-radius: 999px;
  padding: 8px 12px;
  font-size: 0.85rem;
  cursor: pointer;
}
.offline-tools { margin-top: 20px; }
.footer-note {
  margin-top: 16px;
  text-align: center;
  color: var(--soft);
  font-size: 0.78rem;
  line-height: 1.4;
}
.viewer {
  max-width: none;
  padding: 0;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  background: #1b120e;
}
.viewer-bar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: grid;
  grid-template-columns: 72px 1fr auto;
  gap: 8px;
  align-items: center;
  padding: calc(10px + var(--safe-top)) 12px 10px;
  background: rgba(27,18,14,0.92);
  color: #fff;
  backdrop-filter: blur(8px);
}
.back-btn {
  background: transparent;
  color: #fff;
  font-size: 1rem;
  text-align: left;
  padding: 8px 4px;
}
.viewer-title {
  text-align: center;
  font-weight: 700;
  font-size: 0.95rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.page-info { font-size: 0.8rem; color: #d8c4b4; min-width: 3.5em; text-align: right; }
.pdf-container {
  flex: 1;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  padding: 8px 0 24px;
}
.pdf-page {
  display: block;
  margin: 0 auto 10px;
  max-width: 100%;
  height: auto;
  background: #fff;
  box-shadow: 0 2px 10px rgba(0,0,0,0.25);
}
.viewer-status {
  position: fixed;
  left: 50%;
  bottom: calc(18px + var(--safe-bottom));
  transform: translateX(-50%);
  background: rgba(0,0,0,0.7);
  color: #fff;
  padding: 8px 14px;
  border-radius: 999px;
  font-size: 0.85rem;
}
.viewer-status[hidden] { display: none; }
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + var(--safe-bottom));
  transform: translateX(-50%);
  background: rgba(62,39,28,0.92);
  color: #fff;
  padding: 10px 16px;
  border-radius: 12px;
  font-size: 0.9rem;
  z-index: 20;
  max-width: 86vw;
  text-align: center;
}
.toast[hidden] { display: none; }
