/* ── Reset & Base ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* Hide PDF.js internal measurement canvases */
.hiddenCanvasElement { position: absolute !important; top: 0; left: 0; width: 0 !important; height: 0 !important; overflow: hidden; visibility: hidden; }

:root {
  --bg-page:    #F5F1EB;
  --bg-sidebar: #EBE7E0;
  --bg-surface: #FFFFFF;
  --bg-hover:   #E8E4DD;
  --bg-viewer:  #E0DBD3;
  --border:     #D8D3CA;
  --text:       #2D2B28;
  --text-sec:   #807A72;
  --text-dim:   #A8A29A;
  --accent:     #D97757;
  --accent-hover: #C4684A;
  --accent-soft: rgba(217,119,87,0.08);
  --danger:     #D44B4B;
  --radius:     12px;
  --radius-sm:  8px;
  --font:       -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Helvetica Neue', Arial, sans-serif;
  --font-mono:  'SF Mono', 'Cascadia Code', 'Fira Code', 'JetBrains Mono', monospace;
}

html, body {
  height: 100%;
  font-family: var(--font);
  background: var(--bg-page);
  color: var(--text);
  overflow: hidden;
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  display: flex;
  flex-direction: column;
}

/* ── Titlebar ── */
#titlebar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 42px;
  background: var(--bg-page);
  border-bottom: 1px solid var(--border);
  padding: 0 12px;
  -webkit-app-region: drag;
  position: relative;
  z-index: 100;
  flex-shrink: 0;
}

.titlebar-drag {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
}

.titlebar-icon { color: var(--accent); }
.titlebar-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  letter-spacing: -0.2px;
}
.titlebar-file {
  font-size: 13px;
  color: var(--text-sec);
  margin-left: 2px;
}

.titlebar-controls {
  display: flex;
  gap: 2px;
  -webkit-app-region: no-drag;
}

.tb-btn {
  width: 34px;
  height: 30px;
  border: none;
  background: transparent;
  color: var(--text-sec);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  transition: background 0.15s, color 0.15s;
}
.tb-btn:hover { background: var(--bg-hover); color: var(--text); }

/* ── Welcome Screen ── */
#welcome {
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1;
  min-height: 0;
  background: var(--bg-page);
  animation: fadeIn 0.4s ease;
}
#welcome.visible { display: flex; }

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}

.welcome-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.welcome-logo {
  margin-bottom: 4px;
  animation: float 3s ease-in-out infinite;
}
@keyframes float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-6px); }
}

.welcome-content h1 {
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -0.5px;
  color: var(--text);
}

.subtitle {
  color: var(--text-sec);
  font-size: 15px;
  margin-bottom: 8px;
}

.welcome-actions {
  display: flex;
  gap: 12px;
  margin-bottom: 28px;
}

/* ── Buttons ── */
.btn-primary, .btn-secondary {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 24px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 500;
  border: none;
  cursor: pointer;
  transition: all 0.15s;
  font-family: var(--font);
}

.btn-primary {
  background: var(--accent);
  color: #fff;
}
.btn-primary:hover {
  background: var(--accent-hover);
}

.btn-secondary {
  background: var(--bg-surface);
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-secondary:hover {
  background: var(--bg-hover);
}

/* ── Drop Zone ── */
.drop-zone {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 32px 48px;
  border: 1.5px dashed var(--border);
  border-radius: var(--radius);
  color: var(--text-dim);
  font-size: 14px;
  transition: all 0.2s;
}
.drop-zone.drag-over {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
}

/* ── Viewer ── */
#viewer {
  display: none;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  animation: fadeIn 0.3s ease;
}
#viewer.visible { display: flex; }

.viewer-toolbar {
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 6px 12px;
  background: var(--bg-page);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.toolbar-btn {
  width: 32px;
  height: 32px;
  border: none;
  background: transparent;
  color: var(--text-sec);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  transition: all 0.15s;
}
.toolbar-btn:hover { background: var(--bg-hover); color: var(--text); }

.toolbar-label {
  font-size: 13px;
  color: var(--text-sec);
  padding: 0 6px;
  min-width: 42px;
  text-align: center;
  user-select: none;
}

.toolbar-spacer { flex: 1; }

/* ── Search bar ── */
.search-bar {
  overflow: hidden;
  max-height: 0;
  opacity: 0;
  transition: max-height 0.25s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.2s ease;
  background: var(--bg-page);
  border-bottom: 1px solid transparent;
  flex-shrink: 0;
}

.search-bar.open {
  max-height: 52px;
  opacity: 1;
  border-bottom-color: var(--border);
}

.search-bar-inner {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
}

.search-bar-icon {
  color: var(--text-dim);
  flex-shrink: 0;
}

.search-input {
  flex: 1;
  min-width: 0;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg-surface);
  color: var(--text);
  font-size: 13px;
  font-family: var(--font);
  outline: none;
  transition: border-color 0.15s;
}

.search-input:focus {
  border-color: var(--accent);
}

.search-input::placeholder {
  color: var(--text-dim);
}

.search-info {
  font-size: 12px;
  color: var(--text-sec);
  min-width: 60px;
  text-align: center;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.search-nav-btn {
  width: 28px;
  height: 28px;
  border: none;
  background: transparent;
  color: var(--text-sec);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  transition: all 0.15s;
  flex-shrink: 0;
}

.search-nav-btn:hover {
  background: var(--bg-hover);
  color: var(--text);
}

.search-close-btn:hover {
  color: var(--danger);
}

/* ── Search highlights ── */
.search-highlight {
  background: rgba(255, 200, 50, 0.35);
  border-radius: 2px;
  z-index: 5;
  mix-blend-mode: multiply;
}

.search-highlight-active {
  background: rgba(217, 119, 87, 0.55);
  box-shadow: 0 0 0 2px var(--accent);
  border-radius: 2px;
}

body.dark .search-highlight {
  background: rgba(255, 200, 50, 0.25);
  mix-blend-mode: screen;
}

body.dark .search-highlight-active {
  background: rgba(224, 138, 106, 0.45);
}

/* Dictionary toggle */
.dict-toggle {
  width: auto !important;
  padding: 0 8px;
  font-weight: 600;
  font-size: 12px;
  letter-spacing: 0.5px;
}
.dict-toggle-label {
  font-family: var(--font);
  font-size: 12px;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: 0.5px;
}

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

/* ── Sidebar ── */
#sidebar {
  width: 180px;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  flex-shrink: 0;
  padding: 10px 8px;
}

#sidebar::-webkit-scrollbar { width: 5px; }
#sidebar::-webkit-scrollbar-track { background: transparent; }
#sidebar::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}
#sidebar::-webkit-scrollbar-thumb:hover { background: var(--text-dim); }

#thumbnail-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.thumb-item {
  cursor: pointer;
  border: 2px solid transparent;
  border-radius: var(--radius-sm);
  padding: 4px;
  background: var(--bg-surface);
  transition: all 0.15s;
  text-align: center;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}

.thumb-item:hover {
  border-color: var(--border);
}

.thumb-item.active {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.thumb-item canvas {
  width: 100%;
  display: block;
  border-radius: 4px;
}

.thumb-label {
  font-size: 11px;
  margin-top: 4px;
  color: var(--text-dim);
  font-weight: 500;
}

.thumb-item.active .thumb-label {
  color: var(--accent);
}

/* ── Viewer container ── */
#viewer-container {
  flex: 1;
  overflow-y: auto;
  background: var(--bg-viewer);
  position: relative;
}

#viewer-container::-webkit-scrollbar { width: 8px; }
#viewer-container::-webkit-scrollbar-track { background: transparent; }
#viewer-container::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 4px;
}
#viewer-container::-webkit-scrollbar-thumb:hover { background: var(--text-dim); }

#pdf-viewer {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 24px 0;
  gap: 20px;
}

.page-wrapper {
  position: relative;
  box-shadow: 0 1px 8px rgba(0,0,0,0.1), 0 0 1px rgba(0,0,0,0.08);
  border-radius: 4px;
  overflow: hidden;
  background: var(--bg-surface);
  content-visibility: auto;
  contain-intrinsic-size: auto 100vw auto 141vw;
  contain: layout style paint;
  will-change: transform;
}

.page-wrapper canvas {
  display: block;
  max-width: 100%;
  height: auto !important;
}

.text-layer {
  position: absolute;
  text-align: initial;
  inset: 0;
  overflow: clip;
  opacity: 0.25;
  line-height: 1;
  -webkit-text-size-adjust: none;
  text-size-adjust: none;
  forced-color-adjust: none;
  transform-origin: 0 0;
}

.text-layer :is(span, br) {
  color: transparent;
  position: absolute;
  white-space: pre;
  cursor: text;
  transform-origin: 0% 0%;
  -webkit-touch-callout: none;
}

.text-layer ::selection {
  background: rgba(217, 119, 87, 0.25);
}

/* ── Navigation arrows (horizontal mode) ── */
.nav-arrow {
  display: none;
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 44px;
  height: 64px;
  border: none;
  background: var(--bg-surface);
  color: var(--text-sec);
  cursor: pointer;
  border-radius: var(--radius-sm);
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
  opacity: 0;
  transition: opacity 0.2s, background 0.15s, color 0.15s;
  z-index: 10;
}

.nav-arrow:hover {
  background: var(--bg-hover);
  color: var(--text);
}

.nav-arrow-left { left: 16px; }
.nav-arrow-right { right: 16px; }

body.horizontal .nav-arrow {
  display: flex;
  opacity: 0.4;
}

body.horizontal .nav-arrow:hover {
  opacity: 1;
}

body.horizontal #viewer-container {
  overflow: hidden;
}

body.horizontal #pdf-viewer {
  justify-content: center;
  align-items: center;
  height: 100%;
  padding: 16px 0;
  gap: 0;
}

body.horizontal .page-wrapper {
  display: none;
  width: auto !important;
  aspect-ratio: unset !important;
  background: transparent;
  box-shadow: none;
  contain: none;
  content-visibility: visible;
}

body.horizontal .page-wrapper.active-page {
  display: block;
}

/* Sliding animations for horizontal page transitions */
body.horizontal .page-wrapper.slide-in-right {
  animation: slideInRight 0.35s cubic-bezier(0.22, 1, 0.36, 1) both;
}

body.horizontal .page-wrapper.slide-in-left {
  animation: slideInLeft 0.35s cubic-bezier(0.22, 1, 0.36, 1) both;
}

@keyframes slideInRight {
  from { opacity: 0; transform: translateX(60px); }
  to   { opacity: 1; transform: translateX(0); }
}

@keyframes slideInLeft {
  from { opacity: 0; transform: translateX(-60px); }
  to   { opacity: 1; transform: translateX(0); }
}

body.horizontal .page-wrapper canvas {
  max-height: calc(100vh - 130px);
  max-width: calc(100vw - 240px);
  width: auto !important;
  height: auto !important;
}

/* ── Fullscreen ── */
:fullscreen #titlebar {
  display: none;
}

:fullscreen #viewer {
  height: 100vh;
}

/* ── Dark mode ── */
body.dark {
  --bg-page:    #2F2B26;
  --bg-sidebar: #292521;
  --bg-surface: #3A3530;
  --bg-hover:   #44403A;
  --bg-viewer:  #1F1C18;
  --border:     #4A453E;
  --text:       #E8E2D9;
  --text-sec:   #A09890;
  --text-dim:   #787068;
  --accent:     #E08A6A;
  --accent-hover: #D07A5A;
  --accent-soft: rgba(224,138,106,0.1);
}

body.dark .page-wrapper {
  background: #262626;
  box-shadow: 0 1px 6px rgba(0,0,0,0.4);
}

body.dark .page-wrapper canvas {
  filter: invert(0.85) hue-rotate(180deg);
  will-change: filter;
}

/* ── Dictionary popup ── */
#dict-popup {
  position: fixed;
  z-index: 1000;
  max-width: 420px;
  min-width: 300px;
  max-height: 460px;
  display: flex;
  flex-direction: column;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 4px 24px rgba(0,0,0,0.12), 0 0 1px rgba(0,0,0,0.08);
  padding: 0;
  font-size: 14px;
  animation: popupSlideIn 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
  overflow: hidden;
}

@keyframes popupSlideIn {
  from { opacity: 0; transform: scale(0.95) translateY(4px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

#dict-popup.hidden { display: none; }

/* ── Popup tabs ── */
.dict-tabs {
  display: flex;
  gap: 0;
  padding: 10px 14px 0;
  flex-shrink: 0;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
}

.dict-tab {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border: none;
  background: transparent;
  color: var(--text-dim);
  font-size: 13px;
  font-weight: 500;
  font-family: var(--font);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  transition: all 0.15s;
  white-space: nowrap;
}

.dict-tab:hover {
  color: var(--text-sec);
  background: var(--bg-hover);
  border-radius: 6px 6px 0 0;
}

.dict-tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

.dict-tab svg {
  opacity: 0.6;
  flex-shrink: 0;
}

.dict-tab.active svg {
  opacity: 1;
}

/* ── Tab panels ── */
.dict-tab-panels {
  flex: 1;
  overflow-y: auto;
  min-height: 0;
}

.dict-tab-panels::-webkit-scrollbar { width: 5px; }
.dict-tab-panels::-webkit-scrollbar-track { background: transparent; }
.dict-tab-panels::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}

.dict-panel {
  display: none;
  padding: 16px 18px;
}

.dict-panel.active {
  display: block;
}

#dict-close {
  position: absolute;
  top: 10px;
  right: 12px;
  cursor: pointer;
  font-size: 13px;
  color: var(--text-dim);
  line-height: 1;
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  transition: all 0.15s;
  z-index: 2;
}

#dict-close:hover {
  background: var(--bg-hover);
  color: var(--danger);
}

.dict-word {
  font-size: 22px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 2px;
  letter-spacing: -0.3px;
}

.dict-phonetic {
  font-size: 13px;
  color: var(--text-dim);
  margin-bottom: 12px;
}

.dict-audio-btn {
  background: var(--bg-hover);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 3px 12px;
  cursor: pointer;
  font-size: 12px;
  color: var(--text-sec);
  margin-left: 8px;
  transition: all 0.15s;
  font-family: var(--font);
}

.dict-audio-btn:hover {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.dict-pos {
  font-weight: 600;
  font-style: italic;
  margin-top: 12px;
  margin-bottom: 4px;
  color: var(--accent);
  font-size: 13px;
  text-transform: capitalize;
}

.dict-def {
  margin-left: 0;
  margin-bottom: 6px;
  line-height: 1.55;
  color: var(--text);
  padding-left: 12px;
  position: relative;
}

.dict-def::before {
  content: '';
  position: absolute;
  left: 0;
  top: 8px;
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--text-dim);
}

.dict-example {
  margin-left: 12px;
  font-style: italic;
  color: var(--text-sec);
  font-size: 13px;
  padding-left: 10px;
  border-left: 2px solid var(--border);
  margin-bottom: 6px;
  line-height: 1.5;
}

.dict-error {
  color: var(--text-sec);
  font-style: italic;
}

.dict-loading {
  color: var(--text-dim);
}

.dict-more {
  font-size: 12px;
  color: var(--text-dim);
  font-style: italic;
  margin-top: 6px;
  padding-left: 12px;
}

.dict-source {
  margin-top: 14px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
  font-size: 11px;
  color: var(--text-dim);
  text-align: right;
  letter-spacing: 0.3px;
}

/* ── Wikipedia panel ── */
.wiki-thumbnail {
  width: 100%;
  max-height: 180px;
  object-fit: cover;
  border-radius: var(--radius-sm);
  margin-bottom: 12px;
  border: 1px solid var(--border);
}

.wiki-title {
  font-size: 20px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 4px;
  letter-spacing: -0.3px;
  line-height: 1.3;
}

.wiki-description {
  font-size: 13px;
  color: var(--accent);
  font-style: italic;
  margin-bottom: 10px;
}

.wiki-extract {
  font-size: 14px;
  color: var(--text);
  line-height: 1.65;
  margin-bottom: 14px;
}

.wiki-link {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 13px;
  color: var(--accent);
  text-decoration: none;
  font-weight: 500;
  padding: 6px 14px;
  border-radius: 999px;
  background: var(--accent-soft);
  transition: all 0.15s;
}

.wiki-link:hover {
  background: var(--accent);
  color: #fff;
}

/* ── Wiki search results list ── */
.wiki-results-header {
  font-size: 12px;
  color: var(--text-dim);
  margin-bottom: 10px;
  letter-spacing: 0.3px;
  text-transform: uppercase;
  font-weight: 600;
}

.wiki-results-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.wiki-result-item {
  padding: 10px 12px;
  background: var(--bg-page);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.15s;
}

.wiki-result-item:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.wiki-result-item.expanded {
  border-color: var(--accent);
  background: var(--bg-surface);
  cursor: default;
}

.wiki-result-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  line-height: 1.3;
  display: flex;
  align-items: center;
  gap: 6px;
}

.wiki-result-title::before {
  content: '›';
  font-size: 16px;
  color: var(--accent);
  transition: transform 0.2s;
  flex-shrink: 0;
  font-weight: 700;
}

.wiki-result-item.expanded .wiki-result-title::before {
  transform: rotate(90deg);
}

.wiki-result-snippet {
  font-size: 12px;
  color: var(--text-sec);
  line-height: 1.5;
  margin-top: 3px;
  padding-left: 16px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.wiki-result-item.expanded .wiki-result-snippet {
  display: none;
}

.wiki-result-detail {
  display: none;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.wiki-result-item.expanded .wiki-result-detail {
  display: block;
  animation: fadeIn 0.2s ease;
}

.wiki-source {
  margin-top: 14px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
  font-size: 11px;
  color: var(--text-dim);
  text-align: right;
  letter-spacing: 0.3px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

/* ── Reading History ── */
.history-section {
  width: 100%;
  max-width: 480px;
  margin-top: 32px;
}

.history-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.history-header h3 {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-sec);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.history-clear {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 12px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
  transition: all 0.15s;
  font-family: var(--font);
}

.history-clear:hover {
  color: var(--danger);
  background: var(--bg-hover);
}

.history-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.history-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.15s;
}

.history-item:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.history-item-icon {
  flex-shrink: 0;
  color: var(--accent);
  opacity: 0.7;
}

.history-item-info {
  flex: 1;
  min-width: 0;
}

.history-item-name {
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.history-item-meta {
  font-size: 12px;
  color: var(--text-dim);
  margin-top: 1px;
}

.history-item-page {
  flex-shrink: 0;
  font-size: 12px;
  color: var(--text-sec);
  background: var(--bg-hover);
  padding: 3px 10px;
  border-radius: 999px;
  font-weight: 500;
}

.history-item-remove {
  flex-shrink: 0;
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
  font-size: 14px;
  line-height: 1;
  transition: all 0.15s;
  opacity: 0;
}

.history-item:hover .history-item-remove {
  opacity: 1;
}

.history-item-remove:hover {
  color: var(--danger);
  background: var(--bg-hover);
}

/* ── Sidebar overlay (mobile) ── */
#sidebar-overlay {
  display: none;
}

/* ── Mobile Responsive ── */
@media (max-width: 768px) {
  /* Titlebar */
  #titlebar { height: 44px; padding: 0 10px; }
  .titlebar-title { font-size: 13px; }
  .titlebar-file { display: none; }

  /* Welcome */
  .welcome-content h1 { font-size: 22px; }
  .subtitle { font-size: 13px; text-align: center; padding: 0 20px; }
  .drop-zone { padding: 24px 32px; font-size: 13px; }
  #welcome { overflow-y: auto; justify-content: flex-start; padding-top: 40px; }
  .welcome-content { padding: 24px 16px; width: 100%; box-sizing: border-box; }
  .history-section { max-width: none; margin-top: 24px; }
  .history-item-remove { opacity: 1; }

  /* Viewer */

  /* Toolbar */
  .viewer-toolbar { padding: 4px 8px; gap: 1px; }
  .toolbar-btn { width: 36px; height: 36px; }
  .toolbar-label { font-size: 12px; min-width: 36px; padding: 0 3px; }

  /* Sidebar: off-canvas drawer */
  #sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 200px;
    z-index: 500;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    padding-top: 50px;
  }

  #sidebar.open {
    transform: translateX(0);
  }

  #sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 499;
    background: rgba(0,0,0,0.4);
  }

  #sidebar-overlay.visible {
    display: block;
  }

  /* PDF viewer full width */
  #pdf-viewer { padding: 12px 0; gap: 12px; }

  .page-wrapper canvas {
    max-width: 100%;
    height: auto !important;
  }

  /* Dictionary popup */
  #dict-popup {
    left: 8px !important;
    right: 8px !important;
    max-width: none;
    min-width: 0;
    bottom: 8px !important;
    top: auto !important;
    max-height: 55vh;
    border-radius: 16px;
    box-shadow: 0 -4px 24px rgba(0,0,0,0.15);
  }

  .dict-tabs { padding: 8px 10px 0; }
  .dict-tab { padding: 7px 12px; font-size: 12px; }
  .dict-panel { padding: 14px 14px; }

  /* Search bar mobile */
  .search-bar-inner { padding: 6px 10px; }
  .search-info { min-width: 48px; font-size: 11px; }

  /* Horizontal mode mobile */
  body.horizontal .nav-arrow { width: 36px; height: 52px; }
  .nav-arrow-left { left: 8px; }
  .nav-arrow-right { right: 8px; }

  body.horizontal .page-wrapper canvas {
    max-width: calc(100vw - 24px);
  }
}

@media (min-width: 769px) {
  /* Hide sidebar toggle on desktop */
  #btn-sidebar-toggle { display: none; }
}
