/* ═══════════════════════════════════════════════
   LeLab — Design System
   Clean SaaS · Warm Orange Accent
═══════════════════════════════════════════════ */

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

:root {
  --bg:         #F7F6F3;
  --bg-card:    #FFFFFF;
  --surface:    #F0EEE9;
  --accent:     #FF5500;
  --accent-lt:  rgba(255,85,0,0.09);
  --accent-h:   #E54A00;
  --text:       #111111;
  --text-2:     #555555;
  --text-3:     #999999;
  --border:     #E4E2DC;
  --border-h:   #D0CECC;
  --success:    #16A34A;
  --success-bg: rgba(22,163,74,0.07);
  --error:      #DC2626;
  --error-bg:   rgba(220,38,38,0.07);
  --radius:     14px;
  --radius-sm:  8px;
  --radius-lg:  20px;
  --radius-xl:  28px;
  --sidebar-w:  268px;
  --topbar-h:   58px;
  --font:       'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --shadow-sm:  0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
  --shadow:     0 4px 14px rgba(0,0,0,0.07), 0 1px 4px rgba(0,0,0,0.04);
  --shadow-md:  0 8px 28px rgba(0,0,0,0.10), 0 2px 8px rgba(0,0,0,0.05);
  --shadow-lg:  0 20px 60px rgba(0,0,0,0.13), 0 4px 16px rgba(0,0,0,0.07);
  --tr:         0.17s ease;
}

html { font-size: 16px; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
  display: flex;
  -webkit-font-smoothing: antialiased;
}

/* ─── Utilities ─────────────────────────────── */
button { cursor: pointer; border: none; background: none; font-family: inherit; }
input, textarea, select { font-family: inherit; }
.hidden { display: none !important; }

@keyframes fadeUp   { from { opacity:0; transform:translateY(10px) } to { opacity:1; transform:none } }
@keyframes fadeIn   { from { opacity:0 } to { opacity:1 } }
@keyframes spin     { to { transform: rotate(360deg) } }
@keyframes pulse    { 0%,100%{opacity:1} 50%{opacity:.45} }
@keyframes slideIn  { from { opacity:0; transform:translateY(6px) } to { opacity:1; transform:none } }

.spin  { animation: spin 0.9s linear infinite; }
.spin-lg { animation: spin 1.1s linear infinite; }

/* ═══════════════════════════════════════════════
   SIDEBAR
═══════════════════════════════════════════════ */
.sidebar {
  position: fixed;
  top: 0; left: 0; bottom: 0;
  width: var(--sidebar-w);
  background: var(--bg-card);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 0;
  z-index: 200;
  transform: translateX(-100%);
  transition: transform 0.28s cubic-bezier(0.4,0,0.2,1);
  overflow: hidden;
}
.sidebar.open { transform: translateX(0); }

.sidebar-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 16px 14px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 8px;
}
.brand-gem {
  width: 30px; height: 30px;
  background: var(--accent);
  color: #fff;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  flex-shrink: 0;
}
.brand-gem.sm { width: 22px; height: 22px; border-radius: 6px; font-size: 10px; }
.brand-name { font-size: 0.9375rem; font-weight: 650; color: var(--text); letter-spacing: -0.01em; }

.icon-btn {
  width: 30px; height: 30px;
  border-radius: 7px;
  display: flex; align-items: center; justify-content: center;
  color: var(--text-3);
  transition: background var(--tr), color var(--tr);
}
.icon-btn:hover { background: var(--surface); color: var(--text); }

.btn-new-lesson {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 12px 12px 6px;
  padding: 9px 14px;
  background: var(--accent);
  color: #fff;
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  font-weight: 600;
  transition: background var(--tr), transform var(--tr), box-shadow var(--tr);
  box-shadow: 0 2px 8px rgba(255,85,0,0.28);
  flex-shrink: 0;
}
.btn-new-lesson:hover { background: var(--accent-h); transform: translateY(-1px); box-shadow: 0 4px 14px rgba(255,85,0,0.34); }

.sidebar-search-wrap {
  position: relative;
  margin: 6px 12px 4px;
  flex-shrink: 0;
}
.search-icon-sm {
  position: absolute;
  left: 11px; top: 50%;
  transform: translateY(-50%);
  color: var(--text-3);
  pointer-events: none;
}
.sidebar-search {
  width: 100%;
  padding: 8px 10px 8px 32px;
  background: var(--surface);
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  font-size: 0.8125rem;
  color: var(--text);
  outline: none;
  transition: border-color var(--tr), background var(--tr);
}
.sidebar-search:focus { background: #fff; border-color: var(--accent); }
.sidebar-search::placeholder { color: var(--text-3); }

.sidebar-section-label {
  font-size: 0.6875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-3);
  padding: 10px 16px 4px;
  flex-shrink: 0;
}

.history-list {
  flex: 1;
  overflow-y: auto;
  padding: 4px 8px 12px;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}
.history-list::-webkit-scrollbar { width: 4px; }
.history-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.history-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 36px 20px;
  text-align: center;
  color: var(--text-3);
}
.history-empty p { font-size: 0.8125rem; line-height: 1.55; }

.history-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background var(--tr);
  position: relative;
}
.history-item:hover { background: var(--surface); }
.history-item.active { background: var(--accent-lt); }
.history-item-icon {
  width: 28px; height: 28px;
  border-radius: 7px;
  background: var(--surface);
  display: flex; align-items: center; justify-content: center;
  color: var(--text-3);
  flex-shrink: 0;
  font-size: 11px;
  margin-top: 1px;
}
.history-item.active .history-item-icon { background: var(--accent-lt); color: var(--accent); }
.history-item-body { flex: 1; min-width: 0; }
.history-item-title { font-size: 0.8125rem; font-weight: 500; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.history-item-meta { font-size: 0.6875rem; color: var(--text-3); margin-top: 2px; display: flex; gap: 6px; align-items: center; }
.history-item-badge { font-size: 0.625rem; font-weight: 700; background: var(--surface); color: var(--text-2); padding: 1px 5px; border-radius: 4px; }
.history-delete {
  opacity: 0;
  width: 22px; height: 22px;
  border-radius: 5px;
  display: flex; align-items: center; justify-content: center;
  color: var(--text-3);
  flex-shrink: 0;
  transition: opacity var(--tr), background var(--tr), color var(--tr);
}
.history-item:hover .history-delete { opacity: 1; }
.history-delete:hover { background: var(--error-bg); color: var(--error); }

/* ═══════════════════════════════════════════════
   OVERLAY
═══════════════════════════════════════════════ */
.overlay {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.28);
  z-index: 150;
  backdrop-filter: blur(2px);
}
.overlay.show { display: block; animation: fadeIn 0.2s ease; }

/* ═══════════════════════════════════════════════
   MAIN LAYOUT
═══════════════════════════════════════════════ */
.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  overflow-x: hidden;
}

/* ─── Topbar ────────────────────────────────── */
.topbar {
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  background: rgba(247,246,243,0.88);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 100;
  backdrop-filter: blur(14px);
  flex-shrink: 0;
}
.topbar-left { display: flex; align-items: center; gap: 10px; }
.topbar-brand-text {
  display: flex; align-items: center; gap: 7px;
  font-size: 0.9375rem; font-weight: 650; color: var(--text);
  letter-spacing: -0.01em;
}
.topbar-right { display: flex; align-items: center; gap: 8px; }
.menu-btn { color: var(--text-2); }

/* ─── Views ────────────────────────────────── */
.view {
  display: none;
  flex: 1;
  animation: fadeUp 0.3s ease;
}
.view.active { display: flex; flex-direction: column; }

/* ═══════════════════════════════════════════════
   WORKSPACE VIEW
═══════════════════════════════════════════════ */
#viewWorkspace {
  padding: 0 24px 60px;
  max-width: 1200px;
  width: 100%;
  margin: 0 auto;
}

/* Hero */
.hero {
  text-align: center;
  padding: 48px 0 36px;
}
.hero-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--accent);
  background: var(--accent-lt);
  padding: 4px 12px;
  border-radius: 999px;
  margin-bottom: 16px;
}
.hero h1 {
  font-size: clamp(1.75rem, 3.5vw, 2.5rem);
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1.18;
  color: var(--text);
  margin-bottom: 12px;
}
.hero-sub {
  font-size: 1.0625rem;
  color: var(--text-2);
  line-height: 1.65;
}

/* Workspace stacked layout — input on top, settings below */
.workspace-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 20px;
  align-items: start;
}

/* Panel base */
.panel {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

/* ─── Input Panel ───────────────────────────── */
.input-panel { display: flex; flex-direction: column; }

.input-tabs {
  display: flex;
  gap: 2px;
  padding: 10px 14px 0;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.itab {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--text-3);
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
  border: 1px solid transparent;
  border-bottom: none;
  transition: color var(--tr), background var(--tr), border-color var(--tr);
  position: relative;
  bottom: -1px;
}
.itab:hover { color: var(--text); background: var(--bg-card); }
.itab.active {
  color: var(--text);
  font-weight: 600;
  background: var(--bg-card);
  border-color: var(--border);
}

.tab-pane { display: none; padding: 18px; }
.tab-pane.active { display: block; animation: fadeIn 0.18s ease; }

/* Textarea */
.textarea-wrap {
  display: flex;
  flex-direction: column;
  gap: 0;
}
#textInput {
  width: 100%;
  min-height: 260px;
  padding: 14px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.9375rem;
  color: var(--text);
  background: var(--bg);
  resize: vertical;
  outline: none;
  line-height: 1.65;
  transition: border-color var(--tr), box-shadow var(--tr);
}
#textInput:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(255,85,0,0.1);
  background: #fff;
}
#textInput::placeholder { color: var(--text-3); }

.textarea-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 2px 0;
}
.char-count { font-size: 0.75rem; color: var(--text-3); }

/* Buttons (small ghost / link style) */
.ghost-btn {
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-3);
  padding: 2px 6px;
  border-radius: 5px;
  transition: color var(--tr), background var(--tr);
}
.ghost-btn:hover { color: var(--text); background: var(--surface); }

.accent-link-btn {
  color: var(--accent);
  font-weight: 500;
  font-size: inherit;
  text-decoration: underline;
  text-decoration-color: transparent;
  transition: text-decoration-color var(--tr);
}
.accent-link-btn:hover { text-decoration-color: var(--accent); }

/* Dropzone */
.dropzone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 40px 20px;
  text-align: center;
  cursor: pointer;
  transition: border-color var(--tr), background var(--tr);
}
.dropzone:hover, .dropzone.drag-over {
  border-color: var(--accent);
  background: var(--accent-lt);
}
.dropzone-body { pointer-events: none; }
.dropzone-icon-wrap {
  width: 54px; height: 54px;
  background: var(--surface);
  border-radius: var(--radius);
  display: flex; align-items: center; justify-content: center;
  margin: 0 auto 14px;
  color: var(--text-3);
  transition: background var(--tr), color var(--tr);
}
.dropzone:hover .dropzone-icon-wrap,
.dropzone.drag-over .dropzone-icon-wrap { background: var(--accent-lt); color: var(--accent); }
.dropzone-title { font-size: 0.9375rem; font-weight: 500; color: var(--text); margin-bottom: 6px; }
.dropzone-title .accent-link-btn { pointer-events: all; }
.dropzone-formats { font-size: 0.8125rem; color: var(--text-3); }

/* File cards */
.file-cards { display: flex; flex-direction: column; gap: 8px; margin-top: 12px; }
.file-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: var(--surface);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  animation: slideIn 0.2s ease;
}
.file-card-icon {
  width: 36px; height: 36px;
  border-radius: 8px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  display: flex; align-items: center; justify-content: center;
  font-size: 14px;
  flex-shrink: 0;
}
.file-card-info { flex: 1; min-width: 0; }
.file-card-name { font-size: 0.8125rem; font-weight: 500; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.file-card-size { font-size: 0.6875rem; color: var(--text-3); margin-top: 2px; }
.file-card-remove {
  width: 24px; height: 24px;
  border-radius: 6px;
  display: flex; align-items: center; justify-content: center;
  color: var(--text-3);
  flex-shrink: 0;
  transition: background var(--tr), color var(--tr);
}
.file-card-remove:hover { background: var(--error-bg); color: var(--error); }

/* Link input */
.link-row { display: flex; gap: 10px; align-items: stretch; }
.link-input-wrap {
  flex: 1;
  position: relative;
}
.link-prefix-icon {
  position: absolute;
  left: 12px; top: 50%;
  transform: translateY(-50%);
  color: var(--text-3);
  pointer-events: none;
}
.link-input {
  width: 100%;
  height: 44px;
  padding: 0 12px 0 36px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  color: var(--text);
  background: var(--bg);
  outline: none;
  transition: border-color var(--tr), box-shadow var(--tr);
}
.link-input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(255,85,0,0.1); background: #fff; }
.link-input::placeholder { color: var(--text-3); }
.btn-fetch {
  height: 44px;
  padding: 0 18px;
  background: var(--text);
  color: #fff;
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  font-weight: 600;
  transition: background var(--tr), transform var(--tr);
  flex-shrink: 0;
}
.btn-fetch:hover { background: #222; transform: translateY(-1px); }
.link-hint { font-size: 0.75rem; color: var(--text-3); margin-top: 9px; }

/* Vocabulary section */
.vocab-section {
  border-top: 1px solid var(--border);
  padding: 14px 18px 18px;
  background: #FFFDF8;
}
.vocab-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
}
.vocab-header-left {
  display: flex; align-items: center; gap: 6px;
  font-size: 0.8125rem; font-weight: 600; color: var(--text);
}
.vocab-hint-inline { font-size: 0.75rem; font-weight: 400; color: var(--text-3); }

.vocab-text-box {
  font-size: 0.9375rem;
  line-height: 1.75;
  color: var(--text);
  max-height: 160px;
  overflow-y: auto;
  padding: 10px 12px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  margin-bottom: 10px;
  scrollbar-width: thin;
}
.vocab-word {
  display: inline;
  cursor: pointer;
  border-radius: 3px;
  padding: 1px 2px;
  transition: background var(--tr), color var(--tr);
}
.vocab-word:hover { background: var(--accent-lt); }
.vocab-word.selected { background: var(--accent); color: #fff; border-radius: 3px; }

.vocab-chips-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  min-height: 28px;
  align-items: center;
}
.vocab-none-hint { font-size: 0.75rem; color: var(--text-3); font-style: italic; }
.vocab-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: var(--accent-lt);
  color: var(--accent);
  border: 1px solid rgba(255,85,0,0.2);
  padding: 4px 10px 4px 10px;
  border-radius: 999px;
  font-size: 0.8125rem;
  font-weight: 500;
  animation: fadeIn 0.15s ease;
}
.vocab-chip-remove {
  display: flex; align-items: center; justify-content: center;
  color: rgba(255,85,0,0.6);
  font-size: 12px; font-weight: 700;
  transition: color var(--tr);
  line-height: 1;
}
.vocab-chip-remove:hover { color: var(--accent); }

/* ─── Settings Panel ────────────────────────── */
.settings-panel {
  display: flex;
  flex-direction: column;
  gap: 0;
  padding: 0;
}
.settings-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.875rem;
  font-weight: 650;
  color: var(--text);
  padding: 18px 20px 14px;
  border-bottom: 1px solid var(--border);
}
.sgroup {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}
.sgroup:last-child { border-bottom: none; }
.slabel {
  display: block;
  font-size: 0.6875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-3);
  margin-bottom: 10px;
}
.slabel-row {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 10px;
}
.slabel-row .slabel { margin-bottom: 0; }

/* Level pills */
.level-pills {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}
.pill {
  padding: 6px 14px;
  border-radius: 999px;
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--text-2);
  background: var(--surface);
  border: 1.5px solid transparent;
  transition: all var(--tr);
}
.pill:hover { background: var(--border); color: var(--text); }
.pill.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
  box-shadow: 0 2px 8px rgba(255,85,0,0.25);
}

/* Language select */
.select-wrap { position: relative; }
.custom-select {
  width: 100%;
  appearance: none;
  -webkit-appearance: none;
  padding: 10px 34px 10px 12px;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  color: var(--text);
  outline: none;
  cursor: pointer;
  transition: border-color var(--tr), box-shadow var(--tr);
}
.custom-select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(255,85,0,0.1); background: #fff; }
.select-caret {
  position: absolute;
  right: 11px; top: 50%;
  transform: translateY(-50%);
  color: var(--text-3);
  pointer-events: none;
}

/* Exercise type toggles */
.ex-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.ex-tag {
  padding: 5px 11px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-3);
  background: var(--surface);
  border: 1.5px solid transparent;
  transition: all var(--tr);
}
.ex-tag:hover { color: var(--text); background: var(--border); }
.ex-tag.active {
  color: var(--accent);
  background: var(--accent-lt);
  border-color: rgba(255,85,0,0.22);
  font-weight: 600;
}

/* Generate button */
.btn-generate {
  display: flex;
  align-items: center;
  justify-content: center;
  width: calc(100% - 40px);
  margin: 18px 20px 20px;
  padding: 13px 20px;
  background: var(--accent);
  color: #fff;
  border-radius: var(--radius);
  font-size: 0.9375rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  box-shadow: 0 4px 16px rgba(255,85,0,0.28);
  transition: background var(--tr), transform var(--tr), box-shadow var(--tr), opacity var(--tr);
}
.btn-generate:hover:not(:disabled) { background: var(--accent-h); transform: translateY(-1px); box-shadow: 0 6px 22px rgba(255,85,0,0.35); }
.btn-generate:active:not(:disabled) { transform: translateY(0); }
.btn-generate:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-generate-label, .btn-generate-spinner {
  display: flex; align-items: center; gap: 8px;
}

/* ═══════════════════════════════════════════════
   LOADING VIEW
═══════════════════════════════════════════════ */
#viewLoading {
  align-items: center;
  justify-content: center;
  min-height: calc(100vh - var(--topbar-h));
}
.loading-center { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 0; }
.loading-orb {
  position: relative;
  width: 72px; height: 72px;
  display: flex; align-items: center; justify-content: center;
  margin-bottom: 24px;
}
.loading-gem {
  position: absolute;
  font-size: 22px;
  color: var(--accent);
  animation: pulse 2s ease infinite;
}
.loading-h {
  font-size: 1.375rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text);
  margin-bottom: 8px;
}
.loading-sub { font-size: 0.9375rem; color: var(--text-3); margin-bottom: 28px; }
.loading-steps {
  display: flex;
  flex-direction: column;
  gap: 12px;
  align-items: flex-start;
}
.ls-item {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.875rem;
  color: var(--text-3);
  transition: color var(--tr);
}
.ls-item.active { color: var(--text); }
.ls-item.done { color: var(--success); }
.ls-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--border);
  flex-shrink: 0;
  transition: background var(--tr);
}
.ls-item.active .ls-dot { background: var(--accent); animation: pulse 1.2s ease infinite; }
.ls-item.done .ls-dot { background: var(--success); animation: none; }

/* ═══════════════════════════════════════════════
   OUTPUT VIEW
═══════════════════════════════════════════════ */
#viewOutput {
  padding: 0 24px 60px;
  max-width: 900px;
  width: 100%;
  margin: 0 auto;
}

.output-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 22px 0 20px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 24px;
  flex-wrap: wrap;
  gap: 12px;
}
.output-meta-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.output-level-badge {
  font-size: 0.6875rem;
  font-weight: 800;
  background: var(--accent);
  color: #fff;
  padding: 3px 9px;
  border-radius: 999px;
  letter-spacing: 0.04em;
}
.output-lang-tag {
  font-size: 0.8125rem;
  color: var(--text-3);
}
.output-topic {
  font-size: 1.125rem;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.015em;
}
.output-actions { display: flex; gap: 8px; }

/* Small buttons */
.btn-sm-outline {
  display: flex; align-items: center; gap: 6px;
  padding: 7px 14px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--text-2);
  background: var(--bg-card);
  transition: all var(--tr);
}
.btn-sm-outline:hover { border-color: var(--border-h); background: var(--surface); color: var(--text); }

/* Lesson blocks */
.blocks-list {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.lesson-block {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  animation: slideIn 0.25s ease;
  transition: box-shadow var(--tr);
}
.lesson-block:hover { box-shadow: var(--shadow); }

.block-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 20px;
  cursor: pointer;
  user-select: none;
  border-bottom: 1px solid transparent;
  transition: background var(--tr), border-color var(--tr);
}
.block-header:hover { background: var(--surface); }
.lesson-block.collapsed .block-header { border-bottom-color: transparent; }
.lesson-block:not(.collapsed) .block-header { border-bottom-color: var(--border); }

.block-icon {
  width: 34px; height: 34px;
  border-radius: 9px;
  display: flex; align-items: center; justify-content: center;
  font-size: 16px;
  flex-shrink: 0;
}
.block-header-text { flex: 1; min-width: 0; }
.block-title { font-size: 0.9375rem; font-weight: 650; color: var(--text); }
.block-desc { font-size: 0.75rem; color: var(--text-3); margin-top: 1px; }
.block-actions { display: flex; gap: 4px; align-items: center; }

.block-action-btn {
  width: 30px; height: 30px;
  border-radius: 7px;
  display: flex; align-items: center; justify-content: center;
  color: var(--text-3);
  font-size: 12px;
  transition: background var(--tr), color var(--tr);
}
.block-action-btn:hover { background: var(--surface); color: var(--text); }
.block-action-btn.copied { color: var(--success); }

.block-chevron {
  color: var(--text-3);
  transition: transform 0.2s ease;
  flex-shrink: 0;
}
.lesson-block.collapsed .block-chevron { transform: rotate(-90deg); }

.block-body {
  padding: 20px 22px;
  overflow: hidden;
  transition: max-height 0.3s ease, opacity 0.2s ease;
}
.lesson-block.collapsed .block-body { display: none; }

/* Block content elements */
.block-question-list { list-style: none; display: flex; flex-direction: column; gap: 10px; }
.block-question {
  display: flex;
  gap: 10px;
  font-size: 0.9375rem;
  color: var(--text);
  line-height: 1.6;
}
.q-num {
  width: 24px; height: 24px;
  border-radius: 50%;
  background: var(--accent-lt);
  color: var(--accent);
  font-size: 0.6875rem;
  font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  margin-top: 2px;
}

.block-text-body {
  font-size: 0.9375rem;
  line-height: 1.75;
  color: var(--text);
  padding: 16px;
  background: var(--bg);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  max-height: 320px;
  overflow-y: auto;
  scrollbar-width: thin;
}

/* True/False */
.tf-list { display: flex; flex-direction: column; gap: 10px; }
.tf-item {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 13px 16px;
  border-radius: var(--radius-sm);
  background: var(--surface);
  border: 1px solid var(--border);
  cursor: pointer;
  transition: all var(--tr);
  position: relative;
}
.tf-item:hover { border-color: var(--border-h); }
.tf-item.tf-true { background: var(--success-bg); border-color: rgba(22,163,74,0.2); }
.tf-item.tf-false { background: var(--error-bg); border-color: rgba(220,38,38,0.18); }
.tf-badge {
  width: 28px; height: 20px;
  border-radius: 5px;
  font-size: 0.625rem;
  font-weight: 800;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  margin-top: 2px;
  background: var(--border);
  color: var(--text-3);
}
.tf-item.tf-true .tf-badge { background: rgba(22,163,74,0.15); color: var(--success); }
.tf-item.tf-false .tf-badge { background: rgba(220,38,38,0.12); color: var(--error); }
.tf-text { font-size: 0.9375rem; color: var(--text); flex: 1; line-height: 1.55; }
.tf-explain {
  font-size: 0.8125rem;
  color: var(--text-2);
  margin-top: 5px;
  font-style: italic;
  padding-left: 40px;
}

/* Quiz */
.quiz-list { display: flex; flex-direction: column; gap: 18px; }
.quiz-item { }
.quiz-q { font-size: 0.9375rem; font-weight: 500; color: var(--text); margin-bottom: 10px; }
.quiz-options { display: flex; flex-direction: column; gap: 6px; }
.quiz-opt {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  background: var(--surface);
  border: 1.5px solid var(--border);
  cursor: pointer;
  font-size: 0.875rem;
  color: var(--text);
  transition: all var(--tr);
  text-align: left;
}
.quiz-opt:hover { border-color: var(--accent); background: var(--accent-lt); color: var(--text); }
.quiz-opt.correct { border-color: var(--success); background: var(--success-bg); color: var(--success); font-weight: 600; }
.quiz-opt.wrong { border-color: var(--error); background: var(--error-bg); color: var(--error); }
.quiz-opt.dim { opacity: 0.45; cursor: default; }
.quiz-key {
  width: 22px; height: 22px;
  border-radius: 5px;
  background: var(--border);
  color: var(--text-3);
  font-size: 0.6875rem;
  font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.quiz-opt.correct .quiz-key { background: var(--success-bg); color: var(--success); }
.quiz-opt.wrong .quiz-key { background: var(--error-bg); color: var(--error); }
.quiz-explain {
  font-size: 0.8125rem;
  color: var(--text-2);
  margin-top: 8px;
  padding: 8px 12px;
  background: var(--surface);
  border-radius: var(--radius-sm);
  border-left: 3px solid var(--accent);
  line-height: 1.5;
}

/* Vocabulary words */
.vocab-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 10px;
}
.vocab-card {
  padding: 14px;
  background: var(--surface);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  cursor: pointer;
  transition: all var(--tr);
}
.vocab-card:hover { border-color: var(--accent); background: var(--accent-lt); }
.vocab-card.expanded { border-color: var(--accent); background: var(--accent-lt); }
.vocab-word-main { font-size: 0.9375rem; font-weight: 700; color: var(--text); margin-bottom: 3px; }
.vocab-pos { font-size: 0.6875rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; color: var(--accent); background: rgba(255,85,0,0.1); padding: 2px 6px; border-radius: 4px; }
.vocab-def { font-size: 0.8125rem; color: var(--text-2); margin-top: 7px; line-height: 1.5; display: none; }
.vocab-card.expanded .vocab-def { display: block; }
.vocab-example { font-size: 0.8125rem; color: var(--text-3); margin-top: 5px; font-style: italic; display: none; }
.vocab-card.expanded .vocab-example { display: block; }
.vocab-syns { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; display: none; }
.vocab-card.expanded .vocab-syns { display: flex; }
.vocab-syn-tag {
  font-size: 0.6875rem;
  padding: 2px 7px;
  border-radius: 999px;
  background: rgba(255,85,0,0.08);
  color: var(--accent);
  font-weight: 500;
}

/* Fill blanks */
.fill-list { display: flex; flex-direction: column; gap: 12px; }
.fill-item {
  display: flex;
  align-items: baseline;
  gap: 8px;
  font-size: 0.9375rem;
  line-height: 1.65;
}
.fill-num { font-size: 0.75rem; font-weight: 600; color: var(--text-3); flex-shrink: 0; min-width: 18px; }
.fill-input {
  border: none;
  border-bottom: 2px solid var(--border);
  background: transparent;
  outline: none;
  font-size: 0.9375rem;
  color: var(--text);
  padding: 2px 6px;
  min-width: 80px;
  transition: border-color var(--tr);
}
.fill-input:focus { border-color: var(--accent); }
.fill-input.correct { border-color: var(--success); color: var(--success); }
.fill-input.wrong { border-color: var(--error); color: var(--error); }

/* Review key points */
.key-points-list { display: flex; flex-direction: column; gap: 10px; }
.key-point-item {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 12px 14px;
  background: var(--surface);
  border-radius: var(--radius-sm);
  font-size: 0.9375rem;
  color: var(--text);
  line-height: 1.55;
}
.kp-bullet {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--accent);
  flex-shrink: 0;
  margin-top: 7px;
}
.language-focus {
  margin-top: 12px;
  padding: 14px 16px;
  background: var(--accent-lt);
  border-radius: var(--radius-sm);
  border-left: 3px solid var(--accent);
  font-size: 0.875rem;
  color: var(--text);
  line-height: 1.6;
}
.language-focus strong { color: var(--accent); }

/* Writing/Speaking tasks */
.task-card {
  padding: 18px;
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.task-meta { display: flex; gap: 6px; flex-wrap: wrap; }
.task-tag {
  font-size: 0.6875rem;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-2);
}
.task-prompt { font-size: 0.9375rem; font-weight: 600; color: var(--text); line-height: 1.5; }
.task-guidance { font-size: 0.875rem; color: var(--text-2); line-height: 1.6; }
.task-points-list { display: flex; flex-direction: column; gap: 6px; }
.task-point {
  display: flex; gap: 8px; align-items: flex-start;
  font-size: 0.875rem; color: var(--text-2); line-height: 1.5;
}
.task-point::before { content:'→'; color: var(--accent); flex-shrink: 0; }

/* ═══════════════════════════════════════════════
   SAVE MODAL
═══════════════════════════════════════════════ */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.38);
  backdrop-filter: blur(6px);
  z-index: 300;
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
  animation: fadeIn 0.18s ease;
}
.modal {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  padding: 24px;
  max-width: 420px;
  width: 100%;
  box-shadow: var(--shadow-lg);
  animation: fadeUp 0.22s ease;
}
.modal-top {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 6px;
}
.modal-top h3 { font-size: 1.0625rem; font-weight: 700; }
.modal-sub { font-size: 0.875rem; color: var(--text-2); margin-bottom: 16px; line-height: 1.5; }
.modal-input {
  width: 100%;
  padding: 11px 14px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.9375rem;
  color: var(--text);
  background: var(--bg);
  outline: none;
  margin-bottom: 16px;
  transition: border-color var(--tr), box-shadow var(--tr);
}
.modal-input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(255,85,0,0.1); background: #fff; }
.modal-btns { display: flex; justify-content: flex-end; gap: 8px; }

.btn-sm-ghost {
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-2);
  background: var(--surface);
  transition: background var(--tr), color var(--tr);
}
.btn-sm-ghost:hover { background: var(--border); color: var(--text); }
.btn-sm-accent {
  padding: 8px 20px;
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  font-weight: 700;
  color: #fff;
  background: var(--accent);
  box-shadow: 0 2px 8px rgba(255,85,0,0.25);
  transition: background var(--tr), transform var(--tr);
}
.btn-sm-accent:hover { background: var(--accent-h); transform: translateY(-1px); }

/* ═══════════════════════════════════════════════
   TOPBAR SAVE/NEW (output view controls)
═══════════════════════════════════════════════ */
.topbar-lesson-actions { display: flex; align-items: center; gap: 8px; }

/* ═══════════════════════════════════════════════
   SCROLLBAR
═══════════════════════════════════════════════ */
* { scrollbar-width: thin; scrollbar-color: var(--border) transparent; }
*::-webkit-scrollbar { width: 5px; height: 5px; }
*::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* ═══════════════════════════════════════════════
   RESPONSIVE
═══════════════════════════════════════════════ */
@media (max-width: 900px) {
  .workspace-grid {
    grid-template-columns: 1fr;
  }
  #viewWorkspace { padding: 0 16px 40px; }
  #viewOutput { padding: 0 16px 40px; }
}
@media (max-width: 600px) {
  .hero h1 { font-size: 1.5rem; }
  .hero-sub { font-size: 0.9375rem; }
  .vocab-grid { grid-template-columns: 1fr 1fr; }
  .output-header { flex-direction: column; align-items: flex-start; }
}

/* ═══════════════════════════════════════════════
   FILL BLANKS — check interaction
═══════════════════════════════════════════════ */
.fill-item {
  flex-wrap: wrap;
  row-gap: 4px;
}
.fill-sentence-wrap {
  flex: 1;
  min-width: 0;
  display: inline;
  font-size: 0.9375rem;
  line-height: 1.65;
}
.fill-hint {
  font-size: 0.75rem;
  color: var(--text-3);
  font-style: italic;
  margin-left: 2px;
}
.fill-check-btn {
  padding: 4px 12px;
  border-radius: var(--radius-sm);
  background: var(--surface);
  border: 1.5px solid var(--border);
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-2);
  cursor: pointer;
  transition: all var(--tr);
  flex-shrink: 0;
}
.fill-check-btn:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-lt); }
.fill-result {
  font-size: 0.8125rem;
  font-weight: 600;
  flex-shrink: 0;
}
.fill-ok  { color: var(--success); }
.fill-err { color: var(--error); }

/* ═══════════════════════════════════════════════
   FILL-IN-THE-GAPS — word bank ("Show possible answers")
═══════════════════════════════════════════════ */
.fill-bank-wrap {
  margin-bottom: 14px;
  padding-bottom: 12px;
  border-bottom: 1px dashed var(--border);
}
.fill-bank-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  background: var(--accent-lt);
  color: var(--accent);
  border: 1px dashed var(--accent);
  font-size: 0.8125rem;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--tr);
  font-family: inherit;
}
.fill-bank-toggle:hover {
  background: rgba(255,85,0,0.15);
}
.fill-bank {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
  padding: 12px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  animation: fadeIn 0.18s ease;
}
.fill-bank-word {
  display: inline-block;
  padding: 5px 12px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text);
  box-shadow: var(--shadow-sm);
  user-select: text;             /* learners can copy a word from the bank */
}

/* ═══════════════════════════════════════════════
   REFORMULATION EXERCISE
═══════════════════════════════════════════════ */
.refo-list { display: flex; flex-direction: column; gap: 14px; }
.refo-item {
  display: flex;
  gap: 10px;
  padding: 14px;
  background: var(--surface);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}
.refo-num {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--text-3);
  min-width: 18px;
  padding-top: 2px;
  flex-shrink: 0;
}
.refo-body { flex: 1; min-width: 0; }
.refo-original {
  font-size: 0.9375rem;
  color: var(--text);
  line-height: 1.55;
  margin-bottom: 5px;
}
.refo-use {
  font-size: 0.8125rem;
  color: var(--text-2);
  margin-bottom: 8px;
}
.refo-use strong { color: var(--accent); }
.refo-details { font-size: 0.875rem; }
.refo-details summary {
  cursor: pointer;
  color: var(--accent);
  font-weight: 500;
  font-size: 0.8125rem;
  user-select: none;
  outline: none;
}
.refo-details summary:hover { text-decoration: underline; }
.refo-answer {
  margin-top: 7px;
  padding: 10px 12px;
  background: var(--success-bg);
  border-left: 3px solid var(--success);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  color: var(--text);
  line-height: 1.55;
}

/* ═══════════════════════════════════════════════
   TOAST NOTIFICATION
═══════════════════════════════════════════════ */
.app-toast {
  position: fixed;
  bottom: 28px;
  left: 50%;
  transform: translateX(-50%) translateY(16px);
  padding: 11px 22px;
  border-radius: 999px;
  font-size: 0.875rem;
  font-weight: 500;
  box-shadow: var(--shadow-md);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.22s ease, transform 0.22s ease;
  z-index: 999;
  white-space: nowrap;
}
.app-toast-show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
.app-toast-ok  { background: var(--text); color: #fff; }
.app-toast-err { background: var(--error); color: #fff; }

/* ═══════════════════════════════════════════════
   VOCAB SECTION CHIPS
═══════════════════════════════════════════════ */
.vocab-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 10px;
  background: var(--accent-lt);
  border: 1px solid rgba(255,85,0,0.3);
  border-radius: 999px;
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--accent);
}
.chip-del {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 0.9rem;
  line-height: 1;
  color: var(--accent);
  padding: 0;
  opacity: 0.7;
  transition: opacity var(--tr);
}
.chip-del:hover { opacity: 1; }

/* ═══════════════════════════════════════════════
   FILE CARDS
═══════════════════════════════════════════════ */
.file-cards { display: flex; flex-direction: column; gap: 8px; margin-top: 10px; }
.file-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
.file-card-icon {
  font-size: 0.625rem;
  font-weight: 800;
  letter-spacing: 0.02em;
  color: var(--accent);
  background: var(--accent-lt);
  border-radius: 5px;
  padding: 4px 6px;
  flex-shrink: 0;
}
.file-card-info { flex: 1; min-width: 0; }
.file-card-name { font-size: 0.8125rem; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.file-card-size { font-size: 0.75rem; color: var(--text-3); margin-top: 1px; }
.file-card-del {
  color: var(--text-3);
  transition: color var(--tr);
  flex-shrink: 0;
}
.file-card-del:hover { color: var(--error); }
.file-card-status {
  font-size: 0.6875rem;
  font-weight: 500;
  color: var(--text-2);
}
.file-card-status.file-card-ok  { color: var(--success); }
.file-card-status.file-card-err { color: var(--error); }

/* ═══════════════════════════════════════════════
   QUIZ  — q-num in quiz
═══════════════════════════════════════════════ */
.quiz-q {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  font-size: 0.9375rem;
  font-weight: 500;
  color: var(--text);
  margin-bottom: 10px;
  line-height: 1.55;
}
.quiz-q .q-num { flex-shrink: 0; }

/* ═══════════════════════════════════════════════
   HISTORY ITEM TWEAKS
═══════════════════════════════════════════════ */
.history-item-body { cursor: pointer; flex: 1; min-width: 0; }
.history-delete {
  width: 26px; height: 26px;
  border-radius: 6px;
  color: var(--text-3);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  opacity: 0;
  transition: opacity var(--tr), color var(--tr), background var(--tr);
}
.history-item:hover .history-delete { opacity: 1; }
.history-delete:hover { color: var(--error); background: var(--error-bg); }

/* ═══════════════════════════════════════════════
   LOADING STEPS — done state
═══════════════════════════════════════════════ */
.ls-item.done .ls-dot {
  background: var(--success);
  animation: none;
}
.ls-item.done { color: var(--success); opacity: 0.8; }

/* ═══════════════════════════════════════════════
   GLOBAL PERSISTENT ERROR PANEL (visible in any view)
═══════════════════════════════════════════════ */
.error-panel {
  position: fixed;
  top: 70px;
  right: 16px;
  width: min(460px, calc(100vw - 32px));
  max-height: calc(100vh - 90px);
  overflow: auto;
  z-index: 500;
  padding: 16px 18px;
  background: #fff;
  border: 2px solid var(--error);
  border-radius: var(--radius);
  color: var(--text);
  box-shadow: var(--shadow-lg);
}
.error-panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}
.error-panel-title {
  font-weight: 700;
  font-size: 0.9375rem;
  color: var(--error);
}
.error-panel-close {
  background: transparent;
  border: none;
  cursor: pointer;
  font-size: 1.4rem;
  line-height: 1;
  color: var(--error);
  padding: 0 6px;
}
.error-panel-body {
  font-size: 0.875rem;
  white-space: pre-wrap;
  line-height: 1.5;
  margin-bottom: 10px;
}
.error-panel-details {
  font-size: 0.8125rem;
}
.error-panel-details summary {
  cursor: pointer;
  color: var(--error);
  font-weight: 600;
  user-select: none;
}
.error-panel-details pre {
  margin-top: 8px;
  padding: 10px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.75rem;
  font-family: ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
  max-height: 320px;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
}

.block-error {
  padding: 10px 14px;
  background: var(--error-bg);
  border-left: 3px solid var(--error);
  border-radius: var(--radius-sm);
  color: var(--error);
  font-size: 0.875rem;
  line-height: 1.5;
}

/* ═══════════════════════════════════════════════
   VOCAB SELECTION VIEW (full-screen)
═══════════════════════════════════════════════ */
#viewVocab {
  padding: 0;
  max-width: none;
  margin: 0;
}
#viewVocab.active {
  display: block;
}

/* sticky top bar — visible while scrolling the text */
.vocab-bar {
  position: sticky;
  top: var(--topbar-h);
  z-index: 30;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  box-shadow: 0 4px 14px rgba(0,0,0,0.04);
}
.vocab-bar-inner {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 14px 28px;
  max-width: 1280px;
  margin: 0 auto;
}
.vocab-bar-back {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text-2);
  font-size: 0.8125rem;
  font-weight: 500;
  border: 1px solid var(--border);
  transition: all var(--tr);
}
.vocab-bar-back:hover { background: var(--border); color: var(--text); }

.vocab-bar-meta {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
}
.vocab-bar-count {
  font-size: 0.875rem;
  color: var(--text-2);
}
.vocab-bar-count strong {
  color: var(--accent);
  font-size: 1.125rem;
  font-weight: 700;
  padding: 0 4px;
}
.vocab-bar-clear {
  font-size: 0.8125rem !important;
}
.vocab-bar-generate {
  width: auto !important;
  padding: 10px 22px !important;
  font-size: 0.9375rem !important;
  flex-shrink: 0;
}

.vocab-bar-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 0 28px 14px;
  max-width: 1280px;
  margin: 0 auto;
  min-height: 30px;
  align-items: center;
}
.vocab-bar-empty {
  font-size: 0.8125rem;
  color: var(--text-3);
  font-style: italic;
}

/* helper text under the bar */
.vocab-helper {
  max-width: 1100px;
  margin: 22px auto 12px;
  padding: 0 28px;
  font-size: 0.9375rem;
  color: var(--text-2);
  line-height: 1.55;
}

/* the big readable canvas */
.vocab-canvas {
  max-width: 1100px;
  margin: 0 auto 48px;
  padding: 36px 44px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  font-size: 1.0625rem;       /* 17px — comfortable reading */
  line-height: 1.85;
  color: var(--text);
}
.vocab-canvas-empty {
  color: var(--text-3);
  font-style: italic;
  text-align: center;
  padding: 40px 0;
}
.vocab-para {
  margin-bottom: 1.1em;
}
.vocab-para:last-child { margin-bottom: 0; }

/* clickable words — LARGE hit area, comfortable to tap */
.vocab-canvas .vocab-word {
  display: inline;
  cursor: pointer;
  padding: 2px 1px;
  border-radius: 4px;
  transition: background var(--tr), color var(--tr), box-shadow var(--tr);
  -webkit-user-select: none;
  user-select: none;
}
.vocab-canvas .vocab-word:hover {
  background: rgba(255,85,0,0.10);
}
.vocab-canvas .vocab-word.selected {
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  padding: 2px 6px;
  margin: 0 1px;
  border-radius: 5px;
  box-shadow: 0 1px 3px rgba(255,85,0,0.35);
}
.vocab-canvas .vocab-word.selected:hover {
  background: var(--accent-h);
}

/* Responsive */
@media (max-width: 900px) {
  .vocab-bar-inner   { flex-wrap: wrap; padding: 12px 16px; }
  .vocab-bar-chips   { padding: 0 16px 12px; }
  .vocab-helper      { padding: 0 16px; }
  .vocab-canvas      { padding: 22px 18px; margin: 0 12px 24px; font-size: 1rem; line-height: 1.75; }
  .vocab-bar-generate { width: 100% !important; }
}

/* ═══════════════════════════════════════════════
   IMAGE PREVIEWS + OCR EXTRACT FLOW
═══════════════════════════════════════════════ */
.image-previews {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 10px;
  margin-top: 12px;
}
.img-preview {
  position: relative;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
}
.img-preview-thumb {
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  background: #fff;
  display: block;
}
.img-preview-info {
  padding: 6px 9px 8px;
}
.img-preview-name {
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.img-preview-size {
  font-size: 0.6875rem;
  color: var(--text-3);
  margin-top: 1px;
}
.img-preview-del {
  position: absolute;
  top: 6px; right: 6px;
  width: 22px; height: 22px;
  border-radius: 999px;
  background: rgba(0,0,0,0.55);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  border: none;
  transition: background var(--tr);
}
.img-preview-del:hover { background: var(--error); }

.extract-bar {
  margin-top: 12px;
  padding: 10px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: var(--accent-lt);
  border: 1px dashed var(--accent);
  border-radius: var(--radius-sm);
}
.extract-bar-info {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.8125rem;
  color: var(--accent);
  font-weight: 500;
}
.btn-extract {
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: #fff;
  font-size: 0.8125rem;
  font-weight: 600;
  border: none;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: background var(--tr), opacity var(--tr);
  box-shadow: 0 2px 8px rgba(255,85,0,0.25);
}
.btn-extract:hover:not(:disabled) { background: var(--accent-h); }
.btn-extract:disabled { opacity: 0.6; cursor: not-allowed; }
.btn-extract-spinner { display: inline-flex; align-items: center; gap: 6px; }

.extracted-preview {
  margin-top: 14px;
  padding: 14px;
  background: var(--success-bg);
  border: 1px solid rgba(22,163,74,0.3);
  border-radius: var(--radius-sm);
}
.extracted-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
  gap: 10px;
}
.extracted-title {
  font-size: 0.8125rem;
  color: var(--success);
  font-weight: 500;
}
.extracted-textarea {
  width: 100%;
  min-height: 140px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: #fff;
  font-family: inherit;
  font-size: 0.875rem;
  color: var(--text);
  line-height: 1.55;
  resize: vertical;
  outline: none;
  transition: border-color var(--tr);
}
.extracted-textarea:focus { border-color: var(--accent); }
.extracted-footer {
  margin-top: 6px;
  text-align: right;
}

/* ═══════════════════════════════════════════════
   DEV DEBUG PANEL (?debug=1)
═══════════════════════════════════════════════ */
.debug-panel {
  position: fixed;
  bottom: 14px;
  left: 14px;
  width: 280px;
  background: #111;
  color: #d4d4d4;
  border-radius: var(--radius-sm);
  border: 1px solid #333;
  font-family: ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
  font-size: 11px;
  line-height: 1.45;
  z-index: 600;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
  overflow: hidden;
}
.debug-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 10px;
  background: #1a1a1a;
  border-bottom: 1px solid #2a2a2a;
  font-weight: 700;
  font-size: 11px;
  color: #fff;
}
.debug-close {
  background: transparent;
  color: #888;
  border: none;
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
  padding: 0 4px;
}
.debug-close:hover { color: #fff; }
.debug-table {
  width: 100%;
  border-collapse: collapse;
}
.debug-table th,
.debug-table td {
  text-align: left;
  padding: 4px 10px;
  border-bottom: 1px solid #1f1f1f;
  vertical-align: top;
}
.debug-table th {
  color: #888;
  font-weight: 500;
  width: 38%;
  font-size: 10.5px;
}
.debug-table td {
  color: #4ade80;
  word-break: break-all;
}

/* ═══════════════════════════════════════════════
   AUTH UI — topbar pill, modal, signup banner
═══════════════════════════════════════════════ */
.auth-area {
  display: flex;
  align-items: center;
  gap: 8px;
}
.auth-cta {
  padding: 7px 14px;
  border-radius: var(--radius-sm);
  font-size: 0.8125rem;
  font-weight: 500;
  background: transparent;
  color: var(--text-2);
  border: 1px solid var(--border);
  cursor: pointer;
  transition: all var(--tr);
}
.auth-cta:hover:not(:disabled) {
  background: var(--surface);
  color: var(--text);
}
.auth-cta:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
.auth-cta.auth-cta-primary {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
  box-shadow: 0 2px 6px rgba(255,85,0,0.2);
}
.auth-cta.auth-cta-primary:hover:not(:disabled) { background: var(--accent-h); }

.auth-user-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 4px 10px 4px 4px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--border);
}
.auth-user-avatar {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: 0.75rem;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.auth-user-email {
  font-size: 0.8125rem;
  color: var(--text);
  max-width: 200px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.auth-logout-btn {
  font-size: 0.75rem;
  color: var(--text-3);
  background: transparent;
  border: none;
  padding: 2px 8px;
  cursor: pointer;
  border-left: 1px solid var(--border);
  margin-left: 2px;
  transition: color var(--tr);
}
.auth-logout-btn:hover { color: var(--error); }

/* Auth modal */
.auth-modal { max-width: 380px; }
.auth-label {
  display: block;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-2);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin: 6px 0 4px;
}
.auth-submit {
  width: 100%;
  margin-top: 12px;
  padding: 10px 16px !important;
  font-size: 0.9375rem !important;
}
.auth-switch {
  text-align: center;
  margin-top: 12px;
  font-size: 0.8125rem;
  color: var(--text-2);
}
.auth-forgot {
  text-align: center;
  margin-top: 10px;
  font-size: 0.8125rem;
}
.auth-forgot.hidden { display: none; }
#authPasswordWrap.hidden { display: none; }
.auth-link-btn {
  background: transparent;
  border: none;
  cursor: pointer;
  color: var(--accent);
  font-weight: 600;
  font-size: 0.8125rem;
  margin-left: 4px;
  padding: 0;
}
.auth-link-btn:hover { text-decoration: underline; }
.auth-error,
.auth-info {
  margin-top: 8px;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  font-size: 0.8125rem;
  line-height: 1.45;
}
.auth-error {
  background: var(--error-bg);
  color: var(--error);
  border: 1px solid rgba(220,38,38,0.25);
}
.auth-info {
  background: var(--success-bg);
  color: var(--success);
  border: 1px solid rgba(22,163,74,0.25);
}

/* Signup banner (bottom of screen) */
.signup-banner {
  position: fixed;
  bottom: 18px;
  left: 50%;
  transform: translateX(-50%);
  max-width: calc(100vw - 32px);
  z-index: 350;
  animation: fadeUp 0.25s ease;
}
.signup-banner-inner {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 18px;
  background: var(--text);
  color: #fff;
  border-radius: 999px;
  box-shadow: var(--shadow-lg);
}
.signup-banner-icon {
  font-size: 1.1rem;
}
.signup-banner-text {
  font-size: 0.875rem;
}
.signup-banner-text strong { font-weight: 700; }
.signup-banner-dismiss {
  width: 26px; height: 26px;
  border-radius: 50%;
  background: rgba(255,255,255,0.1);
  color: #fff;
  border: none;
  cursor: pointer;
  font-size: 14px;
  display: flex; align-items: center; justify-content: center;
}
.signup-banner-dismiss:hover { background: rgba(255,255,255,0.2); }

@media (max-width: 600px) {
  .auth-user-email { max-width: 100px; }
  .signup-banner-inner { flex-wrap: wrap; border-radius: var(--radius); }
}

/* ═══════════════════════════════════════════════
   SITE FOOTER (legal links — required for YooKassa moderation)
   Lives INSIDE .main (flex column) — `margin-top: auto` pushes it to the
   bottom even on short pages, and it inherits the full width of .main
   instead of becoming a horizontal flex sibling of it.
═══════════════════════════════════════════════ */
.site-footer {
  border-top: 1px solid var(--border);
  background: var(--bg-card);
  margin-top: auto;
}
.site-footer-inner {
  max-width: 1240px;
  margin: 0 auto;
  padding: 20px 24px;
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  justify-content: space-between;
  align-items: center;
}
.site-footer-brand {
  font-size: 0.8125rem;
  color: var(--text-3);
}
.site-footer-brand strong { color: var(--text-2); font-weight: 600; }
.site-footer-links {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 18px;
}
.site-footer-links a {
  font-size: 0.8125rem;
  color: var(--text-2);
  text-decoration: none;
  transition: color var(--tr);
}
.site-footer-links a:hover { color: var(--accent); }
@media (max-width: 600px) {
  .site-footer-inner { flex-direction: column; align-items: flex-start; padding: 16px; }
}

/* ═══════════════════════════════════════════════
   LANGUAGE SWITCHER (EN / RU)
═══════════════════════════════════════════════ */
.lang-switch {
  display: inline-flex;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  padding: 2px;
  gap: 1px;
}
.lang-btn {
  background: transparent;
  border: none;
  cursor: pointer;
  padding: 4px 9px;
  font-size: 0.6875rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--text-3);
  border-radius: 5px;
  transition: all var(--tr);
  font-family: inherit;
}
.lang-btn:hover { color: var(--text); }
.lang-btn.active {
  background: var(--bg-card);
  color: var(--accent);
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}

/* ═══════════════════════════════════════════════
   USAGE PILL — topbar quota indicator
═══════════════════════════════════════════════ */
.usage-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  cursor: pointer;
  font-size: 0.75rem;
  transition: all var(--tr);
}
.usage-pill:hover { border-color: var(--accent); }
.usage-pill-plan {
  text-transform: uppercase;
  font-weight: 700;
  font-size: 0.625rem;
  letter-spacing: 0.04em;
  color: var(--accent);
  background: var(--accent-lt);
  padding: 2px 6px;
  border-radius: 4px;
}
.usage-pill-quota {
  color: var(--text-2);
  font-weight: 500;
  font-size: 0.75rem;
}
.usage-pill.usage-pill-empty .usage-pill-plan {
  color: var(--error);
  background: var(--error-bg);
}
.usage-pill.usage-pill-empty .usage-pill-quota {
  color: var(--error);
  font-weight: 600;
}

/* ═══════════════════════════════════════════════
   PAYWALL MODAL
═══════════════════════════════════════════════ */
.paywall-modal { max-width: 720px; }
.plan-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-top: 14px;
}
.plan-grid.plan-grid-3 {
  grid-template-columns: 1fr 1fr 1fr;
}
.plan-card {
  padding: 18px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  display: flex;
  flex-direction: column;
  gap: 12px;
  transition: border-color var(--tr), box-shadow var(--tr);
}
.plan-card:hover { border-color: var(--border-h); }
.plan-card.plan-card-pro {
  border-color: var(--accent);
  background: linear-gradient(180deg, var(--accent-lt) 0%, var(--bg) 100%);
}
.plan-card-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
}
.plan-card-name {
  font-size: 0.9375rem;
  font-weight: 700;
  color: var(--text);
}
.plan-card-price {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--accent);
}
.plan-card-price span {
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-3);
  margin-left: 1px;
}
.plan-card-features {
  list-style: none;
  padding: 0;
  font-size: 0.8125rem;
  color: var(--text-2);
  line-height: 1.7;
}
.plan-card-features li::before {
  content: '✓';
  color: var(--success);
  font-weight: 700;
  margin-right: 6px;
}
.plan-card-cta {
  width: 100%;
}
.plan-card-cta:disabled {
  opacity: 0.7;
  cursor: not-allowed;
}
@media (max-width: 600px) {
  .plan-grid,
  .plan-grid.plan-grid-3 { grid-template-columns: 1fr; }
}

/* ═══════════════════════════════════════════════
   ADMIN DASHBOARD
═══════════════════════════════════════════════ */
.admin-body {
  display: block;
  background: var(--bg);
  font-family: var(--font);
}
.admin-topbar {
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
}
.admin-topbar-inner {
  max-width: 1240px;
  margin: 0 auto;
  padding: 14px 24px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.admin-brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-size: 1rem;
  text-decoration: none;
  color: var(--text);
}
.admin-brand .brand-gem { color: var(--accent); font-size: 1.1rem; }
.admin-topbar-right {
  display: inline-flex;
  align-items: center;
  gap: 12px;
}
.admin-user {
  font-size: 0.8125rem;
  color: var(--text-2);
}

.admin-main {
  max-width: 1240px;
  margin: 0 auto;
  padding: 32px 24px 60px;
}

.admin-gate {
  text-align: center;
  padding: 60px 24px;
}
.admin-gate h2 { font-size: 1.25rem; margin-bottom: 8px; }
.admin-gate p  { color: var(--text-2); margin-bottom: 20px; }
.admin-gate code {
  background: var(--surface);
  padding: 2px 6px;
  border-radius: 4px;
  font-family: ui-monospace, monospace;
  font-size: 0.8125rem;
}

.admin-h1 {
  font-size: 1.5rem;
  font-weight: 700;
  margin-bottom: 22px;
}

.stat-grid {
  display: flex;
  flex-direction: column;
  gap: 28px;
  margin-bottom: 40px;
}
.stat-section { display: flex; flex-direction: column; gap: 12px; }
.stat-section-heading {
  font-size: 0.8125rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-3);
  margin: 0;
  padding-bottom: 4px;
  border-bottom: 1px solid var(--border);
}
.stat-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 14px;
}
.stat-gaps .gap-list {
  margin: 0;
  padding: 0 0 0 1.25rem;
  font-size: 0.875rem;
  color: var(--text-2);
  line-height: 1.6;
}
.stat-gaps .gap-list li { margin-bottom: 10px; }
.stat-gaps .gap-fix {
  color: var(--text-3);
  font-size: 0.8125rem;
  margin-top: 2px;
}
.stat-gaps .gap-sql {
  margin-top: 14px;
  font-size: 0.8125rem;
}
.stat-gaps .gap-sql summary {
  cursor: pointer;
  color: var(--accent);
  font-weight: 600;
}
.stat-gaps .gap-sql pre {
  background: var(--surface);
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  overflow-x: auto;
  font-family: ui-monospace, 'SF Mono', Menlo, monospace;
  font-size: 0.75rem;
  line-height: 1.55;
  margin-top: 8px;
}
.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  box-shadow: var(--shadow-sm);
  transition: box-shadow var(--tr);
}
.stat-card:hover { box-shadow: var(--shadow); }
.stat-card-label {
  font-size: 0.75rem;
  color: var(--text-3);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 600;
  margin-bottom: 8px;
}
.stat-card-value {
  font-size: 1.875rem;
  font-weight: 700;
  color: var(--text);
  line-height: 1.1;
}
.stat-card-hint {
  font-size: 0.75rem;
  color: var(--text-3);
  margin-top: 4px;
}
.admin-loading { padding: 30px; color: var(--text-3); text-align: center; }

.admin-section {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  margin-bottom: 30px;
}
.admin-section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 22px;
  border-bottom: 1px solid var(--border);
}
.admin-section-head h2 { font-size: 1rem; font-weight: 600; }
.admin-count {
  font-size: 0.75rem;
  color: var(--text-3);
  background: var(--surface);
  padding: 3px 9px;
  border-radius: 999px;
}

.admin-table-wrap { overflow-x: auto; }
.admin-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}
.admin-table th,
.admin-table td {
  text-align: left;
  padding: 10px 22px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.admin-table th {
  font-size: 0.75rem;
  color: var(--text-3);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-weight: 600;
  background: var(--surface);
}
.admin-table tr:last-child td { border-bottom: none; }
.admin-table tr:hover td { background: rgba(0,0,0,0.015); }
.admin-empty { text-align: center; color: var(--text-3); padding: 30px !important; }

.admin-plan-tag {
  font-size: 0.6875rem;
  font-weight: 700;
  text-transform: uppercase;
  padding: 2px 8px;
  border-radius: 4px;
  letter-spacing: 0.04em;
}
.admin-plan-free    { background: var(--surface); color: var(--text-2); }
.admin-plan-starter { background: var(--accent-lt); color: var(--accent); }
.admin-plan-pro     { background: var(--accent); color: #fff; }

.admin-cell-used-high { color: #b8650f; font-weight: 600; }
.admin-cell-used-full { color: var(--error); font-weight: 700; }

.admin-footer {
  text-align: center;
  font-size: 0.8125rem;
  color: var(--text-3);
  margin-top: 20px;
}
