/* ==========================================================================
   My Journal — styles
   1. Design tokens (colors, type, spacing) + dark mode
   2. Base elements
   3. App layout: sidebar / mobile tab bar
   4. Shared components: buttons, badges, lists, empty states, toasts
   5. Pages: home, write/edit, history, entry, insights
   ========================================================================== */

/* ---------- 1. Design tokens ---------- */

:root {
    /* Paper and ink */
    --paper: #f6f6f3;
    --surface: #ffffff;
    --surface-sunken: #efefea;
    --ink: #1d2230;
    --ink-soft: #4a5161;
    --ink-faint: #6c7383;       /* still passes 4.5:1 on --paper */
    --rule: #e2e2dc;
    --rule-strong: #cfcfc7;

    /* Fountain-pen blue: links, focus, the main button */
    --accent: #2c4a8c;
    --accent-hover: #233d76;
    --accent-soft: #e6ebf6;
    --on-accent: #ffffff;

    --danger: #b3261e;
    --danger-soft: #fbe9e7;
    --success: #2f6b46;

    /* Mood colors: one hue per mood, used everywhere a mood appears */
    --mood-happy: #d99a0b;
    --mood-excited: #d6457a;
    --mood-neutral: #8d96a3;
    --mood-sad: #3f7cc4;
    --mood-stressed: #8257c4;
    --mood-none: #b9bec7;

    /* Type */
    --font-ui: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --font-read: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --text-xs: 0.8125rem;   /* 13 */
    --text-sm: 0.875rem;    /* 14 */
    --text-md: 1rem;        /* 16 */
    --text-lg: 1.1875rem;   /* 19 */
    --text-xl: 1.5rem;      /* 24 */
    --text-2xl: 2rem;       /* 32 */
    --text-3xl: 2.5rem;     /* 40 */

    /* Space & shape */
    --radius-sm: 6px;
    --radius: 10px;
    --radius-lg: 16px;
    --sidebar-width: 232px;
    --tabbar-height: 64px;
    --shadow-pop: 0 10px 30px rgba(20, 24, 36, 0.14), 0 2px 6px rgba(20, 24, 36, 0.08);
}

@media (prefers-color-scheme: dark) {
    :root {
        --paper: #14161b;
        --surface: #1c1f26;
        --surface-sunken: #23262f;
        --ink: #e9eaee;
        --ink-soft: #b7bcc7;
        --ink-faint: #8d93a0;
        --rule: #2c303a;
        --rule-strong: #3a3f4b;

        --accent: #9db4ec;
        --accent-hover: #b8c9f2;
        --accent-soft: #252d42;
        --on-accent: #10141f;

        --danger: #f2a49c;
        --danger-soft: #3a2220;
        --success: #8fcfa6;

        --mood-happy: #e9b53b;
        --mood-excited: #ec6f9b;
        --mood-neutral: #9aa3b1;
        --mood-sad: #6ea3e3;
        --mood-stressed: #a789e0;
        --mood-none: #4a4f5c;

        --shadow-pop: 0 10px 30px rgba(0, 0, 0, 0.5);
    }
}

/* Every mood class exposes the same two variables so any component can use them. */
.mood-happy    { --mood: var(--mood-happy); }
.mood-excited  { --mood: var(--mood-excited); }
.mood-neutral  { --mood: var(--mood-neutral); }
.mood-sad      { --mood: var(--mood-sad); }
.mood-stressed { --mood: var(--mood-stressed); }
[class*="mood-"] { --mood-soft: color-mix(in srgb, var(--mood, var(--mood-none)) 16%, var(--surface)); }


/* ---------- 2. Base ---------- */

*, *::before, *::after { box-sizing: border-box; }

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

body {
    margin: 0;
    background: var(--paper);
    color: var(--ink);
    font-family: var(--font-ui);
    font-size: var(--text-md);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { margin: 0; line-height: 1.2; }
p { margin: 0; }
a { color: var(--accent); }
img, svg { display: block; }

button, input, textarea, select { font: inherit; color: inherit; }

svg.lucide { width: 18px; height: 18px; stroke-width: 1.75; flex-shrink: 0; }

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

.visually-hidden {
    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: absolute;
    left: 12px; top: -48px;
    z-index: 100;
    padding: 8px 14px;
    background: var(--ink);
    color: var(--paper);
    border-radius: var(--radius-sm);
    text-decoration: none;
}
.skip-link:focus { top: 12px; }

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { transition: none !important; animation: none !important; }
}


/* ---------- 3. App layout ---------- */

.sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: var(--sidebar-width);
    padding: 24px 14px;
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--rule);
    background: var(--paper);
    z-index: 20;
}

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 6px 12px;
    margin-bottom: 28px;
    color: var(--ink);
    text-decoration: none;
    font-family: var(--font-read);
    font-size: var(--text-lg);
    font-weight: 600;
}
.brand svg.lucide { width: 22px; height: 22px; color: var(--accent); }

.nav { display: flex; flex-direction: column; gap: 2px; }

.nav-link {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 9px 12px;
    border-radius: var(--radius-sm);
    color: var(--ink-soft);
    text-decoration: none;
    font-size: var(--text-sm);
    font-weight: 500;
}
.nav-link:hover { background: var(--surface-sunken); color: var(--ink); }
.nav-link.active { background: var(--surface); color: var(--ink); box-shadow: inset 0 0 0 1px var(--rule); }
.nav-link.active svg.lucide { color: var(--accent); }

.sidebar-note {
    margin-top: auto;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    border-radius: var(--radius-sm);
    font-size: var(--text-xs);
    font-weight: 500;
    color: var(--ink-faint);
    text-decoration: none;
}
.sidebar-note:hover { background: var(--surface-sunken); color: var(--ink); }
.sidebar-note.active { color: var(--ink); }
.sidebar-note.active svg.lucide { color: var(--accent); }
.sidebar-note svg.lucide { width: 14px; height: 14px; }

/* Signed-in account, under Backup & export */
.sidebar-account {
    display: flex;
    flex-direction: column;
    gap: 2px;
    margin-top: 10px;
    padding: 10px 12px 0;
    border-top: 1px solid var(--rule);
    min-width: 0;
}
/* Name (or email) with a settings icon, linking to Settings */
.sidebar-settings {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
    margin: 0 -6px 4px;
    padding: 5px 6px;
    border-radius: var(--radius-sm);
    color: var(--ink);
    text-decoration: none;
}
.sidebar-settings:hover { background: var(--surface-sunken); }
.sidebar-settings svg.lucide { flex: none; width: 15px; height: 15px; color: var(--ink-faint); }
.sidebar-settings:hover svg.lucide, .sidebar-settings.active svg.lucide { color: var(--accent); }
.sidebar-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: var(--text-sm);
    font-weight: 600;
}
.sidebar-settings.active .sidebar-name { color: var(--accent); }
.sidebar-logout { font-size: var(--text-xs); }

/* A button that looks like a text link (Log out, Show password) */
.text-button {
    padding: 0;
    border: 0;
    background: none;
    color: var(--accent);
    font: inherit;
    font-size: var(--text-sm);
    font-weight: 500;
    cursor: pointer;
}
.text-button:hover { text-decoration: underline; }
.text-button[hidden] { display: none; }

/* Logged-out pages (log in, sign up, 404) have no sidebar or tab bar */
.no-sidebar .main { margin-left: 0; }

.main {
    margin-left: var(--sidebar-width);
    padding: 48px 40px 96px;
    outline: none;
}
.main > * { max-width: 720px; margin-left: auto; margin-right: auto; }
.main.history-page > * { max-width: 1040px; }

/* Phones: the sidebar becomes a bottom tab bar */
@media (max-width: 760px) {
    .sidebar {
        inset: auto 0 0 0;
        width: auto;
        height: calc(var(--tabbar-height) + env(safe-area-inset-bottom));
        padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
        flex-direction: row;
        border-right: 0;
        border-top: 1px solid var(--rule);
        background: color-mix(in srgb, var(--paper) 92%, transparent);
        backdrop-filter: blur(12px);
    }
    .brand, .sidebar-note, .sidebar-account { display: none; }
    .nav { flex-direction: row; flex: 1; justify-content: space-around; }
    .nav-link {
        flex: 1;
        flex-direction: column;
        gap: 3px;
        padding: 6px 4px;
        font-size: 11px;
        justify-content: center;
    }
    .nav-link svg.lucide { width: 22px; height: 22px; }
    .nav-link.active { background: none; box-shadow: none; color: var(--accent); }

    .main {
        margin-left: 0;
        padding: 28px 18px calc(var(--tabbar-height) + 40px);
    }
    .no-sidebar .main { padding-bottom: 40px; }
}


/* ---------- 4. Shared components ---------- */

/* Page headers */
.page-header { margin-bottom: 32px; }
.page-header h1 {
    font-family: var(--font-read);
    font-size: var(--text-3xl);
    font-weight: 600;
    letter-spacing: -0.02em;
}
.page-kicker, .page-subtitle { color: var(--ink-faint); font-size: var(--text-sm); }
.page-kicker { margin-bottom: 6px; }
.page-subtitle { margin-top: 8px; font-size: var(--text-md); }
/* A header with a small link or button on the right (History → Trash). */
.page-header-with-link { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 12px 20px; }

@media (max-width: 760px) {
    .page-header h1 { font-size: var(--text-2xl); }
}

.section { margin-top: 44px; }
.section-heading {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 14px;
}
.section-heading h2 { font-size: var(--text-md); font-weight: 600; }

.text-link { font-size: var(--text-sm); font-weight: 500; text-decoration: none; }
.text-link:hover { text-decoration: underline; }

/* Buttons */
.button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 40px;
    padding: 8px 16px;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    font-size: var(--text-sm);
    font-weight: 600;
    text-decoration: none;
    cursor: pointer;
    white-space: nowrap;
    transition: background-color 0.15s, border-color 0.15s;
}
.button svg.lucide { width: 16px; height: 16px; }
.button[hidden] { display: none; }
.button:disabled { opacity: 0.6; cursor: progress; }

.button-primary { background: var(--accent); color: var(--on-accent); }
.button-primary:hover { background: var(--accent-hover); }

.button-secondary { background: var(--surface); color: var(--ink); border-color: var(--rule-strong); }
.button-secondary:hover { border-color: var(--ink-faint); }

.button-quiet { background: transparent; color: var(--ink-soft); }
.button-quiet:hover { background: var(--surface-sunken); color: var(--ink); }

.button-danger { background: var(--danger); color: var(--surface); }
.button-danger:hover { filter: brightness(0.92); }
.button-danger-quiet { color: var(--danger); }
.button-danger-quiet:hover { background: var(--danger-soft); color: var(--danger); }

.icon-button {
    display: inline-grid;
    place-items: center;
    width: 40px; height: 40px;
    border: 0;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--ink-soft);
    cursor: pointer;
}
.icon-button:hover { background: var(--surface-sunken); color: var(--ink); }
.icon-button.danger:hover { background: var(--danger-soft); color: var(--danger); }

.favorite-button.is-favorite { color: var(--mood-happy); }
.favorite-button.is-favorite svg.lucide { fill: currentColor; }

.back-link {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    color: var(--ink-soft);
    font-size: var(--text-sm);
    font-weight: 500;
    text-decoration: none;
}
/* A back link placed directly in .main is inline, so auto margins can't center it;
   make it a shrink-wrapped block aligned to the left edge of the centered column. */
.main > .back-link {
    display: flex;
    width: fit-content;
    margin-left: max(0px, calc((100% - 720px) / 2));
}
.back-link:hover { color: var(--ink); }
.back-link svg.lucide { width: 16px; height: 16px; }

/* Mood badge */
.mood-badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 2px 9px 2px 7px;
    border-radius: 999px;
    background: var(--mood-soft, var(--surface-sunken));
    color: var(--ink-soft);
    font-size: var(--text-xs);
    font-weight: 500;
    line-height: 1.6;
}

/* Tag pills (home, history, entry) */
.tag-list { display: flex; flex-wrap: wrap; gap: 6px; margin: 0; padding: 0; list-style: none; }
.tag-pill {
    display: inline-flex;
    align-items: center;
    padding: 1px 9px;
    border-radius: 999px;
    background: var(--surface-sunken);
    color: var(--ink-soft);
    font-size: var(--text-xs);
    font-weight: 500;
    line-height: 1.6;
    text-decoration: none;
    overflow-wrap: anywhere;
}
a.tag-pill:hover { color: var(--ink); box-shadow: inset 0 0 0 1px var(--rule-strong); }

/* Entry list (home, history) */
.entry-list { display: flex; flex-direction: column; gap: 10px; }

.entry-row {
    position: relative;
    display: block;
    padding: 18px 20px 18px 24px;
    border: 1px solid var(--rule);
    border-radius: var(--radius);
    background: var(--surface);
    color: inherit;
    text-decoration: none;
    transition: border-color 0.15s;
}
/* A thin stripe in the entry's mood color */
.entry-row::before {
    content: "";
    position: absolute;
    left: 0; top: 14px; bottom: 14px;
    width: 3px;
    border-radius: 0 3px 3px 0;
    background: var(--mood, var(--mood-none));
}
a.entry-row:hover, .entry-row.has-actions:hover { border-color: var(--rule-strong); }

.entry-row-link { display: block; color: inherit; text-decoration: none; }
.entry-row-link::after { content: ""; position: absolute; inset: 0; border-radius: inherit; }
.entry-row-link:focus-visible { outline: none; }
.entry-row-link:focus-visible::after { outline: 2px solid var(--accent); outline-offset: 2px; }
.entry-row.has-actions { padding-right: 64px; }

.entry-row-meta {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
    font-size: var(--text-xs);
    color: var(--ink-faint);
}
.entry-row-title {
    margin-top: 8px;
    font-family: var(--font-read);
    font-size: var(--text-lg);
    font-weight: 600;
    letter-spacing: -0.02em;
}
.entry-row-preview {
    margin-top: 6px;
    color: var(--ink-soft);
    font-size: var(--text-sm);
    line-height: 1.6;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.favorite-form { position: absolute; top: 12px; right: 12px; z-index: 1; }
/* Buttons inside a card sit above the card-wide link. */
.entry-row-actions { position: relative; z-index: 1; display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.entry-row-actions form { margin: 0; }
.entry-row-tags { margin-top: 10px; }
/* Tag links sit above the card-wide link so they stay clickable. */
.entry-row.has-actions .entry-row-tags { position: relative; z-index: 1; width: fit-content; max-width: 100%; }

/* Empty states */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    padding: 56px 24px;
    text-align: center;
    border: 1px dashed var(--rule-strong);
    border-radius: var(--radius-lg);
    color: var(--ink-soft);
}
.empty-state svg.lucide { width: 32px; height: 32px; color: var(--ink-faint); margin-bottom: 4px; }
.empty-state h1, .empty-state h2 { font-family: var(--font-read); font-size: var(--text-xl); color: var(--ink); }
.empty-state p { max-width: 36ch; font-size: var(--text-sm); }
.empty-state .button { margin-top: 10px; }

/* Errors */
.form-error {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 0 0 20px;
    padding: 12px 14px;
    border-radius: var(--radius-sm);
    background: var(--danger-soft);
    color: var(--danger);
    font-size: var(--text-sm);
    font-weight: 500;
}
.editor-error { margin-top: 8px; color: var(--danger); font-size: var(--text-sm); }
.editor-error[hidden] { display: none; }

/* Toasts ("Entry saved.") */
.toast-region {
    position: fixed;
    left: 50%;
    bottom: 28px;
    transform: translateX(-50%);
    z-index: 50;
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.toast {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 11px 18px 11px 14px;
    border-radius: 999px;
    background: var(--ink);
    color: var(--paper);
    font-size: var(--text-sm);
    font-weight: 500;
    box-shadow: var(--shadow-pop);
    animation: toast-in 0.25s ease-out;
    transition: opacity 0.4s, transform 0.4s;
}
.toast svg.lucide { width: 16px; height: 16px; color: var(--mood-happy); }
/* visibility (delayed until the fade ends) also takes hidden buttons out of the tab order. */
.toast-hide { opacity: 0; transform: translateY(8px); pointer-events: none; visibility: hidden; transition: opacity 0.4s, transform 0.4s, visibility 0s 0.4s; }
.toast-has-action { padding-right: 6px; }
.toast-action { margin: 0 0 0 6px; }
.toast-button {
    min-height: 32px;
    padding: 4px 12px;
    border: 0;
    border-radius: 999px;
    background: transparent;
    color: var(--accent-soft);
    font-size: var(--text-sm);
    font-weight: 600;
    cursor: pointer;
}
.toast-button:hover { background: color-mix(in srgb, var(--paper) 14%, transparent); }
.toast-button:focus-visible { outline-color: var(--paper); border-radius: 999px; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }
@media (min-width: 761px) { .toast-region { left: calc(50% + var(--sidebar-width) / 2); } }
@media (max-width: 760px) { .toast-region { bottom: calc(var(--tabbar-height) + 20px); } }
@media (min-width: 761px) { .no-sidebar .toast-region { left: 50%; } }
@media (max-width: 760px) { .no-sidebar .toast-region { bottom: 20px; } }

/* Dialog */
.dialog {
    width: min(420px, calc(100vw - 32px));
    padding: 24px;
    border: 0;
    border-radius: var(--radius-lg);
    background: var(--surface);
    color: var(--ink);
    box-shadow: var(--shadow-pop);
}
.dialog::backdrop { background: rgba(15, 18, 26, 0.45); }
.dialog h2 { font-family: var(--font-read); font-size: var(--text-xl); }
.dialog p { margin-top: 10px; color: var(--ink-soft); font-size: var(--text-sm); line-height: 1.6; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 24px; }


/* ---------- 5a. Home ---------- */

/* Phones have no sidebar, so Home's header carries Log out */
.home-page .page-header { position: relative; }
.mobile-account { display: none; }
@media (max-width: 760px) {
    .mobile-account { display: flex; align-items: center; gap: 12px; position: absolute; top: 0; right: 0; }
    .mobile-settings { display: inline-flex; align-items: center; gap: 4px; font-size: var(--text-xs); font-weight: 500; padding: 4px 0; text-decoration: none; }
    .mobile-settings:hover { text-decoration: underline; }
    .mobile-settings svg.lucide { width: 14px; height: 14px; }
    .mobile-logout .text-button { font-size: var(--text-xs); padding: 4px 0; }
}

.home-page .page-header h1 { font-size: var(--text-2xl); }

.today-card {
    padding: 28px;
    border-radius: var(--radius-lg);
    background: var(--surface);
    border: 1px solid var(--rule);
}
.today-prompt {
    font-family: var(--font-read);
    font-size: var(--text-xl);
    line-height: 1.4;
    max-width: 30ch;
}
.today-heading {
    display: flex;
    align-items: center;
    gap: 10px;
    font-family: var(--font-read);
    font-size: var(--text-xl);
    font-weight: 600;
}
.today-heading svg.lucide { width: 22px; height: 22px; color: var(--success); }
.today-text { margin-top: 8px; color: var(--ink-soft); }
.today-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 12px 16px;
    margin-top: 22px;
}
.today-streak {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: var(--text-sm);
    color: var(--ink-soft);
}
.today-streak svg.lucide { width: 16px; height: 16px; color: var(--mood-happy); }

/* Two weeks of moods, one cell per day */
.mood-strip {
    list-style: none;
    margin: 0;
    padding: 0;
    display: grid;
    grid-template-columns: repeat(14, minmax(0, 1fr));
    gap: 6px;
}
.mood-day { display: flex; flex-direction: column; align-items: center; gap: 6px; }
.mood-day-dot {
    display: grid;
    place-items: center;
    width: 100%;
    aspect-ratio: 1;
    max-width: 40px;
    border-radius: 50%;
    border: 1.5px dashed var(--rule-strong);
    font-size: 17px;
    line-height: 1;
}
.mood-day.written .mood-day-dot { border: 0; background: var(--mood-soft); box-shadow: inset 0 0 0 2px var(--mood, var(--mood-none)); }
.mood-day-label { font-size: 11px; color: var(--ink-faint); }
.mood-day.is-today .mood-day-label { color: var(--ink); font-weight: 700; }

@media (max-width: 520px) {
    .mood-strip { gap: 3px; }
    .mood-day-dot { font-size: 12px; }
}

.quick-stats {
    display: flex;
    flex-wrap: wrap;
    gap: 8px 36px;
    margin: 22px 0 0;
}
.quick-stats dt { font-size: var(--text-xs); color: var(--ink-faint); }
.quick-stats dd { margin: 2px 0 0; font-size: var(--text-lg); font-weight: 600; }


/* ---------- 5b. Write & edit ---------- */

.write-page .back-link { margin-bottom: 20px; }

.compose-header { margin-bottom: 20px; }
.compose-date { color: var(--ink-faint); font-size: var(--text-sm); min-height: 1.5em; }
.compose-title {
    width: 100%;
    margin-top: 4px;
    padding: 4px 0;
    border: 0;
    background: transparent;
    font-family: var(--font-read);
    font-size: var(--text-3xl);
    font-weight: 600;
    letter-spacing: -0.02em;
}
.compose-title::placeholder { color: var(--rule-strong); }
.compose-title:focus { outline: none; }
.compose-title:focus-visible { box-shadow: 0 2px 0 var(--accent); border-radius: 0; }
@media (max-width: 760px) { .compose-title { font-size: var(--text-2xl); } }

/* Mood chips */
.mood-picker { margin: 0 0 22px; padding: 0; border: 0; min-width: 0; }
.mood-picker legend { padding: 0; margin-bottom: 10px; font-size: var(--text-sm); font-weight: 600; color: var(--ink-soft); }
.mood-options { display: flex; flex-wrap: wrap; gap: 8px; }
.mood-option {
    position: relative;
    display: inline-flex;
    align-items: center;
    gap: 7px;
    min-height: 40px;
    padding: 6px 14px 6px 10px;
    border: 1px solid var(--rule);
    border-radius: 999px;
    background: var(--surface);
    font-size: var(--text-sm);
    font-weight: 500;
    color: var(--ink-soft);
    cursor: pointer;
    user-select: none;
    transition: background-color 0.15s, border-color 0.15s;
}
.mood-option input { position: absolute; opacity: 0; pointer-events: none; }
.mood-option:hover { border-color: var(--mood); }
.mood-option:has(input:checked) {
    background: var(--mood-soft);
    border-color: var(--mood);
    color: var(--ink);
    box-shadow: inset 0 0 0 1px var(--mood);
}
.mood-option:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: 2px; }
.mood-emoji { font-size: 18px; line-height: 1; }

/* Tag chips */
.tag-field { margin: 0 0 22px; }
.tag-field-label { display: block; margin-bottom: 10px; font-size: var(--text-sm); font-weight: 600; color: var(--ink-soft); }
.tag-box {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
    min-height: 44px;
    padding: 6px 10px;
    border: 1px solid var(--rule);
    border-radius: var(--radius);
    background: var(--surface);
    cursor: text;
}
.tag-box:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.tag-chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 0; padding: 0; list-style: none; }
.tag-chips[hidden] { display: none; }
.tag-chip {
    display: inline-flex;
    align-items: center;
    gap: 2px;
    padding: 2px 2px 2px 10px;
    border-radius: 999px;
    background: var(--surface-sunken);
    color: var(--ink-soft);
    font-size: var(--text-sm);
    font-weight: 500;
    overflow-wrap: anywhere;
}
.tag-chip-remove {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: transparent;
    color: var(--ink-faint);
    font-size: var(--text-md);
    line-height: 1;
    cursor: pointer;
}
.tag-chip-remove:hover { background: var(--rule); color: var(--ink); }
.tag-text { flex: 1; min-width: 8ch; padding: 4px 2px; border: 0; background: transparent; }
.tag-text:focus { outline: none; }
.field-hint { margin-top: 6px; font-size: var(--text-xs); color: var(--ink-faint); }

/* Editor */
.editor-field { margin-bottom: 18px; }
.editor-field textarea, .field textarea {
    width: 100%;
    padding: 14px 16px;
    border: 1px solid var(--rule);
    border-radius: var(--radius);
    background: var(--surface);
    resize: vertical;
    line-height: 1.7;
}
#journal { font-family: var(--font-read); font-size: var(--text-lg); min-height: 320px; }
.editor-field textarea:focus, .field textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

.journal-editor[hidden] { display: none; }

.ql-toolbar.ql-snow {
    position: sticky;
    top: 0;
    z-index: 5;
    border: 1px solid var(--rule);
    border-bottom-color: var(--rule);
    border-radius: var(--radius) var(--radius) 0 0;
    background: var(--surface);
    font-family: var(--font-ui);
    padding: 6px 8px;
}
.ql-snow .ql-stroke { stroke: var(--ink-soft); }
.ql-snow .ql-fill, .ql-snow .ql-stroke.ql-fill { fill: var(--ink-soft); }
.ql-snow .ql-picker { color: var(--ink-soft); }
.ql-snow .ql-picker-options { background: var(--surface); border-radius: var(--radius-sm); }
.ql-toolbar.ql-snow .ql-picker.ql-expanded .ql-picker-label,
.ql-toolbar.ql-snow .ql-picker.ql-expanded .ql-picker-options { border-color: var(--rule); }
.ql-snow.ql-toolbar button:hover, .ql-snow.ql-toolbar button.ql-active,
.ql-snow.ql-toolbar .ql-picker-label:hover, .ql-snow.ql-toolbar .ql-picker-label.ql-active { color: var(--accent); }
.ql-snow.ql-toolbar button:hover .ql-stroke, .ql-snow.ql-toolbar button.ql-active .ql-stroke,
.ql-snow.ql-toolbar .ql-picker-label:hover .ql-stroke, .ql-snow.ql-toolbar .ql-picker-label.ql-active .ql-stroke { stroke: var(--accent); }
.ql-snow.ql-toolbar button:hover .ql-fill, .ql-snow.ql-toolbar button.ql-active .ql-fill { fill: var(--accent); }
.ql-snow .ql-tooltip { background: var(--surface); color: var(--ink); border-color: var(--rule); box-shadow: var(--shadow-pop); border-radius: var(--radius-sm); z-index: 6; }
.ql-snow .ql-tooltip input[type=text] { background: var(--paper); border-color: var(--rule); }
.ql-snow a { color: var(--accent); }

.journal-editor.ql-container {
    min-height: 360px;
    height: auto;
    border: 1px solid var(--rule);
    border-top: 0;
    border-radius: 0 0 var(--radius) var(--radius);
    background: var(--surface);
    font-family: var(--font-read);
    font-size: var(--text-lg);
}
.journal-editor:focus-within { border-color: var(--accent); }
.journal-editor .ql-editor {
    min-height: 360px;
    padding: 22px 24px 40px;
    line-height: 1.75;
    overflow-wrap: anywhere;
}
.journal-editor .ql-editor.ql-blank::before {
    left: 24px; right: 24px;
    color: var(--ink-faint);
    font-style: normal;
}
.journal-editor .ql-editor h2 { font-size: 1.35em; margin: 0.6em 0 0.2em; }
.journal-editor .ql-editor h3 { font-size: 1.15em; margin: 0.6em 0 0.2em; }
.journal-editor .ql-editor blockquote { border-left: 3px solid var(--rule-strong); color: var(--ink-soft); }
@media (max-width: 760px) {
    .journal-editor.ql-container, .journal-editor .ql-editor { min-height: 280px; }
    .journal-editor .ql-editor { padding: 18px 16px 32px; }
    .journal-editor .ql-editor.ql-blank::before { left: 16px; right: 16px; }
}

/* Highlighted text stays readable in dark mode */
.ql-editor span[style*="background-color"],
.formatted-entry-content span[style*="background-color"] { color: #1d2230; border-radius: 2px; }

/* Reflection (collapsible) */
.daily-reflection {
    margin-bottom: 24px;
    border: 1px solid var(--rule);
    border-radius: var(--radius);
    background: var(--surface);
}
.daily-reflection summary {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 16px 20px;
    cursor: pointer;
    list-style: none;
}
.daily-reflection summary::-webkit-details-marker { display: none; }
.daily-reflection summary svg.lucide { color: var(--ink-faint); transition: transform 0.2s; }
.daily-reflection[open] summary svg.lucide { transform: rotate(180deg); }
.reflection-summary-text { display: flex; flex-direction: column; gap: 2px; }
.reflection-title { font-weight: 600; }
.reflection-hint { font-size: var(--text-sm); color: var(--ink-faint); }
.reflection-fields { display: flex; flex-direction: column; gap: 16px; padding: 0 20px 20px; }
.field label { display: block; margin-bottom: 6px; font-size: var(--text-sm); font-weight: 600; }
.field textarea { padding: 10px 14px; min-height: 64px; font-size: var(--text-md); }

/* Sticky save bar */
.compose-bar {
    position: sticky;
    bottom: 0;
    z-index: 4;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin: 0 -12px;
    padding: 12px;
    background: color-mix(in srgb, var(--paper) 90%, transparent);
    backdrop-filter: blur(10px);
    border-top: 1px solid var(--rule);
}
.compose-status { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: var(--text-xs); color: var(--ink-faint); }
#edit-status.is-dirty { color: var(--mood-happy); font-weight: 600; }
.compose-actions { display: flex; gap: 8px; }
@media (max-width: 760px) {
    .compose-bar { bottom: calc(var(--tabbar-height) + env(safe-area-inset-bottom)); margin: 0 -18px; padding: 10px 18px; }
    .compose-status { flex-direction: column; }
    #discard-draft { padding-inline: 10px; }
}


/* "Start from:" template line (Write page, empty entry only) */
.template-picker {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 4px 12px;
    margin: -4px 0 12px;
    font-size: var(--text-sm);
    color: var(--ink-faint);
}
.template-picker[hidden] { display: none; }
.template-options { display: flex; flex-wrap: wrap; gap: 4px 14px; margin: 0; padding: 0; list-style: none; }
.template-option {
    padding: 2px 0;
    border: 0;
    background: none;
    color: var(--accent);
    font: inherit;
    font-weight: 500;
    cursor: pointer;
}
.template-option:hover { text-decoration: underline; }

/* Focus mode: just the title, the editor and a slim save bar */
.focus-icon-exit { display: none; }
.focus-mode .focus-icon-enter { display: none; }
.focus-mode .focus-icon-exit { display: inline; }

.focus-mode .sidebar,
.focus-mode .write-page .back-link,
.focus-mode .compose-date,
.focus-mode .mood-picker,
.focus-mode .tag-field,
.focus-mode .daily-reflection,
.focus-mode .template-picker,
.focus-mode #discard-draft,
.focus-mode .compose-actions > a.button { display: none; }
/* Status messages stay in the page for screen readers, just not on screen. */
.focus-mode #autosave-status,
.focus-mode #edit-status {
    position: absolute;
    width: 1px; height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
}
.focus-mode .main.write-page { margin-left: 0; padding-top: 88px; }
.focus-mode .main.write-page > * { max-width: 680px; }
.focus-mode .compose-bar { padding-block: 8px; }
.focus-mode .ql-toolbar.ql-snow { opacity: 0.3; }
.focus-mode .ql-toolbar.ql-snow:hover,
.focus-mode .ql-toolbar.ql-snow:focus-within,
.focus-mode .editor-field:focus-within .ql-toolbar.ql-snow { opacity: 1; }
@media (prefers-reduced-motion: no-preference) {
    .ql-toolbar.ql-snow { transition: opacity 0.2s; }
}
@media (min-width: 761px) { .focus-mode .toast-region { left: 50%; } }
/* Narrow phones: "Focus" becomes icon-only so it fits beside Discard and Save. */
@media (max-width: 520px) {
    body:not(.focus-mode) .focus-toggle { padding-inline: 10px; }
    body:not(.focus-mode) #focus-toggle-label {
        position: absolute;
        width: 1px; height: 1px;
        overflow: hidden;
        clip: rect(0 0 0 0);
        white-space: nowrap;
    }
}
@media (max-width: 760px) {
    .focus-mode .main.write-page { padding: 40px 18px 40px; }
    .focus-mode .compose-bar { bottom: 0; }
}


/* ---------- 5g. Log in & sign up ---------- */

.main.auth-page { display: grid; place-items: center; min-height: 100vh; padding-top: 40px; }
.main.auth-page > * { width: 100%; max-width: 400px; }
.auth-card {
    padding: 32px 28px;
    border: 1px solid var(--rule);
    border-radius: var(--radius-lg);
    background: var(--surface);
}
.auth-brand { display: flex; align-items: center; gap: 8px; margin-bottom: 18px; font-family: var(--font-read); font-weight: 600; color: var(--ink-soft); }
.auth-brand svg.lucide { width: 20px; height: 20px; color: var(--accent); }
.auth-card h1 { font-family: var(--font-read); font-size: var(--text-2xl); font-weight: 600; letter-spacing: -0.02em; margin-bottom: 22px; }
.auth-form { display: flex; flex-direction: column; gap: 18px; }
.auth-form .form-error { margin: 0; }
.auth-field label { display: block; margin-bottom: 6px; font-size: var(--text-sm); font-weight: 600; }
.auth-field input, .auth-field select {
    width: 100%;
    min-height: 44px;
    padding: 10px 14px;
    border: 1px solid var(--rule-strong);
    border-radius: var(--radius-sm);
    background: var(--paper);
    color: var(--ink);
    font: inherit;
}
.auth-field input:focus, .auth-field select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.auth-field input[aria-invalid="true"], .auth-field select[aria-invalid="true"] { border-color: var(--danger); }
.password-box { position: relative; }
.password-box input { padding-right: 120px; }
.password-toggle { position: absolute; top: 50%; right: 12px; transform: translateY(-50%); font-size: var(--text-xs); }
.field-error { display: flex; align-items: flex-start; gap: 6px; margin-top: 6px; font-size: var(--text-sm); color: var(--danger); }
.field-error svg.lucide { flex: none; width: 16px; height: 16px; margin-top: 2px; }
.field-error a { color: inherit; font-weight: 600; }
.auth-row { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px 16px; }
.auth-link { font-size: var(--text-sm); font-weight: 500; }
.auth-intro { margin: -10px 0 22px; font-size: var(--text-sm); color: var(--ink-soft); }
.auth-notice {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 12px 14px;
    border-radius: var(--radius-sm);
    background: var(--accent-soft);
    color: var(--ink);
    font-size: var(--text-sm);
}
.auth-notice svg.lucide { flex: none; width: 18px; height: 18px; margin-top: 1px; color: var(--accent); }
.auth-check { display: flex; align-items: center; gap: 8px; font-size: var(--text-sm); cursor: pointer; }
.auth-check input { width: 18px; height: 18px; accent-color: var(--accent); }
.auth-submit { width: 100%; min-height: 44px; }
.auth-switch { margin-top: 20px; text-align: center; font-size: var(--text-sm); color: var(--ink-soft); }
.auth-switch a { font-weight: 600; }
@media (max-width: 760px) {
    .main.auth-page { min-height: auto; padding-top: 32px; }
    .auth-card { padding: 26px 20px; }
}

/* ---------- 5c. History ---------- */

.history-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 300px;
    gap: 40px;
    align-items: start;
}
.history-results { grid-column: 1; grid-row: 1; }
.calendar-panel {
    grid-column: 2;
    position: sticky;
    top: 24px;
    padding: 18px;
    border: 1px solid var(--rule);
    border-radius: var(--radius-lg);
    background: var(--surface);
}
@media (max-width: 1100px) {
    .history-layout { grid-template-columns: minmax(0, 1fr); gap: 28px; }
    .calendar-panel, .history-results { grid-column: 1; grid-row: auto; position: static; }
}

.calendar-nav { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.calendar-nav h2 { font-size: var(--text-md); font-weight: 600; }

.calendar-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.calendar-weekday { text-align: center; font-size: 11px; font-weight: 600; color: var(--ink-faint); padding: 4px 0; }
.calendar-day {
    display: grid;
    place-items: center;
    aspect-ratio: 1;
    border-radius: 50%;
    color: var(--ink-soft);
    font-size: var(--text-sm);
    text-decoration: none;
    font-variant-numeric: tabular-nums;
}
.calendar-day:hover { background: var(--surface-sunken); }
.calendar-day.other-month { color: var(--rule-strong); }
.calendar-day.has-entry {
    background: var(--mood-soft);
    box-shadow: inset 0 0 0 2px var(--mood, var(--mood-none));
    color: var(--ink);
    font-weight: 600;
}
.calendar-day.is-today { text-decoration: underline; text-underline-offset: 3px; text-decoration-thickness: 2px; }
.calendar-day.selected { background: var(--ink); color: var(--paper); box-shadow: none; }

.calendar-legend {
    list-style: none;
    display: flex;
    flex-wrap: wrap;
    gap: 6px 12px;
    margin: 14px 0 0;
    padding: 12px 0 0;
    border-top: 1px solid var(--rule);
    font-size: var(--text-xs);
    color: var(--ink-faint);
}
.calendar-legend li { display: inline-flex; align-items: center; gap: 6px; }
.legend-swatch { width: 10px; height: 10px; border-radius: 50%; background: var(--mood); }

@media (max-width: 1100px) {
    .calendar-panel { padding: 14px; }
    .calendar-grid { max-width: 420px; margin: 0 auto; }
}
@media (max-width: 760px) {
    .calendar-grid { max-width: 300px; gap: 2px; }
    .calendar-day { font-size: var(--text-xs); }
    .calendar-nav { max-width: 300px; margin: 0 auto 6px; }
    .calendar-legend { justify-content: center; margin-top: 10px; padding-top: 10px; }
}

.search-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 4px 4px 14px;
    border: 1px solid var(--rule);
    border-radius: var(--radius);
    background: var(--surface);
}
.search-bar:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.search-bar > svg.lucide { color: var(--ink-faint); }
.search-bar input { flex: 1; min-width: 0; padding: 8px 0; border: 0; background: transparent; }
.search-bar input:focus { outline: none; }
.search-bar .button { min-height: 36px; }

.filter-row { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin: 14px 0 6px; }
.segmented { display: inline-flex; padding: 3px; border-radius: var(--radius-sm); background: var(--surface-sunken); }
.segment {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    border-radius: 4px;
    color: var(--ink-soft);
    font-size: var(--text-sm);
    font-weight: 500;
    text-decoration: none;
}
.segment svg.lucide { width: 14px; height: 14px; }
.segment.selected { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08); }
.filter-pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 5px 8px 5px 12px;
    border-radius: 999px;
    background: var(--accent-soft);
    color: var(--accent);
    font-size: var(--text-sm);
    font-weight: 500;
    text-decoration: none;
}
.filter-pill svg.lucide { width: 14px; height: 14px; }
.result-count { margin-left: auto; font-size: var(--text-xs); color: var(--ink-faint); }

.group-label {
    margin: 26px 0 10px;
    font-size: var(--text-sm);
    font-weight: 600;
    color: var(--ink-faint);
}
.history-results .empty-state { margin-top: 20px; }
.trash-link { display: inline-flex; align-items: center; gap: 6px; color: var(--ink-soft); }
.trash-link svg.lucide { width: 16px; height: 16px; }
.trash-link:hover { color: var(--ink); }
.trash-page .back-link { margin-bottom: 20px; }


/* ---------- 5d. Reading an entry ---------- */

.entry-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 36px;
}
.entry-tools { display: flex; align-items: center; gap: 4px; }
.entry-tools form { margin: 0; }
.entry-tools .button { margin: 0 4px; }

.main > .reading { max-width: 720px; }

/* "This entry is in Trash" */
.trash-notice {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 12px 14px;
    /* Only top/bottom: the column's auto side margins keep it aligned. */
    margin-top: -16px;
    margin-bottom: 32px;
    padding: 14px 16px;
    border: 1px solid var(--rule);
    border-radius: var(--radius);
    background: var(--surface-sunken);
}
.trash-notice > svg.lucide { color: var(--ink-faint); }
.trash-notice p { flex: 1; min-width: 12rem; font-size: var(--text-sm); color: var(--ink-soft); }
.trash-notice strong { display: block; color: var(--ink); font-weight: 600; }
.trash-notice form { margin: 0; }
.reading-header { margin-bottom: 28px; }
.reading-tags { margin-top: 12px; }
.reading-date { font-size: var(--text-sm); color: var(--ink-faint); }
.reading-time { white-space: nowrap; }
.reading-title {
    margin: 8px 0 14px;
    font-family: var(--font-read);
    font-size: var(--text-3xl);
    font-weight: 600;
    letter-spacing: -0.02em;
    overflow-wrap: anywhere;
}
@media (max-width: 760px) { .reading-title { font-size: var(--text-2xl); } }

.reading-body {
    font-family: var(--font-read);
    font-size: var(--text-lg);
    line-height: 1.8;
    overflow-wrap: anywhere;
}
.full-entry-content { white-space: pre-wrap; }
.formatted-entry-content p { margin: 0 0 1em; }
.formatted-entry-content h2 { font-size: 1.35em; margin: 1.2em 0 0.4em; }
.formatted-entry-content h3 { font-size: 1.15em; margin: 1.2em 0 0.4em; }
.formatted-entry-content ul, .formatted-entry-content ol { padding-left: 1.5em; margin: 0 0 1em; }
.formatted-entry-content blockquote {
    margin: 1em 0;
    padding-left: 18px;
    border-left: 3px solid var(--rule-strong);
    color: var(--ink-soft);
}

.saved-reflection {
    margin-top: 40px;
    padding: 22px 24px;
    border-radius: var(--radius);
    background: var(--surface);
    border: 1px solid var(--rule);
}
.saved-reflection h2 { font-size: var(--text-md); font-weight: 600; margin-bottom: 14px; }
.saved-reflection dl { margin: 0; display: flex; flex-direction: column; gap: 14px; }
.reflection-item dt { font-size: var(--text-sm); font-weight: 600; color: var(--ink-soft); }
.reflection-answer {
    margin: 4px 0 0;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    font-family: var(--font-read);
    line-height: 1.7;
}

.entry-pager {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    margin-top: 56px;
    padding-top: 20px;
    border-top: 1px solid var(--rule);
}
.pager-link {
    display: flex;
    flex-direction: column;
    gap: 4px;
    max-width: 48%;
    color: inherit;
    text-decoration: none;
}
.pager-newer { text-align: right; margin-left: auto; align-items: flex-end; }
.pager-direction { display: inline-flex; align-items: center; gap: 6px; font-size: var(--text-xs); color: var(--ink-faint); }
.pager-direction svg.lucide { width: 14px; height: 14px; }
.pager-title { font-family: var(--font-read); font-weight: 600; overflow-wrap: anywhere; }
.pager-link:hover .pager-title { color: var(--accent); }


/* ---------- 5e. Insights ---------- */

.stat-band {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    border: 1px solid var(--rule);
    border-radius: var(--radius-lg);
    background: var(--surface);
    margin-bottom: 20px;
}
.stat { padding: 20px 22px; }
.stat + .stat { border-left: 1px solid var(--rule); }
.stat-value { font-family: var(--font-read); font-size: var(--text-2xl); font-weight: 600; font-variant-numeric: tabular-nums; }
.stat-value span { font-family: var(--font-ui); font-size: var(--text-sm); font-weight: 500; color: var(--ink-faint); }
.stat-label { margin-top: 2px; font-size: var(--text-sm); font-weight: 500; color: var(--ink-soft); }
.stat-note { margin-top: 6px; font-size: var(--text-xs); color: var(--ink-faint); line-height: 1.5; }
.stat-band-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
@media (max-width: 860px) {
    .stat-band { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .stat:nth-child(3) { border-left: 0; }
    .stat:nth-child(n+3) { border-top: 1px solid var(--rule); }
    .stat-band-3 .stat:nth-child(3) { grid-column: span 2; }
}

.insights-columns { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 20px; }
@media (max-width: 860px) { .insights-columns { grid-template-columns: minmax(0, 1fr); } }

.panel { padding: 22px; border: 1px solid var(--rule); border-radius: var(--radius-lg); background: var(--surface); }
.panel-title { font-size: var(--text-md); font-weight: 600; margin-bottom: 16px; }
.subhead { margin-top: 20px; font-size: var(--text-sm); font-weight: 600; color: var(--ink-soft); }

.mood-bars { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 12px; }
.mood-bar-row { display: grid; grid-template-columns: 104px minmax(0, 1fr) 28px; align-items: center; gap: 12px; font-size: var(--text-sm); }
.mood-bar-track { height: 10px; border-radius: 999px; background: var(--surface-sunken); overflow: hidden; }
.mood-bar-fill { display: block; height: 100%; border-radius: inherit; background: var(--mood); }
.mood-bar-count { text-align: right; font-variant-numeric: tabular-nums; color: var(--ink-soft); }

.reflection-rate { font-size: var(--text-sm); color: var(--ink-soft); }
.reflection-rate strong { display: block; font-family: var(--font-read); font-size: var(--text-2xl); color: var(--ink); }
.reflection-meter { height: 10px; margin-top: 12px; border-radius: 999px; background: var(--surface-sunken); overflow: hidden; }
.reflection-meter span { display: block; height: 100%; background: var(--accent); border-radius: inherit; }
.insights-questions { margin: 8px 0 0; padding-left: 1.2em; font-family: var(--font-read); line-height: 1.7; }
.insights-question-empty { margin-top: 20px; font-weight: 600; }
.insights-page .empty-state { margin-bottom: 24px; }
.insights-page .text-link { display: inline-block; margin-top: 10px; }


.insights-page .week-review-link { display: inline-flex; align-items: center; gap: 6px; margin-top: 12px; }
.week-review-link svg.lucide { width: 16px; height: 16px; }

/* Weekly review */
.week-header { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 20px; }
.week-nav { display: flex; align-items: center; gap: 6px; margin-left: -8px; }
.week-header h1 { font-size: var(--text-2xl); }
.icon-button.is-disabled { opacity: 0.4; cursor: default; }
.icon-button.is-disabled:hover { background: transparent; color: var(--ink-soft); }
@media (max-width: 760px) {
    .week-header h1 { font-size: var(--text-xl); }
}

.mood-strip-week { grid-template-columns: repeat(7, minmax(0, 1fr)); max-width: 420px; }

.week-reflection + .week-reflection { margin-top: 22px; }
.week-reflection h3 { font-size: var(--text-sm); font-weight: 600; color: var(--ink-soft); margin-bottom: 8px; }
.week-reflection ul { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.week-reflection li { display: grid; grid-template-columns: 40px minmax(0, 1fr); gap: 10px; align-items: baseline; }
.week-reflection .reflection-answer { margin: 0; }
.week-reflection-day { font-size: var(--text-xs); font-weight: 600; color: var(--ink-faint); text-transform: uppercase; letter-spacing: 0.04em; }
.week-muted { font-size: var(--text-sm); color: var(--ink-faint); }
.tag-count { margin-left: 4px; color: var(--ink-faint); }

/* ---------- 5f. Backup & export ---------- */
.backup-page .stat-value { font-size: var(--text-lg); overflow-wrap: anywhere; }
.backup-note {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    margin-bottom: 20px;
    font-size: var(--text-xs);
    color: var(--ink-faint);
    line-height: 1.5;
}
.backup-note svg.lucide { width: 14px; height: 14px; margin-top: 2px; }
.backup-note code { overflow-wrap: anywhere; color: var(--ink-soft); }
.backup-panel + .backup-panel, .backup-page .empty-state + .backup-panel { margin-top: 20px; }
.backup-page .empty-state { margin-bottom: 20px; }
.panel-text { margin: -8px 0 16px; font-size: var(--text-sm); color: var(--ink-soft); }

.download-list { margin: 0; padding: 0; list-style: none; }
.download-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 14px 0;
}
.download-row:first-child { padding-top: 0; }
.download-row:last-child { padding-bottom: 0; }
.download-row + .download-row { border-top: 1px solid var(--rule); }
.download-text h3 { font-size: var(--text-md); font-weight: 600; }
.download-text p { margin-top: 2px; font-size: var(--text-sm); color: var(--ink-soft); }
.download-row .button { flex-shrink: 0; }

.restore-form label { display: block; margin-bottom: 8px; font-size: var(--text-sm); font-weight: 600; }
.restore-form label span { font-weight: 400; color: var(--ink-faint); }
.restore-controls { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; }
.restore-controls input[type="file"] { flex: 1; min-width: 0; font-size: var(--text-sm); color: var(--ink-soft); }
.restore-controls input[type="file"]::file-selector-button {
    margin-right: 12px;
    padding: 7px 12px;
    border: 1px solid var(--rule-strong);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--ink);
    font: inherit;
    font-weight: 600;
    cursor: pointer;
}
.restore-controls input[type="file"]::file-selector-button:hover { border-color: var(--ink-faint); }

@media (max-width: 560px) {
    .download-row { flex-direction: column; align-items: stretch; }
}

/* ---------- 5h. Settings ---------- */

/* Header, rows, the data line and Delete share one column */
.main.settings-page > * { max-width: 600px; }

/* Collapsed rows in one card; each opens its own form */
.settings-list {
    border: 1px solid var(--rule);
    border-radius: var(--radius-lg);
    background: var(--surface);
}
.settings-row + .settings-row { border-top: 1px solid var(--rule); }
/* A closed section's form (and its password inputs) gets no layout box at
   all, so the browser has nothing to autofill. Newer Chrome otherwise only
   skips painting closed <details> content. */
details[name="settings-section"]:not([open]) > :not(summary) { display: none; }
.settings-summary, .settings-delete-toggle { list-style: none; cursor: pointer; }
.settings-summary::-webkit-details-marker, .settings-delete-toggle::-webkit-details-marker { display: none; }
.settings-summary {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    min-height: 56px;
    padding: 12px 20px;
    border-radius: var(--radius-lg);
}
.settings-summary:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.settings-summary-text { display: flex; flex-wrap: wrap; align-items: baseline; gap: 2px 12px; min-width: 0; }
.settings-label { font-size: var(--text-sm); font-weight: 600; min-width: 5.5em; }
.settings-value { min-width: 0; overflow-wrap: anywhere; font-size: var(--text-sm); color: var(--ink-soft); }
.settings-value.is-empty { color: var(--ink-faint); }
.settings-change { flex: none; font-size: var(--text-sm); font-weight: 500; color: var(--accent); }
.settings-summary:hover .settings-change { text-decoration: underline; }
.settings-row[open] .settings-change { visibility: hidden; }
.settings-body { padding: 4px 20px 20px; }

.settings-form { display: flex; flex-direction: column; gap: 18px; }
.settings-form .form-error { margin: 0; }
.settings-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.settings-note { font-size: var(--text-sm); color: var(--ink-soft); }
.settings-note a, .settings-line a { font-weight: 600; }
.settings-line { margin-top: 16px; font-size: var(--text-sm); color: var(--ink-soft); }
.settings-device-zone { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 12px; margin-top: -6px; }
.settings-device-zone:has(button[hidden]):has(span:empty) { display: none; }

/* Delete: apart from everything else, behind a quiet danger-colored toggle */
.settings-delete { margin-top: 48px; padding-top: 20px; border-top: 1px solid var(--rule); }
.settings-delete-toggle {
    display: inline-block;
    padding: 4px;
    margin-left: -4px;
    border-radius: var(--radius-sm);
    font-size: var(--text-sm);
    font-weight: 500;
    color: var(--danger);
}
.settings-delete-toggle:hover { text-decoration: underline; }
.settings-delete-toggle:focus-visible { outline: 2px solid var(--danger); outline-offset: 1px; }
.settings-danger {
    display: flex;
    flex-direction: column;
    gap: 14px;
    margin-top: 12px;
    padding: 22px;
    border: 1px solid color-mix(in srgb, var(--danger) 40%, var(--rule));
    border-radius: var(--radius-lg);
    background: var(--surface);
}
.settings-danger-title { font-size: var(--text-md); font-weight: 600; color: var(--danger); }

@media (max-width: 760px) {
    .settings-summary { padding: 12px 16px; }
    .settings-body { padding: 4px 16px 18px; }
    .settings-danger { padding: 18px 16px; }
}
