/* base.css
   Reset, typography and the shared components: buttons, fields, cards, chips,
   badges, progress, tabs, segmented controls, switches, dialogs and toasts. */

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
    margin: 0;
    min-height: 100vh;
    background: var(--bg);
    color: var(--ink);
    font: 400 var(--fs-base) / var(--lh-body) var(--font);
    font-feature-settings: 'tnum' 0;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}
h1, h2, h3, h4, h5 { margin: 0; line-height: var(--lh-tight); font-weight: 650; letter-spacing: -0.012em; color: var(--ink); }
h1 { font-size: var(--fs-3xl); }
h2 { font-size: var(--fs-2xl); }
h3 { font-size: var(--fs-xl); }
h4 { font-size: var(--fs-lg); }
p { margin: 0; }
ul, ol { margin: 0; padding: 0; }
img, svg { display: block; max-width: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--brand-strong); text-decoration-thickness: 1px; text-underline-offset: 3px; }
strong, b { font-weight: 650; }
small { font-size: var(--fs-sm); }
hr { border: 0; border-top: 1px solid var(--line); margin: var(--s-6) 0; }
table { border-collapse: collapse; }
[hidden] { display: none !important; }
::selection { background: color-mix(in srgb, var(--brand) 26%, transparent); }

:focus { outline: none; }
:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; border-radius: var(--r-xs); }

.sr-only {
    position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px;
    overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.skip-link {
    position: fixed; left: 12px; top: -60px; z-index: 1000;
    padding: 10px 16px; border-radius: var(--r-sm);
    background: var(--ink); color: var(--surface); text-decoration: none; font-weight: 600;
    transition: top var(--t-med) var(--ease);
}
.skip-link:focus { top: 12px; }

.icon { flex: none; }
.muted { color: var(--ink-3); }
.small { font-size: var(--fs-sm); }
.nowrap { white-space: nowrap; }
.num { font-variant-numeric: tabular-nums; }
.eyebrow { font-size: var(--fs-xs); font-weight: 650; letter-spacing: 0.12em; text-transform: uppercase; color: var(--ink-3); }
.stack > * + * { margin-top: var(--s-4); }
.stack-sm > * + * { margin-top: var(--s-2); }
.row { display: flex; align-items: center; gap: var(--s-3); flex-wrap: wrap; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: var(--s-3); flex-wrap: wrap; }
.grow { flex: 1 1 auto; min-width: 0; }

/* ---------- buttons ---------- */
.btn {
    --btn-bg: var(--surface);
    --btn-ink: var(--ink);
    --btn-line: var(--line-strong);
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    min-height: 40px; padding: 0 16px;
    border: 1px solid var(--btn-line); border-radius: var(--r-pill);
    background: var(--btn-bg); color: var(--btn-ink);
    font-size: var(--fs-md); font-weight: 560; line-height: 1; white-space: nowrap;
    text-decoration: none; cursor: pointer; user-select: none;
    transition: background var(--t-fast) var(--ease), border-color var(--t-fast) var(--ease),
        box-shadow var(--t-fast) var(--ease), transform var(--t-fast) var(--ease), color var(--t-fast);
}
.btn:hover { background: color-mix(in srgb, var(--btn-bg) 92%, var(--ink)); }
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: none; box-shadow: var(--ring); }
.btn[disabled], .btn[aria-disabled="true"] { opacity: 0.5; cursor: not-allowed; transform: none; }
.btn-primary { --btn-bg: var(--brand); --btn-ink: var(--on-brand); --btn-line: transparent; box-shadow: 0 1px 0 rgba(255, 255, 255, 0.18) inset, var(--shadow-1); }
.btn-primary:hover { background: var(--brand-strong); }
:root[data-theme="dark"] .btn-primary:hover { background: color-mix(in srgb, var(--brand) 85%, white); }
.btn-accent { --btn-bg: var(--accent); --btn-ink: #2b1d00; --btn-line: transparent; }
.btn-accent:hover { background: color-mix(in srgb, var(--accent) 88%, black); }
.btn-soft { --btn-bg: var(--brand-soft); --btn-ink: var(--brand-strong); --btn-line: transparent; }
.btn-ghost { --btn-bg: transparent; --btn-line: transparent; --btn-ink: var(--ink-2); }
.btn-ghost:hover { background: var(--surface-2); color: var(--ink); }
.btn-danger { --btn-bg: var(--surface); --btn-ink: var(--bad); --btn-line: color-mix(in srgb, var(--bad) 40%, transparent); }
.btn-danger:hover { background: var(--bad-soft); }
.btn-lg { min-height: 50px; padding: 0 24px; font-size: var(--fs-base); }
.btn-sm { min-height: 32px; padding: 0 12px; font-size: var(--fs-sm); gap: 6px; }
.btn-icon { width: 40px; padding: 0; }
.btn-icon.btn-sm { width: 32px; }
.btn-block { width: 100%; }
.link-btn { background: none; border: 0; padding: 0; color: var(--brand-strong); font-weight: 560; text-decoration: underline; text-underline-offset: 3px; cursor: pointer; }

/* ---------- fields ---------- */
.field { display: grid; gap: 6px; }
.field > label, .label { font-size: var(--fs-sm); font-weight: 600; color: var(--ink-2); }
.hint { font-size: var(--fs-sm); color: var(--ink-3); }
.input, .select, .textarea {
    width: 100%; min-height: 44px; padding: 10px 14px;
    border: 1px solid var(--line-strong); border-radius: var(--r-md);
    background: var(--surface); color: var(--ink);
    transition: border-color var(--t-fast), box-shadow var(--t-fast);
}
.input::placeholder, .textarea::placeholder { color: color-mix(in srgb, var(--ink-3) 80%, transparent); }
.input:focus, .select:focus, .textarea:focus { border-color: var(--brand); box-shadow: var(--ring); }
.textarea { min-height: 112px; resize: vertical; line-height: var(--lh-body); }
.select { appearance: none; padding-right: 40px; background-image: linear-gradient(45deg, transparent 50%, var(--ink-3) 50%), linear-gradient(135deg, var(--ink-3) 50%, transparent 50%); background-position: calc(100% - 20px) 52%, calc(100% - 15px) 52%; background-size: 5px 5px; background-repeat: no-repeat; }
.input-mono { font-family: var(--font-mono); letter-spacing: 0.02em; }
.field-error { color: var(--bad); font-size: var(--fs-sm); font-weight: 500; }
.char-count { font-size: var(--fs-xs); color: var(--ink-3); text-align: right; }

/* ---------- cards ---------- */
.card {
    background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg);
    box-shadow: var(--shadow-1);
}
.card-pad { padding: var(--s-6); }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: var(--s-3); padding: var(--s-5) var(--s-6) 0; }
.card-body { padding: var(--s-5) var(--s-6) var(--s-6); }
.card h3 { font-size: var(--fs-lg); }
.panel { background: var(--surface-2); border-radius: var(--r-md); padding: var(--s-4); }

/* ---------- chips, badges, pills ---------- */
.chip {
    display: inline-flex; align-items: center; gap: 6px; min-height: 28px; padding: 0 10px;
    border-radius: var(--r-pill); border: 1px solid var(--line); background: var(--surface);
    font-size: var(--fs-sm); font-weight: 500; color: var(--ink-2); white-space: nowrap;
}
button.chip { cursor: pointer; }
button.chip:hover { border-color: var(--brand); color: var(--brand-strong); }
.chip[aria-pressed="true"] { background: var(--brand-soft); border-color: transparent; color: var(--brand-strong); }
.badge {
    display: inline-flex; align-items: center; gap: 4px; height: 22px; padding: 0 8px;
    border-radius: var(--r-pill); font-size: var(--fs-xs); font-weight: 650; letter-spacing: 0.02em;
    background: var(--surface-2); color: var(--ink-2); white-space: nowrap;
}
.badge-brand { background: var(--brand-soft); color: var(--brand-strong); }
.badge-good { background: var(--good-soft); color: var(--good); }
.badge-warn { background: var(--warn-soft); color: var(--warn); }
.badge-bad { background: var(--bad-soft); color: var(--bad); }
.badge-info { background: var(--info-soft); color: var(--info); }
.badge-accent { background: var(--accent-soft); color: var(--accent-strong); }
.badge-outline { background: transparent; border: 1px solid var(--line-strong); }

/* ---------- progress ---------- */
.bar { height: 8px; border-radius: var(--r-pill); background: var(--surface-3); overflow: hidden; }
.bar > i { display: block; height: 100%; width: 0; border-radius: inherit; background: var(--brand); transition: width var(--t-slow) var(--ease); }
.bar-sm { height: 6px; }
.ring { --size: 44px; --pct: 0; position: relative; width: var(--size); height: var(--size); flex: none; }
.ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring .ring-track { stroke: var(--surface-3); }
.ring .ring-fill { stroke: var(--brand); transition: stroke-dashoffset var(--t-slow) var(--ease); }
.ring-label { position: absolute; inset: 0; display: grid; place-items: center; font-size: var(--fs-xs); font-weight: 650; font-variant-numeric: tabular-nums; }

/* ---------- tabs and segmented controls ---------- */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab {
    position: relative; padding: 12px 14px; border: 0; background: none; color: var(--ink-3);
    font-weight: 560; font-size: var(--fs-md); white-space: nowrap; cursor: pointer;
}
.tab:hover { color: var(--ink); }
a.tab { text-decoration: none; }
.eyebrow > .icon { display: inline-block; vertical-align: -2px; margin-right: 4px; }
.tab[aria-selected="true"], .tab[aria-current="page"] { color: var(--brand-strong); }
.tab[aria-selected="true"]::after, .tab[aria-current="page"]::after { content: ''; position: absolute; left: 10px; right: 10px; bottom: -1px; height: 3px; border-radius: 3px 3px 0 0; background: var(--brand); }
.seg { display: inline-flex; padding: 3px; gap: 2px; border-radius: var(--r-pill); background: var(--surface-2); border: 1px solid var(--line); }
.seg button {
    min-height: 32px; padding: 0 14px; border: 0; border-radius: var(--r-pill); background: transparent;
    color: var(--ink-2); font-size: var(--fs-sm); font-weight: 560; display: inline-flex; align-items: center; gap: 6px;
}
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--ink); box-shadow: var(--shadow-1); }

/* ---------- switch ---------- */
.switch { display: inline-flex; align-items: center; gap: 12px; cursor: pointer; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch .track { position: relative; width: 42px; height: 24px; border-radius: 12px; background: var(--line-strong); transition: background var(--t-fast); flex: none; }
.switch .track::after { content: ''; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; box-shadow: var(--shadow-1); transition: transform var(--t-med) var(--ease); }
.switch input:checked + .track { background: var(--brand); }
.switch input:checked + .track::after { transform: translateX(18px); }
.switch input:focus-visible + .track { box-shadow: var(--ring); }

/* ---------- avatar ---------- */
.avatar {
    --c: var(--brand);
    width: 36px; height: 36px; border-radius: 50%; flex: none;
    display: grid; place-items: center;
    background: color-mix(in srgb, var(--c) 18%, var(--surface)); color: color-mix(in srgb, var(--c) 80%, var(--ink));
    font-weight: 700; font-size: 0.875rem; letter-spacing: 0.02em;
    border: 2px solid color-mix(in srgb, var(--c) 45%, transparent);
}
.avatar-lg { width: 56px; height: 56px; font-size: 1.25rem; }
.avatar-xl { width: 72px; height: 72px; font-size: 1.5rem; }

/* ---------- callouts ---------- */
.callout {
    display: flex; gap: 12px; align-items: flex-start; padding: 14px 16px; border-radius: var(--r-md);
    background: var(--info-soft); color: var(--ink); font-size: var(--fs-md);
}
.callout .icon { color: var(--info); margin-top: 2px; }
.callout-good { background: var(--good-soft); } .callout-good .icon { color: var(--good); }
.callout-warn { background: var(--warn-soft); } .callout-warn .icon { color: var(--warn); }
.callout-bad { background: var(--bad-soft); } .callout-bad .icon { color: var(--bad); }
.callout-brand { background: var(--brand-soft); } .callout-brand .icon { color: var(--brand-strong); }

/* ---------- dialog ---------- */
.modal-root { position: fixed; inset: 0; z-index: 900; display: grid; place-items: center; padding: 16px; }
.modal-scrim { position: absolute; inset: 0; background: var(--scrim); animation: fade-in var(--t-med) var(--ease); }
.modal {
    position: relative; width: min(520px, 100%); max-height: calc(100vh - 32px); overflow: auto;
    background: var(--surface); border-radius: var(--r-xl); box-shadow: var(--shadow-3);
    padding: var(--s-7); animation: pop-in var(--t-med) var(--ease);
}
.modal-wide { width: min(760px, 100%); }
.modal h2 { font-size: var(--fs-xl); margin-bottom: 8px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: var(--s-6); flex-wrap: wrap; }
.modal-close { position: absolute; top: 14px; right: 14px; }

/* ---------- toast ---------- */
.toasts { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 950; display: grid; gap: 8px; width: min(440px, calc(100% - 32px)); pointer-events: none; }
.toast {
    display: flex; align-items: center; gap: 10px; padding: 12px 16px; border-radius: var(--r-md);
    background: var(--ink); color: var(--surface); box-shadow: var(--shadow-3); font-size: var(--fs-md); font-weight: 500;
    animation: toast-in var(--t-med) var(--ease); pointer-events: auto;
}
.toast .icon { color: var(--accent); }
.toast.good .icon { color: #5be3a1; }
.toast.bad .icon { color: #ff8f99; }
.toast.leaving { animation: toast-out var(--t-med) var(--ease) forwards; }

/* ---------- empty states, tables ---------- */
.empty { display: grid; place-items: center; text-align: center; gap: 10px; padding: var(--s-9) var(--s-6); color: var(--ink-3); }
.empty .icon { color: var(--line-strong); }
.empty h3 { color: var(--ink); font-size: var(--fs-lg); }
.table-wrap { width: 100%; overflow-x: auto; border: 1px solid var(--line); border-radius: var(--r-md); background: var(--surface); }
.table { width: 100%; font-size: var(--fs-md); }
/* Headers keep their own case: column labels carry units and formulas (mL, pH, NaOH). */
.table th { text-align: left; font-size: var(--fs-xs); font-weight: 650; letter-spacing: 0.01em; color: var(--ink-3); background: var(--surface-2); padding: 10px 14px; white-space: nowrap; }
.table td { padding: 12px 14px; border-top: 1px solid var(--line); vertical-align: middle; }
.table tbody tr:hover td { background: var(--brand-softer); }
.table .right { text-align: right; }

kbd { font-family: var(--font-mono); font-size: 0.85em; padding: 1px 6px; border-radius: 5px; border: 1px solid var(--line-strong); background: var(--surface-2); }

@keyframes fade-in { from { opacity: 0; } }
@keyframes pop-in { from { opacity: 0; transform: translateY(8px) scale(0.98); } }
@keyframes toast-in { from { opacity: 0; transform: translateY(12px); } }
@keyframes toast-out { to { opacity: 0; transform: translateY(12px); } }
@keyframes rise-in { from { opacity: 0; transform: translateY(10px); } }

/* Reduced motion switches off interface motion. The lab drawings are left out on
   purpose: bubbles and colour changes are the evidence, so art.css slows them
   down instead of removing them. */
@media (prefers-reduced-motion: reduce) {
    :root:not([data-motion="full"]) :not(.art-stage, .art-stage *), :root:not([data-motion="full"]) ::before, :root:not([data-motion="full"]) ::after { animation-duration: 1ms !important; animation-iteration-count: 1 !important; transition-duration: 1ms !important; scroll-behavior: auto !important; }
}
:root[data-motion="reduce"] :not(.art-stage, .art-stage *), :root[data-motion="reduce"] ::before, :root[data-motion="reduce"] ::after {
    animation-duration: 1ms !important; animation-iteration-count: 1 !important; transition-duration: 1ms !important;
}
