:root {
  --paper: #fbf8f3;
  --paper-raised: #ffffff;
  --paper-deep: #f4ebdf;
  --ink: #241b19;
  --ink-soft: #5f4d46;
  --ink-faint: #7f6b61;
  --line: #e8dacf;
  --line-strong: #d1b7a4;
  --accent: #9a1b2a;
  --accent-deep: #5f101c;
  --accent-wash: #f8e9e6;
  --gold: #96701c;
  --gold-wash: #f8efd8;
  --ok: #2b6a43;
  --ok-wash: #e8f2e9;
  --red: #b3261e;
  --red-wash: #fbe9e6;
  --disc-civil: #7b5a3a;
  --disc-mechanical: #a32232;
  --disc-electrical: #96701c;
  --disc-computer: #6a3145;
  --font-display: "Space Grotesk", "Segoe UI", sans-serif;
  --font-body: "Inter", "Segoe UI", sans-serif;
  --font-mono: "IBM Plex Mono", "Cascadia Mono", monospace;
  --topbar-h: 76px;
  --shadow-hard: 4px 4px 0 rgba(36, 27, 25, 0.07);
  --shadow-lift: 8px 8px 0 rgba(36, 27, 25, 0.09);
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.55;
  background-color: var(--paper);
  background-image:
    linear-gradient(rgba(154, 27, 42, 0.045) 1px, transparent 1px),
    linear-gradient(90deg, rgba(154, 27, 42, 0.045) 1px, transparent 1px);
  background-size: 24px 24px;
  -webkit-font-smoothing: antialiased;
}

body.drawer-open { overflow: hidden; }

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

::selection { background: var(--red); color: #fff; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.app-shell { min-height: 100vh; }

/* ---------- Top bar ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  gap: 28px;
  height: var(--topbar-h);
  padding: 0 clamp(20px, 3.2vw, 46px);
  border-bottom: 1px solid var(--line-strong);
  background: rgba(251, 248, 243, 0.93);
  backdrop-filter: blur(10px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 11px;
  text-decoration: none;
  flex-shrink: 0;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border: 1px solid var(--ink);
  background: var(--accent-deep);
  color: var(--paper-raised);
  font-family: var(--font-display);
  font-size: 23px;
  line-height: 1;
  box-shadow: 3px 3px 0 rgba(36, 27, 25, 0.14);
}

.brand-text { display: flex; flex-direction: column; line-height: 1.1; }
.brand-text strong {
  font-family: var(--font-display);
  font-size: 20px;
  letter-spacing: -0.02em;
}
.brand-text small {
  margin-top: 3px;
  color: var(--ink-faint);
  font-family: var(--font-mono);
  font-size: 10.5px;
  letter-spacing: 0.11em;
  text-transform: uppercase;
}

.search-wrap {
  position: relative;
  display: flex;
  align-items: center;
  width: min(380px, 100%);
  margin-left: 6px;
}

.search-icon {
  position: absolute;
  left: 12px;
  width: 17px;
  height: 17px;
  color: var(--ink-faint);
  pointer-events: none;
}

.search-wrap input {
  width: 100%;
  height: 42px;
  padding: 0 42px 0 38px;
  border: 1px solid var(--line-strong);
  border-radius: 2px;
  background: var(--paper-raised);
  font-size: 13.5px;
  -webkit-appearance: none;
  appearance: none;
}
.search-wrap input::placeholder { color: var(--ink-faint); }
.search-wrap input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(154, 27, 42, 0.12);
}
.search-wrap input::-webkit-search-cancel-button { -webkit-appearance: none; }

.search-kbd {
  position: absolute;
  right: 10px;
  display: grid;
  place-items: center;
  width: 21px;
  height: 21px;
  border: 1px solid var(--line);
  border-radius: 2px;
  background: var(--paper);
  color: var(--ink-faint);
  font-family: var(--font-mono);
  font-size: 11px;
  pointer-events: none;
}

.phase-nav {
  display: flex;
  align-items: center;
  gap: 20px;
  margin-left: auto;
  white-space: nowrap;
}

.phase-link {
  position: relative;
  font-size: 12.5px;
  font-weight: 500;
  color: var(--ink-faint);
}
.phase-link.is-active { color: var(--ink); }
.phase-link.is-active::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: -29px;
  height: 2px;
  background: var(--gold);
}
.phase-link.is-future { cursor: default; }
.phase-link em {
  margin-left: 5px;
  padding: 2px 5px;
  border: 1px solid var(--line);
  border-radius: 999px;
  font-family: var(--font-mono);
  font-size: 10.5px;
  font-style: normal;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-faint);
}

.saved-btn {
  display: flex;
  align-items: center;
  gap: 7px;
  height: 38px;
  padding: 0 11px;
  border: 1px solid var(--line-strong);
  border-radius: 2px;
  background: transparent;
  font-size: 12px;
  font-weight: 500;
  flex-shrink: 0;
  transition: background 0.15s, border-color 0.15s;
}
.saved-btn svg { width: 15px; height: 15px; }
.saved-btn b {
  display: grid;
  place-items: center;
  min-width: 18px;
  height: 18px;
  padding: 0 4px;
  border-radius: 2px;
  background: var(--paper-deep);
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 500;
}
.saved-btn:hover { border-color: var(--ink); background: var(--paper-raised); }
.saved-btn[aria-pressed="true"] {
  background: var(--ink);
  border-color: var(--ink);
  color: var(--paper);
}
.saved-btn[aria-pressed="true"] b { background: rgba(255, 255, 255, 0.16); color: var(--paper); }

/* ---------- Layout ---------- */

.layout {
  display: grid;
  grid-template-columns: 228px minmax(0, 1fr);
  gap: clamp(28px, 4vw, 56px);
  width: min(1380px, 100%);
  margin: 0 auto;
  padding: 0 clamp(20px, 3.2vw, 46px);
}

.rail {
  position: sticky;
  top: calc(var(--topbar-h) + 30px);
  align-self: start;
  padding-top: 44px;
  padding-bottom: 40px;
}

.rail-block { margin-bottom: 30px; }

.rail-label {
  margin: 0 0 11px;
  color: var(--ink-faint);
  font-family: var(--font-mono);
  font-size: 10.5px;
  font-weight: 500;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.rail-nav { display: flex; flex-direction: column; border-top: 1px solid var(--line); }

.rail-item {
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  padding: 9px 2px;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: transparent;
  text-align: left;
  font-size: 13px;
  color: var(--ink-soft);
  transition: color 0.15s, padding-left 0.15s;
}
.rail-item:hover { color: var(--ink); padding-left: 6px; }
.rail-item.is-active { color: var(--ink); font-weight: 600; }
.rail-item.is-active .rail-dot { opacity: 1; transform: scale(1); }
.rail-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--disc, var(--ink));
  opacity: 0;
  transform: scale(0.4);
  transition: opacity 0.15s, transform 0.15s;
  flex-shrink: 0;
}
.rail-item .rail-count {
  margin-left: auto;
  color: var(--ink-faint);
  font-family: var(--font-mono);
  font-size: 11px;
}
.rail-item--saved .rail-dot { background: var(--gold); }
.rail-item--saved { color: var(--ink); }

.rail-card {
  margin-bottom: 24px;
  padding: 15px;
  border: 1px solid var(--line-strong);
  background: rgba(251, 248, 243, 0.72);
}
.rail-card p:last-child {
  margin: 0;
  color: var(--ink-soft);
  font-size: 12px;
  line-height: 1.55;
}

.dim-mark {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 4px;
  margin-bottom: 10px;
  font-family: var(--font-mono);
  font-size: 10.5px;
  color: var(--accent);
}
.dim-mark i { color: var(--ink-faint); font-style: normal; }
.dim-mark sup { font-size: 7px; }

.roadmap {
  margin: 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 7px;
}
.roadmap li {
  display: flex;
  gap: 8px;
  align-items: baseline;
  color: var(--ink-faint);
  font-size: 12px;
}
.roadmap li span {
  font-family: var(--font-mono);
  font-size: 10.5px;
  color: var(--ink-faint);
}
.roadmap li.is-now { color: var(--ink); font-weight: 500; }
.roadmap li.is-now span { color: var(--gold); }

.rail-foot {
  margin: 32px 0 0;
  color: var(--ink-faint);
  font-family: var(--font-mono);
  font-size: 10.5px;
  letter-spacing: 0.04em;
}

.main { padding-bottom: 20px; min-width: 0; }

/* ---------- Hero ---------- */

.hero {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 356px;
  gap: clamp(32px, 5vw, 76px);
  align-items: center;
  padding: 58px 0 46px;
}

.hero h1 {
  margin: 0;
  font-family: var(--font-display);
  font-size: clamp(40px, 4.7vw, 66px);
  font-weight: 600;
  line-height: 1.02;
  letter-spacing: -0.045em;
}

.hero-sub {
  max-width: 540px;
  margin: 21px 0 0;
  color: var(--ink-soft);
  font-size: 15px;
  line-height: 1.65;
}

.hero-stats {
  display: flex;
  margin-top: 32px;
  border-top: 1px solid var(--line-strong);
  border-bottom: 1px solid var(--line);
  width: fit-content;
}
.hero-stat {
  padding: 13px 24px 12px 0;
  margin-right: 24px;
  border-right: 1px solid var(--line);
}
.hero-stat:last-child { border-right: 0; margin-right: 0; padding-right: 0; }
.hero-stat b {
  display: block;
  font-family: var(--font-mono);
  font-size: 21px;
  font-weight: 500;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}
.hero-stat small {
  display: block;
  margin-top: 4px;
  color: var(--ink-faint);
  font-family: var(--font-mono);
  font-size: 10.5px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.hero-plate {
  position: relative;
  padding: 24px 24px 20px;
  background-color: var(--accent-deep);
  background-image:
    linear-gradient(rgba(251, 248, 243, 0.065) 1px, transparent 1px),
    linear-gradient(90deg, rgba(251, 248, 243, 0.065) 1px, transparent 1px);
  background-size: 18px 18px;
  border: 1px solid var(--ink);
  box-shadow: 9px 9px 0 rgba(36, 27, 25, 0.12);
  color: var(--paper-raised);
}

.plate-corner {
  position: absolute;
  width: 9px;
  height: 9px;
  border-color: rgba(251, 248, 243, 0.55);
  border-style: solid;
}
.plate-corner--tl { top: 7px; left: 7px; border-width: 1px 0 0 1px; }
.plate-corner--tr { top: 7px; right: 7px; border-width: 1px 1px 0 0; }
.plate-corner--bl { bottom: 7px; left: 7px; border-width: 0 0 1px 1px; }
.plate-corner--br { bottom: 7px; right: 7px; border-width: 0 1px 1px 0; }

.plate-label {
  margin: 0 0 18px;
  color: rgba(251, 248, 243, 0.6);
  font-family: var(--font-mono);
  font-size: 10.5px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.plate-eq {
  padding-bottom: 17px;
  border-bottom: 1px solid rgba(251, 248, 243, 0.22);
  font-family: var(--font-display);
  font-size: 31px;
  letter-spacing: 0.01em;
}

.plate-grid {
  display: grid;
  grid-template-columns: 22px 1fr;
  gap: 2px 12px;
  margin: 15px 0 18px;
  font-family: var(--font-mono);
  font-size: 10.5px;
  color: rgba(251, 248, 243, 0.78);
}
.plate-grid span:nth-child(odd) { color: #e2bd76; }

.plate-note {
  margin: 0;
  padding-top: 12px;
  border-top: 1px dashed rgba(251, 248, 243, 0.22);
  color: rgba(251, 248, 243, 0.5);
  font-family: var(--font-mono);
  font-size: 10.5px;
  letter-spacing: 0.05em;
}

/* ---------- Toolbar ---------- */

.toolbar {
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 13px 0;
  border-top: 1px solid var(--ink);
  border-bottom: 1px solid var(--line-strong);
}

.results-meta {
  margin: 0;
  color: var(--ink-faint);
  font-family: var(--font-mono);
  font-size: 11.5px;
  letter-spacing: 0.02em;
}

.sort-control {
  display: flex;
  align-items: center;
  gap: 9px;
  margin-left: auto;
  color: var(--ink-faint);
  font-family: var(--font-mono);
  font-size: 10.5px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}
.sort-control select {
  height: 30px;
  padding: 0 24px 0 8px;
  border: 1px solid var(--line-strong);
  border-radius: 2px;
  background: var(--paper-raised);
  font-family: var(--font-body);
  font-size: 12px;
  text-transform: none;
  letter-spacing: 0;
  cursor: pointer;
}

.mobile-chips { display: none; }

/* ---------- Cards ---------- */

.formula-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(360px, 1fr));
  gap: 22px;
  padding: 24px 0 12px;
}

.formula-card {
  position: relative;
  display: flex;
  flex-direction: column;
  min-height: 300px;
  border: 1px solid var(--line-strong);
  border-top: 3px solid var(--disc);
  background: var(--paper-raised);
  box-shadow: var(--shadow-hard);
  text-decoration: none;
  transition: transform 0.18s ease, box-shadow 0.18s ease, border-color 0.18s ease;
  animation: card-in 0.4s both;
  animation-delay: calc(var(--i, 0) * 28ms);
}
.formula-card:hover {
  transform: translate(-2px, -3px);
  box-shadow: var(--shadow-lift);
  border-color: var(--line-strong);
}
.card-link:focus-visible { outline: 2px solid var(--accent); outline-offset: 4px; }

.card-link {
  position: absolute;
  inset: 0;
  z-index: 1;
}

.card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px 0;
}

.card-top-right {
  display: flex;
  align-items: center;
  gap: 4px;
}
.card-index {
  color: var(--ink-faint);
  font-family: var(--font-mono);
  font-size: 10.5px;
  letter-spacing: 0.09em;
}
.card-discipline {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  color: var(--disc);
  font-family: var(--font-mono);
  font-size: 10.5px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}
.card-discipline::before {
  content: "";
  width: 5px;
  height: 5px;
  background: var(--disc);
  border-radius: 50%;
}

.card-eq {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 108px;
  margin: 13px 16px 0;
  padding: 18px 20px;
  border: 1px solid var(--line);
  background:
    linear-gradient(rgba(154, 27, 42, 0.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(154, 27, 42, 0.035) 1px, transparent 1px);
  background-size: 16px 16px;
  overflow: hidden;
}
.card-eq .katex-display { margin: 0; }
.card-eq .katex { font-size: 1.27em; }
.card-eq .katex-fallback {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--accent);
  text-align: center;
  overflow-wrap: anywhere;
}

.card-body { display: flex; flex-direction: column; flex: 1; padding: 15px 17px 14px; }
.card-title {
  margin: 0;
  padding-right: 28px;
  font-family: var(--font-display);
  font-size: 18px;
  font-weight: 600;
  line-height: 1.22;
  letter-spacing: -0.015em;
}
.card-short {
  margin: 7px 0 0;
  color: var(--ink-soft);
  font-size: 12px;
  line-height: 1.55;
}
.card-foot {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: auto;
  padding-top: 14px;
}
.card-vars {
  color: var(--ink-faint);
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.03em;
}
.card-arrow {
  margin-left: auto;
  color: var(--ink-faint);
  font-family: var(--font-mono);
  font-size: 12px;
  transition: transform 0.18s, color 0.18s;
}
.formula-card:hover .card-arrow { transform: translateX(3px); color: var(--gold); }

.star-btn {
  display: grid;
  place-items: center;
  width: 29px;
  height: 29px;
  padding: 0;
  border: 1px solid transparent;
  border-radius: 2px;
  background: transparent;
  color: var(--ink-faint);
  transition: color 0.15s, background 0.15s, border-color 0.15s;
}
.star-btn svg { width: 15px; height: 15px; }
.star-btn:hover { color: var(--gold); border-color: var(--line); background: var(--paper); }
.star-btn.is-starred { color: var(--gold); }
.star-btn.is-starred svg { fill: currentColor; }

.card-star {
  position: relative;
  z-index: 2;
  margin-right: -5px;
  background: transparent;
}
.card-star:hover { background: var(--paper); }

.formula-grid.no-anim .formula-card { animation: none; }

/* ---------- Empty ---------- */

.empty-state {
  margin: 24px 0 20px;
  padding: 56px 24px;
  border: 1px dashed var(--line-strong);
  text-align: center;
  background: rgba(251, 248, 243, 0.55);
}
.empty-glyph {
  display: block;
  color: var(--line-strong);
  font-family: var(--font-display);
  font-size: 46px;
  line-height: 1;
}
.empty-state h2 {
  margin: 14px 0 5px;
  font-family: var(--font-display);
  font-size: 20px;
  font-weight: 600;
}
.empty-state p { margin: 0 0 18px; color: var(--ink-faint); font-size: 13px; }

/* ---------- Buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  height: 35px;
  padding: 0 13px;
  border: 1px solid var(--ink);
  border-radius: 2px;
  background: var(--ink);
  color: var(--paper);
  font-size: 12px;
  font-weight: 500;
  transition: background 0.15s, color 0.15s, border-color 0.15s, transform 0.15s;
}
.btn:hover { transform: translateY(-1px); }
.btn svg { width: 14px; height: 14px; }
.btn--ghost { background: transparent; color: var(--ink); border-color: var(--line-strong); }
.btn--ghost:hover { background: var(--paper-deep); border-color: var(--ink); }
.btn--primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn--primary:hover { background: var(--accent-deep); border-color: var(--accent-deep); }
.btn--tiny { height: 29px; padding: 0 9px; font-size: 11px; font-family: var(--font-mono); }

.page-foot {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 8px 24px;
  margin-top: 34px;
  padding: 18px 0 36px;
  border-top: 1px solid var(--line);
}
.page-foot p { margin: 0; color: var(--ink-faint); font-size: 12px; }
.page-foot strong { color: var(--ink-soft); }

/* ---------- Drawer ---------- */

.drawer-backdrop {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: rgba(38, 11, 16, 0.48);
  backdrop-filter: blur(2px);
  opacity: 0;
  transition: opacity 0.24s ease;
}
.drawer-backdrop.is-open { opacity: 1; }

.drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  z-index: 70;
  width: min(640px, 100vw);
  background: var(--paper);
  border-left: 1px solid var(--ink);
  box-shadow: -14px 0 40px rgba(58, 15, 23, 0.22);
  transform: translateX(102%);
  visibility: hidden;
  transition: transform 0.28s cubic-bezier(0.22, 0.8, 0.28, 1), visibility 0s linear 0.28s;
  overflow-y: auto;
  overscroll-behavior: contain;
}
.drawer.is-open { transform: translateX(0); visibility: visible; transition-delay: 0s; }

.drawer-inner { padding: 0 34px 70px; }

.drawer-top {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 0 -34px;
  padding: 15px 22px 15px 34px;
  border-bottom: 1px solid var(--line);
  background: rgba(251, 248, 243, 0.96);
  backdrop-filter: blur(8px);
}
.drawer-crumb {
  color: var(--ink-faint);
  font-family: var(--font-mono);
  font-size: 10.5px;
  letter-spacing: 0.11em;
  text-transform: uppercase;
}
.drawer-crumb b { color: var(--disc, var(--accent)); font-weight: 500; }
.drawer-actions { display: flex; align-items: center; gap: 7px; }
.drawer-close {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  padding: 0;
  border: 1px solid var(--line-strong);
  border-radius: 2px;
  background: var(--paper-raised);
  color: var(--ink-soft);
}
.drawer-close:hover { border-color: var(--ink); color: var(--ink); }
.drawer-close svg { width: 15px; height: 15px; }

.drawer-head { padding: 27px 0 20px; }
.discipline-tag {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 11px;
  color: var(--disc, var(--accent));
  font-family: var(--font-mono);
  font-size: 10.5px;
  letter-spacing: 0.11em;
  text-transform: uppercase;
}
.discipline-tag::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}
.drawer-head h2 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 32px;
  font-weight: 600;
  line-height: 1.08;
  letter-spacing: -0.032em;
}
.drawer-desc {
  margin: 13px 0 0;
  color: var(--ink-soft);
  font-size: 13.5px;
  line-height: 1.65;
}
.tag-row { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 15px; }
.tag {
  padding: 3px 7px;
  border: 1px solid var(--line);
  background: rgba(251, 248, 243, 0.7);
  color: var(--ink-faint);
  font-family: var(--font-mono);
  font-size: 10.5px;
  letter-spacing: 0.04em;
}

.equation-board {
  position: relative;
  margin-top: 6px;
  padding: 32px 50px 32px 24px;
  border: 1px solid var(--ink);
  border-left: 4px solid var(--disc);
  background-color: var(--paper-raised);
  background-image:
    linear-gradient(rgba(154, 27, 42, 0.04) 1px, transparent 1px),
    linear-gradient(90deg, rgba(154, 27, 42, 0.04) 1px, transparent 1px);
  background-size: 18px 18px;
  overflow-x: auto;
}
.equation-board .katex-display { margin: 0; }
.equation-board .katex { font-size: 1.6em; }
.equation-board .katex-fallback {
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--accent);
  overflow-wrap: anywhere;
}
.copy-btn {
  position: absolute;
  top: 9px;
  right: 9px;
  display: flex;
  align-items: center;
  gap: 5px;
  height: 27px;
  padding: 0 8px;
  border: 1px solid var(--line);
  border-radius: 2px;
  background: var(--paper);
  color: var(--ink-faint);
  font-family: var(--font-mono);
  font-size: 10.5px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.copy-btn:hover { border-color: var(--ink); color: var(--ink); }
.copy-btn svg { width: 11px; height: 11px; }

.spec-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 0;
  margin-top: 14px;
  border: 1px solid var(--line);
  background: rgba(251, 248, 243, 0.55);
}
.spec-item {
  flex: 1 1 150px;
  padding: 10px 14px;
  border-right: 1px solid var(--line);
}
.spec-item:last-child { border-right: 0; }
.spec-item small {
  display: block;
  color: var(--ink-faint);
  font-family: var(--font-mono);
  font-size: 10.5px;
  letter-spacing: 0.09em;
  text-transform: uppercase;
}
.spec-item span {
  display: block;
  margin-top: 2px;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--ink-soft);
}

.watch {
  display: flex;
  gap: 10px;
  margin-top: 16px;
  padding: 12px 14px;
  border-left: 3px solid var(--gold);
  background: var(--gold-wash);
}
.watch svg { width: 15px; height: 15px; flex-shrink: 0; margin-top: 1px; color: var(--gold); }
.watch p { margin: 0; font-size: 12px; line-height: 1.55; color: #6f4e16; }
.watch strong { font-family: var(--font-mono); font-size: 10.5px; letter-spacing: 0.06em; text-transform: uppercase; }

.section { margin-top: 32px; }
.section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 13px;
}
.section-kicker {
  display: block;
  margin-bottom: 3px;
  color: var(--gold);
  font-family: var(--font-mono);
  font-size: 10.5px;
  letter-spacing: 0.13em;
  text-transform: uppercase;
}
.section-head h3 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 20px;
  font-weight: 600;
  letter-spacing: -0.02em;
}
.section-hint {
  margin: 5px 0 0;
  color: var(--ink-faint);
  font-size: 12px;
}

.sigfigs {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--ink-faint);
  font-family: var(--font-mono);
  font-size: 10.5px;
  letter-spacing: 0.07em;
  text-transform: uppercase;
}
.sigfigs select {
  height: 27px;
  padding: 0 4px;
  border: 1px solid var(--line-strong);
  border-radius: 2px;
  background: var(--paper-raised);
  font-family: var(--font-mono);
  font-size: 10.5px;
}

/* ---------- Calculator ---------- */

.calc {
  padding: 18px;
  border: 1px solid var(--ink);
  background: var(--paper-raised);
  box-shadow: 4px 4px 0 rgba(36, 27, 25, 0.06);
}

.calc-inputs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px 14px;
  margin-top: 15px;
}

.calc-field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.calc-label {
  display: flex;
  align-items: baseline;
  gap: 6px;
  min-height: 16px;
  color: var(--ink-soft);
  font-size: 12px;
}
.calc-sym {
  display: inline-grid;
  place-items: center;
  min-width: 20px;
  height: 20px;
  padding: 0 4px;
  border: 1px solid var(--line);
  background: var(--paper);
  color: var(--accent);
  font-family: var(--font-mono);
  font-size: 10.5px;
  font-weight: 500;
}
.calc-entry {
  display: flex;
  height: 37px;
  border: 1px solid var(--line-strong);
  background: #ffffff;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.calc-entry:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(154, 27, 42, 0.11);
}
.calc-entry input {
  width: 100%;
  min-width: 0;
  padding: 0 9px;
  border: 0;
  background: transparent;
  font-family: var(--font-mono);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}
.calc-entry input:focus { outline: none; }
.calc-entry select {
  width: 78px;
  flex-shrink: 0;
  padding: 0 2px 0 7px;
  border: 0;
  border-left: 1px solid var(--line);
  background: var(--paper);
  font-family: var(--font-mono);
  font-size: 10.5px;
  cursor: pointer;
}
.calc-entry select:focus { outline: none; }

.result-card {
  margin-top: 15px;
  padding: 16px 16px 13px;
  background-color: var(--ink);
  background-image:
    linear-gradient(rgba(251, 248, 243, 0.045) 1px, transparent 1px),
    linear-gradient(90deg, rgba(251, 248, 243, 0.045) 1px, transparent 1px);
  background-size: 17px 17px;
  color: var(--paper-raised);
}
.result-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  color: rgba(251, 248, 243, 0.5);
  font-family: var(--font-mono);
  font-size: 10.5px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}
.result-top .live-dot {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  color: #e6c47c;
}
.result-top .live-dot::before {
  content: "";
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: #d9b35f;
  box-shadow: 0 0 0 3px rgba(217, 179, 95, 0.18);
}
.result-top .live-dot.is-idle { color: rgba(251, 248, 243, 0.38); }
.result-top .live-dot.is-idle::before {
  background: rgba(251, 248, 243, 0.35);
  box-shadow: none;
}
.result-main {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 8px;
  margin: 12px 0 2px;
}
.result-sym {
  font-family: var(--font-mono);
  font-size: 14px;
  color: #e2bd76;
}
.result-equals { color: rgba(251, 248, 243, 0.4); font-family: var(--font-mono); font-size: 13px; }
.result-value {
  font-family: var(--font-mono);
  font-size: clamp(27px, 4vw, 38px);
  font-weight: 500;
  line-height: 1.05;
  letter-spacing: -0.025em;
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}
.result-value sup { font-size: 0.55em; vertical-align: super; }
.result-value .times { font-size: 0.68em; color: rgba(251, 248, 243, 0.55); }
.result-unit {
  height: 29px;
  margin-left: auto;
  padding: 0 4px;
  border: 1px solid rgba(251, 248, 243, 0.28);
  border-radius: 2px;
  background: rgba(251, 248, 243, 0.08);
  color: var(--paper-raised);
  font-family: var(--font-mono);
  font-size: 12px;
  cursor: pointer;
}
.result-unit option { background: var(--ink); color: var(--paper-raised); }
.result-label {
  margin: 0;
  color: rgba(251, 248, 243, 0.5);
  font-size: 12px;
}

.dim-check {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin-top: 12px;
  padding: 9px 11px;
  border: 1px solid var(--line);
  background: var(--paper);
}
.dim-dot {
  width: 7px;
  height: 7px;
  margin-top: 4px;
  border-radius: 50%;
  background: var(--line-strong);
  flex-shrink: 0;
}
.dim-check strong {
  display: block;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.07em;
  text-transform: uppercase;
}
.dim-check p { margin: 2px 0 0; color: var(--ink-faint); font-family: var(--font-mono); font-size: 11.5px; line-height: 1.45; }
.dim-check.is-ok { border-color: #b6d4bd; background: var(--ok-wash); }
.dim-check.is-ok .dim-dot { background: var(--ok); }
.dim-check.is-ok strong { color: var(--ok); }
.dim-check.is-bad { border-color: #e8b8b1; background: var(--red-wash); }
.dim-check.is-bad .dim-dot { background: var(--red); }
.dim-check.is-bad strong { color: var(--red); }

.calc-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-top: 13px;
}
.calc-actions .btn:last-child { margin-left: auto; }

/* ---------- Worked example ---------- */

.example {
  border: 1px solid var(--line-strong);
  background: rgba(251, 248, 243, 0.6);
}
.example-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 15px;
  border-bottom: 1px solid var(--line);
  background: var(--paper-raised);
}
.example-title {
  margin: 0;
  font-family: var(--font-mono);
  font-size: 10.5px;
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-soft);
}
.example-body { padding: 15px; }
.example-given {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 14px;
}
.given-chip {
  padding: 3px 7px;
  border: 1px solid var(--line);
  background: var(--paper);
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--ink-soft);
}
.steps {
  margin: 0;
  padding: 0;
  list-style: none;
  counter-reset: step;
  display: flex;
  flex-direction: column;
  gap: 9px;
}
.steps li {
  position: relative;
  padding-left: 27px;
  color: var(--ink-soft);
  font-size: 12px;
  line-height: 1.55;
  counter-increment: step;
}
.steps li::before {
  content: counter(step, decimal-leading-zero);
  position: absolute;
  left: 0;
  top: 2px;
  color: var(--gold);
  font-family: var(--font-mono);
  font-size: 10.5px;
}
.example-answer {
  margin: 15px 0 0;
  padding-top: 12px;
  border-top: 1px dashed var(--line-strong);
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--ink);
}
.example-answer b { color: var(--accent); font-weight: 600; }
.example-takeaway {
  margin: 10px 0 0;
  color: var(--ink-faint);
  font-size: 12px;
  font-style: italic;
}

/* ---------- Notes / related ---------- */

.notes-box { position: relative; }
.notes-box textarea {
  width: 100%;
  min-height: 100px;
  padding: 12px 14px;
  border: 1px solid var(--line-strong);
  border-radius: 2px;
  background: #ffffff;
  font-size: 12px;
  line-height: 1.6;
  resize: vertical;
}
.notes-box textarea::placeholder { color: var(--ink-faint); }
.notes-box textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(154, 27, 42, 0.1);
}
.notes-status {
  display: flex;
  justify-content: space-between;
  margin-top: 5px;
  color: var(--ink-faint);
  font-family: var(--font-mono);
  font-size: 10.5px;
  letter-spacing: 0.05em;
}
.notes-status .saved { color: var(--ok); }

.related-list { display: flex; flex-direction: column; border-top: 1px solid var(--line); }
.related-link {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 2px;
  border-bottom: 1px solid var(--line);
  text-decoration: none;
  transition: padding-left 0.15s, color 0.15s;
}
.related-link:hover { padding-left: 6px; color: var(--accent); }
.related-link .rl-disc {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--disc);
  flex-shrink: 0;
}
.related-link .rl-name { font-size: 12px; font-weight: 500; }
.related-link .rl-arrow { margin-left: auto; color: var(--ink-faint); font-family: var(--font-mono); font-size: 12px; }

.drawer-foot {
  margin-top: 34px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
  color: var(--ink-faint);
  font-family: var(--font-mono);
  font-size: 10.5px;
  letter-spacing: 0.04em;
}

/* ---------- Toast ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  z-index: 90;
  padding: 9px 14px;
  border: 1px solid var(--ink);
  background: var(--ink);
  color: var(--paper);
  font-family: var(--font-mono);
  font-size: 12px;
  letter-spacing: 0.03em;
  transform: translate(-50%, 16px);
  opacity: 0;
  pointer-events: none;
  transition: transform 0.22s, opacity 0.22s;
}
.toast.is-visible { transform: translate(-50%, 0); opacity: 1; }

/* ---------- Motion ---------- */

@keyframes card-in {
  from { opacity: 0; transform: translateY(9px); }
  to { opacity: 1; transform: translateY(0); }
}

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

/* ---------- Responsive ---------- */

@media (max-width: 1240px) {
  .phase-nav { display: none; }
}

@media (max-width: 1080px) {
  .hero { grid-template-columns: minmax(0, 1fr) 310px; gap: 36px; }
  .hero-plate { padding: 20px; }
}

@media (max-width: 940px) {
  .layout { grid-template-columns: 1fr; }
  .rail { display: none; }
  .mobile-chips {
    display: flex;
    gap: 6px;
    overflow-x: auto;
    scrollbar-width: none;
    padding-bottom: 2px;
  }
  .mobile-chips::-webkit-scrollbar { display: none; }
  .chip {
    display: flex;
    align-items: center;
    gap: 5px;
    flex-shrink: 0;
    height: 27px;
    padding: 0 9px;
    border: 1px solid var(--line-strong);
    border-radius: 999px;
    background: transparent;
    color: var(--ink-soft);
    font-family: var(--font-mono);
    font-size: 10.5px;
    letter-spacing: 0.03em;
    white-space: nowrap;
  }
  .chip .chip-count { color: var(--ink-faint); font-size: 10.5px; }
  .chip.is-active { background: var(--ink); border-color: var(--ink); color: var(--paper); }
  .chip.is-active .chip-count { color: rgba(251, 248, 243, 0.55); }
  .toolbar { flex-wrap: wrap; }
  .mobile-chips { order: -1; width: 100%; }
  .results-meta { margin-top: 2px; }
  .hero { padding-top: 44px; }
}

@media (max-width: 780px) {
  .topbar {
    flex-wrap: wrap;
    height: auto;
    padding-top: 12px;
    padding-bottom: 12px;
    gap: 10px 16px;
  }
  .brand { margin-right: auto; }
  .saved-btn { order: 2; }
  .search-wrap { order: 3; width: 100%; max-width: none; }
  .search-kbd { display: none; }
  .hero { grid-template-columns: 1fr; padding: 36px 0 32px; }
  .hero-plate { display: none; }
  .hero h1 { font-size: clamp(38px, 9vw, 54px); }
  .formula-grid { grid-template-columns: 1fr; gap: 16px; }
  .page-foot { flex-direction: column; }
  .drawer-inner { padding: 0 20px 60px; }
  .drawer-top { margin: 0 -20px; padding: 12px 14px 12px 20px; }
  .drawer-head h2 { font-size: 26px; }
  .equation-board { padding: 24px 44px 24px 16px; }
  .equation-board .katex { font-size: 1.25em; }
  .calc-inputs { grid-template-columns: 1fr; }
  .spec-item { flex-basis: 50%; }
  .spec-item:nth-child(2) { border-right: 0; }
  .drawer { width: 100vw; }
  .section { margin-top: 27px; }
}

@media (max-width: 460px) {
  .brand-text small { display: none; }
  .saved-btn span { display: none; }
  .hero h1 { font-size: 38px; }
  .hero-stats { width: 100%; }
  .hero-stat { flex: 1; padding-right: 14px; margin-right: 14px; }
  .hero-stat b { font-size: 18px; }
  .formula-card { min-height: 280px; }
  .calc { padding: 13px; }
  .result-value { font-size: 27px; }
  .result-unit { margin-left: 0; }
  .tag-row { gap: 4px; }
}
