:root {
  --bg: #f3f5f9;
  --surface: #ffffff;
  --surface-alt: #f8fafc;
  --navy: #0f2547;
  --navy-2: #1a3a6c;
  --indigo: #4338ca;
  --indigo-soft: #eef2ff;
  --accent: #0ea5e9;
  --emerald: #059669;
  --emerald-bg: #d1fae5;
  --amber: #d97706;
  --amber-bg: #fef3c7;
  --coral: #dc2626;
  --coral-bg: #fee2e2;
  --gold: #b45309;
  --gold-bg: #fef3c7;
  --text: #0f172a;
  --muted: #475569;
  --border: #e2e8f0;
  --radius: 14px;
  --shadow: 0 6px 20px rgba(15, 37, 71, 0.06);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang TC", "Noto Sans TC", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.55;
}

.hidden {
  display: none !important;
}

/* Top Navigation */
.top-nav {
  background: linear-gradient(135deg, var(--navy) 0%, var(--navy-2) 100%);
  color: #fff;
  position: sticky;
  top: 0;
  z-index: 40;
  box-shadow: 0 4px 16px rgba(15, 37, 71, 0.22);
}

.nav-inner {
  max-width: 1220px;
  margin: 0 auto;
  padding: 10px 18px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px 14px;
  flex-wrap: wrap;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  order: 1;
}

.brand-logo {
  font-size: 1.7rem;
  line-height: 1;
}

.brand-title {
  font-weight: 800;
  font-size: 1.08rem;
  letter-spacing: -0.01em;
}

.brand-sub {
  font-size: 0.76rem;
  color: rgba(255, 255, 255, 0.78);
}

.nav-tabs {
  order: 3;
  flex: 1 0 100%;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  background: rgba(255, 255, 255, 0.11);
  padding: 5px;
  border-radius: 14px;
}

.nav-tab {
  border: 0;
  background: transparent;
  color: rgba(255, 255, 255, 0.88);
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 0.84rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.15s ease;
}

.nav-tab:hover {
  color: #fff;
  background: rgba(255, 255, 255, 0.14);
}

.nav-tab.active {
  background: #fff;
  color: var(--navy);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.14);
}

.tab-badge {
  display: inline-block;
  background: rgba(251, 191, 36, 0.25);
  color: #fde68a;
  padding: 1px 7px;
  border-radius: 999px;
  font-size: 0.75rem;
  margin-left: 4px;
}

.nav-tab.active .tab-badge {
  background: var(--indigo-soft);
  color: var(--indigo);
}

.nav-stats {
  display: flex;
  gap: 8px;
  order: 2;
}

.stat-pill {
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid rgba(255, 255, 255, 0.2);
  padding: 4px 10px;
  border-radius: 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 76px;
}

.stat-label {
  font-size: 0.67rem;
  opacity: 0.82;
}

.stat-pill strong {
  font-size: 0.9rem;
}

.warn-pill {
  background: rgba(251, 191, 36, 0.2);
  border-color: rgba(251, 191, 36, 0.45);
}

/* Main Container */
.main-wrap {
  max-width: 1220px;
  margin: 18px auto 48px;
  padding: 0 16px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 14px;
}

/* Filter Bar */
.filter-bar {
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.cat-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.cat-pill {
  border: 1px solid var(--border);
  background: var(--surface-alt);
  color: var(--muted);
  padding: 6px 13px;
  border-radius: 999px;
  font-size: 0.84rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.14s ease;
}

.cat-pill:hover {
  border-color: var(--indigo);
  color: var(--indigo);
}

.cat-pill.active {
  background: var(--navy);
  color: #fff;
  border-color: var(--navy);
}

.control-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.subject-scroll {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  flex: 1;
}

.subj-pill {
  border: 1px solid var(--border);
  background: #fff;
  color: var(--muted);
  padding: 4px 10px;
  border-radius: 8px;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
}

.subj-pill.active {
  background: var(--indigo-soft);
  color: var(--indigo);
  border-color: #a5b4fc;
}

.quick-actions {
  display: flex;
  gap: 6px;
}

/* Buttons */
.action-btn {
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 7px 14px;
  font-size: 0.85rem;
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: transform 0.1s ease, background 0.15s ease;
}

.action-btn:active {
  transform: scale(0.98);
}

.action-btn.primary {
  background: var(--indigo);
  color: #fff;
}

.action-btn.primary:hover {
  background: #3730a3;
}

.action-btn.accent {
  background: var(--emerald);
  color: #fff;
}

.action-btn.accent:hover {
  background: #047857;
}

.action-btn.secondary {
  background: var(--surface-alt);
  border-color: var(--border);
  color: var(--text);
}

.action-btn.secondary:hover {
  background: #e2e8f0;
}

.action-btn.large {
  padding: 10px 20px;
  font-size: 0.94rem;
}

.mini-btn {
  border: 1px solid var(--border);
  background: var(--surface-alt);
  color: var(--muted);
  border-radius: 8px;
  padding: 4px 10px;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
}

.mini-btn:hover {
  border-color: var(--indigo);
  color: var(--indigo);
}

.mini-btn.active {
  background: #fef3c7;
  border-color: #f59e0b;
  color: #92400e;
}

/* Settings Strip */
.settings-strip {
  padding: 10px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  background: #fcfdff;
}

.setting-group {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px 14px;
}

.toggle-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.81rem;
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
  user-select: none;
}

.toggle-chip input {
  accent-color: var(--indigo);
  width: 15px;
  height: 15px;
}

.select-pair {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.81rem;
  font-weight: 600;
  color: var(--muted);
}

.select-pair select {
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
  border-radius: 8px;
  padding: 4px 8px;
  font-size: 0.8rem;
  font-weight: 600;
}

/* Context Card */
.context-card {
  padding: 16px 18px;
}

.drill-switcher-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 10px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
}

.drill-picker-select {
  flex: 1;
  min-width: 240px;
  padding: 7px 11px;
  border: 1px solid #cbd5e1;
  border-radius: 9px;
  font-size: 0.88rem;
  font-weight: 700;
  color: var(--navy);
  background: #f8fafc;
}

.drill-switcher-btns {
  display: flex;
  gap: 6px;
}

.context-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 8px;
}

.context-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.badge {
  font-size: 0.74rem;
  font-weight: 700;
  padding: 3px 9px;
  border-radius: 999px;
}

.badge.subj {
  background: var(--navy);
  color: #fff;
}

.badge.cat {
  background: var(--indigo-soft);
  color: var(--indigo);
}

.badge.freq {
  background: #fff7ed;
  color: #c2410c;
  border: 1px solid #fed7aa;
}

.badge.src {
  background: #f1f5f9;
  color: #475569;
}

.context-tools {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.drill-title {
  margin: 0 0 8px;
  font-size: 1.12rem;
  color: var(--navy);
}

.context-zh {
  background: #f0f9ff;
  border-left: 4px solid var(--accent);
  padding: 9px 12px;
  border-radius: 0 8px 8px 0;
  font-size: 0.91rem;
  color: #0c4a6e;
  margin-bottom: 6px;
}

.context-en {
  font-size: 0.83rem;
  color: var(--muted);
}

.expand-box {
  margin-top: 10px;
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
}

.expand-title {
  font-size: 0.79rem;
  font-weight: 800;
  color: var(--navy);
  margin-bottom: 5px;
}

.expand-body {
  font-size: 0.87rem;
  white-space: pre-wrap;
  color: #1e293b;
  max-height: 220px;
  overflow-y: auto;
}

/* Grammar Correction Strip */
.corrections-strip {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px dashed var(--border);
}

.corr-toggle-btn {
  border: 1px solid #a7f3d0;
  background: #ecfdf5;
  color: #065f46;
  padding: 4px 11px;
  border-radius: 999px;
  font-size: 0.79rem;
  font-weight: 700;
  cursor: pointer;
}

.corr-toggle-btn.has-fixes {
  background: #fffbeb;
  border-color: #fde68a;
  color: #92400e;
}

.corr-list {
  margin-top: 8px;
  display: grid;
  gap: 6px;
}

.corr-item {
  background: #fffdf7;
  border: 1px solid #fde68a;
  border-radius: 8px;
  padding: 7px 10px;
  font-size: 0.82rem;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 10px;
}

.corr-raw {
  text-decoration: line-through;
  color: #b91c1c;
  background: #fee2e2;
  padding: 1px 6px;
  border-radius: 4px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

.corr-fixed {
  color: #047857;
  background: #d1fae5;
  padding: 1px 6px;
  border-radius: 4px;
  font-weight: 700;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

.corr-reason {
  color: #475569;
  font-size: 0.8rem;
}

/* TypeRacer Arena */
.arena-card {
  padding: 18px;
  position: relative;
}

.track-panel {
  position: relative;
  background: linear-gradient(180deg, #0f172a 0%, #1e293b 100%);
  color: #fff;
  border-radius: 12px;
  padding: 14px 16px;
  margin-bottom: 12px;
  overflow: hidden;
}

.telemetry-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 10px;
  margin-bottom: 12px;
}

.tele-item {
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 10px;
  padding: 7px 10px;
  display: flex;
  flex-direction: column;
}

.tele-label {
  font-size: 0.72rem;
  color: rgba(255, 255, 255, 0.7);
}

.tele-val {
  font-size: 1.15rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.tele-val.accent {
  color: #38bdf8;
}

.tele-val.gold {
  color: #fbbf24;
}

.grader-meter {
  display: flex;
  align-items: baseline;
  gap: 7px;
}

.grader-rank {
  font-size: 0.72rem;
  font-weight: 700;
  padding: 1px 7px;
  border-radius: 999px;
  background: rgba(251, 191, 36, 0.2);
  color: #fde68a;
}

.grader-rank.pass {
  background: rgba(16, 185, 129, 0.25);
  color: #6ee7b7;
}

/* Animated Race Lanes */
.race-lanes {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.lane {
  display: grid;
  grid-template-columns: 94px 1fr 44px;
  align-items: center;
  gap: 10px;
}

.lane-label {
  font-size: 0.8rem;
  font-weight: 700;
  white-space: nowrap;
}

.lane-road {
  position: relative;
  height: 22px;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 999px;
  border-bottom: 2px dashed rgba(255, 255, 255, 0.22);
}

.lane-fill {
  height: 100%;
  border-radius: 999px;
  transition: width 0.16s linear;
}

.player-fill {
  background: linear-gradient(90deg, #0ea5e9, #10b981);
}

.ghost-fill {
  background: linear-gradient(90deg, rgba(148, 163, 184, 0.3), rgba(244, 114, 182, 0.45));
}

.racer-car {
  position: absolute;
  top: 50%;
  transform: translate(-50%, -56%) scaleX(-1);
  font-size: 1.35rem;
  line-height: 1;
  transition: left 0.16s linear;
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.4));
  pointer-events: none;
}

.finish-flag {
  position: absolute;
  right: 4px;
  top: 50%;
  transform: translateY(-54%);
  font-size: 0.95rem;
}

.lane-pct {
  font-size: 0.78rem;
  font-weight: 700;
  text-align: right;
  font-variant-numeric: tabular-nums;
  color: rgba(255, 255, 255, 0.85);
}

/* Floating Score Toasts */
.toast-layer {
  position: absolute;
  top: 10px;
  right: 16px;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
  pointer-events: none;
}

.score-toast {
  background: linear-gradient(90deg, #059669, #10b981);
  color: #fff;
  font-size: 0.8rem;
  font-weight: 800;
  padding: 4px 11px;
  border-radius: 999px;
  box-shadow: 0 4px 12px rgba(5, 150, 105, 0.45);
  animation: toastPop 1.6s ease forwards;
}

@keyframes toastPop {
  0% { opacity: 0; transform: translateY(8px) scale(0.92); }
  15% { opacity: 1; transform: translateY(0) scale(1); }
  80% { opacity: 1; transform: translateY(-4px); }
  100% { opacity: 0; transform: translateY(-14px); }
}

/* Scoring Buzzword Chips */
.buzzword-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 10px;
}

.bw-chip {
  font-size: 0.76rem;
  font-weight: 600;
  padding: 3px 9px;
  border-radius: 8px;
  background: #f1f5f9;
  border: 1px solid #cbd5e1;
  color: #334155;
  transition: all 0.2s ease;
}

.bw-chip.hit {
  background: var(--emerald-bg);
  border-color: #34d399;
  color: #065f46;
  font-weight: 800;
  transform: scale(1.03);
}

/* Passage Typing Box */
.passage-box {
  background: #fdfdfb;
  border: 2px solid #cbd5e1;
  border-radius: 12px;
  padding: 18px 20px;
  margin-bottom: 12px;
  cursor: text;
  transition: border-color 0.15s ease;
  outline: none;
}

.passage-box:focus-within,
.passage-box.active-focus {
  border-color: var(--indigo);
  box-shadow: 0 0 0 3px rgba(67, 56, 202, 0.1);
}

.memory-banner {
  background: #eef2ff;
  color: #3730a3;
  font-size: 0.8rem;
  font-weight: 700;
  padding: 5px 10px;
  border-radius: 7px;
  margin-bottom: 10px;
  display: inline-block;
}

.passage-words {
  font-family: "SF Mono", "JetBrains Mono", Menlo, Monaco, Consolas, monospace;
  font-size: 1.15rem;
  line-height: 1.95;
  word-spacing: 0.08em;
  user-select: none;
}

.word-tok {
  display: inline-block;
  padding: 0 3px;
  border-radius: 5px;
  margin-right: 1px;
  transition: background 0.1s ease;
}

.word-tok.active-word {
  background: #e0e7ff;
  box-shadow: 0 2px 0 var(--indigo);
}

.word-tok.done-exact {
  color: #047857;
}

.word-tok.done-fuzzy {
  color: #b45309;
  background: #fef3c7;
  text-decoration: underline wavy #d97706;
}

.word-tok.done-miss {
  color: #b91c1c;
  background: #fee2e2;
  text-decoration: underline wavy #dc2626;
}

.word-tok.is-buzzword:not(.done-exact):not(.done-fuzzy):not(.done-miss) {
  background: #fef9c3;
  border-bottom: 2px solid #f59e0b;
}

.word-tok.dimmed {
  color: #94a3b8;
}

.word-tok.cloze-hidden {
  background: #e2e8f0;
  color: #475569;
  letter-spacing: 0.04em;
}

.ch-ok {
  color: #059669;
  font-weight: 700;
}

.ch-bad {
  color: #dc2626;
  background: #fee2e2;
  border-radius: 2px;
}

.ch-rem {
  color: #334155;
}

/* Input Bar */
.input-bar-wrap {
  display: flex;
  gap: 8px;
  align-items: center;
}

.typing-input {
  flex: 1;
  font-family: "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
  font-size: 1.08rem;
  padding: 12px 15px;
  border: 2px solid #94a3b8;
  border-radius: 11px;
  background: #fff;
  color: var(--text);
  outline: none;
  transition: border-color 0.15s ease;
}

.typing-input:focus {
  border-color: var(--indigo);
  box-shadow: 0 0 0 3px rgba(67, 56, 202, 0.15);
}

.typing-input.has-typo {
  border-color: var(--amber);
  background: #fffbeb;
}

.typing-input.strict-bad {
  border-color: var(--coral);
  background: #fef2f2;
}

.typing-tips {
  margin-top: 8px;
  font-size: 0.78rem;
  color: var(--muted);
}

.typing-tips code {
  background: #e2e8f0;
  padding: 1px 5px;
  border-radius: 4px;
}

/* Post-Race Summary */
.summary-panel {
  margin-top: 18px;
  border-top: 2px solid var(--border);
  padding-top: 18px;
  animation: fadeSlide 0.25s ease;
}

@keyframes fadeSlide {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.summary-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.summary-kicker {
  font-size: 0.85rem;
  font-weight: 800;
  color: var(--indigo);
}

.summary-headline {
  margin: 2px 0 0;
  font-size: 1.25rem;
  color: var(--navy);
}

.summary-score-badge {
  background: linear-gradient(135deg, #047857, #10b981);
  color: #fff;
  border-radius: 12px;
  padding: 8px 16px;
  text-align: center;
  min-width: 118px;
}

.summary-score-badge.tier-80 {
  background: linear-gradient(135deg, #047857, #10b981);
}

.summary-score-badge.tier-70 {
  background: linear-gradient(135deg, #1d4ed8, #3b82f6);
}

.summary-score-badge.tier-65 {
  background: linear-gradient(135deg, #b45309, #f59e0b);
}

.summary-score-badge.tier-50 {
  background: linear-gradient(135deg, #be123c, #ef4444);
}

.summary-meme-card {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 14px 16px;
  border-radius: 14px;
  margin-bottom: 14px;
  border: 2px solid #cbd5e1;
  background: #f8fafc;
}

.summary-meme-card.tier-80 {
  border-color: #34d399;
  background: linear-gradient(135deg, #ecfdf5 0%, #fefce8 100%);
}

.summary-meme-card.tier-70 {
  border-color: #93c5fd;
  background: linear-gradient(135deg, #eff6ff 0%, #eef2ff 100%);
}

.summary-meme-card.tier-65 {
  border-color: #fcd34d;
  background: linear-gradient(135deg, #fffbeb 0%, #fef3c7 100%);
}

.summary-meme-card.tier-50 {
  border-color: #fda4af;
  background: linear-gradient(135deg, #fff1f2 0%, #ffe4e6 100%);
}

.sum-meme-img {
  width: 120px;
  height: 120px;
  object-fit: cover;
  border-radius: 12px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.14);
  flex-shrink: 0;
  background: #0f172a;
}

.sum-meme-body {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.sum-meme-tier {
  font-size: 1.02rem;
  font-weight: 800;
  color: var(--navy);
}

.sum-meme-caption {
  font-size: 0.9rem;
  color: #334155;
  line-height: 1.5;
}

.sg-num {
  display: block;
  font-size: 1.55rem;
  font-weight: 900;
  line-height: 1.1;
}

.sg-sub {
  font-size: 0.74rem;
  font-weight: 700;
  opacity: 0.92;
}

.summary-metrics {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 10px;
  margin-bottom: 12px;
}

.sm-card {
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px;
  text-align: center;
}

.sm-card span {
  display: block;
  font-size: 0.74rem;
  color: var(--muted);
}

.sm-card strong {
  font-size: 1.15rem;
  color: var(--navy);
}

.summary-keywords {
  margin-bottom: 12px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

/* Typo 5-Rep Re-Drill Box */
.typo-redrill-box {
  background: #fff7ed;
  border: 1px solid #fed7aa;
  border-radius: 12px;
  padding: 14px;
  margin-bottom: 14px;
}

.tr-head h4 {
  margin: 0 0 3px;
  color: #9a3412;
  font-size: 0.96rem;
}

.tr-hint {
  font-size: 0.8rem;
  color: #9a3412;
  opacity: 0.85;
}

.tr-items {
  margin-top: 10px;
  display: grid;
  gap: 8px;
}

.tr-row {
  background: #fff;
  border: 1px solid #fdba74;
  border-radius: 9px;
  padding: 8px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

.tr-row.cleared {
  border-color: #6ee7b7;
  background: #ecfdf5;
}

.tr-pair {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: ui-monospace, Menlo, monospace;
  font-size: 0.9rem;
}

.tr-drill-ctrl {
  display: flex;
  align-items: center;
  gap: 8px;
}

.tr-pips {
  display: flex;
  gap: 4px;
}

.tr-pip {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #e2e8f0;
}

.tr-pip.done {
  background: #10b981;
}

.tr-input {
  border: 1px solid #94a3b8;
  border-radius: 7px;
  padding: 5px 9px;
  font-family: ui-monospace, Menlo, monospace;
  font-size: 0.88rem;
  width: 170px;
}

.summary-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

/* Library Tab */
.library-controls {
  padding: 14px;
}

.lib-search-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
}

.lib-search-input {
  flex: 1;
  min-width: 240px;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 9px;
  font-size: 0.9rem;
}

.lib-select {
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 9px;
  font-size: 0.86rem;
  background: #fff;
}

.lib-summary-bar {
  margin-top: 8px;
  font-size: 0.82rem;
  color: var(--muted);
  font-weight: 600;
}

.library-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(350px, 1fr));
  gap: 14px;
}

.lib-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 10px;
  cursor: pointer;
  transition: transform 0.14s ease, border-color 0.14s ease, box-shadow 0.14s ease;
}

.lib-card:hover {
  transform: translateY(-2px);
  border-color: var(--indigo);
  box-shadow: 0 10px 24px rgba(67, 56, 202, 0.12);
}

.lib-card-hint {
  font-size: 0.74rem;
  color: var(--indigo);
  font-weight: 600;
}

.lib-card-top {
  display: flex;
  justify-content: space-between;
  gap: 6px;
  flex-wrap: wrap;
}

.lib-card-title {
  margin: 4px 0;
  font-size: 0.98rem;
  color: var(--navy);
}

.lib-card-ctx {
  font-size: 0.81rem;
  color: #0c4a6e;
  background: #f0f9ff;
  padding: 6px 8px;
  border-radius: 6px;
}

.lib-card-preview {
  font-size: 0.82rem;
  color: var(--muted);
  font-family: ui-monospace, Menlo, monospace;
  line-height: 1.45;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.lib-card-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
  font-size: 0.78rem;
  color: var(--muted);
}

.lib-top-row,
.fav-top-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.lib-weak-banner {
  margin-top: 10px;
  padding: 9px 12px;
  border-radius: 10px;
  background: #fffbeb;
  border: 1px solid #fde68a;
  color: #92400e;
  font-size: 0.82rem;
  line-height: 1.5;
  font-weight: 600;
}

.fav-heading {
  margin: 0;
  font-size: 1.12rem;
  color: var(--navy);
}

.fav-race-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.fav-card-actions {
  display: flex;
  gap: 6px;
  align-items: center;
}

.fav-empty-box {
  grid-column: 1 / -1;
  text-align: center;
  padding: 36px 20px;
  background: var(--surface);
  border: 1px dashed #cbd5e1;
  border-radius: 14px;
  color: var(--muted);
}

.fav-empty-box h3 {
  margin: 0 0 6px;
  color: var(--navy);
}

/* Custom Polisher & Builder */
.custom-grid {
  display: grid;
  grid-template-columns: 1.15fr 1fr;
  gap: 14px;
  align-items: start;
}

.custom-form-card,
.custom-preview-card {
  padding: 18px;
}

.custom-form-card h2,
.custom-preview-card h3 {
  margin: 0 0 8px;
  color: var(--navy);
}

.custom-desc {
  font-size: 0.85rem;
  color: var(--muted);
  margin: 0 0 12px;
}

.form-row-2 {
  display: grid;
  grid-template-columns: 1.3fr 1fr;
  gap: 10px;
}

.field-label {
  display: block;
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--navy);
  margin: 8px 0 4px;
}

.field-input,
.field-textarea {
  width: 100%;
  border: 1px solid #cbd5e1;
  border-radius: 9px;
  padding: 8px 11px;
  font-size: 0.9rem;
  font-family: inherit;
}

.field-textarea {
  font-family: ui-monospace, Menlo, monospace;
  line-height: 1.55;
}

.custom-btn-row {
  margin-top: 12px;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.custom-empty {
  background: var(--surface-alt);
  border: 1px dashed #cbd5e1;
  border-radius: 10px;
  padding: 20px;
  font-size: 0.87rem;
  color: var(--muted);
  text-align: center;
}

.preview-block {
  margin-bottom: 12px;
}

.preview-label {
  font-size: 0.8rem;
  font-weight: 800;
  color: var(--navy);
  margin-bottom: 5px;
}

.cp-corr-list {
  display: grid;
  gap: 5px;
  max-height: 200px;
  overflow-y: auto;
}

.gemini-key-bar {
  background: linear-gradient(135deg, #f8fafc 0%, #eef2ff 100%);
  border: 1px solid #c7d2fe;
  border-radius: 10px;
  padding: 10px 12px;
  margin-bottom: 10px;
}

.gk-head {
  display: flex;
  flex-direction: column;
  gap: 3px;
  margin-bottom: 7px;
}

.gk-badge {
  font-size: 0.82rem;
  font-weight: 800;
  color: var(--indigo);
}

.gk-note {
  font-size: 0.76rem;
  color: var(--muted);
}

.gk-input-row {
  display: flex;
  gap: 8px;
  align-items: center;
}

.cp-engine-tag {
  font-size: 0.8rem;
  font-weight: 700;
  padding: 6px 10px;
  border-radius: 8px;
  margin-bottom: 10px;
  background: #f1f5f9;
  color: var(--navy);
  border: 1px solid #cbd5e1;
}

.cp-engine-tag.ai {
  background: #ecfdf5;
  color: #065f46;
  border-color: #6ee7b7;
}

.cp-engine-tag.warn {
  background: #fffbeb;
  color: #92400e;
  border-color: #fde68a;
}

/* Library Detail Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.58);
  backdrop-filter: blur(3px);
  z-index: 90;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
}

.modal-card {
  background: var(--surface);
  border-radius: 16px;
  width: 100%;
  max-width: 820px;
  max-height: 88vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 24px 60px rgba(15, 23, 42, 0.32);
  border: 1px solid var(--border);
  overflow: hidden;
}

.modal-head {
  padding: 14px 18px 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  border-bottom: 1px solid var(--border);
}

.modal-close-btn {
  border: 1px solid var(--border);
  background: var(--surface-alt);
  color: var(--text);
  width: 32px;
  height: 32px;
  border-radius: 999px;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  flex-shrink: 0;
}

.modal-close-btn:hover {
  background: #e2e8f0;
}

.modal-title {
  margin: 0;
  padding: 10px 18px 4px;
  font-size: 1.14rem;
  color: var(--navy);
}

.modal-body {
  padding: 8px 18px 16px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.md-section {
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: 11px;
  padding: 12px 14px;
}

.md-sec-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 0.8rem;
  font-weight: 800;
  color: var(--navy);
  margin-bottom: 7px;
}

.md-full-text {
  font-family: "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
  font-size: 0.98rem;
  line-height: 1.78;
  color: var(--text);
  background: #fff;
  border: 1px solid #cbd5e1;
  border-radius: 9px;
  padding: 12px 14px;
  user-select: text;
}

.md-buzz {
  background: #fef08a;
  color: #78350f;
  padding: 1px 4px;
  border-radius: 4px;
  font-weight: 700;
}

.md-zh-text {
  font-size: 0.93rem;
  line-height: 1.7;
  color: #1e293b;
}

.modal-foot {
  padding: 12px 18px;
  border-top: 1px solid var(--border);
  background: #f8fafc;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

.modal-nav-btns {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.logout-pill {
  cursor: pointer;
  color: #fff;
  font-family: inherit;
  transition: background 0.15s ease;
}

.logout-pill:hover {
  background: rgba(239, 68, 68, 0.35);
  border-color: rgba(248, 113, 113, 0.6);
}

/* Hide entire app shell before authentication completes (prevents flash & background peek) */
body.auth-locked .top-nav,
body.auth-locked .main-wrap,
body.auth-locked #lib-detail-modal {
  display: none !important;
}

body.auth-locked {
  background: #0b1930;
  overflow: hidden;
}

/* Password Login Overlay */
.login-overlay {
  position: fixed;
  inset: 0;
  z-index: 120;
  background: linear-gradient(135deg, #0b1930 0%, #172e54 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 28px 26px;
  width: 100%;
  max-width: 410px;
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.38);
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.login-icon {
  font-size: 2.3rem;
  line-height: 1;
}

.login-title {
  margin: 0;
  font-size: 1.24rem;
  color: var(--navy);
}

.login-sub {
  margin: 0;
  font-size: 0.84rem;
  color: var(--muted);
}

.login-input {
  text-align: center;
  font-size: 1rem;
  padding: 11px 14px;
}

.login-error {
  background: #fef2f2;
  border: 1px solid #fecaca;
  color: #b91c1c;
  border-radius: 9px;
  padding: 8px 10px;
  font-size: 0.83rem;
  font-weight: 600;
}

.login-btn {
  width: 100%;
  margin-top: 4px;
}

@media (max-width: 900px) {
  .telemetry-grid,
  .summary-metrics {
    grid-template-columns: repeat(2, 1fr);
  }
  .custom-grid,
  .form-row-2 {
    grid-template-columns: 1fr;
  }
  .lane {
    grid-template-columns: 76px 1fr 40px;
  }
  .input-bar-wrap {
    flex-wrap: wrap;
  }
  .typing-input {
    width: 100%;
  }
}
