:root {
    --bg: #eef1ec;
    --surface: #f8faf6;
    --ink: #1b2420;
    --muted: #64706a;
    --line: #d5dcd4;
    --accent: #355e3b;
    --accent-ink: #f4f8f2;
    --danger: #a3361f;
    --pending: #b7832b;
    --radius-photo: 10px;
    --radius-ui: 999px;
    --gutter: 16px;
    --font: 'Schibsted Grotesk', ui-sans-serif, system-ui, -apple-system, sans-serif;
    color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #121614;
        --surface: #1a201d;
        --ink: #e4eae5;
        --muted: #8f9b94;
        --line: #2b332f;
        --accent: #86b58d;
        --accent-ink: #0f1a12;
        --danger: #e07a62;
        --pending: #d9a64e;
    }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--ink);
    font: 400 16px/1.45 var(--font);
    -webkit-font-smoothing: antialiased;
}

[hidden] { display: none !important; }

a { color: inherit; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* --- buttons and forms */

.btn {
    font: inherit;
    font-weight: 600;
    padding: 10px 18px;
    border-radius: var(--radius-ui);
    border: 1px solid var(--line);
    background: var(--surface);
    color: var(--ink);
    cursor: pointer;
}
.btn:disabled { opacity: .6; cursor: default; }
.btn--primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn--danger { color: var(--danger); }

.icon-btn {
    display: inline-grid;
    place-items: center;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: 0;
    background: none;
    color: var(--ink);
    cursor: pointer;
    text-decoration: none;
}
.icon-btn:hover { background: var(--line); }

.text-link { font-weight: 600; text-decoration: none; padding: 8px 6px; }
.text-link:hover { text-decoration: underline; }

.stack { display: flex; flex-direction: column; gap: 8px; }
label { font-weight: 600; font-size: 14px; }
input[type=email], input[type=password], input[type=datetime-local] {
    font: inherit;
    padding: 11px 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
    color: var(--ink);
    width: 100%;
}
.hint { color: var(--muted); font-size: 14px; margin: 0; }
.form-error { color: var(--danger); min-height: 1.4em; margin: 8px 0 0; font-size: 14px; }

/* --- auth */

.auth { min-height: 100dvh; display: grid; place-items: center; padding: var(--gutter); }
.auth-box { width: 100%; max-width: 360px; }
.auth-lede { color: var(--muted); margin: 4px 0 28px; }
.auth-switch { font-size: 14px; color: var(--muted); }
.auth .btn--primary { margin-top: 12px; }

.wordmark { font-weight: 800; letter-spacing: -0.04em; font-size: 22px; text-decoration: none; margin: 0; }
.wordmark--large { font-size: 56px; line-height: 1; }

/* --- shell */

.app { min-height: 100dvh; padding-bottom: calc(120px + env(safe-area-inset-bottom)); }

.topbar {
    position: sticky;
    top: 0;
    z-index: 5;
    display: grid;
    grid-template-columns: auto 1fr auto;
    align-items: center;
    gap: 8px;
    padding: calc(8px + env(safe-area-inset-top)) var(--gutter) 8px;
    background: color-mix(in srgb, var(--bg) 88%, transparent);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
}
.pager { display: flex; align-items: center; justify-content: center; gap: 2px; min-width: 0; }
.title { font-size: 16px; font-weight: 700; margin: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; text-align: center; min-width: 0; }
.topbar-end { display: flex; align-items: center; gap: 2px; }

@media (max-width: 899px) {
    .topbar { grid-template-columns: 1fr auto; }
    .topbar .wordmark { display: none; }
    .pager { justify-content: flex-start; }
    .title { text-align: left; }
}

.banner {
    margin: 0 var(--gutter) 8px;
    padding: 10px 14px;
    border-radius: 8px;
    background: color-mix(in srgb, var(--pending) 18%, var(--surface));
    font-size: 14px;
}

.main { padding: 8px var(--gutter) 24px; max-width: 760px; margin: 0 auto; }
.main--week { max-width: none; }

/* --- meals: the time is the loudest thing on the page */

.meal { padding: 14px 0 18px; border-top: 1px solid var(--line); }
.meal:first-child { border-top: 0; }
.meal-head { display: flex; align-items: baseline; gap: 10px; margin: 0 0 10px; font-weight: 400; }
.meal-time { font-size: 44px; font-weight: 750; letter-spacing: -0.035em; line-height: 1; }
.meal-name { font-size: 15px; color: var(--muted); }
.meal-photos {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    scroll-snap-type: x mandatory;
    scroll-padding-inline: var(--gutter);
    margin: 0 calc(-1 * var(--gutter));
    padding: 0 var(--gutter);
    scrollbar-width: none;
}
.meal-photos::-webkit-scrollbar { display: none; }

.ph {
    flex: 0 0 auto;
    width: min(62vw, 300px);
    aspect-ratio: 1;
    padding: 0;
    border: 0;
    border-radius: var(--radius-photo);
    overflow: hidden;
    background: var(--line);
    cursor: zoom-in;
    scroll-snap-align: start;
    position: relative;
}
.ph img { width: 100%; height: 100%; object-fit: cover; display: block; }
.ph img:not([src]) { visibility: hidden; }
.ph--pending::after, .ph--failed::after {
    content: '';
    position: absolute;
    right: 8px;
    bottom: 8px;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--pending);
    box-shadow: 0 0 0 3px var(--surface);
}
.ph--pending img { opacity: .82; }
.ph--failed::after { background: var(--danger); }
.ph--missing { background: repeating-linear-gradient(45deg, var(--line) 0 6px, transparent 6px 12px); }

.empty { color: var(--muted); font-size: 20px; margin: 48px 0; }
.empty--today { color: var(--ink); max-width: 22ch; }
.empty--quiet, .week .empty { font-size: 14px; margin: 8px 0; }

/* --- week */

.week { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 0 14px; }
.week-day { min-width: 0; border-top: 2px solid var(--line); padding-top: 8px; }
.week-day--today { border-top-color: var(--accent); }
.week-head { display: flex; align-items: baseline; gap: 6px; text-decoration: none; margin-bottom: 4px; }
.week-head:hover .week-dow { text-decoration: underline; }
.week-dow { font-weight: 700; }
.week-date { color: var(--muted); }
.meal--compact { padding: 10px 0 12px; }
.meal--compact .meal-time { font-size: 24px; }
.meal--compact .meal-name { font-size: 13px; }
.meal--compact .meal-photos { display: grid; grid-template-columns: repeat(2, 1fr); gap: 4px; margin: 0; padding: 0; overflow: visible; }
.meal--compact .ph { width: auto; border-radius: 6px; }

/* --- capture bar */

.capture {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 6;
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    padding: 12px var(--gutter) calc(14px + env(safe-area-inset-bottom));
    background: linear-gradient(to top, var(--bg) 60%, transparent);
    pointer-events: none;
}
.capture > * { pointer-events: auto; }
.capture-camera {
    grid-column: 2;
    display: grid;
    place-items: center;
    width: 76px;
    height: 76px;
    border-radius: 50%;
    background: var(--accent);
    color: var(--accent-ink);
    cursor: pointer;
    box-shadow: 0 0 0 6px var(--bg), 0 0 0 7px var(--line);
}
.capture-camera svg { width: 34px; height: 34px; }
.capture-camera:active { transform: scale(.96); }
.capture-library {
    grid-column: 1;
    grid-row: 1;
    justify-self: start;
    display: flex;
    align-items: center;
    gap: 6px;
    font-weight: 600;
    font-size: 14px;
    padding: 10px 12px;
    border-radius: var(--radius-ui);
    background: var(--surface);
    border: 1px solid var(--line);
    cursor: pointer;
}
.capture-library svg { width: 20px; height: 20px; }
.capture-camera:has(input:focus-visible), .capture-library:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: 3px; }
.capture-pending { font-variant-numeric: tabular-nums; grid-column: 3; grid-row: 1; justify-self: end; font-size: 13px; color: var(--muted); text-align: right; }

@media (max-width: 380px) {
    .capture-library span { display: none; }
}

/* --- dialogs */

.sheet {
    border: 0;
    padding: 20px var(--gutter) calc(20px + env(safe-area-inset-bottom));
    background: var(--surface);
    color: var(--ink);
    width: min(100%, 460px);
    max-width: 100%;
    margin: auto auto 0;
    border-radius: 16px 16px 0 0;
}
@media (min-width: 600px) { .sheet { margin: auto; border-radius: 16px; } }
.sheet::backdrop { background: rgb(10 14 12 / .55); }
.sheet h2 { margin: 0; font-size: 22px; }

.times-row { display: grid; grid-template-columns: 56px 1fr; gap: 10px; align-items: center; }
.times-row img { width: 56px; height: 56px; object-fit: cover; border-radius: 6px; }

.sheet--viewer {
    width: 100%;
    height: 100%;
    max-height: none;
    margin: 0;
    padding: 0;
    border-radius: 0;
    background: #0d100e;
    color: #eef2ee;
}
.viewer { display: grid; grid-template-rows: 1fr auto auto; height: 100%; }
.viewer-frame { min-height: 0; display: grid; place-items: center; padding: env(safe-area-inset-top) 0 0; }
.viewer-frame img { max-width: 100%; max-height: 100%; object-fit: contain; display: block; }
.viewer-bar, .viewer-edit {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    justify-content: space-between;
    gap: 12px;
    padding: 14px var(--gutter) calc(14px + env(safe-area-inset-bottom));
}
.viewer-edit { flex-direction: column; align-items: stretch; padding-top: 0; }
.viewer-time { font-size: 40px; font-weight: 750; letter-spacing: -0.035em; line-height: 1; margin: 0; }
.viewer-date, .viewer-source, .viewer-status { margin: 4px 0 0; color: #a9b4ad; font-size: 14px; }
.viewer-status { color: #e4b866; }
.viewer-status--failed { color: #f08f78; }
.viewer-actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.sheet--viewer .btn { background: #1d2420; border-color: #333d38; color: #eef2ee; }
.sheet--viewer .btn--primary { background: #eef2ee; color: #0d100e; border-color: #eef2ee; }
.sheet--viewer .btn--danger { color: #f08f78; }
.sheet--viewer input { background: #1d2420; border-color: #333d38; color: #eef2ee; }

/* --- toast */

.toast {
    position: fixed;
    left: 50%;
    bottom: calc(110px + env(safe-area-inset-bottom));
    transform: translate(-50%, 12px);
    background: var(--ink);
    color: var(--bg);
    padding: 10px 16px;
    border-radius: var(--radius-ui);
    font-size: 14px;
    opacity: 0;
    pointer-events: none;
    transition: opacity .2s, transform .2s;
    z-index: 20;
    max-width: calc(100% - 32px);
}
.toast--show { opacity: 1; transform: translate(-50%, 0); }

@media (prefers-reduced-motion: reduce) {
    .toast { transition: none; }
}
