:root {
    --paper: #f4efe4;
    --paper-2: #ebe4d4;
    --ink: #161412;
    --ink-2: #4a453d;
    --ink-3: #7c7568;
    --rule: #1614121f;
    --accent: #c4471f;
    --good: #2f7d46;
    --warn: #b0730f;
    /* macro series — validated (light, surface #f4efe4) */
    --protein: #c4471f;
    --carbs: #1668b8;
    --fat: #8a7a1e;

    --display: 'Fraunces', Georgia, serif;
    --body: 'IBM Plex Sans', 'Helvetica Neue', sans-serif;
    --mono: 'IBM Plex Mono', ui-monospace, monospace;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
[hidden] { display: none !important; }
html { background: var(--paper); }

body {
    font-family: var(--body);
    color: var(--ink);
    background:
        radial-gradient(1200px 600px at 85% -10%, #e9dcc0 0%, transparent 60%),
        var(--paper);
    background-attachment: fixed;
    min-height: 100vh;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

.grain {
    position: fixed; inset: 0; pointer-events: none; z-index: 50; opacity: .35; mix-blend-mode: multiply;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 .18 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

.mono { font-family: var(--mono); }
.icon, .icon-lg { fill: none; stroke: currentColor; stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round; }
.icon { width: 18px; height: 18px; }
.icon-lg { width: 40px; height: 40px; stroke-width: 1.25; }

/* ── Masthead ───────────────────────────── */
.masthead {
    display: flex; justify-content: space-between; align-items: flex-end;
    padding: 28px clamp(20px, 5vw, 64px) 18px;
    border-bottom: 2px solid var(--ink);
    animation: rise .6s ease both;
}
.brand { display: flex; gap: 14px; align-items: center; }
.brand-mark {
    width: 46px; height: 46px; display: grid; place-items: center;
    background: var(--accent); color: var(--paper);
    font-family: var(--display); font-weight: 800; font-size: 18px; letter-spacing: -.02em;
    border-radius: 50%;
}
.masthead h1 { font-family: var(--display); font-weight: 800; font-size: clamp(28px, 4vw, 40px); letter-spacing: -.03em; line-height: 1; }
.tagline { color: var(--ink-2); font-size: 14px; margin-top: 4px; }
.issue { font-size: 12px; color: var(--ink-3); letter-spacing: .08em; }

/* ── Layout ─────────────────────────────── */
.layout {
    display: grid; grid-template-columns: minmax(300px, 400px) 1fr; gap: clamp(24px, 4vw, 64px);
    padding: 32px clamp(20px, 5vw, 64px) 48px;
    max-width: 1440px; margin: 0 auto;
}
@media (max-width: 900px) { .layout { grid-template-columns: 1fr; } }

.section-label {
    font-family: var(--mono); font-size: 12px; font-weight: 500; letter-spacing: .14em; text-transform: uppercase;
    color: var(--ink-2); display: flex; gap: 10px; align-items: center; margin-bottom: 16px;
}
.section-label span { color: var(--accent); }
.section-label::after { content: ''; flex: 1; height: 1px; background: var(--rule); }
.section-label.small { margin-bottom: 10px; }

/* ── Intake ─────────────────────────────── */
.intake { animation: rise .6s .1s ease both; }
@media (min-width: 901px) { .intake { position: sticky; top: 24px; align-self: start; } }

.dropzone {
    position: relative; display: block; aspect-ratio: 1; cursor: pointer; overflow: hidden;
    border: 1.5px dashed var(--ink-3); border-radius: 50%;
    background: repeating-radial-gradient(circle at center, transparent 0 22px, #16141208 22px 23px), var(--paper-2);
    transition: border-color .2s, transform .3s;
}
.dropzone:hover, .dropzone.drag { border-color: var(--accent); transform: rotate(-1.5deg); }
.dropzone.has-image { border-style: solid; border-color: var(--ink); border-width: 2px; }
.dz-empty {
    position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 6px; text-align: center; color: var(--ink-2); padding: 20%;
}
.dz-empty strong { font-family: var(--display); font-size: 24px; font-weight: 600; color: var(--ink); margin-top: 6px; }
.dz-empty .hint { font-size: 11px; color: var(--ink-3); letter-spacing: .1em; margin-top: 8px; }
#preview { width: 100%; height: 100%; object-fit: cover; display: block; }
.scanline { position: absolute; inset: 0; pointer-events: none; opacity: 0; }
.scanning .scanline {
    opacity: 1;
    background: linear-gradient(180deg, transparent 0%, #c4471f00 40%, #c4471f55 49%, #f4efe4 50%, #c4471f55 51%, transparent 60%);
    background-size: 100% 250%;
    animation: scan 1.8s ease-in-out infinite alternate;
}
@keyframes scan { from { background-position: 0 100%; } to { background-position: 0 0%; } }

.note-label { display: block; font-size: 13px; font-weight: 500; margin: 22px 0 6px; }
.note-label em { color: var(--ink-3); font-style: normal; font-weight: 400; }
textarea {
    width: 100%; resize: vertical; font: inherit; font-size: 14px; color: var(--ink);
    background: transparent; border: none; border-bottom: 1.5px solid var(--ink); padding: 8px 2px;
}
textarea:focus { outline: none; border-bottom-color: var(--accent); }

.actions { display: flex; gap: 10px; margin-top: 20px; }
button { font: inherit; cursor: pointer; }
.btn-primary {
    flex: 1; display: inline-flex; justify-content: center; align-items: center; gap: 10px;
    background: var(--ink); color: var(--paper); border: none; border-radius: 999px;
    padding: 15px 22px; font-weight: 600; font-size: 15px; letter-spacing: .01em;
    transition: background .2s, transform .15s;
}
.btn-primary:hover:not(:disabled) { background: var(--accent); }
.btn-primary:active:not(:disabled) { transform: scale(.98); }
.btn-primary:disabled { opacity: .35; cursor: not-allowed; }
.btn-ghost {
    background: transparent; border: 1.5px solid var(--ink); color: var(--ink); border-radius: 999px;
    padding: 13px 20px; font-weight: 500;
}
.btn-ghost:hover { background: var(--ink); color: var(--paper); }
.error { margin-top: 14px; color: var(--accent); font-size: 14px; font-weight: 500; }

.history { margin-top: 36px; }
.history ul { list-style: none; display: grid; gap: 2px; }
.history li { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 4px; }
.history li .h-open {
    width: 100%; display: grid; grid-template-columns: 40px minmax(0, 1fr) auto; gap: 12px; align-items: center;
    background: none; border: none; padding: 8px 4px; text-align: left; border-radius: 6px; color: var(--ink);
}
.history li .h-open:hover { background: var(--paper-2); }
.h-del {
    display: inline-flex; align-items: center; gap: 6px; height: 36px; min-width: 36px; justify-content: center;
    border: 1px solid transparent; border-radius: 999px; background: none; color: var(--ink-3); padding: 0 8px; cursor: pointer;
    font: 600 12px/1 var(--body); white-space: nowrap;
}
.h-del:hover, .h-del:focus-visible { color: var(--accent); border-color: var(--rule); }
.h-del span { display: none; }
.h-del.armed { color: #fff; background: var(--accent); border-color: var(--accent); padding: 0 12px; }
.h-del.armed span { display: inline; }
.history img { width: 40px; height: 40px; border-radius: 50%; object-fit: cover; }
.history .h-name { font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.history .h-date { font-size: 11px; color: var(--ink-3); }
.history .h-kcal { white-space: nowrap; font-family: var(--mono); font-size: 13px; font-weight: 500; }

/* ── Placeholder / loading ─────────────── */
.report { min-width: 0; animation: rise .6s .2s ease both; }
.ph-big { font-family: var(--display); font-size: clamp(32px, 4.4vw, 60px); line-height: 1.04; letter-spacing: -.03em; max-width: 14ch; font-weight: 400; }
.ph-big em { color: var(--accent); }
.ph-steps { margin-top: 40px; list-style: none; counter-reset: s; display: grid; gap: 12px; font-size: 13px; color: var(--ink-2); }
.ph-steps li { counter-increment: s; display: flex; gap: 14px; align-items: baseline; border-top: 1px solid var(--rule); padding-top: 12px; max-width: 420px; }
.ph-steps li::before { content: '0' counter(s); color: var(--accent); }

.loading-title { font-family: var(--display); font-size: 40px; letter-spacing: -.02em; }
.dots::after { content: ''; animation: dots 1.2s steps(4) infinite; }
@keyframes dots { 0% { content: ''; } 25% { content: '.'; } 50% { content: '..'; } 75% { content: '...'; } }
.loading-steps { list-style: none; margin-top: 28px; display: grid; gap: 10px; font-size: 13px; }
.loading-steps li { color: var(--ink-3); display: flex; gap: 10px; align-items: center; transition: color .3s; }
.loading-steps li::before { content: ''; width: 8px; height: 8px; border-radius: 50%; border: 1.5px solid currentColor; }
.loading-steps li.active { color: var(--ink); }
.loading-steps li.active::before { background: var(--accent); border-color: var(--accent); animation: pulse 1s infinite; }
.loading-steps li.done { color: var(--ink-2); }
.loading-steps li.done::before { background: var(--ink-2); border-color: var(--ink-2); }
@keyframes pulse { 50% { transform: scale(1.5); } }

/* ── Result ─────────────────────────────── */
.result > * { animation: rise .5s ease both; }
.result > *:nth-child(2) { animation-delay: .06s; }
.result > *:nth-child(3) { animation-delay: .12s; }
.result > *:nth-child(4) { animation-delay: .18s; }
.result > *:nth-child(5) { animation-delay: .24s; }
.result > *:nth-child(6) { animation-delay: .3s; }
@keyframes rise { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }

.r-head { display: flex; flex-wrap: wrap; gap: 8px 16px; align-items: baseline; justify-content: space-between; }
.meal-name { font-family: var(--display); font-weight: 600; font-size: clamp(26px, 3vw, 38px); letter-spacing: -.025em; line-height: 1.1; max-width: 22ch; }
.badges { display: flex; gap: 8px; flex-wrap: wrap; }
.badge { font-family: var(--mono); font-size: 11px; letter-spacing: .08em; text-transform: uppercase; padding: 4px 10px; border: 1px solid var(--ink); border-radius: 999px; display: inline-flex; gap: 6px; align-items: center; }
.badge .icon { width: 13px; height: 13px; }
.summary { color: var(--ink-2); margin-top: 10px; max-width: 70ch; }

.hero {
    display: grid; grid-template-columns: auto 1fr auto; gap: 32px; align-items: end;
    margin-top: 28px; padding: 24px 0; border-top: 2px solid var(--ink); border-bottom: 1px solid var(--rule);
}
@media (max-width: 640px) { .hero { grid-template-columns: 1fr; gap: 20px; } }
.kcal-num { font-family: var(--display); font-weight: 800; font-size: clamp(72px, 10vw, 128px); line-height: .85; letter-spacing: -.05em; font-variant-numeric: tabular-nums; }
.kcal-unit { font-family: var(--mono); font-size: 13px; color: var(--ink-2); margin-top: 8px; letter-spacing: .06em; }
.kcal-unit b { color: var(--ink); font-weight: 500; }

.portion { align-self: center; }
.portion label { font-family: var(--mono); font-size: 11px; letter-spacing: .12em; text-transform: uppercase; color: var(--ink-2); display: block; margin-bottom: 8px; }
.seg { display: inline-flex; border: 1.5px solid var(--ink); border-radius: 999px; padding: 3px; gap: 2px; }
.seg button { border: none; background: none; padding: 6px 12px; border-radius: 999px; font-family: var(--mono); font-size: 13px; color: var(--ink); }
.seg button[aria-pressed="true"] { background: var(--ink); color: var(--paper); }
.seg button:hover:not([aria-pressed="true"]) { background: var(--paper-2); }

.score { text-align: center; }
.score-ring { position: relative; width: 104px; height: 104px; }
.score-ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.score-ring .track { stroke: var(--rule); }
.score-ring .bar { stroke: var(--ink); stroke-linecap: round; transition: stroke-dashoffset 1s ease; }
.score-ring .val { position: absolute; inset: 0; display: flex; justify-content: center; align-items: center; font-family: var(--display); font-weight: 800; font-size: 34px; letter-spacing: -.03em; }
.score-ring .val small { font-size: 13px; color: var(--ink-3); font-family: var(--mono); font-weight: 400; margin: 10px 0 0 2px; }
.score-cap { font-family: var(--mono); font-size: 11px; letter-spacing: .12em; text-transform: uppercase; color: var(--ink-2); margin-top: 6px; }

/* macro split */
.macros { margin-top: 28px; }
.macro-legend { display: flex; flex-wrap: wrap; gap: 6px 22px; margin-bottom: 12px; }
.macro-legend li { list-style: none; display: flex; gap: 8px; align-items: center; font-size: 14px; }
.macro-legend .sw { width: 12px; height: 12px; border-radius: 3px; }
.macro-legend b { font-family: var(--mono); font-weight: 600; }
.macro-legend span.g { font-family: var(--mono); color: var(--ink-3); font-size: 12px; }
.macro-bar { display: flex; gap: 2px; height: 36px; }
.macro-bar .seg-m { border-radius: 4px; min-width: 4px; position: relative; cursor: default; transition: filter .15s, flex-grow .6s ease; }
.macro-bar .seg-m:hover { filter: brightness(1.12); }
.macro-bar .seg-m span { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); font-family: var(--mono); font-size: 12px; font-weight: 600; color: #fff; white-space: nowrap; }
.macro-cap { font-size: 12px; color: var(--ink-3); margin-top: 8px; font-family: var(--mono); }

/* two-column body */
.r-body { display: grid; grid-template-columns: 1fr minmax(260px, 300px); gap: 40px; margin-top: 40px; }
@media (max-width: 1100px) { .r-body { grid-template-columns: 1fr; } }

/* items table */
.items-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.items-table th { font-family: var(--mono); font-size: 10.5px; letter-spacing: .1em; text-transform: uppercase; color: var(--ink-3); font-weight: 500; text-align: right; padding: 0 8px 8px; border-bottom: 1.5px solid var(--ink); }
.items-table th:first-child, .items-table td:first-child { text-align: left; padding-left: 0; }
.items-table td { padding: 12px 8px; border-bottom: 1px solid var(--rule); text-align: right; font-family: var(--mono); font-variant-numeric: tabular-nums; vertical-align: top; }
.items-table td:first-child { font-family: var(--body); }
.items-table .it-name { font-weight: 600; }
.items-table .it-sub { font-size: 12px; color: var(--ink-3); }
.items-table td.kc { font-weight: 600; }
.items-table tfoot td { border-bottom: none; border-top: 1.5px solid var(--ink); font-weight: 600; }
.table-wrap { overflow-x: auto; }

/* nutrition facts label */
.facts { border: 2px solid var(--ink); padding: 10px 12px 12px; background: #fbf8f1; font-size: 14px; align-self: start; }
.facts h3 { font-family: var(--display); font-weight: 800; font-size: 34px; letter-spacing: -.02em; line-height: 1; border-bottom: 1px solid var(--ink); padding-bottom: 4px; }
.facts .serv { font-size: 13px; padding: 4px 0 6px; border-bottom: 10px solid var(--ink); display: flex; justify-content: space-between; gap: 8px; }
.facts .cal { display: flex; justify-content: space-between; align-items: end; border-bottom: 5px solid var(--ink); padding: 4px 0; }
.facts .cal b { font-family: var(--display); font-weight: 800; font-size: 28px; }
.facts .cal strong { font-family: var(--display); font-weight: 800; font-size: 40px; line-height: 1; }
.facts .dv-head { text-align: right; font-size: 11px; font-weight: 600; border-bottom: 1px solid var(--ink); padding: 3px 0; }
.facts .row { display: flex; justify-content: space-between; border-bottom: 1px solid var(--ink); padding: 3px 0; }
.facts .row.sub { padding-left: 16px; }
.facts .row.thick { border-bottom-width: 5px; }
.facts .row b { font-weight: 700; }
.facts .row .pct { font-weight: 700; font-family: var(--mono); font-size: 13px; }
.facts .foot-n { font-size: 10.5px; color: var(--ink-2); margin-top: 6px; line-height: 1.35; }

/* notes */
.notes { margin-top: 48px; }
.notes-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0; border-top: 2px solid var(--ink); }
@media (max-width: 900px) { .notes-grid { grid-template-columns: 1fr; } }
.note-col { padding: 18px 20px 18px 0; }
.note-col + .note-col { padding-left: 20px; border-left: 1px solid var(--rule); }
@media (max-width: 900px) { .note-col + .note-col { padding-left: 0; border-left: none; border-top: 1px solid var(--rule); } }
.note-col h4 { display: flex; align-items: center; gap: 8px; font-family: var(--mono); font-size: 11px; letter-spacing: .12em; text-transform: uppercase; font-weight: 600; margin-bottom: 12px; }
.note-col.good h4 { color: var(--good); }
.note-col.watch h4 { color: var(--warn); }
.note-col.do h4 { color: var(--accent); }
.note-col ul { list-style: none; display: grid; gap: 10px; font-size: 14.5px; }
.note-col li { padding-left: 16px; position: relative; }
.note-col li::before { content: '—'; position: absolute; left: 0; color: var(--ink-3); }
.verdict { font-family: var(--display); font-size: clamp(20px, 2vw, 26px); line-height: 1.3; letter-spacing: -.01em; margin: 0 0 22px; max-width: 48ch; font-weight: 400; }
.verdict::before { content: '“'; color: var(--accent); }
.verdict::after { content: '”'; color: var(--accent); }

.extras { display: grid; grid-template-columns: 1fr 1fr; gap: 40px; margin-top: 40px; }
@media (max-width: 900px) { .extras { grid-template-columns: 1fr; } }
.micro { list-style: none; display: grid; gap: 10px; }
.micro li { display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; font-size: 14px; }
.micro .mbar { grid-column: 1 / -1; height: 6px; background: var(--paper-2); border-radius: 3px; overflow: hidden; }
.micro .mbar i { display: block; height: 100%; background: var(--ink); border-radius: 0 3px 3px 0; }
.micro .amt { font-family: var(--mono); font-size: 13px; color: var(--ink-2); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { font-size: 13px; padding: 4px 12px; border-radius: 999px; background: var(--ink); color: var(--paper); }
.assume { list-style: none; display: grid; gap: 6px; font-size: 13px; color: var(--ink-2); margin-top: 18px; }
.assume li::before { content: '› '; color: var(--accent); }
.muted { color: var(--ink-3); font-size: 14px; }

.notfood { margin-top: 20px; padding: 24px; border: 2px solid var(--ink); font-size: 16px; }

/* tooltip */
.tooltip {
    position: fixed; z-index: 60; pointer-events: none; background: var(--ink); color: var(--paper);
    padding: 8px 12px; border-radius: 6px; font-size: 13px; line-height: 1.4; max-width: 240px;
    box-shadow: 0 8px 24px #16141233;
}
.tooltip b { font-family: var(--mono); }

.foot { padding: 20px clamp(20px, 5vw, 64px) 32px; font-size: 11.5px; color: var(--ink-3); border-top: 1px solid var(--rule); letter-spacing: .02em; }

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation: none !important; transition: none !important; }
}
@media (max-width: 520px) { .issue { display: none; } .hero .score { justify-self: start; } }

/* ── Language ───────────────────────────── */
.section-label b { font-weight: inherit; }
.mast-right { display: flex; flex-direction: column; align-items: flex-end; gap: 10px; }
.lang-pick {
    position: relative; display: inline-flex; align-items: center; gap: 6px;
    border: 1px solid var(--ink); border-radius: 999px; padding: 0 10px 0 12px; height: 34px; color: var(--ink);
    background: color-mix(in srgb, var(--paper) 70%, transparent); cursor: pointer;
}
.lang-pick:focus-within { outline: 2px solid var(--accent); outline-offset: 2px; }
.lang-pick select {
    appearance: none; -webkit-appearance: none; border: none; background: none; color: inherit; cursor: pointer;
    font: 500 13px/1 var(--body); padding: 0 18px 0 0; margin-right: -18px; outline: none; max-width: 150px;
}
.lang-pick .chev { width: 14px; height: 14px; pointer-events: none; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.badge.busy { border-color: var(--accent); color: var(--accent); }
.badge.busy .icon { animation: spin 2s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.result.translating .meal-name, .result.translating .summary, .result.translating .items-table tbody,
.result.translating .notes, .result.translating .extras { opacity: .45; transition: opacity .3s; }

/* CJK & Thai: script fonts come from langFonts(); no wide tracking or display tightening on those scripts */
:is([data-script="cjk"], [data-script="thai"]) .section-label, :is([data-script="cjk"], [data-script="thai"]) .badge, :is([data-script="cjk"], [data-script="thai"]) .score-cap,
:is([data-script="cjk"], [data-script="thai"]) .portion label, :is([data-script="cjk"], [data-script="thai"]) .items-table th, :is([data-script="cjk"], [data-script="thai"]) .note-col h4,
:is([data-script="cjk"], [data-script="thai"]) .kcal-unit { letter-spacing: .04em; }
:is([data-script="cjk"], [data-script="thai"]) .ph-big { max-width: 16em; line-height: 1.2; letter-spacing: 0; }
:is([data-script="cjk"], [data-script="thai"]) .meal-name, :is([data-script="cjk"], [data-script="thai"]) .verdict { letter-spacing: 0; }
:is([data-script="cjk"], [data-script="thai"]) .ph-steps, :is([data-script="cjk"], [data-script="thai"]) .loading-steps, :is([data-script="cjk"], [data-script="thai"]) .foot { font-family: var(--body); }
@media (max-width: 520px) { .mast-right .issue { display: none; } }

/* ── Daily intake ───────────────────────── */
.daily {
    max-width: 1440px; margin: 0 auto; padding: 28px clamp(20px, 5vw, 64px) 30px;
    border-bottom: 1px solid var(--rule); animation: rise .6s .05s ease both;
}
.daily .section-label em { font-style: normal; text-transform: none; letter-spacing: .04em; color: var(--ink-3); }
.daily-grid { display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr); gap: clamp(24px, 4vw, 64px); }
@media (max-width: 900px) { .daily-grid { grid-template-columns: 1fr; } }

.meter { --st: var(--ink); display: grid; grid-template-columns: auto 1fr; gap: 28px; align-items: center; }
.meter.st-on { --st: var(--good); }
.meter.st-near { --st: var(--warn); }
.meter.st-over { --st: var(--accent); }
@media (max-width: 520px) { .meter { grid-template-columns: 1fr; gap: 18px; } }
.meter-ring { position: relative; width: 168px; height: 168px; }
.meter-ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.meter-ring .track { stroke: var(--paper-2); }
.meter-ring .bar { stroke: var(--st); stroke-linecap: round; transition: stroke-dashoffset 1s ease, stroke .3s; }
.meter-ring .extra { stroke: var(--accent); stroke-linecap: round; }
.m-val { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.m-val b { font-family: var(--display); font-weight: 800; font-size: 46px; line-height: 1; letter-spacing: -.04em; font-variant-numeric: tabular-nums; }
.m-val small { font-size: 20px; margin-left: 1px; }
.m-val span { font-family: var(--mono); font-size: 10.5px; letter-spacing: .12em; text-transform: uppercase; color: var(--ink-3); margin-top: 4px; }

.m-status { display: inline-flex; align-items: center; gap: 8px; color: var(--st); font-family: var(--mono); font-size: 12px; font-weight: 600; letter-spacing: .12em; text-transform: uppercase; border: 1.5px solid currentColor; border-radius: 999px; padding: 4px 12px; }
.m-status .icon { width: 15px; height: 15px; }
.m-stats { display: grid; grid-template-columns: repeat(3, auto); justify-content: start; gap: 4px 28px; margin-top: 14px; }
.m-stats dt { font-family: var(--mono); font-size: 10.5px; letter-spacing: .12em; text-transform: uppercase; color: var(--ink-3); }
.m-stats dd { font-family: var(--display); font-weight: 600; font-size: 28px; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.m-stats .m-diff dd { color: var(--st); }
.m-bar { position: relative; height: 8px; background: var(--paper-2); border-radius: 4px; margin-top: 12px; }
.m-bar i { display: block; height: 100%; background: var(--st); border-radius: 4px; transition: width .8s ease; }
.m-bar .m-tick { position: absolute; top: -4px; bottom: -4px; width: 2px; background: var(--ink); }
.m-advice { font-size: 14.5px; color: var(--ink-2); margin-top: 12px; max-width: 60ch; }
.d-profile { font-size: 12px; color: var(--ink-2); margin-top: 18px; display: flex; gap: 10px; flex-wrap: wrap; align-items: baseline; }
.d-basis { font-size: 11.5px; color: var(--ink-3); margin-top: 4px; max-width: 72ch; line-height: 1.4; }
.link-btn { background: none; border: none; padding: 0; color: var(--accent); text-decoration: underline; text-underline-offset: 3px; font: inherit; text-align: left; }

.profile-form { border: 1.5px solid var(--ink); border-radius: 14px; padding: 20px 22px; background: #fbf8f1; }
.pf-title { font-family: var(--display); font-weight: 600; font-size: 24px; letter-spacing: -.02em; }
.pf-intro { color: var(--ink-2); font-size: 14px; margin-top: 2px; }
.pf-field { margin-top: 16px; }
.pf-label { display: block; font-family: var(--mono); font-size: 11px; letter-spacing: .12em; text-transform: uppercase; color: var(--ink-2); margin-bottom: 6px; }
.seg-wrap { flex-wrap: wrap; border-radius: 22px; }
.pf-actions { display: flex; gap: 10px; margin-top: 20px; }
.pf-actions .btn-primary { flex: 0 1 auto; padding: 12px 24px; }
.pf-actions .btn-ghost { padding: 11px 20px; }

.log-list { list-style: none; display: grid; }
.log-list li { display: grid; grid-template-columns: auto minmax(0, 1fr) auto auto auto; gap: 12px; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--rule); font-size: 14px; }
.l-time { font-size: 12px; color: var(--ink-3); }
.l-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
button.l-name { color: var(--ink); text-decoration-color: var(--rule); }
button.l-name:hover { color: var(--accent); }
.l-mult { font-size: 11px; color: var(--ink-3); }
.l-kcal { font-weight: 600; font-variant-numeric: tabular-nums; }
.l-rm { background: none; border: none; color: var(--ink-3); padding: 4px; border-radius: 50%; display: grid; }
.l-rm:hover { color: var(--accent); background: var(--paper-2); }
.l-rm .icon { width: 15px; height: 15px; }
.daily .section-label .d-total { margin-left: auto; color: var(--ink); font-weight: 600; }
.daily-log .section-label::after { display: none; }
.daily-log .section-label { border-bottom: 1.5px solid var(--ink); padding-bottom: 8px; margin-bottom: 0; }
.daily-log .muted { padding: 12px 0; }

.manual { display: grid; grid-template-columns: minmax(0, 1fr) 90px auto; gap: 10px; margin-top: 14px; }
.manual input {
    font: inherit; font-size: 14px; color: var(--ink); background: transparent; border: none;
    border-bottom: 1.5px solid var(--ink); padding: 8px 2px; min-width: 0;
}
.manual input:focus { outline: none; border-bottom-color: var(--accent); }
.manual .btn-ghost { display: inline-flex; gap: 6px; align-items: center; padding: 8px 16px; font-size: 14px; }
.manual .btn-ghost .icon { width: 15px; height: 15px; }

.btn-log {
    display: inline-flex; align-items: center; gap: 8px; margin-top: 16px;
    background: var(--ink); color: var(--paper); border: none; border-radius: 999px;
    padding: 10px 18px; font-size: 14px; font-weight: 600; transition: background .2s;
}
.btn-log:hover:not(:disabled) { background: var(--accent); }
.btn-log.done { background: transparent; color: var(--good); border: 1.5px solid var(--good); cursor: default; }
.btn-log .icon { width: 16px; height: 16px; }

:is([data-script="cjk"], [data-script="thai"]) .m-status, :is([data-script="cjk"], [data-script="thai"]) .m-stats dt, :is([data-script="cjk"], [data-script="thai"]) .m-val span, :is([data-script="cjk"], [data-script="thai"]) .pf-label { letter-spacing: .04em; }
:is([data-script="cjk"], [data-script="thai"]) .pf-title { letter-spacing: 0; }

/* daily macros */
.d-macros { margin-top: 28px; }
.d-macros .section-label { border-bottom: 1.5px solid var(--ink); padding-bottom: 8px; margin-bottom: 12px; }
.dm-tiles { list-style: none; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; margin-bottom: 12px; }
.dm-tiles li { display: grid; gap: 2px; align-content: start; }
.dm-label { display: flex; align-items: center; gap: 7px; font-size: 13px; color: var(--ink-2); }
.dm-label .sw { width: 10px; height: 10px; border-radius: 3px; flex: none; }
.dm-g { font-family: var(--display); font-weight: 600; font-size: 26px; letter-spacing: -.02em; line-height: 1.1; font-variant-numeric: tabular-nums; }
.dm-g small { font-family: var(--mono); font-size: 12px; font-weight: 400; color: var(--ink-3); }
.dm-pct { font-size: 11px; color: var(--ink-3); }
.dm-st { display: inline-flex; align-items: center; gap: 4px; font-size: 11px; font-weight: 600; margin-top: 2px; }
.dm-st .icon { width: 13px; height: 13px; flex: none; }
.dm-st.st-ok { color: var(--good); }
.dm-st.st-low, .dm-st.st-high { color: var(--warn); }
.dm-bar { height: 24px; }
@media (max-width: 420px) { .dm-tiles { gap: 10px; } .dm-g { font-size: 22px; } }
.dm-pct > span { white-space: nowrap; }

/* weekly chart */
.week { margin-top: 30px; }
.week .section-label em { font-style: normal; text-transform: none; letter-spacing: .04em; color: var(--ink-3); }
.wk-stats { display: grid; grid-template-columns: repeat(3, auto); justify-content: start; gap: 4px 28px; margin-bottom: 14px; }
.wk-stats dt { font-family: var(--mono); font-size: 10.5px; letter-spacing: .12em; text-transform: uppercase; color: var(--ink-3); }
.wk-stats dd { font-family: var(--display); font-weight: 600; font-size: 22px; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.wk-stats dd small { font-family: var(--mono); font-size: 12px; color: var(--ink-3); font-weight: 400; }

/* plot is 140px; day label + status icon add 40px below it */
.wk-chart { --plot: 140px; position: relative; display: grid; grid-template-columns: repeat(7, 1fr); gap: 0; height: calc(var(--plot) + 40px); }
.wk-col { --st: var(--ink); display: grid; grid-template-rows: var(--plot) 20px 20px; justify-items: center; border-radius: 6px; cursor: default; }
.wk-col:hover { background: #16141208; }
.wk-col.st-on { --st: var(--good); }
.wk-col.st-near { --st: var(--warn); }
.wk-col.st-over { --st: var(--accent); }
.wk-plot { position: relative; width: 100%; height: 100%; display: flex; align-items: flex-end; justify-content: center; border-bottom: 1px solid var(--ink); }
.wk-bar { display: block; width: min(28px, 62%); background: var(--st); border-radius: 4px 4px 0 0; min-height: 3px; transition: height .6s ease; }
.wk-empty { display: block; width: min(28px, 62%); height: 3px; border-radius: 2px; background: var(--paper-2); }
.wk-col.future .wk-empty { background: none; border-top: 1.5px dotted var(--ink-3); opacity: .5; }
.wk-val { position: absolute; left: 50%; transform: translate(-50%, -4px); font-size: 11px; font-weight: 600; white-space: nowrap; color: var(--ink); background: var(--paper); padding: 0 3px; border-radius: 3px; z-index: 2; }
.wk-day { font-family: var(--mono); font-size: 11px; color: var(--ink-3); align-self: end; }
.wk-col.today .wk-day { color: var(--ink); font-weight: 600; }
.wk-st { color: var(--st); display: grid; place-items: center; }
.wk-st .icon { width: 13px; height: 13px; }
.wk-target { position: absolute; left: 0; right: 0; border-top: 1.5px dashed var(--ink-2); pointer-events: none; z-index: 1; }
.wk-target em { position: absolute; right: 0; bottom: 2px; font-style: normal; font-size: 10px; color: var(--ink-2); background: var(--paper); padding: 0 4px; border-radius: 3px; }
:is([data-script="cjk"], [data-script="thai"]) .wk-stats dt { letter-spacing: .04em; }

/* period controls */
.wk-ctrl { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 18px; }
.seg-sm button { padding: 5px 12px; font-size: 12px; }
.wk-nav { display: flex; align-items: center; gap: 8px; }
.wk-nav .link-btn { font-family: var(--mono); font-size: 12px; margin-right: 4px; }
.wk-arrow { width: 36px; height: 36px; display: grid; place-items: center; border: 1.5px solid var(--ink); border-radius: 50%; background: none; color: var(--ink); }
.wk-arrow:hover:not(:disabled) { background: var(--ink); color: var(--paper); }
.wk-arrow:disabled { opacity: .25; cursor: not-allowed; }
.wk-arrow .icon { width: 18px; height: 18px; }
.wk-chart { --below: 56px; height: calc(var(--plot) + var(--below)); }
.wk-col { grid-template-rows: var(--plot) 36px 20px; }
.wk-day { display: flex; flex-direction: column; align-items: center; line-height: 1.25; }
.wk-day small { font-size: 10.5px; opacity: .8; }

/* actions + dialog */
.d-actions { display: flex; justify-content: space-between; align-items: center; gap: 16px; flex-wrap: wrap; margin-top: 36px; padding-top: 20px; border-top: 1px solid var(--rule); }
.d-actions .btn-ghost { display: inline-flex; align-items: center; gap: 8px; padding: 10px 18px; font-size: 14px; }
.d-reset { display: inline-flex; align-items: center; gap: 6px; font-family: var(--mono); font-size: 13px; }
.d-reset:disabled { color: var(--ink-3); text-decoration: none; cursor: not-allowed; opacity: .6; }
.d-actions .icon, .d-dialog .icon { width: 16px; height: 16px; }
.btn-danger { background: var(--accent); color: #fff; border: 1.5px solid var(--accent); border-radius: 999px; padding: 11px 20px; font-weight: 600; display: inline-flex; align-items: center; gap: 8px; }
.btn-danger:hover { filter: brightness(.92); }
.d-dialog { margin: auto; border: none; border-radius: 18px; padding: 0; background: var(--paper); color: var(--ink); max-width: min(520px, calc(100vw - 24px)); width: 100%; box-shadow: 0 24px 60px #16141240; }
.d-dialog::backdrop { background: #161412a0; backdrop-filter: blur(2px); }
.dd-body { padding: 28px; display: grid; gap: 14px; }
.dd-icon { --st: var(--accent); color: var(--st); }
.dd-icon .icon { width: 28px; height: 28px; }
.dd-title { font-family: var(--display); font-weight: 600; font-size: 24px; letter-spacing: -.01em; }
.dd-text { color: var(--ink-2); font-size: 15px; line-height: 1.55; }
.dd-check { display: flex; gap: 10px; align-items: center; font-size: 14px; }
.dd-check input { width: 18px; height: 18px; accent-color: var(--accent); }
.dd-actions { display: flex; justify-content: flex-end; gap: 10px; flex-wrap: wrap; margin-top: 6px; }
.dd-actions .btn-ghost, .dd-actions .btn-primary { padding: 11px 20px; display: inline-flex; align-items: center; gap: 8px; text-decoration: none; font-size: 14px; }
.dd-image img { width: 100%; max-height: 58vh; object-fit: contain; object-position: top; border: 1px solid var(--rule); border-radius: 8px; background: var(--paper-2); -webkit-touch-callout: default; }

/* 30-day trend */
.wk-chart { grid-template-columns: repeat(var(--n, 7), 1fr); }
.wk-long { --below: 30px; }
.wk-long .wk-col { grid-template-rows: var(--plot) 30px; border-radius: 3px; }
.wk-long .wk-st { display: none; }
.wk-long .wk-bar, .wk-long .wk-empty { width: min(10px, 70%); }
.wk-long .wk-bar { border-radius: 3px 3px 0 0; }
.wk-long .wk-day { font-size: 10.5px; white-space: nowrap; overflow: visible; width: 0; align-items: center; padding-top: 6px; }
.wk-long .wk-plot { border-bottom-width: 1px; }
.wk-ma { position: absolute; left: 0; top: 0; width: 100%; height: var(--plot); overflow: visible; pointer-events: none; z-index: 2; }
.wk-ma path { fill: none; stroke: var(--ink); stroke-width: 2.5px; stroke-linejoin: round; stroke-linecap: round; vector-effect: non-scaling-stroke; }
.wk-ma path.halo { stroke: var(--paper); stroke-width: 6px; }
.wk-legend { display: flex; flex-wrap: wrap; gap: 6px 16px; margin-top: 12px; font-size: 11.5px; color: var(--ink-2); }
.wk-legend li { --st: var(--ink); display: inline-flex; align-items: center; gap: 6px; }
.wk-legend li.st-on { --st: var(--good); } .wk-legend li.st-near { --st: var(--warn); } .wk-legend li.st-over { --st: var(--accent); }
.wk-legend .icon { width: 12px; height: 12px; color: var(--st); }
.lg-ma { width: 20px; height: 2.5px; background: var(--ink); border-radius: 2px; }
.lg-target { width: 20px; border-top: 1.5px dashed var(--ink-2); }
.lg-st { width: 9px; height: 12px; background: var(--st); border-radius: 2px; }
.wk-stats { grid-template-columns: none; grid-auto-flow: column; grid-auto-columns: max-content; }
@media (max-width: 560px) {
    .wk-stats:has(> div:nth-child(4)) { grid-auto-flow: row; grid-template-columns: repeat(2, max-content); }
}

/* result card button */
.hero-actions { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-top: 18px; }
.hero-actions .btn-log { margin-top: 0; }
.btn-card { display: inline-flex; align-items: center; gap: 8px; padding: 10px 16px; border: 1.5px solid var(--ink); border-radius: 999px; background: none; color: var(--ink); font-size: 14px; font-weight: 500; }
.btn-card:hover { background: var(--ink); color: var(--paper); }
.btn-card .icon { width: 16px; height: 16px; }

/* Thai: tall stacked vowel/tone marks need more leading on tight display type */
[data-script="thai"] .ph-big, [data-script="thai"] .meal-name, [data-script="thai"] .masthead h1,
[data-script="thai"] .loading-title, [data-script="thai"] .facts h3 { line-height: 1.4; }
.dz-empty strong, .ph-big, .meal-name, .pf-title { text-wrap: balance; }
.brand, .brand > div { min-width: 0; }
.masthead h1 { overflow-wrap: anywhere; hyphens: auto; }
@media (max-width: 520px) {
    .masthead { flex-wrap: wrap; gap: 14px; padding-top: 16px; }
    .mast-right { order: -1; width: 100%; }
}
.facts { min-width: 0; }
.facts h3 { font-size: clamp(24px, 7.5vw, 34px); overflow-wrap: anywhere; hyphens: auto; }
/* Long localized headers (de/fr/es…) must not widen the page: clamp the column, scroll only the table */
@media (max-width: 1100px) { .r-body { grid-template-columns: minmax(0, 1fr); } }
.r-body > div:first-child { min-width: 0; overflow-x: auto; }
@media (max-width: 520px) {
    .items-table th { letter-spacing: .03em; padding-inline: 4px; }
    .items-table td { padding-inline: 4px; }
}

/* ── Membership: sign-in gate + account bar ─ */
.auth { display: none; }
body.locked .daily, body.locked .layout { display: none; }
body.locked .auth {
    display: grid; grid-template-columns: minmax(0, 1fr) minmax(300px, 440px); gap: clamp(28px, 6vw, 96px); align-items: center;
    padding: clamp(36px, 7vw, 96px) clamp(20px, 5vw, 64px); max-width: 1440px; margin: 0 auto; min-height: 62vh;
    animation: rise .6s ease both;
}
@media (max-width: 900px) {
    body.locked .auth { grid-template-columns: minmax(0, 1fr); padding-top: 28px; }
    .auth-pitch .ph-big { font-size: clamp(28px, 8vw, 40px); }
    .auth-pitch .ph-steps { display: none; }
}
.auth-form { display: grid; gap: 12px; border: 1.5px solid var(--ink); border-radius: 14px; padding: 26px 24px; background: #fbf8f1; }
.auth-form .pf-intro { margin-bottom: 8px; line-height: 1.5; }
.auth-form .pf-intro b { color: var(--ink); font-weight: 600; overflow-wrap: anywhere; }
.auth-label { font-family: var(--mono); font-size: 11px; letter-spacing: .12em; text-transform: uppercase; color: var(--ink-2); }
.auth-form input {
    font: inherit; font-size: 18px; color: var(--ink); background: transparent; border: none;
    border-bottom: 1.5px solid var(--ink); padding: 8px 2px 10px; min-width: 0; width: 100%;
}
.auth-form input:focus { outline: none; border-bottom-color: var(--accent); }
.auth-form .code-in { font-family: var(--mono); font-size: 32px; font-weight: 600; letter-spacing: .42em; }
.auth-form .code-in::placeholder { color: #16141226; }
.auth-form .error { margin-top: 0; }
.auth-form .btn-primary { margin-top: 6px; }
.auth-links { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.link-btn { background: none; border: none; padding: 4px 0; color: var(--ink); font-size: 14px; text-decoration: underline; text-underline-offset: 3px; }
.link-btn:hover:not(:disabled) { color: var(--accent); }
.link-btn:disabled { color: var(--ink-3); text-decoration: none; cursor: default; }
.auth-fine { display: flex; gap: 8px; align-items: flex-start; font-size: 13px; color: var(--ink-3); line-height: 1.45; }
.auth-fine .icon { width: 15px; height: 15px; flex: none; margin-top: 2px; }
:is([data-script="cjk"], [data-script="thai"]) .auth-label { letter-spacing: .04em; font-family: var(--body); }

.account { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--ink); max-width: 100%; }
.account .icon { width: 16px; height: 16px; flex: none; }
.acc-email { font-weight: 500; min-width: 0; max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.acc-count { font-size: 12px; color: var(--ink-3); white-space: nowrap; }
.acc-count::before { content: '·'; margin-right: 8px; }
.acc-out {
    background: none; border: 1px solid var(--ink); border-radius: 999px; padding: 4px 12px; font-size: 12px; color: var(--ink); white-space: nowrap;
}
.acc-out:hover { background: var(--ink); color: var(--paper); }
@media (max-width: 520px) {
    .mast-right { flex-direction: row; flex-wrap: wrap; justify-content: space-between; align-items: center; }
    .acc-email { max-width: 42vw; }
}

/* Domain sign-off, bottom right of every page */
.foot { display: flex; justify-content: space-between; align-items: center; gap: 8px 24px; flex-wrap: wrap; }
.foot p { flex: 1 1 320px; max-width: 70ch; }
.site-tag {
    margin-left: auto; font-family: var(--mono); font-weight: 600; font-size: 13px; letter-spacing: .02em;
    line-height: 1.2; color: #000; text-decoration: none; white-space: nowrap;
}
.site-tag em { color: inherit; font-style: inherit; }
.site-tag:hover { text-decoration: underline; text-underline-offset: 3px; }
