*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --accent: #c89968;
  --accent-dim: #a87950;
  --radius: 8px;
  --toolbar-h: 56px;
  --sidebar-w: 220px;
  --transition: 0.2s ease;
}

[data-theme="dark"] {
  --bg:        #282828;
  --surface:   #18181c;
  --surface2:  #21212a;
  --border:    #2a2a35;
  --text:      #d4d4d8;
  --text-dim:  #8b8b94;
  --text-hint: #6b6b76;
  --thumb-bg:  #2f2f3a;
}

[data-theme="light"] {
  --bg:        #f5f5f7;
  --surface:   #ffffff;
  --surface2:  #f9f9fb;
  --border:    #e0e0e5;
  --text:      #1f1f23;
  --text-dim:  #6b6b76;
  --text-hint: #8b8b94;
  --thumb-bg:  #efeff5;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 14px;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: background var(--transition), color var(--transition);
}

body.hand-mode { cursor: grab; }
body.hand-mode:active { cursor: grabbing; }
body.hand-mode #viewer-wrap { user-select: none; }

#toolbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 8px;
  row-gap: 12px;
  padding: 8px 14px;
  transition: background var(--transition), border-color var(--transition), transform 0.3s ease, opacity 0.3s ease;
  z-index: 10;
  flex-wrap: wrap;
}
body.fs #toolbar {
  transform: translateY(-100%);
  opacity: 0;
  position: absolute;
  top: 0; left: 0; right: 0;
  height: auto;
  min-height: auto;
  padding: 8px 14px;
}
body.fs #toolbar:hover, body.fs #toolbar.fs-show {
  transform: translateY(0);
  opacity: 1;
}

#app-name {
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.03em;
  color: var(--text);
  margin-right: 12px;
  white-space: nowrap;
}
#app-name span { color: var(--accent); }

.sep {
  width: 1px;
  height: 28px;
  background: var(--border);
  margin: 0 4px;
  flex-shrink: 0;
}

.tb-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 40px;
  padding: 0 14px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius);
  color: var(--text-dim);
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  transition: all var(--transition);
  min-width: 40px;
  touch-action: manipulation;
}
#page-input, #search-wrap { height: 40px; }
.tb-btn:hover {
  background: var(--surface2);
  color: var(--text);
  border-color: var(--border);
  transform: translateY(-1px);
}
.tb-btn.active {
  color: var(--accent);
  border-color: var(--accent);
  background: transparent;
  background: color-mix(in srgb, var(--accent) 12%, transparent);
}
.tb-btn svg { flex-shrink: 0; }

#open-btn {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
  font-weight: 600;
}
#open-btn:hover {
  background: var(--accent-dim);
  border-color: var(--accent-dim);
}

.split-btn {
  position: relative;
  display: flex;
}
.split-btn #open-btn {
  border-radius: var(--radius) 0 0 var(--radius);
  border-right: 1px solid rgba(255,255,255,0.2);
}
.split-btn #open-arrow {
  border-radius: 0 var(--radius) var(--radius) 0;
  margin-left: -1px;
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}
.split-btn #open-arrow:hover {
  background: var(--accent-dim);
  border-color: var(--accent-dim);
}
.split-btn #open-arrow svg { display: block; }

#open-dropdown {
  display: none;
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  z-index: 300;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 4px;
  min-width: 140px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.5);
}
#open-dropdown.open { display: block; }
#open-dropdown button {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 8px 14px;
  background: transparent;
  border: none;
  border-radius: 6px;
  color: var(--text-dim);
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
  text-align: left;
  transition: all var(--transition);
  white-space: nowrap;
}
#open-dropdown button:hover { background: var(--surface2); color: var(--text); }
#open-dropdown button svg { flex-shrink: 0; }
.dropdown-sep {
  height: 1px;
  background: var(--border);
  margin: 4px 8px;
}

#file-input { display: none; }

#zoom-display {
  width: 68px;
  height: 36px;
  text-align: center;
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-family: inherit;
  padding: 0 6px;
  outline: none;
  transition: all var(--transition);
}
#zoom-display:focus {
  border-color: var(--accent);
  background: var(--surface);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 10%, transparent);
}


#page-info {
  font-size: 13px;
  color: var(--text-dim);
  white-space: nowrap;
  font-weight: 500;
}

#page-input {
  width: 68px;
  height: 36px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  text-align: center;
  font-size: 13px;
  font-family: inherit;
  font-weight: 500;
  padding: 0 6px;
  transition: all var(--transition);
  -moz-appearance: textfield;
}
#page-input::-webkit-inner-spin-button,
#page-input::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
}
#page-input:focus {
  outline: none;
  border-color: var(--accent);
  background: var(--surface);
  box-shadow: none;
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 10%, transparent);
}

.spacer { flex: 1; }

.reading-time {
  font-size: 12px;
  color: var(--text-dim);
  white-space: nowrap;
  padding: 0 10px;
  display: none;
  user-select: none;
}
.reading-time.visible { display: inline; }

/* ── Search ─────────────────────────────── */
#search-wrap {
  display: none;
  align-items: center;
  gap: 4px;
  height: 36px;
  padding: 0 8px;
  border-radius: var(--radius);
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text-dim);
}
#search-wrap.active { display: flex; }
#search-wrap svg { flex-shrink: 0; }

#search-input {
  width: 120px;
  height: 28px;
  background: transparent;
  border: none;
  color: var(--text);
  font-size: 13px;
  font-family: inherit;
  outline: none;
}
#search-input::placeholder { color: var(--text-hint); }

#search-count {
  font-size: 11px;
  color: var(--text-hint);
  min-width: 36px;
  text-align: center;
}

.search-highlight {
  background: rgba(200, 153, 104, 0.4);
  border-radius: 2px;
  outline: 2px solid var(--accent);
}
.search-active {
  background: rgba(200, 153, 104, 0.7);
  outline-color: #fff;
}

/* ── Hand mode ──────────────────────────── */
#hand-btn.active { color: var(--accent); }

/* ── Progress bar ───────────────────────── */
#progress-bar {
  height: 3px;
  background: var(--surface);
  flex-shrink: 0;
  position: relative;
  z-index: 5;
}
#progress-fill {
  height: 100%;
  width: 0%;
  background: var(--accent);
  transition: width 0.2s ease;
}
body.fs #progress-bar { display: none; }

#loading-bar {
  height: 3px;
  background: var(--surface);
  flex-shrink: 0;
  position: relative;
  z-index: 5;
  overflow: hidden;
}
#loading-fill {
  height: 100%;
  width: 0%;
  background: var(--accent);
  transition: none;
}
#loading-bar.active #loading-fill {
  animation: loading-indeterminate 1.5s ease-in-out infinite;
}
@keyframes loading-indeterminate {
  0%   { width: 0%; margin-left: 0; }
  50%  { width: 50%; margin-left: 25%; }
  100% { width: 0%; margin-left: 100%; }
}

/* ── Language picker ────────────────────── */
.lang-picker {
  position: relative;
  display: flex;
  align-items: center;
}
#lang-btn {
  font-weight: 700;
  letter-spacing: 0.02em;
}

#lang-popup {
  display: none;
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 4px;
  z-index: 300;
  min-width: 130px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.5);
}
#lang-popup.open { display: block; }

.lang-opt {
  display: block;
  width: 100%;
  padding: 8px 14px;
  background: transparent;
  border: none;
  border-radius: 6px;
  color: var(--text-dim);
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
  text-align: left;
  transition: all var(--transition);
}
.lang-opt:hover { background: var(--surface2); color: var(--text); }
.lang-opt.active { color: var(--accent); font-weight: 600; }

/* ── Help modal ─────────────────────────── */
#loading-modal {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  z-index: 600;
  align-items: center;
  justify-content: center;
}
#loading-modal.open { display: flex; }
#loading-modal-content {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 32px 40px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  box-shadow: 0 16px 48px rgba(0,0,0,0.5);
}
#loading-modal-content p {
  font-size: 14px;
  color: var(--text-dim);
  margin: 0;
}
#loading-modal-spinner {
  width: 36px;
  height: 36px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: loading-spin 0.8s linear infinite;
}
@keyframes loading-spin {
  to { transform: rotate(360deg); }
}

#help-modal {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 500;
  align-items: center;
  justify-content: center;
}
#help-modal.open { display: flex; }

#help-content {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 28px 32px;
  min-width: 320px;
  max-width: 90vw;
  box-shadow: 0 16px 48px rgba(0,0,0,0.5);
}
#help-content h2 {
  font-size: 18px;
  font-weight: 700;
  margin-bottom: 12px;
  color: var(--text);
}
#help-content table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 12px;
}
#help-content td {
  padding: 6px 0;
  font-size: 13px;
  color: var(--text-dim);
  border-bottom: 1px solid var(--border);
}
#help-content td:first-child { white-space: nowrap; padding-right: 24px; }
#help-content kbd {
  display: inline-block;
  padding: 2px 7px;
  font-size: 11px;
  font-family: inherit;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text);
}
#about-desc {
  font-size: 13px;
  color: var(--text-dim);
  margin-bottom: 20px;
  line-height: 1.5;
}
#help-close {
  margin-top: 4px;
  width: 100%;
  justify-content: center;
}

/* ── PDF Info modal ─────────────────────── */
#info-modal {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 500;
  align-items: center;
  justify-content: center;
}
#info-modal.open { display: flex; }

#info-content {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 28px 32px;
  min-width: 360px;
  max-width: 90vw;
  box-shadow: 0 16px 48px rgba(0,0,0,0.5);
}
#info-content h2 {
  font-size: 18px;
  font-weight: 700;
  margin-bottom: 16px;
  color: var(--text);
}
#info-content table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 16px;
}
#info-content td {
  padding: 5px 0;
  font-size: 13px;
  color: var(--text-dim);
}
#info-content td:first-child {
  white-space: nowrap;
  padding-right: 20px;
  color: var(--text);
  font-weight: 600;
  width: 1%;
}
#info-content td:last-child {
  word-break: break-word;
}
#info-content tr.info-sep td {
  padding: 0;
  border-bottom: 1px solid var(--border);
  height: 1px;
}
#info-close {
  margin-top: 4px;
  width: 100%;
  justify-content: center;
}

#bookmark-btn.bookmarked { color: var(--accent); }
#bookmark-btn.bookmarked svg { fill: var(--accent); }

/* ── PDF theme ──────────────────────────── */
#pdf-theme-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-dim);
}
#pdf-theme-wrap img {
  filter: brightness(0) invert(0.55);
}

#pdf-theme-toggle {
  position: relative;
  width: 52px;
  height: 28px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 14px;
  cursor: pointer;
  transition: all var(--transition);
  flex-shrink: 0;
}
#pdf-theme-toggle:hover { border-color: var(--text-dim); }
#pdf-theme-toggle.dark-pdf {
  background: #21212a;
  border-color: var(--accent);
}
#pdf-theme-toggle::after {
  content: '';
  position: absolute;
  top: 4px;
  left: 4px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--thumb-bg);
  transition: all var(--transition);
}
#pdf-theme-toggle.dark-pdf::after {
  transform: translateX(24px);
  background: var(--accent);
}

#page-theme-btn { width: 36px; padding: 0; }

/* ── Color picker ───────────────────────── */
.color-picker {
  position: relative;
  display: flex;
  align-items: center;
}
#color-swatch {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 2px solid var(--border);
  cursor: pointer;
  transition: transform var(--transition), border-color var(--transition);
  flex-shrink: 0;
  margin: 0 6px;
}
#color-swatch:hover {
  transform: scale(1.15);
  border-color: var(--accent);
}

#color-popup {
  display: none;
  position: absolute;
  top: calc(100% + 8px);
  right: -4px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px;
  z-index: 300;
  box-shadow: 0 8px 32px rgba(0,0,0,0.5);
}
#color-popup.open { display: block; }

.cp-grid {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 4px;
}
.cp-swat {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  border: 2px solid transparent;
  cursor: pointer;
  transition: transform 0.15s ease, border-color 0.15s ease;
}
.cp-swat:hover {
  transform: scale(1.25);
  border-color: var(--accent);
}
.cp-swat.custom {
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface2);
  border-color: var(--border);
  color: var(--text-dim);
}
.cp-swat.custom:hover { color: var(--text); }
#font-color { display: none; }

/* ── PDF Adjust (brightness/contrast) ──── */
#pdf-adjust {
  position: relative;
  display: flex;
  align-items: center;
}

#adjust-popup {
  display: none;
  position: absolute;
  top: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 16px;
  z-index: 300;
  min-width: 180px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.5);
}
#adjust-popup.open { display: block; }
#adjust-popup label {
  display: block;
  font-size: 12px;
  color: var(--text-dim);
  margin: 6px 0 2px;
  font-weight: 500;
}
#adjust-popup label:first-child { margin-top: 0; }
#adjust-popup input[type="range"] {
  width: 100%;
  height: 4px;
  -webkit-appearance: none;
  appearance: none;
  background: var(--border);
  border-radius: 2px;
  outline: none;
  margin-bottom: 6px;
}
#adjust-popup input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid var(--surface);
  cursor: pointer;
  box-shadow: 0 1px 4px rgba(0,0,0,0.3);
}
#adjust-reset {
  width: 100%;
  height: 32px;
  font-size: 12px;
  margin-top: 8px;
  justify-content: center;
}

/* ── Main layout ────────────────────────── */
#main {
  flex: 1;
  display: flex;
  overflow: hidden;
  gap: 0;
}

#sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  transition: width var(--transition), min-width var(--transition), background var(--transition), border-color var(--transition);
  position: relative;
  overflow: hidden;
}
#sidebar.collapsed { width: 48px; min-width: 48px; }
#sidebar.collapsed #sidebar-header { display: none; }
#sidebar.collapsed #sidebar-body { display: none; }
#sidebar.collapsed #sidebar-bar { display: flex; }
#sidebar:not(.collapsed) #sidebar-bar { display: none; }

#sidebar-header {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 8px 8px 6px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

#sidebar-tabs {
  flex: 1;
  display: flex;
  gap: 6px;
}

.stab {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  height: 32px;
  white-space: nowrap;
  background: transparent;
  border: none;
  border-radius: 6px;
  color: var(--text-dim);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
}
.stab:active { background: var(--surface2); }
.stab.active {
  background: transparent;
  background: color-mix(in srgb, var(--accent) 12%, transparent);
  color: var(--accent);
}
.stab svg { flex-shrink: 0; }

#sidebar-toggle {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  border-radius: 6px;
  color: var(--text-dim);
  cursor: pointer;
  transition: all var(--transition);
  flex-shrink: 0;
}
#sidebar-toggle:active { background: var(--surface2); color: var(--text); }
#sidebar.collapsed #sidebar-toggle svg { transform: rotate(180deg); }

#sidebar-body {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  scrollbar-gutter: stable;
}
#sidebar-body::-webkit-scrollbar { width: 6px; }
#sidebar-body::-webkit-scrollbar-track { background: transparent; }
#sidebar-body::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
#sidebar-body::-webkit-scrollbar-thumb:hover { background: var(--text-dim); }

#sidebar-bar {
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 8px 0;
}

.sicon {
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  border-radius: 8px;
  color: var(--text-dim);
  cursor: pointer;
  transition: all var(--transition);
}
.sicon:active { background: var(--surface2); color: var(--text); }
.sicon.active { color: var(--accent); }

#sidebar-expand {
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  border-radius: 8px;
  color: var(--text-dim);
  cursor: pointer;
  transition: all var(--transition);
}
#sidebar-expand:active { background: var(--surface2); color: var(--text); }

.thumb-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  padding: 8px;
  border-radius: var(--radius);
  border: 2px solid transparent;
  transition: all var(--transition);
}
.thumb-item:hover {
  background: var(--surface2);
  transform: translateY(-2px);
}
.thumb-item.active {
  background: transparent;
  background: color-mix(in srgb, var(--accent) 15%, transparent);
  border-color: var(--accent);
}

.thumb-canvas {
  border-radius: 6px;
  border: 1px solid var(--border);
  max-width: 140px;
  display: block;
  box-shadow: 0 2px 6px rgba(0,0,0,0.2);
  transition: box-shadow var(--transition);
}
.thumb-item:hover .thumb-canvas { box-shadow: 0 4px 12px rgba(0,0,0,0.3); }

.thumb-label {
  font-size: 11px;
  color: var(--text-hint);
  font-weight: 600;
}
.thumb-item.active .thumb-label {
  color: var(--accent);
  font-weight: 700;
}

.thumb-item.hidden { display: none; }

#viewer-wrap {
  flex: 1;
  overflow-y: auto;
  overflow-x: auto;
  background: var(--bg);
  display: block;
  overflow-anchor: none;
  position: relative;
  transition: background var(--transition);
}
#viewer-wrap::-webkit-scrollbar { width: 8px; height: 8px; }
#viewer-wrap::-webkit-scrollbar-track { background: transparent; }
#viewer-wrap::-webkit-scrollbar-thumb { background: var(--thumb-bg); border-radius: 4px; }
#viewer-wrap::-webkit-scrollbar-thumb:hover { background: var(--accent); }

.page-wrap {
  position: relative;
  flex-shrink: 0;
  line-height: 0;
  border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.4);
  transition: box-shadow var(--transition);
  margin: 24px auto;
  text-align: left;
}
.page-canvas {
  display: block;
  border-radius: 8px;
  filter: brightness(var(--pdf-brightness, 100%)) contrast(var(--pdf-contrast, 100%));
}

.book-spread {
  display: flex;
  flex-direction: row;
  justify-content: center;
  gap: 16px;
  margin: 24px auto;
  align-items: flex-start;
}
.book-spread .page-wrap {
  margin: 0;
}



#drop-zone {
  position: absolute;
  inset: 10%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  color: var(--text-hint);
  border: 3px dashed var(--border);
  transition: all var(--transition);
  cursor: pointer;
  user-select: none;
}
#drop-zone:hover, #drop-zone.drag-over {
  border-color: var(--accent);
  background: transparent;
  background: color-mix(in srgb, var(--accent) 8%, transparent);
  color: var(--text-dim);
}
#drop-zone svg { opacity: 0.5; transition: opacity var(--transition); }
#drop-zone:hover svg { opacity: 0.7; }
#drop-zone p { font-size: 16px; font-weight: 600; }
#drop-zone small { font-size: 13px; opacity: 0.7; }

#fs-hint {
  position: fixed;
  bottom: 40px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 24px;
  font-size: 14px;
  color: var(--text);
  z-index: 200;
  opacity: 0;
  transition: opacity 0.3s ease;
  pointer-events: none;
  box-shadow: 0 4px 16px rgba(0,0,0,0.4);
}
#fs-hint.visible { opacity: 1; }

body.fs #sidebar { display: none; }
body.fs #viewer-wrap {
  padding: 0;
}

/* ── Mobile bottom bar ────────────────────── */
#mobile-bottom-bar { display: none; }
.flex-break { display: none; }

@media (max-width: 768px) {
  #sidebar { display: none; }

  /* ── Bottom bar with single scrollable row ── */
  #mobile-bottom-bar {
    display: flex;
    flex-shrink: 0;
    background: var(--surface);
    border-top: 1px solid var(--border);
    transition: background var(--transition), border-color var(--transition);
    padding-bottom: env(safe-area-inset-bottom, 0px);
    overflow-x: auto;
    overflow-y: visible;
    scrollbar-width: none;
    position: relative;
    z-index: 100;
  }
  #mobile-bottom-bar::-webkit-scrollbar { display: none; }
  body.fs #mobile-bottom-bar { display: none; }

  .bar-items {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 12px;
    min-height: 56px;
  }
  .bar-items .bar-label {
    font-size: 10px;
    font-weight: 600;
    color: var(--text-hint);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    white-space: nowrap;
    padding: 0 4px;
    flex-shrink: 0;
  }
  .bar-items .bar-sep {
    width: 1px;
    height: 24px;
    background: var(--border);
    flex-shrink: 0;
  }

  #mobile-bottom-bar .color-picker #color-popup {
    top: auto;
    bottom: calc(100% + 8px);
  }
  #mobile-bottom-bar #pdf-adjust #adjust-popup {
    top: auto;
    bottom: calc(100% + 8px);
  }
  #mobile-bottom-bar .split-btn #open-dropdown {
    top: auto;
    bottom: calc(100% + 4px);
    max-height: calc(100vh - 120px);
    overflow-y: auto;
  }

  /* ── Hide top toolbar on mobile ── */
  #toolbar { display: none; }

  .flex-break { display: none; }
  .sep { display: none; }
  .spacer { display: none; }
  #app-name { display: none; }

  .tb-btn { height: 48px; padding: 0 16px; font-size: 14px; min-width: 48px; }
  #page-input { width: 64px; height: 48px; font-size: 14px; }
  #search-wrap { height: 48px; }
  #search-input { width: 110px; font-size: 14px; height: 34px; }
  #search-count { font-size: 13px; }
  #color-swatch { width: 36px; height: 36px; margin: 0 6px; }
  #pdf-theme-wrap { gap: 8px; }
  #pdf-theme-toggle { width: 52px; height: 28px; }
  #hand-btn { display: none !important; }
  #fs-btn { display: none; }

  #drop-zone { position: absolute; inset: 10%; }
  #progress-bar { margin-top: 0; }
}

/* ── Settings Drawer ─────────────────────── */
#settings-drawer {
  position: fixed;
  top: 0; right: 0;
  width: 320px;
  height: 100vh;
  height: 100dvh;
  background: var(--surface);
  border-left: 1px solid var(--border);
  z-index: 400;
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform 0.25s ease, box-shadow 0.25s ease;
  box-shadow: none;
}
#settings-drawer.open {
  transform: translateX(0);
  box-shadow: -8px 0 32px rgba(0,0,0,0.4);
}

#drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
}
#drawer-close {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  border-radius: 6px;
  color: var(--text-dim);
  font-size: 18px;
  cursor: pointer;
  transition: all var(--transition);
}
#drawer-close:hover {
  background: var(--surface2);
  color: var(--text);
}

#drawer-body {
  flex: 1;
  overflow-y: auto;
  padding: 14px 16px 20px;
}
#drawer-body::-webkit-scrollbar { width: 6px; }
#drawer-body::-webkit-scrollbar-track { background: transparent; }
#drawer-body::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

.settings-group {
  margin-bottom: 20px;
}
.settings-group:last-child { margin-bottom: 0; }

.settings-cat {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-hint);
  margin-bottom: 10px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
}

.settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 0;
  gap: 12px;
  min-height: 40px;
}
.settings-row > span:first-child {
  font-size: 13px;
  color: var(--text);
  flex-shrink: 0;
}

.settings-val {
  font-size: 12px;
  height: 32px;
  min-width: 70px;
  padding: 0 14px;
}

/* Toggle switch */
.toggle-switch {
  position: relative;
  width: 44px;
  height: 24px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 12px;
  cursor: pointer;
  transition: all var(--transition);
  flex-shrink: 0;
}
.toggle-switch:hover { border-color: var(--text-dim); }
.toggle-switch.active {
  background: #21212a;
  border-color: var(--accent);
}
.toggle-knob {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--thumb-bg);
  transition: all var(--transition);
}
.toggle-switch.active .toggle-knob {
  transform: translateX(20px);
  background: var(--accent);
}

/* Slider */
.settings-slider {
  width: 120px;
  height: 4px;
  -webkit-appearance: none;
  appearance: none;
  background: var(--border);
  border-radius: 2px;
  outline: none;
  flex-shrink: 0;
}
.settings-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid var(--surface);
  cursor: pointer;
  box-shadow: 0 1px 4px rgba(0,0,0,0.3);
}
.settings-val-num {
  font-size: 12px;
  color: var(--text-dim);
  min-width: 28px;
  text-align: right;
  font-weight: 600;
}

/* Color swatches */
.settings-swatches {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
  justify-content: flex-end;
}
.settings-swat {
  width: 26px;
  height: 26px;
  border-radius: 5px;
  border: 2px solid transparent;
  cursor: pointer;
  padding: 0;
  transition: transform 0.15s ease, border-color 0.15s ease;
}
.settings-swat:hover {
  transform: scale(1.2);
  border-color: var(--accent);
}
.settings-swat.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 30%, transparent);
}
.settings-swat.custom {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--surface2);
  border-color: var(--border);
  color: var(--text-dim);
}
.settings-swat.custom:hover { color: var(--text); }
#settings-font-color { display: none; }

/* Language buttons */
.settings-lang-group {
  display: flex;
  gap: 4px;
}
.settings-lang-btn {
  font-size: 12px;
  height: 32px;
  min-width: 44px;
  padding: 0 12px;
  font-weight: 700;
  letter-spacing: 0.02em;
}
.settings-lang-btn.active {
  color: var(--accent);
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 12%, transparent);
}

#settings-btn svg { transition: transform 0.3s ease; }
#settings-btn:hover svg { transform: rotate(60deg); }

/* Page loading spinner */
.page-wrap { position: relative; }
.page-spinner {
  display: none;
  position: absolute;
  inset: 50% auto auto 50%;
  width: 28px; height: 28px;
  margin: -14px 0 0 -14px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  z-index: 2;
  animation: page-spin 0.7s linear infinite;
}
@keyframes page-spin { to { transform: rotate(360deg); } }
.page-wrap.page-loading .page-spinner { display: block; }
.page-wrap.page-loading .page-canvas { opacity: 0.3; transition: opacity 0.2s; }

/* Page jump input (dbl-click / N) */
.page-jump-input {
  height: 28px;
  width: 56px;
  background: var(--surface2);
  border: 1px solid var(--accent);
  border-radius: 4px;
  color: var(--text);
  text-align: center;
  font-size: 12px;
  font-family: inherit;
  font-weight: 600;
  outline: none;
  padding: 0 4px;
}

/* Hide old toolbar settings — now in the drawer */
#hide-settings, #hide-settings .sep { display: none !important; }

@media print {
  body > * { visibility: hidden; }
  #viewer-wrap, #viewer-wrap * { visibility: visible; }
  #viewer-wrap { position: absolute; inset: 0; overflow: visible; }
  #toolbar, #sidebar, #mobile-bottom-bar, #progress-bar, #info-modal, #help-modal, #settings-drawer, .search-highlight { display: none !important; }
  .page-wrap { box-shadow: none; margin: 0 auto; }
  .page-canvas { filter: none !important; }
}
