/* The theme-color metas of each page and the manifest repeat --header-bg by hand: keep them in step.
   The night values are written twice, in the media query and in the forced rule: change both. */

:root {
    color-scheme: light;

    --ink: #1E2B2A;
    --on-ink: #F7F8F3;
    --ground: #EEF0EA;
    --paper: #F7F8F3;
    --raised: #FDFDFA;
    --sage: #D3E6D8;
    --sage-text: var(--ink);
    --selected: #E1EBE2;
    --tile: #E2E6DC;
    --tile-selected: var(--raised);
    --text-2: #3F4D49;
    --text-3: #55625E;
    --border: #C9CEC6;
    --border-row: #DDE1D8;
    --border-strong: #8A958F;
    --bubble-border: #D5D9D0;
    --attention: #F2C200;
    --on-attention: var(--ink);
    --attention-soft: #F6EBB8;
    --attention-soft-border: #C9B458;
    --attention-soft-text: var(--ink);
    --ok: #0B7A4B;
    --danger: #8C1D18;
    --link: #1F4FD8;
    --scrim: rgba(30, 43, 42, 0.55);

    --header-bg: #1E2B2A;
    --header-text: #F7F8F3;
    --header-text-dim: #B8C2BC;
    --header-line: #4A5A56;
    --header-rule: var(--header-bg);
    --header-control-bg: transparent;
    --header-ok: #3DDC84;
    --header-danger: #F0857D;
    --header-link: #8FB4FF;

    --line-a: #0E7C86;
    --line-b: #1F4FD8;
    --line-c: #C2410C;
    --line-d: #A21C6B;
    --line-e: #5A4FCF;
    --line-f: #4F810F;
    --line-g: #664600;
    --line-h: #455A64;
    --on-line: #FFFFFF;

    --font-display: "Barlow Semi Condensed", "Arial Narrow", "Helvetica Neue", system-ui, sans-serif;
    --font-body: "Atkinson Hyperlegible Next", system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --font-mono: "Atkinson Hyperlegible Mono", ui-monospace, "SF Mono", Menlo, Consolas, monospace;

    --radius-control: 6px;
    --radius-panel: 8px;
    --radius-pill: 9999px;
    --radius-bubble-in: 18px 18px 18px 4px;
    --radius-bubble-out: 18px 18px 4px 18px;
    --radius-composer: 26px 26px 26px 6px;
    --radius-card: 24px 24px 24px 6px;

    --viewport-height: 100dvh;
}

/* On a cold start the installed app on iOS gives 100dvh as the screen less the status bar while
   drawing the page from the very top, which leaves a strip under the bottom bar: 100lvh is the screen. */
@media (display-mode: standalone) {
    :root {
        --viewport-height: 100lvh;
    }
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="day"]) {
        color-scheme: dark;

        --ink: #DDE3DC;
        --on-ink: #151C1B;
        --ground: #151C1B;
        --paper: #1C2524;
        --raised: #243030;
        --sage: #2C4A3D;
        --sage-text: #E4EBE4;
        --selected: #26332F;
        --tile: #2A3633;
        --tile-selected: #34443F;
        --text-2: #B4C0B9;
        --text-3: #9AA8A1;
        --border: #2E3B38;
        --border-row: #2A3633;
        --border-strong: #50605B;
        --bubble-border: transparent;
        --attention: #E0B93A;
        --on-attention: #151C1B;
        --attention-soft: #2F2A18;
        --attention-soft-border: #5E5324;
        --attention-soft-text: #EADFAE;
        --ok: #3DDC84;
        --danger: #F0857D;
        --link: #8FB4FF;
        --scrim: rgba(5, 9, 8, 0.72);

        --header-bg: #0F1514;
        --header-text: #DDE3DC;
        --header-text-dim: #9AA8A1;
        --header-line: #50605B;
        --header-rule: #2E3B38;
        --header-control-bg: var(--raised);

        --line-b: #2A5BE0;
        --line-g: #996900;
        --line-h: #5B7784;
    }
}

:root[data-theme="night"] {
    color-scheme: dark;

    --ink: #DDE3DC;
    --on-ink: #151C1B;
    --ground: #151C1B;
    --paper: #1C2524;
    --raised: #243030;
    --sage: #2C4A3D;
    --sage-text: #E4EBE4;
    --selected: #26332F;
    --tile: #2A3633;
    --tile-selected: #34443F;
    --text-2: #B4C0B9;
    --text-3: #9AA8A1;
    --border: #2E3B38;
    --border-row: #2A3633;
    --border-strong: #50605B;
    --bubble-border: transparent;
    --attention: #E0B93A;
    --on-attention: #151C1B;
    --attention-soft: #2F2A18;
    --attention-soft-border: #5E5324;
    --attention-soft-text: #EADFAE;
    --ok: #3DDC84;
    --danger: #F0857D;
    --link: #8FB4FF;
    --scrim: rgba(5, 9, 8, 0.72);

    --header-bg: #0F1514;
    --header-text: #DDE3DC;
    --header-text-dim: #9AA8A1;
    --header-line: #50605B;
    --header-rule: #2E3B38;
    --header-control-bg: var(--raised);

    --line-b: #2A5BE0;
    --line-g: #996900;
    --line-h: #5B7784;
}

.app-header,
.bottom-nav {
    --ink: var(--header-text);
    --on-ink: var(--header-bg);
    --paper: var(--header-bg);
    --raised: var(--header-control-bg);
    --selected: color-mix(in srgb, var(--header-text) 14%, transparent);
    --text-2: var(--header-text-dim);
    --text-3: var(--header-text-dim);
    --border: var(--header-line);
    --border-row: var(--header-line);
    --border-strong: var(--header-line);
    --ok: var(--header-ok);
    --danger: var(--header-danger);
    --link: var(--header-link);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    height: 100%;
    height: var(--viewport-height, 100dvh);
    overflow: hidden;
    touch-action: manipulation;
    -webkit-text-size-adjust: 100%;
    overscroll-behavior: none;
    -webkit-overscroll-behavior: none;
}

body {
    font-family: var(--font-body);
    font-size: 15px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    background: var(--ground);
    color: var(--ink);
    height: 100%;
    height: var(--viewport-height, 100dvh);
    max-height: var(--viewport-height, 100dvh);
    width: 100%;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    touch-action: manipulation;
    overscroll-behavior: none;
    -webkit-overscroll-behavior: none;
}

button:focus-visible,
a:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
summary:focus-visible {
    outline: 3px solid var(--link);
    outline-offset: 2px;
}

/* iOS Safari zooms into a field whose font is under 16px */
@media screen and (max-width: 768px) {
    input,
    textarea,
    select {
        font-size: 16px !important;
    }
}

::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--border-strong);
    border-radius: var(--radius-pill);
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-3);
}

.badge {
    font-size: 0.72rem;
    padding: 2px 8px;
    border-radius: var(--radius-pill);
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.badge-green { background: transparent; color: var(--ok); border: 1px solid var(--ok); }
.badge-red { background: transparent; color: var(--danger); border: 1px solid var(--danger); }
.badge-yellow { background: var(--attention-soft); color: var(--attention-soft-text); border: 1px solid var(--attention-soft-border); }

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 7px 14px;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-control);
    background: var(--raised);
    color: var(--ink);
    cursor: pointer;
    font-size: 0.84rem;
    font-weight: 500;
    transition: all 0.18s cubic-bezier(0.16, 1, 0.3, 1);
    user-select: none;
}

.btn:hover {
    background: var(--selected);
    border-color: var(--ink);
    color: var(--ink);
    transform: translateY(-1px);
}

.btn:active {
    transform: translateY(0) scale(0.98);
}

.btn:disabled {
    opacity: 0.45;
    cursor: not-allowed;
    transform: none;
}

.btn-primary,
.btn-success {
    background: var(--ink);
    border-color: var(--ink);
    color: var(--on-ink);
    font-weight: 700;
}
.btn-primary:hover,
.btn-success:hover {
    background: var(--text-2);
    border-color: var(--text-2);
    color: var(--on-ink);
}

.btn-danger {
    background: transparent;
    border-color: var(--danger);
    color: var(--danger);
}
.btn-danger:hover {
    background: var(--danger);
    border-color: var(--danger);
    color: var(--on-ink);
}

.btn-secondary {
    background: transparent;
    border-color: var(--border-strong);
    color: var(--ink);
}
.btn-secondary:hover {
    background: var(--selected);
}

.btn-sm {
    padding: 4px 10px;
    font-size: 0.76rem;
    border-radius: var(--radius-control);
}

.btn-theme-toggle {
    min-width: 44px;
    min-height: 44px;
    padding: 0 12px;
    gap: 8px;
    font-size: 14px;
    font-weight: 400;
    flex-shrink: 0;
}

.btn-theme-toggle svg {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
}

.btn-theme-toggle[data-mode="day"] .theme-icon-night,
.btn-theme-toggle[data-mode="night"] .theme-icon-day {
    display: none;
}

.hidden {
    display: none !important;
}
