:root {
  --paper: #f5f7f4;
  --paper-deep: #edf2ef;
  --card: #fff;
  --ink: #18322f;
  --muted: #6d7d79;
  --teal: #19736d;
  --teal-dark: #125a56;
  --teal-soft: #e4f1ed;
  --gold: #c58b3e;
  --gold-soft: #f8eddd;
  --line: #dce6e1;
  --shadow: 0 18px 50px rgba(33, 75, 68, .09);
  --serif: "Noto Serif SC", "Songti SC", SimSun, serif;
  --sans: Inter, "PingFang SC", "Microsoft YaHei", sans-serif;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  min-width: 320px;
  color: var(--ink);
  background: var(--paper);
  font-family: var(--sans);
  line-height: 1.6;
}
button, input { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
button { color: inherit; }
svg { fill: none; stroke: currentColor; stroke-linecap: round; stroke-linejoin: round; stroke-width: 1.8; }
.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; }

.site-header {
  height: 76px;
  padding: 0 clamp(20px, 5vw, 72px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(245, 247, 244, .88);
  border-bottom: 1px solid rgba(220, 230, 225, .75);
  backdrop-filter: blur(14px);
  position: sticky;
  top: 0;
  z-index: 20;
}
.brand { color: var(--ink); text-decoration: none; display: flex; align-items: center; gap: 12px; }
.brand-mark { width: 42px; height: 42px; display: grid; place-items: center; color: var(--teal); background: var(--teal-soft); border-radius: 12px; }
.brand-mark svg { width: 28px; }
.brand strong, .brand small { display: block; line-height: 1.25; }
.brand strong { font-family: var(--serif); font-size: 17px; letter-spacing: .08em; }
.brand small { color: var(--muted); font-size: 11px; letter-spacing: .18em; }
.header-actions { display: flex; align-items: center; gap: 6px; }
.icon-button, .text-button { border: 0; background: transparent; cursor: pointer; border-radius: 10px; transition: .2s ease; }
.icon-button { width: 40px; height: 40px; display: grid; place-items: center; }
.icon-button svg { width: 20px; }
.icon-button:hover, .text-button:hover { color: var(--teal); background: var(--teal-soft); }
.text-button { padding: 9px 13px; font-size: 14px; }
#browseButton { display: inline-flex; align-items: center; gap: 6px; }
#browseButton.is-ready::after { content: ""; width: 7px; height: 7px; background: var(--teal); border-radius: 50%; box-shadow: 0 0 0 3px var(--teal-soft); }
#browseButton[aria-busy="true"]::after { animation: audio-pulse 1s ease-in-out infinite; }

.hero {
  position: relative;
  overflow: visible;
  text-align: center;
  padding: 74px 20px 92px;
  background:
    radial-gradient(circle at 83% 20%, rgba(197, 139, 62, .12) 0 1px, transparent 2px) 0 0 / 22px 22px,
    linear-gradient(145deg, #eef5f1 0%, #f8f7f1 100%);
  border-bottom: 1px solid var(--line);
}
.hero-decoration { position: absolute; left: 6%; top: 34px; width: 150px; height: 76px; opacity: .25; border: 1px solid var(--teal); border-radius: 50%; transform: rotate(-12deg); }
.hero-decoration::after { content: ""; position: absolute; inset: 16px -32px; border: 1px solid var(--teal); border-radius: 50%; }
.eyebrow, .section-kicker { margin: 0 0 8px; color: var(--teal); font-size: 11px; font-weight: 700; letter-spacing: .2em; text-transform: uppercase; }
.hero h1 { margin: 0; font-family: var(--serif); font-size: clamp(38px, 5.5vw, 64px); font-weight: 600; letter-spacing: .06em; line-height: 1.25; }
.hero-copy { margin: 16px auto 26px; max-width: 660px; color: var(--muted); font-size: 16px; }
.search-mode { width: fit-content; margin: 0 auto 12px; padding: 4px; display: flex; gap: 3px; background: rgba(255,255,255,.72); border: 1px solid var(--line); border-radius: 12px; }
.search-mode button { padding: 7px 14px; color: var(--muted); background: transparent; border: 0; border-radius: 8px; cursor: pointer; font-size: 13px; font-weight: 600; transition: .2s ease; }
.search-mode button:hover { color: var(--teal); }
.search-mode button:disabled { opacity: .64; cursor: wait; }
.search-mode button.is-active { color: #fff; background: var(--teal); box-shadow: 0 5px 14px rgba(25,115,109,.18); }
.search-shell {
  width: min(780px, 100%);
  height: 64px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 7px 7px 7px 22px;
  position: relative;
  background: var(--card);
  border: 1px solid rgba(25, 115, 109, .18);
  border-radius: 18px;
  box-shadow: 0 16px 45px rgba(35, 85, 77, .13);
  text-align: left;
}
.search-shell:focus-within { border-color: rgba(25, 115, 109, .55); box-shadow: 0 16px 45px rgba(35, 85, 77, .16), 0 0 0 4px rgba(25, 115, 109, .07); }
.search-icon { width: 22px; flex: 0 0 auto; color: var(--teal); }
.search-shell input { min-width: 0; flex: 1; height: 100%; border: 0; outline: 0; color: var(--ink); background: transparent; font-size: 16px; }
.search-shell input::placeholder { color: #98a7a3; }
.search-shell > button { height: 48px; padding: 0 26px; border: 0; border-radius: 13px; color: #fff; background: var(--teal); font-weight: 700; cursor: pointer; transition: .2s ease; }
.search-shell > button:hover { background: var(--teal-dark); transform: translateY(-1px); }
.search-shell > button:disabled { opacity: .68; cursor: wait; transform: none; }
.search-validation { width: min(780px, 100%); min-height: 20px; margin: 7px auto -3px; color: var(--muted); font-size: 12px; text-align: left; }
.search-validation.is-error { color: #a24639; }
.quick-words { display: inline-flex; flex-wrap: wrap; gap: 2px; }
.suggestions { position: absolute; z-index: 10; top: calc(100% + 10px); left: 0; right: 0; padding: 8px; background: var(--card); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow); }
.suggestion-item { width: 100%; padding: 11px 14px; display: flex; align-items: center; justify-content: space-between; border: 0; background: transparent; border-radius: 9px; cursor: pointer; text-align: left; }
.suggestion-item:hover { background: var(--teal-soft); }
.suggestion-item small { color: var(--muted); }
.region-filter { width: min(780px, 100%); margin: 13px auto 0; display: flex; align-items: center; gap: 9px; color: var(--muted); font-size: 12px; text-align: left; }
.region-filter select { min-width: 230px; padding: 7px 30px 7px 10px; color: var(--ink); background: rgba(255,255,255,.8); border: 1px solid var(--line); border-radius: 9px; outline: 0; }
.region-filter select:focus { border-color: var(--teal); box-shadow: 0 0 0 3px rgba(25,115,109,.08); }
.search-meta { width: min(780px, 100%); margin: 10px auto 0; display: flex; flex-wrap: wrap; align-items: center; gap: 7px; color: var(--muted); font-size: 13px; text-align: left; }
.quick-word { padding: 2px 8px; border: 0; color: var(--teal); background: transparent; cursor: pointer; border-radius: 6px; }
.quick-word:hover { background: var(--teal-soft); }
.privacy-note { margin-left: auto; display: inline-flex; align-items: center; gap: 5px; }
.privacy-note svg { width: 15px; }

.workspace { width: min(1120px, calc(100% - 40px)); margin: -44px auto 0; position: relative; z-index: 2; }
.result-toolbar { padding: 22px 26px 16px; display: flex; align-items: end; justify-content: space-between; background: rgba(255,255,255,.86); border: 1px solid var(--line); border-bottom: 0; border-radius: 18px 18px 0 0; backdrop-filter: blur(10px); }
.result-toolbar h2, .source-heading h2, .dialog-header h2 { margin: 0; font-family: var(--serif); font-size: 23px; font-weight: 600; }
.sample-badge { padding: 5px 10px; border: 1px solid #ecd4b5; border-radius: 999px; color: #8a6028; background: var(--gold-soft); font-size: 12px; }
.entry-card { min-height: 440px; padding: 30px; background: var(--card); border: 1px solid var(--line); border-radius: 0 0 18px 18px; box-shadow: var(--shadow); }
.entry-top { display: grid; grid-template-columns: 1.1fr 1.9fr auto; gap: 26px; align-items: start; padding-bottom: 26px; border-bottom: 1px solid var(--line); }
.headword-block { min-width: 0; display: flex; gap: 16px; align-items: center; }
.headword-audio { min-width: 0; display: flex; align-items: center; gap: 9px; }
.headword { min-width: 0; margin: 0; font-family: var(--serif); font-size: 54px; font-weight: 600; line-height: 1.1; overflow-wrap: anywhere; }
.speak-button { width: 36px; height: 36px; flex: 0 0 auto; display: inline-grid; place-items: center; color: var(--teal); background: var(--teal-soft); border: 1px solid rgba(25,115,109,.2); border-radius: 50%; cursor: pointer; transition: .2s ease; }
.speak-button:hover { color: #fff; background: var(--teal); transform: translateY(-1px); }
.speak-button.is-speaking { color: #fff; background: var(--gold); border-color: var(--gold); animation: audio-pulse 1s ease-in-out infinite; }
.speak-button.is-compact { width: 28px; height: 28px; }
.speak-button svg { width: 18px; }
.speak-button.is-compact svg { width: 15px; }
.word-meta { display: flex; flex-direction: column; gap: 7px; align-items: start; }
.pos, .region-tag { padding: 4px 9px; border-radius: 7px; color: var(--teal); background: var(--teal-soft); font-size: 12px; }
.variants { color: var(--muted); font-size: 13px; }
.pronunciations { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.pronunciation { padding: 10px 13px; background: var(--paper); border-radius: 10px; }
.pronunciation span { display: block; color: var(--muted); font-size: 11px; }
.pronunciation strong { min-width: 0; font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 15px; font-weight: 600; overflow-wrap: anywhere; }
.pronunciation-value { margin-top: 2px; display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.favorite-entry { width: 42px; height: 42px; color: var(--muted); border: 1px solid var(--line); }
.favorite-entry.is-active { color: var(--gold); background: var(--gold-soft); border-color: #ecd4b5; }
.entry-grid { margin-top: 28px; display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.info-block { min-height: 128px; padding: 20px; background: #fbfcfb; border: 1px solid var(--line); border-radius: 13px; }
.info-block.wide { grid-column: 1 / -1; }
.info-label { margin-bottom: 12px; display: flex; align-items: center; gap: 9px; color: var(--teal); font-size: 13px; font-weight: 700; }
.info-label::before { content: ""; width: 5px; height: 18px; border-radius: 4px; background: var(--teal); }
.info-block.gold .info-label { color: #91642c; }
.info-block.gold .info-label::before { background: var(--gold); }
.info-block p { margin: 0; }
.meaning-list { margin: 0; padding-left: 22px; }
.meaning-list li::marker { color: var(--teal); font-weight: 700; }
.example-text { font-family: var(--serif); font-size: 19px; }
.example-audio { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.translation { margin-top: 7px !important; color: var(--muted); font-size: 14px; }
.romanization-line { margin-top: 6px !important; color: var(--teal-dark); font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 13px; }
.audio-disclaimer { margin: 18px 0 0; padding: 9px 12px; color: var(--muted); background: var(--gold-soft); border-radius: 9px; font-size: 11px; }
.source-note { margin-top: 14px; display: flex; align-items: center; justify-content: space-between; gap: 16px; color: var(--muted); font-size: 12px; }
@keyframes audio-pulse { 0%, 100% { box-shadow: 0 0 0 0 rgba(197,139,62,.28); } 50% { box-shadow: 0 0 0 7px rgba(197,139,62,0); } }
.source-pills { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.source-pills span { padding: 3px 8px; background: var(--paper-deep); border-radius: 6px; }
.source-ref { padding: 3px 8px; display: inline-flex; align-items: center; gap: 4px; color: var(--teal-dark); background: var(--teal-soft); border-radius: 6px; text-decoration: none; }
.source-ref:hover { text-decoration: underline; }
.source-ref svg { width: 12px; }
.example-pair + .example-pair { margin-top: 14px; padding-top: 14px; border-top: 1px dashed var(--line); }
.empty-state { padding: 80px 20px; text-align: center; }
.empty-state svg { width: 48px; color: var(--teal); }
.empty-state h3 { margin: 16px 0 6px; font-family: var(--serif); font-size: 24px; }
.empty-state p { color: var(--muted); }
.empty-state.is-error svg { color: #a24639; }
.empty-action { margin-top: 10px; padding: 9px 15px; color: #fff; background: var(--teal); border: 0; border-radius: 9px; cursor: pointer; font-weight: 700; }
.empty-action:hover { background: var(--teal-dark); }
.search-state { min-height: 330px; display: grid; place-content: center; justify-items: center; text-align: center; }
.search-state h3 { margin: 16px 0 4px; font-family: var(--serif); font-size: 22px; }
.search-state p { margin: 0; color: var(--muted); }
.loading-spinner { width: 34px; height: 34px; border: 3px solid var(--teal-soft); border-top-color: var(--teal); border-radius: 50%; animation: search-spin .8s linear infinite; }
@keyframes search-spin { to { transform: rotate(360deg); } }
.reverse-results { display: grid; gap: 22px; }
.reverse-summary { padding-bottom: 18px; display: flex; align-items: end; justify-content: space-between; gap: 24px; border-bottom: 1px solid var(--line); }
.reverse-summary h3 { margin: 6px 0 0; font-family: var(--serif); font-size: 23px; }
.reverse-summary p { max-width: 560px; margin: 0; color: var(--muted); font-size: 13px; text-align: right; }
.reverse-count { display: inline-flex; padding: 4px 9px; color: var(--teal-dark); background: var(--teal-soft); border-radius: 999px; font-size: 12px; font-weight: 700; }
.reverse-result-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.reverse-result-card { min-width: 0; padding: 18px; display: flex; flex-direction: column; gap: 13px; background: #fbfcfb; border: 1px solid var(--line); border-radius: 13px; transition: .2s ease; }
.reverse-result-card:hover { border-color: rgba(25,115,109,.4); box-shadow: 0 10px 24px rgba(33,75,68,.07); }
.reverse-card-top { display: flex; align-items: start; justify-content: space-between; gap: 12px; }
.reverse-card-top h4 { margin: 8px 0 0; font-family: var(--serif); font-size: 29px; line-height: 1.15; overflow-wrap: anywhere; }
.reverse-reading { margin: 0; padding: 9px 11px; display: grid; gap: 2px; background: var(--paper); border-radius: 9px; }
.reverse-reading span { color: var(--muted); font-size: 10px; }
.reverse-reading strong { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 14px; overflow-wrap: anywhere; }
.reverse-definition { flex: 1; margin: 0; color: var(--muted); font-size: 13px; }
.reverse-card-footer { padding-top: 11px; display: flex; align-items: center; justify-content: space-between; gap: 10px; border-top: 1px dashed var(--line); }
.reverse-card-footer > span { color: #91642c; font-size: 11px; }
.reverse-card-footer button { padding: 7px 10px; color: var(--teal-dark); background: var(--teal-soft); border: 0; border-radius: 8px; cursor: pointer; font-size: 12px; font-weight: 700; }
.reverse-card-footer button:hover { color: #fff; background: var(--teal); }

.source-panel { margin: 28px 0 60px; padding: 28px; background: var(--card); border: 1px solid var(--line); border-radius: 18px; box-shadow: var(--shadow); }
.source-heading { display: flex; align-items: end; justify-content: space-between; gap: 20px; padding-bottom: 22px; border-bottom: 1px solid var(--line); }
.source-heading > p { max-width: 340px; margin: 0; color: var(--muted); font-size: 13px; text-align: right; }
.source-groups { margin-top: 23px; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
.source-group { padding: 18px; background: var(--paper); border: 1px solid var(--line); border-radius: 13px; }
.source-group + .source-group { padding-left: 18px; border-left: 1px solid var(--line); }
.source-group h3 { margin: 0 0 11px; font-size: 13px; }
.source-links { display: grid; gap: 8px; }
.source-link { padding: 10px 12px; display: flex; align-items: center; justify-content: space-between; gap: 8px; color: var(--ink); background: var(--paper); border: 1px solid transparent; border-radius: 10px; text-decoration: none; font-size: 13px; transition: .2s ease; }
.source-link:hover { color: var(--teal); background: var(--teal-soft); border-color: rgba(25,115,109,.16); }
.source-link svg { width: 15px; flex: 0 0 auto; }
.source-group-copy { min-height: 40px; margin: -5px 0 11px; color: var(--muted); font-size: 12px; }
.source-link small { display: block; color: var(--muted); font-size: 10px; }
.source-link-label { min-width: 0; }

.external-fallback { margin-top: 20px; padding: 18px; border: 1px dashed rgba(25,115,109,.35); border-radius: 13px; background: var(--teal-soft); text-align: left; }
.external-fallback h4 { margin: 0 0 5px; font-size: 14px; }
.external-fallback p { margin: 0 0 12px; color: var(--muted); font-size: 13px; }
.external-fallback .fallback-links { display: flex; flex-wrap: wrap; gap: 8px; }
.external-fallback a { padding: 7px 10px; color: var(--teal-dark); background: #fff; border: 1px solid rgba(25,115,109,.18); border-radius: 8px; text-decoration: none; font-size: 12px; }

footer { padding: 28px 20px 34px; display: flex; justify-content: center; align-items: center; gap: 16px; color: var(--muted); border-top: 1px solid var(--line); font-size: 12px; }
footer p { margin: 0; color: var(--ink); font-family: var(--serif); }

#sideDialog { width: min(480px, calc(100% - 28px)); max-height: 78vh; padding: 0; color: var(--ink); background: var(--card); border: 1px solid var(--line); border-radius: 18px; box-shadow: 0 30px 100px rgba(20, 50, 46, .25); }
#sideDialog::backdrop { background: rgba(19, 40, 37, .32); backdrop-filter: blur(4px); }
.dialog-header { padding: 22px 24px 17px; display: flex; justify-content: space-between; align-items: start; border-bottom: 1px solid var(--line); }
.close-button { border: 1px solid var(--line); }
#dialogContent { padding: 18px 24px 26px; }
.dialog-list { display: grid; gap: 8px; }
.dialog-item { width: 100%; padding: 12px 14px; display: flex; align-items: center; justify-content: space-between; border: 1px solid var(--line); border-radius: 10px; background: #fff; cursor: pointer; text-align: left; }
.dialog-item:hover { border-color: var(--teal); background: var(--teal-soft); }
.dialog-item span { color: var(--muted); font-size: 12px; }
.dialog-empty { padding: 36px 10px; color: var(--muted); text-align: center; }
.dialog-toolbar { margin-bottom: 14px; display: flex; gap: 8px; }
.dialog-toolbar input { width: 100%; padding: 10px 12px; color: var(--ink); background: var(--paper); border: 1px solid var(--line); border-radius: 9px; outline: 0; }
.dialog-toolbar input:focus { border-color: var(--teal); box-shadow: 0 0 0 3px rgba(25,115,109,.08); }
.browse-summary { margin: -3px 0 13px; color: var(--muted); font-size: 12px; }
.dialog-word-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.dialog-word-card { padding: 14px; display: grid; gap: 7px; color: var(--ink); background: #fff; border: 1px solid var(--line); border-radius: 11px; cursor: pointer; text-align: left; }
.dialog-word-card:hover { border-color: var(--teal); background: var(--teal-soft); }
.dialog-word-card strong { font-family: var(--serif); font-size: 21px; }
.dialog-word-card span { color: var(--muted); font-size: 11px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.about-copy p { color: var(--muted); }
.about-copy strong { color: var(--ink); }
.about-copy a { color: var(--teal-dark); text-underline-offset: 2px; }
.about-copy h3 { margin: 22px 0 8px; font-family: var(--serif); font-size: 17px; }

.toast { position: fixed; left: 50%; bottom: 28px; z-index: 50; transform: translateX(-50%); padding: 10px 16px; color: #fff; background: #173f3b; border-radius: 9px; box-shadow: var(--shadow); font-size: 13px; }

@media (max-width: 1050px) {
  .source-groups { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 820px) {
  .site-header { height: 68px; padding: 0 18px; }
  #aboutButton { display: none; }
  .hero { padding: 54px 18px 78px; }
  .hero-decoration { display: none; }
  .search-shell { height: 58px; padding-left: 16px; }
  .search-shell > button { height: 44px; padding: 0 18px; }
  .privacy-note { width: 100%; margin: 5px 0 0; }
  .workspace { width: min(100% - 24px, 700px); }
  .entry-top { grid-template-columns: 1fr auto; }
  .pronunciations { grid-column: 1 / -1; }
  .entry-grid { grid-template-columns: 1fr; }
  .info-block.wide { grid-column: auto; }
  .reverse-result-grid { grid-template-columns: 1fr; }
  .reverse-summary { align-items: start; flex-direction: column; gap: 10px; }
  .reverse-summary p { text-align: left; }
  .source-groups { grid-template-columns: 1fr; }
  .source-group + .source-group { padding: 18px; border-left: 1px solid var(--line); border-top: 1px solid var(--line); }
}

@media (max-width: 520px) {
  .site-header { padding: 0 10px; }
  .brand { min-width: 0; gap: 8px; }
  .brand strong { font-size: 14px; white-space: nowrap; }
  .brand small { display: none; }
  .brand-mark { width: 34px; height: 34px; flex: 0 0 auto; }
  #browseButton { padding: 7px 8px; font-size: 12px; }
  .header-actions { gap: 2px; }
  .header-actions .icon-button { width: 36px; height: 36px; }
  .hero h1 { font-size: 35px; }
  .hero-copy { font-size: 14px; }
  .search-mode { width: 100%; }
  .search-mode button { flex: 1; padding-left: 8px; padding-right: 8px; font-size: 12px; }
  .search-shell input { font-size: 14px; }
  .search-shell > button { padding: 0 14px; }
  .result-toolbar, .entry-card, .source-panel { padding-left: 18px; padding-right: 18px; }
  .result-toolbar { align-items: start; flex-wrap: wrap; gap: 10px; }
  .sample-badge { max-width: 100%; display: inline-flex; white-space: normal; line-height: 1.45; }
  .headword { font-size: 46px; }
  .entry-top { gap: 16px; }
  .pronunciations { grid-template-columns: 1fr; }
  .source-heading { align-items: start; flex-direction: column; }
  .source-heading > p { text-align: left; }
  .source-note { align-items: start; flex-direction: column; }
  .dialog-word-grid { grid-template-columns: 1fr; }
  footer { flex-direction: column; gap: 2px; text-align: center; }
}

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