:root {
  --research-link: #154a91;
  --research-active: #eaf1fb;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --research-link: #9fc7ff;
    --research-active: #242f42;
  }
}
:root[data-theme="dark"] {
  --research-link: #9fc7ff;
  --research-active: #242f42;
}

body.research-page { height: auto; min-height: 100%; overflow: auto; }
.research-page [hidden] { display: none !important; }
.research-page a { color: var(--research-link); text-underline-offset: .18em; }
.research-page :focus-visible { outline-color: var(--research-link); }
.research-top { height: auto; min-height: var(--head); flex-wrap: wrap; row-gap: 4px; }
.research-top .brand { color: var(--fg); text-decoration: none; }
.research-top nav { display: flex; flex-wrap: wrap; gap: 2px 18px; margin-inline-start: auto; }
.research-top nav a { display: inline-flex; align-items: center; min-height: 38px; }
.research-top nav [aria-current="page"] { font-weight: 700; color: var(--fg); }

.research-heading {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 6px 20px;
  padding: 20px clamp(16px, 3vw, 44px) 16px;
  border-bottom: 1px solid var(--line);
}
.research-heading h1 { margin: 0; font-size: clamp(21px, 2vw, 27px); line-height: 1.4; }
.research-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto 1fr;
  min-height: calc(100vh - 124px);
}
.research-layout:has(#history-panel[open]) {
  grid-template-columns: minmax(225px, 18rem) minmax(0, 1fr);
  grid-template-rows: 1fr;
}
.research-history {
  padding: 8px clamp(16px, 2.5vw, 34px);
  background: var(--panel);
  border-block-end: 1px solid var(--line);
}
.research-history:has(details[open]) {
  padding: 16px 12px;
  border-inline-end: 1px solid var(--line);
  border-block-end: 0;
}
.research-history summary {
  width: fit-content;
  padding: 4px 0;
  color: var(--fg);
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
}
.research-history p { margin: 4px 0 12px; color: var(--mute); font-size: 12px; }
#history-list { display: flex; flex-direction: column; gap: 5px; }
.history-choice {
  width: 100%;
  padding: 7px 10px;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--fg);
  text-align: left;
  line-height: 1.45;
  cursor: pointer;
}
.history-choice:hover { border-color: var(--research-link); }
.history-choice[aria-pressed="true"] {
  border-color: var(--research-link);
  border-inline-start: 3px solid var(--research-link);
  padding-inline-start: 8px;
  background: var(--research-active);
}
.history-choice strong { display: block; font-size: 13px; font-weight: 600; }
.history-meta { display: block; color: var(--mute); margin-block-start: 2px; font-size: 12px; }

.research-main { min-width: 0; padding: 17px clamp(16px, 2.5vw, 34px) 32px; }
.research-main h2 { font-size: 18px; line-height: 1.5; margin: 0 0 12px; }
.research-intents { min-inline-size: 0; margin: 0 0 16px; padding: 0; border: 0; }
.research-intents legend { padding: 0; margin-block-end: 4px; font-weight: 600; }
.research-intent-options, .research-fields { display: flex; flex-wrap: wrap; align-items: end; gap: 8px 12px; }
.research-intent {
  position: relative;
  display: flex;
  cursor: pointer;
}
.research-intent input { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: inherit; }
.research-intent span {
  display: grid;
  align-items: center;
  min-height: 38px;
  padding: 6px 10px;
  background: var(--card);
  border: 1px solid var(--mute);
}
.research-intent input:checked + span { border-color: var(--research-link); background: var(--research-active); color: var(--research-link); }
.research-intent input:focus-visible + span { outline: 2px solid var(--research-link); outline-offset: 2px; }
.research-fields label { display: grid; gap: 4px; color: var(--fg); font-weight: 600; min-width: 0; }
.research-fields label:first-child { flex: 1 1 240px; max-width: 490px; }
.research-fields input, .research-fields select, .research-fields button, #research-retry {
  color: var(--fg);
  background: var(--card);
  border: 1px solid var(--mute);
  min-height: 38px;
  padding: 6px 10px;
  font: inherit;
  font-weight: 400;
}
.research-fields input { width: 100%; }
.research-controls button, #research-retry { cursor: pointer; }
.research-controls :disabled { opacity: .65; cursor: default; }
#research-status { color: var(--mute); margin: 14px 0 8px; }
.research-selection, #research-error { background: var(--panel); border: 1px solid var(--line); padding: 10px 12px; margin-block: 12px; }
.research-selection p, #research-error p { margin: 0; }
#research-error button { margin-block-start: 10px; }
.research-selection ul { margin: 6px 0 0; padding-inline-start: 1.3em; }

.research-table { width: 100%; border-collapse: collapse; line-height: 1.55; background: var(--card); overflow-wrap: anywhere; }
.research-table th, .research-table td {
  border: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
  padding: 10px 12px;
}
.research-table thead th { background: var(--panel); color: var(--mute); }
.research-table tbody th { width: 44%; }
.research-table tbody td:first-of-type { width: 27%; }
.research-title { font-size: 14px; font-weight: 700; }
.research-description { font-weight: 400; margin: 4px 0 6px; }
.research-meta { color: var(--mute); font-size: 12px; font-weight: 400; margin-block-start: 4px; }
.research-link-list { display: grid; justify-items: start; gap: 3px; margin: 0; padding: 0; list-style: none; }
.research-table details { margin-block-start: 5px; }
.research-table details summary { color: var(--research-link); cursor: pointer; }
.research-table details .research-link-list { margin-block-start: 5px; padding-inline-start: 14px; }

.research-reader { padding: 18px clamp(16px, 3vw, 44px) 36px; }
.research-reader article { max-width: 84rem; }
.research-reader h1 { font-size: clamp(22px, 2.8vw, 30px); margin: 14px 0 16px; line-height: 1.35; }
.research-reader h2 { font-size: 19px; margin: 24px 0 8px; border-block-end: 1px solid var(--line); }
.research-reader h3, .research-reader h4 { margin: 18px 0 6px; }
.research-reader p, .research-reader ul, .research-reader ol { margin-block: 8px; }
.research-reader pre, .research-reader blockquote { padding: 10px 14px; margin-inline: 0; background: var(--panel); border: 1px solid var(--line); }
.research-reader pre { white-space: pre-wrap; overflow-wrap: anywhere; }
.research-reader code { font-family: var(--mono); }
.research-reader p, .research-reader li, .research-reader a { overflow-wrap: anywhere; }
.article-table-wrap { overflow-x: auto; }
.research-reader table { width: 100%; border-collapse: collapse; margin: 8px 0; background: var(--card); }
.research-reader th, .research-reader td { text-align: start; padding: 8px 10px; border: 1px solid var(--line); vertical-align: top; }
.research-reader th { background: var(--panel); }

@media (max-width: 760px) {
  .research-layout:has(#history-panel[open]) { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto 1fr; }
  .research-history:has(details[open]) { border-inline-end: 0; border-block-end: 1px solid var(--line); padding: 8px 16px; }
}
@media (max-width: 540px) {
  .research-top nav { margin-inline-start: 0; }
  .research-table thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
  .research-table, .research-table tbody, .research-table tr, .research-table th, .research-table td { display: block; }
  .research-table tbody tr { padding: 10px 12px; border: 1px solid var(--line); }
  .research-table tbody tr + tr { border-block-start: 0; }
  .research-table tbody th, .research-table tbody td:first-of-type { width: auto; }
  .research-table tbody th, .research-table tbody td { border: 0; padding: 2px 0; }
  .research-table tbody td:first-of-type { margin-block-start: 6px; }
}
