/* EasyPoolChem — calm, clean, readable in sunlight. Mobile first. */
:root {
  --bg: #f5f8f7;
  --surface: #ffffff;
  --surface-2: #eef4f3;
  --ink: #102a31;
  --muted: #4d6168;
  --line: #d3dfdf;
  --accent: #0b6e7a;
  --accent-ink: #08525b;
  --accent-soft: #dff0ef;
  --ok: #17703f;
  --ok-soft: #e1f3e8;
  --low: #8a4f00;
  --low-soft: #fdf0d9;
  --high: #a8261c;
  --high-soft: #fbe5e2;
  --warn-soft: #fff6e0;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 42, 49, .06), 0 2px 8px rgba(16, 42, 49, .05);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d1a1d;
    --surface: #132428;
    --surface-2: #182e33;
    --ink: #e3eef0;
    --muted: #a3b8bd;
    --line: #2a4248;
    --accent: #5ac6d1;
    --accent-ink: #8ddbe3;
    --accent-soft: #173a40;
    --ok: #6fd39a;
    --ok-soft: #173525;
    --low: #f1b45a;
    --low-soft: #3a2b12;
    --high: #ff8a7f;
    --high-soft: #3d1c19;
    --warn-soft: #33290f;
    --shadow: none;
  }
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 17px/1.6 var(--font); }
img, svg { max-width: 100%; height: auto; }
a { color: var(--accent-ink); text-underline-offset: 2px; }
a:hover { text-decoration-thickness: 2px; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
h1, h2, h3 { line-height: 1.25; margin: 1.6em 0 .5em; letter-spacing: -.01em; }
h1 { font-size: 1.9rem; margin-top: .3em; }
h2 { font-size: 1.35rem; }
h3 { font-size: 1.1rem; }
p, ul, ol { margin: 0 0 1em; }
.small { font-size: .9rem; color: var(--muted); }
.skip { position: absolute; left: -9999px; }
.skip:focus { left: 8px; top: 8px; background: var(--surface); padding: 8px 12px; z-index: 10; }

.wrap { max-width: 1120px; margin: 0 auto; padding: 0 16px; }
.narrow { max-width: 760px; }

/* Header */
.site-header { background: var(--surface); border-bottom: 1px solid var(--line); }
.header-row { display: flex; align-items: center; justify-content: space-between; min-height: 60px; gap: 12px; }
.wordmark, .footer-brand { display: inline-flex; align-items: center; gap: 8px; color: var(--ink); text-decoration: none; font-size: 1.2rem; letter-spacing: -.01em; }
.wordmark b, .footer-brand b { font-weight: 700; color: var(--accent); }
.logo-mark { color: var(--accent); flex: none; }
.header-nav { display: flex; align-items: center; gap: 14px; }
.header-nav a { color: var(--ink); text-decoration: none; font-weight: 600; }
.mypool-btn { font: inherit; font-weight: 600; color: var(--accent-ink); background: var(--accent-soft); border: 1px solid transparent; border-radius: 999px; padding: 6px 14px; cursor: pointer; }
.mypool-btn[data-saved="1"]::after { content: " ✓"; }

.crumbs { font-size: .88rem; color: var(--muted); margin: 14px 0 0; }
.crumbs a { color: var(--muted); }
.subtitle { color: var(--muted); margin: 0 0 16px; font-size: 1.05rem; }

/* Tool layout */
.tool-wrap { display: grid; gap: 16px; align-items: start; }
@media (min-width: 900px) {
  .tool-wrap { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 24px; }
  .tool-wrap.tool-wide { grid-template-columns: minmax(0, 5fr) minmax(0, 6fr); }
  .result-panel { position: sticky; top: 12px; }
}
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.panel > h2:first-child, .panel > h3:first-child, fieldset > legend + * { margin-top: 0; }
.panel h2 { font-size: 1.1rem; margin: 0 0 12px; }
fieldset { border: 0; padding: 0; margin: 0 0 14px; min-width: 0; }
legend { font-weight: 700; padding: 0; margin-bottom: 8px; }

.grid2 { display: grid; gap: 12px; grid-template-columns: 1fr 1fr; }
.grid3 { display: grid; gap: 12px; grid-template-columns: repeat(3, 1fr); }
@media (max-width: 420px) { .grid3 { grid-template-columns: 1fr 1fr; } }
.span2 { grid-column: 1 / -1; }
.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field > span { font-size: .88rem; font-weight: 600; color: var(--ink); }
.field .hint { font-size: .8rem; font-weight: 400; color: var(--muted); }
input, select, textarea { font: inherit; color: var(--ink); background: var(--surface); border: 1.5px solid var(--line); border-radius: 8px; padding: 10px 11px; min-height: 46px; width: 100%; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); outline: none; box-shadow: 0 0 0 3px var(--accent-soft); }
input[aria-invalid="true"] { border-color: var(--high); }
.unit-input { position: relative; }
.unit-input input { padding-right: 52px; }
.unit-input .unit { position: absolute; right: 11px; top: 50%; transform: translateY(-50%); color: var(--muted); font-size: .88rem; pointer-events: none; }

/* Segmented choices (radio buttons) */
.seg { display: flex; flex-wrap: wrap; gap: 6px; }
.seg label { position: relative; }
.seg input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.seg span { display: inline-block; padding: 8px 12px; border: 1.5px solid var(--line); border-radius: 999px; cursor: pointer; font-size: .92rem; background: var(--surface); min-height: 40px; line-height: 1.4; }
.seg input:checked + span { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
@media (prefers-color-scheme: dark) { .seg input:checked + span { color: #062227; } }
.seg input:focus-visible + span { outline: 3px solid var(--accent); outline-offset: 2px; }

/* Buttons */
.btn { font: inherit; font-weight: 600; font-size: .95rem; display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 44px; padding: 8px 16px; border-radius: 8px; border: 1.5px solid var(--line); background: var(--surface); color: var(--ink); cursor: pointer; text-decoration: none; }
.btn:hover { border-color: var(--accent); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
@media (prefers-color-scheme: dark) { .btn-primary { color: #062227; } }
.btn-small { min-height: 36px; padding: 5px 12px; font-size: .88rem; }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.icon-btn { font: inherit; background: none; border: 0; color: var(--muted); font-size: 1.1rem; cursor: pointer; padding: 6px 10px; min-height: 40px; }
.link-btn { font: inherit; background: none; border: 0; padding: 0; color: var(--accent-ink); text-decoration: underline; cursor: pointer; }

/* Results */
.result-panel { border-color: var(--accent); border-width: 2px; }
.result-empty { color: var(--muted); }
.big { font-size: 2rem; font-weight: 750; line-height: 1.15; letter-spacing: -.02em; margin: 0; }
.big small { font-size: 1rem; font-weight: 500; color: var(--muted); letter-spacing: 0; }
.sub { color: var(--muted); margin: 4px 0 12px; }
.exact { font-size: .85rem; color: var(--muted); }
.steps { padding-left: 0; list-style: none; counter-reset: step; margin: 12px 0; }
.steps > li { counter-increment: step; position: relative; padding: 2px 0 12px 38px; }
.steps > li::before { content: counter(step); position: absolute; left: 0; top: 0; width: 26px; height: 26px; border-radius: 50%; background: var(--accent-soft); color: var(--accent-ink); font-weight: 700; display: grid; place-items: center; font-size: .9rem; }
.steps > li b.dose { white-space: nowrap; }
.note { border-radius: 8px; padding: 10px 12px; margin: 10px 0; font-size: .93rem; }
.note-safety { background: var(--warn-soft); border-left: 4px solid var(--low); }
.note-info { background: var(--surface-2); border-left: 4px solid var(--accent); }
.note-alert { background: var(--high-soft); border-left: 4px solid var(--high); }
.note p:last-child, .note ul:last-child { margin-bottom: 0; }
.note ul { padding-left: 18px; }
.result-actions { border-top: 1px solid var(--line); padding-top: 10px; margin-top: 12px; }
.save-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-top: 10px; }

/* Status badges and reading table */
.badge { display: inline-block; font-size: .78rem; font-weight: 700; text-transform: uppercase; letter-spacing: .03em; padding: 2px 8px; border-radius: 999px; white-space: nowrap; }
.badge-ok { background: var(--ok-soft); color: var(--ok); }
.badge-low { background: var(--low-soft); color: var(--low); }
.badge-high { background: var(--high-soft); color: var(--high); }
.badge-na { background: var(--surface-2); color: var(--muted); }
table { border-collapse: collapse; width: 100%; font-size: .93rem; }
th, td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: .82rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); }
.table-scroll { overflow-x: auto; }

/* Content */
.content-grid { display: grid; gap: 24px; margin-top: 8px; }
@media (min-width: 1000px) { .content-grid { grid-template-columns: minmax(0, 1fr) 300px; } }
.prose { max-width: 760px; }
.prose ol, .prose ul { padding-left: 22px; }
.prose li { margin-bottom: .35em; }
.example { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.formula { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .9rem; background: var(--surface-2); padding: 10px 12px; border-radius: 8px; overflow-x: auto; white-space: pre-wrap; }
details.faq { border-bottom: 1px solid var(--line); padding: 10px 0; }
details.faq summary { font-weight: 650; cursor: pointer; padding: 4px 0; }
details.faq > div { padding-top: 6px; }
.disclaimer { font-size: .88rem; color: var(--muted); border-top: 1px solid var(--line); padding-top: 14px; margin-top: 28px; }
.tool-list { list-style: none; padding: 0 !important; display: grid; gap: 10px; }
@media (min-width: 640px) { .tool-list { grid-template-columns: 1fr 1fr; } }
.tool-list a { display: block; padding: 12px 14px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); text-decoration: none; color: var(--ink); height: 100%; }
.tool-list a:hover { border-color: var(--accent); }
.tool-list b { display: block; color: var(--accent-ink); }
.tool-list span { font-size: .9rem; color: var(--muted); }
.embed-code { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: .8rem; min-height: 0; margin-bottom: 8px; }
.figure { margin: 1em 0; text-align: center; }
.figure svg { max-width: 420px; width: 100%; }
.figure figcaption { font-size: .85rem; color: var(--muted); }
.diagram-ink { stroke: var(--ink); }
.diagram-water { fill: var(--accent-soft); stroke: var(--accent); }
.diagram-dim { stroke: var(--accent-ink); }
.diagram-text { fill: var(--ink); font: 13px var(--font); }

/* Ad slots: fixed heights so nothing jumps when ads load */
.ad-slot { margin: 20px auto; min-height: 280px; width: 100%; max-width: 728px; }
.ad-slot--below-result { min-height: 280px; }
.ad-slot--in-article { min-height: 280px; }
.ad-slot--sidebar { min-height: 600px; display: none; }
@media (min-width: 1000px) { .ad-slot--sidebar { display: block; position: sticky; top: 12px; } .ad-slot--below-result { min-height: 100px; } }
.ad-slot--end { min-height: 250px; }

/* Footer */
.site-footer { background: var(--surface); border-top: 1px solid var(--line); margin-top: 48px; padding: 28px 0 8px; }
.footer-grid { display: grid; gap: 20px; }
@media (min-width: 760px) { .footer-grid { grid-template-columns: 2fr 1fr 1fr; } }
.footer-h { font-size: .85rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin: 0 0 8px; }
.site-footer ul { list-style: none; padding: 0; margin: 0; }
.site-footer li { margin-bottom: 6px; font-size: .93rem; }
.copyright { border-top: 1px solid var(--line); padding-top: 10px; }

/* My Pool dialog */
dialog.mypool { border: 1px solid var(--line); border-radius: 14px; padding: 0; width: min(640px, calc(100% - 24px)); background: var(--surface); color: var(--ink); }
dialog.mypool::backdrop { background: rgba(5, 20, 24, .55); }
.mypool-form { padding: 16px; }
.mypool-head { display: flex; justify-content: space-between; align-items: center; }
.mypool-head h2 { margin: 0; }
@media (max-width: 520px) { .mypool .grid2 { grid-template-columns: 1fr; } }

/* Home */
.hero-note { background: var(--accent-soft); border-radius: var(--radius); padding: 12px 14px; }
.log-list { font-size: .9rem; }

/* Embedded version */
body.embedded { background: var(--surface); }
body.embedded .tool-page { padding: 12px 0; }
.embed-credit { text-align: center; font-size: .85rem; }

/* Print: only the result card and a short header */
@media print {
  body { background: #fff; color: #000; font-size: 12pt; }
  .site-header, .site-footer, .crumbs, .content-grid, .ad-slot, .result-actions, .input-panel, dialog, .save-row, .embed-credit, .no-print { display: none !important; }
  .tool-wrap { display: block; }
  .panel { border: 1px solid #999; box-shadow: none; }
  .result-panel { position: static; }
  .print-only { display: block !important; }
  a { color: #000; }
}
.print-only { display: none; }
.field > .unit-input { font-size: 1rem; font-weight: 400; color: var(--ink); }

.chart th[scope=row] { font-size: .93rem; text-transform: none; letter-spacing: 0; color: var(--ink); }
th[scope=row] { text-transform: none; letter-spacing: 0; font-size: .93rem; color: var(--ink); }
@media print { .text-page .prose { max-width: none; } table { font-size: 9.5pt; } h2 { margin-top: 1em; } .text-page h2 { break-after: avoid; } }
.swatches { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
@media (min-width: 640px) { .swatches { grid-template-columns: repeat(4, 1fr); } }
.swatch { position: relative; }
.swatch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.swatch > span { display: flex; flex-direction: column; gap: 4px; padding: 8px; border: 2px solid var(--line); border-radius: 10px; cursor: pointer; height: 100%; background: var(--surface); }
.swatch b { font-size: .92rem; }
.swatch small { font-size: .78rem; color: var(--muted); line-height: 1.3; }
.swatch input:checked + span { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }
.swatch input:focus-visible + span { outline: 3px solid var(--accent); outline-offset: 2px; }
.check { display: flex; gap: 10px; align-items: flex-start; padding: 6px 0; cursor: pointer; font-size: .95rem; }
.check input { width: 20px; height: 20px; min-height: 0; margin-top: 2px; flex: none; accent-color: var(--accent); }
