#archiveSearch {
  --search-edge: clamp(1rem, 3vw, 1.65rem);
  color: var(--text);
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 0;
  width: min(39rem, calc(100% - 2rem));
  max-height: min(78dvh, 43rem);
  box-shadow: var(--shadow), 0 28px 84px #09101555;
  overflow: hidden;
}
#archiveSearch[open] { display: flex; flex-direction: column; }
#archiveSearch::backdrop { background: #10182389; }
body:has(#archiveSearch[open]), body:has(#charModal:not([hidden])) { overflow: hidden; }
.archive-search-head {
  display: flex; justify-content: space-between; align-items: center;
  padding: .85rem var(--search-edge) .55rem; gap: 1rem;
}
.archive-search-head h2 { font-size: 1.4rem; line-height: 1.35; color: var(--text); margin: 0; }
.archive-search-close {
  display: grid; place-content: center; background: transparent; color: var(--text-muted);
  border: 0; border-radius: 50%; font: inherit; font-size: 1.65rem; width: 2.65rem; height: 2.65rem;
  line-height: 1; cursor: pointer;
}
.archive-search-close:hover { background: var(--bg-hover); color: var(--text); }
.archive-search-box {
  margin: 0 var(--search-edge); padding: 0 .85rem; display: flex; align-items: center; gap: .7rem;
  flex: none; color: var(--text-muted); border: 1px solid var(--border); border-radius: 6px;
  background: var(--bg);
}
.archive-search-box:focus-within { outline: 2px solid var(--gold); outline-offset: 1px; }
#archiveSearchInput {
  flex: 1 1 auto; min-width: 0; height: 2.9rem; font: inherit; font-size: 1rem;
  color: var(--text); background: transparent; border: 0; padding: 0; outline: none; box-shadow: none;
}
#archiveSearchCount { font-size: .875rem; color: var(--text-muted); margin: .8rem var(--search-edge) 0; }
#archiveSearchCount:empty { margin-top: .35rem; }
#archiveSearchResults {
  padding: .5rem var(--search-edge) 1.1rem; overflow-y: auto; overscroll-behavior: contain;
  scrollbar-color: var(--border) transparent;
}
.search-group-head { display: flex; align-items: baseline; justify-content: space-between; gap: .75rem; }
#archiveSearch .search-group-title {
  font: inherit; font-size: .875rem; font-weight: 650; color: var(--text-muted);
  margin: .9rem 0 .28rem; letter-spacing: .025em;
}
.search-group-title span { font-size: .8rem; font-variant-numeric: tabular-nums; font-weight: 400; margin-left: .2rem; }
.search-hit {
  display: flex; align-items: center; gap: .8rem; padding: .48rem .38rem; border-radius: 5px;
  color: var(--text); text-decoration: none; margin: 0;
}
.search-hit:is(:hover,:focus-visible,.chosen) { background: var(--bg-hover); }
.search-hit:focus-visible, .search-expand:focus-visible, .archive-search-close:focus-visible {
  outline: 2px solid var(--gold); outline-offset: -2px;
}
.search-hit-visual {
  width: 2.45rem; height: 2.45rem; flex: none; display: grid; place-content: center; overflow: hidden;
  color: var(--text-muted); border: 1px solid var(--border); border-radius: 5px; background: var(--bg);
  font-family: "Songti SC","SimSun",serif; font-size: 1.08rem;
}
.search-hit-visual img { width: 100%; height: 100%; object-fit: cover; display: block; }
.search-hit-copy { display: flex; flex-direction: column; gap: .15rem; min-width: 0; }
.search-hit-copy strong { font-size: 1rem; line-height: 1.4; font-weight: 600; overflow-wrap: anywhere; }
.search-hit-copy small { font-size: .82rem; color: var(--text-muted); line-height: 1.35; overflow-wrap: anywhere; }
.search-expand, .archive-route-notice button {
  font: inherit; font-size: .875rem; font-weight: 600; border: 0; background: transparent; color: var(--text);
  text-decoration: underline; text-underline-offset: .2em; cursor: pointer; padding: .55rem .3rem;
}
.search-empty { color: var(--text-muted); font-size: 1rem; padding: .8rem 0 1.35rem; }
.archive-target { outline: 2px solid var(--gold); outline-offset: -2px; scroll-margin: 6rem 0 2rem; }
.archive-route-notice { color: var(--text); padding: .6rem .85rem; border: 1px solid var(--border); background: var(--bg-card); }
.cite-copy {
  display: inline-flex; align-items: center; min-height: 2.5rem; margin-block: .2rem; padding: .3rem .65rem;
  border: 1px solid var(--border); border-radius: 5px; background: var(--bg-card); color: var(--teal);
  font: inherit; font-size: .875rem; font-weight: 600; line-height: 1.35; cursor: pointer;
}
.cite-copy:hover, .archive-copy-fallback button:hover { background: var(--bg-hover); }
.archive-copy-status {
  position: fixed; z-index: 140; bottom: max(1.25rem, env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%);
  width: max-content; max-width: calc(100% - 2rem); margin: 0; padding: .6rem .95rem; font: 500 .95rem/1.5 var(--body);
  color: var(--text); background: var(--bg-card); border: 1px solid var(--border); border-radius: 6px; box-shadow: var(--shadow);
}
.archive-copy-buffer { position: fixed; left: 0; top: 0; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.archive-copy-fallback {
  width: min(32rem, calc(100% - 2rem)); max-height: 90dvh; padding: 1.15rem;
  color: var(--text); background: var(--bg-card); border: 1px solid var(--border); border-radius: 10px;
}
.archive-copy-fallback::backdrop { background: #10182389; }
.archive-copy-fallback h2 { font-size: 1.3rem; margin: 0; }
.archive-copy-fallback p { font-size: 1rem; margin: .45rem 0 .8rem; }
.archive-copy-fallback textarea {
  width: 100%; height: 8rem; padding: .65rem; border: 1px solid var(--border); border-radius: 5px;
  color: var(--text); background: var(--bg); font: inherit; font-size: 1rem; resize: vertical;
}
.archive-copy-fallback form { display: flex; justify-content: flex-end; margin-top: .5rem; }
.archive-copy-fallback button { min-height: 2.75rem; border: 1px solid var(--border); padding: .35rem .85rem; border-radius: 4px; }
@media (max-width: 500px) {
  #archiveSearch {
    width: calc(100% - 1rem); max-height: 85dvh; max-width: none; margin: max(.55rem, env(safe-area-inset-top)) auto auto;
    border-radius: 10px; --search-edge: .9rem;
  }
  .search-hit { min-height: 3.25rem; }
  .cite-copy { min-height: 2.75rem; }
}
