* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  font-family: -apple-system, "Helvetica Neue", "Apple SD Gothic Neo", sans-serif;
  color: #222;
  background: #fafaf7;
  font-size: 14px;
  line-height: 1.5;
}

/* ── Header ─────────────────────────────────────────────────────── */
header {
  position: sticky; top: 0; z-index: 10;
  background: #fff;
  border-bottom: 1px solid #ddd;
  padding: 0.6rem 1rem 0.7rem;
}
header .title { display: flex; align-items: baseline; gap: 0.8rem; flex-wrap: wrap; }
header h1 { margin: 0; font-size: 1.05rem; font-weight: 600; }
.status { font-size: 0.75rem; color: #999; }

/* Mode tabs */
.mode-tabs { display: flex; gap: 2px; }
.mode-tab {
  padding: 0.25rem 0.7rem; font-size: 0.78rem;
  border: 1px solid #ccc; background: #f4f4ef;
  cursor: pointer; border-radius: 3px;
  color: #666; font-weight: 500;
}
.mode-tab.active {
  background: #1a3a5a; color: #fff; border-color: #1a3a5a;
}
.mode-tab:hover:not(.active) { background: #e8e8e0; }

#search-section { display: flex; gap: 0.5rem; margin-top: 0.5rem; }
.search-input-wrap { position: relative; flex: 1; }
#q {
  width: 100%; padding: 0.5rem 0.7rem; font-size: 0.95rem;
  border: 1px solid #ccc; border-radius: 4px;
  font-family: inherit;
}
#q:focus { outline: none; border-color: #888; }
#go {
  padding: 0.5rem 1rem; font-size: 0.9rem; cursor: pointer;
  border: 1px solid #888; background: #fff; border-radius: 4px;
}
#go:hover { background: #f0f0ec; }

/* ── Autocomplete dropdown ─────────────────────────────────────── */
#autocomplete-list {
  position: absolute; top: 100%; left: 0; right: 0;
  margin: 2px 0 0; padding: 0;
  list-style: none;
  background: #fff; border: 1px solid #ccc; border-radius: 4px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.12);
  max-height: 280px; overflow-y: auto;
  z-index: 100;
}
.ac-item {
  padding: 0.45rem 0.7rem; cursor: pointer;
  font-size: 0.9rem; color: #333;
}
.ac-item b { color: #1a3a5a; }
.ac-item:hover, .ac-item.ac-active {
  background: #eef2f7; color: #111;
}

/* ── Layout ─────────────────────────────────────────────────────── */
main {
  display: grid;
  grid-template-columns: 240px 1fr;
  gap: 0;
  height: calc(100vh - 95px);
}

/* ── Sidebar ────────────────────────────────────────────────────── */
#sidebar {
  border-right: 1px solid #e4e4e0;
  background: #f4f4ef;
  overflow-y: auto;
  padding: 0.6rem 0.4rem;
  font-size: 0.82rem;
}

/* Filter pills */
.side-filters {
  display: flex; flex-wrap: wrap; gap: 4px;
  padding: 0.3rem 0.2rem 0.5rem;
  border-bottom: 1px solid #e0ddd5;
  margin-bottom: 0.5rem;
}
.filter-pill {
  font-size: 0.68rem; padding: 2px 8px;
  border-radius: 10px; border: 1px solid #ccc;
  background: #fff; color: #777; cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.filter-pill.active {
  background: var(--pill-color, #888);
  color: #fff;
  border-color: var(--pill-color, #888);
}
.filter-pill:hover { opacity: 0.85; }

.side-total { color: #666; padding: 0.2rem 0.4rem 0.6rem; font-weight: 600; }
.side-group-title {
  font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.06em;
  color: #999; margin: 0.6rem 0.4rem 0.2rem;
}
.side-link {
  display: flex; justify-content: space-between; align-items: center;
  padding: 0.25rem 0.4rem; border-radius: 3px;
  text-decoration: none; color: #333;
  gap: 0.4rem;
}
.side-link:hover { background: #e4e4dc; }
.side-name {
  flex: 1;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.side-count { color: #888; font-size: 0.72rem; flex-shrink: 0; }

/* ── Results area ───────────────────────────────────────────────── */
#results {
  overflow-y: auto;
  padding: 0.8rem 1.2rem 4rem;
  scroll-padding-top: 0.5rem;
}
.hint { color: #888; font-size: 0.9rem; }
.hint.error { color: #b33; }

/* ── Zone A: Quick Answer ───────────────────────────────────────── */
.zone-a {
  background: #f7f5ed;
  border: 1px solid #e4e0d0;
  border-radius: 6px;
  padding: 0.8rem 1rem;
  margin-bottom: 1rem;
}
.qa-headword {
  font-size: 1.2rem; font-weight: 700;
  color: #1a3a5a;
  margin-bottom: 0.3rem;
}
.qa-bilex {
  font-size: 0.82rem;
  color: #5a4a2a;
  margin-bottom: 0.5rem;
  padding: 0.2rem 0;
}
.qa-lines { margin: 0.3rem 0; }
.qa-line {
  display: flex; gap: 0.5rem; align-items: baseline;
  padding: 0.2rem 0;
  font-size: 0.85rem;
  cursor: pointer;
  border-radius: 3px;
}
.qa-line:hover { background: #eeeadd; }
.qa-dict-tag {
  flex-shrink: 0;
  font-size: 0.7rem; font-weight: 600;
  color: #555;
  border-left: 2px solid #999;
  padding-left: 6px;
  min-width: 80px;
}
.qa-snippet {
  color: #444;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
.qa-stats {
  font-size: 0.72rem; color: #aaa;
  margin-top: 0.4rem;
}

/* ── Zone B: Bilex (equivalents) ────────────────────────────────── */
.bilex-block {
  margin-bottom: 1rem;
  background: #f0efe8;
  border: 1px solid #d8d5c8;
  border-radius: 6px;
  padding: 0.6rem 0.8rem;
}
.bilex-header {
  margin: 0 0 0.4rem;
  font-size: 0.85rem;
  font-weight: 600;
  color: #6a5d3a;
}
.bilex-count { font-weight: normal; color: #999; font-size: 0.75rem; }
.bilex-exact-group { display: flex; flex-wrap: wrap; gap: 0.3rem 0.6rem; margin-bottom: 0.4rem; }
.bilex-partial-group { display: flex; flex-wrap: wrap; gap: 0.3rem 0.6rem; }
.bilex-partial-label {
  width: 100%;
  font-size: 0.72rem;
  color: #999;
  margin-top: 0.2rem;
  border-top: 1px solid #e4e0d0;
  padding-top: 0.3rem;
}
.bilex-entry {
  font-size: 0.85rem;
  padding: 0.2rem 0.5rem;
  background: #fff;
  border-radius: 3px;
  border: 1px solid #e4e0d0;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
}
.bilex-entry.bilex-exact {
  background: #fffbef;
  border-color: #e0d49a;
}
.bilex-entry.bilex-hidden { display: none; }
.bilex-src {
  font-size: 0.6rem;
  font-weight: 600;
  color: #fff;
  background: #b0a88a;
  border-radius: 2px;
  padding: 0 3px;
  line-height: 1.4;
  text-transform: uppercase;
}
.bilex-entry.bilex-exact .bilex-src { background: #8a7a4a; }
.bilex-num { color: #aaa; font-size: 0.72rem; }
.bilex-arrow { color: #bbb; font-size: 0.8rem; }
.bilex-zh { color: #8a3a1a; font-size: 0.88rem; font-weight: 500; }
.bilex-cat { color: #999; font-size: 0.72rem; }
.bilex-link {
  cursor: pointer;
  text-decoration: none;
  font-weight: 500;
}
.bilex-link:hover { text-decoration: underline; }
.bilex-skt { color: #1a3a5a; }
.bilex-tib { color: #5a1a3a; }
.bilex-more-btn {
  font-size: 0.75rem;
  color: #6a5d3a;
  background: none;
  border: 1px dashed #d8d5c8;
  border-radius: 3px;
  padding: 0.15rem 0.6rem;
  cursor: pointer;
  margin-top: 0.2rem;
}
.bilex-more-btn:hover { background: #f8f6f0; border-color: #b0a88a; }

/* ── Zone C: Display groups + dict blocks ───────────────────────── */
.zone-c { margin-bottom: 1rem; }

.display-group { margin-bottom: 0.8rem; }
.display-group.dg-hidden { display: none; }

.dg-header {
  margin: 1rem 0 0.4rem; font-size: 0.78rem;
  color: #777; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.08em;
  border-left: 2px solid #ccc;
  padding-left: 8px;
}
.dg-header:first-child { margin-top: 0; }

.dict-block {
  margin-bottom: 0.4rem;
  background: #fff;
  border: 1px solid #e4e4e0;
  border-radius: 4px;
}
.dict-block.tier-1 { }
.dict-block.tier-2 { }
.dict-block.tier-3 .dict-label { color: #777; }

.dict-head {
  margin: 0;
  padding: 0.5rem 0.7rem;
  font-size: 0.85rem; font-weight: 600;
  display: flex; align-items: center; gap: 0.5rem;
  cursor: pointer;
  border-bottom: 1px solid transparent;
  user-select: none;
}
.dict-head:hover { background: #f8f8f3; }
.dict-block:has(.dict-entries) .dict-head { border-bottom-color: #eeeae0; }
.arrow { color: #999; width: 0.8em; display: inline-block; }
.dict-label { color: #333; }
.dict-count { color: #aaa; font-weight: normal; font-size: 0.78rem; margin-left: auto; }

.pin-btn {
  font-size: 0.9rem;
  color: #ccc;
  cursor: pointer;
  padding: 0 4px;
  transition: color 0.15s;
}
.pin-btn:hover { color: #e6a817; }
.dict-block.pinned .pin-btn { color: #e6a817; }

.dict-entries { padding: 0.3rem 0; }
.entry {
  padding: 0.5rem 0.9rem;
  border-top: 1px solid #f1eee5;
}
.entry:first-child { border-top: none; }
.entry.exact { background: #fffbef; }
.entry .head {
  font-weight: 600;
  color: #1a3a5a;
  margin-bottom: 0.2rem;
  font-size: 0.95rem;
}
.entry .body {
  font-size: 0.88rem;
  color: #333;
  word-wrap: break-word;
}
.entry .body-ko {
  font-size: 0.9rem;
  line-height: 1.65;
  color: #2a2a2a;
  word-wrap: break-word;
  margin-bottom: 0.3rem;
}
.body-orig-toggle {
  margin-top: 0.2rem;
}
.body-orig-toggle summary {
  font-size: 0.75rem;
  color: #999;
  cursor: pointer;
  user-select: none;
}
.body-orig-toggle summary:hover { color: #666; }
.body-orig-toggle .body {
  font-size: 0.8rem;
  color: #888;
  border-left: 2px solid #ddd;
  padding-left: 0.5rem;
  margin-top: 0.3rem;
}

/* Tier 3 toggle */
.tier3-toggle {
  padding: 0.3rem 0.7rem;
}
.tier3-btn {
  font-size: 0.78rem;
  color: #888;
  background: none;
  border: 1px dashed #ccc;
  border-radius: 4px;
  padding: 0.3rem 0.8rem;
  cursor: pointer;
  width: 100%;
}
.tier3-btn:hover { background: #f4f4ef; color: #555; }

/* Family alternate source toggle */
.family-alt-toggle {
  padding: 0.15rem 0.7rem 0.15rem 1.2rem;
}
.family-alt-btn {
  font-size: 0.78rem;
  color: #777;
  background: none;
  border: 1px dashed #d0c8b0;
  border-radius: 4px;
  padding: 0.2rem 0.7rem;
  cursor: pointer;
}
.family-alt-btn:hover { background: #f5f0e5; color: #555; }
.family-alt-content {
  margin-left: 0.5rem;
  border-left: 2px dotted #d0c8b0;
  padding-left: 0.3rem;
}
.family-alt-content .dict-block {
  opacity: 0.85;
}

/* ── Zone D: Partial match headword list ────────────────────────── */
.zone-d {
  margin-top: 1rem;
  padding: 0.8rem 1rem;
  background: #f8f7f2;
  border: 1px solid #e4e0d8;
  border-radius: 6px;
}
.zd-header {
  margin: 0 0 0.5rem;
  font-size: 0.85rem;
  font-weight: 600;
  color: #555;
}
.zd-count { font-weight: normal; color: #999; font-size: 0.78rem; }
.zd-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.2rem 0.1rem;
}
.zd-word {
  display: inline-block;
  font-size: 0.83rem;
  color: #2a5a8a;
  cursor: pointer;
  padding: 0.15rem 0.4rem;
  border-radius: 3px;
  text-decoration: none;
  transition: background 0.1s;
}
.zd-word:hover {
  background: #dde8f0;
  text-decoration: underline;
}
.zd-word::after {
  content: " \00b7";
  color: #ccc;
  margin-left: 2px;
}
.zd-word:last-child::after,
.zd-word.zd-hidden + .zd-word:not(.zd-hidden)::after { }
.zd-hidden { display: none; }
.zd-n {
  font-size: 0.6rem;
  color: #aaa;
  vertical-align: super;
}
.zd-more {
  margin-top: 0.5rem;
  font-size: 0.78rem;
  color: #2a5a8a;
  background: none;
  border: 1px solid #ccc;
  border-radius: 4px;
  padding: 0.3rem 0.8rem;
  cursor: pointer;
}
.zd-more:hover { background: #eee; }

/* ══════════════════════════════════════════════════════════════════
   READER MODE
   ══════════════════════════════════════════════════════════════════ */

#reader-mode {
  display: grid;
  grid-template-columns: 200px 1fr 380px;
  gap: 0;
  height: calc(100vh - 95px);
}

/* File tree */
#file-tree {
  border-right: 1px solid #e4e4e0;
  background: #f4f4ef;
  overflow-y: auto;
  padding: 0;
  font-size: 0.82rem;
}
.tree-header {
  padding: 0.5rem 0.6rem;
  font-weight: 600; font-size: 0.8rem;
  color: #555;
  border-bottom: 1px solid #e0ddd5;
  background: #eeeae0;
}
.tree-empty { color: #999; padding: 0.5rem; font-size: 0.82rem; }
.tree-lang { margin-bottom: 0.3rem; }
.tree-lang-head {
  padding: 0.4rem 0.6rem 0.2rem;
  font-size: 0.7rem; text-transform: uppercase;
  letter-spacing: 0.06em; color: #999; font-weight: 600;
}
.tree-work { margin-left: 0.3rem; }
.tree-work-head {
  padding: 0.2rem 0.6rem;
  font-size: 0.78rem; color: #555; font-weight: 600;
}
.tree-file {
  display: block;
  padding: 0.2rem 0.6rem 0.2rem 1.2rem;
  color: #2a5a8a; text-decoration: none;
  cursor: pointer; border-radius: 3px;
}
.tree-file:hover { background: #e4e4dc; }
.tree-file.tree-active {
  background: #d0dce8;
  font-weight: 600;
}

/* Text panel */
#text-panel {
  overflow-y: auto;
  border-right: 1px solid #e4e4e0;
  display: flex; flex-direction: column;
}
#text-header {
  padding: 0.4rem 0.8rem;
  background: #f8f7f2;
  border-bottom: 1px solid #e4e0d8;
  font-size: 0.78rem; color: #666;
  font-weight: 500;
  flex-shrink: 0;
}
#text-body {
  flex: 1;
  overflow-y: auto;
  padding: 0.5rem 0.8rem 4rem;
}

/* Tokenized text */
.reader-text {
  font-size: 1rem;
  line-height: 1.8;
}
.text-sanskrit { font-family: "Gentium Plus", "Gentium", "Times New Roman", serif; }
.text-tibetan { font-family: "Noto Sans Tibetan", "Microsoft Himalaya", sans-serif; }

.text-line {
  position: relative;
  padding-left: 2.5rem;
  min-height: 1.4em;
}
.text-empty { height: 0.8em; }
.line-num {
  position: absolute; left: 0; top: 0;
  width: 2rem; text-align: right;
  font-size: 0.7rem; color: #bbb;
  user-select: none;
}
.token {
  cursor: pointer;
  border-radius: 2px;
  transition: background 0.1s;
}
.token:hover {
  background: #dde8f0;
}
.token-active {
  background: #b8d4f0;
  outline: 1px solid #7ab0d8;
}

/* Lookup panel */
#lookup-panel {
  overflow-y: auto;
  display: flex; flex-direction: column;
  background: #fafaf7;
}
#lookup-header {
  padding: 0.4rem 0.8rem;
  background: #f0efe8;
  border-bottom: 1px solid #e4e0d8;
  font-size: 0.8rem; font-weight: 600;
  color: #555;
  flex-shrink: 0;
}
#lookup-results {
  flex: 1;
  overflow-y: auto;
  padding: 0.5rem 0.6rem 4rem;
}
#lookup-results .zone-a { font-size: 0.9em; }
#lookup-results .qa-headword { font-size: 1.05rem; }
#lookup-results .dict-block { font-size: 0.88em; }

/* ── Vocab save button (in lookup panel) ────────────────────────── */
.vocab-save-bar {
  padding: 0.4rem 0; margin-bottom: 0.4rem;
  border-bottom: 1px solid #e4e0d8;
}
.vocab-save-btn {
  width: 100%;
  padding: 0.4rem 0;
  font-size: 0.82rem; font-weight: 500;
  color: #2a5a8a;
  background: #eef3f8;
  border: 1px solid #b8c8d8;
  border-radius: 4px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.vocab-save-btn:hover { background: #d8e8f4; border-color: #8ab; }
.vocab-save-btn.saved {
  background: #e8f5e8; color: #3a7a3a;
  border-color: #b8d8b8; cursor: default;
}

/* ══════════════════════════════════════════════════════════════════
   VOCAB MODE
   ══════════════════════════════════════════════════════════════════ */

#vocab-mode {
  display: block;
  max-width: 800px;
  margin: 0 auto;
  padding: 0.5rem 1rem 4rem;
}

/* Toolbar */
.vocab-toolbar {
  display: flex; flex-wrap: wrap;
  gap: 0.5rem; align-items: center;
  padding: 0.5rem 0;
  border-bottom: 1px solid #e4e0d8;
  margin-bottom: 0.5rem;
}
#vocab-search {
  flex: 1; min-width: 150px;
  padding: 0.4rem 0.6rem;
  font-size: 0.88rem; font-family: inherit;
  border: 1px solid #ccc; border-radius: 4px;
}
#vocab-search:focus { outline: none; border-color: #888; }

.vocab-filters { display: flex; gap: 2px; }
.vocab-filter-btn {
  padding: 0.25rem 0.6rem;
  font-size: 0.75rem; font-weight: 500;
  border: 1px solid #ccc; border-radius: 3px;
  background: #f4f4ef; color: #666;
  cursor: pointer;
}
.vocab-filter-btn.active {
  background: #1a3a5a; color: #fff; border-color: #1a3a5a;
}
.vocab-filter-btn:hover:not(.active) { background: #e8e8e0; }

.vocab-actions { display: flex; gap: 4px; margin-left: auto; }
.vocab-action-btn {
  padding: 0.25rem 0.5rem;
  font-size: 0.75rem;
  border: 1px solid #ccc; border-radius: 3px;
  background: #fff; cursor: pointer;
}
.vocab-action-btn:hover { background: #f0f0ec; }

/* Stats */
.vocab-stats {
  font-size: 0.78rem; color: #999;
  padding: 0.3rem 0;
}

/* Card list */
.vocab-list { }

.vocab-card {
  background: #fff;
  border: 1px solid #e4e4e0;
  border-radius: 6px;
  padding: 0.7rem 0.9rem;
  margin-bottom: 0.5rem;
  transition: box-shadow 0.1s;
}
.vocab-card:hover { box-shadow: 0 1px 4px rgba(0,0,0,0.08); }

.vocab-card-header {
  display: flex; align-items: center; gap: 0.4rem;
  margin-bottom: 0.3rem;
}
.vocab-headword {
  font-size: 1.05rem; font-weight: 600;
  color: #1a3a5a;
  font-family: "Gentium Plus", "Times New Roman", serif;
}
.vocab-lang-tag {
  font-size: 0.6rem; font-weight: 700;
  color: #fff; background: #8a8a7a;
  border-radius: 2px; padding: 0 4px;
  line-height: 1.5;
}
.vocab-status {
  font-size: 0.7rem; font-weight: 500;
  padding: 1px 6px; border-radius: 3px;
}
.vocab-status-new { background: #e8f0ff; color: #3a6aaa; }
.vocab-status-learning { background: #fff3e0; color: #aa6a2a; }
.vocab-status-known { background: #e8f5e8; color: #3a7a3a; }
.vocab-date {
  font-size: 0.7rem; color: #bbb;
  margin-left: auto;
}

.vocab-card-meaning {
  font-size: 0.88rem; color: #333;
  margin-bottom: 0.3rem;
  line-height: 1.5;
}
.vocab-card-context {
  font-size: 0.8rem; color: #888;
  padding: 0.3rem 0.5rem;
  background: #f8f7f2;
  border-left: 2px solid #ddd;
  border-radius: 2px;
  margin-bottom: 0.3rem;
  font-family: "Gentium Plus", "Times New Roman", serif;
}
.vocab-card-source {
  font-size: 0.72rem; color: #aaa;
  margin-bottom: 0.2rem;
}
.vocab-card-note {
  font-size: 0.82rem; color: #555;
  padding: 0.25rem 0.5rem;
  background: #fffbe8;
  border-left: 2px solid #e6c84a;
  border-radius: 2px;
  margin-bottom: 0.3rem;
}

.vocab-card-actions {
  display: flex; align-items: center; gap: 0.3rem;
  padding-top: 0.3rem;
  border-top: 1px solid #f0eee5;
}
.vocab-status-select {
  font-size: 0.75rem;
  padding: 2px 4px;
  border: 1px solid #ddd; border-radius: 3px;
  background: #fff;
}
.vocab-note-btn, .vocab-search-btn, .vocab-delete-btn {
  background: none; border: none;
  font-size: 0.85rem; cursor: pointer;
  padding: 2px 4px; border-radius: 3px;
  opacity: 0.5;
  transition: opacity 0.1s;
}
.vocab-note-btn:hover, .vocab-search-btn:hover { opacity: 1; }
.vocab-delete-btn:hover { opacity: 1; color: #c44; }

/* ── Upload ─────────────────────────────────────────────────────── */

/* Tree: uploaded texts section */
.tree-uploads { border-top: 1px solid #e0ddd5; padding-top: 0.2rem; }
.tree-upload-item {
  display: flex; align-items: center;
  padding-right: 0.3rem;
}
.tree-upload-item .tree-file { flex: 1; }
.upload-lang-tag {
  display: inline-block;
  font-size: 0.6rem; font-weight: 700;
  color: #fff; background: #8a8a7a;
  border-radius: 2px; padding: 0 3px;
  margin-right: 4px; line-height: 1.4;
  vertical-align: middle;
}
.tree-delete {
  background: none; border: none;
  color: #ccc; font-size: 1rem;
  cursor: pointer; padding: 2px 4px;
  line-height: 1;
}
.tree-delete:hover { color: #c44; }
.tree-upload-area {
  padding: 0.4rem 0.6rem;
}
.upload-btn {
  width: 100%;
  padding: 0.35rem 0;
  font-size: 0.78rem;
  color: #2a5a8a;
  background: #fff;
  border: 1px dashed #b8c8d8;
  border-radius: 4px;
  cursor: pointer;
}
.upload-btn:hover { background: #eef3f8; border-color: #8ab; }

/* Upload dialog overlay */
.upload-dialog-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 100;
  display: flex; align-items: center; justify-content: center;
}
.upload-dialog {
  background: #fff;
  border-radius: 8px;
  box-shadow: 0 8px 30px rgba(0,0,0,0.25);
  padding: 1.5rem;
  width: 90%; max-width: 480px;
  max-height: 90vh; overflow-y: auto;
}
.upload-dialog h3 {
  margin: 0 0 1rem; font-size: 1rem; font-weight: 600;
}
.upload-field {
  margin-bottom: 0.8rem;
}
.upload-field label {
  display: block;
  font-size: 0.78rem; color: #666;
  margin-bottom: 0.25rem; font-weight: 500;
}
.upload-field input[type="text"],
.upload-field textarea {
  width: 100%; padding: 0.4rem 0.6rem;
  font-size: 0.88rem; font-family: inherit;
  border: 1px solid #ccc; border-radius: 4px;
}
.upload-field textarea { resize: vertical; }
.upload-field input[type="text"]:focus,
.upload-field textarea:focus { outline: none; border-color: #888; }
.upload-field input[type="file"] { font-size: 0.82rem; }
.upload-lang-btns {
  display: flex; gap: 4px;
}
.upload-lang-opt {
  flex: 1;
  padding: 0.35rem 0.5rem;
  font-size: 0.82rem;
  border: 1px solid #ccc; border-radius: 4px;
  background: #f8f8f3; color: #555;
  cursor: pointer; text-align: center;
}
.upload-lang-opt.active {
  background: #1a3a5a; color: #fff; border-color: #1a3a5a;
}
.upload-lang-opt:hover:not(.active) { background: #eee; }
.upload-actions {
  display: flex; gap: 0.5rem; justify-content: flex-end;
  margin-top: 1rem;
}
.upload-cancel, .upload-confirm {
  padding: 0.4rem 1rem;
  font-size: 0.85rem;
  border-radius: 4px; cursor: pointer;
  border: 1px solid #ccc;
}
.upload-cancel { background: #fff; color: #666; }
.upload-cancel:hover { background: #f4f4ef; }
.upload-confirm { background: #1a3a5a; color: #fff; border-color: #1a3a5a; }
.upload-confirm:hover { background: #254a6e; }

/* ── Responsive ─────────────────────────────────────────────────── */
@media (max-width: 900px) {
  #reader-mode { grid-template-columns: 1fr 320px; }
  #file-tree { display: none; }
}
@media (max-width: 700px) {
  #search-mode { grid-template-columns: 1fr; }
  #sidebar { display: none; }
  #reader-mode { grid-template-columns: 1fr; position: relative; }
  #file-tree { display: none; }

  /* Mobile lookup panel: bottom sheet */
  #lookup-panel {
    display: none;
    position: fixed;
    bottom: 0; left: 0; right: 0;
    max-height: 55vh;
    z-index: 20;
    background: #fff;
    border-top: 2px solid #1a3a5a;
    box-shadow: 0 -4px 16px rgba(0,0,0,0.15);
    overflow-y: auto;
    border-radius: 12px 12px 0 0;
  }
  #lookup-panel.mobile-open { display: block; }

  /* Floating button to toggle lookup panel */
  .mobile-lookup-btn {
    display: flex !important;
    position: fixed;
    bottom: 1rem; right: 1rem;
    z-index: 21;
    width: 48px; height: 48px;
    border-radius: 50%;
    background: #1a3a5a;
    color: #fff;
    font-size: 1.2rem;
    align-items: center;
    justify-content: center;
    border: none;
    box-shadow: 0 2px 8px rgba(0,0,0,0.25);
    cursor: pointer;
  }

  /* Close button inside lookup panel */
  .mobile-lookup-close {
    display: block !important;
    position: sticky;
    top: 0;
    text-align: right;
    padding: 0.4rem 0.8rem;
    background: #fff;
    border-bottom: 1px solid #eee;
    font-size: 1.1rem;
    cursor: pointer;
    color: #666;
    border: none;
    width: 100%;
  }
}

/* ── Init error ────────────────────────────────────────────────── */
.init-error {
  max-width: 520px;
  margin: 2rem auto;
  padding: 1.5rem;
  background: #fff8f0;
  border: 1px solid #e8c080;
  border-radius: 6px;
  color: #6a4000;
  font-size: 0.88rem;
  line-height: 1.7;
}
.init-error h3 { margin: 0 0 0.5rem; font-size: 1rem; color: #a05000; }
.init-error code { background: #f0e0c8; padding: 0.15em 0.4em; border-radius: 3px; font-size: 0.82rem; }

/* ── Footer ─────────────────────────────────────────────────────── */
#site-footer {
  padding: 1rem 1.5rem;
  background: #f4f4ef;
  border-top: 1px solid #ddd;
  text-align: center;
  font-size: 0.72rem;
  color: #888;
  line-height: 1.6;
}
#site-footer a { color: #5a7a9a; text-decoration: none; }
#site-footer a:hover { text-decoration: underline; }
