/* ==========================================================================
   CellCalc — styles
   ========================================================================== */
:root {
  --bg:        #f4f6fb;
  --surface:   #ffffff;
  --surface-2: #f0f3fa;
  --ink:       #16202e;
  --ink-soft:  #56637a;
  --muted:     #8a95a8;
  --border:    #e2e7f1;
  --brand:     #2f6df6;
  --brand-ink: #ffffff;
  --brand-soft:#e7effe;
  --accent:    #10a5a0;
  --good:      #128a5a;
  --warn-bg:   #fff5e6;
  --warn-ink:  #9a5a00;
  --err-bg:    #fdecec;
  --err-ink:   #b42318;
  --code-bg:   #eef2fb;
  --shadow:    0 1px 2px rgba(16,32,54,.06), 0 8px 24px rgba(16,32,54,.06);
  --radius:    14px;
  --mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
}

:root[data-theme="dark"] {
  --bg:        #0e1420;
  --surface:   #161d2b;
  --surface-2: #1c2536;
  --ink:       #e8edf6;
  --ink-soft:  #a9b4c7;
  --muted:     #6f7c92;
  --border:    #26303f;
  --brand:     #4d86ff;
  --brand-soft:#182338;
  --accent:    #2bc2bc;
  --good:      #3fd08a;
  --warn-bg:   #2c2410;
  --warn-ink:  #ffcf7a;
  --err-bg:    #331a1a;
  --err-ink:   #ff9a90;
  --code-bg:   #1c2637;
  --shadow:    0 1px 2px rgba(0,0,0,.3), 0 10px 30px rgba(0,0,0,.35);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

code {
  font-family: var(--mono);
  background: var(--code-bg);
  padding: .1em .4em;
  border-radius: 6px;
  font-size: .92em;
}

a { color: var(--brand); text-decoration: none; }

/* ---- Header ---- */
.site-header {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: .75rem clamp(1rem, 4vw, 2.5rem);
  padding-top: calc(.75rem + env(safe-area-inset-top));
  padding-left: max(clamp(1rem, 4vw, 2.5rem), env(safe-area-inset-left));
  padding-right: max(clamp(1rem, 4vw, 2.5rem), env(safe-area-inset-right));
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 50;
  flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: .5rem; font-size: 1.25rem; color: var(--ink); }
.brand-mark { font-size: 1.4rem; }
.brand-text strong { color: var(--brand); }
.top-nav { display: flex; gap: .25rem; margin-left: auto; flex-wrap: wrap; }
.nav-link {
  padding: .4rem .7rem;
  border-radius: 9px;
  color: var(--ink-soft);
  font-size: .88rem;
  font-weight: 500;
  white-space: nowrap;
}
.nav-link:hover { background: var(--surface-2); color: var(--ink); }
.nav-link.active { background: var(--brand-soft); color: var(--brand); }
.theme-toggle {
  border: 1px solid var(--border);
  background: var(--surface-2);
  border-radius: 10px;
  width: 38px; height: 38px;
  font-size: 1.05rem; cursor: pointer;
}

/* ---- View container ---- */
.view {
  max-width: 960px;
  margin: 0 auto;
  padding: clamp(1.25rem, 4vw, 2.75rem) clamp(1rem, 4vw, 1.5rem) 3rem;
}

/* ---- Home ---- */
.hero { text-align: center; margin-bottom: 2rem; }
.hero h1 {
  font-size: clamp(1.7rem, 5vw, 2.6rem);
  line-height: 1.15; margin: 0 0 .6rem;
  letter-spacing: -.02em;
}
.hero-sub { color: var(--ink-soft); max-width: 620px; margin: 0 auto; font-size: 1.05rem; }

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 1rem;
}
.calc-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.4rem;
  display: flex; flex-direction: column; gap: .35rem;
  box-shadow: var(--shadow);
  transition: transform .15s ease, border-color .15s ease;
  color: var(--ink);
}
.calc-card:hover { transform: translateY(-3px); border-color: var(--brand); }
.calc-card-icon { font-size: 1.9rem; }
.calc-card h3 { margin: .3rem 0 0; font-size: 1.15rem; }
.calc-card p { margin: 0; color: var(--ink-soft); font-size: .92rem; flex: 1; }
.calc-card-go { color: var(--brand); font-weight: 600; font-size: .9rem; margin-top: .4rem; }
.home-note {
  margin-top: 1.6rem; text-align: center; color: var(--ink-soft);
  background: var(--surface); border: 1px dashed var(--border);
  border-radius: var(--radius); padding: .9rem 1rem; font-size: .95rem;
}

/* ---- Calculator page ---- */
.back-link { font-size: .9rem; font-weight: 500; display: inline-block; margin-bottom: 1rem; }
.calc-head { display: flex; gap: 1rem; align-items: flex-start; margin-bottom: 1.5rem; }
.calc-head-icon { font-size: 2.4rem; line-height: 1; }
.calc-head h1 { margin: 0 0 .25rem; font-size: clamp(1.4rem, 4vw, 2rem); }
.calc-question { margin: 0; color: var(--ink-soft); max-width: 60ch; }

.calc-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.1fr);
  gap: 1.25rem;
  align-items: start;
}
@media (max-width: 720px) { .calc-layout { grid-template-columns: 1fr; } }

.calc-form, .calc-output {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  box-shadow: var(--shadow);
}

.field { margin-bottom: 1rem; }
.field > label { display: block; font-weight: 600; font-size: .9rem; margin-bottom: .4rem; }
.field .opt { color: var(--muted); font-weight: 400; }
.field-hint { margin: .4rem 0 0; font-size: .8rem; line-height: 1.45; color: var(--ink-soft); }
.field-hint strong { color: var(--ink); font-weight: 600; }
.field-controls { display: flex; gap: .5rem; }
.field-controls input {
  flex: 1; min-width: 0;
  padding: .6rem .7rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-2);
  color: var(--ink);
  font-size: 1rem;
  font-family: var(--mono);
}
.field-controls input:focus,
.unit-select:focus { outline: 2px solid var(--brand); outline-offset: 1px; border-color: var(--brand); }
.unit-select {
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-2);
  color: var(--ink);
  padding: 0 .5rem;
  font-size: .95rem;
  min-width: 72px;
}
.suffix {
  display: flex; align-items: center;
  padding: 0 .7rem;
  color: var(--ink-soft);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: .85rem; white-space: nowrap;
}

.btn-row { display: flex; gap: .5rem; flex-wrap: wrap; margin-top: 1.1rem; }
.btn {
  padding: .6rem 1.1rem; border-radius: 10px; font-size: .95rem;
  font-weight: 600; cursor: pointer; border: 1px solid transparent;
  font-family: inherit;
}
.btn-primary { background: var(--brand); color: var(--brand-ink); }
.btn-primary:hover { filter: brightness(1.06); }
.btn-ghost { background: transparent; border-color: var(--border); color: var(--ink-soft); }
.btn-ghost:hover { background: var(--surface-2); color: var(--ink); }

/* ---- Output ---- */
.output-empty { color: var(--muted); text-align: center; padding: 1.5rem 0; }
.output-empty .muted { font-size: .88rem; }

.result-headline {
  background: var(--brand-soft);
  border: 1px solid color-mix(in srgb, var(--brand) 30%, transparent);
  border-radius: 12px;
  padding: .9rem 1rem;
  font-size: 1.05rem;
  margin-bottom: 1rem;
}
.result-headline strong { color: var(--brand); }
:root[data-theme="dark"] .result-headline strong { color: var(--accent); }

.result-warn { background: var(--warn-bg); color: var(--warn-ink); border-radius: 10px; padding: .75rem .9rem; margin-bottom: 1rem; font-size: .92rem; }
.result-errors { background: var(--err-bg); color: var(--err-ink); border-radius: 10px; padding: .8rem 1rem; }
.result-errors h4 { margin: 0 0 .4rem; }
.result-errors ul { margin: 0; padding-left: 1.1rem; }

.formula-block { margin-bottom: 1.1rem; }
.formula-label, .worked-label {
  display: block; text-transform: uppercase; letter-spacing: .06em;
  font-size: .72rem; font-weight: 700; color: var(--muted); margin-bottom: .4rem;
}
.formula {
  font-family: var(--mono);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: .7rem .9rem;
  font-size: 1rem;
  overflow-x: auto;
}

.steps { list-style: none; counter-reset: step; margin: 0; padding: 0; }
.step {
  counter-increment: step;
  position: relative;
  padding: .55rem 0 .55rem 2rem;
  border-bottom: 1px dashed var(--border);
}
.step:last-child { border-bottom: none; }
.step::before {
  content: counter(step);
  position: absolute; left: 0; top: .5rem;
  width: 1.4rem; height: 1.4rem;
  background: var(--brand-soft); color: var(--brand);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: .78rem; font-weight: 700;
}
.step-label { display: block; font-size: .85rem; color: var(--ink-soft); margin-bottom: .15rem; }
.step-expr { display: block; font-family: var(--mono); font-size: .95rem; }

/* ---- Visualization ---- */
.viz-block { margin-bottom: 1.1rem; }
.viz-label {
  display: block; text-transform: uppercase; letter-spacing: .06em;
  font-size: .72rem; font-weight: 700; color: var(--muted); margin-bottom: .4rem;
}
.viz {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: .6rem;
}
.viz svg { display: block; width: 100%; height: auto; }

/* shared svg element styling (SVG inherits these classes) */
.viz-glass       { stroke: var(--ink-soft); stroke-width: 2.4; stroke-linejoin: round; stroke-linecap: round; }
.viz-liquid      { fill: color-mix(in srgb, var(--brand) 22%, transparent); }
.viz-beaker-fill { fill: color-mix(in srgb, var(--brand) 16%, transparent); }
.viz-solute      { fill: var(--accent); }
.viz-cell        { fill: var(--accent); }
.viz-well        { fill: color-mix(in srgb, var(--brand) 10%, transparent); stroke: var(--ink-soft); stroke-width: 1.2; }
.viz-well.counted { fill: color-mix(in srgb, var(--brand) 20%, transparent); stroke: var(--brand); stroke-width: 2; }
.viz-grid-fine   { stroke: var(--ink-soft); stroke-width: .5; opacity: .5; }
.viz-stock       { fill: var(--brand); }
.viz-diluent     { fill: color-mix(in srgb, var(--ink-soft) 22%, transparent); stroke: var(--border); stroke-width: 1; }
.viz-text        { fill: var(--ink); font-size: 12px; font-weight: 600; font-family: 'Inter', sans-serif; }
.viz-text-soft   { fill: var(--ink-soft); font-size: 11px; font-family: 'Inter', sans-serif; }
.viz-conc        { fill: var(--ink-soft); font-size: 12px; font-family: 'Inter', sans-serif; }
.viz-vol         { fill: var(--ink-soft); font-size: 12px; font-weight: 600; font-family: 'Inter', sans-serif; }
.viz-vol.on      { fill: var(--brand); }
.viz-fill-line   { stroke: var(--ink-soft); stroke-width: 1.4; }
.viz-fill-line.on{ stroke: var(--brand); stroke-width: 1.8; }
.viz-arrow       { stroke: var(--accent); stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.viz-arrow-big   { stroke: var(--ink-soft); stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.viz-chip        { fill: var(--surface); stroke: var(--border); stroke-width: 1.4; }
.viz-chip.on     { fill: var(--brand); stroke: var(--brand); }
.viz-chip-text   { fill: var(--ink); font-size: 12px; font-weight: 700; font-family: var(--mono); }
.viz-chip-text.on{ fill: var(--brand-ink); }
.viz-badge-text  { fill: var(--ink); font-size: 12px; font-weight: 700; font-family: var(--mono); }

/* ---- Results table (serial dilution) ---- */
.table-wrap { margin-top: 1.1rem; overflow-x: auto; }
.result-table {
  width: 100%; border-collapse: collapse; font-size: .9rem;
  font-variant-numeric: tabular-nums;
}
.result-table th, .result-table td {
  padding: .5rem .7rem; text-align: left; border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.result-table thead th {
  text-transform: uppercase; letter-spacing: .05em; font-size: .7rem;
  color: var(--muted); font-weight: 700;
}
.result-table tbody th { font-family: var(--mono); font-weight: 600; color: var(--brand); }
.result-table tbody td { font-family: var(--mono); color: var(--ink); }
.result-table tbody tr:last-child th,
.result-table tbody tr:last-child td { border-bottom: none; }

/* ---- Concept ---- */
.concept {
  margin-top: 1.5rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: .3rem 1.25rem;
  box-shadow: var(--shadow);
}
.concept summary {
  cursor: pointer; font-weight: 600; padding: .8rem 0;
  list-style: none;
}
.concept summary::-webkit-details-marker { display: none; }
.concept[open] summary { border-bottom: 1px solid var(--border); margin-bottom: .8rem; }
.concept-body { padding-bottom: 1rem; color: var(--ink-soft); }
.concept-body code { color: var(--ink); }

/* ---- Footer ---- */
.site-footer {
  text-align: center; padding: 2rem 1rem; color: var(--muted);
  font-size: .85rem; border-top: 1px solid var(--border);
}
.site-footer .credit { margin: .4rem 0 0; font-size: .8rem; }
.site-footer .credit a { color: var(--ink-soft); font-weight: 600; border-bottom: 1px dotted var(--muted); }
.site-footer .credit a:hover { color: var(--brand); border-bottom-color: var(--brand); }

/* remove number-input spinners for a cleaner mono look */
input[type=number]::-webkit-inner-spin-button,
input[type=number]::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
input[type=number] { -moz-appearance: textfield; }

/* ---- Mobile / installed-app refinements ---- */
@media (max-width: 560px) {
  /* The wrapping 4-item nav is noisy on phones — the home cards and the
     "← All calculators" link cover navigation, so hide it here. */
  .top-nav { display: none; }
  .theme-toggle { margin-left: auto; }
  .site-footer { padding-bottom: calc(2rem + env(safe-area-inset-bottom)); }
  /* Bigger tap targets on touch screens */
  .btn { padding: .7rem 1.1rem; }
  .field-controls input, .unit-select { min-height: 46px; }
}

/* When launched from the home screen (installed PWA) */
@media (display-mode: standalone) {
  .view { padding-bottom: calc(3rem + env(safe-area-inset-bottom)); }
}
