:root {
  color-scheme: light;
  --ink: #16211d;
  --muted: #627069;
  --paper: #f4f1e9;
  --surface: #fffdf8;
  --line: #dcd8cc;
  --forest: #174f3d;
  --forest-dark: #10382c;
  --mint: #cde5da;
  --accent: #d05a3a;
  --shadow: 0 18px 55px rgba(26, 43, 36, 0.1);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    radial-gradient(circle at 85% 0%, rgba(205, 229, 218, 0.85), transparent 35rem),
    linear-gradient(180deg, #faf8f2 0%, var(--paper) 100%);
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0.22;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 160 160' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='.11'/%3E%3C/svg%3E");
}

button,
input,
select {
  font: inherit;
}

.shell {
  position: relative;
  width: min(1120px, calc(100% - 40px));
  margin: 0 auto;
  padding: 68px 0 96px;
}

.brand-logo {
  display: block;
  width: clamp(209px, 24vw, 250px);
  height: auto;
  margin-bottom: 30px;
}

.eyebrow {
  margin-bottom: 16px;
  color: var(--accent);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.hero-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 32px;
}

h1 {
  max-width: 960px;
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(2.7rem, 6vw, 4.9rem);
  font-weight: 500;
  letter-spacing: -0.055em;
  line-height: 0.94;
}

h1 span {
  color: var(--forest);
}

.lede {
  max-width: 700px;
  margin: 24px 0 0;
  color: var(--muted);
  font-size: clamp(1rem, 2vw, 1.24rem);
  line-height: 1.55;
}

.index-status {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  gap: 9px;
  margin-top: 8px;
  padding: 10px 14px;
  border: 1px solid rgba(23, 79, 61, 0.18);
  border-radius: 999px;
  background: rgba(255, 253, 248, 0.68);
  color: var(--forest);
  font-size: 0.8rem;
  font-weight: 700;
  backdrop-filter: blur(10px);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #c6982d;
  box-shadow: 0 0 0 4px rgba(198, 152, 45, 0.14);
}

.index-status.ready .status-dot {
  background: #2b956d;
  box-shadow: 0 0 0 4px rgba(43, 149, 109, 0.14);
}

.index-status.error .status-dot {
  background: var(--accent);
  box-shadow: 0 0 0 4px rgba(208, 90, 58, 0.14);
}

.search-panel {
  margin-top: 48px;
  padding: 26px;
  border: 1px solid rgba(42, 64, 55, 0.12);
  border-radius: 22px;
  background: rgba(255, 253, 248, 0.92);
  box-shadow: var(--shadow);
}

.engine-workspace {
  margin-top: 34px;
}

.engine-tabs {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  padding: 8px;
  border: 1px solid rgba(42, 64, 55, 0.12);
  border-radius: 16px;
  background: rgba(255, 253, 248, 0.72);
}

.engine-tab {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 58px;
  padding: 12px 16px;
  border: 1px solid transparent;
  border-radius: 11px;
  background: transparent;
  color: var(--muted);
  font-weight: 800;
  cursor: pointer;
  transition: color 150ms ease, background 150ms ease, border-color 150ms ease;
}

.engine-tab:hover {
  border-color: var(--line);
  color: var(--forest);
}

.engine-tab:focus-visible {
  outline: 3px solid rgba(23, 79, 61, 0.2);
  outline-offset: 2px;
}

.engine-tab.active {
  border-color: rgba(23, 79, 61, 0.2);
  background: var(--forest);
  color: white;
  box-shadow: 0 7px 18px rgba(23, 79, 61, 0.16);
}

.engine-tab small {
  padding: 4px 7px;
  border-radius: 999px;
  background: rgba(22, 33, 29, 0.07);
  font-size: 0.68rem;
  font-weight: 700;
}

.engine-tab.active small {
  background: rgba(255, 255, 255, 0.15);
}

.engine-tab.tab-error small {
  background: rgba(208, 90, 58, 0.14);
  color: #984229;
}

.engine-tab.active.tab-error small {
  background: rgba(255, 255, 255, 0.18);
  color: white;
}

.engine-panel {
  margin-top: 14px;
  padding: 24px 26px 0;
  border: 1px solid rgba(42, 64, 55, 0.12);
  border-radius: 20px;
  background: rgba(255, 253, 248, 0.84);
  box-shadow: 0 12px 35px rgba(26, 43, 36, 0.06);
}

.engine-panel[hidden] {
  display: none;
}

.engine-intro {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 28px;
  margin-bottom: 18px;
}

.engine-intro h2 {
  margin: 4px 0 0;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1.65rem;
  font-weight: 500;
}

.engine-intro p {
  max-width: 510px;
  margin: 0;
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.5;
  text-align: right;
}

.engine-kicker {
  color: var(--accent);
  font-size: 0.65rem;
  font-weight: 800;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.search-panel label {
  display: block;
  margin-bottom: 10px;
  font-size: 0.76rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.search-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
}

input[type="search"] {
  width: 100%;
  min-height: 60px;
  padding: 0 20px;
  border: 1px solid var(--line);
  border-radius: 13px;
  outline: none;
  background: #fff;
  color: var(--ink);
  font-size: 1.05rem;
  transition: border-color 150ms ease, box-shadow 150ms ease;
}

input[type="search"]:focus {
  border-color: var(--forest);
  box-shadow: 0 0 0 4px rgba(23, 79, 61, 0.11);
}

.intent-control {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-top: 16px;
  padding: 13px 15px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: rgba(255, 255, 255, 0.62);
}

.intent-control label {
  margin: 0 0 4px;
}

.intent-control p {
  max-width: 680px;
  margin: 0;
  color: var(--muted);
  font-size: 0.72rem;
  line-height: 1.45;
}

.intent-control select {
  flex: 0 0 auto;
  max-width: 100%;
  padding: 8px 30px 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  color: var(--ink);
  font-size: 0.78rem;
  font-weight: 700;
}

#search-button {
  min-width: 130px;
  min-height: 60px;
  border: 0;
  border-radius: 13px;
  background: var(--forest);
  color: white;
  font-weight: 800;
  cursor: pointer;
  transition: background 150ms ease, transform 150ms ease;
}

#search-button:hover {
  background: var(--forest-dark);
  transform: translateY(-1px);
}

#search-button:disabled {
  cursor: wait;
  opacity: 0.76;
  transform: none;
}

.button-spinner {
  display: none;
  width: 18px;
  height: 18px;
  margin: auto;
  border: 2px solid rgba(255, 255, 255, 0.35);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 650ms linear infinite;
}

.loading .button-label {
  display: none;
}

.loading .button-spinner {
  display: block;
}

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

.search-options {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 24px;
  margin-top: 16px;
}

.blend-control {
  margin-top: 20px;
  padding: 18px 20px 15px;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: rgba(244, 241, 233, 0.62);
}

.blend-heading,
.blend-values,
.blend-scale {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.blend-heading {
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.blend-total {
  color: var(--muted);
  font-size: 0.68rem;
  font-weight: 700;
}

.blend-values {
  margin-top: 13px;
  color: var(--muted);
  font-size: 0.84rem;
}

.blend-values strong {
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}

#semantic-weight {
  --semantic-weight: 70%;
  width: 100%;
  height: 6px;
  margin: 14px 0 8px;
  border: 0;
  border-radius: 999px;
  outline: none;
  appearance: none;
  background: linear-gradient(
    90deg,
    var(--accent) 0%,
    var(--accent) calc(100% - var(--semantic-weight)),
    var(--forest) calc(100% - var(--semantic-weight)),
    var(--forest) 100%
  );
  cursor: pointer;
}

#semantic-weight::-webkit-slider-thumb {
  width: 21px;
  height: 21px;
  border: 3px solid var(--surface);
  border-radius: 50%;
  appearance: none;
  background: var(--ink);
  box-shadow: 0 2px 8px rgba(22, 33, 29, 0.3);
}

#semantic-weight::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border: 3px solid var(--surface);
  border-radius: 50%;
  background: var(--ink);
  box-shadow: 0 2px 8px rgba(22, 33, 29, 0.3);
}

#semantic-weight:focus-visible {
  box-shadow: 0 0 0 4px rgba(23, 79, 61, 0.15);
}

#semantic-weight:disabled {
  cursor: wait;
  opacity: 0.65;
}

.blend-scale {
  color: var(--muted);
  font-size: 0.7rem;
}

.relevance-guard {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-top: 16px;
  padding-top: 15px;
  border-top: 1px solid var(--line);
}

.relevance-guard label {
  margin: 0 0 4px;
}

.relevance-guard p {
  margin: 0;
  color: var(--muted);
  font-size: 0.72rem;
  line-height: 1.45;
}

.relevance-guard select {
  flex: 0 0 auto;
  padding: 8px 30px 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  color: var(--ink);
  font-size: 0.78rem;
  font-weight: 700;
}

.examples {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 0.83rem;
}

.example-query {
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: transparent;
  color: var(--forest);
  cursor: pointer;
}

.example-query:hover {
  border-color: var(--forest);
  background: var(--mint);
}

.top-k {
  display: flex !important;
  flex: 0 0 auto;
  align-items: center;
  gap: 8px;
  margin: 0 !important;
}

.top-k select {
  padding: 6px 28px 6px 9px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  color: var(--ink);
}

.feedback {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 24px;
  padding: 30px 2px 15px;
  border-bottom: 1px solid var(--line);
}

.feedback h2 {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1.65rem;
  font-weight: 500;
}

.feedback p {
  margin: 6px 0 0;
  color: var(--muted);
}

.timing {
  flex: 0 0 auto;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  font-size: 0.82rem;
}

.result-card {
  display: grid;
  grid-template-columns: 48px minmax(0, 1fr);
  gap: 18px;
  padding: 25px 4px;
  border-bottom: 1px solid var(--line);
  animation: reveal 260ms ease both;
}

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

.result-rank {
  display: grid;
  width: 40px;
  height: 40px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 50%;
  color: var(--muted);
  font-family: Georgia, "Times New Roman", serif;
}

.result-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 7px;
}

.reference-code {
  color: var(--accent);
  font-size: 0.74rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.score {
  padding: 4px 8px;
  border-radius: 7px;
  background: var(--mint);
  color: var(--forest-dark);
  font-size: 0.74rem;
  font-variant-numeric: tabular-nums;
  font-weight: 800;
}

.result-title {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(1.2rem, 3vw, 1.55rem);
  font-weight: 500;
  line-height: 1.25;
}

.result-summary {
  max-width: 880px;
  max-height: 4.74em;
  margin: 10px 0 0;
  overflow: hidden;
  color: var(--muted);
  line-height: 1.58;
  transition: max-height 320ms ease;
}

.result-summary.expanded {
  overflow: visible;
}

.read-more {
  margin-top: 9px;
  padding: 0;
  border: 0;
  border-bottom: 1px solid currentColor;
  background: transparent;
  color: var(--forest);
  font-size: 0.78rem;
  font-weight: 800;
  cursor: pointer;
}

.read-more:hover {
  color: var(--accent);
}

.result-signals {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin-top: 12px;
}

.result-signals span {
  padding: 4px 7px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--muted);
  font-size: 0.68rem;
  font-weight: 700;
}

.result-signals .low {
  border-color: rgba(208, 90, 58, 0.32);
  background: rgba(208, 90, 58, 0.08);
  color: #984229;
}

.why-toggle {
  margin-top: 14px;
  padding: 8px 11px;
  border: 1px solid rgba(23, 79, 61, 0.28);
  border-radius: 8px;
  background: rgba(205, 229, 218, 0.32);
  color: var(--forest);
  font-size: 0.76rem;
  font-weight: 800;
  cursor: pointer;
  transition: border-color 150ms ease, background 150ms ease;
}

.why-toggle:hover {
  border-color: var(--forest);
  background: var(--mint);
}

.why-toggle[aria-expanded="true"] {
  background: var(--forest);
  color: white;
}

.why-panel {
  margin-top: 12px;
  padding: 18px;
  border: 1px solid rgba(23, 79, 61, 0.18);
  border-radius: 12px;
  background: rgba(244, 241, 233, 0.62);
}

.why-panel.loading-explanation {
  color: var(--muted);
  font-size: 0.82rem;
}

.why-interpretation {
  margin: 0 0 14px;
  padding: 11px 13px;
  border-left: 3px solid var(--forest);
  background: rgba(205, 229, 218, 0.48);
  color: var(--forest-dark);
  font-size: 0.86rem;
  font-weight: 700;
  line-height: 1.5;
}

.why-interpretation.caution {
  border-left-color: var(--accent);
  background: rgba(208, 90, 58, 0.08);
  color: #7a3825;
}

.why-metrics {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}

.why-metric {
  min-width: 0;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.why-metric span,
.why-metric strong {
  display: block;
}

.why-metric span {
  color: var(--muted);
  font-size: 0.65rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.why-metric strong {
  margin-top: 5px;
  overflow-wrap: anywhere;
  font-size: 0.78rem;
  font-variant-numeric: tabular-nums;
}

.why-panel h4 {
  margin: 18px 0 9px;
  font-size: 0.72rem;
  letter-spacing: 0.07em;
  text-transform: uppercase;
}

.why-note {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 0.75rem;
  line-height: 1.5;
}

.separation-note {
  padding-left: 10px;
  border-left: 2px solid var(--line);
}

.evidence-list {
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.evidence-list li {
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.evidence-heading {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  color: var(--forest);
  font-size: 0.7rem;
}

.evidence-heading span {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.evidence-list p {
  margin: 6px 0 0;
  color: var(--ink);
  font-size: 0.82rem;
  line-height: 1.5;
}

.source-fields {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.source-fields span {
  padding: 4px 7px;
  border-radius: 999px;
  background: var(--mint);
  color: var(--forest-dark);
  font-size: 0.68rem;
  font-weight: 700;
}

.result-id {
  margin-top: 11px;
  color: #8b938f;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.7rem;
}

.debug {
  margin: 30px 0 26px;
  color: var(--muted);
  font-size: 0.82rem;
}

.debug summary {
  cursor: pointer;
}

.debug pre {
  max-height: 460px;
  overflow: auto;
  padding: 18px;
  border-radius: 12px;
  background: #19231f;
  color: #e8eee9;
  white-space: pre-wrap;
}

.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;
}

@media (max-width: 760px) {
  .shell {
    width: min(100% - 24px, 1120px);
    padding-top: 40px;
  }

  .brand-logo {
    margin-bottom: 24px;
  }

  .hero-row,
  .search-options {
    display: block;
  }

  .index-status {
    width: fit-content;
    margin-top: 24px;
  }

  .search-panel {
    margin-top: 32px;
    padding: 16px;
  }

  .engine-workspace {
    margin-top: 24px;
  }

  .engine-tabs {
    gap: 6px;
    padding: 6px;
  }

  .engine-tab {
    align-items: flex-start;
    flex-direction: column;
    gap: 5px;
    padding: 10px 12px;
  }

  .engine-panel {
    padding: 18px 16px 0;
  }

  .engine-intro {
    align-items: flex-start;
    flex-direction: column;
    gap: 8px;
  }

  .engine-intro p {
    text-align: left;
  }

  .search-row {
    grid-template-columns: 1fr;
  }

  #search-button {
    min-height: 52px;
  }

  .top-k {
    width: fit-content;
    margin-top: 16px !important;
  }

  .blend-control {
    padding: 15px;
  }

  .intent-control {
    align-items: stretch;
    flex-direction: column;
    gap: 10px;
  }

  .intent-control select {
    width: 100%;
  }

  .relevance-guard {
    align-items: stretch;
    flex-direction: column;
    gap: 10px;
  }

  .relevance-guard select {
    width: 100%;
  }

  .feedback {
    align-items: flex-start;
    flex-direction: column;
    gap: 10px;
  }

  .result-card {
    grid-template-columns: 36px minmax(0, 1fr);
    gap: 12px;
  }

  .result-rank {
    width: 32px;
    height: 32px;
  }

  .why-metrics {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 460px) {
  .why-metrics {
    grid-template-columns: 1fr;
  }
}

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