:root {
  --ink: #17251f;
  --muted: #6c7b74;
  --soft: #eef2ed;
  --paper: rgba(255, 255, 252, 0.84);
  --paper-solid: #fffef9;
  --line: rgba(31, 59, 47, 0.13);
  --moss: #214f3c;
  --moss-dark: #15382a;
  --lime: #c3cf8e;
  --coral: #c27050;
  --danger: #b44232;
  --shadow: 0 24px 70px rgba(41, 58, 50, 0.11);
  --radius: 24px;
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: #f4f5ef;
  font-synthesis: none;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  background:
    radial-gradient(circle at 18% -8%, rgba(223, 240, 110, 0.24), transparent 31rem),
    linear-gradient(180deg, #f6f7f1 0%, #eef1eb 100%);
  overflow-x: hidden;
}

button, input, select { font: inherit; }
button, select { cursor: pointer; }

button:focus-visible, input:focus-visible, select:focus-visible, a:focus-visible, summary:focus-visible, pre:focus-visible {
  outline: 3px solid rgba(233, 120, 84, 0.35);
  outline-offset: 2px;
}

.ambient {
  position: fixed;
  border-radius: 999px;
  filter: blur(1px);
  pointer-events: none;
  z-index: -1;
}

.ambient-one {
  width: 430px;
  height: 430px;
  top: 8%;
  right: -240px;
  border: 1px solid rgba(33, 79, 60, 0.11);
  box-shadow: 0 0 0 68px rgba(255, 255, 255, 0.13), 0 0 0 136px rgba(33, 79, 60, 0.025);
}

.ambient-two {
  width: 170px;
  height: 170px;
  bottom: 9%;
  left: -70px;
  background: rgba(233, 120, 84, 0.07);
}

.topbar, .shell, footer {
  width: min(1440px, calc(100% - 48px));
  margin-inline: auto;
}

.topbar {
  min-height: 88px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--line);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  color: inherit;
  text-decoration: none;
}

.brand-mark {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 13px 13px 13px 4px;
  background: var(--moss);
  color: var(--lime);
  font: 700 22px/1 Georgia, serif;
  box-shadow: 0 9px 22px rgba(33, 79, 60, 0.21);
}

.brand strong { display: block; font-size: 15px; letter-spacing: -0.01em; }
.brand small { display: block; margin-top: 3px; color: var(--muted); font-size: 9px; letter-spacing: 0.16em; }

.health {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 9px 13px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.4);
  font-size: 12px;
}

.health-dot { width: 7px; height: 7px; border-radius: 50%; background: #aeb7b1; box-shadow: 0 0 0 4px rgba(174, 183, 177, 0.15); }
.health.is-online .health-dot { background: #4ca36f; box-shadow: 0 0 0 4px rgba(76, 163, 111, 0.14); }
.health.is-error .health-dot { background: var(--coral); box-shadow: 0 0 0 4px rgba(233, 120, 84, 0.13); }

.shell { padding: 74px 0 88px; }

.hero { max-width: 760px; margin-bottom: 42px; }
.eyebrow { margin: 0 0 11px; color: var(--coral); font-size: 10px; font-weight: 800; letter-spacing: 0.19em; text-transform: uppercase; }

h1 {
  margin: 0;
  font: 400 clamp(3.2rem, 7vw, 6.8rem)/0.93 Georgia, "Times New Roman", serif;
  letter-spacing: -0.065em;
}

h1 em { color: var(--moss); font-weight: 400; }
.hero-copy { max-width: 600px; margin: 25px 0 0; color: var(--muted); font-size: 16px; line-height: 1.75; }

.panel {
  background: var(--paper);
  border: 1px solid rgba(255, 255, 255, 0.88);
  box-shadow: var(--shadow);
  backdrop-filter: blur(22px);
}

.search-panel { padding: 18px; border-radius: var(--radius); }
.search-line { display: grid; grid-template-columns: 1fr auto; gap: 12px; }

.query-field {
  min-height: 64px;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 20px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.72);
  transition: border-color 160ms ease, box-shadow 160ms ease;
}

.query-field:focus-within { border-color: rgba(33, 79, 60, 0.45); box-shadow: 0 0 0 4px rgba(33, 79, 60, 0.06); }
.query-field input { width: 100%; border: 0; outline: 0; color: var(--ink); background: transparent; font-size: 17px; }
.query-field input::placeholder { color: #9aa49e; }
.search-icon { width: 16px; height: 16px; border: 2px solid var(--moss); border-radius: 50%; position: relative; flex: 0 0 auto; }
.search-icon::after { content: ""; position: absolute; width: 7px; height: 2px; right: -5px; bottom: -3px; background: var(--moss); transform: rotate(45deg); border-radius: 2px; }

.primary-button {
  min-width: 156px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 24px;
  border: 0;
  border-radius: 16px;
  background: var(--moss);
  color: #fff;
  font-weight: 700;
  transition: transform 160ms ease, background 160ms ease;
}

.primary-button:hover { transform: translateY(-2px); background: var(--moss-dark); }
.primary-button:disabled { cursor: wait; opacity: 0.65; transform: none; }

.parameter-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(140px, 1fr));
  gap: 12px;
  align-items: end;
  padding: 17px 4px 2px;
}

.field { display: grid; gap: 7px; }
.api-key-field { grid-column: 1 / -1; }
.parameter-grid > .field:nth-child(2) { grid-column: span 2; }
.field > span { color: var(--muted); font-size: 10px; font-weight: 750; letter-spacing: 0.08em; text-transform: uppercase; }
.field input, .field select {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 11px;
  padding: 0 11px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.62);
}

.switches { min-height: 40px; display: flex; align-items: center; gap: 15px; padding-inline: 3px; }
.switch-row { display: flex; align-items: center; gap: 7px; color: var(--muted); font-size: 12px; cursor: pointer; }
.switch-row input { position: absolute; opacity: 0; pointer-events: none; }
.switch { width: 31px; height: 18px; padding: 2px; border-radius: 99px; background: #d9dfda; transition: background 150ms ease; }
.switch::after { content: ""; display: block; width: 14px; height: 14px; border-radius: 50%; background: white; box-shadow: 0 2px 5px rgba(0, 0, 0, 0.13); transition: transform 150ms ease; }
.switch-row input:checked + .switch { background: var(--moss); }
.switch-row input:checked + .switch::after { transform: translateX(13px); }
.switch-row input:focus-visible + .switch { outline: 3px solid rgba(233, 120, 84, 0.35); outline-offset: 2px; }
.token-row { display: flex; padding: 14px 4px 2px; border-top: 1px solid var(--line); margin-top: 14px; }
.grow { flex: 1; }

.content-options { display: flex; align-items: end; gap: 16px; padding: 14px 4px 2px; }
.content-options .field { width: 150px; }
.content-options p { margin: 0 0 8px; color: var(--muted); font-size: 11px; line-height: 1.5; }
.content-options code { color: var(--moss); }
.content-mode-switch { min-height: 40px; }

.workspace { display: grid; grid-template-columns: minmax(0, 1.05fr) minmax(390px, 0.95fr); gap: 28px; align-items: start; margin-top: 70px; }
.results-column { min-width: 0; }
.section-heading { display: flex; justify-content: space-between; align-items: end; gap: 20px; margin-bottom: 22px; }
.section-heading h2 { margin: 0; font: 400 32px/1.1 Georgia, serif; letter-spacing: -0.035em; }
.result-count, .reader-state { color: var(--muted); font-size: 12px; }

.status-card {
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 25px;
  border: 1px dashed rgba(33, 79, 60, 0.22);
  border-radius: 18px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.35);
}

.status-card strong { color: var(--ink); font-size: 15px; }
.status-card p { margin: 6px 0 0; font-size: 13px; line-height: 1.5; }
.status-index { font: italic 31px/1 Georgia, serif; color: var(--coral); }
.status-card.is-loading .status-index { animation: pulse 0.9s ease-in-out infinite alternate; }
.status-card.is-error { border-style: solid; border-color: rgba(180, 66, 50, 0.22); background: rgba(255, 239, 233, 0.72); }

.meta-strip { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 18px; }
.meta-chip { display: inline-flex; align-items: center; gap: 6px; padding: 7px 10px; border: 1px solid var(--line); border-radius: 999px; color: var(--muted); background: rgba(255, 255, 255, 0.55); font-size: 11px; }
.meta-chip strong { color: var(--ink); font-weight: 750; }
.meta-chip.is-accent { color: var(--moss); border-color: rgba(33, 79, 60, 0.22); background: rgba(223, 240, 110, 0.16); }

.notice-stack { display: grid; gap: 8px; margin-bottom: 14px; }
.notice { overflow-wrap: anywhere; padding: 11px 13px; border-left: 3px solid var(--coral); border-radius: 4px 10px 10px 4px; color: #774638; background: rgba(233, 120, 84, 0.09); font-size: 12px; line-height: 1.5; }
.notice strong { margin-right: 5px; }

.results-list { display: grid; gap: 11px; }
.result-card {
  width: 100%;
  display: grid;
  grid-template-columns: 47px 1fr auto;
  gap: 15px;
  align-items: start;
  padding: 20px;
  text-align: left;
  border: 1px solid var(--line);
  border-radius: 17px;
  color: inherit;
  background: rgba(255, 255, 252, 0.62);
  transition: transform 160ms ease, border-color 160ms ease, box-shadow 160ms ease, background 160ms ease;
}

.result-card:hover { transform: translateY(-2px); border-color: rgba(33, 79, 60, 0.28); box-shadow: 0 13px 30px rgba(33, 51, 43, 0.08); background: var(--paper-solid); }
.result-card.is-selected { border-color: var(--moss); box-shadow: inset 4px 0 0 var(--lime); background: var(--paper-solid); }
.rank { display: grid; gap: 4px; font: italic 25px/1 Georgia, serif; color: var(--coral); }
.rank-detail { color: var(--muted); font: 9px/1.1 ui-monospace, SFMono-Regular, Menlo, monospace; }
.result-main { min-width: 0; }
.result-main h3 { margin: 0 0 7px; font-size: 15px; line-height: 1.35; }
.result-main p { display: -webkit-box; overflow: hidden; margin: 0 0 11px; color: var(--muted); font-size: 12.5px; line-height: 1.6; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.result-host { display: block; overflow: hidden; color: #5f786c; font: 11px/1.2 ui-monospace, SFMono-Regular, Menlo, monospace; text-overflow: ellipsis; white-space: nowrap; }
.result-source { display: inline-flex; margin: 0 0 8px; padding: 3px 7px; border-radius: 999px; color: var(--moss); background: rgba(223, 240, 110, 0.22); font-size: 9px; font-weight: 800; letter-spacing: 0.08em; text-transform: uppercase; }
.result-arrow { color: var(--moss); font-size: 17px; }

.pagination { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-top: 18px; }
.pagination span { color: var(--muted); font-size: 12px; }
.ghost-button { min-height: 38px; padding: 0 14px; border: 1px solid var(--line); border-radius: 10px; color: var(--ink); background: rgba(255, 255, 255, 0.5); }
.ghost-button:hover { border-color: rgba(33, 79, 60, 0.3); background: white; }
.ghost-button:disabled { opacity: 0.45; cursor: not-allowed; }

.diagnostics { margin-top: 18px; border: 1px solid var(--line); border-radius: 13px; background: rgba(255, 255, 255, 0.42); }
.diagnostics summary { padding: 13px 15px; color: var(--muted); cursor: pointer; font-size: 12px; font-weight: 700; }
.diagnostics > div { padding: 0 15px 15px; }
.diagnostic-block { padding: 12px 0; border-top: 1px solid var(--line); }
.diagnostic-block h4 { margin: 0 0 7px; font-size: 12px; }
.diagnostic-block dl { display: grid; grid-template-columns: 110px 1fr; gap: 6px 10px; margin: 0; font-size: 11px; }
.diagnostic-block dt { color: var(--muted); }
.diagnostic-block dd { min-width: 0; margin: 0; overflow-wrap: anywhere; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.diagnostic-block pre, .error-raw { max-height: 230px; overflow: auto; margin: 10px 0 0; padding: 10px; border-radius: 9px; color: #dcecdf; background: #17251f; white-space: pre-wrap; overflow-wrap: anywhere; font: 10.5px/1.55 ui-monospace, SFMono-Regular, Menlo, monospace; }
.json-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 0 10px; color: var(--muted); font-size: 10px; font-weight: 750; letter-spacing: 0.08em; text-transform: uppercase; }
.copy-button { min-height: 30px; padding: 0 10px; border: 1px solid var(--line); border-radius: 8px; color: var(--moss); background: rgba(255, 255, 255, 0.66); font-size: 10px; font-weight: 700; }
.copy-button:hover { background: white; border-color: rgba(33, 79, 60, 0.3); }
.json-tree { max-height: 480px; overflow: auto; padding: 12px; border: 1px solid var(--line); border-radius: 11px; color: #31473d; background: #fbfbf6; font: 11px/1.65 ui-monospace, SFMono-Regular, Menlo, monospace; }
.json-tree details { margin-left: 15px; }
.json-tree > details { margin-left: 0; }
.json-tree summary { cursor: pointer; color: #4c6157; list-style-position: outside; }
.json-key { color: #9d4c34; }
.json-value { overflow-wrap: anywhere; }
.json-string { color: #226a46; }
.json-number { color: #3e62a0; }
.json-boolean { color: #8556a6; }
.json-null { color: #8c9892; font-style: italic; }
.json-leaf { margin-left: 15px; }

.reader-column { position: sticky; top: 20px; min-width: 0; border-radius: var(--radius); }
.reader-sticky { padding: 28px; }
.reader-heading { align-items: center; }
.reader-state { padding: 6px 9px; border-radius: 999px; background: var(--soft); }
.reader-state.is-loading { color: #795b12; background: #fff4cb; }
.reader-state.is-ready { color: #22623e; background: #def1e4; }
.reader-state.is-error { color: var(--danger); background: #fde5df; }
.read-controls { display: grid; grid-template-columns: 1fr 1fr auto; gap: 10px; align-items: end; padding-bottom: 20px; border-bottom: 1px solid var(--line); }
.reader-switch { min-height: 40px; }
.reader-empty { min-height: 390px; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 42px; text-align: center; color: var(--muted); }
.reader-empty strong { margin-top: 17px; color: var(--ink); font: 400 23px/1.2 Georgia, serif; }
.reader-empty p { max-width: 330px; margin: 11px 0 0; font-size: 12px; line-height: 1.7; }
.reader-empty code { font-size: 10px; }
.reader-glyph { width: 76px; height: 76px; display: grid; place-items: center; border: 1px solid rgba(33, 79, 60, 0.17); border-radius: 50%; color: var(--moss); background: rgba(223, 240, 110, 0.19); font: italic 25px/1 Georgia, serif; }
.reader-title-block { padding: 25px 0 18px; }
.reader-title-block p { margin: 0 0 8px; color: var(--coral); font-size: 10px; font-weight: 750; letter-spacing: 0.08em; text-transform: uppercase; }
.reader-title-block h3 { margin: 0 0 10px; font: 400 27px/1.15 Georgia, serif; letter-spacing: -0.025em; }
.reader-title-block a { color: var(--moss); font-size: 11px; text-decoration-thickness: 1px; text-underline-offset: 3px; }
.reader-meta { margin-bottom: 15px; }
.reader-tabs { display: flex; gap: 5px; padding: 4px; margin: 5px 0 14px; border: 1px solid var(--line); border-radius: 12px; background: rgba(238, 242, 237, 0.72); }
.reader-tab { flex: 1; min-height: 34px; padding: 0 7px; border: 0; border-radius: 8px; color: var(--muted); background: transparent; font-size: 11px; font-weight: 750; }
.reader-tab:hover { color: var(--ink); }
.reader-tab.is-active { color: var(--moss); background: white; box-shadow: 0 3px 12px rgba(38, 57, 48, 0.08); }
.reader-tab-panel { min-height: 310px; }
.markdown-preview { max-height: 64vh; overflow: auto; padding: 24px; border: 1px solid var(--line); border-radius: 15px; color: #263d33; background: #fffef9; font-family: Georgia, "Times New Roman", serif; line-height: 1.75; }
.markdown-preview h1, .markdown-preview h2, .markdown-preview h3, .markdown-preview h4, .markdown-preview h5, .markdown-preview h6 { margin: 1.35em 0 0.55em; color: var(--ink); line-height: 1.2; letter-spacing: -0.02em; }
.markdown-preview h1:first-child, .markdown-preview h2:first-child, .markdown-preview h3:first-child, .markdown-preview p:first-child { margin-top: 0; }
.markdown-preview h1 { font-size: 28px; }
.markdown-preview h2 { font-size: 23px; }
.markdown-preview h3 { font-size: 19px; }
.markdown-preview p, .markdown-preview li { font-size: 14px; }
.markdown-preview p { margin: 0 0 1em; }
.markdown-preview ul, .markdown-preview ol { padding-left: 1.5em; }
.markdown-preview blockquote { margin: 1.2em 0; padding: 5px 0 5px 16px; border-left: 3px solid var(--lime); color: var(--muted); }
.markdown-preview code { padding: 2px 5px; border-radius: 5px; background: var(--soft); font: 0.88em/1.5 ui-monospace, SFMono-Regular, Menlo, monospace; }
.markdown-preview pre { overflow: auto; padding: 15px; border-radius: 11px; color: #dcecdf; background: #17251f; }
.markdown-preview pre code { padding: 0; color: inherit; background: transparent; }
.markdown-preview a { color: var(--moss); text-decoration-color: var(--coral); text-underline-offset: 3px; }
.debug-tab-content { min-height: 300px; margin-top: 0; padding: 0 15px 15px; }
#articleBody { min-height: 310px; max-height: 64vh; overflow: auto; margin: 0; padding: 21px; border: 1px solid var(--line); border-radius: 15px; color: #263d33; background: #fbfbf6; white-space: pre-wrap; overflow-wrap: anywhere; font: 12.5px/1.8 ui-monospace, SFMono-Regular, Menlo, Monaco, monospace; tab-size: 2; }

.is-hidden { display: none !important; }
.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; }

footer { display: flex; justify-content: space-between; gap: 20px; padding: 24px 0 35px; border-top: 1px solid var(--line); color: var(--muted); font-size: 10px; letter-spacing: 0.1em; text-transform: uppercase; }

@keyframes pulse { from { opacity: 0.35; transform: scale(0.94); } to { opacity: 1; transform: scale(1); } }

@media (max-width: 1080px) {
  .parameter-grid { grid-template-columns: 1.5fr 1fr 90px 90px; }
  .switches { grid-column: 1 / -1; }
  .workspace { grid-template-columns: 1fr; }
  .reader-column { position: static; }
  #articleBody { max-height: none; }
}

@media (max-width: 680px) {
  .topbar, .shell, footer { width: min(100% - 28px, 1440px); }
  .topbar { min-height: 72px; }
  .health span:last-child { display: none; }
  .shell { padding: 45px 0 60px; }
  .hero { margin-bottom: 30px; }
  h1 { font-size: clamp(2.65rem, 14vw, 4.4rem); }
  .content-options { align-items: stretch; flex-direction: column; }
  .content-options .field { width: 100%; }
  .hero-copy { font-size: 14px; }
  .search-panel { padding: 12px; }
  .search-line { grid-template-columns: 1fr; }
  .primary-button { min-height: 52px; }
  .parameter-grid { grid-template-columns: 1fr 1fr; }
  .parameter-grid .field:first-child, .parameter-grid .field:nth-child(2), .switches { grid-column: 1 / -1; }
  .workspace { margin-top: 50px; gap: 42px; }
  .result-card { grid-template-columns: 36px 1fr; padding: 16px; }
  .result-arrow { display: none; }
  .reader-sticky { padding: 19px; }
  .read-controls { grid-template-columns: 1fr 1fr; }
  .reader-switch { grid-column: 1 / -1; }
  .reader-empty { min-height: 320px; padding: 30px 12px; }
  footer { flex-direction: column; }
}

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

/* Result cards rise in as results arrive */
@keyframes card-rise {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}
.results-list .result-card {
  animation: card-rise 380ms ease both;
}
.results-list .result-card:nth-child(2) { animation-delay: 45ms; }
.results-list .result-card:nth-child(3) { animation-delay: 90ms; }
.results-list .result-card:nth-child(4) { animation-delay: 135ms; }
.results-list .result-card:nth-child(5) { animation-delay: 180ms; }
.results-list .result-card:nth-child(n+6) { animation-delay: 220ms; }

/* Reader state transitions stay smooth */
.reader-state,
.result-count {
  transition: opacity 240ms ease;
}
