/* ==========================================================================
   M3 Theme —— Material Design 3 动态配色主题
   使用 @material/web 组件 + 自定义 CSS 变量
   ========================================================================== */

:root {
  /* M3 配色（light） */
  --md-sys-color-primary: #8f4a3c;
  --md-sys-color-on-primary: #ffffff;
  --md-sys-color-primary-container: #ffdad2;
  --md-sys-color-on-primary-container: #3a0a05;
  --md-sys-color-secondary: #77564f;
  --md-sys-color-on-secondary: #ffffff;
  --md-sys-color-secondary-container: #ffdad2;
  --md-sys-color-on-secondary-container: #2c1512;
  --md-sys-color-tertiary: #6e5d2e;
  --md-sys-color-on-tertiary: #ffffff;
  --md-sys-color-tertiary-container: #f8e1a6;
  --md-sys-color-on-tertiary-container: #251a00;
  --md-sys-color-error: #ba1a1a;
  --md-sys-color-on-error: #ffffff;
  --md-sys-color-error-container: #ffdad6;
  --md-sys-color-on-error-container: #410002;
  --md-sys-color-background: #fff8f6;
  --md-sys-color-on-background: #271815;
  --md-sys-color-surface: #fff8f6;
  --md-sys-color-on-surface: #271815;
  --md-sys-color-surface-variant: #f5ded9;
  --md-sys-color-on-surface-variant: #534340;
  --md-sys-color-outline: #86736f;
  --md-sys-color-outline-variant: #d8c2bd;
  --md-sys-color-inverse-surface: #3d2c29;
  --md-sys-color-inverse-on-surface: #ffede9;
  --md-sys-color-inverse-primary: #ffb4a3;
  --md-sys-color-surface-container-lowest: #ffffff;
  --md-sys-color-surface-container-low: #fff1ed;
  --md-sys-color-surface-container: #ffe9e4;
  --md-sys-color-surface-container-high: #f8e2dd;
  --md-sys-color-surface-container-highest: #f2dcd7;

  /* 间距与形状 */
  --m3-radius-xs: 4px;
  --m3-radius-sm: 8px;
  --m3-radius-md: 12px;
  --m3-radius-lg: 16px;
  --m3-radius-xl: 28px;
  --m3-space-1: 4px;
  --m3-space-2: 8px;
  --m3-space-3: 12px;
  --m3-space-4: 16px;
  --m3-space-5: 20px;
  --m3-space-6: 24px;
  --m3-space-8: 32px;
  --m3-space-10: 40px;
  --m3-space-12: 48px;
  --m3-content-max: 960px;

  /* 字体 */
  --m3-font-family: 'MiSans', 'MiSans L3', system-ui, -apple-system, 'PingFang SC', 'Noto Sans SC', sans-serif;
  --m3-font-mono: 'JetBrains Mono', 'Fira Code', 'Cascadia Code', monospace;

  /* 特殊语义色 */
  --m3-gold: #7a5c00;
  --m3-vermilion: #ba1a1a;
}

/* ── 全局重置 ─────────────────────────────────────────────────────────── */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-family: var(--m3-font-family);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  text-autospace: normal;
  scroll-behavior: smooth;
}

body {
  background: var(--md-sys-color-background);
  color: var(--md-sys-color-on-background);
  font-size: 16px;
  line-height: 1.7;
  min-height: 100vh;
  transition: background-color 0.3s ease, color 0.3s ease;
}

/* ── 布局骨架 ─────────────────────────────────────────────────────────── */
pboc-app {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.page-header {
  text-align: center;
  padding: var(--m3-space-8) var(--m3-space-4) var(--m3-space-4);
}

.page-header h1 a {
  text-decoration: none;
  color: inherit;
  display: inline-flex;
  flex-direction: column;
  gap: var(--m3-space-1);
}

.project-english-line {
  font-size: 1.25rem;
  font-weight: 300;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--md-sys-color-on-surface-variant);
}

.project-chinese-line {
  font-size: 2rem;
  font-weight: 500;
  color: var(--md-sys-color-on-surface);
}

.project-acronym {
  font-size: 0.8125rem;
  font-weight: 600;
  letter-spacing: 0.3em;
  color: var(--md-sys-color-primary);
  text-transform: uppercase;
  margin-top: var(--m3-space-1);
}

/* ── 搜索区 ───────────────────────────────────────────────────────────── */
.search-container {
  max-width: var(--m3-content-max);
  margin: 0 auto;
  padding: 0 var(--m3-space-4) var(--m3-space-6);
  display: flex;
  flex-direction: column;
  gap: var(--m3-space-4);
}

.search-box {
  display: flex;
  gap: var(--m3-space-3);
  align-items: flex-start;
}

.field-wrap {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.search-box md-filled-text-field {
  width: 100%;
}

/* 字数计数器（按 Unicode 码点计；原生 maxlength 按 UTF-16 码元，扩展区汉字会错算为 2） */
.char-counter {
  align-self: flex-end;
  font-size: 0.8125rem;
  line-height: 1.6;
  color: var(--md-sys-color-on-surface-variant);
  user-select: none;
}

.search-box md-filled-button {
  --md-filled-button-container-height: 56px;
  --md-filled-button-container-shape: var(--m3-radius-lg);
  --md-filled-button-label-text-size: 1.125rem;
  --md-filled-button-label-text-weight: 600;
  flex-shrink: 0;
  align-self: flex-start;
  min-width: 88px;
}

@media (max-width: 640px) {
  .search-box {
    flex-direction: column;
    align-items: stretch;
  }
  .search-box md-filled-button {
    --md-filled-button-container-height: 48px;
    --md-filled-button-label-text-size: 1rem;
    width: 100%;
  }
}

.search-options {
  display: flex;
  gap: var(--m3-space-2);
  flex-wrap: wrap;
  justify-content: center;
}

.search-options md-filter-chip {
  --md-filter-chip-container-height: 36px;
}

/* ── 加载进度 ─────────────────────────────────────────────────────────── */
.loading-progress {
  text-align: center;
  padding: var(--m3-space-4);
  color: var(--md-sys-color-on-surface-variant);
  font-size: 0.9375rem;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--m3-space-3);
}

/* ── 更新提示条 ───────────────────────────────────────────────────────── */
.update-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--m3-space-3);
  padding: var(--m3-space-3) var(--m3-space-4);
  margin: 0 auto var(--m3-space-4);
  max-width: var(--m3-content-max);
  background: var(--md-sys-color-primary-container);
  color: var(--md-sys-color-on-primary-container);
  border-radius: var(--m3-radius-md);
  font-size: 0.9375rem;
}

.update-bar md-text-button {
  --md-text-button-label-text-color: var(--md-sys-color-on-primary-container);
}

/* ── 状态条 ───────────────────────────────────────────────────────────── */
.status-bar {
  text-align: center;
  padding: var(--m3-space-2) var(--m3-space-4);
  font-size: 0.875rem;
  color: var(--m3-gold);
  max-width: var(--m3-content-max);
  margin: 0 auto var(--m3-space-2);
}

.status-bar.error {
  color: var(--m3-vermilion);
}

.regex-error {
  text-align: center;
  padding: var(--m3-space-2) var(--m3-space-4);
  font-size: 0.875rem;
  color: var(--m3-vermilion);
  max-width: var(--m3-content-max);
  margin: 0 auto var(--m3-space-2);
}

/* ── 搜索历史 ─────────────────────────────────────────────────────────── */
.search-history-section {
  max-width: var(--m3-content-max);
  margin: 0 auto var(--m3-space-4);
  padding: 0 var(--m3-space-4);
}

.search-history-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--m3-space-3);
}

.search-history-title {
  font-size: 0.9375rem;
  font-weight: 500;
  color: var(--md-sys-color-on-surface-variant);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.search-history-list {
  display: flex;
  flex-wrap: wrap;
  gap: var(--m3-space-2);
  list-style: none;
}

.history-chip {
  display: inline-flex;
  align-items: center;
  gap: var(--m3-space-1);
  padding: var(--m3-space-1) var(--m3-space-2) var(--m3-space-1) var(--m3-space-3);
  background: var(--md-sys-color-surface-container);
  color: var(--md-sys-color-on-surface);
  border-radius: var(--m3-radius-sm);
  font-size: 0.875rem;
  cursor: pointer;
  transition: background 0.2s;
  border: none;
  user-select: none;
}

.history-chip:hover {
  background: var(--md-sys-color-surface-container-high);
}

.history-chip-query {
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-chip-mode {
  font-size: 0.75rem;
  color: var(--md-sys-color-primary);
  font-weight: 500;
}

.history-chip-delete {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  border: none;
  background: none;
  border-radius: 50%;
  cursor: pointer;
  color: var(--md-sys-color-on-surface-variant);
  transition: background 0.2s;
}

.history-chip-delete:hover {
  background: var(--md-sys-color-surface-container-highest);
  color: var(--m3-vermilion);
}

/* ── 结果区 ───────────────────────────────────────────────────────────── */
.results-main {
  flex: 1;
  max-width: var(--m3-content-max);
  width: 100%;
  margin: 0 auto;
  padding: 0 var(--m3-space-4) var(--m3-space-8);
}

/* ── 分页条 ───────────────────────────────────────────────────────────── */
.pagination-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--m3-space-3);
  padding: var(--m3-space-3) 0;
  margin-bottom: var(--m3-space-4);
}

.pagination-summary {
  font-size: 0.875rem;
  color: var(--md-sys-color-on-surface-variant);
}

.pagination-summary b {
  color: var(--md-sys-color-on-surface);
  font-weight: 600;
}

.pagination-controls {
  display: flex;
  align-items: center;
  gap: var(--m3-space-1);
  flex-wrap: wrap;
}

.pagination-controls select {
  font-family: inherit;
  font-size: 0.875rem;
  padding: var(--m3-space-1) var(--m3-space-2);
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: var(--m3-radius-xs);
  background: var(--md-sys-color-surface);
  color: var(--md-sys-color-on-surface);
  cursor: pointer;
}

.pagination-size, .sort-select {
  display: inline-flex;
  align-items: center;
  gap: var(--m3-space-1);
  font-size: 0.875rem;
  color: var(--md-sys-color-on-surface-variant);
  margin-right: var(--m3-space-2);
}

.pagination-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 32px;
  height: 32px;
  padding: 0 var(--m3-space-1);
  border: none;
  border-radius: var(--m3-radius-xs);
  background: none;
  color: var(--md-sys-color-on-surface);
  font-family: inherit;
  font-size: 0.875rem;
  cursor: pointer;
  transition: background 0.2s;
}

.pagination-btn:hover:not(:disabled) {
  background: var(--md-sys-color-surface-container-high);
}

.pagination-btn:disabled {
  opacity: 0.38;
  cursor: default;
}

.pagination-btn[aria-current="page"] {
  background: var(--md-sys-color-primary-container);
  color: var(--md-sys-color-on-primary-container);
  font-weight: 600;
}

.pagination-ellipsis {
  color: var(--md-sys-color-on-surface-variant);
  padding: 0 var(--m3-space-1);
}

/* ── 结果卡片 ─────────────────────────────────────────────────────────── */
.result-card {
  background: var(--md-sys-color-surface-container-low);
  border-radius: var(--m3-radius-lg);
  margin-bottom: var(--m3-space-4);
  overflow: hidden;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
  animation: fadeInUp 0.4s ease both;
}

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

.card-banner {
  display: flex;
  gap: var(--m3-space-4);
  padding: var(--m3-space-5);
  background: var(--md-sys-color-surface-container);
}

.card-banner-left {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--m3-space-2);
  flex-shrink: 0;
}

.card-glyph {
  font-size: 3.5rem;
  font-weight: 400;
  line-height: 1;
  color: var(--md-sys-color-on-surface);
  min-width: 64px;
  text-align: center;
  font-family: var(--m3-font-family);
}

.zi-link {
  font-size: 0.75rem;
  color: var(--md-sys-color-primary);
  text-decoration: underline;
  text-decoration-style: dotted;
  text-underline-offset: 3px;
  display: inline-flex;
  align-items: center;
  gap: 2px;
}

.zi-link:hover {
  text-decoration-style: solid;
}

.card-banner-right {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: var(--m3-space-3);
  min-width: 0;
}

.phonetic-row {
  display: flex;
  align-items: center;
  gap: var(--m3-space-2);
}

.phonetic-label {
  font-size: 0.75rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--md-sys-color-on-surface-variant);
  min-width: 32px;
}

.phonetic-value {
  font-family: var(--m3-font-mono);
  font-size: 1.125rem;
  font-weight: 500;
  color: var(--md-sys-color-primary);
}

.pinyin-value {
  font-family: var(--m3-font-mono);
  font-size: 1rem;
  color: var(--md-sys-color-on-surface);
}

.copy-icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border: none;
  border-radius: 50%;
  background: none;
  color: var(--md-sys-color-on-surface-variant);
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
}

.copy-icon-btn:hover {
  background: var(--md-sys-color-surface-container-highest);
  color: var(--md-sys-color-primary);
}

.derived-phonology {
  display: flex;
  flex-wrap: wrap;
  gap: var(--m3-space-3);
  padding: var(--m3-space-2) var(--m3-space-3);
  background: var(--md-sys-color-surface-container-high);
  border-radius: var(--m3-radius-sm);
  font-size: 0.875rem;
}

.derived-heading {
  font-weight: 500;
  color: var(--md-sys-color-on-surface-variant);
}

.derived-item {
  display: inline-flex;
  align-items: center;
  gap: var(--m3-space-1);
}

.derived-label {
  color: var(--md-sys-color-on-surface-variant);
  font-size: 0.8125rem;
}

.derived-value {
  color: var(--md-sys-color-on-surface);
  font-family: var(--m3-font-mono);
  font-size: 0.875rem;
}

button.derived-value {
  border: none;
  background: none;
  cursor: pointer;
  padding: 0;
  color: var(--md-sys-color-primary);
  text-decoration: underline;
  text-underline-offset: 3px;
}

button.derived-value:hover {
  text-decoration-thickness: 2px;
}

.card-tags {
  display: flex;
  flex-wrap: wrap;
  gap: var(--m3-space-2);
}

.tag-btn {
  display: inline-flex;
  align-items: center;
  gap: var(--m3-space-1);
  padding: var(--m3-space-1) var(--m3-space-2);
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: var(--m3-radius-xs);
  background: none;
  color: var(--md-sys-color-on-surface-variant);
  font-family: inherit;
  font-size: 0.8125rem;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.2s;
}

.tag-btn:hover {
  background: var(--md-sys-color-surface-container-high);
}

.tag-btn.xiesheng {
  color: var(--md-sys-color-primary);
  border-color: var(--md-sys-color-primary-container);
  background: var(--md-sys-color-primary-container);
}

.tag-btn.rhyme {
  color: var(--md-sys-color-tertiary);
  border-color: var(--md-sys-color-tertiary-container);
  background: var(--md-sys-color-tertiary-container);
}

.card-actions {
  display: flex;
  align-items: flex-start;
  gap: var(--m3-space-1);
  flex-shrink: 0;
}

.export-btn {
  display: inline-flex;
  align-items: center;
  gap: var(--m3-space-1);
  padding: var(--m3-space-1) var(--m3-space-2);
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: var(--m3-radius-xs);
  background: none;
  color: var(--md-sys-color-on-surface-variant);
  font-family: inherit;
  font-size: 0.8125rem;
  cursor: pointer;
  transition: background 0.2s;
  white-space: nowrap;
}

.export-btn:hover:not(:disabled) {
  background: var(--md-sys-color-surface-container-high);
}

.export-btn:disabled {
  opacity: 0.5;
  cursor: default;
}

.card-body {
  padding: var(--m3-space-4) var(--m3-space-5) var(--m3-space-5);
}

.section-header {
  display: flex;
  align-items: baseline;
  gap: var(--m3-space-2);
  margin-bottom: var(--m3-space-2);
}

.section-label {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--md-sys-color-primary);
}

.section-note {
  font-size: 0.8125rem;
  color: var(--md-sys-color-on-surface-variant);
}

.meanings-list {
  list-style: none;
  padding-left: 0;
}

.meanings-list li {
  display: flex;
  gap: var(--m3-space-2);
  padding: var(--m3-space-1) 0;
  font-size: 1rem;
  line-height: 1.7;
  color: var(--md-sys-color-on-surface);
}

.sense-num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--md-sys-color-primary-container);
  color: var(--md-sys-color-on-primary-container);
  font-size: 0.75rem;
  font-weight: 600;
  flex-shrink: 0;
  margin-top: 2px;
}

.empty-meaning {
  font-size: 0.875rem;
  color: var(--md-sys-color-on-surface-variant);
  font-style: italic;
}

.section-divider {
  height: 1px;
  background: var(--md-sys-color-outline-variant);
  margin: var(--m3-space-4) 0;
}

.annotation-list {
  list-style: none;
  padding-left: 0;
}

.annotation-list li {
  padding: var(--m3-space-1) 0 var(--m3-space-1) var(--m3-space-4);
  position: relative;
  font-size: 1rem;
  line-height: 1.7;
  color: var(--md-sys-color-on-surface-variant);
}

.annotation-list li::before {
  content: '';
  position: absolute;
  left: var(--m3-space-2);
  top: 0.7em;
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--md-sys-color-outline);
}

.annotation-link {
  color: var(--md-sys-color-primary);
  text-decoration: underline;
  text-underline-offset: 3px;
  text-decoration-thickness: 1px;
}

.annotation-link:hover {
  text-decoration-thickness: 2px;
}

mark.meaning-search-hit {
  background: var(--md-sys-color-tertiary-container);
  color: var(--md-sys-color-on-tertiary-container);
  border-radius: 2px;
  padding: 0 2px;
}

/* ── 批量结果 ─────────────────────────────────────────────────────────── */
.batch-container {
  padding: var(--m3-space-4) 0;
}

.batch-actions {
  display: flex;
  gap: var(--m3-space-2);
  margin-bottom: var(--m3-space-4);
}

.batch-actions md-outlined-button {
  --md-outlined-button-container-height: 48px;
  --md-outlined-button-label-text-size: 1rem;
  --md-outlined-button-label-text-weight: 500;
  min-width: 160px;
}

.batch-table-wrap {
  overflow-x: auto;
  border-radius: var(--m3-radius-md);
  border: 1px solid var(--md-sys-color-outline-variant);
}

.batch-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

.batch-table th {
  background: var(--md-sys-color-surface-container);
  padding: var(--m3-space-2) var(--m3-space-3);
  text-align: left;
  font-weight: 600;
  color: var(--md-sys-color-on-surface-variant);
  font-size: 0.8125rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.batch-table td {
  padding: var(--m3-space-2) var(--m3-space-3);
  border-top: 1px solid var(--md-sys-color-outline-variant);
}

.batch-char {
  font-size: 1.25rem;
  font-weight: 500;
  text-align: center;
  min-width: 48px;
}

.batch-not-found {
  color: var(--md-sys-color-on-surface-variant);
  font-style: italic;
}

.batch-pinyin, .batch-phonetic, .batch-domain {
  font-family: var(--m3-font-mono);
  font-size: 0.875rem;
}

.batch-summary {
  margin-top: var(--m3-space-3);
  font-size: 0.875rem;
  color: var(--md-sys-color-on-surface-variant);
}

/* ── 欢迎页 ───────────────────────────────────────────────────────────── */
.welcome-page {
  max-width: 720px;
  margin: 0 auto;
}

.welcome-intro h2 {
  font-size: 1.25rem;
  font-weight: 500;
  color: var(--md-sys-color-on-surface);
  margin-bottom: var(--m3-space-3);
}

.welcome-intro p {
  font-size: 1rem;
  line-height: 1.8;
  color: var(--md-sys-color-on-surface-variant);
  margin-bottom: var(--m3-space-6);
}

.welcome-intro a,
.welcome-details a,
.welcome-section a {
  color: var(--md-sys-color-primary);
  text-decoration: underline;
  text-underline-offset: 3px;
  text-decoration-thickness: 1px;
  text-decoration-color: color-mix(in srgb, var(--md-sys-color-primary) 55%, transparent);
}

.welcome-intro a:hover,
.welcome-details a:hover,
.welcome-section a:hover {
  text-decoration-color: var(--md-sys-color-primary);
  text-decoration-thickness: 2px;
}

.welcome-section {
  margin-bottom: var(--m3-space-6);
}

.welcome-section h3 {
  font-size: 1rem;
  font-weight: 600;
  color: var(--md-sys-color-on-surface);
  margin-bottom: var(--m3-space-3);
}

.welcome-section p {
  font-size: 1rem;
  line-height: 1.7;
  color: var(--md-sys-color-on-surface-variant);
  margin-bottom: var(--m3-space-3);
}

.welcome-list {
  padding-left: var(--m3-space-5);
}

.welcome-list li {
  font-size: 1rem;
  line-height: 1.7;
  color: var(--md-sys-color-on-surface-variant);
  margin-bottom: var(--m3-space-2);
}

.welcome-list strong {
  color: var(--md-sys-color-on-surface);
}

.welcome-details {
  margin-bottom: var(--m3-space-2);
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: var(--m3-radius-sm);
  padding: var(--m3-space-3) var(--m3-space-4);
}

.welcome-details summary {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--md-sys-color-on-surface);
  cursor: pointer;
  user-select: none;
}

.welcome-details summary:hover {
  color: var(--md-sys-color-primary);
}

.welcome-details p {
  margin-top: var(--m3-space-2);
  font-size: 1rem;
  line-height: 1.7;
  color: var(--md-sys-color-on-surface-variant);
}

.welcome-details code {
  font-family: var(--m3-font-mono);
  font-size: 0.9375rem;
  background: var(--md-sys-color-surface-container);
  padding: 1px 4px;
  border-radius: 2px;
}

.welcome-details a {
  color: var(--md-sys-color-primary);
  text-decoration: none;
}

.welcome-details a:hover {
  text-decoration: underline;
}

/* ── 无结果 ───────────────────────────────────────────────────────────── */
.no-result {
  text-align: center;
  padding: var(--m3-space-10) var(--m3-space-4);
  color: var(--md-sys-color-on-surface-variant);
}

.no-result span {
  font-size: 0.875rem;
  opacity: 0.7;
}

/* ── 页脚 ─────────────────────────────────────────────────────────────── */
.site-footer {
  text-align: center;
  padding: var(--m3-space-4);
  font-size: 0.8125rem;
  color: var(--md-sys-color-on-surface-variant);
  border-top: 1px solid var(--md-sys-color-outline-variant);
  margin-top: auto;
}

/* MiSans 知识产权归属声明（PRD §3.2.3：醒目标注） */
.misans-attribution {
  margin-top: var(--m3-space-2);
  max-width: 64ch;
  margin-left: auto;
  margin-right: auto;
  line-height: 1.6;
}

/* ── 回到搜索 ─────────────────────────────────────────────────────────── */
.back-to-top {
  position: fixed;
  bottom: var(--m3-space-6);
  right: var(--m3-space-6);
  z-index: 100;
  display: inline-flex;
  align-items: center;
  gap: var(--m3-space-1);
  padding: var(--m3-space-2) var(--m3-space-3);
  background: var(--md-sys-color-primary-container);
  color: var(--md-sys-color-on-primary-container);
  border: none;
  border-radius: var(--m3-radius-md);
  font-family: inherit;
  font-size: 0.8125rem;
  font-weight: 500;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(0,0,0,0.12);
  opacity: 0;
  pointer-events: none;
  transform: translateY(8px);
  transition: opacity 0.25s, transform 0.25s;
}

.back-to-top.visible {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
}

.back-to-top:hover {
  background: var(--md-sys-color-primary);
  color: var(--md-sys-color-on-primary);
}

/* ── Material Symbols 图标 ────────────────────────────────────────────── */
.material-symbols-rounded {
  font-family: 'Material Symbols Rounded';
  font-weight: normal;
  font-style: normal;
  font-size: 20px;
  line-height: 1;
  letter-spacing: normal;
  text-transform: none;
  display: inline-block;
  white-space: nowrap;
  word-wrap: normal;
  direction: ltr;
  -webkit-font-smoothing: antialiased;
  font-variation-settings: 'FILL' 0, 'wght' 400, 'GRAD' 0, 'opsz' 24;
}

/* ── 全局链接样式（WCAG 1.4.1 不能仅靠颜色区分） ── */
a {
  /* 覆盖 UA 默认蓝色；页眉标题链接由 .page-header a（higher specificity）恢复 inherit */
  color: var(--md-sys-color-primary);
}

a,
button.derived-value,
button.initial-search,
button.tag-btn {
  text-decoration: underline;
  text-underline-offset: 3px;
  text-decoration-thickness: 1px;
}

a:hover,
button.derived-value:hover,
button.initial-search:hover,
button.tag-btn:hover {
  text-decoration-thickness: 2px;
}

/* 明确不希望下划线的链接（卡片标题区除外） */
.page-header a,
.zi-link,
.back-to-top {
  text-decoration: none;
}

/* ── 响应式 ───────────────────────────────────────────────────────────── */
@media (max-width: 640px) {
  .search-box {
    flex-direction: column;
  }
  .search-box md-filled-text-field {
    width: 100%;
  }
  .search-box md-filled-button {
    width: 100%;
    --md-filled-button-container-height: 48px;
  }
  .card-banner {
    flex-direction: column;
    align-items: center;
    text-align: center;
  }
  .card-banner-right {
    width: 100%;
  }
  .phonetic-row {
    justify-content: center;
  }
  .derived-phonology {
    justify-content: center;
  }
  .card-tags {
    justify-content: center;
  }
  .pagination-bar {
    flex-direction: column;
    align-items: center;
  }
  .project-chinese-line {
    font-size: 1.5rem;
  }
}

/* ════════════════════════════════════════════════════════════════════════
   深色模式 —— WCAG AA 对比度（≥4.5:1 正文，≥3:1 大字/UI 组件）
   所有 token 经 https://webaim.org/resources/contrastchecker/ 校验
   ════════════════════════════════════════════════════════════════════════ */
@media (prefers-color-scheme: dark) {
  :root {
    /* primary: #ffb4a3 on #1c1a17 → 7.0:1 */
    --md-sys-color-primary: #ffb4a3;
    --md-sys-color-on-primary: #4a0000;          /* on primary btn, 11.6:1 */
    --md-sys-color-primary-container: #723427;
    --md-sys-color-on-primary-container: #ffdad2; /* 8.0:1 */

    --md-sys-color-secondary: #e7bdb4;
    --md-sys-color-on-secondary: #442924;
    --md-sys-color-secondary-container: #5c3f39;
    --md-sys-color-on-secondary-container: #ffdad2;

    --md-sys-color-tertiary: #d8c58d;
    --md-sys-color-on-tertiary: #3b2f05;
    --md-sys-color-tertiary-container: #53461a;
    --md-sys-color-on-tertiary-container: #f5e1a6;

    --md-sys-color-error: #ffb4ab;
    --md-sys-color-on-error: #690005;
    --md-sys-color-error-container: #93000a;
    --md-sys-color-on-error-container: #ffdad6;

    --md-sys-color-background: #1c1a17;          /* base surface */
    --md-sys-color-on-background: #efe0dc;        /* 13.4:1 */
    --md-sys-color-surface: #1c1a17;
    --md-sys-color-on-surface: #efe0dc;           /* 13.4:1 */

    --md-sys-color-surface-variant: #534340;
    --md-sys-color-on-surface-variant: #d8c2bd;   /* 8.6:1 */

    --md-sys-color-outline: #a08c88;
    --md-sys-color-outline-variant: #534340;

    --md-sys-color-inverse-surface: #efe0dc;
    --md-sys-color-inverse-on-surface: #382e2b;
    --md-sys-color-inverse-primary: #8f4a3c;

    /* elevation surfaces */
    --md-sys-color-surface-container-lowest: #110f0d;
    --md-sys-color-surface-container-low: #1c1a17;
    --md-sys-color-surface-container: #211f1b;
    --md-sys-color-surface-container-high: #2b2523;
    --md-sys-color-surface-container-highest: #36302d;

    /* 语义色 */
    --m3-gold: #f5e1a6;                          /* 7.4:1 on dark bg */
    --m3-vermilion: #ffb4ab;                     /* 7.0:1 */
  }

  /* 阴影在深色下要更深 */
  .result-card {
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.5);
  }
  .back-to-top {
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.6);
  }

  /* 高亮 hit 标记在深色下可读 */
  mark.meaning-search-hit {
    background: #6b5a1f;
    color: #f5e1a6;
  }

  /* M3 web 组件深色适配：自动跟随 token */
  md-filled-text-field,
  md-filled-button,
  md-outlined-button,
  md-text-button,
  md-filter-chip {
    color-scheme: dark;
  }

  /* 链接在深色下要更高对比 */
  .zi-link,
  .annotation-link,
  .welcome-intro a,
  .welcome-details a,
  button.derived-value {
    color: var(--md-sys-color-primary);
    text-decoration: underline;
    text-underline-offset: 3px;
    text-decoration-thickness: 1px;
  }
}
