:root {
  --bg: #f8fafc;
  --panel: #ffffff;
  --row: #f1f5f9;
  --ink: #0f172a;
  --muted: #64748b;
  --line: #e2e8f0;
  --accent: #087f75;
  --on-accent: #ffffff;
  --accent-soft: #ccfbf1;
  --ring: rgba(13, 148, 136, 0.25);
  --glass: #ffffff;
  --liquid: #14b8a6;
  --stopper: #1e293b;
  --rod: #94a3b8;
  --warn: #b45309;
  --on-warn: #ffffff;
  --warn-bg: #fef3c7;
  --crit: #dc2626;
  --on-crit: #ffffff;
  --crit-bg: #fee2e2;
  --ok: #047857;
  --info: #f0fdf4;
  --radius: 8px;
  --font-body: "Instrument Sans", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}

[data-theme="dark"] {
  color-scheme: dark;
  --bg: #090d16;
  --panel: #111827;
  --row: #1f2937;
  --ink: #f8fafc;
  --muted: #94a3b8;
  --line: #1e293b;
  --accent: #2dd4bf;
  --on-accent: #042f2e;
  --accent-soft: #134e4a;
  --ring: rgba(45, 212, 191, 0.3);
  --glass: #0f172a;
  --liquid: #0d9488;
  --stopper: #cbd5e1;
  --rod: #64748b;
  --warn: #f59e0b;
  --on-warn: #451a03;
  --warn-bg: #451a03;
  --crit: #f87171;
  --on-crit: #450a0a;
  --crit-bg: #450a0a;
  --ok: #34d399;
  --info: #064e3b;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #090d16;
    --panel: #111827;
    --row: #1f2937;
    --ink: #f8fafc;
    --muted: #94a3b8;
    --line: #1e293b;
    --accent: #2dd4bf;
    --on-accent: #042f2e;
    --accent-soft: #134e4a;
    --ring: rgba(45, 212, 191, 0.3);
    --glass: #0f172a;
    --liquid: #0d9488;
    --stopper: #cbd5e1;
    --rod: #64748b;
    --warn: #f59e0b;
    --on-warn: #451a03;
    --warn-bg: #451a03;
    --crit: #f87171;
    --on-crit: #450a0a;
    --crit-bg: #450a0a;
    --ok: #34d399;
    --info: #064e3b;
  }
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { color-scheme: light; scroll-padding-top: 1rem; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.5;
  padding: 1.5rem 1rem 3.5rem;
  -webkit-font-smoothing: antialiased;
}

.container {
  max-width: 1120px;
  margin: 0 auto;
}

header {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  padding-bottom: 1.25rem;
  border-bottom: 1px solid var(--line);
}

.brand-tag {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  background: var(--accent-soft);
  color: var(--accent);
  padding: 0.25rem 0.75rem;
  border-radius: 9999px;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1 {
  font-size: 2.1rem;
  font-weight: 700;
  letter-spacing: 0;
  color: var(--ink);
  margin-top: 0.35rem;
}

.subtitle {
  color: var(--muted);
  font-size: 0.92rem;
  margin-top: 0.2rem;
}

.btn-theme {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  background: var(--panel);
  border: 1px solid var(--line);
  color: var(--ink);
  padding: 0.5rem 0.9rem;
  border-radius: 8px;
  font-weight: 600;
  font-size: 0.88rem;
  cursor: pointer;
  transition: all 0.15s ease;
}
.btn-theme:hover { background: var(--row); }

/* Layout */
.grid-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 1.75rem;
  margin-top: 1.5rem;
}
@media (min-width: 960px) {
  .grid-layout {
    grid-template-columns: minmax(0, 5fr) minmax(0, 7fr);
    align-items: start;
  }
}

/* Cards */
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.35rem;
  box-shadow: 0 1px 3px rgba(0,0,0,0.03);
}
.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--line);
  padding-bottom: 0.85rem;
  margin-bottom: 1.15rem;
}
.card-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--ink);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.btn-reset {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--muted);
  background: none;
  border: none;
  cursor: pointer;
}
.btn-reset:hover { color: var(--ink); }

/* Segmented Controls */
.seg-group {
  margin-bottom: 1.15rem;
}
.seg-label {
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 0.45rem;
  display: block;
}
.seg {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.35rem;
  background: var(--row);
  padding: 0.35rem;
  border-radius: 10px;
  border: 1px solid var(--line);
}
.seg.syr-seg {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}
.seg label {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 0.5rem 0.25rem;
  border-radius: 7px;
  cursor: pointer;
  color: var(--muted);
  font-weight: 500;
  font-size: 0.88rem;
  transition: all 0.15s ease;
  text-align: center;
}
.seg label span.sub {
  font-size: 0.72rem;
  opacity: 0.75;
  font-family: var(--font-mono);
}
.seg input { display: none; }
.seg input:checked + label {
  background: var(--panel);
  color: var(--ink);
  font-weight: 700;
  border: 1px solid var(--line);
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}

/* Form Fields */
.field {
  margin-bottom: 1.15rem;
}
.field label {
  display: block;
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--ink);
  margin-bottom: 0.4rem;
}
.control {
  display: flex;
  border: 1.5px solid var(--line);
  border-radius: 9px;
  background: var(--panel);
  overflow: hidden;
  transition: border 0.15s ease, box-shadow 0.15s ease;
}
.control:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--ring);
}
.control input {
  flex: 1;
  border: none;
  background: transparent;
  padding: 0.65rem 0.85rem;
  font-family: var(--font-mono);
  font-size: 1.3rem;
  font-weight: 600;
  color: var(--ink);
  outline: none;
  font-variant-numeric: tabular-nums;
}
.control select {
  border: none;
  border-left: 1.5px solid var(--line);
  background: var(--row);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 0.95rem;
  font-weight: 600;
  padding: 0 0.85rem;
  outline: none;
  cursor: pointer;
}
.control .suffix {
  display: grid;
  place-items: center;
  border-left: 1.5px solid var(--line);
  background: var(--row);
  padding: 0 0.9rem;
  font-weight: 600;
  font-size: 0.92rem;
  color: var(--muted);
}
.field-hint {
  font-size: 0.75rem;
  color: var(--muted);
  margin-top: 0.35rem;
}

.select-styled {
  width: 100%;
  padding: 0.65rem 0.85rem;
  border: 1.5px solid var(--line);
  border-radius: 9px;
  background: var(--panel);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 0.95rem;
  font-weight: 500;
  outline: none;
  cursor: pointer;
}
.select-styled:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--ring);
}

/* Chips */
.chip-wrap {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem;
  margin-top: 0.45rem;
}
.chip-label {
  font-size: 0.75rem;
  color: var(--muted);
  font-weight: 600;
}
.chip {
  background: var(--panel);
  border: 1.5px solid var(--line);
  color: var(--ink);
  font-family: var(--font-mono);
  font-size: 0.78rem;
  font-weight: 600;
  padding: 0.25rem 0.7rem;
  border-radius: 9999px;
  cursor: pointer;
  transition: all 0.15s ease;
}
.chip:hover {
  border-color: var(--accent);
  background: var(--row);
}
.chip.active {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
}

/* Hero Result Card */
.hero-card {
  background: var(--panel);
  border: 2px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05);
}
.hero-bar {
  height: 7px;
  background: var(--accent);
  transition: background 0.2s ease;
}
.hero-bar.bad { background: var(--crit); }
.hero-bar.warn { background: var(--warn); }
.hero-bar.ok { background: var(--ok); }

.hero-body {
  padding: 1.5rem;
}
.hero-top {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
}
.readout-label {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0;
  text-transform: uppercase;
  color: var(--muted);
}
.readout-num-wrap {
  display: flex;
  align-items: baseline;
  gap: 0.6rem;
  margin-top: 0.25rem;
}
.readout-num {
  font-family: var(--font-mono);
  font-size: 4.5rem;
  font-weight: 800;
  line-height: 1;
  color: var(--accent);
  letter-spacing: 0;
}
.readout-num.bad { color: var(--crit); }
.readout-unit {
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--ink);
}
.readout-ml {
  background: var(--row);
  padding: 0.35rem 0.65rem;
  border-radius: 6px;
  font-family: var(--font-mono);
  font-size: 0.92rem;
  font-weight: 600;
  color: var(--muted);
}

.badge-status {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.35rem 0.75rem;
  border-radius: 9999px;
  font-size: 0.8rem;
  font-weight: 700;
}
.badge-status.ok { background: var(--info); color: var(--ok); }
.badge-status.warn { background: var(--warn-bg); color: var(--warn); }
.badge-status.crit { background: var(--crit-bg); color: var(--crit); }

.action-instruction {
  margin-top: 1rem;
  padding: 0.9rem 1rem;
  border-radius: 9px;
  font-size: 0.94rem;
  font-weight: 500;
  background: var(--accent-soft);
  color: var(--ink);
}
.action-instruction.bad { background: var(--crit-bg); color: var(--crit); }

/* Syringe Container */
.syringe-box {
  margin-top: 1.25rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 1rem;
  background: var(--panel);
}
.syringe-box-header {
  display: flex;
  justify-content: space-between;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0;
  margin-bottom: 0.5rem;
}

/* Magnifier box */
.zoom-box {
  margin-top: 1rem;
  padding: 0.85rem;
  background: var(--row);
  border-radius: 9px;
  border: 1px solid var(--line);
}
.zoom-box-header {
  display: flex;
  justify-content: space-between;
  font-size: 0.75rem;
  color: var(--muted);
  margin-bottom: 0.4rem;
}

/* Metrics Grid */
.metrics-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 0.75rem;
  margin-top: 1.25rem;
}
.metric-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.85rem;
}
.metric-card-label {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0;
}
.metric-card-val {
  font-family: var(--font-mono);
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--ink);
  margin-top: 0.2rem;
}
.metric-card-sub {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--muted);
  margin-top: 0.15rem;
}

/* Notes */
.notes-list {
  margin-top: 1rem;
  display: grid;
  gap: 0.5rem;
}
.note-item {
  display: flex;
  gap: 0.65rem;
  align-items: flex-start;
  padding: 0.75rem 0.9rem;
  border-radius: 8px;
  font-size: 0.88rem;
  background: var(--info);
  border: 1px solid rgba(5,150,105,0.2);
}
.note-item .tag {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  padding: 0.2rem 0.45rem;
  border-radius: 4px;
  background: var(--accent);
  color: var(--on-accent);
  white-space: nowrap;
  margin-top: 0.1rem;
}
.note-item.warn { background: var(--warn-bg); border-color: rgba(217,119,6,0.25); }
.note-item.warn .tag { background: var(--warn); color: var(--on-warn); }
.note-item.crit { background: var(--crit-bg); border-color: rgba(220,38,38,0.25); }
.note-item.crit .tag { background: var(--crit); color: var(--on-crit); }

/* Summary & Action Buttons */
.summary-box {
  margin-top: 1.25rem;
  border-top: 1px solid var(--line);
  padding-top: 1.15rem;
}
.summary-text {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: var(--muted);
  line-height: 1.55;
  background: var(--row);
  padding: 0.9rem;
  border-radius: 8px;
  white-space: pre-line;
  border: 1px solid var(--line);
}
.btn-row {
  display: flex;
  gap: 0.65rem;
  margin-top: 0.85rem;
}
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  padding: 0.6rem 1.15rem;
  border-radius: 8px;
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
  border: 1.5px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  transition: all 0.15s ease;
}
.btn:hover { background: var(--row); }
.btn.solid {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--on-accent);
}
.btn.solid:hover { filter: brightness(1.08); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* Volume Comparison Table */
.tbl-wrap {
  overflow-x: auto;
  margin-top: 0.75rem;
}
table {
  width: 100%;
  border-collapse: collapse;
  font-family: var(--font-mono);
  font-size: 0.82rem;
  text-align: left;
}
th {
  background: var(--row);
  padding: 0.6rem 0.75rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  font-size: 0.72rem;
  border-bottom: 1px solid var(--line);
}
td {
  padding: 0.6rem 0.75rem;
  border-bottom: 1px solid var(--line);
}
tr.active-vol {
  background: var(--accent-soft);
  font-weight: 700;
}
.btn-apply-vol {
  color: var(--accent);
  background: none;
  border: none;
  font-family: var(--font-mono);
  font-weight: 700;
  cursor: pointer;
  text-decoration: underline;
}

/* Saved formulas */
.saved-list {
  list-style: none;
  margin-top: 0.75rem;
  display: grid;
  gap: 0.5rem;
}
.saved-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem 0.9rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}
.saved-item-title { font-weight: 600; font-size: 0.9rem; }
.saved-item-sub { font-family: var(--font-mono); font-size: 0.75rem; color: var(--muted); }

/* Step guide accordion */
details.guide {
  margin-top: 1.5rem;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.15rem;
}
details.guide summary {
  font-weight: 700;
  font-size: 0.95rem;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
details.guide ol {
  margin-top: 0.9rem;
  padding-left: 1.25rem;
  font-size: 0.85rem;
  color: var(--muted);
  display: grid;
  gap: 0.5rem;
  line-height: 1.5;
}
details.guide ol strong { color: var(--ink); }

footer.disclaimer {
  margin-top: 2rem;
  font-size: 0.78rem;
  color: var(--muted);
  border-top: 1px solid var(--line);
  padding-top: 1.25rem;
  display: grid;
  gap: 0.4rem;
}
footer.disclaimer strong { color: var(--ink); }

/* SVG Styling */
svg.syringe-svg { width: 100%; height: auto; display: block; }
.s-glass { fill: var(--glass); stroke: var(--line); stroke-width: 1; }
.s-barrel { fill: none; stroke: var(--ink); stroke-width: 2; }
.s-flange { fill: var(--glass); stroke: var(--ink); stroke-width: 2; }
.s-hub { fill: var(--row); stroke: var(--ink); stroke-width: 2; stroke-linejoin: round; }
.s-needle { fill: none; stroke: var(--muted); stroke-width: 2.5; stroke-linecap: round; }
.s-needle-bevel { stroke: var(--ink); stroke-width: 1.5; }
.s-stopper { fill: var(--stopper); }
.s-rod { fill: var(--rod); stroke: var(--line); stroke-width: 1; }
.s-tick { fill: none; stroke: var(--ink); stroke-width: 1.4; }
.s-tick.major { stroke-width: 2.2; }
.s-num { fill: var(--ink); font: 600 20px var(--font-mono); }
.s-num-zoom { fill: var(--ink); font: 500 5.2px var(--font-mono); font-variant-numeric: tabular-nums; }
.s-cap { fill: var(--muted); font: 500 18px var(--font-mono); }
.s-line { fill: none; stroke: var(--accent); stroke-width: 3; }
.s-tri, .s-pill { fill: var(--accent); }
.s-pilltxt { fill: var(--on-accent); font: 700 22px var(--font-body); }
.syringe-svg.over .s-line { stroke: var(--crit); }
.syringe-svg.over .s-tri, .syringe-svg.over .s-pill { fill: var(--crit); }
.syringe-svg.over .s-pilltxt { fill: var(--on-crit); }
.lgr-heading { display:flex; align-items:center; gap:1.25rem; min-width:0; }
.grid-layout > *, .card, .hero-card { min-width:0; }
.card-header { flex-wrap:wrap; gap:0.5rem; }
.tbl-wrap { max-width:100%; }
.lgr-logo { display:block; position:relative; flex:0 0 140px; width:140px; height:108px; overflow:hidden; background:#fff; border-radius:4px; }
.lgr-logo img { position:absolute; width:168px; height:168px; max-width:none; left:-14px; top:-27px; }
.safety-notice { margin-top:1rem; padding:0.75rem 1rem; border-left:3px solid var(--accent); background:var(--accent-soft); font-size:0.8rem; }
.control { min-width:0; }
.control input { min-width:0; width:100%; }
.control select { min-width:70px; max-width:155px; padding-inline:0.55rem; }
.seg input { display:block; position:absolute; width:1px; height:1px; overflow:hidden; clip-path:inset(50%); white-space:nowrap; }
.seg input:focus-visible + label { outline:2px solid var(--accent); outline-offset:2px; }
.readout-num-wrap, .btn-row, .saved-item, .zoom-box-header, .syringe-box-header { flex-wrap:wrap; }
.readout-num-wrap { min-width:0; }
.readout-num { overflow-wrap:anywhere; max-width:100%; }
.saved-item > div { min-width:0; overflow-wrap:anywhere; }
.saved-item { gap:0.75rem; }
.formula-save { display:flex; gap:0.5rem; margin-top:0.75rem; }
.formula-save input { min-width:0; }
.formula-save button { flex:0 0 auto; }
.btn i, .btn-theme i, .card-title i, .guide summary i { display:inline-flex; }
svg.lucide { width:18px; height:18px; flex:0 0 auto; vertical-align:middle; }
[hidden] { display:none!important; }
#readoutMl:empty, #mathExplainBox:empty, #metricsGrid:empty { display:none; }
:focus-visible { outline:2px solid var(--accent); outline-offset:3px; }
.control input:focus-visible, .control select:focus-visible { outline:none; }
@media (max-width:600px) {
  .lgr-heading { flex-direction:column; align-items:flex-start; gap:0.6rem; }
  .lgr-logo { flex-basis:auto; }
  h1 { font-size:1.6rem; }
  .readout-num { font-size:3rem; }
  .hero-body, .card { padding:1rem; }
  .note-item { flex-direction:column; }
  .syringe-box, .zoom-box { padding:0.6rem; }
  .syringe-box-header, .zoom-box-header { gap:0.4rem; }
  .select-styled, .control select { font-size:16px; }
  .seg label { min-height:74px; }
  .chip { min-height:44px; }
}
.skip-link { position:absolute; top:0; left:1rem; z-index:5; padding:0.75rem; background:var(--panel); color:var(--accent); transform:translateY(-150%); }
.skip-link:focus { transform:none; }
.btn, .btn-theme, .btn-reset, .btn-apply-vol { min-height:44px; touch-action:manipulation; }
.field-label { font-size:0.88rem; font-weight:600; }
.metric-card-val, .metric-card-sub, .summary-text { overflow-wrap:anywhere; }
#suggestionBox { gap:0.75rem; flex-wrap:wrap; }
#suggestionText { flex:1 1 200px; min-width:0; }
#applyFinerBtn { min-height:44px!important; }
.btn-apply-vol:disabled { color:var(--muted); text-decoration:none; cursor:default; }
[data-theme="light"] { color-scheme:light; }
@media (prefers-reduced-motion:reduce) { * { transition:none!important; scroll-behavior:auto!important; } }
