/* ==========================================================================
 * tb-search — 全站搜索弹窗（独立命名空间）
 * ========================================================================== */

.tb-search {
  --tb-s-accent: #ff5745;
  --tb-s-teal: #0f766e;
  --tb-s-ink: #15202b;
  --tb-s-muted: #667085;
  --tb-s-line: rgba(21, 32, 43, 0.1);
  --tb-s-surface: #ffffff;
  --tb-s-surface-2: #f3f6f8;
  --tb-s-radius: 22px;
  --tb-s-ease: cubic-bezier(0.22, 0.8, 0.28, 1);
  position: fixed;
  inset: 0;
  z-index: 19950;
  display: none;
  padding: max(12px, env(safe-area-inset-top)) 16px max(16px, env(safe-area-inset-bottom));
}

.tb-search.is-open {
  display: flex;
  align-items: flex-start;
  justify-content: center;
}

.nice-dark-mode .tb-search {
  --tb-s-ink: #f2f4f7;
  --tb-s-muted: #a8b0bd;
  --tb-s-line: rgba(255, 255, 255, 0.1);
  --tb-s-surface: #23272e;
  --tb-s-surface-2: #2c313a;
}

.tb-search-overlay {
  position: absolute;
  inset: 0;
  background: rgba(11, 42, 48, 0.52);
  backdrop-filter: blur(14px) saturate(125%);
  -webkit-backdrop-filter: blur(14px) saturate(125%);
  opacity: 0;
  transition: opacity 0.28s var(--tb-s-ease);
}

.tb-search.is-open .tb-search-overlay { opacity: 1; }

.tb-search-dialog {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 42rem;
  margin-top: min(10vh, 5.5rem);
  background: var(--tb-s-surface);
  color: var(--tb-s-ink);
  border-radius: var(--tb-s-radius);
  box-shadow:
    0 4px 6px rgba(21, 32, 43, 0.04),
    0 28px 64px rgba(11, 42, 48, 0.24);
  overflow: hidden;
  opacity: 0;
  transform: translate3d(0, 16px, 0) scale(0.98);
  transition: opacity 0.32s var(--tb-s-ease), transform 0.32s var(--tb-s-ease);
}

.tb-search-ambient {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 7.25rem;
  overflow: hidden;
  pointer-events: none;
  z-index: 0;
}

.tb-search-ambient img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  filter: blur(22px) saturate(1.15);
  transform: scale(1.25);
  opacity: 0.42;
}

.tb-search-ambient::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.18) 0%, var(--tb-s-surface) 92%);
}

.nice-dark-mode .tb-search-ambient img { opacity: 0.32; }

.nice-dark-mode .tb-search-ambient::after {
  background: linear-gradient(180deg, rgba(35, 39, 46, 0.2) 0%, var(--tb-s-surface) 92%);
}

.tb-search-form {
  position: relative;
  z-index: 1;
  margin: 0;
}

.tb-search.is-open .tb-search-dialog {
  opacity: 1;
  transform: none;
}

.tb-search-bar {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0.9rem 0.95rem 0.75rem 1.1rem;
  border-bottom: 1px solid var(--tb-s-line);
}

.tb-search-ico {
  flex: 0 0 auto;
  width: 2.1rem;
  height: 2.1rem;
  border-radius: 10px;
  color: #fff;
  background: linear-gradient(160deg, #0f766e 0%, #14b8a6 100%);
  display: grid;
  place-items: center;
  box-shadow: 0 6px 14px rgba(15, 118, 110, 0.28);
}

.tb-search-bar input {
  flex: 1 1 auto;
  min-width: 0;
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  font-size: 1.05rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  outline: none;
  padding: 0.35rem 0;
}

.tb-search-bar input::placeholder { color: var(--tb-s-muted); font-weight: 500; }

.tb-search-esc {
  flex: 0 0 auto;
  min-width: 2.1rem;
  padding: 0.12rem 0.4rem;
  border-radius: 6px;
  border: 1px solid var(--tb-s-line);
  background: var(--tb-s-surface-2);
  color: var(--tb-s-muted);
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  cursor: pointer;
}

.tb-search-x {
  display: none;
  width: 2rem;
  height: 2rem;
  border: 0;
  border-radius: 99px;
  background: var(--tb-s-surface-2);
  color: var(--tb-s-muted);
  font-size: 1.2rem;
  line-height: 1;
  cursor: pointer;
}

.tb-search-cats {
  display: flex;
  gap: 0.12rem;
  margin: 0.7rem 1.1rem 0.1rem;
  padding: 0.18rem;
  border-radius: 12px;
  background: var(--tb-s-surface-2);
}

.tb-search-cat {
  appearance: none;
  flex: 1 1 0;
  min-width: 0;
  min-height: 1.85rem;
  padding: 0.2rem 0.35rem;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--tb-s-muted);
  font: inherit;
  font-size: 0.76rem;
  font-weight: 600;
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: pointer;
  transition: background 0.18s, color 0.18s, box-shadow 0.18s;
}

.tb-search-cat:hover { color: var(--tb-s-ink); }

.tb-search-cat.is-on {
  color: var(--tb-s-ink);
  background: var(--tb-s-surface);
  box-shadow: 0 1px 2px rgba(21, 32, 43, 0.08);
}

.nice-dark-mode .tb-search-cat.is-on {
  background: #3a414c;
  color: #fff;
  box-shadow: none;
}

.tb-search-body {
  padding: 0.65rem 1.1rem 0.9rem;
  max-height: min(58vh, 26rem);
  overflow: auto;
}

.tb-search-block + .tb-search-block { margin-top: 0.85rem; }

.tb-search-block-h {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.45rem;
  color: var(--tb-s-muted);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.06em;
}

.tb-search-clear {
  border: 0;
  background: none;
  color: var(--tb-s-muted);
  font: inherit;
  font-size: 0.72rem;
  font-weight: 600;
  cursor: pointer;
  padding: 0;
}

.tb-search-clear:hover { color: var(--tb-s-accent); }

.tb-search-recent {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  list-style: none;
  margin: 0;
  padding: 0;
}

.tb-search-recent li {
  display: block;
  max-width: 100%;
}

.tb-search-recent a {
  display: inline-flex;
  align-items: center;
  max-width: 100%;
  min-height: 1.75rem;
  padding: 0.2rem 0.7rem;
  border: 0;
  border-radius: 99px;
  background: var(--tb-s-surface-2);
  color: inherit;
  text-decoration: none;
  font-size: 0.8rem;
  font-weight: 600;
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tb-search-recent a:hover {
  background: rgba(15, 118, 110, 0.12);
  color: var(--tb-s-teal);
}

.nice-dark-mode .tb-search-recent a {
  background: rgba(255, 255, 255, 0.06);
}

.nice-dark-mode .tb-search-recent a:hover {
  background: rgba(20, 184, 166, 0.16);
  color: #5eead4;
}

.tb-search-hot {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.45rem 0.55rem;
  margin: 0;
  padding: 0;
  list-style: none;
}

.tb-search-hot-item {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  min-height: 2.7rem;
  padding: 0.22rem 0.3rem 0.22rem 0.22rem;
  margin: 0;
  border-radius: 10px;
  color: inherit;
  text-decoration: none;
  background: var(--tb-s-surface-2);
  transition: background 0.18s, transform 0.18s;
}

.tb-search-hot-item:hover {
  background: rgba(15, 118, 110, 0.1);
  transform: translateY(-1px);
}

.tb-search-hot-thumb {
  flex: 0 0 auto;
  width: 3.35rem;
  height: 2.25rem;
  border-radius: 7px;
  overflow: hidden;
  background: linear-gradient(145deg, #d7e4e2, #c5d4d1);
  display: grid;
  place-items: center;
}

.tb-search-hot-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.tb-search-hot-thumb em {
  font-style: normal;
  font-size: 0.68rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.04em;
  color: var(--tb-s-teal);
}

.tb-search-hot-meta {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0.08rem;
}

.tb-search-hot-meta b {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.86rem;
  font-weight: 600;
}

.tb-search-hot-meta i {
  font-style: normal;
  font-size: 0.64rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.06em;
  color: var(--tb-s-muted);
  opacity: 0.8;
}

.tb-search-hot li:nth-child(-n+3) .tb-search-hot-meta i {
  color: var(--tb-s-teal);
  opacity: 1;
}

.nice-dark-mode .tb-search-hot-item {
  background: rgba(255, 255, 255, 0.04);
}

.nice-dark-mode .tb-search-hot-item:hover {
  background: rgba(20, 184, 166, 0.14);
}

.nice-dark-mode .tb-search-hot-thumb {
  background: linear-gradient(145deg, #3a414c, #2c313a);
}

@media (max-width: 479.98px) {
  .tb-search-hot {
    grid-template-columns: 1fr;
  }
}

.tb-search-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.55rem 1.1rem 0.7rem;
  border-top: 1px solid var(--tb-s-line);
  background: var(--tb-s-surface-2);
  color: var(--tb-s-muted);
  font-size: 0.72rem;
}

.tb-search-foot kbd {
  display: inline-block;
  min-width: 1.25rem;
  padding: 0.08rem 0.28rem;
  margin-left: 0.15rem;
  border-radius: 5px;
  border: 1px solid var(--tb-s-line);
  background: var(--tb-s-surface);
  font-size: 0.68rem;
  font-weight: 700;
}

.tb-search [hidden] { display: none !important; }

.tb-search .visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

@media (max-width: 767.98px) {
  .tb-search {
    align-items: stretch;
    padding: 0;
  }
  .tb-search-dialog {
    margin: auto 0 0;
    max-width: none;
    border-radius: 22px 22px 0 0;
    transform: translate3d(0, 24px, 0);
  }
  .tb-search.is-open .tb-search-dialog { transform: none; }
  .tb-search-esc { display: none; }
  .tb-search-x { display: grid; place-items: center; }
  .tb-search-foot-kbd { display: none; }
  .tb-search-bar input { font-size: 16px; }
  .tb-search-cats { margin-left: 0.85rem; margin-right: 0.85rem; }
  .tb-search-cat { font-size: 0.7rem; padding: 0.2rem 0.2rem; }
}

/* 接管后隐藏旧关键词遮罩，避免双层弹窗 */
.search-popup:not(#tb-search):has(.search-popup-form) {
  display: none !important;
  pointer-events: none !important;
}

/* 搜索中弹窗（对齐详情页语音合成 .stts-modal） */
.tb-swait {
  position: fixed;
  inset: 0;
  z-index: 20000;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  background: rgba(15, 23, 42, 0.5);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}

.tb-swait.is-open,
.tb-swait:not([hidden]) {
  display: flex;
}

.tb-swait[hidden] { display: none !important; }

.tb-swait-card {
  width: min(360px, 88vw);
  text-align: center;
  background: #fff;
  color: #0f172a;
  border: 1px solid rgba(148, 163, 184, 0.28);
  border-radius: 16px;
  padding: 1.35rem 1.25rem 1.2rem;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.35);
  animation: tbSwaitUp 0.25s ease;
}

.nice-dark-mode .tb-swait-card {
  background: #1e293b;
  color: #f1f5f9;
  border-color: rgba(148, 163, 184, 0.22);
}

.tb-swait-ring {
  width: 3.2rem;
  height: 3.2rem;
  margin: 0 auto 0.85rem;
  border-radius: 50%;
  border: 3px solid rgba(15, 118, 110, 0.22);
  border-top-color: #0f766e;
  animation: tbSwaitSpin 0.9s linear infinite;
}

.tb-swait-title {
  margin: 0;
  font-weight: 700;
  font-size: 0.95rem;
}

.tb-swait-bars {
  display: flex;
  justify-content: center;
  align-items: flex-end;
  gap: 0.28rem;
  height: 1.6rem;
  margin: 0.65rem 0 0.4rem;
}

.tb-swait-bars span {
  width: 0.28rem;
  height: 100%;
  border-radius: 99px;
  background: linear-gradient(180deg, #0f766e, #38bdf8);
  animation: tbSwaitWave 0.9s ease-in-out infinite;
}

.tb-swait-bars span:nth-child(2) { animation-delay: 0.1s; }
.tb-swait-bars span:nth-child(3) { animation-delay: 0.2s; }
.tb-swait-bars span:nth-child(4) { animation-delay: 0.3s; }
.tb-swait-bars span:nth-child(5) { animation-delay: 0.4s; }

.tb-swait-sub {
  margin: 0.35rem 0 0;
  font-size: 0.78rem;
  color: #64748b;
  line-height: 1.45;
}

.nice-dark-mode .tb-swait-sub { color: #94a3b8; }

.tb-swait-progress {
  height: 4px;
  margin-top: 1rem;
  background: rgba(100, 116, 139, 0.15);
  border-radius: 99px;
  overflow: hidden;
}

.tb-swait-progress > i {
  display: block;
  height: 100%;
  width: 100%;
  background: linear-gradient(90deg, #0f766e, #38bdf8, #ff5745, #0f766e);
  background-size: 200% 100%;
  animation: tbSwaitFlow 2s linear infinite;
}

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

@keyframes tbSwaitWave {
  0%, 100% { transform: scaleY(0.45); opacity: 0.45; }
  50% { transform: scaleY(1); opacity: 1; }
}

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

@keyframes tbSwaitFlow {
  0% { background-position: 0% 50%; }
  100% { background-position: 100% 50%; }
}

@media (prefers-reduced-motion: reduce) {
  .tb-swait-ring,
  .tb-swait-bars span,
  .tb-swait-progress > i,
  .tb-swait-card {
    animation: none !important;
  }
}
