:root {
  color-scheme: light;
  --ink: #0b1727;
  --muted: #617084;
  --line: #dce4eb;
  --line-strong: #c5d0da;
  --surface: #ffffff;
  --canvas: #edf2f6;
  --teal: #c62828;
  --teal-dark: #8e1b1b;
  --teal-soft: #fdeaea;
  --amber: #a35b00;
  --amber-soft: #fff4dc;
  --navy: #4a1114;
  --shadow: 0 1px 2px rgb(15 23 42 / 5%), 0 8px 30px rgb(15 23 42 / 5%);
}

* { box-sizing: border-box; }

/* Keep inactive calculators and correlation-specific fields completely out
   of the layout. This must override grid/flex display rules below. */
[hidden] { display: none !important; }

html { font-size: 16px; }

body {
  margin: 0;
  min-width: 320px;
  background: var(--canvas);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.45;
}

button, input, select { font: inherit; }

.topbar {
  min-height: 88px;
  display: flex;
  align-items: center;
  padding: 10px clamp(18px, 3vw, 44px);
  background: #ffffff;
  border-bottom: 3px solid #ef5350;
}

.brand-logo {
  display: block;
  width: min(440px, 72vw);
  height: auto;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.workbench {
  width: min(1900px, 100%);
  min-height: calc(100vh - 120px);
  margin: 0 auto;
  padding: 18px clamp(12px, 2vw, 28px) 24px;
  display: grid;
  grid-template-columns: minmax(250px, 0.8fr) minmax(520px, 1.75fr) minmax(310px, 1fr);
  gap: 16px;
  align-items: start;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow);
}

.panel-heading {
  min-height: 66px;
  padding: 14px 16px;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 10px;
  border-bottom: 1px solid var(--line);
}
.panel-heading strong { font-size: .86rem; color: #334155; }
.eyebrow, .section-label {
  display: block;
  color: var(--teal-dark);
  font-size: .72rem;
  font-weight: 800;
  letter-spacing: .11em;
  text-transform: uppercase;
}

.catalog-panel { position: sticky; top: 14px; max-height: calc(100vh - 30px); overflow: auto; }
.catalog-tree { padding: 8px; }
.family { border-bottom: 1px solid #edf1f4; }
.family:last-child { border-bottom: 0; }
.family-title {
  width: 100%;
  padding: 13px 10px 9px;
  border: 0;
  background: transparent;
  color: #526274;
  text-align: left;
  font-size: .76rem;
  font-weight: 800;
  letter-spacing: .035em;
  text-transform: uppercase;
}
.topic-button {
  width: 100%;
  display: block;
  padding: 10px 11px;
  margin: 2px 0;
  border: 0;
  border-left: 3px solid transparent;
  border-radius: 5px;
  background: transparent;
  color: #344256;
  text-align: left;
  font-size: .86rem;
  line-height: 1.35;
  cursor: pointer;
  transition: background .15s ease, color .15s ease, border-color .15s ease;
}
.topic-button:hover { background: #fff3f3; color: var(--teal-dark); }
.topic-button.active { background: var(--teal-soft); border-left-color: var(--teal); color: var(--teal-dark); font-weight: 700; }
.topic-button .topic-code { display: inline-block; min-width: 42px; font-variant-numeric: tabular-nums; }
.topic-button.depth-3 { padding-left: 25px; font-size: .81rem; }

.main-panel { display: grid; gap: 16px; }
.correlation-card { overflow: hidden; }
.correlation-head { display: flex; justify-content: space-between; gap: 18px; padding: 20px 22px 16px; border-bottom: 1px solid var(--line); }
.correlation-head h2 { margin: 8px 0 2px; font-size: clamp(1.08rem, 1.8vw, 1.38rem); letter-spacing: -.02em; }
.breadcrumb { margin: 0; color: var(--muted); font-size: .8rem; }
.status-badge, .output-chip { display: inline-flex; align-items: center; border-radius: 999px; font-size: .72rem; font-weight: 800; letter-spacing: .06em; text-transform: uppercase; }
.status-badge { padding: 5px 9px; background: var(--amber-soft); color: var(--amber); }
.status-badge.ready { background: #dcfce7; color: #166534; }
.output-chip { height: fit-content; padding: 7px 10px; background: #eef2f7; color: #46566a; white-space: nowrap; }

.formula-stage {
  position: relative;
  min-height: 154px;
  display: grid;
  place-items: center;
  padding: clamp(24px, 5vw, 54px) 22px;
  overflow-x: auto;
  background-color: #fbfdff;
  background-image: linear-gradient(rgb(198 40 40 / 4%) 1px, transparent 1px), linear-gradient(90deg, rgb(198 40 40 / 4%) 1px, transparent 1px);
  background-size: 24px 24px;
  border-bottom: 1px solid var(--line);
}
.formula-list { width: 100%; display: grid; gap: 22px; justify-items: center; }
.formula-line { min-width: max-content; color: #0f172a; font-size: clamp(1.02rem, 1.45vw, 1.38rem); }
.formula-line .katex-display { margin: 0; }
.formula-fallback { margin: 0; font-family: "Cambria Math", Georgia, serif; font-size: 1.18rem; }

.notation-block { padding: 18px 22px 22px; }
.section-label { margin-bottom: 9px; }
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 8px; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 10px 12px; border-bottom: 1px solid #e8edf1; text-align: left; }
th { background: #f3f6f8; color: #526174; font-size: .76rem; text-transform: uppercase; letter-spacing: .06em; }
td { font-size: .9rem; }
tbody tr:last-child td { border-bottom: 0; }
.symbol-cell { width: 28%; color: #7f1d1d; font-size: 1rem; white-space: nowrap; }
.symbol-cell .katex { font-size: 1.08em; }
.definition-pending { color: #9a5a08; }

.input-card { padding: 20px 22px 22px; }
.section-title-row { display: flex; justify-content: space-between; margin-bottom: 14px; }
.section-title-row h2 { margin: 4px 0 0; font-size: 1.16rem; }
.pending-message { padding: 14px 15px; border: 1px solid #f3d8a4; border-radius: 8px; background: #fff9ed; color: #83510f; font-size: .9rem; }
.input-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 15px; }
.input-grid label { display: grid; gap: 6px; color: #435267; font-size: .82rem; font-weight: 650; }
.compound-input { display: grid; grid-template-columns: 1fr 82px; }
input, select {
  width: 100%;
  min-height: 43px;
  border: 1px solid var(--line-strong);
  background: #fff;
  color: var(--ink);
  padding: 8px 10px;
}
input { border-radius: 6px 0 0 6px; }
select { border-left: 0; border-radius: 0 6px 6px 0; color: #475569; }
.single-input { border: 1px solid var(--line-strong); border-radius: 6px; }
.unit-suffix {
  min-height: 43px;
  display: flex;
  align-items: center;
  padding: 8px 10px;
  border: 1px solid var(--line-strong);
  border-left: 0;
  border-radius: 0 6px 6px 0;
  background: #f8fafc;
  color: #475569;
  font-size: .78rem;
  white-space: nowrap;
}
.form-note { grid-column: 1 / -1; margin: 0; color: var(--muted); font-size: .8rem; }
input:focus, select:focus { position: relative; z-index: 1; outline: 2px solid rgb(198 40 40 / 22%); border-color: var(--teal); }
.calculate-button {
  align-self: end;
  min-height: 43px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 9px 15px;
  border: 0;
  border-radius: 7px;
  background: var(--teal);
  color: white;
  font-weight: 750;
  cursor: pointer;
}
.calculate-button:hover { background: var(--teal-dark); }

.results-panel { position: sticky; top: 14px; min-height: 520px; overflow: hidden; }
.result-empty { min-height: 450px; padding: 36px 25px; display: grid; place-content: center; justify-items: center; text-align: center; color: var(--muted); }
.result-empty h2 { margin: 16px 0 7px; color: #334155; font-size: 1.1rem; }
.result-empty p { max-width: 280px; margin: 0; font-size: .88rem; }
.result-symbol { width: 66px; height: 66px; display: grid; place-items: center; border: 1px solid #efb6b6; border-radius: 50%; background: var(--teal-soft); color: var(--teal); font: italic 700 2rem Georgia, serif; }
#result-content { padding: 18px; }
.primary-result { padding: 17px; border-radius: 10px; background: var(--navy); color: white; }
.primary-result small { color: #efc0c0; font-size: .72rem; text-transform: uppercase; letter-spacing: .08em; }
.primary-result strong { display: block; margin-top: 5px; font-size: clamp(1.5rem, 3vw, 2.15rem); font-variant-numeric: tabular-nums; }
.result-section { margin-top: 18px; }
.result-section h3 { margin: 0 0 7px; color: var(--teal-dark); font-size: .74rem; letter-spacing: .08em; text-transform: uppercase; }
.result-list { margin: 0; border-top: 1px solid var(--line); }
.result-row { display: flex; justify-content: space-between; gap: 15px; padding: 8px 2px; border-bottom: 1px solid var(--line); font-size: .82rem; }
.result-row dt { color: var(--muted); }
.result-row dd { margin: 0; color: #172033; font-weight: 700; text-align: right; font-variant-numeric: tabular-nums; }
.warning-box { margin-top: 16px; padding: 11px 12px; border-radius: 7px; background: #fff5e5; color: #8a4e06; font-size: .8rem; }
.error-box { padding: 13px; border-radius: 8px; background: #fff1f2; color: #9f1239; }

footer { display: flex; justify-content: space-between; gap: 20px; padding: 16px clamp(18px, 3vw, 44px) 24px; color: #66778a; font-size: .75rem; }

@media (max-width: 1180px) {
  .workbench { grid-template-columns: 250px minmax(0, 1fr); }
  .results-panel { position: static; grid-column: 2; min-height: 0; }
  .result-empty { min-height: 220px; }
}

@media (max-width: 760px) {
  .topbar { min-height: 68px; padding-block: 8px; }
  .brand-logo { width: min(360px, 88vw); }
  .workbench { display: block; padding: 10px; }
  .catalog-panel { position: static; max-height: 310px; margin-bottom: 10px; }
  .main-panel { gap: 10px; }
  .results-panel { margin-top: 10px; }
  .correlation-head { padding: 17px 15px 13px; }
  .formula-stage { justify-content: start; padding: 30px 16px; }
  .formula-list { justify-items: start; }
  .notation-block, .input-card { padding: 16px; }
  .input-grid { grid-template-columns: 1fr; }
  .symbol-cell { width: 36%; }
  footer { display: block; padding: 14px 18px 22px; }
  footer span { display: block; margin-top: 4px; }
}
