/* =============================================================
   THE INDEX — letterpress / card-catalog visual system
   COMP4321 Search Instrument · static prototype
   ============================================================= */

@import url('https://fonts.googleapis.com/css2?family=Instrument+Serif:ital@0;1&family=Spectral:ital,wght@0,200;0,300;0,400;0,500;0,600;0,700;1,300;1,400;1,600&family=IBM+Plex+Mono:wght@300;400;500;600&display=swap');

:root {
  --paper: #efe7d4;
  --paper-2: #ece1c8;
  --paper-deep: #ddd0b3;
  --ink: #1a1410;
  --ink-soft: #4a4036;
  --ink-faint: #8a7e6a;
  --hair: #b8a98c;
  --rule: #6a5d49;

  --accent: #a8331f;            /* sealing-wax red */
  --accent-deep: #7c1d1d;
  --accent-soft: #cf7a64;
  --link: #1e3a5f;              /* navy ink */
  --link-hover: #a8331f;
  --stamp: #3b5a3b;             /* archive green */

  --serif:   'Spectral', 'Iowan Old Style', 'Cambria', Georgia, serif;
  --display: 'Instrument Serif', 'Iowan Old Style', Georgia, serif;
  --mono:    'IBM Plex Mono', 'Menlo', 'Consolas', monospace;

  --max:  1280px;
  --rail: 240px;
}

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }

body {
  background: var(--paper);
  color: var(--ink);
  font-family: var(--serif);
  font-size: 17px;
  line-height: 1.55;
  font-feature-settings: 'liga', 'onum', 'kern';
  min-height: 100vh;
  position: relative;
  overflow-x: hidden;
}

/* ---- paper grain ------------------------------------------- */
.grain {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 100;
  opacity: 0.55;
  mix-blend-mode: multiply;
  background-image: url("data:image/svg+xml;utf8,<svg viewBox='0 0 220 220' xmlns='http://www.w3.org/2000/svg'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.92' numOctaves='2' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 0.10 0 0 0 0 0.08 0 0 0 0 0.06 0 0 0 0.18 0'/></filter><rect width='100%25' height='100%25' filter='url(%23n)'/></svg>");
}

::selection { background: var(--accent); color: var(--paper); }

a { color: var(--link); }
a:hover { color: var(--link-hover); }

/* ====================================================
   MASTHEAD
   ==================================================== */
.masthead {
  border-bottom: 1px solid var(--rule);
  padding: 16px 36px;
  background: var(--paper);
  position: relative;
  z-index: 2;
}
.masthead__row {
  display: flex;
  align-items: baseline;
  gap: 28px;
  max-width: var(--max);
  margin: 0 auto;
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--ink-soft);
}
.masthead__mark {
  font-family: var(--display);
  font-style: italic;
  font-size: 16px;
  letter-spacing: 0;
  text-transform: none;
  color: var(--accent);
}
.masthead__title {
  flex: 1;
  font-family: var(--display);
  font-size: 19px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--ink);
  text-decoration: none;
}
.masthead__title:hover { color: var(--accent); }
.masthead__date { white-space: nowrap; }
.masthead__nav {
  display: flex;
  gap: 18px;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  font-size: 10px;
}
.masthead__nav a {
  color: var(--ink-soft);
  text-decoration: none;
  border-bottom: 1px solid transparent;
  padding-bottom: 1px;
}
.masthead__nav a:hover,
.masthead__nav a.is-current {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

/* ====================================================
   HOME PAGE
   ==================================================== */
.home {
  max-width: 980px;
  margin: 0 auto;
  padding: 92px 36px 60px;
  position: relative;
}
.home__eyebrow {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--ink-faint);
  margin: 0 0 32px;
  border-top: 1px solid var(--hair);
  padding-top: 14px;
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 14px;
}
.home__eyebrow span:nth-child(2) { color: var(--accent); }
.home__lede {
  font-family: var(--display);
  font-weight: 400;
  font-size: clamp(56px, 9vw, 116px);
  line-height: 0.94;
  letter-spacing: -0.025em;
  margin: 0 0 12px;
  color: var(--ink);
}
.home__lede em {
  font-style: italic;
  color: var(--accent);
}
.home__lede-suffix {
  display: block;
  font-family: var(--display);
  font-size: clamp(22px, 2.6vw, 30px);
  font-style: italic;
  color: var(--ink-soft);
  font-weight: 300;
  margin-top: 22px;
  letter-spacing: 0;
  line-height: 1.3;
  max-width: 720px;
}

/* big horizontal-rule searchbox */
.searchbox {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: end;
  gap: 14px;
  margin: 84px 0 22px;
  padding-bottom: 14px;
  border-bottom: 2px solid var(--ink);
  position: relative;
}
.searchbox::before {
  content: 'q ›';
  position: absolute;
  top: -22px;
  left: 0;
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--ink-faint);
}
.searchbox__prompt {
  font-family: var(--display);
  font-size: 38px;
  color: var(--accent);
  line-height: 1;
  user-select: none;
}
.searchbox__input {
  font-family: var(--display);
  font-size: clamp(26px, 3.6vw, 42px);
  font-style: italic;
  background: transparent;
  border: none;
  outline: none;
  width: 100%;
  color: var(--ink);
  caret-color: var(--accent);
  padding: 0;
}
.searchbox__input::placeholder {
  color: var(--ink-faint);
  opacity: 0.55;
}
.searchbox__submit {
  background: transparent;
  border: 1px solid var(--ink);
  padding: 8px 18px;
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  cursor: pointer;
  color: var(--ink);
  transition: all .18s ease;
  white-space: nowrap;
  font-weight: 500;
}
.searchbox__submit:hover {
  background: var(--ink);
  color: var(--paper);
}
.searchbox__submit kbd {
  font-family: var(--mono);
  font-size: 10px;
  margin-left: 6px;
  opacity: 0.6;
}

/* recent strip */
.recent {
  list-style: none;
  padding: 0;
  margin: 22px 0 0;
  display: flex;
  flex-wrap: wrap;
  gap: 8px 22px;
  font-family: var(--mono);
  font-size: 12px;
  color: var(--ink-faint);
  align-items: baseline;
}
.recent::before {
  content: 'recent ›';
  letter-spacing: 0.22em;
  text-transform: uppercase;
  font-size: 10px;
  color: var(--ink-faint);
}
.recent a {
  color: var(--ink-soft);
  text-decoration: none;
  border-bottom: 1px dotted var(--hair);
  padding-bottom: 2px;
  transition: all .18s ease;
}
.recent a:hover {
  color: var(--accent);
  border-bottom-color: var(--accent);
  border-bottom-style: solid;
}

/* --- side margin annotation (optional ornament) --- */
.home__sidenote {
  position: absolute;
  left: -180px;
  top: 92px;
  width: 160px;
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--ink-faint);
  text-align: right;
  line-height: 1.6;
  border-right: 1px solid var(--hair);
  padding-right: 14px;
}
.home__sidenote em {
  font-family: var(--display);
  font-style: italic;
  letter-spacing: 0;
  text-transform: none;
  color: var(--accent);
  font-size: 14px;
  display: block;
  margin-top: 2px;
}
@media (max-width: 1240px) { .home__sidenote { display: none; } }

/* ====================================================
   COLOPHON (footer)
   ==================================================== */
.colophon {
  max-width: var(--max);
  margin: 96px auto 0;
  padding: 24px 36px 48px;
  border-top: 1px solid var(--rule);
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 24px;
  font-family: var(--mono);
  font-size: 12px;
  color: var(--ink);
}
.colophon__col { display: flex; flex-direction: column; gap: 4px; }
.colophon__label {
  font-size: 10px;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--ink-faint);
}
@media (max-width: 720px) {
  .colophon { grid-template-columns: 1fr 1fr; }
}

/* ====================================================
   RESULTS PAGE
   ==================================================== */
.results-shell {
  max-width: var(--max);
  margin: 0 auto;
  padding: 32px 36px 96px;
  display: grid;
  grid-template-columns: var(--rail) 1fr;
  gap: 56px;
}
@media (max-width: 1000px) {
  .results-shell { grid-template-columns: 1fr; gap: 36px; }
}

/* --- aside / left rail --- */
.aside {
  font-family: var(--mono);
  font-size: 12px;
  border-top: 1px solid var(--rule);
  padding-top: 16px;
  align-self: start;
  position: sticky;
  top: 24px;
  color: var(--ink-soft);
}
.aside__h {
  font-size: 10px;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--ink-faint);
  font-weight: 500;
  margin: 22px 0 8px;
}
.aside__h:first-child { margin-top: 0; }
.aside__row {
  display: flex;
  justify-content: space-between;
  padding: 5px 0;
  border-bottom: 1px dotted var(--hair);
  gap: 8px;
}
.aside__row:last-of-type { border-bottom: none; }
.aside__row strong { color: var(--ink); font-weight: 500; }
.aside__list { list-style: none; padding: 0; margin: 0; }
.aside__list li {
  padding: 5px 0;
  border-bottom: 1px dotted var(--hair);
}
.aside__list li:last-child { border-bottom: none; }
.aside__list a {
  display: flex;
  justify-content: space-between;
  color: var(--ink-soft);
  text-decoration: none;
  transition: color .18s ease;
}
.aside__list a:hover { color: var(--accent); }
.aside__list a span { font-size: 11px; }

/* --- main --- */
.results-main { min-width: 0; }

.results-head {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: baseline;
  gap: 24px;
  border-bottom: 1px solid var(--rule);
  padding-bottom: 20px;
}
.results-head__query {
  font-family: var(--display);
  font-style: italic;
  font-size: clamp(40px, 6vw, 64px);
  font-weight: 400;
  line-height: 1;
  color: var(--ink);
  margin: 0;
  letter-spacing: -0.012em;
}
.results-head__query::before { content: '“'; color: var(--accent); margin-right: 4px; }
.results-head__query::after  { content: '”'; color: var(--accent); margin-left: 2px; }

.results-head__meta {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--ink-faint);
  text-align: right;
  white-space: nowrap;
  line-height: 1.6;
}
.results-head__meta strong { color: var(--ink); font-weight: 500; }
.results-head__meta .big {
  font-family: var(--display);
  font-size: 32px;
  font-style: italic;
  letter-spacing: 0;
  text-transform: none;
  color: var(--accent);
  display: block;
  line-height: 1;
}

.searchbar-inline {
  margin: 22px 0 32px;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: end;
  gap: 12px;
  border-bottom: 1px solid var(--rule);
  padding-bottom: 8px;
}
.searchbar-inline .searchbox__input { font-size: 24px; }
.searchbar-inline .searchbox__prompt { font-size: 24px; }
.searchbar-inline .searchbox__submit { padding: 6px 12px; }

/* --- result rows --- */
.results-list { list-style: none; padding: 0; margin: 0; }
.result {
  display: grid;
  grid-template-columns: 64px 1fr 110px;
  gap: 28px;
  padding: 28px 0;
  border-bottom: 1px solid var(--hair);
  position: relative;
  transition: background .25s ease;
}
.result:hover { background: rgba(255, 245, 220, 0.35); }

.result__rank {
  font-family: var(--display);
  font-style: italic;
  font-size: 56px;
  line-height: 0.9;
  color: var(--ink-faint);
  text-align: right;
  font-feature-settings: 'lnum';
}
.result.is-top .result__rank { color: var(--accent); }

.result__body { min-width: 0; }

.boost-row {
  display: flex;
  gap: 8px;
  margin-bottom: 10px;
  flex-wrap: wrap;
}
.boost {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: var(--mono);
  font-size: 9.5px;
  letter-spacing: 0.20em;
  text-transform: uppercase;
  padding: 3px 9px;
  border: 1px solid var(--accent);
  color: var(--accent);
  font-weight: 500;
  line-height: 1.4;
}
.boost--phrase {
  background: var(--accent);
  color: var(--paper);
  border-color: var(--accent);
}
.boost--title { border-style: dashed; }
.boost--corpus { border-color: var(--stamp); color: var(--stamp); }
.boost--high {
  border-color: var(--ink);
  color: var(--ink);
}

.result__title {
  font-family: var(--display);
  font-size: 30px;
  font-weight: 400;
  line-height: 1.1;
  margin: 0 0 6px;
  letter-spacing: -0.005em;
}
.result__title a {
  color: var(--ink);
  text-decoration: none;
  background-image: linear-gradient(currentColor, currentColor);
  background-repeat: no-repeat;
  background-size: 0% 1px;
  background-position: 0 100%;
  transition: background-size .35s ease, color .18s ease;
  padding-bottom: 1px;
}
.result__title a:hover {
  color: var(--accent);
  background-size: 100% 1px;
}
.result.has-title-boost .result__title a {
  text-decoration: underline;
  text-decoration-style: dotted;
  text-decoration-color: var(--accent);
  text-decoration-thickness: 1.5px;
  text-underline-offset: 6px;
  background-image: none;
}

.result__url {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--link);
  word-break: break-all;
  margin: 0 0 10px;
  letter-spacing: 0;
}

.result__meta {
  font-family: var(--mono);
  font-size: 10.5px;
  color: var(--ink-faint);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  margin: 0 0 12px;
  display: flex;
  flex-wrap: wrap;
  gap: 4px 14px;
  align-items: center;
}
.result__meta-item { display: inline-flex; align-items: center; }
.result__meta-item + .result__meta-item::before {
  content: '·';
  color: var(--hair);
  margin-right: 14px;
  font-size: 13px;
}

.result__keywords {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 12px 0 4px;
}
.kw {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.04em;
  border: 1px solid var(--hair);
  padding: 3px 9px;
  color: var(--ink-soft);
  background: transparent;
  transition: all .18s ease;
  display: inline-flex;
  gap: 6px;
  align-items: baseline;
  cursor: default;
}
.kw:hover { border-color: var(--ink); color: var(--ink); background: rgba(255,255,255,0.4); }
.kw__n {
  color: var(--accent);
  font-weight: 600;
  font-size: 10px;
  letter-spacing: 0;
}

.result__children {
  margin-top: 14px;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--ink-faint);
}
.result__children summary {
  cursor: pointer;
  list-style: none;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--ink-soft);
  user-select: none;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
.result__children summary::-webkit-details-marker { display: none; }
.result__children summary::before {
  content: '▸';
  display: inline-block;
  transition: transform .18s ease;
  font-size: 9px;
  color: var(--accent);
}
.result__children[open] summary::before { transform: rotate(90deg); }
.result__children summary:hover { color: var(--accent); }
.result__children ul {
  list-style: none;
  padding: 12px 0 0 16px;
  margin: 6px 0 0;
  border-left: 1px dotted var(--hair);
  margin-left: 4px;
}
.result__children li { padding: 3px 0; }
.result__children a {
  color: var(--link);
  text-decoration: none;
  font-size: 11px;
  letter-spacing: 0;
  text-transform: none;
  border-bottom: 1px dotted transparent;
  transition: all .15s ease;
}
.result__children a:hover {
  border-bottom-color: var(--accent);
  color: var(--accent);
}

.result__score { text-align: right; }
.score-num {
  font-family: var(--display);
  font-size: 36px;
  font-style: italic;
  color: var(--ink);
  line-height: 1;
  display: block;
  font-feature-settings: 'lnum';
}
.result.is-top .score-num { color: var(--accent); }
.score-label {
  font-family: var(--mono);
  font-size: 9px;
  letter-spacing: 0.24em;
  text-transform: uppercase;
  color: var(--ink-faint);
  display: block;
  margin-top: 6px;
}
.score-bar {
  height: 3px;
  background: var(--paper-deep);
  margin-top: 10px;
  position: relative;
  overflow: hidden;
}
.score-bar::after {
  content: '';
  position: absolute;
  inset: 0;
  background: var(--ink);
  width: var(--w, 0%);
}
.result.is-top .score-bar::after { background: var(--accent); }

/* phrase highlight in title */
.phrase-hl {
  background: var(--accent);
  color: var(--paper);
  padding: 0 5px;
  font-style: italic;
  margin: 0 1px;
  display: inline-block;
}

/* pagination */
.pagination {
  display: flex;
  gap: 14px;
  align-items: center;
  margin: 56px 0 0;
  padding-top: 24px;
  border-top: 1px solid var(--rule);
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--ink-faint);
}
.pagination a, .pagination span {
  text-decoration: none;
  color: var(--ink-soft);
  padding: 4px 10px;
  border: 1px solid transparent;
}
.pagination a:hover { color: var(--accent); border-color: var(--accent); }
.pagination .is-current {
  color: var(--paper);
  background: var(--ink);
  border-color: var(--ink);
}

/* ====================================================
   EMPTY / ERROR PAGES
   ==================================================== */
.notice-shell {
  max-width: 760px;
  margin: 0 auto;
  padding: 80px 36px 96px;
}
.notice__stamp {
  display: inline-block;
  border: 2px solid var(--accent);
  padding: 6px 14px;
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.28em;
  text-transform: uppercase;
  color: var(--accent);
  transform: rotate(-2deg);
  margin-bottom: 36px;
  font-weight: 600;
}
.notice__stamp--error {
  border-color: var(--accent-deep);
  color: var(--accent-deep);
  border-style: double;
  border-width: 4px;
}
.notice__h {
  font-family: var(--display);
  font-size: clamp(56px, 9vw, 96px);
  font-weight: 400;
  line-height: 0.95;
  margin: 0 0 22px;
  letter-spacing: -0.02em;
}
.notice__h em { font-style: italic; color: var(--accent); }
.notice__sub {
  font-family: var(--display);
  font-style: italic;
  font-size: clamp(20px, 2.4vw, 26px);
  color: var(--ink-soft);
  max-width: 600px;
  margin: 0 0 40px;
  line-height: 1.45;
  font-weight: 300;
}

.notice__list {
  list-style: none;
  padding: 18px 0;
  margin: 0 0 36px;
  border-top: 1px solid var(--rule);
  border-bottom: 1px solid var(--rule);
  font-family: var(--mono);
  font-size: 13px;
}
.notice__list li {
  display: grid;
  grid-template-columns: 36px 1fr;
  padding: 8px 0;
  color: var(--ink-soft);
  align-items: baseline;
}
.notice__list li::before {
  content: attr(data-n);
  font-family: var(--display);
  font-style: italic;
  color: var(--accent);
  font-size: 18px;
}
.notice__list li code {
  font-family: var(--mono);
  background: var(--paper-2);
  padding: 1px 6px;
  border: 1px solid var(--hair);
  font-size: 12px;
  color: var(--ink);
}

.notice__back {
  display: inline-block;
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--ink);
  border-bottom: 1px solid var(--ink);
  padding-bottom: 2px;
  text-decoration: none;
  transition: all .18s ease;
}
.notice__back:hover { color: var(--accent); border-color: var(--accent); }

.notice__suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 18px 0 30px;
}
.notice__suggestions a {
  font-family: var(--mono);
  font-size: 12px;
  padding: 6px 12px;
  border: 1px solid var(--hair);
  text-decoration: none;
  color: var(--ink-soft);
  transition: all .18s ease;
}
.notice__suggestions a:hover {
  border-color: var(--accent);
  color: var(--accent);
}

/* error trace block */
.error-card {
  background: var(--paper-2);
  border: 1px solid var(--rule);
  padding: 28px 32px;
  margin-top: 32px;
  position: relative;
}
.error-card::before {
  content: 'EXCEPTION';
  position: absolute;
  top: -10px;
  left: 22px;
  background: var(--paper);
  padding: 0 10px;
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.28em;
  color: var(--accent-deep);
  font-weight: 600;
}
.error-card__h {
  font-family: var(--display);
  font-style: italic;
  font-size: 22px;
  margin: 0 0 6px;
  color: var(--accent-deep);
}
.error-card__msg {
  font-family: var(--mono);
  font-size: 13px;
  color: var(--ink);
  margin: 0;
  line-height: 1.5;
}
.error-trace {
  font-family: var(--mono);
  font-size: 11px;
  background: var(--paper);
  padding: 14px 18px;
  border-left: 2px solid var(--accent);
  margin: 18px 0 0;
  color: var(--ink-soft);
  line-height: 1.85;
  white-space: pre-wrap;
  overflow-x: auto;
}
.error-trace .lh { color: var(--accent-deep); }
.error-trace .at { color: var(--ink-faint); }

/* ====================================================
   ADVANCED PAGE
   ==================================================== */
.advanced-shell {
  max-width: var(--max);
  margin: 0 auto;
  padding: 32px 36px 96px;
  display: grid;
  grid-template-columns: 230px 1fr 280px;
  gap: 48px;
}
@media (max-width: 1180px) {
  .advanced-shell { grid-template-columns: 230px 1fr; }
  .history-rail { display: none; }
}
@media (max-width: 760px) {
  .advanced-shell { grid-template-columns: 1fr; }
}

.advanced-head {
  grid-column: 1 / -1;
  border-bottom: 1px solid var(--rule);
  padding-bottom: 22px;
  margin-bottom: 8px;
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 18px;
}
.advanced-head h1 {
  font-family: var(--display);
  font-style: italic;
  font-size: clamp(36px, 5vw, 52px);
  font-weight: 400;
  margin: 0;
  letter-spacing: -0.012em;
}
.advanced-head h1 em { color: var(--accent); }
.advanced-head .meta {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--ink-faint);
}

.history-rail {
  font-family: var(--mono);
  font-size: 12px;
  border-top: 1px solid var(--rule);
  padding-top: 16px;
  align-self: start;
  position: sticky;
  top: 24px;
}
.history-rail h3 {
  font-size: 10px;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--ink-faint);
  margin: 0 0 14px;
  font-weight: 500;
}
.history-rail ol { list-style: none; padding: 0; margin: 0; }
.history-rail li {
  border-bottom: 1px dotted var(--hair);
  padding: 9px 0;
}
.history-rail li:last-child { border-bottom: none; }
.history-rail .h-row {
  display: grid;
  grid-template-columns: 22px 1fr;
  gap: 8px;
  align-items: baseline;
  text-decoration: none;
  color: inherit;
}
.history-rail .h-n {
  font-family: var(--display);
  font-style: italic;
  color: var(--accent);
  font-size: 14px;
  text-align: right;
}
.history-rail .h-q {
  color: var(--ink);
  font-size: 12px;
  letter-spacing: 0;
  text-transform: none;
}
.history-rail .h-time {
  color: var(--ink-faint);
  font-size: 9px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  margin-top: 2px;
}
.history-rail .h-row:hover .h-q { color: var(--accent); }

.advanced-main { min-width: 0; }

.section-h {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.28em;
  text-transform: uppercase;
  color: var(--ink-faint);
  margin: 36px 0 14px;
  padding-top: 14px;
  border-top: 1px solid var(--hair);
  font-weight: 500;
  display: flex;
  align-items: baseline;
  gap: 12px;
}
.section-h::before {
  content: '§';
  font-family: var(--display);
  font-style: italic;
  font-size: 18px;
  color: var(--accent);
  letter-spacing: 0;
}
.section-h:first-of-type { margin-top: 8px; padding-top: 0; border-top: none; }

/* phrase-window viz */
.phrase-window {
  font-family: var(--mono);
  font-size: 13.5px;
  background: var(--paper-2);
  border: 1px solid var(--hair);
  padding: 22px 24px 16px;
  line-height: 2;
  position: relative;
  overflow-x: auto;
  margin-bottom: 14px;
}
.phrase-window mark {
  background: transparent;
  color: var(--ink);
  font-weight: 500;
  position: relative;
  padding: 1px 4px;
}
.phrase-window mark.tok-A { background: var(--accent); color: var(--paper); }
.phrase-window mark.tok-B { background: var(--ink); color: var(--paper); }
.phrase-window mark.tok-A + sup,
.phrase-window mark.tok-B + sup { color: var(--accent); }
.phrase-window sup {
  font-size: 9px;
  color: var(--ink-faint);
  margin-left: 2px;
  letter-spacing: 0;
}
.phrase-window__legend {
  display: flex;
  gap: 18px;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px dotted var(--hair);
  font-size: 10px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--ink-faint);
}
.phrase-window__legend span::before {
  content: '';
  display: inline-block;
  width: 10px; height: 10px;
  margin-right: 6px;
  vertical-align: middle;
}
.phrase-window__legend .lA::before { background: var(--accent); }
.phrase-window__legend .lB::before { background: var(--ink); }

/* score breakdown */
.breakdown {
  margin: 0 0 10px;
  padding: 0;
  list-style: none;
  font-family: var(--mono);
  font-size: 12px;
}
.breakdown li {
  display: grid;
  grid-template-columns: 1fr 220px 80px;
  gap: 16px;
  padding: 9px 0;
  border-bottom: 1px dotted var(--hair);
  align-items: center;
}
@media (max-width: 720px) {
  .breakdown li { grid-template-columns: 1fr 80px; }
  .breakdown li .breakdown__bar { display: none; }
}
.breakdown__label {
  color: var(--ink-soft);
  letter-spacing: 0.06em;
}
.breakdown__label small {
  color: var(--ink-faint);
  font-size: 10px;
  display: block;
  margin-top: 2px;
}
.breakdown__bar {
  height: 6px;
  background: var(--paper-2);
  border: 1px solid var(--hair);
  position: relative;
}
.breakdown__fill {
  position: absolute;
  inset: 0;
  background: var(--ink);
  height: 100%;
  width: var(--w, 0%);
  transform-origin: left;
  animation: bar-fill .9s cubic-bezier(.4,.0,.2,1) both;
}
.breakdown__fill--accent { background: var(--accent); }
.breakdown__fill--soft { background: var(--ink-faint); }
.breakdown__val {
  font-family: var(--display);
  font-style: italic;
  color: var(--ink);
  font-size: 18px;
  text-align: right;
}
.breakdown__total {
  border-top: 2px solid var(--ink) !important;
  border-bottom: none !important;
  padding-top: 14px !important;
  margin-top: 6px;
}
.breakdown__total .breakdown__val { color: var(--accent); font-size: 26px; }
.breakdown__total .breakdown__label { color: var(--ink); font-weight: 500; }

@keyframes bar-fill {
  from { transform: scaleX(0); }
  to   { transform: scaleX(1); }
}

/* similar-pages rail */
.similar-rail {
  font-family: var(--mono);
  font-size: 12px;
  border-top: 1px solid var(--rule);
  padding-top: 16px;
  align-self: start;
  position: sticky;
  top: 24px;
}
.similar-rail h3 {
  font-size: 10px;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--ink-faint);
  margin: 0 0 16px;
  font-weight: 500;
}
.similar-card {
  border: 1px solid var(--hair);
  padding: 14px 14px 12px;
  margin-bottom: 10px;
  background: var(--paper);
  transition: all .2s ease;
  cursor: pointer;
}
.similar-card:hover {
  border-color: var(--accent);
  background: rgba(255,245,225,0.5);
}
.similar-card__sim {
  font-family: var(--mono);
  font-size: 9px;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 4px;
  font-weight: 500;
}
.similar-card__sim strong {
  font-family: var(--display);
  font-style: italic;
  font-size: 14px;
  letter-spacing: 0;
  color: var(--accent);
  font-weight: 400;
  margin-right: 4px;
}
.similar-card__t {
  font-family: var(--display);
  font-style: italic;
  font-size: 18px;
  margin: 0 0 6px;
  line-height: 1.15;
  font-weight: 400;
}
.similar-card__t a { color: var(--ink); text-decoration: none; }
.similar-card__t a:hover { color: var(--accent); }
.similar-card__url {
  font-size: 10px;
  color: var(--link);
  word-break: break-all;
  margin-top: 4px;
  letter-spacing: 0;
  text-transform: none;
}
.similar-card__overlap {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 8px;
}
.similar-card__overlap span {
  font-size: 10px;
  border: 1px solid var(--hair);
  padding: 1px 6px;
  color: var(--ink-soft);
}

/* detail head card */
.detail-card {
  border: 1px solid var(--rule);
  padding: 28px 32px;
  background: var(--paper-2);
  margin: 0 0 18px;
  position: relative;
}
.detail-card::before {
  content: '№ 8 / 297';
  position: absolute;
  top: -10px;
  right: 22px;
  background: var(--paper);
  padding: 0 10px;
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.22em;
  color: var(--ink-faint);
}
.detail-card__title {
  font-family: var(--display);
  font-style: italic;
  font-size: 38px;
  margin: 0 0 6px;
  font-weight: 400;
  line-height: 1.05;
}
.detail-card__url {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--link);
  margin: 0 0 12px;
  word-break: break-all;
}
.detail-card__meta {
  display: flex;
  flex-wrap: wrap;
  gap: 18px;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--ink-faint);
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

/* ====================================================
   SIMILAR-PAGES BANNER (above results)
   ==================================================== */
.results-banner {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 6px 12px;
  margin: 14px 0 -6px;
  padding: 10px 14px;
  background: var(--paper-2);
  border: 1px solid var(--hair);
  border-left: 3px solid var(--accent);
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.06em;
  color: var(--ink-soft);
}
.results-banner__label {
  text-transform: uppercase;
  letter-spacing: 0.22em;
  font-size: 10px;
  color: var(--accent);
  font-weight: 500;
}
.results-banner__url {
  color: var(--link);
  word-break: break-all;
  text-decoration: none;
  border-bottom: 1px dotted var(--hair);
}
.results-banner__url:hover {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

/* ====================================================
   KEYWORDS BROWSER (full page)
   ==================================================== */
.keywords-shell {
  max-width: var(--max);
  margin: 0 auto;
  padding: 32px 36px 96px;
}
.keywords-head {
  border-bottom: 1px solid var(--rule);
  padding-bottom: 20px;
  margin-bottom: 22px;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 18px;
}
.keywords-head h1 {
  font-family: var(--display);
  font-style: italic;
  font-size: clamp(36px, 5vw, 52px);
  font-weight: 400;
  margin: 0;
  letter-spacing: -0.012em;
}
.keywords-head h1 em { color: var(--accent); }
.keywords-head .meta {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--ink-faint);
}
.keywords-hint {
  font-family: var(--display);
  font-style: italic;
  font-size: 17px;
  color: var(--ink-soft);
  max-width: 720px;
  margin: 0 0 24px;
  line-height: 1.5;
}
.kw-controls {
  display: flex;
  gap: 12px;
  align-items: center;
  position: sticky;
  top: 0;
  background: var(--paper);
  padding: 14px 0;
  margin-bottom: 14px;
  border-bottom: 1px solid var(--hair);
  z-index: 5;
  font-family: var(--mono);
  font-size: 11px;
}
.kw-controls__count {
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--ink-faint);
}
.kw-controls__count strong { color: var(--accent); font-weight: 500; }
.kw-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 2px 12px;
}
.kw-cell {
  font-family: var(--mono);
  font-size: 11.5px;
  letter-spacing: 0.02em;
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 5px 8px;
  cursor: pointer;
  border-bottom: 1px dotted transparent;
  transition: all .12s ease;
  user-select: none;
}
.kw-cell:hover {
  background: rgba(255, 255, 255, 0.4);
  border-bottom-color: var(--hair);
}
.kw-cell input[type='checkbox'] {
  margin: 0;
  accent-color: var(--accent);
  cursor: pointer;
  flex-shrink: 0;
}
.kw-cell__stem { flex: 1; color: var(--ink); }
.kw-cell__df { color: var(--ink-faint); font-size: 10px; }
.kw-cell:has(input:checked) {
  background: rgba(168, 51, 31, 0.07);
  border-bottom-color: var(--accent);
}
.kw-cell:has(input:checked) .kw-cell__stem {
  color: var(--accent);
  font-weight: 500;
}
.kw-cell:has(input:checked) .kw-cell__df {
  color: var(--accent);
}

/* ====================================================
   HISTORY (full page)
   ==================================================== */
.history-shell {
  max-width: 760px;
  margin: 0 auto;
  padding: 60px 36px 96px;
}
.history-page-h {
  font-family: var(--display);
  font-style: italic;
  font-size: clamp(48px, 7vw, 72px);
  font-weight: 400;
  margin: 0 0 16px;
  letter-spacing: -0.018em;
  line-height: 1;
}
.history-page-h em { color: var(--accent); }
.history-page-sub {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--ink-faint);
  margin: 0 0 32px;
  border-top: 1px solid var(--hair);
  padding-top: 14px;
}
.history-page-list {
  list-style: none;
  padding: 0;
  margin: 0;
  border-top: 1px solid var(--rule);
}
.history-page-list li {
  border-bottom: 1px solid var(--hair);
  padding: 14px 0;
  display: grid;
  grid-template-columns: 38px 1fr auto;
  gap: 18px;
  align-items: baseline;
  transition: background .15s;
}
.history-page-list li:hover {
  background: rgba(255, 255, 255, 0.3);
}
.history-page-list .hp-n {
  font-family: var(--display);
  font-style: italic;
  color: var(--accent);
  font-size: 22px;
  text-align: right;
  line-height: 1;
}
.history-page-list .hp-q {
  font-family: var(--display);
  font-size: 22px;
  color: var(--ink);
  line-height: 1.15;
  letter-spacing: -0.01em;
}
.history-page-list .hp-q a {
  color: inherit;
  text-decoration: none;
  background-image: linear-gradient(currentColor, currentColor);
  background-repeat: no-repeat;
  background-size: 0% 1px;
  background-position: 0 100%;
  transition: background-size .3s ease, color .15s ease;
  padding-bottom: 1px;
}
.history-page-list .hp-q a:hover {
  color: var(--accent);
  background-size: 100% 1px;
}
.history-page-list .hp-time {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--ink-faint);
  white-space: nowrap;
}
.history-actions {
  margin-top: 36px;
  display: flex;
  gap: 14px;
  align-items: center;
}
.history-actions a {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--ink);
  border-bottom: 1px solid var(--ink);
  padding-bottom: 2px;
  text-decoration: none;
  transition: all .18s ease;
}
.history-actions a.danger { color: var(--accent-deep); border-color: var(--accent-deep); }
.history-actions a:hover { color: var(--accent); border-color: var(--accent); }
.history-empty {
  font-family: var(--display);
  font-style: italic;
  font-size: 22px;
  color: var(--ink-soft);
  padding: 36px 0;
  border-top: 1px solid var(--hair);
  border-bottom: 1px solid var(--hair);
  text-align: center;
}

/* ============== ANIMATIONS ============== */
@keyframes rise {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}
.home__eyebrow { animation: rise .55s ease both; animation-delay: 0.00s; }
.home__lede    { animation: rise .65s ease both; animation-delay: 0.10s; }
.searchbox     { animation: rise .55s ease both; animation-delay: 0.30s; }
.recent        { animation: rise .55s ease both; animation-delay: 0.45s; }
.colophon      { animation: rise .55s ease both; animation-delay: 0.55s; }

.result { animation: rise .5s ease both; }
.result:nth-child(1)  { animation-delay: 0.04s; }
.result:nth-child(2)  { animation-delay: 0.08s; }
.result:nth-child(3)  { animation-delay: 0.12s; }
.result:nth-child(4)  { animation-delay: 0.16s; }
.result:nth-child(5)  { animation-delay: 0.20s; }
.result:nth-child(6)  { animation-delay: 0.24s; }
.result:nth-child(7)  { animation-delay: 0.28s; }
.result:nth-child(8)  { animation-delay: 0.32s; }
.result:nth-child(9)  { animation-delay: 0.36s; }
.result:nth-child(10) { animation-delay: 0.40s; }
.result:nth-child(11) { animation-delay: 0.44s; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* ====================================================
   PER-QUERY-STEM CONTRIBUTION TABLE (anatomy page)
   ==================================================== */
.per-stem-list {
  list-style: none;
  padding: 0;
  margin: 0 0 14px;
  font-family: var(--mono);
  font-size: 12px;
  border-top: 1px solid var(--hair);
}
.per-stem-list li {
  display: grid;
  grid-template-columns: 110px 150px 1fr 1fr 110px;
  gap: 14px;
  padding: 8px 0;
  border-bottom: 1px dotted var(--hair);
  align-items: baseline;
}
.psl-stem {
  color: var(--ink);
  letter-spacing: 0.04em;
  font-weight: 500;
}
.psl-stem--missing { color: var(--accent-deep); }
.psl-meta {
  color: var(--ink-faint);
  font-size: 10px;
  letter-spacing: 0.06em;
}
.psl-tf { color: var(--ink-faint); font-size: 11px; }
.psl-tf strong {
  color: var(--ink-faint);
  font-weight: 500;
  margin-left: 2px;
}
.psl-tf.is-on { color: var(--ink); }
.psl-tf.is-on strong { color: var(--ink); font-weight: 600; }
.psl-tf.is-title { color: var(--accent); }
.psl-tf.is-title strong { color: var(--accent); font-weight: 600; }
.psl-idf {
  color: var(--ink-soft);
  text-align: right;
  font-size: 11px;
}

/* ====================================================
   MOBILE / TABLET RESPONSIVE
   tightened in this order: 900 → 720 → 560 → 420
   ==================================================== */

@media (max-width: 900px) {
  /* aside collapses; keep order so it appears above results */
  .results-shell {
    grid-template-columns: 1fr;
    gap: 28px;
    padding: 24px 22px 64px;
  }
  .aside {
    position: static;
    border-bottom: 1px solid var(--rule);
    padding-bottom: 16px;
  }
  .aside__h:first-child { margin-top: 6px; }

  .keywords-shell { padding: 24px 22px 64px; }
  .advanced-shell { padding: 24px 22px 64px; gap: 32px; }
  .home          { padding: 64px 22px 48px; }
  .notice-shell  { padding: 56px 22px 64px; }
  .history-shell { padding: 48px 22px 72px; }
}

@media (max-width: 720px) {
  /* masthead: stop trying to fit everything on one line */
  .masthead { padding: 12px 18px; }
  .masthead__row {
    flex-wrap: wrap;
    gap: 6px 14px;
    font-size: 10px;
  }
  .masthead__title { font-size: 16px; flex-basis: auto; flex-grow: 0; }
  .masthead__nav {
    order: 99;
    flex-basis: 100%;
    gap: 12px;
    padding-top: 4px;
    border-top: 1px dotted var(--hair);
  }
  .masthead__date { display: none; }

  /* result cards: stack score below body, drop the 3-col grid */
  .result {
    grid-template-columns: 44px 1fr;
    grid-template-rows: auto auto;
    gap: 8px 14px;
    padding: 22px 0;
  }
  .result__rank {
    font-size: 38px;
    grid-row: 1;
    grid-column: 1;
  }
  .result__body {
    grid-row: 1;
    grid-column: 2;
  }
  .result__score {
    grid-row: 2;
    grid-column: 1 / -1;
    text-align: left;
    padding-top: 8px;
    border-top: 1px dotted var(--hair);
    display: flex;
    align-items: baseline;
    gap: 12px;
  }
  .score-num { font-size: 26px; }
  .score-label { margin-top: 0; }
  .score-bar { flex: 1; margin-top: 0; }

  .result__title { font-size: 24px; }
  .result__rank { line-height: 1.1; }

  /* keywords browser: looser controls */
  .kw-controls {
    flex-wrap: wrap;
    gap: 8px 12px;
    padding: 10px 0;
  }
  .kw-controls__count { width: 100%; order: 99; }
  .kw-grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }

  /* anatomy page: tighten cards & drop bars */
  .detail-card { padding: 22px 18px; }
  .detail-card::before { right: 14px; }
  .detail-card__title { font-size: 28px; }
  .breakdown li {
    grid-template-columns: 1fr auto;
    gap: 8px 14px;
    padding: 8px 0;
  }
  .breakdown__bar { display: none; }
  .per-stem-list li {
    grid-template-columns: 110px 1fr;
    gap: 4px 14px;
    padding: 10px 0;
  }
  .per-stem-list .psl-meta,
  .per-stem-list .psl-tf,
  .per-stem-list .psl-idf {
    grid-column: 2;
    text-align: left;
  }

  /* history full page: smaller numerals, looser rows */
  .history-page-list li {
    grid-template-columns: 30px 1fr;
    gap: 4px 14px;
    padding: 12px 0;
  }
  .history-page-list .hp-time {
    grid-column: 2;
    margin-top: 2px;
  }

  /* notice page tweaks */
  .notice__list li { grid-template-columns: 30px 1fr; }
  .notice__suggestions { gap: 6px; }
}

@media (max-width: 560px) {
  body { font-size: 16px; }

  /* further padding tighten */
  .home          { padding: 48px 18px 36px; }
  .results-shell { padding: 18px 18px 56px; gap: 22px; }
  .keywords-shell{ padding: 18px 18px 56px; }
  .advanced-shell{ padding: 18px 18px 56px; gap: 22px; }
  .notice-shell  { padding: 48px 18px 56px; }
  .history-shell { padding: 40px 18px 64px; }

  /* masthead: smaller mark + nav scrolls horizontally if needed */
  .masthead { padding: 10px 16px; }
  .masthead__mark { font-size: 12px; }
  .masthead__title { font-size: 15px; letter-spacing: 0.02em; }
  .masthead__nav {
    overflow-x: auto;
    flex-wrap: nowrap;
    padding-bottom: 4px;
  }
  .masthead__nav a { white-space: nowrap; }

  /* home lede: scale back further */
  .home__lede {
    font-size: clamp(40px, 11vw, 56px);
    letter-spacing: -0.02em;
    line-height: 0.96;
  }
  .home__lede-suffix { font-size: clamp(16px, 4vw, 20px); margin-top: 16px; }
  .home__eyebrow {
    font-size: 10px;
    flex-direction: column;
    gap: 4px;
    align-items: flex-start;
  }

  /* searchbox: shrink prompt + button */
  .searchbox { gap: 10px; margin: 56px 0 18px; }
  .searchbox__prompt { font-size: 26px; }
  .searchbox__input { font-size: 22px; }
  .searchbox__submit { padding: 6px 12px; font-size: 10px; }
  .searchbox__submit kbd { display: none; }

  .searchbar-inline { padding-bottom: 6px; }
  .searchbar-inline .searchbox__input { font-size: 18px; }
  .searchbar-inline .searchbox__prompt { font-size: 18px; }

  /* results-head: query echo doesn't need to be huge */
  .results-head { padding-bottom: 14px; gap: 8px; }
  .results-head__query { font-size: clamp(28px, 7vw, 40px); }
  .results-head__meta { font-size: 10px; }
  .results-head__meta .big { font-size: 22px; }

  .result__title { font-size: 20px; }
  .result__url { font-size: 11px; }
  .result__keywords { gap: 4px; }
  .kw { font-size: 10px; padding: 2px 6px; }

  /* anatomy: tighter still */
  .advanced-head h1 { font-size: clamp(26px, 7vw, 36px); }
  .detail-card { padding: 18px 16px; }
  .detail-card__title { font-size: 22px; }
  .detail-card__meta { gap: 10px; font-size: 10px; }

  .similar-card__t { font-size: 16px; }
  .history-page-h { font-size: clamp(36px, 9vw, 52px); }
  .history-page-list .hp-q { font-size: 18px; }
  .history-page-list .hp-n { font-size: 18px; }
  .history-page-list li { padding: 10px 0; }

  .notice__h { font-size: clamp(36px, 9vw, 56px); }
  .notice__sub { font-size: 16px; }
  .notice__stamp { font-size: 9px; padding: 4px 10px; }

  .colophon {
    grid-template-columns: 1fr 1fr;
    padding: 18px 18px 36px;
    gap: 16px;
  }

  /* per-stem stack: stem on its own line */
  .per-stem-list li {
    grid-template-columns: 1fr;
    gap: 2px;
    padding: 10px 0;
  }
  .per-stem-list .psl-stem { font-size: 14px; }
  .per-stem-list .psl-meta,
  .per-stem-list .psl-tf,
  .per-stem-list .psl-idf {
    grid-column: 1;
  }
}

@media (max-width: 420px) {
  /* tiniest devices: pull a few last things in */
  .home__lede { font-size: clamp(34px, 13vw, 46px); }
  .results-head__query { font-size: clamp(24px, 9vw, 34px); }
  .result__rank { font-size: 30px; }
  .score-num { font-size: 22px; }
  .home__sidenote { display: none !important; }
}
