/* 阅读型词典：黑白灰中性底 + 单一蓝色主题色 */
:root {
  color-scheme: light;
  --bg: #f7f7f7;
  --bg-elevated: rgba(255, 255, 255, .92);
  --surface: #ffffff;
  --surface-raised: #ffffff;
  --surface-soft: #f0f0f0;
  --text: #232323;
  --text-strong: #101010;
  --muted: #5f5f5f;
  --subtle: #7d7d7d;
  --border: #e0e0e0;
  --border-strong: #cfcfcf;
  --primary: #2563eb;
  --primary-strong: #1d4ed8;
  --primary-soft: #dbe7fd;
  --primary-text: #ffffff;
  --accent: #525252;
  --accent-soft: #e8e8e8;
  --danger: #b42318;
  --danger-soft: #fdecea;
  --success: #2e7d32;
  --success-soft: #e6f2e7;
  --focus: #2563eb;
  --shadow: 0 20px 55px rgba(0, 0, 0, .10);
  --shadow-soft: 0 10px 30px rgba(0, 0, 0, .08);
  --scrim: rgba(0, 0, 0, .42);
  --radius-sm: 10px;
  --radius: 16px;
  --radius-lg: 24px;
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-8: 32px;
  --space-10: 40px;
  --font-sans: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "SF Pro Text", "PingFang SC", "Microsoft YaHei", sans-serif;
  --font-serif: "Iowan Old Style", "Source Serif 4", "Noto Serif SC", Georgia, serif;
  --header-h: 60px;
  --nav-h: 64px;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #121212;
  --bg-elevated: rgba(26, 26, 26, .94);
  --surface: #1a1a1a;
  --surface-raised: #242424;
  --surface-soft: #262626;
  --text: #e6e6e6;
  --text-strong: #f4f4f4;
  --muted: #a8a8a8;
  --subtle: #878787;
  --border: #363636;
  --border-strong: #474747;
  --primary: #7aa2f7;
  --primary-strong: #9bb9f9;
  --primary-soft: #1e2f4d;
  --primary-text: #0d1b33;
  --accent: #d4d4d4;
  --accent-soft: #3a3a3a;
  --danger: #ff938b;
  --danger-soft: #46201e;
  --success: #7fb386;
  --success-soft: #273528;
  --focus: #7aa2f7;
  --shadow: 0 24px 60px rgba(0, 0, 0, .30);
  --shadow-soft: 0 12px 32px rgba(0, 0, 0, .22);
  --scrim: rgba(0, 0, 0, .68);
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--bg); }
body {
  min-height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.5;
  text-rendering: optimizeLegibility;
  overflow-x: hidden;
}
button, input, select { font: inherit; color: inherit; }
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
button, a, summary, .history-row { touch-action: manipulation; }
button { border: 0; cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .55; }
.icon {
  display: inline-block;
  width: 24px;
  height: 24px;
  flex: none;
  fill: currentColor;
}
[hidden] { display: none !important; }
a { color: var(--primary); text-underline-offset: 3px; }
:focus { outline: none; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 3px; border-radius: 8px; }
::selection { background: var(--primary-soft); color: var(--text-strong); }

.skip-link {
  position: fixed;
  z-index: 50;
  top: var(--space-4);
  left: var(--space-4);
  transform: translateY(-150%);
  background: var(--primary);
  color: var(--primary-text);
  padding: 10px 14px;
  border-radius: 999px;
  text-decoration: none;
  transition: transform .18s ease;
}
.skip-link:focus { transform: translateY(0); }

.app-shell {
  min-height: 100dvh;
  padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom));
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  height: var(--header-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: 0 max(var(--space-4), env(safe-area-inset-left)) 0 max(var(--space-4), env(safe-area-inset-left));
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(18px);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  min-height: 44px;
  border-radius: 999px;
  color: var(--text-strong);
  text-decoration: none;
  font-size: 15px;
  font-weight: 700;
}
.brand-mark {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: 10px;
  background: var(--primary);
  color: var(--primary-text);
  box-shadow: var(--shadow-soft);
}
.brand .icon { width: 20px; height: 20px; }
.brand span:last-child { letter-spacing: .01em; }

.header-actions { display: flex; align-items: center; gap: 4px; }
.header-actions .icon-button[data-open-settings] { display: none; }
.nav-label { display: none; }

.icon-button {
  position: relative;
  display: inline-grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  transition: background-color .16s ease, color .16s ease;
}
.icon-button:hover { background: var(--surface-soft); color: var(--text); }
.icon-button:active { background: var(--border); }
.icon-button[aria-pressed="true"],
.icon-button[aria-current="page"] { background: var(--primary-soft); color: var(--primary-strong); }

.badge {
  position: absolute;
  right: 5px;
  top: 5px;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border: 2px solid var(--bg);
  border-radius: 999px;
  background: var(--primary);
  color: var(--primary-text);
  font-size: 10px;
  line-height: 14px;
  font-weight: 700;
}
.badge[hidden] { display: none; }

.app-main { width: min(100%, 1180px); margin: 0 auto; }
.view {
  display: none;
  padding: var(--space-5) max(var(--space-4), env(safe-area-inset-left)) var(--space-8) max(var(--space-4), env(safe-area-inset-left));
}
.view.active { display: block; }

.search-panel { position: relative; z-index: 10; max-width: 820px; margin: 0 auto; }
.search-box {
  display: grid;
  grid-template-columns: 22px 1fr auto;
  align-items: center;
  gap: 10px;
  min-height: 54px;
  padding: 5px 5px 5px 16px;
  border: 1px solid var(--border-strong);
  border-radius: 14px;
  background: var(--surface-raised);
  box-shadow: 0 4px 18px rgba(0, 0, 0, .05);
}
.search-box:focus-within { border-color: var(--primary); box-shadow: 0 0 0 3px color-mix(in srgb, var(--focus) 14%, transparent); }
.search-box .icon { width: 22px; height: 22px; color: var(--subtle); }
.search-box input {
  width: 100%;
  min-width: 0;
  border: 0;
  background: transparent;
  color: var(--text-strong);
  font-size: 16px;
}
.search-box input::placeholder { color: var(--subtle); }
.search-box input:focus { outline: 0; }
.recent-searches { display: flex; flex-wrap: nowrap; gap: 6px; margin-top: 10px; overflow-x: auto; padding-bottom: 2px; scrollbar-width: none; }
.recent-searches::-webkit-scrollbar { display: none; }
.recent-search {
  flex: none;
  max-width: 160px;
  min-height: 40px;
  overflow: hidden;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.recent-search:hover { border-color: var(--primary); background: var(--primary-soft); color: var(--primary-strong); }

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 16px;
  border-radius: 14px;
  background: var(--surface-soft);
  color: var(--text);
  font-weight: 700;
  text-decoration: none;
  transition: transform .14s ease, background-color .16s ease, color .16s ease;
}
.button:hover { background: var(--border); }
.button:active { transform: translateY(1px); }
.button-primary {
  min-height: 44px;
  padding: 0 18px;
  border-radius: 11px;
  background: var(--primary);
  color: var(--primary-text);
}
.button-primary:hover { background: var(--primary-strong); }
.button-accent { background: var(--accent); color: var(--text-strong); }
.button-danger { background: var(--danger-soft); color: var(--danger); }
.button-text { min-height: 44px; padding: 0 10px; background: transparent; color: var(--muted); }
.button-text:hover { background: var(--surface-soft); color: var(--text); }
.button.small { min-height: 44px; padding: 0 12px; border-radius: 10px; font-size: 13px; }
.button.full { width: 100%; }

.status {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 22px;
  margin-top: 10px;
  padding: 0 2px;
  color: var(--muted);
  font-size: 13px;
}
.status[role="status"]:not(:empty)::before,
.source-dot {
  content: "";
  width: 9px;
  height: 9px;
  flex: none;
  border-radius: 50%;
  background: var(--subtle);
}
.status[data-state="loading"]::before { background: var(--primary); animation: pulse 1.1s ease-in-out infinite; }
.status[data-state="success"]::before { background: var(--success); }
.status[data-state="error"] { color: var(--danger); }
.status[data-state="error"]::before { background: var(--danger); }
@keyframes pulse { 50% { opacity: .38; transform: scale(.75); } }

.result-view { display: none; margin-top: var(--space-5); }
.result-view.has-result { display: block; }
.word-card {
  max-width: 820px;
  margin: 0 auto var(--space-3);
  padding: var(--space-5);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow-soft);
}
.word-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
}
.word-heading h2 {
  margin: 0;
  overflow-wrap: anywhere;
  color: var(--text-strong);
  font-family: var(--font-serif);
  font-size: clamp(1.75rem, 4vw, 2.4rem);
  line-height: 1.1;
  letter-spacing: -.025em;
}
.word-actions { display: flex; flex: none; gap: 2px; }
.word-actions .icon-button[aria-pressed="true"] { color: var(--primary-strong); background: var(--primary-soft); }

.tag-list { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.tag {
  padding: 3px 9px;
  border-radius: 999px;
  background: var(--surface-soft);
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
}
.tag-list[data-kind="tags"] .tag { background: var(--primary-soft); color: var(--primary-strong); }
.tag-list[data-kind="syns"] .tag { background: var(--primary-soft); color: var(--primary-strong); }

.pronunciations {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  margin-top: var(--space-4);
}
.accent-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 50px;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface-raised);
}
.accent-card > div { min-width: 0; }
.accent-name { display: block; color: var(--subtle); font-size: 12px; font-weight: 650; }
.ipa { color: var(--text-strong); font-family: var(--font-serif); font-size: 17px; letter-spacing: .01em; }
.play-button { color: var(--primary-strong); }
.play-button:hover { background: var(--primary-soft); color: var(--primary-strong); }
.play-button.is-loading .icon { animation: pulse 1s ease-in-out infinite; }

.details-section { margin-top: var(--space-4); border-top: 1px solid var(--border); padding-top: var(--space-4); }
.section-title {
  margin: 0 0 10px;
  color: var(--text-strong);
  font-size: 12px;
  letter-spacing: .06em;
  text-transform: uppercase;
}
.definition-list { display: grid; gap: 10px; margin: 0; padding: 0; list-style: none; }
.definition-list li { display: grid; grid-template-columns: auto 1fr; gap: 9px; align-items: start; }
.definition-list .index { display: grid; place-items: center; width: 21px; height: 21px; border-radius: 7px; background: var(--primary-soft); color: var(--primary-strong); font-size: 11px; font-weight: 800; }
.definition-list p { margin: 0; color: var(--text); font-size: 15px; }
.detail-list { margin: 0; color: var(--muted); font-size: 14px; padding-left: 1.2em; }
.detail-list li + li { margin-top: 4px; }

.examples { display: grid; gap: 8px; margin: 0; padding: 0; list-style: none; }
.example {
  padding: 12px;
  border-left: 3px solid var(--primary);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  background: var(--surface-raised);
}
.example p { margin: 0; color: var(--text-strong); font-family: var(--font-serif); font-size: 15px; }
.example span { display: block; margin-top: 3px; color: var(--muted); font-size: 13px; }
.example-more { margin-top: 10px; }

.sources { max-width: 820px; margin: 0 auto; border-top: 1px solid var(--border); }
.sources summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 44px;
  color: var(--muted);
  font-size: 13px;
  cursor: pointer;
  list-style: none;
}
.sources summary::-webkit-details-marker { display: none; }
.sources summary .chevron { transition: transform .16s ease; }
.sources[open] summary .chevron { transform: rotate(180deg); }
.sources-list { display: grid; gap: 8px; padding-bottom: 10px; }
.source-row {
  display: grid;
  grid-template-columns: auto 1fr auto auto;
  align-items: center;
  gap: 10px;
  min-height: 48px;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
}
.source-name { min-width: 0; font-weight: 650; }
.source-status { color: var(--muted); font-size: 13px; }
.source-dot.ok { background: var(--success); }
.source-dot.fail { background: var(--danger); }
.source-dot.loading { background: var(--accent); animation: pulse 1s ease-in-out infinite; }

.section-header { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); margin-bottom: var(--space-4); }
.section-header h2 { margin: 0; color: var(--text-strong); font-family: var(--font-serif); font-size: clamp(1.4rem, 3vw, 1.75rem); letter-spacing: -.02em; }
.history-tools { display: flex; align-items: center; gap: 10px; margin-bottom: var(--space-4); }
.history-tools .search-input {
  flex: 1 1 220px;
  min-width: 0;
  min-height: 44px;
  padding: 0 13px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface-raised);
  font-size: 15px;
}
.history-tools .search-input:focus { border-color: var(--primary); }
.history-tools .setting-note { flex: none; margin: 0; white-space: nowrap; }

.history-list { display: grid; gap: 8px; }
.history-row {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  box-shadow: 0 3px 12px rgba(0, 0, 0, .03);
}
.history-main { display: grid; gap: 2px; min-width: 0; border: 0; background: transparent; text-align: left; }
.history-word { display: flex; align-items: baseline; gap: 7px; min-width: 0; }
.history-word strong { overflow: hidden; color: var(--text-strong); font-size: 16px; text-overflow: ellipsis; white-space: nowrap; }
.history-word span { flex: none; color: var(--subtle); font-size: 11px; font-weight: 700; }
.history-gloss { display: -webkit-box; overflow: hidden; color: var(--muted); font-size: 13px; -webkit-line-clamp: 1; -webkit-box-orient: vertical; }
.history-meta { color: var(--subtle); font-size: 11px; }
.history-actions { display: flex; gap: 0; }
.history-actions .icon-button { width: 40px; height: 40px; }
.empty-state {
  display: grid;
  justify-items: center;
  gap: 8px;
  padding: clamp(36px, 9vw, 64px) 20px;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface);
  text-align: center;
}
.empty-state .icon { width: 34px; height: 34px; color: var(--primary); }
.empty-state h2, .empty-state h3 { margin: 0; color: var(--text-strong); font-size: 16px; }

.bottom-nav {
  position: fixed;
  z-index: 30;
  right: max(12px, env(safe-area-inset-right));
  bottom: max(12px, env(safe-area-inset-bottom));
  left: max(12px, env(safe-area-inset-left));
  height: var(--nav-h);
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: 22px;
  background: var(--bg-elevated);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}
.nav-item {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 52px;
  border-radius: 16px;
  background: transparent;
  color: var(--muted);
  font-weight: 700;
  text-decoration: none;
}
.nav-item[aria-current="page"] { background: var(--primary-soft); color: var(--primary-strong); }

.dialog {
  width: min(100vw - 24px, 560px);
  max-height: min(760px, calc(100dvh - 24px));
  margin: auto;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
}
.dialog::backdrop { background: var(--scrim); backdrop-filter: blur(4px); }
.dialog-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.dialog-header h2 { margin: 0; color: var(--text-strong); font-size: 18px; }
.dialog-body { display: grid; gap: 20px; padding: 20px; overflow-y: auto; }
.setting-section h3 { margin: 0 0 10px; color: var(--text-strong); font-size: 15px; }
.segmented { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; padding: 4px; border: 1px solid var(--border); border-radius: 14px; background: var(--surface-soft); }
.segmented button { min-height: 40px; border-radius: 10px; background: transparent; color: var(--muted); font-weight: 700; }
.segmented button[aria-pressed="true"] { background: var(--surface-raised); color: var(--primary-strong); box-shadow: 0 2px 8px rgba(0,0,0,.08); }
.sync-row { display: grid; grid-template-columns: 1fr auto; gap: 8px; }
.sync-row input {
  min-width: 0;
  min-height: 48px;
  padding: 0 14px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--surface-raised);
}
.setting-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.setting-note { min-height: 22px; margin: 10px 0 0; color: var(--muted); font-size: 13px; }
.setting-note.error { color: var(--danger); }
.hidden-file { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.toast-region { position: fixed; z-index: 60; right: 16px; bottom: calc(var(--nav-h) + 28px + env(safe-area-inset-bottom)); left: 16px; display: grid; justify-items: center; gap: 8px; pointer-events: none; }
.toast { display: flex; align-items: center; gap: 12px; max-width: min(100%, 480px); padding: 12px 14px; border: 1px solid var(--border); border-radius: 16px; background: var(--surface-raised); color: var(--text); box-shadow: var(--shadow); pointer-events: auto; }
.toast.error { border-color: color-mix(in srgb, var(--danger) 35%, var(--border)); color: var(--danger); }

.skeleton { position: relative; overflow: hidden; border-radius: 12px; background: var(--surface-soft); }
.skeleton::after { content: ""; position: absolute; inset: 0; transform: translateX(-100%); background: linear-gradient(90deg, transparent, color-mix(in srgb, var(--surface-raised) 70%, transparent), transparent); animation: shimmer 1.2s infinite; }
@keyframes shimmer { to { transform: translateX(100%); } }

@media (min-width: 620px) {
  .pronunciations { grid-template-columns: 1fr 1fr; }
  .header-actions .icon-button[data-open-settings] { display: inline-grid; }
}

@media (min-width: 900px) {
  .app-shell {
    display: grid;
    grid-template-columns: 220px minmax(0, 1fr);
    align-items: start;
    padding-bottom: 0;
  }
  .app-header {
    position: sticky;
    top: 0;
    align-self: start;
    grid-row: 1;
    height: 100dvh;
    min-height: 0;
    overflow-y: auto;
    flex-direction: column;
    align-items: stretch;
    justify-content: flex-start;
    gap: 20px;
    padding: 16px 12px;
    border-right: 1px solid var(--border);
    border-bottom: 0;
  }
  .brand { padding: 0 6px; }
  .header-actions { flex-direction: column; align-items: stretch; gap: 2px; }
  .header-actions .icon-button {
    display: inline-grid;
    grid-template-columns: 22px minmax(0, 1fr) auto;
    gap: 10px;
    width: 100%;
    height: 44px;
    padding: 0 10px;
    justify-items: start;
  }
  .nav-label {
    display: block;
    overflow: hidden;
    color: inherit;
    font-size: 14px;
    font-weight: 700;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .header-actions .badge { position: static; grid-column: 3; margin-left: auto; }
  .app-main { grid-column: 2; grid-row: 1; width: min(100% - 56px, 920px); margin: 0 auto; }
  .view { padding: 32px 0 64px; }
  .search-panel, .word-card, .sources { max-width: 820px; }
  .word-card { padding: var(--space-5); }
  .bottom-nav { display: none; }
  .toast-region { left: auto; bottom: 24px; justify-items: end; }
}

@media (max-width: 619px) {
  .app-header { padding-left: max(14px, env(safe-area-inset-left)); padding-right: max(12px, env(safe-area-inset-right)); }
  .view { padding-top: 10px; padding-bottom: var(--space-6); }
  .search-box { grid-template-columns: 20px 1fr auto; gap: 8px; min-height: 50px; padding: 4px 4px 4px 13px; border-radius: 13px; }
  .search-box .button-primary { min-width: 64px; padding: 0 12px; border-radius: 10px; }
  .status { min-height: 20px; margin-top: 8px; padding: 0; }
  .result-view { margin-top: 14px; }
  .word-heading h2 { font-size: 1.7rem; }
  .word-card { margin-left: -2px; margin-right: -2px; padding: 14px; }
  .pronunciations { margin-top: 14px; }
  .details-section { margin-top: 14px; padding-top: 14px; }
  .section-header { align-items: center; margin-bottom: 12px; }
  .history-tools { gap: 8px; }
  .history-tools .search-input { flex: 1 1 0; }
  .history-tools .setting-note { margin: 0; }
  .history-row { grid-template-columns: minmax(0, 1fr) 88px; padding: 10px 12px; }
  .history-actions .icon-button { width: 44px; height: 44px; }
  .dialog { width: 100vw; max-height: 88dvh; margin: auto auto 0; border-right: 0; border-bottom: 0; border-left: 0; border-radius: 24px 24px 0 0; padding-bottom: env(safe-area-inset-bottom); }
  .dialog::backdrop { align-items: end; }
}

@media (max-height: 520px) and (orientation: landscape) and (max-width: 899px) {
  .app-shell { padding-bottom: 0; }
  .bottom-nav { display: none; }
  .view { padding-top: 10px; }
  .status { min-height: 18px; margin-top: 6px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
    transition-duration: .01ms !important;
  }
}
