/* ── Reset & Variables ── pearead · Neo-Brutalism ────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* Hide scrollbars */
* { scrollbar-width: none; -ms-overflow-style: none; }
*::-webkit-scrollbar { display: none; }

:root {
  --bg:          #F5F0E8;
  --bg-card:     #FFFFFF;
  --bg-input:    #F5F0E8;
  --border:      #1A1A1A;
  --border-w:    2px;
  --text:        #1A1A1A;
  --text-dim:    #555;
  --text-muted:  #888;
  --accent:      #3D3B4F;  /* 玄青 */
  --accent-hover:#161823;  /* 漆黑 */
  --pop:         #C8E6C3;  /* neo-brut green highlight */
  --pop-yellow:  #FBE39A;
  --pop-pink:    #F7C5CC;
  --success:     #424C50;
  --warning:     #665757;
  --danger:      #6B2D2D;
  --primary:     #3D3B4F;
  --primary-rgb: 61, 59, 79;
  --surface:     #F5F0E8;
  --bg-dim:      #EBE5DA;
  --radius:      10px;
  --shadow:      4px 4px 0 var(--text);
  --shadow-sm:   2px 2px 0 var(--text);
  --sidebar-w:   280px;
}

/* ── Dark theme ─────────────────────────────────────────────────────── */
[data-theme="dark"] {
  --bg:          #161823;
  --bg-card:     #1E2030;
  --bg-input:    #282A3A;
  --border:      #555;
  --text:        #E0E0E0;
  --text-dim:    #999;
  --text-muted:  #777;
  --accent:      #7397AB;
  --accent-hover:#A1AFC9;
  --pop:         #2E4A3A;
  --pop-yellow:  #4A4530;
  --pop-pink:    #4A2D33;
  --success:     #BBCDC5;
  --warning:     #BACAC6;
  --danger:      #995555;
  --primary:     #7397AB;
  --primary-rgb: 115, 151, 171;
  --surface:     #1E2030;
  --bg-dim:      #161823;
  --shadow:      4px 4px 0 rgba(0,0,0,.5);
  --shadow-sm:   2px 2px 0 rgba(0,0,0,.4);
}

/* Dark-mode element overrides */
[data-theme="dark"] .research-card {
  background: var(--bg-card);
}
/* Dark site-theme highlight overrides removed — now controlled by reader theme variables */
[data-theme="dark"] .modal-overlay {
  background: rgba(0, 0, 0, 0.65);
}
[data-theme="dark"] .qa-msg.user {
  background: rgba(115, 151, 171, 0.12);
  border-color: var(--border);
}
[data-theme="dark"] .annotation-options {
  border-color: var(--border);
}

html { font-size: 15px; }
body {
  font-family: "Inter", "Helvetica Neue", system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.7;
  height: 100vh;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ── Material Symbols icon via data-icon attribute ────────────────── */
[data-icon]::before {
  font-family: 'Material Symbols Outlined';
  content: attr(data-icon);
  font-size: 1.15em;
  font-weight: normal;
  font-style: normal;
  line-height: 1;
  letter-spacing: normal;
  text-transform: none;
  white-space: nowrap;
  display: inline-block;
  vertical-align: middle;
  margin-right: .25em;
  -webkit-font-smoothing: antialiased;
}

#app {
  display: flex;
  height: 100vh;
}

/* ── Sidebar ────────────────────────────────────────────────────────── */
#sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  background: var(--bg-card);
  border-right: var(--border-w) solid var(--border);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  padding: 1.6rem;
  gap: 1.4rem;
  transition: width 0.25s ease, min-width 0.25s ease, padding 0.25s ease;
}

#sidebar.collapsed {
  width: 48px;
  min-width: 48px;
  padding: 0.8rem 0.5rem;
  overflow: hidden;
}

#sidebar.collapsed .sidebar-section {
  display: none;
}

#sidebar.collapsed .logo h1 {
  font-size: 0;
  overflow: hidden;
  line-height: 1;
}
#sidebar.collapsed .logo-icon {
  font-size: 1.2rem;
}
#sidebar.collapsed .sidebar-top-row {
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

#sidebar.collapsed .sidebar-toggle {
  transform: none;
}
#sidebar.collapsed .sidebar-toggle[data-icon]::before {
  content: "menu";
}

.sidebar-top-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.sidebar-toggle {
  font-size: 1rem;
  color: var(--text-dim);
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px;
  border-radius: 6px;
  flex-shrink: 0;
  margin-left: auto;
}

.sidebar-toggle:hover {
  color: var(--text);
  background: var(--bg-input);
}

a.logo {
  text-decoration: none;
  display: block;
  cursor: pointer;
}
.logo h1 {
  font-size: 1.25rem;
  font-weight: 900;
  letter-spacing: -0.02em;
  color: var(--text);
  text-transform: none;
}
.logo-icon {
  font-size: 1rem;
  vertical-align: -0.05em;
}
.logo .format-note {
  font-size: .68rem;
  color: var(--text-dim);
  opacity: 0.65;
  margin-top: .15rem;
}
#sidebar.collapsed .logo .format-note {
  display: none;
}

.sidebar-section h3 {
  font-size: .85rem;
  text-transform: uppercase;
  letter-spacing: .08em;
  font-weight: 800;
  color: var(--text);
  margin-bottom: .6rem;
}

.sidebar-section label,
.sidebar-section .sidebar-field {
  display: block;
  font-size: .78rem;
  color: var(--text-dim);
  margin-bottom: .45rem;
}

.api-key-warning {
  background: var(--pop-pink);
  border: var(--border-w) solid var(--border);
  border-radius: var(--radius);
  padding: 6px 10px;
  font-size: .75rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: .45rem;
  animation: pulse-warning 2s ease-in-out infinite;
}
@keyframes pulse-warning {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.7; }
}

.sidebar-field .sidebar-label {
  display: block;
  margin-bottom: .15rem;
}

.sidebar-section input,
.sidebar-section select,
.sidebar-field select,
.sidebar-field input {
  display: block;
  width: 100%;
  padding: .4rem .55rem;
  background: var(--bg-card);
  border: var(--border-w) solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: .82rem;
  margin-top: .15rem;
}
.sidebar-section input:focus,
.sidebar-section select:focus {
  outline: none;
  border-color: var(--accent);
}
.sidebar-section select optgroup { color: var(--text-dim); font-style: normal; }
.sidebar-section select option { color: var(--text); }

#project-list,
#mobile-project-list {
  display: flex;
  flex-direction: column;
  gap: .55rem;
}
.project-item {
  display: flex;
  align-items: center;
  padding: .65rem .85rem;
  background: var(--bg-card);
  border-radius: var(--radius);
  font-size: .82rem;
  font-weight: 500;
  border: var(--border-w) solid var(--border);
  box-shadow: var(--shadow-sm);
  transition: border-color .15s;
}
.project-item:hover {
  transform: translate(-1px, -1px);
  box-shadow: 3px 3px 0 var(--border);
}
.project-item.active {
  background: var(--pop-yellow);
}
.project-item.cached-only {
  opacity: .75;
  border-style: dashed;
}
.cached-badge {
  display: inline-block;
  font-size: .6rem;
  padding: 1px 5px;
  margin-left: 6px;
  border-radius: 3px;
  background: var(--bg-dim);
  color: var(--text-dim);
  border: 1px solid var(--border);
  vertical-align: middle;
  text-transform: uppercase;
  letter-spacing: .3px;
}
.project-item .project-info {
  flex: 1;
  min-width: 0;
  cursor: pointer;
}
.project-item .project-info > div:first-child {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.project-item .project-status {
  font-size: .7rem;
  color: var(--text-dim);
  margin-top: .15rem;
}
.project-actions {
  display: flex;
  align-items: center;
  gap: 2px;
  flex-shrink: 0;
  margin-left: 4px;
}
.btn-project-action {
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  padding: 3px 5px;
  border-radius: 6px;
  line-height: 1;
  font-size: .85rem;
  opacity: 0;
  transition: opacity .15s, color .15s, background .15s;
}
.project-item:hover .btn-project-action {
  opacity: 1;
}
.btn-project-delete {
  font-size: 1.05rem;
}
.btn-project-delete:hover {
  color: var(--danger);
  background: rgba(73, 49, 49, 0.06);
}
.btn-project-rename:hover,
.btn-project-cloud:hover {
  color: var(--accent);
  background: rgba(var(--primary-rgb), .08);
}

/* ── Main Area ──────────────────────────────────────────────────────── */
#main {
  flex: 1;
  overflow-y: auto;
  padding: 0 3rem 0;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  scrollbar-width: thin;
  scrollbar-color: var(--text-muted) transparent;
}
#main::-webkit-scrollbar { display: block; width: 6px; }
#main::-webkit-scrollbar-track { background: transparent; }
#main::-webkit-scrollbar-thumb { background: var(--text-muted); border-radius: 3px; }
#main::-webkit-scrollbar-thumb:hover { background: var(--text-dim); }
/* When no steps bar is visible (upload panel), add top padding */
#panel-upload.active { padding-top: 2rem; }

/* Steps bar — sticky at top */
#steps-bar {
  display: flex;
  gap: .5rem;
  padding: 1rem 0 .6rem;
  flex-wrap: wrap;
  flex-shrink: 0;
  position: sticky;
  top: 0;
  z-index: 60;
  background: var(--bg);
  border-bottom: 1px solid transparent;
  transition: border-color .2s;
}
#steps-bar.scrolled {
  border-bottom-color: var(--border);
}
#steps-bar .step {
  display: flex;
  align-items: center;
  gap: .35rem;
  padding: .35rem .75rem;
  border-radius: 999px;
  font-size: .78rem;
  font-weight: 600;
  background: var(--bg-card);
  border: var(--border-w) solid var(--border);
  color: var(--text-dim);
  transition: transform .1s, box-shadow .1s;
  box-shadow: var(--shadow-sm);
}
#steps-bar .step.active {
  background: var(--pop);
  color: var(--text);
  border-color: var(--border);
}
#steps-bar .step.done {
  background: var(--pop-yellow);
  border-color: var(--border);
  color: var(--text);
  cursor: pointer;
}
#steps-bar .step.done:hover {
  transform: translate(-1px, -1px);
  box-shadow: 3px 3px 0 var(--border);
}
.step-num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.3rem;
  height: 1.3rem;
  border-radius: 50%;
  font-size: .7rem;
  font-weight: 700;
  background: rgba(var(--primary-rgb), .08);
}
.step.active .step-num { background: rgba(255, 255, 255, .25); }
.step.done .step-num { background: rgba(var(--primary-rgb), .12); }

/* Panels — z-index below steps bar so sticky bar is never obscured */
.panel { display: none; flex-direction: column; gap: 1.6rem; padding-bottom: 80px; position: relative; z-index: 1; }
.panel.active { display: flex; }
.panel h2 { font-size: 1.4rem; font-weight: 900; letter-spacing: -0.01em; }
.panel .hint { color: var(--text-dim); font-size: .88rem; margin-top: -.4rem; }

#analysis-content,
#strategy-content {
  display: flex;
  flex-direction: column;
  gap: 1.4rem;
}

/* Language editor */
.lang-editor {
  display: flex;
  align-items: flex-end;
  gap: 1.2rem;
  flex-wrap: wrap;
  background: var(--bg-card);
  border: var(--border-w) solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.4rem;
  box-shadow: var(--shadow-sm);
}
.lang-editor label {
  font-size: .82rem;
  color: var(--text-dim);
}
.lang-editor input {
  display: block;
  margin-top: .2rem;
  padding: .4rem .55rem;
  background: var(--bg-card);
  border: var(--border-w) solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: .85rem;
  width: 160px;
}
.lang-editor input:focus { outline: none; border-color: var(--accent); }

.panel-center {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  flex: 1;
  min-height: 60vh;
}

/* Upload */
.upload-area {
  background: var(--bg-card);
  border: 3px dashed var(--border);
  border-radius: var(--radius);
  padding: 3rem 2.5rem;
  cursor: pointer;
  transition: transform .1s, box-shadow .1s;
  max-width: 520px;
  box-shadow: var(--shadow);
}
.upload-area:hover,
.upload-area.dragover {
  transform: translate(-2px, -2px);
  box-shadow: 6px 6px 0 var(--border);
}
.upload-icon { font-size: 3rem; margin-bottom: .8rem; line-height: 1; }
.upload-icon[data-icon]::before { font-size: 3rem; margin-right: 0; }
.upload-area h2 { margin-bottom: .3rem; }
.upload-area p { color: var(--text-dim); font-size: .88rem; }
.upload-options {
  display: flex;
  gap: 1rem;
  margin-top: 1.4rem;
  margin-bottom: 1.2rem;
}
.upload-options label {
  flex: 1;
  font-size: .82rem;
  color: var(--text-dim);
}
.upload-options input {
  display: block;
  width: 100%;
  margin-top: .3rem;
  padding: .4rem .55rem;
  background: var(--bg-input);
  border: var(--border-w) solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: .85rem;
}

.upload-footer {
  margin-top: 1.5rem;
  font-size: .7rem;
  color: var(--text-muted);
  display: flex;
  gap: .6rem;
  align-items: center;
  justify-content: center;
}
.upload-footer a {
  color: var(--text-dim);
  text-decoration: none;
}
.upload-footer a:hover { color: var(--accent); text-decoration: underline; }

/* Buttons — Neo-Brutalism */
.btn {
  padding: .5rem 1.1rem;
  border-radius: var(--radius);
  border: var(--border-w) solid var(--border);
  background: var(--bg-card);
  color: var(--text);
  font-size: .85rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform .1s, box-shadow .1s;
  box-shadow: var(--shadow-sm);
}
.btn:hover { transform: translate(-1px, -1px); box-shadow: 3px 3px 0 var(--border); }
.btn:active { transform: translate(2px, 2px); box-shadow: none; }
.btn-primary {
  background: var(--pop);
  color: var(--text);
  border-color: var(--border);
}
.btn-primary:hover { background: var(--pop); transform: translate(-1px, -1px); box-shadow: 3px 3px 0 var(--border); }
.btn-danger {
  background: var(--pop-pink);
  color: var(--text);
  border-color: var(--border);
}
.btn-danger:hover { transform: translate(-1px, -1px); box-shadow: 3px 3px 0 var(--border); }
.btn-outline {
  background: transparent;
  color: var(--text);
  border: var(--border-w) solid var(--border);
  box-shadow: none;
}
.btn-outline:hover { background: var(--bg-input); box-shadow: var(--shadow-sm); }
.btn-sm { padding: .35rem .8rem; font-size: .78rem; }
.btn-lg { padding: .65rem 2rem; font-size: 1rem; }
.btn-row { display: flex; gap: .6rem; flex-wrap: wrap; }

/* Cards */
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 1.2rem;
}
.card {
  background: var(--bg-card);
  border: var(--border-w) solid var(--border);
  border-radius: var(--radius);
  padding: 1.3rem 1.5rem;
  box-shadow: var(--shadow);
}
.card.full-width { grid-column: 1 / -1; }
.card h3 {
  font-size: .82rem;
  text-transform: uppercase;
  letter-spacing: .06em;
  font-weight: 800;
  color: var(--text);
  margin-bottom: .5rem;
}
.card ul { list-style: none; display: flex; flex-wrap: wrap; gap: .4rem; }
.card ul li {
  background: var(--pop-yellow);
  padding: .2rem .6rem;
  border-radius: 6px;
  border: var(--border-w) solid var(--border);
  font-size: .82rem;
  font-weight: 500;
}

/* Research card */
.research-card {
  background: var(--pop-yellow);
  border-left: 5px solid var(--border);
}

.research-author {
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 0.5rem;
}

.research-details {
  margin-top: 0.5rem;
}

.research-details summary {
  cursor: pointer;
  color: var(--accent);
  font-size: 0.88rem;
  font-weight: 500;
  user-select: none;
}

.research-details summary:hover {
  text-decoration: underline;
}

.research-report {
  margin-top: 0.75rem;
  padding: 12px;
  background: var(--bg-input);
  color: var(--text);
  border-radius: 6px;
  font-size: 0.88rem;
  line-height: 1.7;
  max-height: 50vh;
  overflow-y: auto;
  white-space: pre-wrap;
}

/* Chapter range picker */
.chapter-range-picker {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 0.75rem;
  flex-wrap: wrap;
}

.range-input {
  width: 60px;
  text-align: center;
  padding: 4px 6px;
  border: var(--border-w) solid var(--border);
  border-radius: 6px;
  font-size: 0.95rem;
}

.range-hint {
  font-size: 0.82rem;
  color: var(--text-dim);
}

.range-presets {
  display: flex;
  gap: 6px;
  margin-bottom: 0.75rem;
  flex-wrap: wrap;
}

.range-presets button {
  padding: 3px 10px;
  font-size: 0.8rem;
  border: var(--border-w) solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  cursor: pointer;
  transition: all 0.15s;
}

.range-presets button:hover {
  background: var(--pop);
  color: var(--text);
  border-color: var(--border);
}

/* Chapter overview in analysis */
.chapter-overview-list {
  max-height: 300px;
  overflow-y: auto;
  font-size: 0.85rem;
}

.chapter-overview-list .ch-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 0;
  border-bottom: var(--border-w) solid var(--border);
}

.chapter-overview-list .ch-row .ch-idx {
  color: var(--text-dim);
  min-width: 40px;
}
.ch-seq-num {
  display: inline-block;
  font-size: .7rem;
  color: var(--text-dim);
  min-width: 30px;
  text-align: right;
  margin-right: 6px;
  flex-shrink: 0;
  font-variant-numeric: tabular-nums;
}
.ch-type-tag {
  display: inline-block;
  font-size: .7rem;
  font-weight: 600;
  padding: 1px 6px;
  border-radius: 4px;
  min-width: 28px;
  text-align: center;
  flex-shrink: 0;
}
.ch-tag-chapter {
  background: rgba(var(--primary-rgb), .08);
  color: var(--accent);
}
.ch-tag-part {
  background: rgba(var(--primary-rgb), .06);
  color: var(--text-dim);
  font-weight: 700;
}
.ch-tag-frontmatter {
  background: rgba(var(--primary-rgb), .05);
  color: var(--text-dim);
}
.ch-tag-backmatter {
  background: rgba(var(--primary-rgb), .04);
  color: var(--text-dim);
}
.ch-type-part {
  font-weight: 600;
}
.ch-title-text {
  flex: 1;
}

/* Review translate more (inline in sticky footer) */
.review-translate-more {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  font-size: .85rem;
}
.review-translate-more .range-input {
  width: 50px;
}
.review-translate-more .range-hint {
  font-size: .78rem;
}

/* Character & term items */
.char-item, .term-item {
  padding: .45rem 0;
  border-bottom: var(--border-w) solid var(--border);
  font-size: .85rem;
}
.char-item:last-child, .term-item:last-child { border-bottom: none; }
.char-item strong, .term-item strong { color: var(--accent); }

/* Strategy form */
.strategy-field { margin-bottom: 1rem; }
.strategy-field .editable-table { margin-bottom: .6rem; }
.strategy-field label {
  display: block;
  font-size: .82rem;
  color: var(--text-dim);
  margin-bottom: .3rem;
  font-weight: 600;
}
.strategy-field textarea {
  width: 100%;
  background: var(--bg-card);
  border: var(--border-w) solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  padding: .6rem .8rem;
  font-size: .85rem;
  font-family: inherit;
  line-height: 1.5;
  resize: vertical;
}
.strategy-field textarea:focus { outline: none; border-color: var(--accent); }

.annotation-options {
  background: var(--bg-card);
  border: var(--border-w) solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 1.2rem 1.4rem;
  margin: 1.2rem 0;
  position: relative;
}
.annotation-options > label {
  margin-bottom: .7rem;
  font-size: .92rem !important;
  color: var(--accent) !important;
  letter-spacing: .02em;
}
.annotation-options > label::before {
  font-family: 'Material Symbols Outlined';
  content: "settings";
  font-size: 1.1em;
  vertical-align: middle;
  margin-right: .25em;
}
.checkbox-row {
  margin: .6rem 0;
  padding: .6rem .85rem;
  background: var(--bg-card);
  box-shadow: var(--shadow-sm);
  border-radius: 6px;
  border: var(--border-w) solid var(--border);
  transition: border-color .2s, background .2s;
}
.checkbox-row:hover {
  border-color: var(--accent);
  background: rgba(var(--primary-rgb), .03);
}
.checkbox-label {
  display: flex;
  align-items: flex-start;
  gap: .6rem;
  font-size: .88rem;
  cursor: pointer;
  color: var(--text);
  line-height: 1.5;
}
.checkbox-label input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
  cursor: pointer;
  flex-shrink: 0;
  margin-top: 2px;
}
.annotation-options .hint {
  margin-top: .6rem;
  padding: .5rem .7rem;
  background: var(--bg-input);
  border-radius: 6px;
  font-size: .8rem;
  line-height: 1.6;
  border-left: 3px solid var(--accent);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: .84rem;
}
th {
  text-align: left;
  padding: .4rem .6rem;
  background: var(--bg-input);
  color: var(--text-dim);
  font-weight: 600;
  font-size: .78rem;
}
td {
  padding: .4rem .6rem;
  border-bottom: var(--border-w) solid var(--border);
}
td input {
  width: 100%;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 6px;
  color: var(--text);
  font-size: .84rem;
  font-family: inherit;
  padding: 2px 4px;
  transition: border-color .2s, background .2s;
}
td input:hover {
  border-color: var(--border);
  background: rgba(var(--primary-rgb), .03);
}
td input:focus {
  outline: none;
  border-color: var(--accent);
  background: rgba(var(--primary-rgb), .04);
}
.editable-hint {
  font-size: .75rem;
  color: var(--accent);
  margin: 0 0 .4rem 0;
  opacity: .85;
}
.btn-delete-row {
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  font-size: .9rem;
  padding: 2px 5px;
  border-radius: 6px;
}
.btn-delete-row:hover { color: var(--danger); background: rgba(73, 49, 49, 0.06); }

.name-variant { white-space: nowrap; }
.name-variant small { color: var(--text-dim); }
.unify-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  align-items: center;
}
.name-table tr.inconsistent { background: rgba(var(--primary-rgb), .05); }
.name-table .trans-variants { max-width: 200px; }
.name-table .unify-input { width: 120px; }
.name-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}
.btn-replace-custom { font-size: .7rem; }
.unify-input {
  width: 120px;
  padding: 3px 6px;
  background: var(--bg-input);
  border: var(--border-w) solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: .8rem;
}
.btn-unify {
  font-size: .72rem !important;
  padding: 2px 8px !important;
}
td input:focus { outline: none; }

/* Comparison */
.comparison {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.2rem;
}
.comparison-col h3 {
  font-size: .88rem;
  color: var(--accent);
  margin-bottom: .5rem;
}
.text-display {
  background: var(--bg-card);
  border: var(--border-w) solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.2rem;
  max-height: 50vh;
  overflow-y: auto;
  white-space: pre-wrap;
  font-size: .85rem;
  line-height: 1.7;
}

/* Sample actions */
.sample-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.2rem;
  margin-top: .5rem;
}
.sample-action-card {
  background: var(--bg-card);
  border: var(--border-w) solid var(--border);
  border-radius: var(--radius);
  padding: 1.2rem 1.4rem;
  display: flex;
  flex-direction: column;
  gap: .6rem;
}
.sample-action-card.highlight {
  border-color: var(--accent);
  background: rgba(var(--primary-rgb), .03);
}
.sample-action-card h3 { font-size: .95rem; font-weight: 600; }
.sample-action-card .hint { margin: 0; font-size: .82rem; }
.sample-action-card textarea {
  width: 100%;
  background: var(--bg-input);
  border: var(--border-w) solid var(--border);
  border-radius: 8px;
  color: var(--text);
  padding: .6rem .8rem;
  font-size: .85rem;
  font-family: inherit;
  line-height: 1.5;
  resize: vertical;
}
.sample-action-card textarea:focus { outline: none; border-color: var(--accent); }
.sample-action-card .btn { align-self: flex-start; margin-top: auto; }
@media (max-width: 860px) {
  .sample-actions { grid-template-columns: 1fr; }
}

/* Done panel */
.done-actions {
  display: flex;
  gap: .8rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}
.chapter-dl-row {
  display: flex;
  align-items: center;
  gap: .8rem;
  padding: .45rem 0;
  border-bottom: var(--border-w) solid var(--border);
  font-size: .84rem;
}
.chapter-dl-row:last-child { border-bottom: none; }
.chapter-dl-row .ch-title { flex: 1; }
.chapter-dl-row .btn { flex-shrink: 0; }

/* Progress */
.progress-bar {
  width: 100%;
  height: 10px;
  background: var(--bg-input);
  border: var(--border-w) solid var(--border);
  border-radius: 6px;
  overflow: hidden;
  margin-bottom: .6rem;
}
.progress-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 4px;
  width: 0%;
  transition: width .6s ease-out;
}
#progress-text { color: var(--text-dim); font-size: .88rem; }

#chapter-status-list {
  margin-top: 1rem;
  display: flex;
  flex-direction: column;
  gap: .3rem;
}
.chapter-row {
  display: flex;
  align-items: center;
  gap: .6rem;
  font-size: .84rem;
  padding: .3rem 0;
}
.chapter-row .status-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}
.status-dot.pending { background: var(--text-dim); }
.status-dot.translating { background: var(--warning); }
.status-dot.translated { background: var(--success); }

/* Done */
.done-icon { font-size: 3.5rem; margin-bottom: 1rem; }

/* Loading */
.loading-spinner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: .8rem;
  padding: 2rem;
}
.spinner {
  width: 36px; height: 36px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Review Panel ──────────────────────────────────────────────────── */

.review-title-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}

.review-title-actions .hint {
  font-size: 0.8rem;
  color: var(--text-dim);
}

.review-filter-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 8px 0;
  font-size: 13px;
}
.review-filter-bar label {
  color: var(--text-dim);
  font-weight: 500;
}
.btn-xs {
  padding: 3px 10px;
  font-size: 12px;
  border-radius: 999px;
}
.review-filter-btn {
  border: var(--border-w) solid var(--border);
  background: var(--bg);
  color: var(--text-dim);
}
.review-filter-btn.active {
  background: var(--pop);
  color: var(--text);
  border-color: var(--border);
  font-weight: 700;
}

.review-chapter-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 1.5rem;
}

.review-chapter-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  background: var(--bg-card);
  border: var(--border-w) solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: transform .1s, box-shadow .1s;
}

.review-chapter-item:hover {
  transform: translate(-1px, -1px);
  box-shadow: 3px 3px 0 var(--border);
}

.review-chapter-item .ch-title {
  font-weight: 500;
  flex: 1;
}

.review-chapter-item .ch-status {
  font-size: 0.82rem;
  padding: 2px 10px;
  border-radius: 999px;
  background: rgba(var(--primary-rgb), .06);
  color: var(--success);
}

.review-chapter-item .ch-status.pending {
  background: rgba(var(--primary-rgb), .04);
  color: var(--text-dim);
}

.review-chapter-item .ch-status.translating {
  background: rgba(var(--primary-rgb), .08);
  color: var(--accent);
  animation: pulse 1.5s infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

.review-footer, .panel-sticky-footer {
  position: sticky;
  bottom: 0;
  z-index: 40;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 14px;
  padding: 1rem 0;
  background: var(--bg);
  border-top: var(--border-w) solid var(--border);
  margin-top: auto;
  flex-wrap: wrap;
}

.btn-sm {
  padding: 4px 12px;
  font-size: 0.85rem;
}

.feedback-section {
  padding: 18px 22px;
  border: var(--border-w) dashed var(--border);
  border-radius: var(--radius);
  background: var(--bg-card);
  box-shadow: var(--shadow-sm);
}

.feedback-section h3 {
  margin: 0 0 6px;
  font-size: 1rem;
}

.feedback-section .hint {
  margin: 0 0 10px;
}

.feedback-section textarea {
  width: 100%;
  resize: vertical;
  margin-bottom: 10px;
  padding: 10px 12px;
  border: var(--border-w) solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font-size: 0.9rem;
  font-family: inherit;
}

.feedback-section .btn {
  margin-top: 4px;
}

.sample-chapter-picker {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 1.5rem 0 1rem;
  padding: 12px 16px;
  background: var(--bg-input);
  border: var(--border-w) solid var(--border);
  border-radius: 8px;
  box-sizing: border-box;
  max-width: 100%;
  overflow: hidden;
}

.sample-chapter-picker label {
  font-weight: 600;
  white-space: nowrap;
  flex-shrink: 0;
}

.sample-chapter-picker select {
  padding: 4px 8px;
  border-radius: 6px;
  border: var(--border-w) solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 0.9rem;
  min-width: 120px;
  max-width: 320px;
  flex: 1 1 auto;
  box-sizing: border-box;
}

.sample-chapter-picker .hint {
  font-size: 0.82rem;
  color: var(--text-muted);
  margin: 0;
  flex-shrink: 1;
  min-width: 0;
}

/* ── Book Reader ────────────────────────────────────────────────────── */

#panel-reader {
  display: none;
  flex-direction: column;
  height: calc(100vh - 20px);
  min-height: 0;
  padding-bottom: 0 !important;
  overflow: hidden;
}
#panel-reader.active {
  display: flex !important;
}

.reader-toolbar {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 8px 0;
  border-bottom: var(--border-w) solid var(--border);
  position: sticky;
  top: 0;
  z-index: 40;
  background: var(--bg);
  flex-shrink: 0;
}

.reader-toolbar-row1 {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.reader-nav-label {
  font-weight: 600;
  font-size: 0.82rem;
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}

.reader-toolbar-row2 {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: nowrap;
}

.reader-toolbar-row2-left {
  display: flex;
  align-items: center;
  gap: 4px;
}

.reader-toolbar-row2-right {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
}

.reader-nav {
  display: flex;
  align-items: center;
  gap: 4px;
}

.reader-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.85rem;
  cursor: pointer;
}

.reader-toggle input { cursor: pointer; }

/* ── Reader "More" actions dropdown ────────────────────────────────── */
.reader-more-wrap { position: relative; }
.reader-more-dropdown {
  position: absolute;
  top: 100%;
  right: 0;
  z-index: 100;
  background: var(--bg-card);
  border: var(--border-w) solid var(--border);
  border-radius: var(--radius);
  padding: 6px;
  min-width: 200px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.reader-more-item {
  width: 100%;
  text-align: left;
  justify-content: flex-start;
  border: none !important;
  box-shadow: none !important;
  border-radius: 6px;
  padding: 7px 12px;
  font-size: .84rem;
}
.reader-more-item:hover { background: var(--bg-dim); }
.reader-more-item.btn-danger { background: none; color: var(--danger); }
.reader-more-item.btn-danger:hover { background: rgba(107, 45, 45, 0.08); }

/* ── Reader settings dropdown ──────────────────────────────────────── */
.reader-settings-wrap { position: relative; }
.reader-settings-dropdown {
  position: absolute;
  top: 100%;
  right: 0;
  z-index: 100;
  background: var(--bg-card);
  border: var(--border-w) solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  min-width: 210px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.35);
}
.rset-group { margin-bottom: 12px; }
.rset-group:last-child { margin-bottom: 0; }
.rset-group > label { display: block; font-size: 0.78rem; color: var(--text-dim); margin-bottom: 6px; font-weight: 600; }
.rset-options { display: flex; gap: 4px; }
.rset-opt {
  flex: 1;
  padding: 5px 8px;
  border: var(--border-w) solid var(--border);
  border-radius: 6px;
  background: transparent;
  color: var(--text);
  font-size: 0.82rem;
  cursor: pointer;
  text-align: center;
  transition: all 0.15s;
}
.rset-opt:hover { background: var(--bg-input); }
.rset-opt.active { background: var(--pop); color: var(--text); border-color: var(--border); font-weight: 700; }

/* ── Reader book view ─────────────────────────────────────────────── */
.reader-book-view {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0;
  flex: 1 1 auto;
  min-height: 150px;
  overflow: hidden;
  border-bottom: var(--border-w) solid var(--border);
}

/* ── Reader font size presets ─────────────────────────────────────── */
#panel-reader.rf-small .reader-book-content { font-size: 0.9rem; line-height: 1.7; }
#panel-reader.rf-medium .reader-book-content { font-size: 1.05rem; line-height: 1.9; }
#panel-reader.rf-large .reader-book-content { font-size: 1.22rem; line-height: 2.0; }

/* ── Reader color themes (scoped to book panes only) ──────────────── */

/* Light reader theme */
#panel-reader.rt-light {
  --hl-ann: #43A047;
  --hl-ann-bg: rgba(67, 160, 71, 0.08);
  --hl-ann-bg-hover: rgba(67, 160, 71, 0.16);
  --hl-mark: #F9A825;
  --hl-note-bg: rgba(156, 39, 176, 0.10);
  --hl-note-border: #AB47BC;
}
#panel-reader.rt-light .reader-book-content { background: #FAFAFA; color: #1A1A1A; }
#panel-reader.rt-light .reader-book-header { background: #F2F1EE; color: #666; border-color: #D4D2CD; }
#panel-reader.rt-light .reader-book-pane { border-color: #D4D2CD; }

/* Dark reader theme */
#panel-reader.rt-dark {
  --hl-ann: #00E676;
  --hl-ann-bg: rgba(0, 230, 118, 0.08);
  --hl-ann-bg-hover: rgba(0, 230, 118, 0.18);
  --hl-mark: #FFEA00;
  --hl-note-bg: rgba(206, 147, 255, 0.16);
  --hl-note-border: #CE93FF;
}
#panel-reader.rt-dark .reader-book-content { background: #1A1A1A; color: #D1D9E0; }
#panel-reader.rt-dark .reader-book-header { background: #1A1A1A; color: #888; }

/* Sepia reader theme */
#panel-reader.rt-sepia {
  --hl-ann: #558B2F;
  --hl-ann-bg: rgba(85, 139, 47, 0.08);
  --hl-ann-bg-hover: rgba(85, 139, 47, 0.16);
  --hl-mark: #F57F17;
  --hl-note-bg: rgba(149, 117, 205, 0.12);
  --hl-note-border: #7E57C2;
}
#panel-reader.rt-sepia .reader-book-content { background: #F5EFDE; color: #3D3027; }
#panel-reader.rt-sepia .reader-book-header { background: #EDE5D0; color: #7A7060; border-color: #D8D0BF; }
#panel-reader.rt-sepia .reader-book-pane { border-color: #D8D0BF; }

.reader-book-view.single-pane {
  grid-template-columns: 1fr;
}

.reader-book-pane {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border-right: var(--border-w) solid var(--border);
}

.reader-book-pane:last-child { border-right: none; }

.reader-book-header {
  padding: 6px 16px;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-dim);
  background: var(--bg-card);
  border-bottom: var(--border-w) solid var(--border);
  flex-shrink: 0;
}

.reader-book-content {
  padding: 20px 24px;
  overflow-y: auto;
  flex: 1;
  font-size: 1rem;
  line-height: 1.9;
  scrollbar-width: thin;
  scrollbar-color: var(--text-muted) transparent;
}
.reader-book-content::-webkit-scrollbar { display: block; width: 6px; }
.reader-book-content::-webkit-scrollbar-track { background: transparent; }
.reader-book-content::-webkit-scrollbar-thumb { background: var(--text-muted); border-radius: 3px; }
.reader-book-content::-webkit-scrollbar-thumb:hover { background: var(--text-dim); }

.reader-book-content h1 {
  font-size: 1.3em;
  font-weight: 700;
  margin: 0.8em 0 0.5em;
  text-align: center;
  text-transform: none;
  letter-spacing: normal;
}

.reader-book-content h2 {
  font-size: 1.1em;
  font-weight: 600;
  margin: 0.7em 0 0.4em;
  text-transform: none;
  letter-spacing: normal;
}

.reader-book-content p {
  text-indent: 2em;
  margin: 0.75em 0;
}

.reader-book-content p.separator {
  text-align: center;
  text-indent: 0;
  margin: 1.2em 0;
  color: var(--text-dim);
}

.reader-book-content ::selection {
  background: rgba(var(--primary-rgb), 0.15);
}

/* ── Chapter Selector Overlay ─────────────────────────────────────── */

.chapter-selector-overlay {
  position: fixed;
  inset: 0;
  z-index: 9000;
  background: rgba(0,0,0,0.4);
  display: flex;
  align-items: center;
  justify-content: center;
}
.chapter-selector-overlay.hidden { display: none; }

.chapter-selector-sheet {
  background: var(--bg-card);
  border-radius: 16px;
  width: 380px;
  max-height: 60vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 8px 32px rgba(0,0,0,0.18);
  overflow: hidden;
}

.chapter-selector-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px 10px;
  border-bottom: 1px solid var(--border);
}
.chapter-selector-header h3 { margin: 0; font-size: 1rem; font-weight: 700; }

.chapter-selector-list {
  flex: 1;
  overflow-y: auto;
  padding: 6px 0;
}

.chapter-selector-item {
  padding: 10px 18px;
  cursor: pointer;
  font-size: 0.92rem;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: background 0.15s;
}
.chapter-selector-item:hover { background: var(--bg-dim); }
.chapter-selector-item.active {
  color: var(--accent);
  font-weight: 600;
  background: color-mix(in srgb, var(--accent) 8%, transparent);
}
.chapter-selector-item .chapter-current-badge {
  font-size: 0.72rem;
  background: var(--accent);
  color: #fff;
  padding: 1px 6px;
  border-radius: 8px;
  margin-left: auto;
  flex-shrink: 0;
}

@media (max-width: 767px) {
  .chapter-selector-overlay {
    align-items: flex-end;
    justify-content: stretch;
  }
  .chapter-selector-sheet {
    width: 100%;
    max-height: 70vh;
    border-radius: 16px 16px 0 0;
    animation: slideUp .25s ease;
  }
  @keyframes slideUp {
    from { transform: translateY(100%); }
    to   { transform: translateY(0); }
  }
}

/* ── AI Q&A Panel ─────────────────────────────────────────────────── */

.reader-qa {
  flex-shrink: 0;
  border-top: var(--border-w) solid var(--border);
  background: var(--bg-card);
  max-height: 35vh;
  display: flex;
  flex-direction: column;
}

.reader-qa-header {
  padding: 10px 16px 4px;
  display: flex;
  align-items: baseline;
  gap: 12px;
}

.reader-qa-header h4 { margin: 0; font-size: 0.92rem; font-weight: 700; }
.reader-qa-header .hint { margin: 0; font-size: 0.78rem; color: var(--text-dim); flex: 1; }
.qa-close-btn { margin-left: auto; flex-shrink: 0; }

.reader-qa-messages {
  flex: 1;
  overflow-y: auto;
  padding: 8px 16px;
  min-height: 60px;
  max-height: 20vh;
}

.qa-msg {
  margin-bottom: 8px;
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 0.88rem;
  line-height: 1.6;
}

.qa-msg.user {
  background: rgba(var(--primary-rgb), 0.05);
  border: 1px solid rgba(var(--primary-rgb), 0.1);
  text-align: right;
}

.qa-msg.ai {
  background: var(--bg-input);
  border: 1px solid var(--border);
}

.qa-msg .qa-selection-badge {
  display: block;
  font-size: 0.78rem;
  color: var(--text-dim);
  margin-bottom: 4px;
  font-style: italic;
}

.reader-qa-input {
  padding: 8px 16px 10px;
  border-top: var(--border-w) solid var(--border);
}

.reader-qa-selection {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px;
  margin-bottom: 6px;
  background: rgba(115, 151, 171, 0.1);
  border-radius: 8px;
  font-size: 0.82rem;
}

.reader-qa-selection-label { color: var(--accent); font-weight: 600; }

#reader-qa-selection-text {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.reader-qa-input-row {
  display: flex;
  gap: 8px;
}

.reader-qa-input-row input {
  flex: 1;
  padding: 8px 12px;
  border: var(--border-w) solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font-size: 0.88rem;
}

.btn-icon {
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 1rem;
  padding: 2px 6px;
}
.btn-icon[data-icon]::before,
[data-icon]:empty::before { margin-right: 0; }
.btn-icon[data-icon]::before { font-size: 1.1rem; }
.btn-icon:hover { color: var(--text); }

/* ── Title Editor Modal ──────────────────────────────────────────── */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.25);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.modal-content {
  background: var(--bg-card);
  border: var(--border-w) solid var(--border);
  border-radius: var(--radius);
  padding: 28px;
  box-shadow: 6px 6px 0 var(--border);
  max-width: 700px;
  width: 90%;
  max-height: 80vh;
  overflow-y: auto;
}

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

.modal-header h3 { margin: 0; }

.title-editor-modal {
  max-width: 720px;
  max-height: 80vh;
  overflow-y: auto;
}

.name-table-modal {
  max-width: 960px;
  max-height: 80vh;
  overflow-y: auto;
}

.title-editor-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 12px;
}

.title-editor-row {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 8px 10px;
  border: var(--border-w) solid var(--border);
  border-radius: 8px;
  background: var(--bg-input);
}

.te-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 0.5rem;
}

.te-header {
  display: flex;
  align-items: center;
  gap: 8px;
}
.te-seq {
  font-size: .75rem;
  color: var(--text-dim);
  min-width: 28px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}
.te-body-num {
  font-size: .7rem;
  color: var(--accent);
  min-width: 36px;
  font-weight: 600;
}

.te-type {
  padding: 3px 8px;
  border: var(--border-w) solid var(--border);
  border-radius: 6px;
  background: var(--bg-card);
  color: var(--text);
  font-size: 0.82rem;
}

.te-titles {
  display: flex;
  gap: 8px;
}

.te-titles input {
  flex: 1;
  padding: 5px 8px;
  border: var(--border-w) solid var(--border);
  border-radius: 6px;
  background: var(--bg-card);
  color: var(--text);
  font-size: 0.85rem;
}

.te-titles input::placeholder {
  color: var(--text-dim);
  font-style: italic;
}

.sidebar-home-btn {
  width: 100%;
  text-align: center;
  margin-bottom: -0.4rem;
}

#sidebar.collapsed .sidebar-home-btn {
  font-size: 0;
  padding: 6px 0;
}

#sidebar.collapsed #btn-docs::before {
  font-family: 'Material Symbols Outlined';
  content: "menu_book";
  font-size: 1.15rem;
}
#sidebar.collapsed #btn-bookshelf::before {
  font-family: 'Material Symbols Outlined';
  content: "auto_stories";
  font-size: 1.15rem;
}

.sidebar-lang-section {
  padding-top: 0;
}

.sidebar-lang-section label {
  font-size: 0.82rem;
}

.sidebar-lang-section select {
  width: 100%;
  margin-top: 2px;
}

/* ── Theme toggle ─────────────────────────────────────────────────── */
.theme-toggle-row {
  display: flex;
  align-items: center;
  gap: 8px;
}
.theme-toggle-row label {
  font-size: .82rem;
  color: var(--text-dim);
}
.btn-theme-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border: var(--border-w) solid var(--border);
  border-radius: 6px;
  background: var(--bg-card);
  color: var(--text);
  font-size: .78rem;
  font-weight: 600;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: border-color .15s, background .15s;
  font-family: inherit;
}
.btn-theme-toggle:hover {
  border-color: var(--accent);
  background: var(--bg-card);
}
.btn-theme-toggle .theme-icon {
  font-size: 1rem;
  line-height: 1;
}
.btn-theme-toggle .theme-icon[data-icon]::before {
  font-size: 1.1rem;
  margin-right: 0;
}
#sidebar.collapsed .theme-toggle-row label { display: none; }
#sidebar.collapsed .btn-theme-toggle span:not(.theme-icon) { display: none; }
#sidebar.collapsed .btn-theme-toggle { padding: 4px 6px; }

/* ── Annotations (AI translator notes) ────────────────────────────────── */
mark.ann-highlight {
  background: var(--hl-ann-bg, rgba(67, 160, 71, 0.08));
  color: inherit;
  border-bottom: 2px dotted var(--hl-ann, #43A047);
  cursor: pointer;
  padding: 0 2px;
  border-radius: 2px;
  transition: background 0.15s;
}
mark.ann-highlight:hover {
  background: var(--hl-ann-bg-hover, rgba(67, 160, 71, 0.16));
}

/* ── Annotation tooltip (single note at bottom of reader) ────────────── */
.reader-ann-tooltip {
  position: sticky;
  bottom: 0;
  left: 0; right: 0;
  z-index: 20;
  background: var(--bg-card);
  color: var(--text);
  border-top: 2px solid var(--primary);
  box-shadow: 0 -4px 16px rgba(0,0,0,0.25);
  padding: 12px 16px;
  animation: ann-tooltip-slide-up 0.2s ease;
}
@keyframes ann-tooltip-slide-up {
  from { transform: translateY(100%); opacity: 0; }
  to   { transform: translateY(0);    opacity: 1; }
}
.ann-tooltip-close {
  position: absolute;
  top: 8px; right: 8px;
  font-size: 1rem;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  color: var(--text-dim);
  background: var(--bg-input);
  border: 1px solid var(--border);
}
.ann-tooltip-close:hover { background: var(--bg-dim); color: var(--text); }
.ann-tooltip-body { padding-right: 24px; }
.ann-tooltip-src, .ann-tooltip-tgt { margin: 2px 0; font-size: 0.9rem; color: var(--text); }
.ann-tooltip-src { color: var(--text-dim); font-style: italic; }
.ann-label { font-weight: 600; color: var(--primary); }
.ann-tooltip-note { margin: 6px 0 0; line-height: 1.6; font-size: 0.95rem; color: var(--text); }

/* ── Annotations modal (all notes for chapter) ──────────────────────── */
.annotations-modal {
  max-width: 800px;
  width: 90vw;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
}
.annotations-modal-list {
  overflow-y: auto;
  flex: 1;
  padding: 0 4px;
}
.annotations-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}
.annotations-table th {
  text-align: left;
  padding: 6px 8px;
  background: var(--bg);
  border-bottom: 2px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 1;
}
.annotations-table td {
  padding: 6px 8px;
  border-bottom: var(--border-w) solid var(--border);
  vertical-align: top;
}
.annotations-table td:first-child { width: 30px; text-align: center; color: var(--text-dim); }
.ann-src { color: var(--text-dim); font-style: italic; max-width: 180px; }
.ann-tgt { max-width: 180px; }
.ann-note { line-height: 1.5; }

/* ── Download panel modal ──────────────────────────────────────────── */
.download-panel-modal {
  max-width: 520px;
  width: 95vw;
}
.download-panel-body {
  padding: 0 4px;
}
.dl-section {
  margin: 12px 0;
}
.dl-section h4 {
  margin: 0 0 8px;
  font-size: 15px;
  font-weight: 600;
}
.dl-option-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 6px 0;
  font-size: 14px;
}
.dl-option-row label {
  display: flex;
  align-items: center;
  gap: 5px;
  cursor: pointer;
}
.dl-option-row select {
  font-size: 13px;
  padding: 3px 8px;
  border-radius: 6px;
  border: var(--border-w) solid var(--border);
  background: var(--bg);
  color: var(--text);
}
.dl-btn-group {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
}
.dl-divider {
  border: none;
  border-top: var(--border-w) solid var(--border);
  margin: 14px 0;
}
.btn-danger {
  background: #493131;
  color: #fff;
  border: none;
}
.btn-danger:hover { background: #312520; }

/* ── User highlights & notes ───────────────────────────────────────── */
/* User highlight/note tooltip */
.reader-hl-tooltip {
  position: sticky;
  bottom: 0;
  z-index: 150;
  background: var(--bg-card);
  color: var(--text);
  border-top: var(--border-w) solid var(--border);
  padding: 10px 40px 10px 14px;
  box-shadow: 0 -4px 16px rgba(0,0,0,0.15);
  animation: slideUpTip 0.2s ease;
  font-size: 14px;
  line-height: 1.6;
}
.hl-tooltip-body {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.hl-tooltip-body .hl-note-label {
  font-weight: 600;
  color: var(--text-dim);
  font-size: 12px;
  text-transform: uppercase;
}
.hl-tooltip-body .hl-note-text {
  margin: 0;
}
.hl-tooltip-body .hl-imported-badge {
  display: inline-block;
  font-size: 11px;
  background: rgba(115, 151, 171, 0.15);
  color: var(--primary);
  padding: 1px 6px;
  border-radius: 8px;
  margin-bottom: 4px;
}

/* User highlight = fluorescent yellow solid underline */
mark.user-highlight {
  background: transparent;
  color: inherit;
  border-bottom: 2.5px solid var(--hl-mark, #F9A825);
  border-radius: 0;
  padding: 0;
  cursor: pointer;
}
/* User note = fluorescent purple background highlight */
mark.user-highlight.has-note {
  background: var(--hl-note-bg, rgba(156, 39, 176, 0.10));
  color: inherit;
  border-bottom: 2.5px solid var(--hl-note-border, #AB47BC);
  cursor: pointer;
}

.reader-highlight-bar {
  position: absolute;
  z-index: 200;
  display: flex;
  gap: 4px;
  background: var(--bg-card);
  border: var(--border-w) solid var(--border);
  border-radius: var(--radius);
  padding: 10px 8px;
  box-shadow: var(--shadow-sm);
}
.btn-highlight-action {
  font-size: 13px;
  padding: 5px 12px;
  background: var(--bg-card);
  border: 1px solid var(--text-muted);
  cursor: pointer;
  border-radius: 6px;
  display: flex;
  align-items: center;
  gap: 4px;
  color: var(--text);
  white-space: nowrap;
  transition: background .1s, border-color .1s;
}
.btn-highlight-action[data-icon]::before { margin-right: 0; font-size: 1rem; }
.btn-highlight-action:hover { background: var(--pop); border-color: var(--border); }

.reader-note-popup {
  position: fixed;
  bottom: 120px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 210;
  background: var(--bg-card);
  color: var(--text);
  border: var(--border-w) solid var(--border);
  border-radius: 8px;
  padding: 12px 16px;
  width: 380px;
  max-width: 92vw;
  box-shadow: 0 8px 32px rgba(0,0,0,0.24);
}
.reader-note-popup textarea {
  width: 100%;
  resize: vertical;
  min-height: 60px;
  font-size: 14px;
  background: var(--bg);
  color: var(--text);
  border: var(--border-w) solid var(--border);
  border-radius: 6px;
  padding: 8px;
}
.note-popup-actions {
  display: flex;
  gap: 8px;
  margin-top: 8px;
  justify-content: flex-end;
}

.import-divider {
  display: flex;
  align-items: center;
  margin: 12px 0;
  color: var(--text-dim);
  font-size: 13px;
}
.import-divider::before, .import-divider::after {
  content: '';
  flex: 1;
  border-bottom: var(--border-w) solid var(--border);
}
.import-divider span { padding: 0 10px; }

.hidden { display: none !important; }

/* ── Mobile Top Bar ─────────────────────────────────────────────────── */
#mobile-topbar {
  display: none;
}

.mobile-topbar-left {
  display: flex;
  align-items: center;
  gap: 8px;
}
.mobile-logo {
  font-size: .88rem;
  font-weight: 900;
  letter-spacing: -0.02em;
  color: var(--text);
  text-decoration: none;
  cursor: pointer;
}
.mobile-topbar-right {
  display: flex;
  align-items: center;
  gap: 2px;
}
.mobile-topbar-btn {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  color: var(--text);
  background: none;
  border: none;
  cursor: pointer;
}
.mobile-topbar-btn:hover { background: var(--bg-input); }
.mobile-topbar-btn[data-icon]::before { font-size: 1.15rem; margin-right: 0; }
#btn-mobile-login {
  border: 1.5px solid var(--accent);
  border-radius: 50%;
  color: var(--accent);
}

/* ── Mobile Drawers ─────────────────────────────────────────────────── */
.mobile-drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: 300px;
  max-width: 85vw;
  background: var(--bg-card);
  z-index: 2000;
  display: none;
  flex-direction: column;
  box-shadow: -4px 0 24px rgba(0,0,0,.2);
  overflow-y: auto;
}
.mobile-drawer.drawer-open {
  display: flex !important;
}
.mobile-drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 16px 12px;
  border-bottom: var(--border-w) solid var(--border);
}
.mobile-drawer-header h3 {
  margin: 0;
  font-size: 1rem;
  font-weight: 700;
}
.mobile-drawer-body {
  padding: 12px 16px;
  flex: 1;
  overflow-y: auto;
}
.mobile-drawer-body label {
  display: block;
  font-size: .82rem;
  color: var(--text-dim);
  margin-bottom: .45rem;
}
.mobile-drawer-body select,
.mobile-drawer-body input {
  display: block;
  width: 100%;
  padding: .4rem .55rem;
  background: var(--bg-input);
  border: var(--border-w) solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: .82rem;
  margin-top: .15rem;
}
.mobile-drawer-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.3);
  z-index: 1999;
}

/* ── Responsive ─────────────────────────────────────────────────────── */
@media (max-width: 860px) {
  /* Show mobile top bar, hide desktop sidebar */
  #mobile-topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 4px 10px;
    background: var(--bg-card);
    border-bottom: var(--border-w) solid var(--border);
    position: sticky;
    top: 0;
    z-index: 100;
    flex-shrink: 0;
    min-height: 0;
  }
  #sidebar {
    display: none !important;
  }
  #app {
    flex-direction: column;
  }
  #main {
    padding: 0 1rem;
  }
  #panel-upload.active {
    padding-top: 1rem;
  }

  /* Steps bar: horizontal scroll instead of wrapping */
  #steps-bar {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    padding: .5rem 0 .4rem;
    gap: .35rem;
    scroll-snap-type: x mandatory;
    mask-image: linear-gradient(to right, transparent 0, black 8px, black calc(100% - 24px), transparent 100%);
    -webkit-mask-image: linear-gradient(to right, transparent 0, black 8px, black calc(100% - 24px), transparent 100%);
  }
  #steps-bar .step {
    flex-shrink: 0;
    scroll-snap-align: start;
    font-size: .72rem;
    padding: .3rem .6rem;
  }
  #steps-bar .step-num {
    width: 1.1rem;
    height: 1.1rem;
    font-size: .62rem;
  }

  /* Comparison grids go single column */
  .comparison { grid-template-columns: 1fr; }
  .comparison .text-display { max-height: 45vh; }
  .sample-actions { grid-template-columns: 1fr; }
  .reader-book-view { grid-template-columns: 1fr; }

  /* Upload area smaller padding */
  .upload-area {
    padding: 2rem 1.5rem;
    max-width: 100%;
  }
  .panel-center { min-height: 40vh; }
  .upload-options { flex-direction: column; gap: .5rem; }

  /* Project action buttons always visible on mobile (no hover) */
  .btn-project-action { opacity: 1; }

  /* Cards */
  .card-grid { grid-template-columns: 1fr; gap: .8rem; }
  .card { padding: 1rem 1.1rem; }

  /* Panels general */
  .panel { gap: 1rem; padding-bottom: 60px; }
  .panel h2 { font-size: 1.15rem; }

  /* Lang editor */
  .lang-editor { padding: .75rem 1rem; gap: .8rem; }
  .lang-editor input { width: 120px; }

  /* Strategy fields */
  .strategy-field textarea { font-size: .82rem; }
  .editable-table { font-size: .78rem; }
  .editable-table th, .editable-table td { padding: .3rem .4rem; }

  /* Review footer — keep compact */
  .review-footer {
    gap: 8px;
    padding: .5rem 0;
  }
  /* Continue-translate row: keep everything on one line */
  .review-translate-more {
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
    font-size: .78rem;
  }
  .review-translate-more .range-input { width: 42px; }
  .review-translate-more [data-icon]::before { display: none; }

  /* Done actions */
  .done-actions { flex-direction: column; gap: .5rem; }
  .done-actions .btn { width: 100%; text-align: center; }

  /* Chapter range picker */
  .chapter-range-picker { flex-direction: column; align-items: flex-start; gap: 6px; }

  /* Modals */
  .modal-content { padding: 18px 14px; width: 95%; }

  /* Template & version sections */
  .template-save-row { flex-direction: column; }
  .template-input { min-width: 0; }

  /* Feedback section */
  .feedback-section { padding: 12px 14px; }

  /* Tables overflow */
  .editable-table { display: block; overflow-x: auto; }

  /* Sample chapter picker */
  .sample-chapter-picker {
    flex-direction: column;
    align-items: flex-start;
    gap: 6px;
    padding: 10px 12px;
  }

  /* Progress text */
  #progress-text { font-size: .82rem; }

  /* Button sizing */
  .btn { font-size: .82rem; padding: .45rem .9rem; }
  .btn-lg { padding: .55rem 1.5rem; font-size: .9rem; }

  /* Reader panel adjustments (non-immersive) */
  #panel-reader { height: calc(100vh - 44px); }
  .reader-toolbar { padding: 6px 0; gap: 3px; }
  .reader-toolbar-row2 { flex-wrap: wrap; gap: 4px; }
  .reader-toolbar-row2-right { flex-wrap: wrap; gap: 4px; }
  .reader-toggle { font-size: .78rem; gap: 4px; }
  .reader-book-content { padding: 14px 16px; }
  .btn-immersive { font-size: .75rem; padding: .3rem .6rem; }

  /* Reader QA panel */
  .reader-qa { max-height: 30vh; }
  .reader-qa-header { padding: 8px 12px 3px; }
  .reader-qa-input { padding: 6px 12px 8px; }

  /* Title editor */
  .te-titles { flex-direction: column; gap: 4px; }

  /* Review chapter items */
  .review-chapter-item { padding: 8px 12px; }
  .review-chapter-item .ch-status { font-size: .75rem; padding: 2px 8px; }

  /* Hide unnecessary text in compact buttons on small widths */
  .review-title-actions .hint { display: none; }
}

/* ── Version History ──────────────────────────────────────────────── */
.versions-modal { max-width: 750px; max-height: 80vh; overflow-y: auto; }
.retranslate-modal { max-width: 600px; }
.retranslate-modal textarea { width: 100%; margin: .5rem 0; }
.retranslate-modal .btn-row { justify-content: flex-end; gap: .5rem; margin-top: .5rem; }

.versions-list { display: flex; flex-direction: column; gap: .5rem; margin: .75rem 0; }
.version-row {
  display: flex; justify-content: space-between; align-items: flex-start;
  padding: .6rem .75rem; border-radius: 8px;
  background: var(--bg-input); border: var(--border-w) solid var(--border);
}
.version-row.active { border-color: var(--primary); background: rgba(var(--primary-rgb), .08); }
.ver-info { flex: 1; min-width: 0; }
.ver-label { font-weight: 600; font-size: .95rem; }
.ver-badge {
  display: inline-block; font-size: .7rem; font-weight: 700;
  padding: 1px 6px; border-radius: 4px; margin-left: .3rem;
  background: var(--pop); color: var(--text); border: 1px solid var(--border); vertical-align: middle;
}
.ver-meta { display: block; font-size: .78rem; color: var(--text-dim); margin-top: 2px; }
.ver-feedback {
  font-size: .8rem; color: var(--text-dim); margin-top: 4px;
  border-left: 3px solid var(--border); padding-left: .5rem;
  white-space: pre-wrap; max-height: 3rem; overflow: hidden;
}
.ver-actions { display: flex; gap: .4rem; align-items: center; flex-shrink: 0; margin-left: .5rem; }

.version-compare { margin-top: 1rem; border-top: var(--border-w) solid var(--border); padding-top: .75rem; }
.version-text { max-height: 300px; overflow-y: auto; font-size: .88rem; white-space: pre-wrap; }

/* ── Strategy Version & Template Sections ─────────────────────────── */
.strategy-version-section,
.strategy-template-section {
  margin-top: 2rem; padding-top: 1.25rem; border-top: 2px solid var(--border);
}
.section-header-row { display: flex; align-items: center; gap: .75rem; }
.current-ver-badge {
  font-size: .75rem; font-weight: 700; padding: 2px 8px; border-radius: 4px;
  background: var(--pop-yellow); color: var(--text); border: 1px solid var(--border);
}

.template-save-row { display: flex; gap: .5rem; margin: .5rem 0; flex-wrap: wrap; }
.template-input { flex: 1; min-width: 150px; padding: .4rem .6rem; border: var(--border-w) solid var(--border); border-radius: 6px; background: var(--bg-input); color: var(--text); }

/* ── Template picker button row (analysis page) ─────────────────── */
.template-picker-row {
  display: flex; align-items: center; gap: .75rem;
  margin: 1.5rem 0 1rem;
}
.picked-tpl-label { font-size: .85rem; color: var(--accent); font-weight: 600; }

/* ── Template selection modal ────────────────────────────────────── */
.template-modal { max-width: 600px; }
.tpl-modal-select-row {
  display: flex; align-items: center; gap: .5rem; margin: .75rem 0;
}
.tpl-modal-select-row label { font-weight: 600; white-space: nowrap; flex-shrink: 0; }
.tpl-modal-select-row select {
  flex: 1; padding: .4rem .6rem; border-radius: 6px;
  border: var(--border-w) solid var(--border); background: var(--bg); color: var(--text); font-size: .9rem;
}
.tpl-modal-detail {
  max-height: 320px; overflow-y: auto;
  padding: .75rem; border-radius: 8px;
  background: var(--bg); border: var(--border-w) solid var(--border);
  font-size: .85rem; min-height: 60px;
}
.tpl-modal-detail .tpl-detail-field { margin-bottom: .5rem; }
.tpl-modal-detail .tpl-detail-field strong { display: block; font-size: .8rem; color: var(--text-dim); margin-bottom: 2px; }
.tpl-modal-detail .tpl-detail-field p { margin: 0; white-space: pre-wrap; }
.tpl-modal-detail .tpl-detail-meta {
  font-size: .8rem; color: var(--text-dim); margin-bottom: .5rem;
  padding-bottom: .4rem; border-bottom: var(--border-w) solid var(--border);
}
.tpl-modal-detail .mini-table { width: 100%; font-size: .82rem; border-collapse: collapse; }
.tpl-modal-detail .mini-table th,
.tpl-modal-detail .mini-table td { padding: 2px 6px; border: var(--border-w) solid var(--border); text-align: left; }

/* ── Retranslate options ─────────────────────────────────────────── */
.retranslate-options { display: flex; flex-direction: column; gap: .3rem; margin: .5rem 0; }
.retranslate-options .checkbox-row { margin: 0; }

/* ── Clickable version row ───────────────────────────────────────── */
.version-row.clickable { cursor: pointer; transition: border-color .15s, background .15s; }
.version-row.clickable:hover { border-color: var(--primary); background: rgba(var(--primary-rgb), .05); }

/* ── Strategy Version Preview ────────────────────────────────────── */
.strategy-version-preview {
  margin-top: .75rem; padding: .75rem 1rem; border-radius: 8px;
  background: var(--bg-card); border: 1px solid var(--primary);
  box-shadow: 0 2px 12px rgba(0,0,0,.12);
}
.strategy-version-preview .preview-header {
  display: flex; justify-content: space-between; align-items: center; margin-bottom: .5rem;
}
.strategy-version-preview .preview-header h4 { margin: 0; font-size: .95rem; }
.strategy-version-preview .preview-fields { max-height: 400px; overflow-y: auto; }
.preview-field { margin-bottom: .6rem; }
.preview-field strong { display: block; font-size: .82rem; color: var(--text-dim); margin-bottom: 2px; }
.preview-field p { margin: 0; font-size: .88rem; white-space: pre-wrap; line-height: 1.45; }
.mini-table { width: 100%; font-size: .82rem; border-collapse: collapse; margin-top: 4px; }
.mini-table th, .mini-table td {
  padding: 3px 6px; border: var(--border-w) solid var(--border); text-align: left;
}
.mini-table th { background: var(--bg-input); font-weight: 600; }

/* ── Immersive Reading Mode ──────────────────────────────────────── */
.btn-immersive {
  flex-shrink: 0;
  background: var(--pop);
  color: var(--text);
  border-color: var(--border);
}
.btn-immersive:hover { transform: translate(-1px,-1px); box-shadow: 3px 3px 0 var(--border); }

.annotation-density-row {
  display: flex; align-items: center; gap: .5rem; margin: .4rem 0 .4rem 1.6rem;
}
.annotation-density-row.compact { margin-left: 0; }
.annotation-density-row select {
  padding: 3px 8px; border-radius: 6px; border: var(--border-w) solid var(--border);
  background: var(--bg-input); color: var(--text); font-size: .85rem;
}
.annotation-density-row .hint { font-size: .78rem; }

/* Floating action buttons (immersive only) */
.immersive-ai-fab,
.immersive-menu-fab {
  position: fixed;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: 1.3rem;
  border: none;
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(0,0,0,.3);
  z-index: 1100;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform .15s;
}
.immersive-ai-fab { bottom: 24px; right: 24px; }
.immersive-menu-fab { bottom: 24px; left: 24px; background: var(--bg-card); color: var(--text); border: var(--border-w) solid var(--border); }
.immersive-ai-fab:hover,
.immersive-menu-fab:hover { transform: scale(1.1); }

/* ── Common immersive rules ─────────────────────────────────────── */
body.immersive #sidebar,
body.immersive #steps-bar {
  display: none !important;
}

body.immersive #panel-reader {
  position: fixed !important;
  inset: 0;
  z-index: 999;
  padding: 0;
  overflow: hidden;
}

/* Immersive pagination: column-based paging, hidden scrollbar */
body.immersive .reader-book-content {
  overflow-x: scroll;
  overflow-y: hidden;
  scrollbar-width: none;
  column-fill: auto;
  box-sizing: border-box;
  padding: 36px 48px 64px;
}
@media (max-width: 767px) {
  body.immersive .reader-book-content {
    padding: 16px 18px 100px;
  }
}
body.immersive .reader-book-content::-webkit-scrollbar { display: none; }
body.immersive .reader-book-content::after {
  content: "";
  display: block;
  break-before: column;
  width: 1px;
  height: 1px;
}

/* Desktop: Hide the floating menu fab — toolbar at top is sufficient */
body.immersive .immersive-menu-fab { display: none !important; }
/* Mobile: always show menu fab in immersive */
@media (max-width: 767px) {
  body.immersive .immersive-menu-fab { display: flex !important; }
}

/* Page indicator & nav */
.immersive-page-nav {
  position: fixed;
  bottom: 14px;
  left: 50%;
  transform: translateX(-50%);
  display: none;
  align-items: center;
  gap: 12px;
  background: var(--bg-card);
  border: var(--border-w) solid var(--border);
  border-radius: var(--radius);
  padding: 5px 16px;
  font-size: .8rem;
  font-weight: 600;
  color: var(--text);
  z-index: 1001;
  user-select: none;
  box-shadow: var(--shadow-sm);
}
body.immersive .immersive-page-nav { display: flex; }
.immersive-page-nav button {
  background: none;
  border: none;
  color: var(--text);
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 6px;
  line-height: 1;
}
.immersive-page-nav button[data-icon]::before {
  font-size: 1.2rem;
  margin-right: 0;
}
.immersive-page-nav button:hover { background: var(--bg-input); }
.immersive-page-nav button:disabled { opacity: .3; cursor: default; }
.immersive-page-nav .page-indicator { font-variant-numeric: tabular-nums; }

/* ── Desktop immersive (≥768px): Photoshop-style icon sidebar ──── */
@media (min-width: 768px) {
  body.immersive .reader-toolbar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    width: 48px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0;
    padding: 6px 0;
    overflow-x: hidden;
    overflow-y: auto;
    border-bottom: none;
    border-right: var(--border-w) solid var(--border);
    background: var(--bg-card);
    z-index: 1001;
    flex-wrap: nowrap;
    flex-shrink: 0;
    transition: width .2s ease;
  }

  /* Expanded on hover — overlay, does not push content */
  body.immersive .reader-toolbar:hover {
    width: 220px;
    align-items: stretch;
    box-shadow: 4px 0 24px rgba(0,0,0,.25);
  }

  /* ── Icon-only buttons (collapsed) ── */
  body.immersive .reader-toolbar [data-icon] {
    width: 40px;
    height: 38px;
    padding: 0;
    margin: 3px 4px;
    border-radius: 8px;
    font-size: 0;         /* hide all text */
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    position: relative;
    overflow: hidden;
  }
  body.immersive .reader-toolbar [data-icon]::before {
    font-family: 'Material Symbols Outlined';
    content: attr(data-icon);
    font-size: 1.3rem;
    line-height: 1;
    margin-right: 0;
  }

  /* Checkbox toggles — icon mode */
  body.immersive .reader-toolbar .reader-toggle[data-icon] {
    width: 40px;
    height: 38px;
    padding: 0;
    margin: 3px 4px;
    border-radius: 8px;
    font-size: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    cursor: pointer;
    position: relative;
    background: var(--bg-input);
    border: var(--border-w) solid var(--border);
  }
  body.immersive .reader-toolbar .reader-toggle[data-icon]::before {
    font-family: 'Material Symbols Outlined';
    content: attr(data-icon);
    font-size: 1.3rem;
    line-height: 1;
    margin-right: 0;
  }
  body.immersive .reader-toolbar .reader-toggle[data-icon] input { position: absolute; opacity: 0; width: 100%; height: 100%; cursor: pointer; margin: 0; }
  body.immersive .reader-toolbar .reader-toggle[data-icon] span { display: none; }
  body.immersive .reader-toolbar .reader-toggle[data-icon]:has(input:checked) {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
  }

  /* ── Expanded state: show full text ── */
  body.immersive .reader-toolbar:hover [data-icon] {
    width: auto;
    height: auto;
    padding: 7px 12px;
    font-size: .85rem;
    justify-content: flex-start;
    gap: 8px;
  }
  body.immersive .reader-toolbar:hover [data-icon]::before {
    font-size: 1.1rem;
    flex-shrink: 0;
    margin-right: .35em;
  }

  body.immersive .reader-toolbar:hover .reader-toggle[data-icon] {
    width: auto;
    height: auto;
    padding: 7px 12px;
    font-size: .85rem;
    justify-content: flex-start;
    gap: 6px;
  }
  body.immersive .reader-toolbar:hover .reader-toggle[data-icon]::before {
    font-size: 1.1rem;
    flex-shrink: 0;
    margin-right: .2em;
  }
  body.immersive .reader-toolbar:hover .reader-toggle[data-icon] span { display: inline; }
  body.immersive .reader-toolbar:hover .reader-toggle[data-icon] input {
    position: static;
    opacity: 1;
    width: auto;
    height: auto;
  }

  /* Nav group */
  body.immersive .reader-nav {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0;
    padding: 0;
  }
  body.immersive .reader-nav-label { display: none; }
  body.immersive .reader-toolbar:hover .reader-nav-label {
    display: block;
    font-size: .7rem;
    text-align: center;
    padding: 3px 6px;
    line-height: 1.2;
    color: var(--text-dim);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
  }
  body.immersive .reader-toolbar:hover .reader-nav {
    align-items: stretch;
  }

  /* Flatten toolbar row wrappers in sidebar mode */
  body.immersive .reader-toolbar-row1,
  body.immersive .reader-toolbar-row2,
  body.immersive .reader-toolbar-row2-left,
  body.immersive .reader-toolbar-row2-right {
    display: contents;
  }

  /* Dropdown wraps (settings & more) */
  body.immersive .reader-settings-wrap,
  body.immersive .reader-more-wrap { width: 100%; display: flex; justify-content: center; }
  body.immersive .reader-toolbar:hover .reader-settings-wrap,
  body.immersive .reader-toolbar:hover .reader-more-wrap { justify-content: stretch; }
  body.immersive .reader-settings-dropdown,
  body.immersive .reader-more-dropdown {
    position: fixed;
    left: 56px;
    top: auto;
    bottom: 10px;
    right: auto;
    max-height: calc(100vh - 20px);
    overflow-y: auto;
  }
  body.immersive .reader-toolbar:hover .reader-settings-dropdown,
  body.immersive .reader-toolbar:hover .reader-more-dropdown {
    left: 228px;
  }

  /* Divider between groups */
  body.immersive .reader-toolbar .reader-nav::before {
    content: "";
    display: block;
    width: 32px;
    height: 1px;
    background: var(--border);
    margin: 4px auto;
  }
  body.immersive .reader-toolbar:hover .reader-nav::before {
    width: 90%;
  }

  /* ── Reading area — offset by sidebar ── */
  body.immersive .reader-book-view {
    position: fixed !important;
    left: 48px;
    top: 0;
    right: 0;
    bottom: 0;
    height: auto !important;
  }

  /* AI Q&A as floating panel */
  body.immersive .reader-qa {
    position: fixed;
    bottom: 80px;
    right: 24px;
    width: 400px;
    max-height: 500px;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    border: var(--border-w) solid var(--border);
    background: var(--bg-card);
    z-index: 1050;
    display: none;
    flex-direction: column;
    overflow: hidden;
  }
  body.immersive .reader-qa.qa-visible { display: flex; }
  body.immersive .reader-qa .reader-qa-messages { max-height: 320px; overflow-y: auto; }

  body.immersive #immersive-ai-fab { display: flex; }
  body.immersive #immersive-menu-fab { display: none; }
}

/* ── Immersive z-index: modals & tooltips above sidebar ─────────── */
body.immersive .modal-overlay {
  z-index: 1200;
}
body.immersive .reader-ann-tooltip,
body.immersive .reader-hl-tooltip {
  z-index: 1100;
}
body.immersive .reader-highlight-bar {
  z-index: 1100;
}
body.immersive .reader-note-popup {
  z-index: 1100;
}

/* ── Bookshelf reader: only hide the immersive toggle ────────────── */
body.bookshelf-reader #btn-reader-immersive {
  display: none !important;
}

/* ── Mobile immersive (< 768px) ─────────────────────────────────── */
@media (max-width: 767px) {
  /* Hide the immersive toggle on mobile — we auto-enter immersive */
  .btn-immersive { display: none !important; }

  /* Hide the original toolbar, use floating menu button */
  body.immersive .reader-toolbar {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    top: auto;
    z-index: 1100;
    background: var(--bg-card);
    border-top: var(--border-w) solid var(--border);
    border-bottom: none;
    padding: 10px 12px 14px;
    gap: 6px;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    transform: translateY(100%);
    transition: transform .3s ease;
    max-height: 55vh;
    overflow-y: auto;
  }
  body.immersive .reader-toolbar.toolbar-visible {
    transform: translateY(0);
  }

  /* When toolbar is open, hide overlapping elements (toggled via JS) */
  body.immersive .immersive-page-nav.toolbar-open,
  body.immersive .immersive-ai-fab.toolbar-open,
  body.immersive .immersive-menu-fab.toolbar-open {
    opacity: 0 !important;
    pointer-events: none !important;
    transition: opacity .2s;
  }

  /* Flatten row wrappers so children flow as column items */
  body.immersive .reader-toolbar-row1,
  body.immersive .reader-toolbar-row2,
  body.immersive .reader-toolbar-row2-left,
  body.immersive .reader-toolbar-row2-right {
    display: contents;
  }

  /* Exit button — full width, prominent at top */
  body.immersive #btn-reader-exit {
    width: 100%;
    text-align: center;
    margin-bottom: 4px;
    order: -2;
  }

  /* Chapter label */
  body.immersive .reader-nav-label {
    font-size: .75rem;
    text-align: center;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    order: -1;
    margin-bottom: 4px;
    color: var(--text-dim);
  }

  /* Nav row: prev / next */
  body.immersive .reader-nav {
    display: flex;
    flex-direction: row;
    width: 100%;
    justify-content: center;
    gap: 6px;
    padding-bottom: 6px;
    border-bottom: var(--border-w) solid var(--border);
    margin-bottom: 6px;
  }

  /* General buttons in toolbar */
  body.immersive .reader-toolbar button,
  body.immersive .reader-toolbar .reader-toggle {
    flex: 0 0 auto;
    padding: 8px 12px;
    font-size: .82rem;
    white-space: nowrap;
    border-radius: 8px;
  }

  /* Toggle labels — show as full-width rows */
  body.immersive .reader-toolbar .reader-toggle {
    width: 100%;
    justify-content: flex-start;
    gap: 8px;
    padding: 8px 12px;
    background: var(--bg-input);
    border: var(--border-w) solid var(--border);
  }
  body.immersive .reader-toolbar .reader-toggle span { display: inline; }
  body.immersive .reader-toolbar .reader-toggle input {
    position: static;
    opacity: 1;
    width: auto;
    height: auto;
  }

  /* More & settings wraps: flatten into the toolbar flow */
  body.immersive .reader-more-wrap,
  body.immersive .reader-settings-wrap {
    display: contents;
  }

  /* Hide the trigger buttons (we show the items inline instead) */
  body.immersive #btn-reader-more,
  body.immersive #btn-reader-settings { display: none; }

  /* Show dropdown items inline as stacked buttons */
  body.immersive .reader-more-dropdown,
  body.immersive .reader-settings-dropdown {
    position: static !important;
    display: flex !important;
    flex-direction: column;
    background: none;
    border: none;
    box-shadow: none;
    padding: 0;
    min-width: 0;
    gap: 4px;
    width: 100%;
  }
  body.immersive .reader-more-dropdown.hidden,
  body.immersive .reader-settings-dropdown.hidden {
    display: flex !important;
  }

  /* Separator before more section */
  body.immersive .reader-more-dropdown {
    padding-top: 6px !important;
    border-top: var(--border-w) solid var(--border);
    margin-top: 2px;
  }

  /* More items: full width rows */
  body.immersive .reader-more-item {
    width: 100%;
    text-align: left;
    justify-content: flex-start;
    padding: 8px 12px;
    border: var(--border-w) solid var(--border) !important;
    box-shadow: none !important;
    background: var(--bg-input);
    border-radius: 8px;
    font-size: .82rem;
  }

  /* Settings groups: compact inline */
  body.immersive .rset-group {
    margin-bottom: 6px;
    padding: 6px 10px;
    background: var(--bg-input);
    border: var(--border-w) solid var(--border);
    border-radius: 8px;
  }
  body.immersive .rset-group > label {
    font-size: .72rem;
    margin-bottom: 4px;
  }

  /* Reading area fills screen */
  body.immersive .reader-book-view {
    position: fixed !important;
    inset: 0;
    height: auto !important;
  }

  /* Also hide top bar in immersive */
  body.immersive #mobile-topbar { display: none !important; }

  /* AI Q&A as bottom sheet */
  body.immersive .reader-qa { display: none; }
  body.immersive .reader-qa.qa-visible {
    display: flex;
    position: fixed;
    bottom: 0; left: 0; right: 0;
    max-height: 50vh;
    z-index: 1150;
    border-radius: 12px 12px 0 0;
    box-shadow: 0 -4px 20px rgba(0,0,0,.3);
    background: var(--bg-card);
    flex-direction: column;
  }

  /* FABs — near bottom edge, below content */
  body.immersive #immersive-ai-fab {
    display: flex;
    bottom: 12px;
    right: 16px;
    width: 42px; height: 42px; font-size: 1.1rem;
  }
  body.immersive #immersive-menu-fab {
    display: flex;
    bottom: 12px;
    left: 16px;
    width: 42px; height: 42px; font-size: 1.2rem;
  }

  /* Page nav at very bottom on mobile */
  body.immersive .immersive-page-nav {
    bottom: 10px;
    z-index: 1050;
  }
}

/* ── Offline mode (sidebar indicator) ─────────────────────────────── */
.offline-icon {
  filter: grayscale(1);
}
.offline-badge {
  display: inline-block;
  font-size: .55rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  background: var(--border);
  color: var(--text-dim);
  padding: 1px 5px;
  border-radius: 4px;
  margin-left: 6px;
  vertical-align: middle;
}
#sidebar.collapsed .offline-badge { display: none; }

/* ── Documentation modal ─────────────────────────────────────────── */
.docs-modal {
  max-width: 680px;
  width: 92%;
  max-height: 85vh;
  overflow-y: auto;
  padding: 28px 32px;
}

.docs-intro {
  font-size: .92rem;
  line-height: 1.7;
  color: var(--text-dim);
  margin-bottom: 1.2rem;
}

.docs-section {
  margin-bottom: 1rem;
  padding: .75rem 1rem;
  border-radius: var(--radius);
  background: var(--bg);
  border: var(--border-w) solid transparent;
}
.docs-section h4 {
  font-size: .95rem;
  margin-bottom: .4rem;
  display: flex;
  align-items: center;
  gap: .4rem;
}
.docs-section h4::before {
  font-family: 'Material Symbols Outlined';
  content: attr(data-icon);
  font-size: 1.15rem;
  color: var(--accent);
}
.docs-section p {
  font-size: .88rem;
  line-height: 1.65;
  color: var(--text);
  margin: 0;
}
.docs-section.docs-highlight {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 6%, var(--bg));
}

.docs-steps {
  margin-top: .5rem;
  font-size: .82rem;
  color: var(--accent);
  font-weight: 600;
  padding: .35rem .6rem;
  background: color-mix(in srgb, var(--accent) 8%, var(--bg-card));
  border-radius: 6px;
  display: inline-block;
}

.docs-tip {
  margin-top: 1rem;
  padding: .65rem 1rem;
  border-radius: var(--radius);
  background: var(--pop-yellow);
  font-size: .85rem;
  line-height: 1.55;
  display: flex;
  gap: .5rem;
  align-items: baseline;
}
.docs-tip strong {
  white-space: nowrap;
  flex-shrink: 0;
}

@media (max-width: 860px) {
  .docs-modal,
  .legal-modal {
    width: 100%;
    max-width: 100%;
    max-height: 92vh;
    padding: 20px 16px;
    border-radius: 12px 12px 0 0;
    margin-top: auto;
  }
}

/* ── Sidebar footer ──────────────────────────────────────────────── */
.sidebar-footer {
  margin-top: auto;
  padding-top: .8rem;
  border-top: 1px solid color-mix(in srgb, var(--border) 30%, transparent);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: .2rem;
  font-size: .7rem;
}
.sidebar-footer a {
  color: var(--text-dim);
  text-decoration: none;
  cursor: pointer;
}
.sidebar-footer a:hover { color: var(--accent); text-decoration: underline; }
.sidebar-footer-copy {
  color: var(--text-muted);
  font-size: .65rem;
}
#sidebar.collapsed .sidebar-footer a { font-size: 0; }
#sidebar.collapsed .sidebar-footer a::before {
  font-family: 'Material Symbols Outlined';
  content: "gavel";
  font-size: .95rem;
  color: var(--text-dim);
}
#sidebar.collapsed .sidebar-footer-copy { display: none; }

/* ── Legal / Policy modal ────────────────────────────────────────── */
.legal-modal {
  max-width: 660px;
  width: 92%;
  max-height: 85vh;
  overflow-y: auto;
  padding: 28px 32px;
}

.legal-section {
  margin-bottom: 1rem;
}
.legal-section h4 {
  font-size: .9rem;
  font-weight: 700;
  margin-bottom: .35rem;
  color: var(--text);
}
.legal-section p {
  font-size: .84rem;
  line-height: 1.7;
  color: var(--text-dim);
  margin: 0 0 .4rem;
}

.legal-footer {
  margin-top: 1.2rem;
  padding-top: .8rem;
  border-top: 1px solid var(--border);
  text-align: center;
}
.legal-footer p {
  font-size: .78rem;
  color: var(--text-muted);
  margin: .15rem 0;
  line-height: 1.5;
}

/* ── Legal Developed by ──────────────────────────────────────────── */
.legal-developed-by {
  margin-top: 1.2rem;
  padding-top: .8rem;
  border-top: 1px solid var(--border);
  text-align: center;
}
.legal-developed-by > span {
  font-size: .82rem;
  color: var(--text-dim);
}
.dev-name {
  font-weight: 700;
  margin-left: .3rem;
}
.dev-links {
  display: flex;
  gap: 1.2rem;
  justify-content: center;
  margin-top: .5rem;
}
.dev-links a {
  font-size: .82rem;
  color: var(--accent);
  text-decoration: none;
  display: flex;
  align-items: center;
  gap: .3rem;
}
.dev-links a:hover { text-decoration: underline; }

/* ── Login modal ─────────────────────────────────────────────────── */
.login-modal {
  max-width: 420px;
  width: 92%;
  padding: 28px 32px;
}
.login-form, .login-account {
  display: flex;
  flex-direction: column;
  gap: .75rem;
}
.btn-google-sign-in {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: .5rem;
  padding: .6rem 1rem;
  font-size: .9rem;
}
.login-divider {
  display: flex;
  align-items: center;
  gap: .8rem;
  color: var(--text-muted);
  font-size: .8rem;
}
.login-divider::before, .login-divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--border);
}
.login-form input[type="email"],
.login-form input[type="password"] {
  padding: .55rem .75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: .88rem;
  background: var(--surface);
  color: var(--text);
}
.login-error {
  color: #e74c3c;
  font-size: .8rem;
  margin: 0;
}
.login-toggle-text {
  font-size: .82rem;
  color: var(--text-dim);
  text-align: center;
}
.login-toggle-text a {
  color: var(--accent);
  font-weight: 600;
  cursor: pointer;
}
.account-info {
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: .5rem 0;
}
.account-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  font-weight: 700;
  flex-shrink: 0;
}
.account-email {
  font-size: .88rem;
  color: var(--text);
  word-break: break-all;
}
.cloud-projects-section {
  margin-top: .5rem;
}
.cloud-projects-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: .5rem;
}
.cloud-projects-header h4 { margin: 0; font-size: .9rem; }
.cloud-count {
  font-size: .78rem;
  color: var(--text-muted);
  background: var(--surface);
  padding: .15rem .5rem;
  border-radius: 10px;
}
.cloud-project-list {
  display: flex;
  flex-direction: column;
  gap: .4rem;
  max-height: 240px;
  overflow-y: auto;
  margin-bottom: .5rem;
}
.cloud-project-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: .5rem .6rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: .82rem;
  cursor: pointer;
  transition: background .15s;
}
.cloud-project-item:hover { background: var(--hover); }
.cloud-project-item .cp-name { font-weight: 600; flex: 1; }
.cloud-project-item .cp-meta {
  font-size: .72rem;
  color: var(--text-muted);
  margin-left: .5rem;
}
.cloud-project-item .btn-delete-cloud {
  margin-left: .5rem;
  padding: .15rem .3rem;
  font-size: .7rem;
}
.sidebar-login-btn {
  width: 100%;
  border: 2px solid var(--accent);
  color: var(--accent);
  font-weight: 700;
  background: transparent;
  transition: background .15s, color .15s;
}
.sidebar-login-btn:hover {
  background: var(--accent);
  color: #fff;
}
#sidebar.collapsed .sidebar-login-btn {
  font-size: 0;
  padding: .4rem;
  min-width: 0;
  border-width: 2px;
}
#sidebar.collapsed .sidebar-login-btn::before {
  font-family: 'Material Symbols Outlined';
  content: "person";
  font-size: 1.1rem;
}

/* ── Bookshelf panel ─────────────────────────────────────────────── */
.bookshelf-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: .75rem;
  margin-top: .5rem;
}
@media (max-width: 767px) {
  .bookshelf-grid { grid-template-columns: 1fr; }
}
.bookshelf-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: .8rem 1rem;
  cursor: pointer;
  transition: box-shadow .15s, border-color .15s;
  background: var(--surface);
}
.bookshelf-card:hover {
  border-color: var(--accent);
  box-shadow: 0 2px 8px rgba(0,0,0,.08);
}
.bookshelf-card-title {
  font-weight: 700;
  font-size: .9rem;
  margin-bottom: .3rem;
  display: flex;
  align-items: center;
  gap: 6px;
}
.bookshelf-sync-badge {
  flex-shrink: 0;
  font-size: .72rem;
  color: var(--text-dim);
}
.bookshelf-sync-badge::before {
  font-family: 'Material Symbols Outlined';
  content: attr(data-icon);
  font-size: .95rem;
  vertical-align: middle;
}
.bookshelf-card.needs-download {
  opacity: 0.65;
  border-style: dashed;
}
.bookshelf-card.needs-download:hover { opacity: 0.85; }
.download-hint {
  color: var(--accent);
  font-weight: 600;
  font-size: .72rem;
}
.bookshelf-card-meta {
  font-size: .76rem;
  color: var(--text-dim);
  display: flex;
  flex-direction: column;
  gap: .15rem;
}
.bookshelf-progress-bar {
  height: 4px;
  border-radius: 2px;
  background: var(--border);
  margin-top: .4rem;
  overflow: hidden;
}
.bookshelf-progress-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 2px;
  transition: width .3s;
}

/* ── Toast notification ─────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--accent);
  color: #fff;
  padding: .6rem 1.2rem;
  border-radius: var(--radius);
  font-size: .84rem;
  z-index: 9999;
  opacity: 0;
  transition: opacity .3s, transform .3s;
  pointer-events: none;
  max-width: 90vw;
  text-align: center;
  box-shadow: 0 4px 16px rgba(0,0,0,.2);
}
.toast.visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
  pointer-events: auto;
}

/* ── Cloud sync badge on project items ──────────────────────────── */
.project-cloud-badge {
  font-size: .65rem;
  padding: 1px 5px;
  border-radius: 4px;
  margin-left: 6px;
  vertical-align: middle;
  font-weight: 600;
}
.project-cloud-badge.synced {
  background: rgba(var(--primary-rgb), .1);
  color: var(--accent);
}
.project-cloud-badge.local-only {
  background: rgba(0,0,0,.05);
  color: var(--text-muted);
}

.project-name-edit {
  width: 100%;
  max-width: 200px;
  padding: 2px 6px;
  font-size: .9rem;
  border: 2px solid var(--accent);
  border-radius: 4px;
  background: var(--bg-card);
  color: var(--text);
}
