:root {
  --bg: #faf7f0;
  --bg-card: #ffffff;
  --bg-sunken: #f3eee2;
  --ink: #231d14;
  --ink-soft: #6b6052;
  --ink-faint: #9c917f;
  --line: #e8e0d0;
  --accent: #b8430f;
  --accent-soft: #fbe9df;
  --gold: #a06b00;
  --gold-bg: #fdf3d8;
  --gold-line: #ecd9a4;
  --sage: #5d6e45;
  --sage-bg: #eef0e4;
  --danger: #a32014;
  --danger-bg: #fbe9e7;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(60, 42, 20, .06), 0 8px 24px -12px rgba(60, 42, 20, .18);
  --font-display: "Fraunces", "Iowan Old Style", Georgia, serif;
  --font-ui: "Inter", -apple-system, "Segoe UI", sans-serif;
  --topbar-h: 60px;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 15px;
  line-height: 1.55;
}
a { color: inherit; }
button { font: inherit; cursor: pointer; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 50;
  display: flex; align-items: center; gap: 18px;
  height: var(--topbar-h);
  padding: 0 20px;
  background: rgba(250, 247, 240, .92);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.menu-btn {
  display: none;
  background: none; border: 1px solid var(--line); border-radius: 8px;
  padding: 4px 10px; font-size: 16px; color: var(--ink-soft);
}
.brand {
  display: flex; align-items: center; gap: 8px;
  text-decoration: none; white-space: nowrap;
}
.brand-mark { font-size: 20px; }
.brand-text {
  font-family: var(--font-display);
  font-weight: 600; font-size: 19px; letter-spacing: -.01em;
}
.brand-text em { font-style: italic; font-weight: 400; color: var(--accent); }

.searchwrap { position: relative; flex: 1; max-width: 480px; }
#search {
  width: 100%;
  padding: 9px 14px 9px 38px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--bg-card) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='15' height='15' viewBox='0 0 24 24' fill='none' stroke='%239c917f' stroke-width='2.4'%3E%3Ccircle cx='11' cy='11' r='7'/%3E%3Cpath d='m20 20-3.5-3.5'/%3E%3C/svg%3E") 14px 50% no-repeat;
  font: inherit; color: var(--ink);
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
#search:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

.search-results {
  position: absolute; top: calc(100% + 8px); left: 0; right: 0;
  max-height: 420px; overflow-y: auto;
  background: var(--bg-card);
  border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 6px;
}
.search-results a {
  display: flex; align-items: baseline; gap: 8px;
  padding: 8px 12px; border-radius: 8px;
  text-decoration: none; font-size: 14px;
}
.search-results a .hint { color: var(--ink-faint); font-size: 12px; }
.search-results a:hover, .search-results a.active { background: var(--bg-sunken); }
.search-results .noresults { padding: 10px 12px; color: var(--ink-faint); font-size: 13.5px; }

.topnav { display: flex; gap: 4px; margin-left: auto; }
.topnav a {
  padding: 7px 14px; border-radius: 999px;
  text-decoration: none; font-weight: 500; font-size: 14px;
  color: var(--ink-soft);
  transition: background .15s, color .15s;
}
.topnav a:hover { background: var(--bg-sunken); color: var(--ink); }
.topnav a.on { background: var(--ink); color: var(--bg); }

/* ---------- layout ---------- */
.layout { display: flex; min-height: calc(100vh - var(--topbar-h)); }

.sidebar {
  width: 290px; flex-shrink: 0;
  position: sticky; top: var(--topbar-h);
  height: calc(100vh - var(--topbar-h));
  display: flex; flex-direction: column;
  border-right: 1px solid var(--line);
  background: var(--bg);
}
.sidebar-head {
  padding: 14px 18px 10px;
  border-bottom: 1px solid var(--line);
}
#ingCount {
  font-size: 11.5px; font-weight: 600; letter-spacing: .08em;
  text-transform: uppercase; color: var(--ink-faint);
}
.letters { display: flex; flex-wrap: wrap; gap: 1px; margin-top: 8px; }
.letters button {
  border: none; background: none;
  width: 21px; height: 22px; border-radius: 6px;
  font-size: 11.5px; font-weight: 600; color: var(--ink-soft);
}
.letters button:hover { background: var(--accent-soft); color: var(--accent); }

.inglist { overflow-y: auto; flex: 1; padding: 8px 10px 40px; }
.inglist h3 {
  font-family: var(--font-display);
  font-size: 15px; color: var(--accent);
  margin: 18px 8px 4px; padding-bottom: 3px;
  border-bottom: 1px solid var(--line);
}
.inglist a {
  display: block; padding: 4.5px 9px; border-radius: 7px;
  text-decoration: none; font-size: 13.8px; color: var(--ink-soft);
}
.inglist a:hover { background: var(--bg-sunken); color: var(--ink); }
.inglist a.on { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.inglist a.alias { color: var(--ink-faint); font-style: italic; }

.main { flex: 1; min-width: 0; padding: 34px clamp(20px, 5vw, 64px) 90px; }
.scrim { display: none; }

/* ---------- home ---------- */
.hero { max-width: 760px; margin: 6vh auto 0; text-align: center; }
.hero h1 {
  font-family: var(--font-display);
  font-size: clamp(34px, 5.5vw, 54px);
  line-height: 1.08; font-weight: 600; letter-spacing: -.015em;
  margin: 0 0 14px;
}
.hero h1 em { font-style: italic; color: var(--accent); }
.hero p.lede { font-size: 17px; color: var(--ink-soft); max-width: 540px; margin: 0 auto; }
.hero .stats {
  display: flex; gap: 34px; justify-content: center; margin: 30px 0 8px;
}
.hero .stat b {
  display: block; font-family: var(--font-display);
  font-size: 28px; font-weight: 600; color: var(--ink);
}
.hero .stat span { font-size: 12.5px; color: var(--ink-faint); letter-spacing: .04em; text-transform: uppercase; }
.hero .cta { margin-top: 26px; display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; }
.btn {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 11px 22px; border-radius: 999px; border: none;
  background: var(--ink); color: var(--bg);
  font-weight: 600; font-size: 14.5px; text-decoration: none;
  transition: transform .12s, box-shadow .12s;
}
.btn:hover { transform: translateY(-1px); box-shadow: var(--shadow); }
.btn.ghost { background: transparent; color: var(--ink); border: 1.5px solid var(--ink); }
.btn.accent { background: var(--accent); }

.shelf { max-width: 900px; margin: 7vh auto 0; }
.shelf h2 {
  font-family: var(--font-display); font-size: 21px; font-weight: 600;
  margin: 0 0 14px; text-align: center;
}
.cardgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 14px; }
.ingcard {
  background: var(--bg-card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 16px 18px;
  text-decoration: none; box-shadow: 0 1px 2px rgba(60,42,20,.04);
  transition: transform .14s, box-shadow .14s, border-color .14s;
}
.ingcard:hover { transform: translateY(-2px); box-shadow: var(--shadow); border-color: #d8cdb6; }
.ingcard b { font-family: var(--font-display); font-size: 16.5px; font-weight: 600; display: block; }
.ingcard span { font-size: 12.5px; color: var(--ink-faint); }

.legend-box {
  max-width: 640px; margin: 7vh auto 0;
  background: var(--bg-card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 22px 26px;
}
.legend-box h2 { font-family: var(--font-display); font-size: 19px; margin: 0 0 4px; }
.legend-box p { color: var(--ink-soft); font-size: 13.5px; margin: 0 0 14px; }
.legend-row { display: flex; align-items: center; gap: 12px; margin: 9px 0; font-size: 13.5px; color: var(--ink-soft); }

/* ---------- ingredient view ---------- */
.crumb { font-size: 12.5px; color: var(--ink-faint); margin-bottom: 8px; }
.crumb a { color: var(--ink-faint); }
.ing-head h1 {
  font-family: var(--font-display);
  font-size: clamp(30px, 4.5vw, 44px); font-weight: 600;
  letter-spacing: -.01em; line-height: 1.06; margin: 0;
}
.ing-head .desc { font-size: 15.5px; color: var(--ink-soft); font-style: italic; margin-top: 6px; }
.seealso { margin-top: 8px; font-size: 13.5px; color: var(--ink-soft); }
.seealso a { color: var(--accent); font-weight: 500; }

.metachips { display: flex; flex-wrap: wrap; gap: 8px; margin: 18px 0 4px; }
.metachip {
  display: inline-flex; align-items: baseline; gap: 6px;
  background: var(--bg-card); border: 1px solid var(--line);
  border-radius: 999px; padding: 5px 13px; font-size: 13px;
}
.metachip b { font-size: 10.5px; letter-spacing: .07em; text-transform: uppercase; color: var(--ink-faint); font-weight: 600; }

.tipbox {
  margin: 16px 0 0; padding: 13px 17px;
  background: var(--sage-bg); border-left: 3px solid var(--sage);
  border-radius: 0 10px 10px 0;
  font-size: 14px; color: #3e4a2e;
}
.tipbox b { text-transform: uppercase; font-size: 10.5px; letter-spacing: .07em; }

.pair-actions { margin: 22px 0 0; display: flex; gap: 10px; flex-wrap: wrap; }
.pair-actions .btn { padding: 8px 16px; font-size: 13.5px; }

section.level { margin-top: 30px; }
.level-head { display: flex; align-items: baseline; gap: 10px; margin-bottom: 12px; }
.level-head h2 {
  font-family: var(--font-display); font-weight: 600;
  font-size: 19px; margin: 0;
}
.level-head .sub { font-size: 12.5px; color: var(--ink-faint); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }

.chip {
  display: inline-block; max-width: 100%;
  padding: 6px 14px; border-radius: 999px;
  font-size: 13.5px; line-height: 1.4;
  text-decoration: none;
  border: 1px solid var(--line);
  background: var(--bg-card); color: var(--ink-soft);
  transition: transform .1s, box-shadow .1s, border-color .1s;
}
a.chip:hover { transform: translateY(-1px); box-shadow: var(--shadow); }
span.chip { cursor: default; }
.chip .q { color: var(--ink-faint); font-size: 12.5px; }

.chip.l2 { background: #fff; border-color: #ddcdb4; color: var(--ink); font-weight: 600; }
.chip.l3 { background: var(--accent-soft); border-color: #eec4ab; color: var(--accent); font-weight: 700; }
.chip.l3 .q { color: #c98f6e; }
.chip.l4 {
  background: linear-gradient(135deg, #fdf3d8, #fbe9b8);
  border-color: var(--gold-line); color: var(--gold); font-weight: 700;
}
.chip.l4::before { content: "★ "; }
.chip.l4 .q { color: #bd9b4e; }
a.chip.l3:hover { border-color: var(--accent); }
a.chip.l4:hover { border-color: var(--gold); }
.chip.avoid { background: var(--danger-bg); border-color: #ecbcb6; color: var(--danger); }
.chip.dead { border-style: dashed; }

.avoid-head h2 { color: var(--danger); }

.affin { margin-top: 30px; }
.affin-row {
  display: flex; flex-wrap: wrap; align-items: center; gap: 7px;
  padding: 9px 0; border-bottom: 1px dashed var(--line);
  font-size: 13.5px;
}
.affin-row .plus { color: var(--ink-faint); font-weight: 600; }
.affin-row a { color: var(--ink); text-decoration: none; border-bottom: 1px solid #d8cdb6; }
.affin-row a:hover { color: var(--accent); border-color: var(--accent); }
.affin-row .self { font-weight: 700; color: var(--accent); border: none; }

.backlinks { margin-top: 34px; }
.backlinks p.sub { font-size: 13px; color: var(--ink-faint); margin: -6px 0 12px; }

.note { margin-top: 14px; font-size: 13.5px; color: var(--ink-soft); font-style: italic; }

/* ---------- match view ---------- */
.match-head { max-width: 780px; }
.match-head h1 { font-family: var(--font-display); font-size: clamp(26px, 4vw, 38px); font-weight: 600; margin: 0 0 8px; }
.match-head p { color: var(--ink-soft); margin: 0 0 18px; max-width: 560px; }
.match-picker { position: relative; max-width: 560px; }
#matchInput {
  width: 100%; padding: 12px 18px;
  border: 1.5px solid var(--line); border-radius: var(--radius);
  font: inherit; outline: none; background: var(--bg-card);
}
#matchInput:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.match-sel { display: flex; flex-wrap: wrap; gap: 8px; margin: 14px 0 6px; }
.selchip {
  display: inline-flex; align-items: center; gap: 8px;
  background: var(--ink); color: var(--bg);
  border-radius: 999px; padding: 7px 9px 7px 16px;
  font-weight: 600; font-size: 14px;
}
.selchip button {
  background: rgba(255,255,255,.18); border: none; color: inherit;
  border-radius: 50%; width: 20px; height: 20px; line-height: 1;
  font-size: 12px; display: grid; place-items: center;
}
.selchip button:hover { background: rgba(255,255,255,.35); }

.match-results { margin-top: 26px; }
.match-results .group { margin-top: 24px; }
.match-results h2 { font-family: var(--font-display); font-size: 19px; font-weight: 600; margin: 0 0 4px; }
.match-results .sub { font-size: 13px; color: var(--ink-faint); margin: 0 0 12px; }
.match-empty {
  margin-top: 30px; padding: 26px; text-align: center;
  border: 1.5px dashed var(--line); border-radius: var(--radius);
  color: var(--ink-faint);
}
.mrow {
  display: flex; align-items: center; gap: 12px;
  padding: 8px 10px; border-radius: 10px;
}
.mrow:hover { background: var(--bg-sunken); }
.mrow .who { margin-left: auto; display: flex; gap: 5px; flex-shrink: 0; }
.mrow .who span {
  font-size: 10.5px; font-weight: 700; letter-spacing: .03em;
  padding: 2.5px 8px; border-radius: 999px;
  background: var(--bg-sunken); color: var(--ink-faint);
  border: 1px solid var(--line);
}
.mrow .who span.l2 { color: var(--ink); border-color: #ddcdb4; background: #fff; }
.mrow .who span.l3 { color: var(--accent); background: var(--accent-soft); border-color: #eec4ab; }
.mrow .who span.l4 { color: var(--gold); background: var(--gold-bg); border-color: var(--gold-line); }

/* ---------- footer note ---------- */
.colophon {
  margin-top: 70px; padding-top: 18px; border-top: 1px solid var(--line);
  font-size: 12.5px; color: var(--ink-faint); max-width: 640px;
}

/* ---------- responsive ---------- */
@media (max-width: 900px) {
  .topbar { gap: 10px; padding: 0 14px; }
  .menu-btn { display: block; }
  .brand-text { display: none; }
  .topnav a { padding: 7px 10px; font-size: 13px; }
  .sidebar {
    position: fixed; left: 0; top: var(--topbar-h); bottom: 0; z-index: 40;
    transform: translateX(-100%);
    transition: transform .22s ease;
    box-shadow: none; background: var(--bg); width: 300px;
  }
  body.nav-open .sidebar { transform: none; box-shadow: var(--shadow); }
  body.nav-open .scrim {
    display: block; position: fixed; inset: var(--topbar-h) 0 0 0;
    background: rgba(35, 29, 20, .35); z-index: 30;
  }
  .main { padding: 24px 18px 80px; }
  .hero .stats { gap: 22px; }
}
