@font-face {
    font-family: "Libre Baskerville";
    src: url("/assets/libre-baskerville-latin.woff2") format("woff2");
    font-style: normal;
    font-weight: 400;
    font-display: swap;
}
:root {
    color-scheme: light;
    --bg: #f6f8f5;
    --surface: #ffffff;
    --text: #193c32;
    --muted: #596d62;
    --border: #d4ded7;
    --control-border: #85958b;
    --accent: #176149;
    --accent-hover: #104c38;
    --on-accent: #ffffff;
    --result: #e9f0e5;
    --danger: #a02e33;
    --focus: #277958;
    --hero: #103b2f;
    --hero-text: #ffffff;
    --citrus: #deed9c;
    --scroll-thumb: #85958b;
    --scroll-track: var(--bg);
    --scroll-hover: #596d62;
    --scroll-active: #193c32;
    --font-body: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    --font-display: "Libre Baskerville", Georgia, serif;
    --panel-gutter: clamp(32px, 4vw, 72px);
    --radius: 12px;
    --motion: 160ms;
    font-family: var(--font-body);
    background: var(--bg);
    color: var(--text);
    scrollbar-color: var(--scroll-thumb) var(--scroll-track);
    scrollbar-width: auto;
    scrollbar-gutter: stable;
}
:root[data-theme="dark"] {
    color-scheme: dark;
    --bg: #14231f;
    --surface: #1c3028;
    --text: #edf3e9;
    --muted: #a8bbae;
    --border: #40554a;
    --control-border: #6e8978;
    --accent: #c8dfa2;
    --accent-hover: #deedb7;
    --on-accent: #183425;
    --result: #243b2c;
    --danger: #ffb0ad;
    --focus: #c8dfa2;
    --scroll-thumb: #6e8978;
    --scroll-hover: #a8bbae;
    --scroll-active: #edf3e9;
}
* { box-sizing: border-box; }
body { margin: 0; }
* { scrollbar-color: var(--scroll-thumb) var(--scroll-track); }
::-webkit-scrollbar { width: 12px; height: 12px; }
::-webkit-scrollbar-track { background: var(--scroll-track); }
::-webkit-scrollbar-thumb { background: var(--scroll-thumb); border: 3px solid var(--scroll-track); border-radius: 8px; }
::-webkit-scrollbar-thumb:hover { background: var(--scroll-hover); }
::-webkit-scrollbar-thumb:active { background: var(--scroll-active); }
[hidden] { display: none !important; /* Preserve semantic hidden state across component display rules. */ }
button, input, select { font: inherit; }
button, select, summary, a, .segments label { cursor: pointer; -webkit-tap-highlight-color: transparent; }
a { color: inherit; }
button { color: inherit; }
button:disabled { cursor: wait; opacity: .65; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 4px; }
p, h1, h2 { margin: 0; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; border: 0; }
.skip-link { position: fixed; top: 12px; left: 12px; padding: 12px; background: var(--surface); z-index: 5; transform: translateY(-200%); }
.skip-link:focus { transform: none; }
.split-layout { display: grid; grid-template-columns: 1fr 1fr; min-height: 100svh; }
.intro { position: sticky; top: 0; height: 100svh; min-height: 560px; overflow: hidden; isolation: isolate; display: flex; flex-direction: column; justify-content: space-between; padding: var(--panel-gutter); color: var(--hero-text); background: var(--hero); }
.intro-image { position: absolute; inset: 0; z-index: -2; width: 100%; height: 100%; object-fit: cover; }
.intro::after { content: ""; position: absolute; inset: 0; z-index: -1; background: linear-gradient(180deg, rgba(10,36,27,.65) 0%, rgba(10,36,27,.48) 24%, rgba(10,36,27,.86) 66%, rgba(10,36,27,.96) 100%); }
.brand { display: inline-flex; align-items: center; gap: 10px; width: fit-content; text-decoration: none; font-size: 25px; font-weight: 750; letter-spacing: -1px; }
.brand:hover { color: var(--citrus); }
.brand:active { opacity: .75; }
.brand-mark { width: 32px; height: 32px; }
.brand-light { font-weight: 400; }
.brand-dot { color: var(--citrus); }
.intro-copy { margin-top: auto; padding: 64px 0 48px; }
.eyebrow { font-size: 11px; font-weight: 650; letter-spacing: .15em; text-transform: uppercase; display: flex; align-items: center; gap: 8px; }
.intro .eyebrow { color: var(--citrus); margin-bottom: 24px; }
h1 { font: 400 clamp(48px, 5.4vw, 88px)/1.12 var(--font-display); letter-spacing: -.025em; white-space: pre-line; }
.intro-description { max-width: 360px; margin-top: 28px; font-size: 17px; line-height: 1.7; color: #eef3e9; }
.intro-note { padding-top: 24px; border-top: 1px solid rgba(255,255,255,.3); font-size: 12px; letter-spacing: .015em; display: flex; gap: 12px; align-items: center; }
.intro-note span { color: var(--citrus); font-size: 24px; }
.workspace { min-width: 0; display: flex; flex-direction: column; padding: 20px var(--panel-gutter) 16px; }
.workspace-header { display: flex; justify-content: flex-end; margin-bottom: 24px; }
.preferences { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.segments { display: inline-flex; border: 1px solid var(--border); background: var(--result); padding: 3px; margin: 0; border-radius: 9px; min-width: 0; }
.segments label { position: relative; display: flex; }
.segments input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.segments label > span { display: grid; place-items: center; border-radius: 6px; min-width: 42px; min-height: 36px; padding: 0 11px; font-size: 12px; color: var(--muted); transition: background var(--motion), color var(--motion); }
.segments input:checked + span { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px #00000012; font-weight: 650; }
.segments label:hover span { color: var(--text); }
.segments input:focus-visible + span { outline: 3px solid var(--focus); outline-offset: 3px; }
.segments input:active + span { background: var(--border); }
.language select { border: 0; background: transparent; color: var(--text); font-size: 12px; min-height: 32px; padding: 0 3px; }
.language select:hover { color: var(--accent); }
.calculator { width: 100%; max-width: 460px; margin: 0 auto; }
.calculator-heading { margin-bottom: 20px; }
h2 { font: 400 clamp(28px, 2.7vw, 38px)/1.2 var(--font-display); letter-spacing: -.025em; margin-bottom: 16px; }
.muted { color: var(--muted); font-size: 14px; line-height: 1.7; max-width: 38ch; }
.field { margin-bottom: 14px; }
.field > label, .field-heading > label { font-size: 13px; font-weight: 650; }
.field > label { display: block; margin-bottom: 8px; }
.field-heading { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.control { display: block; width: 100%; color: var(--text); background: var(--surface); border: 1px solid var(--control-border); border-radius: var(--radius); transition: border-color var(--motion); }
.control:hover { border-color: var(--muted); }
.control:focus { border-color: var(--accent); }
.control[aria-invalid="true"] { border-color: var(--danger); }
.food-select { height: 44px; padding: 0 16px; font-size: 16px; text-overflow: ellipsis; }
.weight-input { height: 58px; padding: 8px 16px; font-size: 32px; letter-spacing: -.03em; font-variant-numeric: tabular-nums; }
.weight-input::placeholder { color: var(--muted); opacity: 1; font-size: 28px; }
.field-feedback { min-height: 22px; }
.field-help, .field-error { font-size: 12px; line-height: 1.5; margin-top: 4px; }
.field-help { color: var(--muted); }
.field-error { color: var(--danger); }
.button { display: inline-flex; align-items: center; justify-content: center; gap: 12px; border: 1px solid transparent; border-radius: var(--radius); min-height: 46px; padding: 10px 20px; font-size: 14px; font-weight: 650; transition: background var(--motion); }
.button-primary { background: var(--accent); color: var(--on-accent); }
.button-primary:hover:not(:disabled) { background: var(--accent-hover); }
.button-primary:active:not(:disabled) { transform: translateY(1px); }
.calculate-button { width: 100%; position: relative; }
.button-arrow, .spinner { position: absolute; right: 20px; }
.button-arrow { font-size: 23px; font-weight: 400; }
.spinner { width: 18px; height: 18px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.form-message { min-height: 12px; padding-top: 4px; color: var(--danger); font-size: 12px; line-height: 1.5; }
.result-panel { padding: 20px; background: var(--result); border: 1px solid var(--border); border-radius: var(--radius); }
.result-label { color: var(--muted); font-size: 12px; font-weight: 650; }
#result { min-height: 72px; display: flex; flex-direction: column; justify-content: center; padding: 12px 0; }
.result-empty { color: var(--muted); font-size: 14px; }
.result-value { font: 500 clamp(36px, 4vw, 52px)/1.1 var(--font-body); letter-spacing: -.035em; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.result-unit { font: 400 20px var(--font-body); color: var(--muted); margin-left: 8px; }
.result-context { font-size: 12px; color: var(--muted); margin-top: 8px; overflow-wrap: anywhere; }
.explanation { margin-top: 4px; font-size: 12px; color: var(--muted); }
.explanation summary { display: flex; justify-content: space-between; align-items: center; min-height: 44px; list-style: none; }
.explanation summary::-webkit-details-marker { display: none; }
.explanation summary:hover { color: var(--text); }
.explanation summary span { font-size: 19px; }
.explanation[open] summary span { transform: rotate(45deg); }
.explanation p { line-height: 1.7; padding-bottom: 12px; }
.workspace-footer { display: flex; justify-content: space-between; align-items: start; gap: 24px; margin-top: auto; padding-top: 8px; color: var(--muted); font-size: 11px; }
.workspace-footer > span { padding-top: 12px; }
.text-link { border: 0; background: none; padding: 12px 0; font-size: 12px; font-weight: 600; text-decoration: underline; text-underline-offset: 4px; color: var(--text); }
.text-link:hover { color: var(--accent); }
.text-link:active { opacity: .7; }
.install-area { text-align: right; max-width: 280px; }
.install-area p { line-height: 1.6; padding-top: 8px; }
.connection-status { color: var(--danger); font-size: 12px; line-height: 1.6; padding-top: 12px; }
@media (min-width: 1600px) { .calculator { max-width: 500px; } }
@media (max-width: 800px) {
    .split-layout { grid-template-columns: 1fr; }
    .intro { position: relative; height: auto; min-height: 0; padding: 12px 20px; gap: 8px; }
    .intro-image { object-position: center 45%; }
    .intro::after { background: linear-gradient(90deg, rgba(10,36,27,.92), rgba(10,36,27,.56)); }
    .brand { font-size: 21px; gap: 6px; }
    .brand-mark { width: 26px; height: 26px; }
    .intro-copy { padding: 0; margin: 0; }
    .intro .eyebrow, .intro-note { display: none; }
    h1 { font-size: clamp(28px, 5vw, 40px); white-space: normal; letter-spacing: -.025em; }
    .intro-description { font-size: 12px; line-height: 1.4; margin-top: 6px; max-width: 43ch; }
    .workspace { padding: 8px 20px max(8px, env(safe-area-inset-bottom)); }
    .workspace-header { margin-bottom: 8px; }
    .preferences { width: 100%; justify-content: space-between; }
    .calculator { margin: 0 auto; max-width: 500px; }
    .calculator-heading { margin-bottom: 12px; }
    .field { margin-bottom: 10px; }
    .result-panel { padding: 14px 20px; }
    h2 { font-size: 28px; margin-bottom: 6px; }
    .workspace-footer { max-width: 500px; width: 100%; margin: 0 auto; }
}
@media (max-width: 800px) and (max-height: 650px) {
    .intro { padding-block: 10px; gap: 6px; }
    .intro-description { display: none; }
    h1 { font-size: 26px; }
    .calculator-heading .muted { display: none; }
    .calculator-heading { margin-bottom: 8px; }
    .result-panel { padding: 12px 16px; }
    #result { min-height: 64px; padding: 8px 0; }
}
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation-duration: 0s !important; transition-duration: 0s !important; /* Respect the system motion preference. */ }
}
@media (forced-colors: active) {
    * { scrollbar-color: auto; }
    .segments input:checked + span { outline: 2px solid Highlight; }
    .intro::after { background: Canvas; }
    .intro { color: CanvasText; }
    .intro-description, .intro .eyebrow { color: CanvasText; }
}

/* Compact preferences keep the primary task close to the top of the page. */
.theme-picker { padding: 2px; }
.theme-picker label > span { min-width: 30px; min-height: 28px; padding: 0 6px; }
.theme-picker svg { width: 17px; height: 17px; }
.unit-picker label > span { min-height: 28px; }
.search-box { position: relative; margin-bottom: 8px; }
.search-input { height: 38px; padding: 6px 40px 6px 12px; font-size: 16px; }
.search-input::-webkit-search-cancel-button { display: none; }
.search-clear { position: absolute; right: 1px; top: 1px; width: 36px; height: 36px; border: 0; border-radius: var(--radius); background: transparent; color: var(--muted); font-size: 22px; }
.search-clear:hover { background: var(--result); color: var(--text); }
.search-clear:active { background: var(--border); }
@media (max-width: 800px) {
    .calculator-heading .muted { font-size: 12px; line-height: 1.5; max-width: none; }
    .result-value { font-size: 36px; }
}
/* Prioritize the answer on phone-sized viewports; keep natural scrolling for zoom,
   validation errors, and the on-screen keyboard instead of clipping content. */
@media (max-width: 800px) and (max-height: 760px) {
    .intro-description, .calculator-heading .muted { display: none; }
}
@media (max-width: 800px) and (max-height: 650px) {
    .intro .brand { display: none; }
    .field-feedback { min-height: 0; }
    .field-help { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
}
