/* ==========================================================================
   Component Styles
   ========================================================================== */

/* -------------------- 1. Search Bar -------------------- */
.search-container {
  position: relative;
  width: 100%;
}

.search-input-wrapper {
  position: relative;
  display: flex;
  align-items: center;
  width: 100%;
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-full);
  padding: 0 16px;
  height: 40px;
  box-shadow: var(--shadow-xs);
  transition: var(--transition-normal);
}

.search-input-wrapper:focus-within {
  border-color: var(--color-root);
  box-shadow: 0 0 0 3px var(--color-root-glow);
}

.search-input-wrapper svg.search-icon {
  width: 18px;
  height: 18px;
  color: var(--text-muted);
  flex-shrink: 0;
  margin-right: 10px;
}

.search-input {
  width: 100%;
  font-size: 0.9rem;
  color: var(--text-primary);
  background: transparent;
}

.search-input::placeholder {
  color: var(--text-muted);
}

.search-shortcut {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  padding: 2px 6px;
  background: var(--bg-subtle);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-xs);
  color: var(--text-muted);
  flex-shrink: 0;
  margin-left: 8px;
}

.search-clear-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  border-radius: var(--radius-full);
  background: var(--bg-subtle);
  color: var(--text-muted);
  margin-left: 8px;
  font-size: 14px;
  transition: var(--transition-fast);
}
.search-clear-btn:hover {
  background: var(--text-muted);
  color: #fff;
}

/* Big Hero Search */
.hero-search-wrapper {
  max-width: 640px;
  margin: 0 auto;
}

.hero-search-wrapper .search-input-wrapper {
  height: 52px;
  padding: 0 20px;
  border-radius: var(--radius-lg);
  font-size: 1.05rem;
  box-shadow: var(--shadow-md);
}

.hero-search-wrapper .search-input-wrapper svg.search-icon {
  width: 22px;
  height: 22px;
}

/* Autocomplete Dropdown */
.search-dropdown {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-xl);
  max-height: 420px;
  overflow-y: auto;
  z-index: var(--z-modal);
  padding: 8px;
}

.search-group-title {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  padding: 6px 12px 4px;
}

.search-result-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: var(--transition-fast);
}

.search-result-item:hover,
.search-result-item.highlighted {
  background: var(--bg-subtle);
}

.search-item-left {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.search-item-title {
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--text-primary);
}

.search-item-desc {
  font-size: 0.85rem;
  color: var(--text-secondary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* -------------------- 2. Stats / Metric Cards -------------------- */
.stat-card {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 18px 20px;
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-xs);
  transition: var(--transition-normal);
}

.stat-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.stat-icon-wrapper {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 46px;
  height: 46px;
  border-radius: var(--radius-md);
  background: var(--color-root-bg);
  color: var(--color-root);
  flex-shrink: 0;
}

.stat-number {
  font-size: 1.5rem;
  font-weight: 800;
  line-height: 1.2;
  color: var(--text-primary);
  font-feature-settings: "tnum";
}

.stat-label {
  font-size: 0.82rem;
  color: var(--text-muted);
}

/* -------------------- 2.5 Home Page & Section Headers -------------------- */
.home-hero {
  text-align: center;
  padding: 28px 12px 36px;
}

.home-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 5px 14px;
  border-radius: var(--radius-full);
  background: var(--color-root-bg);
  color: var(--color-root-text);
  font-size: 0.82rem;
  font-weight: 600;
  margin-bottom: 14px;
  border: 1px solid var(--color-root-border);
  line-height: 1.35;
  max-width: 100%;
}

.home-title {
  font-size: clamp(1.6rem, 3.8vw, 2.4rem);
  font-weight: 800;
  letter-spacing: -0.03em;
  margin-bottom: 10px;
  color: var(--text-primary);
  line-height: 1.25;
}

.home-subtitle {
  font-size: 0.95rem;
  color: var(--text-secondary);
  max-width: 580px;
  margin: 0 auto 24px;
  line-height: 1.55;
}

.home-stats-section {
  margin-bottom: 36px;
}

.section-header-row {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.section-header-title {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.01em;
}

.section-header-sub {
  font-size: 0.82rem;
  color: var(--text-muted);
  margin-top: 2px;
}

.section-header-link {
  font-size: 0.86rem;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
  transition: var(--transition-fast);
}

/* -------------------- 3. Card Components (Compact & Refined) -------------------- */
/* Root Card */
.root-card {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 12px 14px;
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-xs);
  transition: var(--transition-fast);
  cursor: pointer;
  position: relative;
}

.root-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-sm);
  border-color: var(--color-root);
}

.card-header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
  gap: 8px;
}

.card-title {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.01em;
}

.root-card .card-title {
  color: var(--color-root-text);
}

.card-gloss-zh {
  font-size: 0.88rem;
  font-weight: 500;
  color: var(--text-primary);
  margin-bottom: 4px;
  line-height: 1.35;
}

.card-gloss-en {
  font-size: 0.78rem;
  color: var(--text-secondary);
  line-height: 1.35;
  margin-bottom: 8px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.card-footer-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-top: 8px;
  border-top: 1px solid var(--border-subtle);
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* Affix Card */
.affix-card {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 12px 14px;
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-xs);
  transition: var(--transition-fast);
  cursor: pointer;
  position: relative;
}

.affix-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-sm);
  border-color: var(--color-suffix);
}

.affix-card.is-prefix:hover {
  border-color: var(--color-prefix);
}

/* Word Card */
.word-card {
  padding: 10px 12px;
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-xs);
  transition: var(--transition-fast);
  cursor: pointer;
}

.word-card:hover {
  border-color: var(--color-root);
  box-shadow: var(--shadow-sm);
  transform: translateY(-1px);
}

.word-header-line {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  margin-bottom: 4px;
}

.word-name {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text-primary);
}

.word-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 3px;
  margin-bottom: 4px;
}

.word-meaning {
  font-size: 0.8rem;
  color: var(--text-secondary);
  line-height: 1.35;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* Detail Header Card Components */
.detail-header-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 16px 20px;
  box-shadow: var(--shadow-xs);
  margin-bottom: 16px;
}

.detail-header-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 8px;
}

.detail-stat-badge {
  text-align: right;
  flex-shrink: 0;
}

.detail-stat-num {
  font-size: 1.5rem;
  font-weight: 800;
  line-height: 1.1;
  font-feature-settings: "tnum";
}

.detail-stat-lbl {
  font-size: 0.72rem;
  color: var(--text-muted);
}

@media (max-width: 600px) {
  .detail-header-card {
    padding: 14px 14px;
  }
  .detail-header-top {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
  }
  .detail-stat-badge {
    text-align: left;
    display: inline-flex;
    align-items: baseline;
    gap: 6px;
    padding: 4px 10px;
    background: var(--bg-subtle);
    border-radius: var(--radius-xs);
    width: fit-content;
  }
  .detail-stat-num {
    font-size: 1.15rem;
  }
}

.word-relation {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  margin-top: 8px;
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.word-relation-link {
  font-weight: 700;
  color: var(--primary);
}

.word-relation-dot {
  color: var(--text-muted);
}

.word-meta-line {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  margin-top: 6px;
  font-size: 0.82rem;
}

.word-meta-label {
  color: var(--text-muted);
}

.lemma-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}

.lemma-search {
  height: 30px;
  width: 220px;
  max-width: 100%;
  padding: 0 12px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-full);
  background: var(--bg-surface);
  color: var(--text-primary);
  font-size: 0.82rem;
}

.lemma-chips {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px;
}

.lemma-toolbar .filter-chip {
  padding: 3px 9px;
  font-size: 0.74rem;
}

.lemma-count {
  margin-left: auto;
  font-size: 0.76rem;
  color: var(--text-muted);
}

.lemma-table-wrap {
  overflow-x: auto;
  overscroll-behavior-x: contain;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  background: var(--bg-surface);
  -webkit-overflow-scrolling: touch;
}

.lemma-table {
  width: max-content;
  min-width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 0.78rem;
}

.lemma-table th,
.lemma-table td {
  padding: 4px 8px;
  border-bottom: 1px solid var(--border-subtle);
  white-space: nowrap;
  vertical-align: middle;
  line-height: 1.3;
}

.lemma-table th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--bg-subtle);
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--text-muted);
  letter-spacing: 0.02em;
  text-align: left;
}

.lemma-table tbody tr {
  cursor: pointer;
}

.lemma-table tbody tr:last-child td {
  border-bottom: none;
}

.lemma-table tbody tr:hover td {
  background: var(--bg-subtle);
}

.lemma-table th:first-child,
.lemma-table td:first-child {
  position: sticky;
  left: 0;
  z-index: 1;
  min-width: 7.5em;
  background: var(--bg-surface);
  box-shadow: 1px 0 0 var(--border-color);
}

.lemma-table th:first-child {
  z-index: 3;
  background: var(--bg-subtle);
}

.lemma-table tbody tr:hover td:first-child {
  background: var(--bg-subtle);
}

.lemma-col-word a {
  font-weight: 700;
  color: var(--text-primary);
}

.lemma-col-morph .badge,
.lemma-col-tags .tag-exam {
  margin-right: 3px;
}

.lemma-col-zh {
  color: var(--text-secondary);
}

.lemma-col-extra {
  color: var(--text-muted);
  font-size: 0.72rem;
}

.lemma-empty {
  text-align: center;
  color: var(--text-muted);
  padding: 28px 12px !important;
  white-space: normal !important;
}

.lemma-block .load-more-container {
  margin-top: 12px;
}

.lemma-check {
  display: inline-flex;
  align-items: center;
  margin-right: 6px;
  vertical-align: middle;
}

.lemma-check input {
  width: 14px;
  height: 14px;
  accent-color: var(--color-root);
}

.lemma-bulk,
.nb-bulk {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.lemma-bulk[hidden] {
  display: none !important;
}

.nb-hero {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.nb-title {
  font-size: 1.5rem;
  font-weight: 800;
  color: var(--text-primary);
}

.nb-sub {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-top: 4px;
}

.nb-hero-actions {
  display: flex;
  gap: 8px;
}

.nb-tabs {
  display: flex;
  gap: 6px;
  border-bottom: 1px solid var(--border-color);
  margin-bottom: 12px;
}

.nb-tabs .tab-btn {
  padding: 6px 14px;
  font-weight: 600;
  font-size: 0.88rem;
  color: var(--text-muted);
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  cursor: pointer;
}

.nb-tabs .tab-btn.active {
  color: var(--color-root);
  border-bottom-color: var(--color-root);
}

.nb-tab-count {
  font-family: var(--font-mono);
  font-size: 0.75rem;
}

.nb-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}

.nb-btn {
  height: 30px;
  padding: 0 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
  background: var(--bg-surface);
  color: var(--text-primary);
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
}

.nb-btn-primary {
  background: var(--color-root);
  color: #fff;
  border-color: var(--color-root);
}

.nb-btn-danger,
.nb-link-danger {
  color: #b91c1c;
}

.nb-link-btn {
  background: none;
  border: none;
  color: var(--primary);
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  padding: 0;
}

.nb-date {
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

@media (max-width: 840px) {
  .nb-hero {
    flex-direction: column;
  }

  .nb-search,
  .lemma-search {
    width: 100%;
  }

  .nb-toolbar,
  .lemma-toolbar {
    align-items: stretch;
  }

  .nb-bulk,
  .lemma-bulk {
    width: 100%;
  }

  .toast-container {
    bottom: calc(var(--bottom-nav-height) + 12px);
    right: 12px;
    left: 12px;
    align-items: stretch;
  }
}

/* -------------------- 4. Morpheme Breakdown Visualizer -------------------- */
.morpheme-breakdown-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 24px;
  box-shadow: var(--shadow-sm);
  margin-bottom: 24px;
}

.morpheme-chain {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  margin-top: 14px;
}

.morpheme-block {
  display: flex;
  flex-direction: column;
  padding: 12px 18px;
  border-radius: var(--radius-md);
  border: 2px solid;
  cursor: pointer;
  transition: var(--transition-fast);
  position: relative;
}

.morpheme-block:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.morpheme-block.type-root {
  background: var(--color-root-bg);
  border-color: var(--color-root-border);
  color: var(--color-root-text);
}

.morpheme-block.type-prefix {
  background: var(--color-prefix-bg);
  border-color: var(--color-prefix-border);
  color: var(--color-prefix-text);
}

.morpheme-block.type-suffix {
  background: var(--color-suffix-bg);
  border-color: var(--color-suffix-border);
  color: var(--color-suffix-text);
}

.morpheme-block.type-base {
  background: var(--color-base-bg);
  border-color: var(--color-base-border);
  color: var(--color-base-text);
}

.morpheme-text {
  font-family: var(--font-mono);
  font-size: 1.25rem;
  font-weight: 700;
  line-height: 1.2;
}

.morpheme-role {
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  opacity: 0.8;
  margin-top: 2px;
}

.morpheme-meaning {
  font-size: 0.82rem;
  font-weight: 500;
  margin-top: 6px;
  max-width: 220px;
  line-height: 1.3;
}

.morpheme-divider {
  font-size: 1.2rem;
  color: var(--text-muted);
  font-weight: 600;
}

/* -------------------- 5. TreeView (rtree & etree) -------------------- */
.tree-section-title {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text-primary);
  margin: 0 0 12px;
}
.tree-section-title small {
  display: inline-block;
  margin-left: 8px;
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--text-muted);
}

.treewrap {
  overflow-x: auto;
  overscroll-behavior-x: contain;
  -webkit-overflow-scrolling: touch;
  padding: 8px 6px;
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
}
.treewrap svg { max-width: none; display: block; }
.treewrap text { font-family: var(--font-sans, inherit); dominant-baseline: middle; }
.treewrap .tl { font-size: 13px; fill: var(--text-primary); font-weight: 500; }
.treewrap .ts { font-size: 11.5px; fill: var(--text-muted); }
.treewrap .tn { fill: var(--bg-surface); stroke: var(--border-color); stroke-width: 1; }
.treewrap .tn.r { fill: var(--color-root-bg); stroke: var(--color-root-border); }
.treewrap .tn.p { fill: var(--color-prefix-bg); stroke: var(--color-prefix-border); }
.treewrap .tn.l { fill: var(--color-prefix-bg); stroke: var(--color-prefix-border); }
.treewrap .tn.w { fill: var(--bg-surface); stroke: var(--border-color); }
.treewrap a .tn { cursor: pointer; }
.treewrap a:hover .tn { stroke: var(--color-root); stroke-width: 1.6; }
.treewrap a:hover .tl { fill: var(--color-root); }

.matrixwrap {
  overflow: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  background: var(--bg-surface);
  max-height: 70vh;
}
table.matrix {
  border-collapse: separate;
  border-spacing: 0;
  font-size: 13px;
  min-width: 100%;
}
table.matrix th,
table.matrix td {
  border-right: 1px solid var(--border-color);
  border-bottom: 1px solid var(--border-color);
  padding: 6px 9px;
  vertical-align: top;
  text-align: left;
}
table.matrix thead th {
  position: sticky;
  top: 0;
  background: var(--bg-subtle);
  z-index: 2;
  font-weight: 600;
  color: var(--color-suffix-text);
  white-space: nowrap;
}
table.matrix tbody th {
  position: sticky;
  left: 0;
  background: var(--bg-subtle);
  z-index: 1;
  color: var(--color-prefix-text);
  white-space: nowrap;
}
table.matrix thead th:first-child {
  left: 0;
  z-index: 3;
  color: var(--color-root-text);
}
table.matrix td a {
  display: block;
  padding: 1px 0;
  color: var(--text-primary);
}
table.matrix td a:hover {
  color: var(--color-root);
  text-decoration: underline;
}
table.matrix td.empty {
  background: repeating-linear-gradient(
    45deg,
    transparent,
    transparent 5px,
    var(--bg-subtle) 5px,
    var(--bg-subtle) 6px
  );
}
.tiny-muted {
  font-size: 0.72rem;
  color: var(--text-muted);
}
.text-muted { color: var(--text-muted); }

.tree-container {
  padding: 16px;
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  overflow-x: auto;
}

.tree-node {
  margin-left: 20px;
  position: relative;
  padding-left: 12px;
  border-left: 2px solid var(--border-color);
  margin-top: 8px;
}

.tree-node-content {
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  transition: var(--transition-fast);
}

.tree-node-content:hover {
  background: var(--bg-subtle);
}

.tree-word {
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--primary);
  cursor: pointer;
}

.tree-word:hover {
  text-decoration: underline;
}

.tree-meaning {
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.tree-toggle-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  border-radius: 4px;
  background: var(--bg-subtle);
  border: 1px solid var(--border-color);
  font-size: 11px;
  font-family: var(--font-mono);
  cursor: pointer;
  margin-right: 4px;
}

/* -------------------- 6. Filter Bar & Controls -------------------- */
.filter-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 20px;
  padding: 12px 16px;
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
}

.filter-chips {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.filter-chip {
  padding: 6px 14px;
  border-radius: var(--radius-full);
  font-size: 0.82rem;
  font-weight: 500;
  background: var(--bg-subtle);
  color: var(--text-secondary);
  border: 1px solid var(--border-color);
  cursor: pointer;
  transition: var(--transition-fast);
}

.filter-chip:hover {
  background: var(--bg-subtle-hover);
  color: var(--text-primary);
}

.filter-chip.active {
  background: var(--color-root);
  color: #fff;
  border-color: var(--color-root);
}

.sort-select {
  padding: 6px 12px;
  font-size: 0.82rem;
  font-weight: 500;
  border-radius: var(--radius-sm);
  background: var(--bg-subtle);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  cursor: pointer;
}

.filter-search-input {
  padding: 6px 14px;
  font-size: 0.82rem;
  font-weight: 500;
  border-radius: var(--radius-full);
  background: var(--bg-subtle);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  flex: 1;
  min-width: 160px;
  transition: var(--transition-fast);
}

.filter-search-input:focus {
  border-color: var(--color-root);
  background: var(--bg-surface);
}

/* -------------------- 7. Drawer Component -------------------- */
.drawer-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(4px);
  z-index: var(--z-drawer);
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition-normal);
}

.drawer-backdrop.open {
  opacity: 1;
  pointer-events: auto;
}

.drawer-panel {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: 580px;
  max-width: 100vw;
  background: var(--bg-surface);
  box-shadow: var(--shadow-xl);
  z-index: calc(var(--z-drawer) + 1);
  transform: translateX(100%);
  transition: transform var(--transition-normal);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.drawer-backdrop.open .drawer-panel {
  transform: translateX(0);
}

.drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 24px;
  border-bottom: 1px solid var(--border-color);
}

.drawer-body {
  flex: 1;
  padding: 24px;
  overflow-y: auto;
}

/* -------------------- 8. Toast Notifications -------------------- */
.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: var(--z-toast);
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.toast {
  padding: 10px 18px;
  background: var(--text-primary);
  color: var(--text-inverse);
  font-size: 0.88rem;
  font-weight: 500;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg);
  display: flex;
  align-items: center;
  gap: 8px;
  animation: toastIn 0.25s ease-out forwards;
}

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

/* -------------------- 9. Protocol Alert Banner (for file://) -------------------- */
.protocol-banner {
  background: linear-gradient(135deg, #fef3c7, #fee2e2);
  border: 1px solid #fcd34d;
  color: #78350f;
  padding: 12px 18px;
  border-radius: var(--radius-md);
  margin-bottom: 20px;
  display: flex;
  align-items: flex-start;
  gap: 12px;
  font-size: 0.88rem;
  line-height: 1.5;
}

[data-theme="dark"] .protocol-banner {
  background: linear-gradient(135deg, rgba(245, 158, 11, 0.15), rgba(239, 68, 68, 0.15));
  border-color: rgba(245, 158, 11, 0.3);
  color: #fde68a;
}

.protocol-banner svg {
  width: 22px;
  height: 22px;
  flex-shrink: 0;
  margin-top: 2px;
}

/* -------------------- 10. Load More & Empty States -------------------- */
.load-more-container {
  display: flex;
  justify-content: center;
  margin-top: 32px;
}

.btn-load-more {
  padding: 10px 24px;
  border-radius: var(--radius-full);
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  font-weight: 600;
  font-size: 0.9rem;
  box-shadow: var(--shadow-xs);
  transition: var(--transition-fast);
}

.btn-load-more:hover {
  background: var(--bg-subtle);
  border-color: var(--color-root);
  color: var(--color-root);
}

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 64px 20px;
  text-align: center;
  color: var(--text-muted);
}

.empty-state svg {
  width: 48px;
  height: 48px;
  margin-bottom: 16px;
  opacity: 0.6;
}

.empty-state-title {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.loading-spinner {
  display: inline-block;
  width: 24px;
  height: 24px;
  border: 3px solid var(--border-color);
  border-top-color: var(--color-root);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.review-link-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  box-sizing: border-box;
}

.family-nav {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
  padding: 8px 12px;
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  font-size: 0.82rem;
}

.family-nav-link {
  font-weight: 600;
  color: var(--primary);
  text-decoration: none;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

.family-nav-link:last-child,
.family-nav > :last-child {
  justify-self: end;
  text-align: right;
}

.family-nav-pos {
  color: var(--text-secondary);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.family-nav-label {
  color: var(--color-root);
  font-weight: 700;
  text-decoration: none;
}

.family-nav-muted {
  color: var(--text-muted);
}

.page-review {
  max-width: 560px;
  margin: 0 auto;
}

.review-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
  font-size: 0.85rem;
}

.review-back-link,
.review-detail-link a {
  color: var(--primary);
  font-weight: 600;
  text-decoration: none;
}

.review-progress {
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.review-card {
  width: 100%;
  min-height: 220px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  background: var(--bg-surface);
  padding: 28px 20px;
  text-align: center;
  cursor: pointer;
  box-shadow: var(--shadow-xs);
}

.review-card-kind {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--text-muted);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  margin-bottom: 10px;
}

.review-card-title {
  font-size: 2rem;
  font-weight: 800;
  color: var(--text-primary);
  letter-spacing: -0.03em;
  word-break: break-word;
}

.review-card-zh {
  margin-top: 16px;
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--text-primary);
  line-height: 1.5;
}

.review-card-hint {
  margin-top: 18px;
  font-size: 0.78rem;
  color: var(--text-muted);
}

.review-actions {
  display: flex;
  gap: 10px;
  margin-top: 16px;
}

.review-actions .nb-btn {
  flex: 1;
  height: 42px;
  font-size: 0.95rem;
}

.review-actions .nb-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.review-unknown {
  color: #b91c1c;
}

.review-detail-link {
  margin-top: 14px;
  text-align: center;
  font-size: 0.85rem;
}

.review-done {
  padding: 32px 24px;
  text-align: center;
}

@media (max-width: 840px) {
  /* Search & Inputs: Prevent iOS auto-zoom (<16px triggers zoom) and compact sizing */
  .search-shortcut {
    display: none !important;
  }

  .search-input-wrapper {
    height: 36px;
    padding: 0 10px;
  }

  .search-input-wrapper svg.search-icon {
    width: 15px;
    height: 15px;
    margin-right: 6px;
  }

  .search-input {
    font-size: 16px; /* 阻止移动端聚焦时自动整体放大视口 */
  }

  .search-input::placeholder {
    font-size: 0.82rem;
  }

  .hero-search-wrapper .search-input-wrapper {
    height: 44px;
    padding: 0 12px;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
  }

  .hero-search-wrapper .search-input-wrapper svg.search-icon {
    width: 18px;
    height: 18px;
    margin-right: 8px;
  }

  .hero-search-wrapper .search-input {
    font-size: 16px;
  }

  /* Home Hero & Titles */
  .home-hero {
    padding: 20px 8px 24px;
  }

  .home-badge {
    font-size: 0.78rem;
    padding: 4px 10px;
    margin-bottom: 12px;
  }

  .home-title {
    font-size: clamp(1.35rem, 5.2vw, 1.75rem);
    margin-bottom: 8px;
    line-height: 1.3;
  }

  .home-subtitle {
    font-size: 0.85rem;
    margin-bottom: 18px;
    line-height: 1.5;
  }

  .home-stats-section {
    margin-bottom: 24px;
  }

  /* Stats / Metric Cards: Compact, Never Split Numbers into 2 Lines */
  .stat-card {
    padding: 10px 12px;
    gap: 8px;
    border-radius: var(--radius-sm);
    min-width: 0;
  }

  .stat-icon-wrapper {
    width: 34px;
    height: 34px;
    border-radius: var(--radius-sm);
  }

  .stat-icon-wrapper svg {
    width: 18px;
    height: 18px;
  }

  .stat-number {
    font-size: 1.15rem;
    white-space: nowrap; /* 严禁数字断行 */
    line-height: 1.15;
  }

  .stat-label {
    font-size: 0.72rem;
    white-space: nowrap;
  }

  /* Section Header Rows */
  .section-header-row {
    flex-direction: column;
    align-items: flex-start;
    gap: 6px;
    margin-bottom: 12px;
  }

  .section-header-title {
    font-size: 1.15rem;
  }

  .section-header-sub {
    font-size: 0.78rem;
  }

  .section-header-link {
    font-size: 0.82rem;
    margin-top: 2px;
  }

  /* Card Components (Root, Affix, Word) */
  .root-card,
  .affix-card {
    padding: 10px 12px;
    border-radius: var(--radius-sm);
  }

  .card-header-row {
    flex-wrap: wrap;
    gap: 6px;
  }

  .card-title {
    font-size: 1rem;
    word-break: break-word;
  }

  .card-gloss-zh {
    font-size: 0.84rem;
    line-height: 1.35;
  }

  .card-gloss-en {
    font-size: 0.75rem;
    line-height: 1.35;
    margin-bottom: 6px;
  }

  .card-footer-row {
    flex-wrap: wrap;
    gap: 4px;
    padding-top: 6px;
  }

  /* Filter Bar & Chips */
  .filter-bar {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
    margin-bottom: 14px;
  }

  .filter-chips {
    overflow-x: auto;
    flex-wrap: nowrap;
    padding-bottom: 4px;
    -webkit-overflow-scrolling: touch;
    width: 100%;
    scrollbar-width: none;
  }

  .filter-chips::-webkit-scrollbar {
    display: none;
  }

  .filter-chip {
    flex-shrink: 0;
    font-size: 0.78rem;
    padding: 4px 10px;
  }

  .sort-select {
    width: 100%;
    font-size: 0.85rem;
  }

  /* Lemma Table & List */
  .lemma-toolbar {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
  }

  .lemma-search {
    width: 100%;
    font-size: 16px;
  }

  .lemma-chips {
    overflow-x: auto;
    flex-wrap: nowrap;
    padding-bottom: 4px;
    -webkit-overflow-scrolling: touch;
    width: 100%;
    scrollbar-width: none;
  }

  .lemma-chips::-webkit-scrollbar {
    display: none;
  }

  .lemma-chips .filter-chip {
    flex-shrink: 0;
  }

  .lemma-bulk {
    width: 100%;
    flex-wrap: wrap;
    gap: 6px;
  }

  /* Morpheme Breakdown in Mobile */
  .morpheme-breakdown-card {
    padding: 12px 14px 16px;
    border-radius: var(--radius-md);
    margin-bottom: 16px;
  }

  .morpheme-chain {
    gap: 8px;
    margin-top: 10px;
  }

  .morpheme-block {
    padding: 8px 12px;
    border-radius: var(--radius-sm);
    flex: 1 1 auto;
    min-width: 68px;
  }

  .morpheme-text {
    font-size: 1.05rem;
  }

  .morpheme-role {
    font-size: 0.65rem;
  }

  .morpheme-meaning {
    font-size: 0.76rem;
    max-width: 100%;
    margin-top: 4px;
  }

  .morpheme-divider {
    font-size: 1rem;
  }

  /* Family Navigation & Detail Pages */
  .family-nav {
    padding: 8px 10px;
    font-size: 0.75rem;
    flex-wrap: wrap;
    gap: 6px;
  }

  .detail-title-row {
    gap: 8px;
  }

  .detail-title-row h1 {
    font-size: 1.55rem !important;
    word-break: break-word;
  }

  .word-relation {
    font-size: 0.8rem;
    line-height: 1.45;
    word-break: break-word;
  }

  /* Notebook & Review */
  .nb-hero {
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
  }

  .nb-hero-actions {
    width: 100%;
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
  }

  .nb-hero-actions .nb-btn,
  .nb-hero-actions .review-link-btn {
    flex: 1;
    min-width: 70px;
    text-align: center;
    justify-content: center;
  }

  .nb-toolbar {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
  }

  .nb-search {
    width: 100%;
    font-size: 16px;
  }

  .nb-kind-chips {
    width: 100%;
    overflow-x: auto;
    flex-wrap: nowrap;
    scrollbar-width: none;
  }

  .nb-kind-chips::-webkit-scrollbar {
    display: none;
  }

  .nb-bulk {
    width: 100%;
    flex-wrap: wrap;
    gap: 6px;
    align-items: center;
  }

  .review-card-title {
    font-size: 1.45rem;
    word-break: break-word;
  }

  .review-card {
    min-height: 160px;
    padding: 18px 14px;
  }
}
