:root {
  --bg: #2b2622;
  --bg-2: #3a332d;
  --ink: #f4ede4;
  --muted: #bfb2a3;
  --accent: #c9a77c;
  --panel: rgba(30, 26, 23, .97);
  --bar-h: 56px;
  --top-h: 52px;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: radial-gradient(ellipse at 50% 40%, var(--bg-2), var(--bg) 70%);
  color: var(--ink);
  font: 14px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", sans-serif;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}
button, a.tb { font: inherit; color: inherit; }

/* top bar */
.topbar {
  height: calc(var(--top-h) + env(safe-area-inset-top)); display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: env(safe-area-inset-top) 16px 0;
}
.brand { display: flex; align-items: baseline; gap: 10px; min-width: 0; }
.brand-mark { letter-spacing: .28em; font-weight: 600; color: var(--accent); white-space: nowrap; }
.brand-sub { color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.langs { display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none; }
.langs::-webkit-scrollbar { display: none; }
.langs button {
  background: transparent; border: 1px solid rgba(201, 167, 124, .35); border-radius: 999px;
  padding: 4px 10px; cursor: pointer; white-space: nowrap; font-size: 13px;
}
.langs button:hover, .langs button.on { background: var(--accent); color: #241f1b; border-color: var(--accent); }

/* stage */
.stage {
  position: relative;
  height: calc(100% - var(--top-h) - var(--bar-h) - env(safe-area-inset-top) - env(safe-area-inset-bottom));
  display: flex; align-items: center; justify-content: center; padding: 8px 56px;
}
.book-wrap { width: 100%; height: 100%; display: flex; align-items: center; justify-content: center; }
.book { filter: drop-shadow(0 18px 30px rgba(0, 0, 0, .45)); transition: transform .5s ease; }
.page { background: #f6f1ea; overflow: hidden; }
.page img { width: 100%; height: 100%; display: block; object-fit: cover; user-select: none; -webkit-user-drag: none; pointer-events: none; }
.page .hot {
  position: absolute; cursor: pointer; border-radius: 4px; z-index: 2;
  background: transparent; border: 0; padding: 0; margin: 0;
}
.page .sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.nav-arrow {
  position: absolute; top: 50%; transform: translateY(-50%); z-index: 5;
  width: 44px; height: 72px; border: 0; border-radius: 8px; cursor: pointer;
  background: rgba(0, 0, 0, .18); color: var(--ink); font-size: 40px; line-height: 1;
}
.nav-arrow:hover { background: rgba(0, 0, 0, .35); }
.nav-arrow:disabled { opacity: .15; cursor: default; }
.nav-arrow.prev { left: 6px; }
.nav-arrow.next { right: 6px; }
.loading { position: absolute; color: var(--muted); }

/* toolbar */
.toolbar {
  height: calc(var(--bar-h) + env(safe-area-inset-bottom)); display: flex; align-items: center; justify-content: center; gap: 10px;
  padding: 0 12px env(safe-area-inset-bottom); background: rgba(0, 0, 0, .25);
}
.tb-group { display: flex; gap: 2px; }
.tb {
  min-width: 40px; height: 40px; display: inline-flex; align-items: center; justify-content: center;
  background: transparent; border: 0; border-radius: 8px; cursor: pointer; font-size: 18px; text-decoration: none;
}
.tb:hover { background: rgba(255, 255, 255, .1); }
.tb:focus-visible, .langs button:focus-visible, .nav-arrow:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.tb-slider { display: flex; align-items: center; gap: 10px; flex: 0 1 360px; min-width: 120px; }
.tb-slider input { flex: 1; accent-color: var(--accent); }
.counter { color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; min-width: 64px; text-align: center; }

/* panels */
.panel {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(380px, 100%); z-index: 20;
  background: var(--panel); display: flex; flex-direction: column; padding: 12px 16px;
  box-shadow: -10px 0 30px rgba(0, 0, 0, .4);
}
.panel[hidden] { display: none; }
.panel-head { display: flex; align-items: center; justify-content: space-between; }
.panel-head h2 { font-size: 16px; font-weight: 600; margin: 8px 0; }
.thumb-grid { overflow-y: auto; display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 10px; padding: 4px 2px 20px; }
.thumb-grid button { background: none; border: 2px solid transparent; border-radius: 6px; padding: 0; cursor: pointer; color: var(--muted); font-size: 12px; }
.thumb-grid button.on { border-color: var(--accent); color: var(--ink); }
.thumb-grid img { width: 100%; aspect-ratio: var(--aspect, 1); object-fit: cover; display: block; border-radius: 4px; background: #ddd; }
#searchInput {
  width: 100%; padding: 10px 12px; border-radius: 8px; border: 1px solid rgba(255, 255, 255, .2);
  background: rgba(255, 255, 255, .06); color: var(--ink); font: inherit; font-size: 16px;
}
.results { list-style: none; margin: 10px 0 0; padding: 0; overflow-y: auto; }
.results li { padding: 10px 8px; border-bottom: 1px solid rgba(255, 255, 255, .08); cursor: pointer; border-radius: 6px; }
.results li:hover { background: rgba(255, 255, 255, .06); }
.results b { color: var(--accent); }
.results mark { background: rgba(201, 167, 124, .4); color: inherit; }
.results .empty { color: var(--muted); cursor: default; }

/* zoom */
.zoom { position: fixed; inset: 0; z-index: 30; background: rgba(15, 13, 11, .97); display: flex; flex-direction: column; }
.zoom[hidden] { display: none; }
.zoom-bar { display: flex; align-items: center; justify-content: center; gap: 12px; height: 52px; color: var(--muted); }
.zoom-bar .close { position: absolute; right: 12px; }
.zoom-scroll { flex: 1; overflow: auto; text-align: center; touch-action: pan-x pan-y pinch-zoom; }
.zoom-scroll img { width: min(1600px, 100%); height: auto; }

.toast {
  position: fixed; left: 50%; bottom: calc(var(--bar-h) + 16px); transform: translateX(-50%) translateY(20px);
  background: #111; color: #fff; padding: 8px 14px; border-radius: 8px; opacity: 0; pointer-events: none; transition: .2s; z-index: 40;
}
.toast.show { opacity: 1; transform: translateX(-50%); }

@media (max-width: 720px) {
  .topbar { padding-left: 10px; padding-right: 10px; gap: 8px; }
  .brand { flex: none; }
  .brand-sub { display: none; }
  .brand-mark { letter-spacing: .16em; font-size: 13px; }
  .langs { min-width: 0; flex: 1 1 auto; }
  .langs button { padding: 4px 8px; font-size: 12px; }
  .stage { padding: 6px 8px; }
  .nav-arrow { display: none; }
  #firstBtn, #lastBtn, #fsBtn, .tb-slider input { display: none; }
  .toolbar { justify-content: space-between; gap: 2px; padding-left: 6px; padding-right: 6px; }
  .tb-slider { flex: 0 0 auto; min-width: 0; }
  .tb { min-width: 36px; }
  .counter { min-width: 56px; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
@media (max-width: 380px) {
  .tb { min-width: 30px; font-size: 16px; }
  .counter { min-width: 46px; font-size: 13px; }
  .langs button { padding: 3px 7px; }
}
