:root {
  --accent: #246bfe;
  --accent-dark: #1749b7;
  --ink: #172033;
  --muted: #657084;
  --line: #d8dee9;
  --panel: #ffffff;
  --surface: #f5f7fb;
  --danger: #c7353e;
  --warn: #a86800;
  --ok: #227447;
  --timeline-top: 106px;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  padding: 0;
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  color: var(--ink);
  background: var(--surface);
}

a {
  color: var(--accent);
}

.page-shell {
  min-height: 100%;
}

.topbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 1000;
  background: rgba(255, 255, 255, 0.96);
  border-bottom: 1px solid var(--line);
  box-shadow: 0 8px 28px rgba(23, 32, 51, 0.08);
  backdrop-filter: blur(14px);
}

.topbar-inner {
  max-width: 1180px;
  margin: 0 auto;
  padding: 7px 20px 4px;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  align-items: center;
}

.brand {
  min-width: 0;
}

.eyebrow {
  margin: 0 0 2px;
  color: var(--accent);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

.page-title {
  margin: 0;
  font-size: 18px;
  line-height: 1.25;
  font-weight: 760;
}

.page-summary {
  display: none;
}

.home-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 32px;
  padding: 0 13px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: #fff;
  text-decoration: none;
  font-size: 14px;
  font-weight: 650;
  transition: border-color 0.2s ease, color 0.2s ease, transform 0.2s ease;
}

.home-link:hover {
  color: var(--accent);
  border-color: var(--accent);
  transform: translateY(-1px);
}

.controls {
  max-width: 1180px;
  margin: 0 auto;
  display: grid;
  gap: 10px;
  align-items: end;
}

.controls-primary {
  padding: 0 20px 6px;
  grid-template-columns: minmax(260px, 1fr) minmax(92px, 112px) minmax(128px, 152px);
  align-items: center;
}

.controls-advanced {
  position: absolute;
  left: 50%;
  top: calc(100% - 1px);
  width: min(1180px, calc(100% - 40px));
  padding: 14px;
  grid-template-columns: repeat(auto-fit, minmax(128px, 1fr));
  transform: translateX(-50%);
  border: 1px solid var(--line);
  border-radius: 0 0 8px 8px;
  background: rgba(255, 255, 255, 0.98);
  box-shadow: 0 18px 42px rgba(23, 32, 51, 0.16);
  backdrop-filter: blur(14px);
  max-height: calc(100vh - var(--timeline-top) - 14px);
  overflow: auto;
}

.controls-advanced[hidden] {
  display: none;
}

.field {
  min-width: 0;
  display: grid;
  gap: 6px;
}

.controls-primary .field-label {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.field-label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 760;
  line-height: 1;
}

.control,
.action-button {
  width: 100%;
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  font-size: 14px;
  outline: none;
}

.control {
  padding: 0 12px;
}

.control:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(36, 107, 254, 0.13);
}

.action-button {
  cursor: pointer;
  font-weight: 700;
  transition: background 0.2s ease, border-color 0.2s ease;
}

.action-button:hover {
  border-color: var(--accent);
  background: #f7faff;
}

.filter-toggle {
  position: relative;
}

.filter-toggle::after {
  content: "";
  display: inline-block;
  width: 6px;
  height: 6px;
  margin-left: 8px;
  border-right: 1.5px solid currentColor;
  border-bottom: 1.5px solid currentColor;
  transform: translateY(-2px) rotate(45deg);
  transition: transform 0.18s ease;
}

.filter-toggle[aria-expanded="true"]::after {
  transform: translateY(2px) rotate(225deg);
}

.filter-toggle.has-active {
  border-color: rgba(36, 107, 254, 0.34);
  background: #f7faff;
  color: var(--accent);
}

.meta-row {
  max-width: 1180px;
  margin: 0 auto;
  padding: 0 20px 4px;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

#stats {
  min-height: 18px;
  padding: 0;
  display: flex;
  flex: 1 1 100%;
  flex-wrap: wrap;
  gap: 4px 0;
  align-items: center;
  border-top: 1px solid rgba(216, 222, 233, 0.82);
  color: var(--muted);
}

.meta-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 18px;
  padding: 0 10px;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
  white-space: nowrap;
}

#stats .meta-pill + .meta-pill {
  border-left: 1px solid var(--line);
}

.meta-label {
  color: #7c8798;
  font-size: 11px;
  font-weight: 650;
}

.meta-value {
  color: var(--ink);
  font-weight: 760;
}

.result-toggle {
  justify-content: center;
  border: 1px solid rgba(36, 107, 254, 0.22);
  background: #f7faff;
  color: var(--accent);
  font-weight: 760;
}

.result-toggle::after {
  content: "";
  width: 6px;
  height: 6px;
  margin-left: 2px;
  border-top: 1.5px solid currentColor;
  border-right: 1.5px solid currentColor;
  transform: rotate(45deg);
}

.timeline-wrap {
  position: absolute;
  top: var(--timeline-top);
  left: 0;
  right: 0;
  bottom: 0;
  background: #fff;
}

#timeline-embed {
  width: 100%;
  height: 100%;
}

.result-overlay {
  position: fixed;
  inset: 0;
  z-index: 998;
  display: none;
  background: rgba(15, 23, 42, 0.38);
}

.result-overlay.show {
  display: block;
}

.result-panel {
  position: fixed;
  top: calc(var(--timeline-top) + 10px);
  left: 50%;
  z-index: 999;
  width: min(920px, calc(100% - 28px));
  max-height: calc(100vh - var(--timeline-top) - 28px);
  display: none;
  transform: translateX(-50%);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 18px 55px rgba(23, 32, 51, 0.22);
  overflow: hidden;
}

.result-panel.show {
  display: flex;
  flex-direction: column;
}

.result-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--line);
}

.result-title {
  font-size: 17px;
  font-weight: 760;
}

.close-button {
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: 8px;
  background: var(--surface);
  cursor: pointer;
  color: var(--muted);
  font-size: 22px;
  line-height: 1;
}

.result-list {
  min-height: 0;
  overflow: auto;
  padding: 14px;
  display: grid;
  gap: 12px;
}

.result-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: #fff;
  cursor: pointer;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.result-item:hover {
  border-color: var(--accent);
  box-shadow: 0 8px 22px rgba(36, 107, 254, 0.12);
}

.result-item-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin-bottom: 8px;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 8px;
  border-radius: 8px;
  background: var(--surface);
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.badge.trust-high {
  background: rgba(34, 116, 71, 0.11);
  color: var(--ok);
}

.badge.trust-medium {
  background: rgba(168, 104, 0, 0.12);
  color: var(--warn);
}

.badge.trust-low {
  background: rgba(199, 53, 62, 0.1);
  color: var(--danger);
}

.result-name {
  margin: 0 0 7px;
  font-size: 16px;
  line-height: 1.45;
  font-weight: 760;
}

.result-desc {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.65;
}

.result-source {
  margin-top: 10px;
  font-size: 13px;
}

mark {
  background: #fff2a8;
  color: inherit;
  padding: 0 2px;
  border-radius: 4px;
}

.empty-state {
  padding: 42px 16px;
  text-align: center;
  color: var(--muted);
}

.tl-media-content img,
.tl-slide img {
  box-shadow: none !important;
}

#timeline-embed .tl-headline-title {
  font-size: 28px !important;
  line-height: 1.2 !important;
}

#timeline-embed .tl-headline {
  font-size: 12px !important;
  line-height: 1.28 !important;
}

#timeline-embed .tl-text-content,
#timeline-embed .tl-text-content p {
  font-size: 14px !important;
  line-height: 1.65 !important;
}

#timeline-embed .tl-headline-date {
  font-size: 12px !important;
  line-height: 1.4 !important;
}

#timeline-embed .tl-timemarker .tl-timemarker-content-container,
#timeline-embed .tl-timeaxis {
  font-size: 10px !important;
}

.tl-text p a {
  text-decoration: none !important;
}

@media (max-width: 900px) {
  .topbar-inner {
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .home-link {
    justify-self: start;
  }

  .controls-primary {
    grid-template-columns: 1fr 104px 132px;
  }

  .controls-advanced {
    grid-template-columns: 1fr 1fr;
  }

  .controls-advanced .action-button {
    grid-column: 1 / -1;
  }

  #timeline-embed .tl-headline-title,
  #timeline-embed .tl-headline {
    font-size: 20px !important;
  }

  #timeline-embed .tl-text-content,
  #timeline-embed .tl-text-content p {
    font-size: 13px !important;
  }
}

@media (max-width: 560px) {
  .topbar-inner,
  .controls,
  .meta-row {
    padding-left: 12px;
    padding-right: 12px;
  }

  .controls {
    gap: 6px;
  }

  .controls-primary {
    grid-template-columns: minmax(0, 1fr) 76px 100px;
  }

  .controls-primary .action-button,
  .controls-primary .control {
    min-height: 32px;
    font-size: 13px;
  }

  .controls-advanced {
    width: calc(100% - 24px);
    grid-template-columns: 1fr;
  }

  .page-title {
    font-size: 19px;
  }
}
