/* =========================================================
   Lingora — Design System
   Modern · Soft · Clean
   ========================================================= */

/* ---------- 1. Design Tokens ---------- */
:root {
  /* Brand */
  --primary:        #6366f1;
  --primary-hover:  #4f46e5;
  --primary-soft:   #eef2ff;
  --primary-ring:   rgba(99, 102, 241, .18);

  /* Accents */
  --success:        #10b981;
  --success-soft:   #ecfdf5;
  --warning:        #f59e0b;
  --warning-soft:   #fffbeb;
  --danger:         #ef4444;
  --danger-soft:    #fef2f2;
  --info:           #0ea5e9;
  --info-soft:      #f0f9ff;

  /* Surfaces */
  --bg:             #f6f7fb;
  --surface:        #ffffff;
  --surface-muted:  #fafbfd;
  --border:         #e8eaf2;
  --border-strong:  #d9dce8;

  /* Text */
  --text:           #1f2437;
  --text-body:      #4a5168;
  --text-muted:     #7b8299;
  --text-faint:     #a3a9bd;

  /* Radii */
  --r-sm:   8px;
  --r-md:   10px;
  --r-lg:   14px;
  --r-xl:   20px;
  --r-full: 999px;

  /* Shadows */
  --shadow-xs: 0 1px 2px rgba(20, 25, 45, .04);
  --shadow-sm: 0 1px 3px rgba(20, 25, 45, .06), 0 1px 2px rgba(20, 25, 45, .04);
  --shadow-md: 0 4px 16px rgba(20, 25, 45, .06);
  --shadow-lg: 0 12px 32px rgba(20, 25, 45, .10);

  /* Layout */
  --sidebar-w:      248px;
  --footer-h:       52px;

  /* Type scale */
  --text-xs:  12px;
  --text-sm:  13px;
  --text-base:14px;
  --text-md:  16px;
  --text-lg:  20px;
  --text-xl:  26px;

  /* Motion */
  --ease: cubic-bezier(.4, 0, .2, 1);
}

/* ---------- 2. Base ---------- */
*, *::before, *::after { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  padding: 0;
}

body {
  background: var(--bg);
  color: var(--text-body);
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI",
               "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  font-size: var(--text-base);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

h1, h2, h3, h4 { color: var(--text); margin: 0; font-weight: 600; line-height: 1.3; }
p { margin: 0; }
a { color: var(--primary); text-decoration: none; transition: color .15s var(--ease); }
a:hover { color: var(--primary-hover); }

::selection { background: var(--primary-ring); color: var(--primary-hover); }

/* Scrollbars */
.content-container::-webkit-scrollbar,
.modal-card::-webkit-scrollbar,
.sidebar::-webkit-scrollbar { width: 10px; height: 10px; }
.content-container::-webkit-scrollbar-thumb,
.modal-card::-webkit-scrollbar-thumb,
.sidebar::-webkit-scrollbar-thumb {
  background: #dcdfeb; border-radius: 999px; border: 3px solid transparent;
  background-clip: content-box;
}
.content-container::-webkit-scrollbar-thumb:hover { background: #c3c8db; background-clip: content-box; }

/* ---------- 3. App Shell ---------- */
.app-container {
  display: flex;
  height: calc(100vh - var(--footer-h));
  width: 100%;
}

.main-content-wrapper {
  margin-left: var(--sidebar-w);
  width: calc(100% - var(--sidebar-w));
  height: 100%;
  position: relative;
}

.content-container {
  position: absolute;
  inset: 0;
  overflow-y: auto;
  overflow-x: hidden;
}

.content-loading-area { width: 100%; min-height: 100%; }

/* Standalone pages (login / register) render without the sidebar, so the
   content area must not keep reserving the sidebar gutter. */
body.auth-layout .main-content-wrapper { margin-left: 0; width: 100%; }

/* ---------- 4. Sidebar ---------- */
.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  position: fixed;
  inset: 0 auto 0 0;
  height: 100%;
  display: flex;
  flex-direction: column;
  z-index: 60;
  transition: transform .25s var(--ease);
}

.sidebar-header {
  padding: 20px 18px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 72px;
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text);
  text-decoration: none;
  min-width: 0;
}

.brand-mark {
  width: 34px; height: 34px;
  flex-shrink: 0;
  border-radius: 10px;
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  display: grid;
  place-items: center;
  color: #fff;
  font-size: 15px;
  box-shadow: 0 4px 12px rgba(99, 102, 241, .28);
}

.sidebar-logo-text {
  font-size: 14px;
  font-weight: 650;
  letter-spacing: -.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-menu {
  list-style: none;
  margin: 0;
  padding: 14px 12px;
  flex: 1;
  overflow-y: auto;
}

.sidebar-menu-item { margin-bottom: 2px; }

.sidebar-menu-link {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 9px 12px;
  border-radius: var(--r-md);
  color: var(--text-body);
  font-size: var(--text-sm);
  font-weight: 500;
  text-decoration: none;
  cursor: pointer;
  transition: background .15s var(--ease), color .15s var(--ease);
  user-select: none;
}

.sidebar-menu-link:hover {
  background: var(--surface-muted);
  color: var(--text);
}

.sidebar-menu-link.active {
  background: var(--primary-soft);
  color: var(--primary-hover);
  font-weight: 600;
}

.sidebar-menu-link.active .sidebar-menu-icon { color: var(--primary); }

.sidebar-menu-icon {
  width: 18px;
  text-align: center;
  font-size: 15px;
  color: var(--text-faint);
  flex-shrink: 0;
  transition: color .15s var(--ease);
}

.sidebar-menu-link:hover .sidebar-menu-icon { color: var(--primary); }

.sidebar-section-label {
  padding: 14px 12px 6px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--text-faint);
}

/* User area */
.sidebar-user-area {
  border-top: 1px solid var(--border);
  padding: 12px;
  background: var(--surface);
  position: relative;
}

.user-trigger {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: var(--r-md);
  cursor: pointer;
  transition: background .15s var(--ease);
}
.user-trigger:hover { background: var(--surface-muted); }

.user-avatar {
  width: 34px; height: 34px;
  border-radius: var(--r-full);
  object-fit: cover;
  flex-shrink: 0;
  background: var(--primary-soft);
  border: 1px solid var(--border);
}

.user-info { display: flex; flex-direction: column; min-width: 0; flex: 1; }

.user-name {
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--text);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.user-role {
  font-size: 11px;
  color: var(--text-faint);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.user-trigger .fa-chevron-right { color: var(--text-faint); font-size: 11px; transition: transform .2s var(--ease); }

.user-dropdown-menu {
  display: none;
  position: absolute;
  bottom: calc(100% + 6px);
  left: 12px;
  right: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-lg);
  padding: 6px;
  z-index: 70;
}
.user-dropdown-menu.show { display: block; animation: popIn .14s var(--ease); }
@keyframes popIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

.user-dropdown-item {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px;
  border-radius: var(--r-sm);
  font-size: var(--text-sm);
  color: var(--text-body);
  transition: background .15s var(--ease), color .15s var(--ease);
}
.user-dropdown-item i { width: 16px; text-align: center; color: var(--text-faint); }
.user-dropdown-item:hover { background: var(--surface-muted); color: var(--text); }
.user-dropdown-item:hover i { color: var(--primary); }
.user-dropdown-item.logout { color: var(--danger); }
.user-dropdown-item.logout i { color: var(--danger); }
.user-dropdown-item.logout:hover { background: var(--danger-soft); }
.user-dropdown-divider { height: 1px; background: var(--border); margin: 5px 6px; }

/* ---------- 5. Page Scaffold ---------- */
.page-container {
  padding: 28px 32px 40px;
  min-height: 100%;
}

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 20px;
  flex-wrap: wrap;
  margin-bottom: 24px;
}

.page-title {
  font-size: var(--text-xl);
  font-weight: 680;
  letter-spacing: -.02em;
  display: flex;
  align-items: center;
  gap: 11px;
}
.page-title i { color: var(--primary); font-size: 21px; }

.page-subtitle {
  margin-top: 6px;
  font-size: var(--text-sm);
  color: var(--text-muted);
}

.page-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

/* ---------- 6. Cards ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-xs);
  margin-bottom: 20px;
  overflow: hidden;
}
.card:last-child { margin-bottom: 0; }

.card-body { padding: 20px; }

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.card-title { font-size: var(--text-md); font-weight: 640; }
.card-header-actions { display: flex; align-items: center; gap: 8px; }

.card-footer {
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  background: var(--surface-muted);
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: wrap;
}

/* ---------- 7. Stats ---------- */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 18px 20px;
  box-shadow: var(--shadow-xs);
  display: flex;
  align-items: center;
  gap: 14px;
  transition: box-shadow .2s var(--ease), transform .2s var(--ease);
}
.stat-card:hover { box-shadow: var(--shadow-md); transform: translateY(-2px); }

.stat-icon {
  width: 42px; height: 42px;
  flex-shrink: 0;
  border-radius: 12px;
  display: grid; place-items: center;
  font-size: 17px;
  background: var(--primary-soft);
  color: var(--primary);
}
.stat-icon.is-success { background: var(--success-soft); color: var(--success); }
.stat-icon.is-warning { background: var(--warning-soft); color: var(--warning); }
.stat-icon.is-info    { background: var(--info-soft);    color: var(--info); }
.stat-icon.is-neutral { background: var(--surface-muted); color: var(--text-muted); }

.stat-content { min-width: 0; }
.stat-value {
  font-size: 24px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -.02em;
  line-height: 1.2;
}
.stat-label {
  font-size: var(--text-xs);
  color: var(--text-muted);
  margin-top: 2px;
}

/* ---------- 8. Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 9px 16px;
  border: 1px solid transparent;
  border-radius: var(--r-md);
  font-size: var(--text-sm);
  font-weight: 550;
  font-family: inherit;
  cursor: pointer;
  white-space: nowrap;
  text-decoration: none;
  transition: background .15s var(--ease), border-color .15s var(--ease),
              color .15s var(--ease), box-shadow .15s var(--ease), transform .1s var(--ease);
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: not-allowed; transform: none; }
.btn:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--primary-ring); }

.btn-primary {
  background: var(--primary);
  color: #fff;
  box-shadow: 0 1px 2px rgba(99, 102, 241, .25);
}
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); color: #fff; }

.btn-secondary {
  background: var(--surface);
  color: var(--text-body);
  border-color: var(--border-strong);
}
.btn-secondary:hover:not(:disabled) { background: var(--surface-muted); color: var(--text); border-color: #c7ccdd; }

.btn-default { background: var(--surface-muted); color: var(--text-body); border-color: var(--border); }
.btn-default:hover:not(:disabled) { background: #f1f3f9; }

.btn-ghost { background: transparent; color: var(--text-muted); }
.btn-ghost:hover:not(:disabled) { background: var(--surface-muted); color: var(--text); }

.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover:not(:disabled) { background: #dc2626; color: #fff; }

.btn-sm { padding: 6px 11px; font-size: var(--text-xs); border-radius: var(--r-sm); }
.btn-lg { padding: 12px 20px; font-size: var(--text-base); }
.btn-block { width: 100%; }

.btn-icon {
  width: 32px; height: 32px;
  padding: 0;
  border-radius: var(--r-sm);
  display: inline-grid;
  place-items: center;
}

/* ---------- 9. Forms ---------- */
.form-group { margin-bottom: 16px; }
.form-group:last-child { margin-bottom: 0; }

.form-label {
  display: block;
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--text-body);
  margin-bottom: 6px;
}

.form-input,
.form-select,
.form-textarea {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--r-md);
  background: var(--surface);
  color: var(--text);
  font-size: var(--text-sm);
  font-family: inherit;
  outline: none;
  transition: border-color .15s var(--ease), box-shadow .15s var(--ease);
}
.form-textarea { resize: vertical; min-height: 76px; line-height: 1.6; }

.form-input::placeholder,
.form-textarea::placeholder { color: var(--text-faint); }

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-ring);
}

.form-select {
  appearance: none;
  cursor: pointer;
  padding-right: 32px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%237b8299' d='M6 8.2L1.8 4h8.4z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 11px center;
}

.filter-select { width: auto; min-width: 150px; }

.form-hint { font-size: 11px; color: var(--text-faint); margin-top: 5px; }

.form-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
}

.checkbox-field,
.radio-field {
  display: flex;
  align-items: flex-start;
  gap: 9px;
  font-size: var(--text-sm);
  color: var(--text-body);
  cursor: pointer;
}
.checkbox-field input,
.radio-field input { accent-color: var(--primary); width: 15px; height: 15px; margin-top: 2px; flex-shrink: 0; }

/* Toggle-ish option tiles (used in settings) */
.option-tile {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 13px 15px;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  cursor: pointer;
  background: var(--surface);
  transition: border-color .15s var(--ease), background .15s var(--ease);
}
.option-tile:hover { border-color: var(--border-strong); background: var(--surface-muted); }
.option-tile input { accent-color: var(--primary); width: 16px; height: 16px; margin-top: 2px; flex-shrink: 0; }
.option-tile-title { font-size: var(--text-sm); font-weight: 600; color: var(--text); }
.option-tile-desc { font-size: var(--text-xs); color: var(--text-muted); margin-top: 1px; }

/* ---------- 10. Badges & Pills ---------- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 9px;
  border-radius: var(--r-full);
  font-size: 11px;
  font-weight: 600;
  line-height: 1.7;
  white-space: nowrap;
}
.badge-primary { background: var(--primary-soft); color: var(--primary-hover); }
.badge-success { background: var(--success-soft); color: #047857; }
.badge-warning { background: var(--warning-soft); color: #b45309; }
.badge-danger  { background: var(--danger-soft);  color: #b91c1c; }
.badge-info    { background: var(--info-soft);    color: #0369a1; }
.badge-neutral { background: var(--surface-muted); color: var(--text-muted); border: 1px solid var(--border); }

.status-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  display: inline-block;
  flex-shrink: 0;
  background: var(--text-faint);
}
.status-dot.is-online { background: var(--success); box-shadow: 0 0 0 3px rgba(16,185,129,.15); }
.status-dot.is-offline { background: var(--danger); box-shadow: 0 0 0 3px rgba(239,68,68,.13); }

/* ---------- 11. Progress ---------- */
.progress {
  height: 6px;
  background: #eef0f7;
  border-radius: var(--r-full);
  overflow: hidden;
}
.progress-bar {
  height: 100%;
  background: linear-gradient(90deg, var(--primary), #8b5cf6);
  border-radius: var(--r-full);
  transition: width .4s var(--ease);
}

/* ---------- 12. Lists & Empty State ---------- */
.list-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  transition: background .15s var(--ease);
}
.list-row:last-child { border-bottom: none; }
.list-row:hover { background: var(--surface-muted); }

.list-row-main { min-width: 0; flex: 1; }
.list-row-title { font-size: var(--text-base); font-weight: 600; color: var(--text); }
.list-row-meta { font-size: var(--text-xs); color: var(--text-muted); margin-top: 3px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.list-row-actions { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }

.empty-state {
  text-align: center;
  padding: 52px 24px;
  color: var(--text-muted);
}
.empty-state i {
  font-size: 40px;
  color: var(--border-strong);
  display: block;
  margin-bottom: 14px;
}
.empty-state p { font-size: var(--text-sm); }
.empty-state .empty-title { font-size: var(--text-base); font-weight: 600; color: var(--text-body); margin-bottom: 4px; }

/* ---------- 13. Module Cards ---------- */
.module-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(290px, 1fr));
  gap: 16px;
}

.module-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 20px;
  box-shadow: var(--shadow-xs);
  transition: box-shadow .2s var(--ease), transform .2s var(--ease), border-color .2s var(--ease);
}
.module-card:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-md);
  border-color: #cdd3ea;
}

.module-icon {
  width: 46px; height: 46px;
  border-radius: 13px;
  display: grid; place-items: center;
  margin-bottom: 14px;
}
.module-icon i { font-size: 19px; color: #fff; }

.module-name { font-size: var(--text-md); font-weight: 640; color: var(--text); margin-bottom: 5px; }
.module-desc { font-size: var(--text-xs); color: var(--text-muted); line-height: 1.6; }

.module-status {
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}

/* ---------- 14. Modal ---------- */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(24, 28, 45, .45);
  backdrop-filter: blur(2px);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 24px;
  z-index: 200;
  animation: fadeIn .16s var(--ease);
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.modal-card {
  background: var(--surface);
  border-radius: var(--r-xl);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 560px;
  max-height: 88vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: slideUp .2s var(--ease);
}
.modal-card.is-wide { max-width: 880px; }
@keyframes slideUp { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 22px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.modal-title { font-size: var(--text-md); font-weight: 640; }
.modal-body { padding: 22px; overflow-y: auto; flex: 1; }
.modal-footer {
  padding: 14px 22px;
  border-top: 1px solid var(--border);
  background: var(--surface-muted);
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: wrap;
  flex-shrink: 0;
}

.modal-close {
  width: 30px; height: 30px;
  border: none;
  background: var(--surface-muted);
  color: var(--text-muted);
  border-radius: var(--r-sm);
  cursor: pointer;
  display: grid; place-items: center;
  font-size: 13px;
  transition: background .15s var(--ease), color .15s var(--ease);
}
.modal-close:hover { background: var(--danger-soft); color: var(--danger); }

/* Legacy inline-modal compatibility: pages still use .modal > .card */
.modal > .card {
  border-radius: var(--r-xl);
  border: none;
  box-shadow: var(--shadow-lg);
  max-height: 88vh;
  display: flex;
  flex-direction: column;
  margin: 0;
  animation: slideUp .2s var(--ease);
}
.modal > .card > .card-header { flex-shrink: 0; }

/* ---------- 15. Auth Layout ---------- */
.auth-page {
  display: grid;
  place-items: center;
  min-height: 100%;
  padding: 40px 24px;
}

.auth-card {
  width: 100%;
  max-width: 420px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-xl);
  box-shadow: var(--shadow-md);
  padding: 36px 32px 28px;
}

.auth-brand {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-bottom: 22px;
}
.auth-title {
  font-size: 22px;
  font-weight: 680;
  text-align: center;
  letter-spacing: -.02em;
  margin-bottom: 6px;
}
.auth-subtitle { text-align: center; font-size: var(--text-sm); color: var(--text-muted); margin-bottom: 26px; }

.auth-divider {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 22px 0;
  color: var(--text-faint);
  font-size: 11px;
}
.auth-divider::before, .auth-divider::after {
  content: ""; flex: 1; height: 1px; background: var(--border);
}

.auth-footer {
  margin-top: 20px;
  padding-top: 18px;
  border-top: 1px solid var(--border);
  text-align: center;
  font-size: var(--text-sm);
  color: var(--text-muted);
}

.demo-hint {
  margin-top: 16px;
  padding: 11px 14px;
  background: var(--primary-soft);
  border: 1px dashed #c7cdfa;
  border-radius: var(--r-md);
  font-size: var(--text-xs);
  color: var(--primary-hover);
  text-align: center;
}

.auth-aside {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  font-size: var(--text-xs);
  color: var(--text-muted);
}

/* ---------- 16. Settings / Sections ---------- */
.settings-section { margin-bottom: 20px; }
.section-note {
  margin-top: 14px;
  padding: 14px 16px;
  background: var(--surface-muted);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  font-size: var(--text-xs);
  color: var(--text-muted);
  line-height: 1.65;
}

.danger-zone { border-color: #f3c7c7; }
.danger-zone .card-header { background: var(--danger-soft); border-bottom-color: #f7d4d4; }
.danger-zone .card-title { color: #b91c1c; }

/* Toggle switch */
.switch { position: relative; display: inline-flex; align-items: center; cursor: pointer; flex-shrink: 0; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch-track {
  width: 38px; height: 22px;
  background: #d3d8e8;
  border-radius: var(--r-full);
  transition: background .2s var(--ease);
  position: relative;
}
.switch-track::after {
  content: "";
  position: absolute;
  top: 3px; left: 3px;
  width: 16px; height: 16px;
  background: #fff;
  border-radius: 50%;
  box-shadow: var(--shadow-xs);
  transition: transform .2s var(--ease);
}
.switch input:checked + .switch-track { background: var(--primary); }
.switch input:checked + .switch-track::after { transform: translateX(16px); }
.switch input:focus-visible + .switch-track { box-shadow: 0 0 0 3px var(--primary-ring); }

/* ---------- 17. Listening page specifics ---------- */
.controller,
.contoller {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  padding: 0 0 20px;
}

.listening-settings {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  padding: 10px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-xs);
}
.listening-settings label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: var(--text-xs);
  font-weight: 550;
  color: var(--text-body);
  white-space: nowrap;
}
.listening-settings input[type="number"] {
  width: 62px;
  padding: 5px 8px;
  border: 1px solid var(--border-strong);
  border-radius: var(--r-sm);
  font-size: var(--text-xs);
  font-family: inherit;
  color: var(--text);
  outline: none;
  transition: border-color .15s var(--ease), box-shadow .15s var(--ease);
}
.listening-settings input[type="number"]:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-ring);
}
.listening-settings select {
  padding: 5px 26px 5px 8px;
  border: 1px solid var(--border-strong);
  border-radius: var(--r-sm);
  font-size: var(--text-xs);
  font-family: inherit;
  background: var(--surface);
  color: var(--text);
  outline: none;
  cursor: pointer;
}
.listening-settings input[type="checkbox"] { accent-color: var(--primary); width: 15px; height: 15px; }

.attempt-count-field {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: var(--text-xs);
  font-weight: 550;
  color: var(--text-body);
  padding: 7px 12px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-md);
  white-space: nowrap;
}
.attempt-count-field input {
  width: 58px;
  padding: 5px 8px;
  border: 1px solid var(--border-strong);
  border-radius: var(--r-sm);
  font-size: var(--text-xs);
  font-family: inherit;
  outline: none;
}
.attempt-count-field input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-ring); }

.generation-status {
  font-size: var(--text-xs);
  color: var(--text-muted);
  display: inline-flex;
  align-items: center;
  gap: 7px;
}

.accuracy-summary {
  padding: 11px 20px;
  background: var(--primary-soft);
  border-bottom: 1px solid var(--border);
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--primary-hover);
}

/* ---------- 18. Footer ---------- */
.app-footer {
  height: var(--footer-h);
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  flex-wrap: wrap;
  font-size: var(--text-xs);
  color: var(--text-faint);
  padding: 0 20px;
}
.app-footer a { color: var(--text-muted); }
.app-footer a:hover { color: var(--primary); }
.footer-sep { color: var(--border-strong); }

/* ---------- 19. Utilities ---------- */
.flex { display: flex; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-8 { gap: 8px; }
.gap-12 { gap: 12px; }
.flex-wrap { flex-wrap: wrap; }
.mr-2 { margin-right: 8px; }
.ml-auto { margin-left: auto; }
.mt-16 { margin-top: 16px; }
.mb-16 { margin-bottom: 16px; }
.text-muted { color: var(--text-muted); }
.text-xs { font-size: var(--text-xs); }
.text-sm { font-size: var(--text-sm); }
.fw-600 { font-weight: 600; }
.hidden { display: none !important; }

.transition-transform { transition: transform .2s var(--ease); }

.sidebar-close-btn { display: none; }

/* ---------- 20. Responsive ---------- */
@media (max-width: 1024px) {
  .page-container { padding: 24px 20px 36px; }
}

@media (max-width: 860px) {
  .sidebar { transform: translateX(-100%); box-shadow: var(--shadow-lg); }
  .sidebar.is-open { transform: none; }
  .main-content-wrapper { margin-left: 0; width: 100%; }
  .sidebar-close-btn {
    display: grid; place-items: center;
    width: 30px; height: 30px;
    border: none; background: var(--surface-muted);
    color: var(--text-muted); border-radius: var(--r-sm); cursor: pointer;
  }
  .mobile-menu-btn { display: inline-flex !important; }
  .stat-grid { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
  .page-header { align-items: flex-start; }
  .modal { padding: 12px; }
}

.mobile-menu-btn {
  display: none;
  position: fixed;
  left: 14px; bottom: 18px;
  z-index: 80;
  width: 46px; height: 46px;
  border: none;
  border-radius: var(--r-full);
  background: var(--primary);
  color: #fff;
  font-size: 17px;
  box-shadow: var(--shadow-lg);
  cursor: pointer;
  align-items: center;
  justify-content: center;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

/* ---------------------------------------------------------------------------
   Reinforcement drill -- the targeted practice attached to one submission.
   --------------------------------------------------------------------------- */
.reinforce {
  margin-top: 18px;
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  background: linear-gradient(180deg, #fbfcff 0%, var(--surface) 60%);
  overflow: hidden;
}
.reinforce-head {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 16px 18px 12px;
  border-bottom: 1px solid var(--border);
}
.reinforce-head .rh-icon {
  width: 34px;
  height: 34px;
  flex: 0 0 34px;
  border-radius: var(--r-md);
  display: grid;
  place-items: center;
  background: var(--primary-soft);
  color: var(--primary-hover);
}
.reinforce-title {
  font-size: 15px;
  font-weight: 650;
  color: var(--text);
  margin: 0;
}
.reinforce-sub {
  margin: 2px 0 0;
  font-size: var(--text-xs);
  color: var(--text-muted);
}
.reinforce-note {
  padding: 12px 18px;
  font-size: var(--text-sm);
  line-height: 1.65;
  color: var(--text-body);
  background: var(--info-soft);
  border-bottom: 1px solid var(--border);
}
.skill-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 10px 18px 0;
}
.skill-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px;
  border-radius: var(--r-full);
  font-size: var(--text-xs);
  font-weight: 600;
  background: var(--surface-muted);
  border: 1px solid var(--border);
  color: var(--text-body);
}
.skill-chip.sev-high   { background: var(--danger-soft);  border-color: #fecaca; color: #b91c1c; }
.skill-chip.sev-medium { background: var(--warning-soft); border-color: #fde68a; color: #b45309; }
.skill-chip.sev-low    { background: var(--success-soft); border-color: #a7f3d0; color: #047857; }

.reinforce-item {
  padding: 16px 18px;
  border-top: 1px solid var(--border);
}
.reinforce-item:first-child { border-top: 0; }
.ri-head {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}
.ri-index {
  width: 22px;
  height: 22px;
  flex: 0 0 22px;
  border-radius: var(--r-full);
  display: grid;
  place-items: center;
  font-size: var(--text-xs);
  font-weight: 700;
  background: var(--primary-soft);
  color: var(--primary-hover);
}
.ri-player {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}
.speed-group {
  display: inline-flex;
  border: 1px solid var(--border-strong);
  border-radius: var(--r-full);
  overflow: hidden;
  background: var(--surface);
}
.speed-btn {
  border: 0;
  background: transparent;
  padding: 4px 12px;
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
}
.speed-btn + .speed-btn { border-left: 1px solid var(--border); }
.speed-btn.active { background: var(--primary); color: #fff; }
.ri-question {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  margin: 0 0 10px;
}
.ri-options { display: grid; gap: 8px; }
.ri-option {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: var(--surface);
  cursor: pointer;
  font-size: var(--text-sm);
  color: var(--text-body);
  transition: border-color .15s, background .15s;
}
.ri-option:hover { border-color: var(--border-strong); background: var(--surface-muted); }
.ri-option input { accent-color: var(--primary); }
.ri-option.selected { border-color: var(--primary); background: var(--primary-soft); }
.ri-option.correct  { border-color: var(--success); background: var(--success-soft); color: #047857; }
.ri-option.wrong    { border-color: var(--danger);  background: var(--danger-soft);  color: #b91c1c; }
.ri-option.locked   { cursor: default; }
.ri-hint {
  margin: 0 0 10px;
  font-size: var(--text-xs);
  color: var(--text-muted);
  font-style: italic;
}
.ri-feedback {
  margin-top: 12px;
  padding: 12px 14px;
  border-radius: var(--r-md);
  background: var(--surface-muted);
  border: 1px solid var(--border);
  font-size: var(--text-sm);
  line-height: 1.7;
  color: var(--text-body);
}
.ri-feedback .rf-line { margin: 0 0 6px; }
.ri-feedback .rf-line:last-child { margin-bottom: 0; }
.ri-feedback .rf-text {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px dashed var(--border-strong);
  font-weight: 600;
  color: var(--text);
}
/* Coach note for a wrong answer: a distinct blue block, deliberately different
   from the neutral feedback box above it, so the explanation does not read as
   one more grey line of results. */
.rf-explain { margin-top: 10px; }
.rf-explain-block {
  padding: 12px 14px;
  border: 1px solid #bfdbfe;
  border-left: 4px solid #3b82f6;
  border-radius: var(--r-md);
  background: #eff6ff;
  color: #1e3a5f;
  font-size: var(--text-sm);
  line-height: 1.75;
}
.rf-explain-head {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 0 0 6px;
  font-weight: 650;
  color: #1d4ed8;
}
.rf-explain-text { margin: 0 0 10px; }
.rf-explain-block.is-loading {
  display: flex;
  align-items: center;
  gap: 8px;
  color: #3b6ea5;
}
.rf-explain-speak { padding: 3px 12px; font-size: 12px; }
.reinforce-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  padding: 14px 18px;
  border-top: 1px solid var(--border);
  background: var(--surface-muted);
}
.reinforce-score {
  margin-left: auto;
  font-size: var(--text-sm);
  font-weight: 650;
  color: var(--text);
}
.reinforce-mastery {
  padding: 12px 18px;
  border-top: 1px solid var(--border);
  font-size: var(--text-xs);
  color: var(--text-muted);
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}
.reinforce-empty { padding: 16px 18px; font-size: var(--text-sm); color: var(--text-muted); }

/* ---------------------------------------------------------------------------
   Personal vocabulary book -- inline capture + marks
   --------------------------------------------------------------------------- */
mark.vocab-mark {
  background: #fef3c7;
  color: inherit;
  padding: 1px 2px;
  border-radius: 3px;
  box-shadow: inset 0 -1px 0 #fcd34d;
  transition: background .3s ease, box-shadow .3s ease;
}
mark.vocab-mark:hover { background: #fde68a; cursor: help; }
mark.vocab-mark.just-added {
  background: #a7f3d0;
  box-shadow: inset 0 -1px 0 #34d399;
}

.vocab-popover {
  position: fixed;
  z-index: 4000;
  width: 268px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-md);
  box-shadow: 0 12px 32px rgba(15, 23, 42, .16);
  font-size: var(--text-sm);
  opacity: 0;
  transform: translateY(4px);
  pointer-events: none;
  transition: opacity .12s ease, transform .12s ease;
}
.vocab-popover.visible { opacity: 1; transform: translateY(0); pointer-events: auto; }
.vocab-pop-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-muted);
  border-radius: var(--r-md) var(--r-md) 0 0;
}
.vocab-pop-term {
  font-weight: 650;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.vocab-pop-close {
  border: 0;
  background: transparent;
  font-size: 18px;
  line-height: 1;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0 2px;
}
.vocab-pop-close:hover { color: var(--text); }
.vocab-pop-body { padding: 10px 12px; }
.vocab-pop-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 10px;
}
.vocab-tag {
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text-body);
  border-radius: var(--r-full);
  padding: 3px 10px;
  font-size: var(--text-xs);
  font-weight: 600;
  cursor: pointer;
  transition: background .12s, border-color .12s, color .12s;
}
.vocab-tag:hover { border-color: var(--primary); color: var(--primary-hover); }
.vocab-tag.selected {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}
.vocab-pop-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.vocab-pop-hint { font-size: var(--text-xs); color: var(--text-muted); }
.vocab-pop-save,
.vocab-pop-remove {
  border: 0;
  border-radius: var(--r-sm);
  padding: 6px 16px;
  font-size: var(--text-xs);
  font-weight: 650;
  cursor: pointer;
  color: #fff;
  background: var(--primary);
}
.vocab-pop-save:hover { background: var(--primary-hover); }
.vocab-pop-remove { background: var(--danger); }
.vocab-pop-save:disabled,
.vocab-pop-remove:disabled { opacity: .6; cursor: default; }
.vocab-pop-status {
  margin-top: 8px;
  font-size: var(--text-xs);
  color: var(--text-muted);
}
.vocab-pop-status.ok { color: #047857; }
.vocab-pop-status.err { color: #b91c1c; }
.vocab-pop-saved {
  display: flex;
  align-items: center;
  gap: 6px;
  color: #047857;
  font-size: var(--text-xs);
  font-weight: 600;
  margin-bottom: 10px;
}

/* Touch devices (tablets / phones): enlarge tap targets so the popover is
   comfortable to use without a mouse. Gated to coarse pointers only. */
@media (hover: none) and (pointer: coarse) {
  .vocab-tag {
    padding: 8px 14px;
    font-size: var(--text-sm);
    min-height: 36px;
  }
  .vocab-pop-save,
  .vocab-pop-remove {
    padding: 12px 22px;
    font-size: var(--text-sm);
    min-height: 44px;
  }
  .vocab-pop-close {
    font-size: 22px;
    padding: 2px 8px;
    min-height: 36px;
  }
  .vocab-pop-head { padding: 12px 14px; }
  .vocab-pop-body { padding: 12px 14px; }
}

/* --- vocabulary page --- */
.vocab-stat-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}
.vocab-stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 14px 16px;
}
.vocab-stat .vs-value { font-size: 24px; font-weight: 700; color: var(--text); }
.vocab-stat .vs-label { font-size: var(--text-xs); color: var(--text-muted); margin-top: 2px; }
.vocab-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-bottom: 14px;
}
.vocab-filter {
  border: 1px solid var(--border-strong);
  border-radius: var(--r-full);
  background: var(--surface);
  padding: 5px 14px;
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
}
.vocab-filter.active { background: var(--primary); border-color: var(--primary); color: #fff; }
.vocab-list { display: grid; gap: 10px; }
.vocab-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 14px 16px;
}
.vocab-card-head {
  display: flex;
  align-items: baseline;
  gap: 10px;
  flex-wrap: wrap;
}
.vocab-card-term { font-size: 16px; font-weight: 650; color: var(--text); }
.vocab-card-meta { font-size: var(--text-xs); color: var(--text-muted); margin-left: auto; }
.vocab-card-context {
  margin: 8px 0 10px;
  font-size: var(--text-sm);
  line-height: 1.65;
  color: var(--text-body);
  padding-left: 10px;
  border-left: 2px solid var(--border-strong);
}
.vocab-card-context mark { background: #fde68a; padding: 0 2px; border-radius: 2px; }
.vocab-card-tags { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.vocab-card-actions { display: flex; gap: 6px; margin-left: auto; }
.vocab-mini-btn {
  border: 1px solid var(--border-strong);
  background: var(--surface);
  border-radius: var(--r-sm);
  padding: 3px 9px;
  font-size: var(--text-xs);
  color: var(--text-muted);
  cursor: pointer;
}
.vocab-mini-btn:hover { color: var(--text); border-color: var(--primary); }
.vocab-mini-btn.danger:hover { color: #b91c1c; border-color: var(--danger); }

/* Vocabulary Book study-card layer: simplified wording first, full card on
   demand. Visual twin of the review page's .vr-simple block. */
.vocab-card-meaning-cta { margin: 0 0 10px; }
.vocab-card-meaning { margin: 0 0 12px; }
.vbk-simple {
  background: var(--primary-soft);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 12px 14px;
  margin-bottom: 10px;
}
.vbk-simple-label {
  font-size: var(--text-xs);
  font-weight: 650;
  color: var(--primary);
  margin-bottom: 6px;
}
.vbk-simple-def { font-size: var(--text-md); color: var(--text); margin-bottom: 8px; line-height: 1.6; }
.vbk-label { font-size: var(--text-xs); font-weight: 650; color: var(--text-muted); margin: 10px 0 6px; }
.vbk-def { font-size: var(--text-sm); color: var(--text-body); line-height: 1.65; }
.vbk-example { margin-top: 6px; padding-left: 10px; border-left: 2px solid var(--border-strong); }
.vbk-example-sentence { font-size: var(--text-sm); color: var(--text-body); line-height: 1.6; }
.vbk-example-gloss { font-size: var(--text-xs); color: var(--text-muted); margin-top: 2px; }
.vbk-collocations { display: flex; flex-wrap: wrap; gap: 6px; }
.vbk-collocation {
  font-size: var(--text-xs);
  background: var(--surface-muted);
  border: 1px solid var(--border);
  border-radius: var(--r-full);
  padding: 2px 10px;
  color: var(--text-body);
}
.vbk-collocation-ex { color: var(--text-faint); font-style: italic; }
.vbk-notes { font-size: var(--text-xs); color: var(--text-muted); margin-top: 10px; }
.vbk-actions { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 4px; }
.vbk-too-hard-note { font-size: var(--text-xs); color: var(--danger); margin-top: 8px; }
.vbk-error { font-size: var(--text-xs); color: var(--danger); margin-top: 4px; }
.vocab-status-pill {
  font-size: var(--text-xs);
  font-weight: 650;
  padding: 2px 9px;
  border-radius: var(--r-full);
  background: var(--surface-muted);
  color: var(--text-muted);
  border: 1px solid var(--border);
}
.vocab-status-pill.status-learning { background: var(--info-soft); color: #1d4ed8; border-color: #bfdbfe; }
.vocab-status-pill.status-familiar { background: var(--warning-soft); color: #b45309; border-color: #fde68a; }
.vocab-status-pill.status-mastered { background: var(--success-soft); color: #047857; border-color: #a7f3d0; }
.vocab-status-pill.status-ignored { opacity: .7; text-decoration: line-through; }

/* Vocabulary load failure -- must never be mistaken for an empty book. */
.vocab-load-error .empty-title { color: #b91c1c; }
.vocab-load-error { border: 1px dashed #fca5a5; border-radius: var(--r-md); background: var(--danger-soft); }
.vocab-load-error .fa { color: #b91c1c; }

/* ===== Audio progress bar (listening player) ===== */
.audio-progress {
  position: relative;
  width: 100%;
  height: 12px;                  /* thicker, easier to grab */
  background: var(--surface-muted);
  border: 1.5px solid var(--border-strong);
  border-radius: var(--r-full);
  cursor: pointer;
  box-shadow: inset 0 1px 2px rgba(31, 36, 55, .05);
  transition: border-color .15s var(--ease), box-shadow .15s var(--ease);
}
.audio-progress:hover,
.audio-progress:focus-within {
  border-color: var(--primary);
  box-shadow: inset 0 1px 2px rgba(31, 36, 55, .05), 0 0 0 4px var(--primary-ring);
}
.audio-progress-bar {
  position: absolute;
  left: 0; top: 0; bottom: 0;
  height: 100%;
  min-width: 2px;
  background: linear-gradient(90deg, var(--primary) 0%, var(--primary-hover) 100%);
  border-radius: var(--r-full);
  transition: width .2s var(--ease);
}
/* playhead knob, only visible while interacting */
.audio-progress-bar::after {
  content: "";
  position: absolute;
  right: -6px;
  top: 50%;
  width: 13px; height: 13px;
  transform: translateY(-50%);
  background: var(--surface);
  border: 3px solid var(--primary-hover);
  border-radius: var(--r-full);
  box-shadow: 0 1px 4px rgba(31, 36, 55, .3);
  opacity: 0;
  transition: opacity .15s var(--ease);
}
.audio-progress:hover .audio-progress-bar::after,
.audio-progress:focus-within .audio-progress-bar::after { opacity: 1; }

.audio-progress-meta {
  display: flex;
  justify-content: space-between;
  margin-top: 6px;
  font-size: 12px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

/* ===== Individual lines (per-segment listen-along) ===== */
.individual-lines {
  margin-top: 18px;
  text-align: left;          /* keep the heading + rows on the left */
}
.individual-lines-title {
  display: block;
  font-size: 13px;
  font-weight: 700;
  color: var(--text-muted);
  letter-spacing: .04em;
  text-transform: uppercase;
  margin-bottom: 4px;
}
.individual-lines-hint {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 10px;
  line-height: 1.5;
}
.listening-line {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 12px;
  margin-top: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  transition: border-color .15s var(--ease), background .15s var(--ease),
              box-shadow .15s var(--ease);
}
.listening-line:hover {
  border-color: var(--border-strong);
  background: var(--surface-muted);
}
.listening-line.is-playing {
  border-color: var(--primary);
  background: var(--primary-soft);
  box-shadow: 0 0 0 3px var(--primary-ring);
}
/* Play/pause and replay are the same control in two modes, so they share every
   rule; only the icon differs. Keeping one selector list is what stops the replay
   button from drifting out of step with the player next to it. */
.listening-line .line-play-btn,
.listening-line .line-replay-btn {
  flex-shrink: 0;
  width: 34px;
  height: 34px;
  padding: 0;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--surface);
  color: var(--primary);
  border: 1px solid var(--border-strong);
  transition: background .15s var(--ease), color .15s var(--ease),
              border-color .15s var(--ease), transform .1s var(--ease);
}
.listening-line .line-play-btn:hover:not(:disabled),
.listening-line .line-replay-btn:hover:not(:disabled) {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}
.listening-line .line-play-btn:active:not(:disabled),
.listening-line .line-replay-btn:active:not(:disabled) {
  transform: scale(.95);
}
.listening-line .line-play-btn:disabled,
.listening-line .line-replay-btn:disabled {
  opacity: .45;
  cursor: not-allowed;
}
.listening-line .line-play-btn i,
.listening-line .line-replay-btn i { font-size: 11px; }
.listening-line .line-speaker {
  flex-shrink: 0;
  min-width: 64px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  letter-spacing: .02em;
}
.listening-line .line-text {
  flex: 1 1 auto;
  min-width: 0;              /* allow long sentences to wrap inside the flex row */
  font-size: 14px;
  line-height: 1.55;
  color: var(--text);
  user-select: text;         /* keep selection for vocab add */
  cursor: text;
}
.listening-line .line-text:empty::before {
  content: "(no transcript text)";
  color: var(--text-muted);
  font-style: italic;
  font-size: 12px;
}
/* Subtitle withheld: keep the flex slot so the play button and speed selector
   stay in their usual positions instead of collapsing left. */
.listening-line .line-text.is-hidden {
  visibility: hidden;
  user-select: none;
  cursor: default;
}
.listening-line .line-speed {
  flex-shrink: 0;
  padding: 5px 8px;
  border-radius: 8px;
  border: 1px solid var(--border-strong);
  background: var(--surface-muted);
  color: var(--text);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
  transition: border-color .15s var(--ease), background .15s var(--ease);
}
.listening-line .line-speed:hover { border-color: var(--primary); background: var(--surface); }
.listening-line .line-speed:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-ring); }

/* ---------- Individual lines: the sentence-analysis button ----------
   Sits next to the speed selector so "how fast" and "how is it built" are the
   two controls on a line, and shares its height so the row stays even. */
.listening-line .line-grammar-btn {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 10px;
  border-radius: 8px;
  border: 1px solid var(--border-strong);
  background: var(--surface-muted);
  color: var(--text-body);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: border-color .15s var(--ease), background .15s var(--ease),
              color .15s var(--ease);
}
.listening-line .line-grammar-btn i { font-size: 11px; }
.listening-line .line-grammar-btn:hover {
  border-color: var(--primary);
  background: var(--surface);
  color: var(--primary);
}
.listening-line .line-grammar-btn:focus-visible {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-ring);
}
.listening-line .line-grammar-btn.is-open {
  border-color: var(--primary);
  background: var(--primary-soft);
  color: var(--primary-hover);
}
.listening-line .line-grammar-btn.is-busy { opacity: .7; cursor: progress; }
.listening-line .line-grammar-btn:disabled { opacity: .45; cursor: not-allowed; }

/* The panel is a sibling of .listening-line inside .listening-line-group, so a
   long analysis never squeezes the play button out of the row. */
.listening-line-group { margin-top: 6px; }
.listening-line-group .listening-line { margin-top: 0; }

.grammar-panel {
  margin-top: 8px;
  padding: 16px 18px 14px;
  border: 1px solid var(--border);
  border-left: 3px solid var(--primary);
  border-radius: var(--r-md);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  animation: grammar-panel-in .18s var(--ease);
}
@keyframes grammar-panel-in {
  from { opacity: 0; transform: translateY(-4px); }
  to   { opacity: 1; transform: none; }
}
.grammar-panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}
.grammar-panel-title {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--text-muted);
}
.grammar-panel-close {
  border: 0;
  background: transparent;
  color: var(--text-faint);
  font-size: 13px;
  cursor: pointer;
  padding: 2px 4px;
  border-radius: 6px;
}
.grammar-panel-close:hover { color: var(--text); background: var(--surface-muted); }

/* Skeleton strip: S | V | O of the MAIN clause only. */
.grammar-skeleton {
  display: flex;
  flex-wrap: wrap;
  align-items: stretch;
  gap: 8px;
  margin-bottom: 14px;
}
.grammar-slot {
  display: flex;
  align-items: baseline;
  gap: 6px;
  padding: 5px 10px;
  border-radius: 8px;
  background: var(--surface-muted);
  border: 1px solid var(--border);
  font-size: 13px;
  max-width: 100%;
}
.grammar-slot-tag {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--text-faint);
}
.grammar-slot-value { color: var(--text); font-weight: 600; }
.grammar-slot.is-subject  { border-color: rgba(37, 99, 235, .30); }
.grammar-slot.is-subject  .grammar-slot-tag { color: #2563eb; }
.grammar-slot.is-verb     { border-color: rgba(220, 38, 38, .30); }
.grammar-slot.is-verb     .grammar-slot-tag { color: #dc2626; }
.grammar-slot.is-object   { border-color: rgba(5, 150, 105, .30); }
.grammar-slot.is-object   .grammar-slot-tag { color: #059669; }
.grammar-slot.is-empty    { opacity: .5; font-style: italic; }
.grammar-slot.is-empty    .grammar-slot-value { font-weight: 400; color: var(--text-muted); }

/* =====================================================================
   The annotation standard
   ---------------------------------------------------------------------
   One visual channel per grammatical dimension, so the three never fight:
     colour      -> syntactic ROLE      (subject / predicate / object / ...)
     typeface    -> part of SPEECH      (noun serif, verb bold, ...)
     underline   -> SUBORDINATE CLAUSE  (style + colour encode clause type)
     pill fill   -> FIXED EXPRESSION    (members of one phrase share a fill)
   A word inside a subordinate clause switches to that clause's own typeface:
   role colour and phrase fill survive, the clause now also reads as "not the
   main clause" at a glance.
   ===================================================================== */
.grammar-sentence {
  font-size: 17px;
  line-height: 2.5;
  color: var(--text);
  padding: 2px 0 6px;
  word-break: normal;
  overflow-wrap: break-word;
}

.gt {
  position: relative;
  display: inline;
  padding: 2px 1px;
  border-radius: 4px;
  cursor: help;
  user-select: text;
  color: var(--text);
  transition: background .12s var(--ease), box-shadow .12s var(--ease);
}
.gt + .gt:not(.gt-punct) { margin-left: .3em; }
/* Punctuation hugs the word before it. The 1px side padding of .gt is enough to
   make "cycle ." look like a typo, so it is dropped on both sides here. */
.gt.gt-punct { margin-left: 0; padding-left: 0; padding-right: 0; }

/* ---------- channel 1: colour = syntactic role ---------- */
.gt-role-subject        { color: #2563eb; }
.gt-role-predicate      { color: #dc2626; font-weight: 700; }
.gt-role-object         { color: #059669; }
.gt-role-indirect_object{ color: #0d9488; }
.gt-role-predicative    { color: #0891b2; }
.gt-role-object_complement { color: #db2777; }
.gt-role-attributive    { color: #7c3aed; }
.gt-role-adverbial      { color: #b45309; }
.gt-role-conjunction,
.gt-role-preposition,
.gt-role-determiner,
.gt-role-aux,
.gt-role-particle       { color: #64748b; }
.gt-role-other          { color: var(--text-body); }
.gt-role-punct          { color: var(--text-faint); }

/* ---------- channel 2: typeface = part of speech ---------- */
.gt-pos-noun       { font-family: Georgia, "Songti SC", "Times New Roman", serif; font-weight: 500; }
.gt-pos-verb       { font-family: "Segoe UI", "Helvetica Neue", system-ui, sans-serif; font-weight: 700; }
.gt-pos-adjective  { font-family: Georgia, "Times New Roman", serif; font-style: italic; }
.gt-pos-adverb     { font-style: italic; font-size: .96em; }
.gt-pos-pronoun    { font-size: .95em; }
.gt-pos-numeral    { font-variant-numeric: tabular-nums; font-weight: 600; }
.gt-pos-auxiliary,
.gt-pos-modal,
.gt-pos-determiner,
.gt-pos-preposition,
.gt-pos-conjunction,
.gt-pos-particle   { font-size: .93em; }
.gt-pos-interjection { font-style: italic; font-weight: 600; }

/* ---------- channel 3: underline = subordinate clause ----------
   Written AFTER the typeface block: same specificity, so the clause typeface
   wins inside a clause, which is exactly the point. */
.gt.is-in-clause {
  font-family: var(--gt-clause-font, Georgia, serif);
  text-underline-offset: 4px;
  text-decoration-thickness: 2px;
  text-decoration-line: underline;
  text-decoration-color: var(--gt-clause-color, #7c3aed);
}
.gt-clause-relative              { text-decoration-style: solid;  }
.gt-clause-noun                  { text-decoration-style: dotted; }
.gt-clause-adverbial_time,
.gt-clause-adverbial_reason,
.gt-clause-adverbial_condition,
.gt-clause-adverbial_concession,
.gt-clause-adverbial_purpose,
.gt-clause-adverbial_result      { text-decoration-style: dashed; }
.gt-clause-infinitive,
.gt-clause-participial           { text-decoration-style: solid; }
.gt-clause-comparative           { text-decoration-style: double; }
.gt-clause-reported_speech       { text-decoration-style: wavy; }

/* ---------- channel 4: pill fill = fixed expression ---------- */
.gt.is-in-phrase {
  background: var(--gt-phrase-bg, rgba(99, 102, 241, .12));
  border-radius: var(--r-full);
  padding: 2px 5px;
  box-shadow: inset 0 0 0 1px var(--gt-phrase-border, rgba(99, 102, 241, .28));
}
.gt.is-in-phrase + .gt.is-in-phrase { margin-left: .12em; }

/* ---------- hover: the word lifts, the whole phrase lights up ---------- */
.gt:hover,
.gt.is-hover {
  background: rgba(31, 36, 55, .06);
  box-shadow: 0 1px 0 rgba(31, 36, 55, .12);
}
.gt.is-in-phrase:hover,
.gt.is-in-phrase.is-hover {
  background: var(--gt-phrase-bg-hover, rgba(99, 102, 241, .22));
}

/* ---------- the tooltip ---------- */
.grammar-tip {
  position: fixed;
  z-index: 4000;
  min-width: 190px;
  max-width: 320px;
  padding: 10px 12px;
  border-radius: 10px;
  background: #1f2437;
  color: #f3f4f8;
  box-shadow: 0 12px 32px rgba(15, 20, 35, .28);
  font-size: 12px;
  line-height: 1.55;
  pointer-events: none;
  opacity: 0;
  transform: translateY(4px);
  transition: opacity .12s var(--ease), transform .12s var(--ease);
}
.grammar-tip.is-visible { opacity: 1; transform: none; }
.grammar-tip-head {
  display: flex;
  align-items: baseline;
  gap: 7px;
  flex-wrap: wrap;
  margin-bottom: 6px;
}
.grammar-tip-word {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: .01em;
}
.grammar-tip-lemma { color: #a9b0c6; font-size: 11px; }
.grammar-tip-badges { display: flex; gap: 5px; flex-wrap: wrap; margin-bottom: 7px; }
.grammar-tip-badge {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .04em;
  text-transform: uppercase;
  padding: 2px 6px;
  border-radius: 999px;
  background: rgba(255, 255, 255, .10);
  color: #d7dcf0;
}
.grammar-tip-badge.is-role { background: rgba(99, 102, 241, .30); color: #e4e7ff; }
.grammar-tip-row { display: flex; gap: 6px; margin-top: 4px; }
.grammar-tip-label {
  flex-shrink: 0;
  min-width: 52px;
  color: #9aa1b8;
  font-size: 11px;
}
.grammar-tip-value { flex: 1; }
.grammar-tip-value.is-sense { color: #ffe9a8; }
.grammar-tip-phrase {
  margin-top: 7px;
  padding-top: 7px;
  border-top: 1px solid rgba(255, 255, 255, .12);
  color: #c9d0e6;
}
.grammar-tip-phrase strong { color: #fff; }

/* ---------- legend ---------- */
.grammar-legend {
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px dashed var(--border);
  display: flex;
  flex-wrap: wrap;
  gap: 6px 14px;
  font-size: 11px;
  color: var(--text-muted);
}
.grammar-legend-item { display: inline-flex; align-items: center; gap: 5px; }
.grammar-legend-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: currentColor;
}
.grammar-legend-key { font-weight: 600; }
.grammar-legend-sep { flex-basis: 100%; height: 0; }
.grammar-note {
  margin-top: 10px;
  padding: 8px 10px;
  border-radius: 8px;
  background: var(--primary-soft);
  color: var(--primary-hover);
  font-size: 12px;
  line-height: 1.6;
}
/* Whole-sentence meaning, shown above the structure note so the learner reads
   "what it says" before "how it is built". Kept flat white so it does not read
   as a second note. */
.grammar-meaning {
  margin-top: 10px;
  padding: 8px 10px;
  border-radius: 8px;
  background: var(--surface, #fff);
  border: 1px solid var(--border, #e5e7eb);
  color: var(--text, #1f2437);
  font-size: 13px;
  line-height: 1.7;
}
.grammar-meaning-tag {
  display: inline-block;
  margin-right: 6px;
  padding: 0 7px;
  border-radius: 999px;
  background: var(--primary-soft);
  color: var(--primary-hover);
  font-size: 11px;
  font-weight: 600;
}

/* Ad slot at the top of the sentence-analysis panel. Same deal as the
   generation wait screen: the model call is paid for with a few seconds of
   attention, so the answer never appears at zero cost to the reader. */
.grammar-ad {
  margin: 0 0 10px;
  padding: 12px 14px;
  border: 1px dashed var(--border);
  border-radius: 10px;
  background: var(--surface-muted);
}
.grammar-ad-pitch {
  margin: 0 0 6px;
  font-size: 13px;
  font-weight: 600;
  line-height: 1.55;
  color: var(--text);
}
.grammar-ad-pitch:empty { display: none; }
.grammar-ad-copy { margin: 0; font-size: 12.5px; color: var(--text-muted); line-height: 1.5; }
.grammar-ad-countdown { margin: 6px 0 0; font-size: 12px; color: var(--primary); }
.grammar-ad-countdown:empty { display: none; }

.grammar-panel-status {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--text-muted);
  padding: 6px 0;
}
.grammar-panel-status.is-error { color: var(--danger); }
.grammar-panel-status .fa { font-size: 12px; }
.grammar-panel-retry {
  border: 1px solid currentColor;
  background: transparent;
  color: inherit;
  border-radius: 6px;
  font-size: 11px;
  padding: 2px 8px;
  cursor: pointer;
}

@media (max-width: 640px) {
  .grammar-sentence { font-size: 16px; line-height: 2.35; }
  .grammar-panel { padding: 14px 12px 12px; }
}

@media (max-width: 640px) {
  .listening-line { flex-wrap: wrap; row-gap: 6px; }
  .listening-line .line-text { flex-basis: 100%; order: 5; }
  .listening-line .line-speed { order: 4; }
  /* Keep the two transport buttons together when the row wraps. */
  .listening-line .line-play-btn { order: 1; }
  .listening-line .line-replay-btn { order: 2; }
}

/* ---------- Individual lines: collapsed until asked for ----------
   The section can hold twenty rows, which buries the questions under it on a
   normal screen. It starts folded and the title becomes the disclosure. */
.individual-lines-toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s var(--ease), border-color .15s var(--ease), color .15s var(--ease);
}
.individual-lines-toggle:hover {
  border-color: var(--primary);
  background: var(--primary-soft);
  color: var(--primary-hover);
}
.individual-lines-toggle i { font-size: 10px; transition: transform .18s var(--ease); }
.individual-lines-toggle.is-open i { transform: rotate(90deg); }
.individual-lines-count {
  font-size: 10.5px;
  font-weight: 600;
  padding: 1px 7px;
  border-radius: 999px;
  background: var(--surface-muted);
  color: var(--text-muted);
}
.individual-lines-body { margin-top: 12px; }
.individual-lines-body[hidden] { display: none; }

/* ---------- Persona stage ----------
   Exercises rendered with a chosen persona show the speaker above the transport.
   Whoever is not talking is blurred back: it reads as "listening" and keeps the
   eye on the active face without hiding the other one. */
.avatar-stage {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: 16px;
  /* Deliberately capped: full-bleed faces dominate the page and make the
     transcript below feel like an afterthought. */
  max-width: 640px;
  margin: 0 auto 18px;
}
.avatar-stage.is-pair .avatar-figure { flex: 1 1 0; max-width: 300px; }
.avatar-stage.is-solo .avatar-figure { flex: 0 1 auto; max-width: 360px; }
.avatar-figure {
  position: relative;
  margin: 0;
  width: 100%;
  border-radius: var(--r-lg, 14px);
  overflow: hidden;
  background: var(--surface-muted);
  box-shadow: 0 4px 14px rgba(15, 23, 42, .12);
  transition: filter .28s var(--ease), opacity .28s var(--ease),
              transform .28s var(--ease), box-shadow .28s var(--ease);
}
.avatar-figure video {
  display: block;
  width: 100%;
  aspect-ratio: 4 / 5;
  object-fit: cover;
  background: var(--surface-muted);
}
.avatar-figure.is-speaking { box-shadow: 0 6px 20px rgba(15, 23, 42, .2); }
.avatar-figure.is-dimmed {
  filter: blur(5px) saturate(.55);
  opacity: .5;
  transform: scale(.97);
}
.avatar-name {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  padding: 14px 10px 7px;
  font-size: 11.5px;
  font-weight: 600;
  color: #fff;
  text-align: center;
  text-shadow: 0 1px 2px rgba(0, 0, 0, .45);
  background: linear-gradient(to top, rgba(15, 23, 42, .62), rgba(15, 23, 42, 0));
  pointer-events: none;
}
@media (max-width: 640px) {
  .avatar-stage { gap: 10px; }
  .avatar-figure.is-dimmed { filter: blur(3px) saturate(.6); }
}

/* ---------- Shared alert box ---------- */
.alert {
  padding: 10px 13px;
  border-radius: var(--r-md);
  font-size: var(--text-xs);
  margin-bottom: 16px;
  border: 1px solid transparent;
}
.alert-danger  { background: var(--danger-soft);  color: #b91c1c;  border-color: #f7d4d4; }
.alert-success { background: var(--success-soft); color: #15803d; border-color: #c6efdd; }
.alert-info    { background: var(--info-soft);    color: #0369a1; border-color: #cbeaf9; }

/* ---------- Scenario picker (listening) ---------- */
.scenario-shell { display: flex; flex-direction: column; gap: 18px; }
.scenario-block-title {
  display: flex; align-items: center; gap: 8px;
  font-size: 13px; font-weight: 650; color: var(--text); margin-bottom: 10px;
}
.scenario-block-title .badge { font-weight: 600; }
.scenario-list { display: flex; flex-direction: column; gap: 8px; }
.scenario-item {
  display: flex; align-items: flex-start; gap: 12px;
  padding: 11px 13px;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: var(--surface);
  cursor: pointer;
  transition: border-color .15s var(--ease), background .15s var(--ease), box-shadow .15s var(--ease);
}
.scenario-item:hover { border-color: var(--primary); background: var(--primary-soft); }
.scenario-item.is-selected {
  border-color: var(--primary);
  background: var(--primary-soft);
  box-shadow: 0 0 0 3px var(--primary-ring);
}
.scenario-item input[type="radio"] { margin-top: 3px; accent-color: var(--primary); }
.scenario-item-main { flex: 1; min-width: 0; }
.scenario-item-title { font-size: 13.5px; font-weight: 600; color: var(--text); }
.scenario-item-desc  { font-size: 12px; color: var(--text-muted); margin-top: 3px; line-height: 1.5; }
.scenario-count {
  flex-shrink: 0;
  font-size: 11px; font-weight: 600;
  padding: 3px 9px; border-radius: var(--r-full);
  background: var(--primary-soft); color: var(--primary-hover);
  border: 1px solid var(--primary-ring);
  white-space: nowrap;
}
.scenario-count.is-new { background: var(--success-soft); color: #15803d; border-color: #c6efdd; }
.scenario-custom {
  display: flex; gap: 8px; align-items: center; flex-wrap: wrap;
  margin-top: 6px; padding-top: 14px; border-top: 1px dashed var(--border);
}
.scenario-custom input[type="text"] { flex: 1; min-width: 220px; }
.scenario-hint { font-size: 12px; color: var(--text-muted); line-height: 1.6; }

/* ==========================================================================
   Reference materials (System)
   ========================================================================== */
.ref-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}

.ref-drop {
  border: 1.5px dashed var(--border-strong);
  border-radius: var(--r-lg);
  background: var(--surface-muted);
  padding: 26px 18px;
  text-align: center;
  cursor: pointer;
  transition: border-color .18s var(--ease), background .18s var(--ease);
}
.ref-drop:hover,
.ref-drop.is-over {
  border-color: var(--primary);
  background: var(--primary-soft);
}
.ref-drop-title {
  margin-top: 8px;
  font-weight: 600;
  color: var(--text);
}
.ref-drop-hint {
  margin-top: 4px;
  font-size: var(--text-xs);
  color: var(--text-muted);
}
.ref-chosen {
  margin-top: 10px;
  font-size: var(--text-sm);
  color: var(--primary);
  font-weight: 500;
}

.ref-or {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 16px 0 12px;
  color: var(--text-faint);
  font-size: var(--text-xs);
}
.ref-or::before,
.ref-or::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--border);
}

.ref-status {
  margin-top: 10px;
  font-size: var(--text-sm);
  color: var(--text-muted);
  min-height: 0;
}
.ref-status.is-error { color: var(--danger); }
.ref-status.is-ok    { color: var(--success); }

.ref-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 12px;
}

.ref-card {
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 14px 16px;
  margin-bottom: 12px;
  background: var(--surface);
  transition: border-color .18s var(--ease), box-shadow .18s var(--ease);
}
.ref-card:hover {
  border-color: var(--border-strong);
  box-shadow: var(--shadow-sm);
}
.ref-card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}
.ref-card-title {
  font-weight: 600;
  font-size: var(--text-md);
  color: var(--text);
}
.ref-card-sub {
  margin-top: 4px;
  font-size: var(--text-xs);
  color: var(--text-muted);
}
.ref-file { color: var(--text-body); }
.ref-meta { color: var(--primary); }
.ref-card-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}
.ref-summary {
  margin: 10px 0 0;
  font-size: var(--text-sm);
  color: var(--text-body);
  line-height: 1.6;
}
.ref-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
}
.ref-chip {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: var(--r-full);
  font-size: var(--text-xs);
  line-height: 1.5;
  border: 1px solid transparent;
}
.ref-chip.is-scenario {
  background: var(--primary-soft);
  color: var(--primary-hover);
  border-color: rgba(99, 102, 241, .22);
}
.ref-chip.is-industry {
  background: var(--warning-soft);
  color: #92610a;
  border-color: rgba(245, 158, 11, .28);
}

.ref-label {
  display: block;
  margin: 12px 0 6px;
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--text-body);
}
.ref-note {
  margin-top: 6px;
  font-size: var(--text-xs);
  color: var(--text-muted);
}

.ref-detail-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  font-size: var(--text-xs);
  color: var(--text-muted);
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
}
.ref-detail-block { margin-top: 14px; }
.ref-detail-block h4 {
  margin: 0 0 6px;
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--text);
}
.ref-detail-block p,
.ref-detail-block ul {
  margin: 0;
  font-size: var(--text-sm);
  color: var(--text-body);
  line-height: 1.65;
}
.ref-detail-block ul { padding-left: 20px; }
.ref-raw {
  max-height: 260px;
  overflow: auto;
  background: var(--surface-muted);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 12px;
  font-size: var(--text-xs);
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
  margin: 0;
}

/* ==========================================================================
   Listening: generation mode switch + reference picker
   ========================================================================== */
.mode-switch {
  display: inline-flex;
  padding: 3px;
  gap: 3px;
  background: var(--surface-muted);
  border: 1px solid var(--border);
  border-radius: var(--r-full);
  margin-bottom: 12px;
}
.mode-btn {
  border: 0;
  background: transparent;
  border-radius: var(--r-full);
  padding: 6px 16px;
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  transition: background .18s var(--ease), color .18s var(--ease);
}
.mode-btn:hover { color: var(--text-body); }
.mode-btn.is-active {
  background: var(--surface);
  color: var(--primary);
  box-shadow: var(--shadow-xs);
}

.ref-picker {
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 12px;
  background: var(--surface-muted);
}
.ref-option {
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: var(--surface);
  padding: 10px 12px;
  margin-bottom: 8px;
  cursor: pointer;
  transition: border-color .18s var(--ease), box-shadow .18s var(--ease);
}
.ref-option:hover { border-color: var(--border-strong); }
.ref-option.is-selected {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-ring);
}
.ref-option-title {
  font-weight: 600;
  font-size: var(--text-sm);
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 8px;
}
.ref-option-summary {
  margin-top: 4px;
  font-size: var(--text-xs);
  color: var(--text-muted);
  line-height: 1.55;
}
.ref-tag-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
}
.ref-tag-toggle {
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: var(--r-full);
  padding: 3px 10px;
  font-size: var(--text-xs);
  color: var(--text-body);
  cursor: pointer;
  transition: all .18s var(--ease);
}
.ref-tag-toggle:hover { border-color: var(--primary); }
.ref-tag-toggle.is-on {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}
.ref-empty {
  font-size: var(--text-sm);
  color: var(--text-muted);
  padding: 10px 2px;
}

@media (max-width: 640px) {
  .ref-card-head { flex-direction: column; }
  .ref-card-actions { width: 100%; }
  .mode-switch { width: 100%; }
  .mode-btn { flex: 1; }
}

/* --- vocabulary review session --- */
.vr-modebar {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}
.vr-mode {
  border: 1px solid var(--border-strong);
  background: var(--surface);
  border-radius: var(--r-full);
  padding: 6px 16px;
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 7px;
}
.vr-mode.active { background: var(--primary); border-color: var(--primary); color: #fff; }
/* Phase 2 modes are rendered but inert. Greyed out on purpose: saying they
   exist and refusing to run them is honest, hiding them is not. */
.vr-mode.disabled {
  opacity: .45;
  cursor: not-allowed;
  background: var(--surface-muted);
}
.vr-mode .vr-soon {
  font-size: 10px;
  font-weight: 600;
  padding: 1px 6px;
  border-radius: var(--r-full);
  background: var(--surface-muted);
  color: var(--text-faint);
  border: 1px solid var(--border);
}

.vr-progress {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}
.vr-progress-track {
  flex: 1;
  height: 6px;
  background: var(--surface-muted);
  border-radius: var(--r-full);
  overflow: hidden;
}
.vr-progress-fill {
  height: 100%;
  background: var(--primary);
  border-radius: var(--r-full);
  transition: width .3s var(--ease);
}
.vr-progress-label { font-size: var(--text-xs); color: var(--text-muted); white-space: nowrap; }

.vr-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 26px 28px;
  box-shadow: var(--shadow-sm);
}
.vr-tagline {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 14px;
}
.vr-tag {
  font-size: var(--text-xs);
  font-weight: 600;
  padding: 2px 9px;
  border-radius: var(--r-full);
  background: var(--primary-soft);
  color: var(--primary);
  border: 1px solid var(--primary-ring);
}
.vr-tag.mode { background: var(--info-soft); color: #1d4ed8; border-color: #bfdbfe; }

.vr-prompt {
  font-size: 26px;
  font-weight: 650;
  color: var(--text);
  line-height: 1.35;
  margin-bottom: 6px;
  word-break: break-word;
}
.vr-prompt.sentence {
  font-size: var(--text-md);
  font-weight: 400;
  line-height: 1.7;
  color: var(--text-body);
  padding: 12px 16px;
  background: var(--primary-soft);
  border-radius: var(--r-md);
}
/* The term under test inside its own sentence. It has to read as "this
   is the word being asked about" without shouting: a soft tint, not a
   hard box, so the sentence stays readable as a sentence. */
.vr-prompt .vr-term {
  background: #fde68a;
  color: var(--text);
  padding: 1px 4px;
  border-radius: 3px;
  font-weight: 600;
}
.vr-hint { font-size: var(--text-xs); color: var(--text-muted); margin-bottom: 18px; }

.vr-audio {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 18px;
  flex-wrap: wrap;
}
.vr-audio-btn {
  border: 1px solid var(--border-strong);
  background: var(--surface);
  border-radius: var(--r-sm);
  padding: 7px 14px;
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--text-body);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 7px;
}
.vr-audio-btn:hover { border-color: var(--primary); color: var(--primary); }
.vr-audio-btn:disabled { opacity: .5; cursor: default; }
.vr-audio-note { font-size: var(--text-xs); color: var(--text-faint); }

.vr-options { display: grid; gap: 10px; }
.vr-option {
  text-align: left;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  border-radius: var(--r-md);
  padding: 13px 16px;
  font-size: var(--text-base);
  color: var(--text-body);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 12px;
  transition: border-color .15s var(--ease), background .15s var(--ease);
}
.vr-option:hover:not(:disabled) { border-color: var(--primary); background: var(--primary-soft); }
.vr-option:disabled { cursor: default; }
.vr-option-key {
  flex: 0 0 24px;
  height: 24px;
  border-radius: var(--r-sm);
  background: var(--surface-muted);
  color: var(--text-muted);
  font-size: var(--text-xs);
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
}
.vr-option.correct {
  border-color: var(--success);
  background: var(--success-soft);
  color: #047857;
}
.vr-option.correct .vr-option-key { background: #a7f3d0; color: #047857; }
.vr-option.wrong {
  border-color: var(--danger);
  background: var(--danger-soft);
  color: #b91c1c;
}
.vr-option.wrong .vr-option-key { background: #fecaca; color: #b91c1c; }

/* Self-rating: a right answer the learner guessed must not advance the word. */
.vr-selfrate {
  margin-top: 18px;
  padding-top: 16px;
  border-top: 1px dashed var(--border-strong);
}
.vr-selfrate-label { font-size: var(--text-sm); font-weight: 600; color: var(--text-body); margin-bottom: 10px; }
.vr-selfrate-row { display: flex; gap: 8px; flex-wrap: wrap; }
.vr-rate {
  border: 1px solid var(--border-strong);
  background: var(--surface);
  border-radius: var(--r-sm);
  padding: 7px 14px;
  font-size: var(--text-sm);
  color: var(--text-body);
  cursor: pointer;
}
.vr-rate:hover { border-color: var(--primary); }
.vr-rate.selected { background: var(--primary); border-color: var(--primary); color: #fff; }

.vr-feedback {
  margin-top: 18px;
  padding: 16px 18px;
  border-radius: var(--r-md);
  background: var(--surface-muted);
  border: 1px solid var(--border);
}
.vr-feedback.ok { background: var(--success-soft); border-color: #a7f3d0; }
.vr-feedback.no { background: var(--danger-soft); border-color: #fecaca; }
.vr-feedback-head { font-size: var(--text-base); font-weight: 650; margin-bottom: 8px; }
.vr-feedback.ok .vr-feedback-head { color: #047857; }
.vr-feedback.no .vr-feedback-head { color: #b91c1c; }
.vr-feedback-body { font-size: var(--text-sm); line-height: 1.7; color: var(--text-body); }
.vr-feedback-body .vr-ctx {
  display: block;
  margin-top: 8px;
  padding-left: 10px;
  border-left: 2px solid var(--border-strong);
  color: var(--text-muted);
}
.vr-feedback-body .vr-ctx mark { background: #fde68a; padding: 0 2px; border-radius: 2px; }

/* Learn-before-test card: an unseen word is not a question, it is new material. */
.vr-study-term { font-size: 26px; font-weight: 650; color: var(--text); margin-bottom: 4px; }
.vr-study-pos { font-size: var(--text-xs); color: var(--text-faint); margin-bottom: 14px; }
.vr-study-def {
  font-size: var(--text-md);
  line-height: 1.7;
  color: var(--text-body);
  margin-bottom: 12px;
}
/* Pinned play/pause + replay controls on the study term and definition. They
   sit in front of the word/explanation so the learner can hear it spoken first,
   then replay either one without leaving the card. */
.vr-study-term, .vr-study-def { display: flex; align-items: flex-start; gap: 12px; flex-wrap: wrap; }
.vr-study-term > :not(.vr-audio-ctl), .vr-study-def > :not(.vr-audio-ctl) { flex: 1 1 auto; min-width: 0; }
.vr-audio-ctl { display: inline-flex; gap: 4px; margin-right: auto; flex: 0 0 auto; }
.vr-mini-btn {
  width: 30px; height: 30px;
  border-radius: 50%;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text-body);
  cursor: pointer;
  font-size: 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: border-color .15s var(--ease), color .15s var(--ease);
}
.vr-mini-btn:hover { border-color: var(--primary); color: var(--primary); }
.vr-mini-btn:disabled { opacity: .5; cursor: default; }
.vr-audio-unavail {
  font-size: var(--text-xs);
  color: var(--text-faint);
  font-style: italic;
  align-self: center;
  padding-left: 2px;
}
.vr-study-label {
  font-size: var(--text-xs);
  font-weight: 700;
  color: var(--text-faint);
  text-transform: uppercase;
  letter-spacing: .04em;
  margin: 14px 0 6px;
}
.vr-example {
  padding: 10px 0 10px 12px;
  border-left: 2px solid var(--primary-ring);
  margin-bottom: 8px;
}
.vr-example-sentence { font-size: var(--text-base); color: var(--text); line-height: 1.6; }
.vr-example-gloss { font-size: var(--text-xs); color: var(--text-muted); margin-top: 3px; }
.vr-collocations { display: flex; flex-wrap: wrap; gap: 6px; }
.vr-collocation {
  font-size: var(--text-xs);
  padding: 3px 10px;
  border-radius: var(--r-full);
  background: var(--surface-muted);
  border: 1px solid var(--border);
  color: var(--text-body);
}
.vr-notes {
  font-size: var(--text-sm);
  color: var(--text-body);
  background: var(--warning-soft);
  border: 1px solid #fde68a;
  border-radius: var(--r-md);
  padding: 10px 12px;
  margin-top: 12px;
  line-height: 1.6;
}
.vr-actions { display: flex; gap: 10px; margin-top: 20px; flex-wrap: wrap; }

/* Simplified layer: what the learner reads first, before the full card. */
.vr-simple {
  background: var(--primary-soft);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 14px 16px;
  margin-bottom: 14px;
}
.vr-simple-label {
  font-size: var(--text-xs);
  font-weight: 650;
  color: var(--primary);
  margin-bottom: 6px;
}
.vr-simple-def { font-size: var(--text-md); color: var(--text); margin-bottom: 8px; line-height: 1.6; }
.vr-simple .vr-example { margin-top: 4px; }
/* Mini example sentence attached to a collocation pattern. */
.vr-collocation-ex { color: var(--text-faint); font-style: italic; }
.vr-too-hard-note { font-size: var(--text-xs); color: var(--danger); margin-top: 8px; }

.vr-summary-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 12px; margin-bottom: 18px; }
.vr-summary {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 14px 16px;
  text-align: center;
}
.vr-summary .vs-value { font-size: 24px; font-weight: 700; color: var(--text); }
.vr-summary .vs-label { font-size: var(--text-xs); color: var(--text-muted); margin-top: 2px; }

@media (max-width: 640px) {
  .vr-card { padding: 20px 18px; }
  .vr-prompt { font-size: 21px; }
  .vr-mode { padding: 5px 12px; font-size: var(--text-xs); }
}

/* Due badge on the review card. Small and non-blocking: a dashboard that
   shouts about unfinished work gets ignored, one that states a number does not. */
.module-due {
  margin-top: 8px;
  font-size: 11px;
  font-weight: 700;
  color: var(--primary);
  background: var(--primary-soft);
  border: 1px solid var(--primary-ring);
  border-radius: var(--r-full);
  padding: 2px 9px;
  display: inline-block;
}

/* ---------- 21. Dashboard charts ---------- */
.charts-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 20px;
  margin-top: 20px;
}
.charts-grid .span-2 { grid-column: 1 / -1; }
.dash-chart-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-xs);
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.dash-chart-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 20px 0;
}
.dash-chart-title { font-size: var(--text-md); font-weight: 640; margin: 0; color: var(--text); }
.dash-chart-sub { font-size: var(--text-xs); color: var(--text-muted); margin: 3px 0 0; }
.dash-chart-body { padding: 14px 16px 18px; height: 280px; position: relative; }
.dash-chart-body.tall { height: 360px; }

/* Color key for the Practice Scores bar chart (matches scoreColor in index.html) */
.score-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 18px;
  padding: 0 16px 12px;
  font-size: var(--text-xs);
  color: var(--text-muted);
}
.sl-item { display: inline-flex; align-items: center; gap: 6px; }
.sl-swatch {
  width: 11px; height: 11px;
  border-radius: 3px;
  display: inline-block;
  flex: 0 0 auto;
}
.dash-filter {
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 6px 10px;
  font-size: var(--text-sm);
  color: var(--text);
  background: var(--surface);
  cursor: pointer;
  flex-shrink: 0;
}
.dash-chart-empty {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  color: var(--text-muted);
  gap: 6px;
  padding: 20px;
}
.dash-chart-empty i { font-size: 26px; opacity: .5; }
.dash-chart-empty .empty-title { font-weight: 600; color: var(--text-body); }
.dash-chart-empty p { font-size: var(--text-sm); margin: 0; }
.stat-value.is-text { font-size: 18px; font-weight: 680; line-height: 1.2; }

@media (max-width: 860px) {
  .charts-grid { grid-template-columns: 1fr; }
  .charts-grid .span-2 { grid-column: auto; }
}
