/* ── 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;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  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: 10px;
  width: 100%;
  max-width: 640px;
  margin: 0 auto;
  padding: 56px 24px 24px;
}

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

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

.subtitle {
  color: var(--text-sec);
  font-size: 14.5px;
  margin-bottom: 4px;
  text-align: center;
}

/* ── 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 (primary CTA) ── */
.drop-zone {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  width: 100%;
  max-width: 420px;
  padding: 28px 32px;
  margin-top: 12px;
  border: 1.5px dashed var(--border);
  border-radius: var(--radius);
  background: var(--bg-surface);
  color: var(--text-sec);
  font-family: var(--font);
  cursor: pointer;
  transition: all 0.2s;
}
.drop-zone:hover,
.drop-zone:focus-visible {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
  outline: none;
  transform: translateY(-1px);
  box-shadow: 0 6px 20px rgba(217, 119, 87, 0.12);
}
.drop-zone.drag-over {
  border-color: var(--accent);
  border-style: solid;
  background: var(--accent-soft);
  color: var(--accent);
  transform: translateY(-1px);
}
.drop-zone-icon {
  color: var(--accent);
  opacity: 0.85;
  margin-bottom: 2px;
}
.drop-zone-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  letter-spacing: -0.1px;
}
.drop-zone:hover .drop-zone-title,
.drop-zone:focus-visible .drop-zone-title,
.drop-zone.drag-over .drop-zone-title {
  color: var(--accent);
}
.drop-zone-hint {
  font-size: 12.5px;
  color: var(--text-dim);
}

/* ── 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: hidden;
  flex-shrink: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
}

#sidebar-tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.sidebar-tab {
  flex: 1;
  padding: 8px 4px;
  border: none;
  background: none;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-sec);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: all 0.15s;
  font-family: var(--font);
}

.sidebar-tab:hover { color: var(--text); background: var(--bg-hover); }
.sidebar-tab.active { color: var(--accent); border-bottom-color: var(--accent); }

.sidebar-panel {
  padding: 10px 8px;
  overflow-y: auto;
  flex: 1;
  min-height: 0;
}

/* ── TOC tree ── */
.toc-item { }

.toc-entry {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px 8px;
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: background 0.12s;
  font-size: 12px;
  line-height: 1.4;
}

.toc-entry:hover { background: var(--bg-hover); }

.toc-entry.active {
  background: var(--accent-soft);
  color: var(--accent);
}

.toc-entry.toc-disabled {
  cursor: default;
  opacity: 0.5;
}

.toc-toggle {
  font-size: 8px;
  width: 14px;
  flex-shrink: 0;
  text-align: center;
  color: var(--text-dim);
  transition: transform 0.15s;
  cursor: pointer;
  user-select: none;
}

.toc-item.expanded > .toc-entry > .toc-toggle {
  transform: rotate(90deg);
}

.toc-title {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.toc-page {
  flex-shrink: 0;
  font-size: 10px;
  color: var(--text-dim);
  margin-left: auto;
}

.toc-children {
  display: none;
}

.toc-item.expanded > .toc-children {
  display: block;
}

/* TOC loading spinner */
.toc-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 24px 8px;
  color: var(--text-dim);
  font-size: 12px;
}

.toc-spinner {
  width: 20px;
  height: 20px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: toc-spin 0.6s linear infinite;
}

@keyframes toc-spin {
  to { transform: rotate(360deg); }
}

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

#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;
}

/* ── Eye-save (sepia) mode — warm dark bg + amber text for long reading ── */
body.sepia {
  --bg-page:    #1A1611;
  --bg-sidebar: #16120D;
  --bg-surface: #241D15;
  --bg-hover:   #2E251B;
  --bg-viewer:  #100D08;
  --border:     #3A2F22;
  --text:       #E8C88A;
  --text-sec:   #B89A66;
  --text-dim:   #7A6844;
  --accent:     #F0B866;
  --accent-hover: #F5C478;
  --accent-soft: rgba(240,184,102,0.1);
}

body.sepia .page-wrapper {
  background: #1F1A13;
  box-shadow: 0 1px 6px rgba(0,0,0,0.5);
}

body.sepia .page-wrapper canvas {
  filter: invert(0.88) hue-rotate(180deg) sepia(0.55) saturate(1.35);
  will-change: filter;
}

body.sepia .search-highlight {
  background: rgba(240, 184, 102, 0.28);
  outline: 1px solid rgba(240, 184, 102, 0.5);
}

body.sepia .search-highlight-active {
  background: rgba(240, 184, 102, 0.45);
  outline: 1px solid rgba(240, 184, 102, 0.75);
}

/* ── 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;
}

/* ── Multi-word lookup ── */
.dict-lookup-btn {
  position: fixed;
  z-index: 10000;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 11px;
  border: none;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.2px;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(0,0,0,0.18), 0 1px 3px rgba(0,0,0,0.12);
  transition: background 0.15s, transform 0.12s;
  user-select: none;
  -webkit-user-select: none;
}
.dict-lookup-btn:hover { background: var(--accent-hover); }
.dict-lookup-btn:active { transform: scale(0.96); }
.dict-lookup-btn.hidden { display: none; }

.dict-phrase-header {
  font-size: 12px;
  color: var(--text-dim);
  margin-bottom: 10px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}

.dict-word-subhead {
  font-size: 14px;
  font-weight: 600;
  color: var(--accent);
  margin-top: 14px;
  margin-bottom: 4px;
  letter-spacing: 0.2px;
}
.dict-word-subhead:first-child,
.dict-phrase-header + .dict-word-subhead { margin-top: 0; }

.dict-error-inline {
  font-size: 12px;
  padding-left: 2px;
}

/* ── 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-perword-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 16px;
}

.wiki-perword-item {
  padding: 12px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

.wiki-perword-head {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 8px;
}

.wiki-perword-word {
  font-size: 14px;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: 0.2px;
}

.wiki-perword-title {
  font-size: 12px;
  color: var(--text-dim);
  font-style: italic;
}

.wiki-perword-thumb {
  width: 100%;
  max-height: 140px;
  object-fit: cover;
  border-radius: var(--radius-sm);
  margin-bottom: 8px;
  border: 1px solid var(--border);
}

.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: 100%;
  margin-top: 28px;
}

.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: 22px 28px; max-width: 100%; }
  .drop-zone-title { font-size: 14px; }
  .drop-zone-hint { font-size: 12px; }
  #welcome { overflow-y: auto; }
  .welcome-content { padding: 32px 16px 20px; 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; }
}

/* ─────────────────────────────────────────────
   Account chip + dropdown
   ───────────────────────────────────────────── */
.account-chip {
  position: relative;
  display: flex;
  align-items: center;
  margin-right: 6px;
}

.account-signin {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  font-size: 12px;
  font-weight: 500;
  color: var(--fg, #2e2e2e);
  background: transparent;
  border: 1px solid rgba(0, 0, 0, 0.12);
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.account-signin:hover {
  background: rgba(0, 0, 0, 0.05);
  border-color: rgba(0, 0, 0, 0.2);
}
body.dark .account-signin,
body.sepia .account-signin {
  color: var(--text);
  border-color: rgba(255, 255, 255, 0.18);
}
body.dark .account-signin:hover,
body.sepia .account-signin:hover {
  background: rgba(255, 255, 255, 0.06);
}

.account-chip-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 4px 10px 4px 4px;
  background: transparent;
  border: 1px solid rgba(0, 0, 0, 0.1);
  border-radius: 999px;
  cursor: pointer;
  font-size: 12px;
  color: inherit;
  max-width: 200px;
  transition: background 0.15s;
}
.account-chip-btn:hover { background: rgba(0, 0, 0, 0.05); }
body.dark .account-chip-btn,
body.sepia .account-chip-btn { border-color: rgba(255, 255, 255, 0.15); }
body.dark .account-chip-btn:hover,
body.sepia .account-chip-btn:hover { background: rgba(255, 255, 255, 0.06); }

.account-avatar {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
}
.account-avatar-initial {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: #c96442;
  color: white;
  font-weight: 600;
  font-size: 11px;
}

.account-chip-name {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 120px;
}

.account-plus-badge {
  display: inline-block;
  padding: 1px 6px;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.5px;
  background: linear-gradient(135deg, #c96442, #e89467);
  color: white;
  border-radius: 4px;
}

.account-dropdown {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  min-width: 260px;
  background: var(--bg, #faf9f6);
  border: 1px solid rgba(0, 0, 0, 0.1);
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
  z-index: 1000;
  overflow: hidden;
}
.account-dropdown.hidden { display: none; }
body.dark .account-dropdown {
  background: #2a2824;
  border-color: rgba(255, 255, 255, 0.1);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
}
body.sepia .account-dropdown {
  background: var(--bg-surface);
  border-color: rgba(240, 184, 102, 0.14);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
}

.account-dropdown-header {
  padding: 12px 14px;
  border-bottom: 1px solid rgba(0, 0, 0, 0.08);
}
body.dark .account-dropdown-header,
body.sepia .account-dropdown-header { border-color: rgba(255, 255, 255, 0.08); }
.account-dropdown-name {
  font-weight: 600;
  font-size: 13px;
  margin-bottom: 2px;
}
.account-dropdown-email {
  font-size: 11px;
  opacity: 0.7;
  word-break: break-all;
}

.account-dropdown-body {
  padding: 12px 14px;
}
.account-dropdown-status {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
}

.account-upgrade-btn {
  width: 100%;
  justify-content: center;
  flex-direction: column;
  gap: 2px;
  padding: 10px 16px;
}

.account-upgrade-price {
  font-size: 10px;
  font-weight: 400;
  opacity: 0.85;
}

.account-cancel-btn {
  margin-top: 8px;
  background: transparent;
  border: none;
  padding: 4px 0;
  font-size: 11px;
  color: #b04a3d;
  cursor: pointer;
  opacity: 0.8;
}
.account-cancel-btn:hover { opacity: 1; text-decoration: underline; }
body.dark .account-cancel-btn,
body.sepia .account-cancel-btn { color: #e07a6d; }

.account-dropdown-footer {
  padding: 8px 14px 10px;
  border-top: 1px solid rgba(0, 0, 0, 0.08);
}
body.dark .account-dropdown-footer,
body.sepia .account-dropdown-footer { border-color: rgba(255, 255, 255, 0.08); }
.account-signout-btn {
  background: transparent;
  border: none;
  padding: 6px 0;
  font-size: 12px;
  color: inherit;
  cursor: pointer;
  opacity: 0.75;
}
.account-signout-btn:hover { opacity: 1; }

/* ─────────────────────────────────────────────
   Upgrade modal
   ───────────────────────────────────────────── */
.upgrade-modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2000;
  padding: 20px;
  transition: background 0.3s ease;
}

.upgrade-modal-overlay.visible {
  background: rgba(0, 0, 0, 0.5);
}

.upgrade-modal {
  position: relative;
  background: #FFFBF7;
  border-radius: 20px;
  padding: 0;
  max-width: 440px;
  width: 100%;
  box-shadow: 0 25px 80px rgba(0, 0, 0, 0.2), 0 0 0 1px rgba(217, 119, 87, 0.08);
  overflow: hidden;
  transform: translateY(20px) scale(0.96);
  opacity: 0;
  transition: transform 0.35s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.25s ease;
}

.upgrade-modal-overlay.visible .upgrade-modal {
  transform: translateY(0) scale(1);
  opacity: 1;
}

body.dark .upgrade-modal {
  background: #2A2520;
  box-shadow: 0 25px 80px rgba(0, 0, 0, 0.5), 0 0 0 1px rgba(224, 138, 106, 0.1);
}
body.sepia .upgrade-modal {
  background: #241D15;
  box-shadow: 0 25px 80px rgba(0, 0, 0, 0.55), 0 0 0 1px rgba(240, 184, 102, 0.12);
}

.upgrade-modal-badge {
  display: inline-block;
  margin: 28px 0 14px 28px;
  padding: 4px 14px;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 1.5px;
  background: linear-gradient(135deg, #C96442, #E89467);
  color: white;
  border-radius: 6px;
}

.upgrade-modal h2 {
  margin: 0 28px 6px;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.4px;
  color: var(--text);
  line-height: 1.3;
}

.upgrade-modal-subtitle {
  margin: 0 28px 20px;
  font-size: 14px;
  color: var(--text-sec);
  line-height: 1.55;
}

.upgrade-modal-price {
  display: flex;
  align-items: baseline;
  gap: 4px;
  margin: 0 28px 24px;
  padding: 16px 20px;
  background: linear-gradient(135deg, rgba(217, 119, 87, 0.08), rgba(217, 119, 87, 0.03));
  border: 1px solid rgba(217, 119, 87, 0.15);
  border-radius: 14px;
}

body.dark .upgrade-modal-price {
  background: linear-gradient(135deg, rgba(224, 138, 106, 0.1), rgba(224, 138, 106, 0.04));
  border-color: rgba(224, 138, 106, 0.15);
}
body.sepia .upgrade-modal-price {
  background: linear-gradient(135deg, rgba(240, 184, 102, 0.12), rgba(240, 184, 102, 0.04));
  border-color: rgba(240, 184, 102, 0.18);
}

.upgrade-modal-price-label {
  font-size: 12px;
  color: var(--text-dim);
  font-weight: 500;
  margin-right: 4px;
}

.upgrade-modal-price-amount {
  font-size: 32px;
  font-weight: 800;
  color: var(--accent);
  letter-spacing: -1px;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.upgrade-modal-price-currency {
  font-size: 16px;
  font-weight: 600;
  margin-right: 2px;
}

.upgrade-modal-price-period {
  font-size: 13px;
  color: var(--text-dim);
  font-weight: 500;
}

.upgrade-modal-features {
  margin: 0 28px 24px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.upgrade-modal-feature {
  display: flex;
  align-items: flex-start;
  gap: 12px;
}

.upgrade-modal-feature-icon {
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(217, 119, 87, 0.08);
  border-radius: 10px;
  color: var(--accent);
}

body.dark .upgrade-modal-feature-icon {
  background: rgba(224, 138, 106, 0.1);
}
body.sepia .upgrade-modal-feature-icon {
  background: rgba(240, 184, 102, 0.12);
}

.upgrade-modal-feature-text {
  display: flex;
  flex-direction: column;
  gap: 1px;
  padding-top: 1px;
}

.upgrade-modal-feature-text strong {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}

.upgrade-modal-feature-text span {
  font-size: 12px;
  color: var(--text-sec);
  line-height: 1.4;
}

.upgrade-modal-actions {
  margin: 0 28px 16px;
}

.upgrade-modal-cta {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 13px 24px;
  background: linear-gradient(135deg, #C96442, #D97757);
  color: white;
  border: none;
  border-radius: 12px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  font-family: var(--font);
  box-shadow: 0 4px 16px rgba(201, 100, 66, 0.3);
}

.upgrade-modal-cta:hover {
  background: linear-gradient(135deg, #B85838, #C4684A);
  box-shadow: 0 6px 20px rgba(201, 100, 66, 0.4);
  transform: translateY(-1px);
}

.upgrade-modal-cta:active {
  transform: translateY(0);
  box-shadow: 0 2px 8px rgba(201, 100, 66, 0.3);
}

.upgrade-modal-footer {
  padding: 12px 28px 20px;
  font-size: 11px;
  color: var(--text-dim);
  text-align: center;
  letter-spacing: 0.2px;
}

.upgrade-modal-close {
  position: absolute;
  top: 14px;
  right: 14px;
  background: transparent;
  border: none;
  cursor: pointer;
  color: var(--text-dim);
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  transition: all 0.15s;
  z-index: 2;
}
.upgrade-modal-close:hover {
  background: var(--bg-hover);
  color: var(--text);
}

/* ─────────────────────────────────────────────
   Dict upgrade prompt (inside dict popup)
   ───────────────────────────────────────────── */
.dict-upgrade {
  padding: 22px 18px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.dict-upgrade-icon {
  width: 48px;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, rgba(217, 119, 87, 0.12), rgba(217, 119, 87, 0.04));
  border-radius: 14px;
  color: var(--accent);
  margin-bottom: 4px;
}

body.dark .dict-upgrade-icon {
  background: linear-gradient(135deg, rgba(224, 138, 106, 0.15), rgba(224, 138, 106, 0.05));
}
body.sepia .dict-upgrade-icon {
  background: linear-gradient(135deg, rgba(240, 184, 102, 0.18), rgba(240, 184, 102, 0.06));
}

.dict-upgrade-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.2px;
}

.dict-upgrade-msg {
  font-size: 12px;
  color: var(--text-sec);
  line-height: 1.5;
  max-width: 260px;
}

.dict-upgrade-price {
  font-size: 13px;
  color: var(--text-sec);
  margin-top: 2px;
}

.dict-upgrade-price strong {
  color: var(--accent);
  font-weight: 700;
}

.dict-upgrade-cta {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: 100%;
  max-width: 220px;
  margin-top: 8px;
  padding: 10px 20px;
  background: linear-gradient(135deg, #C96442, #D97757);
  color: white;
  border: none;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  font-family: var(--font);
  box-shadow: 0 3px 12px rgba(201, 100, 66, 0.25);
}

.dict-upgrade-cta:hover {
  background: linear-gradient(135deg, #B85838, #C4684A);
  box-shadow: 0 4px 16px rgba(201, 100, 66, 0.35);
  transform: translateY(-1px);
}

/* ─────────────────────────────────────────────
   Toast
   ───────────────────────────────────────────── */
.app-toast {
  position: fixed;
  bottom: 30px;
  left: 50%;
  transform: translateX(-50%) translateY(10px);
  background: #2a2824;
  color: #fff;
  padding: 12px 20px;
  border-radius: 999px;
  font-size: 13px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3);
  opacity: 0;
  transition: opacity 0.25s, transform 0.25s;
  z-index: 3000;
  pointer-events: none;
}
.app-toast.visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ─────────────────────────────────────────────
   Welcome screen Plus promo
   ───────────────────────────────────────────── */
/* ── Welcome Footer ── */
.welcome-footer {
  padding: 24px 16px 20px;
  text-align: center;
  flex-shrink: 0;
}

.welcome-footer-links {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-size: 13px;
  margin-bottom: 8px;
}

.welcome-footer-links a {
  color: var(--accent);
  text-decoration: none;
  font-weight: 500;
  transition: color 0.15s;
}

.welcome-footer-links a:hover {
  text-decoration: underline;
}

.welcome-footer-dot {
  color: var(--text-dim);
  font-size: 10px;
}

.welcome-footer-tagline {
  font-size: 12px;
  color: var(--text-dim);
  font-style: italic;
  line-height: 1.6;
  margin: 0;
}

.welcome-footer-attr {
  font-style: normal;
  font-size: 11px;
  opacity: 0.7;
}

/* ── Tutorial Modal ── */
.tutorial-modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2000;
  padding: 20px;
  transition: background 0.3s ease;
}

.tutorial-modal-overlay.visible {
  background: rgba(0, 0, 0, 0.5);
}

.tutorial-modal {
  position: relative;
  background: #FFFBF7;
  border-radius: 20px;
  padding: 0;
  max-width: 420px;
  width: 100%;
  box-shadow: 0 25px 80px rgba(0, 0, 0, 0.2), 0 0 0 1px rgba(217, 119, 87, 0.08);
  overflow: hidden;
  transform: translateY(20px) scale(0.96);
  opacity: 0;
  transition: transform 0.35s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.25s ease;
}

.tutorial-modal-overlay.visible .tutorial-modal {
  transform: translateY(0) scale(1);
  opacity: 1;
}

body.dark .tutorial-modal {
  background: #2A2520;
  box-shadow: 0 25px 80px rgba(0, 0, 0, 0.5), 0 0 0 1px rgba(224, 138, 106, 0.1);
}
body.sepia .tutorial-modal {
  background: #241D15;
  box-shadow: 0 25px 80px rgba(0, 0, 0, 0.55), 0 0 0 1px rgba(240, 184, 102, 0.12);
}

.tutorial-modal-close {
  position: absolute;
  top: 14px;
  right: 14px;
  background: transparent;
  border: none;
  cursor: pointer;
  color: var(--text-dim);
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  transition: all 0.15s;
  z-index: 2;
}
.tutorial-modal-close:hover {
  background: var(--bg-hover);
  color: var(--text);
}

.tutorial-modal-header {
  padding: 28px 28px 0;
}

.tutorial-modal-header h2 {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.4px;
  color: var(--text);
  margin-bottom: 4px;
}

.tutorial-modal-header p {
  font-size: 14px;
  color: var(--text-sec);
  line-height: 1.5;
}

.tutorial-modal-steps {
  padding: 24px 28px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.tutorial-modal-step {
  display: flex;
  align-items: flex-start;
  gap: 14px;
  opacity: 0;
  animation: tutorialStepFadeIn 0.5s ease forwards;
}

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

.tutorial-modal-step-icon {
  flex-shrink: 0;
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--accent-soft);
  border-radius: 12px;
  color: var(--accent);
}

.tutorial-modal-step-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding-top: 2px;
}

.tutorial-modal-step-text strong {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}

.tutorial-modal-step-text span {
  font-size: 13px;
  color: var(--text-sec);
  line-height: 1.45;
}

.tutorial-modal-dismiss {
  display: block;
  width: calc(100% - 56px);
  margin: 0 28px 24px;
  padding: 13px 24px;
  background: linear-gradient(135deg, #C96442, #D97757);
  color: white;
  border: none;
  border-radius: 12px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  font-family: var(--font);
  box-shadow: 0 4px 16px rgba(201, 100, 66, 0.3);
}

.tutorial-modal-dismiss:hover {
  background: linear-gradient(135deg, #B85838, #C4684A);
  box-shadow: 0 6px 20px rgba(201, 100, 66, 0.4);
  transform: translateY(-1px);
}

.tutorial-modal-dismiss:active {
  transform: translateY(0);
  box-shadow: 0 2px 8px rgba(201, 100, 66, 0.3);
}


/* Mobile adjustments for upgrade modal */
@media (max-width: 768px) {
  .upgrade-modal {
    max-width: none;
    margin: 0 8px;
    border-radius: 18px;
  }

  .upgrade-modal-badge { margin: 22px 0 10px 22px; }
  .upgrade-modal h2 { margin: 0 22px 6px; font-size: 19px; }
  .upgrade-modal-subtitle { margin: 0 22px 16px; }
  .upgrade-modal-price { margin: 0 22px 20px; }
  .upgrade-modal-features { margin: 0 22px 20px; }
  .upgrade-modal-actions { margin: 0 22px 12px; }
  .upgrade-modal-footer { padding: 10px 22px 16px; }

  .upgrade-modal-price-amount { font-size: 28px; }

  /* Tutorial modal mobile */
  .tutorial-modal {
    max-width: none;
    margin: 0 8px;
    border-radius: 18px;
  }
  .tutorial-modal-header { padding: 22px 22px 0; }
  .tutorial-modal-header h2 { font-size: 19px; }
  .tutorial-modal-steps { padding: 20px 22px; }
  .tutorial-modal-dismiss { width: calc(100% - 44px); margin: 0 22px 20px; }
}

/* ── AI lookup tab ── */
#ai-content {
  display: none;
  flex-direction: column;
  padding: 12px 14px 12px;
  gap: 10px;
}

#ai-content.active {
  display: flex;
}

.ai-selection-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  align-self: flex-start;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 12px;
  font-weight: 500;
  max-width: 100%;
}

.ai-selection-chip span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ai-conversation {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.ai-msg {
  max-width: 92%;
  padding: 9px 12px;
  border-radius: 12px;
  line-height: 1.5;
  font-size: 13.5px;
  word-wrap: break-word;
  white-space: pre-wrap;
}

.ai-msg-user {
  align-self: flex-end;
  background: var(--accent);
  color: #fff;
  border-bottom-right-radius: 4px;
}

.ai-msg-assistant {
  align-self: flex-start;
  background: var(--bg-hover);
  color: var(--text);
  border-bottom-left-radius: 4px;
}

.ai-loading {
  display: inline-flex;
  gap: 4px;
  padding: 12px;
}

.ai-loading span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-dim);
  animation: aiDot 1.2s infinite ease-in-out;
}

.ai-loading span:nth-child(2) { animation-delay: 0.15s; }
.ai-loading span:nth-child(3) { animation-delay: 0.3s; }

@keyframes aiDot {
  0%, 80%, 100% { opacity: 0.3; transform: scale(0.8); }
  40% { opacity: 1; transform: scale(1); }
}

.ai-followups {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.ai-followup-btn {
  text-align: left;
  padding: 8px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg-surface);
  color: var(--text);
  font-size: 13px;
  font-family: var(--font);
  cursor: pointer;
  transition: all 0.15s;
  line-height: 1.4;
}

.ai-followup-btn:hover {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
}

.ai-input-row {
  display: flex;
  gap: 6px;
  padding-top: 4px;
  border-top: 1px solid var(--border);
  margin-top: 2px;
}

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

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

.ai-send-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  transition: background 0.15s;
  flex-shrink: 0;
}

.ai-send-btn:hover {
  background: var(--accent-hover);
}

.ai-source {
  font-size: 11px;
  color: var(--text-dim);
  text-align: right;
  margin-top: 2px;
}

/* Dark mode */
:root.dark .ai-msg-assistant {
  background: rgba(255,255,255,0.06);
}

:root.dark .ai-followup-btn {
  background: rgba(255,255,255,0.03);
}

:root.dark .ai-followup-btn:hover {
  background: var(--accent-soft);
}

:root.dark .ai-input-row input {
  background: rgba(255,255,255,0.03);
}
