/* =========================================================================
 * Balance — web design system.
 *
 * One file. Loaded by every page in the redesign (landing, today, log,
 * library, account). Contains:
 *
 *   - @font-face / web fonts (Instrument Serif + Inter + JetBrains Mono)
 *   - Design tokens as CSS custom properties (light + dark via :root and
 *     [data-theme="dark"]). Token names match the iOS handoff verbatim.
 *   - Per-area colors derived from `--area-hue` (set inline per-element)
 *     using oklch().
 *   - Reusable utility classes: typography (.bal-serif, .bal-sans,
 *     .bal-mono), buttons (.bal-btn, .bal-btn--ghost), pills, eyebrows.
 *   - App shell layout: sidebar (240px) + main pane.
 *   - Cards, hairlines, tile primitives.
 *   - Animations (bar-grow, fade, rise).
 *
 * Theme switching: read prefers-color-scheme; honor a `bal-theme` cookie /
 * localStorage override. The actual JS lives in app.js.
 *
 * Legacy pages (public/data.html, service-status.html) still use
 * debug.css and are unaffected — they keep their existing look.
 * ========================================================================= */

@import url('https://fonts.googleapis.com/css2?family=Instrument+Serif:ital@0;1&family=Inter:wght@300;400;500;600;700&family=JetBrains+Mono:wght@400;500&display=swap');

/* --- Tokens --------------------------------------------------------------
 *
 * Colors were copied from the web design hand-off so the web app
 * matches iOS pixel-for-pixel. oklch() is universally supported across
 * the browsers we target (Safari 15.4+, Chrome 111+, Firefox 113+).
 */

:root {
    --paper:    oklch(0.975 0.008 85);
    --paper2:   oklch(0.955 0.01 80);
    --card:     #ffffff;
    --cardHi:   oklch(0.985 0.005 80);
    --ink:      oklch(0.24 0.012 60);
    --inkDim:   oklch(0.34 0.012 60);
    --muted:    oklch(0.56 0.01 60);
    --muted2:   oklch(0.72 0.008 70);
    --hairline: oklch(0.9 0.008 70);
    --hairline2:oklch(0.93 0.008 70);
    --accent:   oklch(0.55 0.13 35);
    --sidebar:  oklch(0.96 0.01 80);
    --danger:   oklch(0.55 0.17 25);
    --shadow-card:  0 1px 2px rgba(60, 50, 40, 0.04);
    --shadow-modal: 0 24px 60px rgba(0, 0, 0, 0.35);
}

[data-theme="dark"] {
    --paper:    oklch(0.13 0.012 70);
    --paper2:   oklch(0.155 0.013 70);
    --card:     oklch(0.18 0.012 70);
    --cardHi:   oklch(0.215 0.012 70);
    --ink:      oklch(0.94 0.01 80);
    --inkDim:   oklch(0.85 0.01 75);
    --muted:    oklch(0.66 0.012 70);
    --muted2:   oklch(0.5 0.01 70);
    --hairline: oklch(0.27 0.012 70);
    --hairline2:oklch(0.23 0.012 70);
    --accent:   oklch(0.72 0.13 35);
    --sidebar:  oklch(0.11 0.012 70);
    --danger:   oklch(0.66 0.16 25);
    --shadow-card:  0 1px 2px rgba(0, 0, 0, 0.3);
}

/* --- Reset + base -------------------------------------------------------- */

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

html, body {
    margin: 0;
    padding: 0;
    min-height: 100%;
    background: var(--paper);
    color: var(--ink);
    font-family: 'Inter', -apple-system, system-ui, sans-serif;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

button { font-family: inherit; color: inherit; }

a { color: inherit; }

/* Paper-tinted scrollbar — matches the iOS feel. */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
    background: rgba(120, 110, 100, 0.22);
    border-radius: 5px;
    border: 2px solid transparent;
    background-clip: padding-box;
}
::-webkit-scrollbar-thumb:hover { background: rgba(120, 110, 100, 0.35); background-clip: padding-box; }

/* --- Typography ---------------------------------------------------------- */

.bal-serif {
    font-family: 'Instrument Serif', 'Times New Roman', serif;
    font-weight: 400;
    letter-spacing: -0.01em;
}
.bal-sans  { font-family: 'Inter', -apple-system, system-ui, sans-serif; }
.bal-mono  { font-family: 'JetBrains Mono', ui-monospace, monospace; font-variant-numeric: tabular-nums; }

.bal-h1   { font-family: 'Instrument Serif', serif; font-weight: 400; font-size: 48px; line-height: 1; letter-spacing: -0.6px; margin: 0; color: var(--ink); }
.bal-h2   { font-family: 'Instrument Serif', serif; font-weight: 400; font-size: 28px; line-height: 1.05; letter-spacing: -0.4px; margin: 0; color: var(--ink); }
.bal-h3   { font-family: 'Instrument Serif', serif; font-weight: 400; font-size: 22px; line-height: 1.1; letter-spacing: -0.2px; margin: 0; color: var(--ink); }
.bal-em   { color: var(--accent); font-style: italic; }

.bal-eyebrow {
    font-family: 'Inter', sans-serif;
    font-size: 11px;
    font-weight: 500;
    letter-spacing: 1.6px;
    text-transform: uppercase;
    color: var(--muted2);
}

.bal-muted    { color: var(--muted); }
.bal-muted2   { color: var(--muted2); }
.bal-ink      { color: var(--ink); }
.bal-inkDim   { color: var(--inkDim); }

/* --- Buttons ------------------------------------------------------------- */

.bal-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 16px;
    border: none;
    border-radius: 10px;
    background: var(--ink);
    color: var(--paper);
    font-family: 'Inter', sans-serif;
    font-size: 13.5px;
    font-weight: 500;
    letter-spacing: -0.1px;
    cursor: pointer;
    text-decoration: none;
}
.bal-btn:hover { filter: brightness(1.1); }
.bal-btn:disabled { opacity: 0.5; cursor: not-allowed; }

.bal-btn--ghost {
    background: var(--card);
    color: var(--ink);
    border: 1px solid var(--hairline);
    padding: 8px 13px;
    font-size: 13px;
    border-radius: 9px;
}
.bal-btn--ghost:hover { background: var(--cardHi); filter: none; }
.bal-btn--ghost.is-active { background: var(--cardHi); }

.bal-btn--danger {
    background: var(--danger);
    color: white;
}

.bal-iconbtn {
    width: 30px;
    height: 30px;
    border-radius: 8px;
    border: 1px solid var(--hairline);
    background: var(--card);
    color: var(--muted);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
.bal-iconbtn:hover { color: var(--ink); }

/* --- Cards / hairlines --------------------------------------------------- */

.bal-card {
    background: var(--card);
    border: 1px solid var(--hairline2);
    border-radius: 16px;
    box-shadow: var(--shadow-card);
}
.bal-card--lg { border-radius: 22px; }
.bal-card--sm { border-radius: 14px; }

.bal-hairline { border-top: 1px solid var(--hairline2); }

/* --- App shell ----------------------------------------------------------- */

body.app {
    display: flex;
    min-height: 100vh;
    margin: 0;
}

.bal-sidebar {
    width: 240px;
    flex-shrink: 0;
    background: var(--sidebar);
    border-right: 1px solid var(--hairline2);
    display: flex;
    flex-direction: column;
    padding: 26px 18px 22px;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
}

.bal-sidebar__brand {
    padding: 0 8px 26px;
    display: flex;
    align-items: center;
    gap: 10px;
}
.bal-sidebar__brand-mark {
    width: 30px; height: 30px;
    flex-shrink: 0;
    /* The favicon SVG itself is the mark — it ships its own paper-
       colored rounded background, so this wrapper has no visual
       styling beyond size + flex. */
    display: flex; align-items: center; justify-content: center;
}
.bal-sidebar__brand-name {
    font-family: 'Instrument Serif', serif;
    font-size: 22px;
    color: var(--ink);
    letter-spacing: -0.2px;
}

.bal-sidebar__nav {
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.bal-sidebar__nav a {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 9px 12px;
    border-radius: 9px;
    color: var(--muted);
    font-family: 'Inter', sans-serif;
    font-size: 14px;
    font-weight: 400;
    text-decoration: none;
}
.bal-sidebar__nav a:hover { color: var(--ink); }
.bal-sidebar__nav a.is-active {
    background: var(--card);
    color: var(--ink);
    font-weight: 500;
    box-shadow: inset 0 0 0 1px var(--hairline2);
}
.bal-sidebar__nav a svg { width: 16px; height: 16px; }

.bal-sidebar__group-label {
    margin: 26px 12px 8px;
}

.bal-sidebar__areas {
    display: flex;
    flex-direction: column;
    gap: 1px;
}
.bal-sidebar__area {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 6px 12px;
    border: none;
    background: transparent;
    cursor: pointer;
    text-align: left;
    color: var(--inkDim);
    font-family: 'Inter', sans-serif;
    font-size: 13px;
    border-radius: 7px;
    text-decoration: none;
}
.bal-sidebar__area:hover { background: var(--card); }
.bal-sidebar__area-dot {
    width: 8px; height: 8px;
    border-radius: 4px;
    background: oklch(0.72 0.11 var(--area-hue, 28));
}
[data-theme="dark"] .bal-sidebar__area-dot {
    background: oklch(0.6 0.13 var(--area-hue, 28));
}

.bal-sidebar__user {
    margin-top: auto;
    padding: 12px 8px 0;
    border-top: 1px solid var(--hairline2);
    display: flex;
    align-items: center;
    gap: 10px;
}
.bal-sidebar__avatar {
    width: 30px; height: 30px;
    border-radius: 15px;
    background: linear-gradient(135deg, oklch(0.92 0.04 28), oklch(0.92 0.04 50));
    color: oklch(0.42 0.09 28);
    display: flex; align-items: center; justify-content: center;
    font-family: 'Instrument Serif', serif;
    font-size: 13px;
    font-weight: 600;
    flex-shrink: 0;
}
[data-theme="dark"] .bal-sidebar__avatar {
    background: linear-gradient(135deg, oklch(0.28 0.05 28), oklch(0.28 0.05 50));
    color: oklch(0.86 0.075 28);
}
.bal-sidebar__user-name {
    font-family: 'Inter', sans-serif;
    font-size: 12.5px;
    color: var(--ink);
    font-weight: 500;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    min-width: 0;
}
.bal-sidebar__user-info {
    flex: 1;
    min-width: 0;
}
.bal-sidebar__user-meta {
    font-family: 'Inter', sans-serif;
    font-size: 11px;
    color: var(--muted2);
}

/* --- Main pane ----------------------------------------------------------- */

.bal-main {
    flex: 1;
    min-width: 0;
    background: var(--paper);
}

.bal-page-header {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    padding: 36px 48px 34px;
    gap: 24px;
}
.bal-page-header__left { min-width: 0; }
.bal-page-header__eyebrow { margin-bottom: 10px; }
.bal-page-header__right {
    display: flex;
    gap: 10px;
    align-items: center;
}

.bal-page-body { padding: 0 48px 48px; }

/* --- Stat strip --------------------------------------------------------- */

.bal-statstrip {
    margin: 0 48px 18px;
    padding: 14px 22px;
    background: var(--card);
    border: 1px solid var(--hairline2);
    border-radius: 14px;
    display: flex;
    flex-wrap: wrap;
    gap: 18px 28px;
    color: var(--inkDim);
    font-size: 13px;
}
.bal-statstrip strong { color: var(--ink); font-weight: 600; }
.bal-statstrip .sep { color: var(--muted2); }

/* --- Today: Rings tile -------------------------------------------------- */

.bal-rings-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 18px;
}

.bal-ring-tile {
    background: var(--card);
    border: 1px solid var(--hairline2);
    border-radius: 22px;
    padding: 28px 24px;
    display: flex;
    align-items: center;
    gap: 22px;
    position: relative;
    overflow: hidden;
    min-height: 180px;
}
.bal-ring-tile__glow {
    position: absolute;
    inset: 0;
    background: radial-gradient(circle at 22% 40%, oklch(0.68 0.13 var(--area-hue, 28)) 0%, transparent 55%);
    opacity: 0.14;
    pointer-events: none;
}
[data-theme="dark"] .bal-ring-tile__glow {
    background: radial-gradient(circle at 22% 40%, oklch(0.55 0.12 var(--area-hue, 28)) 0%, transparent 55%);
    opacity: 0.18;
}
.bal-ring-tile__svg {
    position: relative;
    width: 132px;
    height: 132px;
    flex-shrink: 0;
}
.bal-ring-tile__svg svg { transform: rotate(-90deg); }
.bal-ring-tile__emoji {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 28px;
}
.bal-ring-tile__body { position: relative; flex: 1; }
.bal-ring-tile__name { margin-bottom: 6px; }
.bal-ring-tile__value {
    display: flex;
    align-items: baseline;
    gap: 4px;
}
.bal-ring-tile__num {
    font-family: 'Instrument Serif', serif;
    font-size: 44px;
    color: var(--ink);
    letter-spacing: -0.8px;
    line-height: 1;
}
.bal-ring-tile__den {
    font-family: 'JetBrains Mono', monospace;
    font-size: 13px;
    color: var(--muted2);
}
.bal-ring-tile__bar {
    margin-top: 12px;
    height: 3px;
    border-radius: 2px;
    background: var(--hairline);
    overflow: hidden;
}
.bal-ring-tile__bar-fill {
    height: 100%;
    background: oklch(0.72 0.11 var(--area-hue, 28));
    transform-origin: left;
    animation: bal-grow 0.7s cubic-bezier(.2,.7,.3,1);
}
[data-theme="dark"] .bal-ring-tile__bar-fill {
    background: oklch(0.6 0.13 var(--area-hue, 28));
}

/* --- Today: Bars -------------------------------------------------------- */

.bal-bars-layout {
    display: grid;
    grid-template-columns: 1.6fr 1fr;
    gap: 24px;
    align-items: start;
}

.bal-bar-row { }
.bal-bar-row__head {
    display: flex;
    align-items: baseline;
    margin-bottom: 6px;
}
.bal-bar-row__emoji { font-size: 14px; margin-right: 8px; }
.bal-bar-row__name { font-size: 14px; font-weight: 500; color: var(--ink); }
.bal-bar-row__value { margin-left: auto; font-family: 'JetBrains Mono', monospace; font-size: 12px; color: var(--muted); white-space: nowrap; }
.bal-bar-row__num { color: var(--ink); font-weight: 500; }
.bal-bar-row__sep { color: var(--muted2); }
.bal-bar-row__track {
    height: 10px;
    border-radius: 6px;
    background: oklch(0.94 0.025 var(--area-hue, 28));
    overflow: hidden;
}
[data-theme="dark"] .bal-bar-row__track {
    background: oklch(0.23 0.03 var(--area-hue, 28));
}
.bal-bar-row__fill {
    height: 100%;
    background: oklch(0.72 0.11 var(--area-hue, 28));
    border-radius: 6px;
    transform-origin: left;
    animation: bal-grow 0.7s cubic-bezier(.2,.7,.3,1);
}
[data-theme="dark"] .bal-bar-row__fill { background: oklch(0.6 0.13 var(--area-hue, 28)); }

/* --- Today: Garden ------------------------------------------------------ */

.bal-garden-layout {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 24px;
    align-items: start;
}

.bal-garden-hero {
    background: var(--card);
    border: 1px solid var(--hairline2);
    border-radius: 22px;
    padding: 32px;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: 14px;
}
.bal-garden-donut {
    /* Default 320px, but never wider than the hero card. aspect-ratio
     * keeps it circular when the width clamps on narrow viewports. */
    width: min(320px, 100%);
    aspect-ratio: 1;
    border-radius: 50%;
    position: relative;
    flex-shrink: 0;
}
.bal-garden-donut__hole {
    position: absolute;
    /* Percentage so the hole scales with the donut at narrow viewports. */
    inset: 12%;
    background: var(--card);
    border-radius: 50%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}
.bal-garden-donut__num {
    font-family: 'Instrument Serif', serif;
    font-size: 84px;
    color: var(--ink);
    letter-spacing: -2px;
    line-height: 1;
}
.bal-garden-donut__den {
    font-family: 'JetBrains Mono', monospace;
    font-size: 13px;
    color: var(--muted);
    margin-top: 6px;
}
.bal-garden-tiles {
    display: grid;
    grid-template-columns: 1fr;
    gap: 10px;
}
.bal-garden-tile {
    background: var(--card);
    border: 1px solid var(--hairline2);
    border-radius: 14px;
    padding: 14px 18px;
    display: flex;
    align-items: center;
    gap: 14px;
    position: relative;
    overflow: hidden;
}
.bal-garden-tile__bar {
    position: absolute;
    left: 0; top: 0; bottom: 0;
    width: 3px;
    background: oklch(0.72 0.11 var(--area-hue, 28));
}
[data-theme="dark"] .bal-garden-tile__bar { background: oklch(0.6 0.13 var(--area-hue, 28)); }
.bal-garden-tile__swatch {
    width: 32px; height: 32px;
    border-radius: 9px;
    background: oklch(0.92 0.04 var(--area-hue, 28));
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    flex-shrink: 0;
}
[data-theme="dark"] .bal-garden-tile__swatch { background: oklch(0.28 0.05 var(--area-hue, 28)); }
.bal-garden-tile__body { flex: 1; min-width: 0; }
.bal-garden-tile__name { font-size: 14px; color: var(--ink); font-weight: 500; }
.bal-garden-tile__row { display: flex; align-items: baseline; gap: 6px; margin-top: 2px; }
.bal-garden-tile__num { font-family: 'JetBrains Mono', monospace; font-size: 13px; color: var(--ink); font-weight: 500; }
.bal-garden-tile__den { font-family: 'JetBrains Mono', monospace; font-size: 11px; color: var(--muted2); }
.bal-garden-tile__progress {
    height: 4px;
    width: 100%;
    border-radius: 2px;
    background: var(--hairline);
    overflow: hidden;
    margin-top: 6px;
}
.bal-garden-tile__fill {
    height: 100%;
    background: oklch(0.72 0.11 var(--area-hue, 28));
    transform-origin: left;
    animation: bal-grow 0.7s cubic-bezier(.2,.7,.3,1);
}
[data-theme="dark"] .bal-garden-tile__fill { background: oklch(0.6 0.13 var(--area-hue, 28)); }

/* --- Pills (used in Log + Library) -------------------------------------- */

.bal-pill {
    display: inline-flex;
    font-family: 'JetBrains Mono', monospace;
    font-size: 10.5px;
    padding: 3px 8px;
    border-radius: 7px;
    background: oklch(0.92 0.04 var(--area-hue, 28));
    color: oklch(0.42 0.09 var(--area-hue, 28));
}
[data-theme="dark"] .bal-pill {
    background: oklch(0.28 0.05 var(--area-hue, 28));
    color: oklch(0.86 0.075 var(--area-hue, 28));
}

/* --- Log timeline ------------------------------------------------------- */

.bal-log-layout {
    display: grid;
    grid-template-columns: 1fr 300px;
    gap: 28px;
    align-items: start;
}
.bal-log-day { display: flex; flex-direction: column; gap: 10px; margin-bottom: 26px; }
.bal-log-day__head { display: flex; align-items: baseline; gap: 10px; }
.bal-log-day__count { font-size: 12px; color: var(--muted2); }
.bal-log-row {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 14px 22px;
    border-top: 1px solid var(--hairline2);
}
.bal-log-row:first-child { border-top: none; }
.bal-log-row__time {
    font-family: 'JetBrains Mono', monospace;
    font-size: 12px;
    color: var(--muted2);
    width: 70px;
    flex-shrink: 0;
}
.bal-log-row__title {
    flex: 1;
    font-size: 14px;
    color: var(--ink);
    font-weight: 500;
    min-width: 0;
}
.bal-log-row__pills {
    display: flex;
    gap: 5px;
    flex-wrap: wrap;
    justify-content: flex-end;
}
.bal-log-row__remove {
    flex-shrink: 0;
    background: transparent;
    border: none;
    color: var(--muted2);
    cursor: pointer;
    width: 28px;
    height: 28px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
}
.bal-log-row__remove:hover { color: var(--danger); background: var(--cardHi); }

.bal-log-aside {
    background: var(--card);
    border: 1px solid var(--hairline2);
    border-radius: 14px;
    padding: 20px 22px;
    position: sticky;
    top: 24px;
}
.bal-log-aside__filter {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 20px;
}
.bal-filter-row {
    display: flex;
    align-items: center;
    gap: 9px;
    cursor: pointer;
    padding: 4px 0;
    user-select: none;
}
.bal-filter-row__swatch {
    width: 14px; height: 14px;
    border-radius: 4px;
    border: 1.5px solid oklch(0.72 0.11 var(--area-hue, 28));
    background: oklch(0.92 0.04 var(--area-hue, 28));
    flex-shrink: 0;
}
[data-theme="dark"] .bal-filter-row__swatch {
    border-color: oklch(0.6 0.13 var(--area-hue, 28));
    background: oklch(0.28 0.05 var(--area-hue, 28));
}
.bal-filter-row.is-off .bal-filter-row__swatch {
    background: var(--card);
    opacity: 0.55;
}
.bal-filter-row__label {
    font-size: 13px;
    color: var(--inkDim);
}

.bal-heatmap {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 4px;
    margin-bottom: 10px;
}
.bal-heatmap__cell {
    text-align: center;
}
.bal-heatmap__box {
    height: 28px;
    border-radius: 5px;
    background: oklch(0.94 0.025 28);
    border: 1px solid var(--hairline2);
    position: relative;
    overflow: hidden;
}
[data-theme="dark"] .bal-heatmap__box { background: oklch(0.23 0.03 28); }
.bal-heatmap__fill {
    position: absolute;
    inset: 0;
    background: var(--accent);
}
.bal-heatmap__day {
    font-family: 'JetBrains Mono', monospace;
    font-size: 9px;
    color: var(--muted2);
    margin-top: 4px;
}

/* --- Library areas grid ------------------------------------------------- */

.bal-areas-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
    margin-bottom: 36px;
}
.bal-area-card {
    background: var(--card);
    border: 1px solid var(--hairline2);
    border-radius: 16px;
    padding: 18px 20px;
    cursor: pointer;
    text-align: left;
    display: flex;
    align-items: center;
    gap: 14px;
    position: relative;
    overflow: hidden;
}
.bal-area-card__bar {
    position: absolute;
    left: 0; top: 0; bottom: 0;
    width: 3px;
    background: oklch(0.72 0.11 var(--area-hue, 28));
}
[data-theme="dark"] .bal-area-card__bar { background: oklch(0.6 0.13 var(--area-hue, 28)); }
.bal-area-card__swatch {
    width: 44px; height: 44px;
    border-radius: 12px;
    background: oklch(0.92 0.04 var(--area-hue, 28));
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    flex-shrink: 0;
}
[data-theme="dark"] .bal-area-card__swatch { background: oklch(0.28 0.05 var(--area-hue, 28)); }
.bal-area-card__body { flex: 1; min-width: 0; }
.bal-area-card__name {
    font-size: 15px;
    color: var(--ink);
    font-weight: 500;
}
.bal-area-card__count {
    font-size: 12px;
    color: var(--muted);
    margin-top: 2px;
}

/* --- Library activities table ------------------------------------------- */

.bal-table {
    background: var(--card);
    border: 1px solid var(--hairline2);
    border-radius: 16px;
    overflow: hidden;
}
.bal-table__head {
    display: grid;
    grid-template-columns: 2.2fr 2fr 1.5fr 40px;
    padding: 10px 22px;
    border-bottom: 1px solid var(--hairline2);
    background: var(--cardHi);
    gap: 16px;
}
.bal-table__head > * { font-size: 10.5px; letter-spacing: 1.4px; text-transform: uppercase; color: var(--muted2); font-weight: 500; }
.bal-table__row {
    display: grid;
    grid-template-columns: 2.2fr 2fr 1.5fr 40px;
    align-items: center;
    padding: 14px 22px;
    border-top: 1px solid var(--hairline2);
    background: none;
    border-left: none;
    border-right: none;
    border-bottom: none;
    cursor: pointer;
    text-align: left;
    width: 100%;
    gap: 16px;
}
.bal-table__row:first-child { border-top: none; }
.bal-table__row:hover { background: var(--cardHi); }
.bal-table__row__title { font-size: 14px; color: var(--ink); font-weight: 500; }
.bal-table__row__desc  { font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bal-table__row__pills { display: flex; gap: 5px; flex-wrap: wrap; }
.bal-table__row__chev  { color: var(--muted2); justify-self: end; }

/* --- Account ------------------------------------------------------------ */

.bal-account-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 18px;
    align-items: start;
}
.bal-account-profile {
    grid-column: 1 / -1;
    display: flex;
    align-items: center;
    gap: 18px;
    padding: 22px 24px;
}
.bal-account-profile__avatar {
    width: 66px; height: 66px;
    border-radius: 33px;
    background: linear-gradient(135deg, oklch(0.92 0.04 28), oklch(0.92 0.04 50));
    color: oklch(0.42 0.09 28);
    display: flex; align-items: center; justify-content: center;
    font-family: 'Instrument Serif', serif;
    font-size: 24px;
    font-weight: 600;
}
[data-theme="dark"] .bal-account-profile__avatar {
    background: linear-gradient(135deg, oklch(0.28 0.05 28), oklch(0.28 0.05 50));
    color: oklch(0.86 0.075 28);
}
.bal-account-profile__name { font-size: 18px; color: var(--ink); font-weight: 600; }
.bal-account-profile__meta { font-size: 13px; color: var(--muted); margin-top: 3px; }
.bal-account-section { }
.bal-account-section__label {
    margin-bottom: 10px;
    padding-left: 4px;
}
.bal-account-list {
    background: var(--card);
    border: 1px solid var(--hairline2);
    border-radius: 14px;
    overflow: hidden;
}
.bal-account-row {
    display: flex;
    align-items: center;
    padding: 14px 20px;
    border-top: 1px solid var(--hairline2);
    background: none;
    border-left: none;
    border-right: none;
    border-bottom: none;
    width: 100%;
    cursor: pointer;
    color: var(--ink);
    font-size: 14px;
    text-decoration: none;
}
.bal-account-row:first-child { border-top: none; }
.bal-account-row:hover { background: var(--cardHi); }
.bal-account-row.is-static { cursor: default; }
.bal-account-row.is-static:hover { background: none; }
.bal-account-row__label { flex: 1; }
.bal-account-row__value { font-family: 'JetBrains Mono', monospace; font-size: 12.5px; color: var(--muted); }
.bal-account-row__chev { color: var(--muted2); margin-left: 10px; }
.bal-account-row.is-danger .bal-account-row__label { color: var(--danger); }

/* iOS-style toggle pill */
.bal-toggle {
    width: 44px;
    height: 24px;
    border-radius: 12px;
    border: none;
    background: var(--hairline);
    position: relative;
    cursor: pointer;
    flex-shrink: 0;
}
.bal-toggle.is-on { background: var(--accent); }
.bal-toggle__thumb {
    position: absolute;
    top: 2px;
    left: 2px;
    width: 20px;
    height: 20px;
    border-radius: 10px;
    background: var(--card);
    transition: left 0.18s ease;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}
.bal-toggle.is-on .bal-toggle__thumb { left: 22px; }

/* --- Modal -------------------------------------------------------------- */

.bal-modal-backdrop {
    position: fixed;
    inset: 0;
    z-index: 200;
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 40px;
    animation: bal-fade 0.16s ease;
}
.bal-modal {
    background: var(--paper2);
    border-radius: 20px;
    width: 560px;
    max-width: 100%;
    max-height: 86vh;
    display: flex;
    flex-direction: column;
    border: 1px solid var(--hairline);
    box-shadow: var(--shadow-modal);
    animation: bal-rise 0.22s cubic-bezier(.2,.7,.3,1);
}
.bal-modal__head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 18px 22px;
    border-bottom: 1px solid var(--hairline2);
}
.bal-modal__title {
    font-family: 'Instrument Serif', serif;
    font-size: 22px;
    color: var(--ink);
    letter-spacing: -0.2px;
}
.bal-modal__close {
    border: none;
    background: none;
    cursor: pointer;
    color: var(--muted);
    width: 30px;
    height: 30px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
}
.bal-modal__close:hover { color: var(--ink); background: var(--cardHi); }
.bal-modal__body {
    padding: 20px 22px;
    overflow-y: auto;
    flex: 1;
}
.bal-modal__foot {
    display: flex;
    gap: 10px;
    padding: 14px 22px;
    border-top: 1px solid var(--hairline2);
    justify-content: flex-end;
}

/* --- Form fields (used in editor modals) -------------------------------- */

.bal-field { margin-bottom: 14px; }
.bal-field__label {
    display: block;
    font-family: 'Inter', sans-serif;
    font-size: 11px;
    letter-spacing: 1.5px;
    text-transform: uppercase;
    color: var(--muted2);
    font-weight: 500;
    margin-bottom: 6px;
}
.bal-field__input {
    width: 100%;
    padding: 10px 14px;
    border-radius: 10px;
    border: 1px solid var(--hairline);
    background: var(--card);
    color: var(--ink);
    font-family: 'Inter', sans-serif;
    font-size: 14px;
}
.bal-field__input:focus {
    outline: none;
    border-color: var(--accent);
}
.bal-field__hint {
    font-size: 11px;
    color: var(--muted2);
    margin-top: 4px;
}

/* --- Activity picker (modal body) --------------------------------------- */

.bal-activity-picker {
    background: var(--card);
    border-radius: 12px;
    border: 1px solid var(--hairline2);
    overflow: hidden;
}
.bal-activity-picker__row {
    display: flex;
    align-items: center;
    width: 100%;
    padding: 12px 16px;
    border: none;
    background: none;
    cursor: pointer;
    text-align: left;
    border-top: 1px solid var(--hairline2);
}
.bal-activity-picker__row:first-child { border-top: none; }
.bal-activity-picker__row:hover { background: var(--cardHi); }
.bal-activity-picker__radio {
    width: 20px;
    height: 20px;
    border-radius: 10px;
    border: 1.5px solid var(--muted2);
    background: transparent;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-right: 12px;
    flex-shrink: 0;
}
.bal-activity-picker__row.is-selected .bal-activity-picker__radio {
    border-color: var(--accent);
    background: var(--accent);
}
.bal-activity-picker__row.is-selected .bal-activity-picker__radio::after {
    content: '';
    width: 7px;
    height: 7px;
    border-radius: 4px;
    background: var(--card);
}
.bal-activity-picker__title {
    flex: 1;
    font-size: 14px;
    color: var(--ink);
    font-weight: 500;
}

/* --- Today header right (segmented + log) ------------------------------ */

.bal-segmented {
    display: inline-flex;
    border: 1px solid var(--hairline);
    border-radius: 9px;
    background: var(--card);
    padding: 2px;
    gap: 2px;
}
.bal-segmented__btn {
    padding: 6px 12px;
    border: none;
    background: transparent;
    border-radius: 7px;
    color: var(--muted);
    font-family: 'Inter', sans-serif;
    font-size: 12.5px;
    font-weight: 500;
    cursor: pointer;
}
.bal-segmented__btn:hover { color: var(--ink); }
.bal-segmented__btn.is-active {
    background: var(--cardHi);
    color: var(--ink);
}

/* --- Animations --------------------------------------------------------- */

@keyframes bal-fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes bal-rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }
@keyframes bal-grow { from { transform: scaleX(0); } to { transform: scaleX(1); } }

/* --- Inline status messages --------------------------------------------- */

.bal-empty {
    text-align: center;
    padding: 60px 24px;
    color: var(--muted);
    font-size: 14px;
    line-height: 1.6;
}
.bal-empty strong { color: var(--ink); font-weight: 500; }

/* --- Mobile shell: top bar + slide-in sidebar -------------------------- */
/*
 * Hidden on desktop. The mobile media query below shows it and turns
 * the desktop sticky-column sidebar into a slide-in overlay.
 */
.bal-mobile-bar { display: none; }
.bal-sidebar-backdrop { display: none; }

/* --- Responsive: tablet collapse --------------------------------------- */

@media (max-width: 960px) {
    .bal-rings-grid    { grid-template-columns: 1fr; }
    .bal-bars-layout   { grid-template-columns: 1fr; }
    .bal-garden-layout { grid-template-columns: 1fr; }
    .bal-log-layout    { grid-template-columns: 1fr; }
    .bal-areas-grid    { grid-template-columns: 1fr; }
    .bal-account-grid  { grid-template-columns: 1fr; }
    .bal-page-header   { padding: 24px 24px 18px; flex-wrap: wrap; }
    .bal-page-body     { padding: 0 24px 32px; }
    .bal-statstrip     { margin: 0 24px 14px; }
}

/* --- Responsive: mobile (≤720px) — phone-class viewport ---------------- */

@media (max-width: 720px) {
    /* Stop laying body.app as flex(sidebar | main); on mobile the
       sidebar is an overlay on top of the main content, not a sibling
       column. */
    body.app {
        display: block;
    }

    /* Sticky top bar — hamburger + brand. */
    .bal-mobile-bar {
        display: flex;
        align-items: center;
        gap: 10px;
        padding: 10px 14px;
        background: var(--paper);
        border-bottom: 1px solid var(--hairline);
        position: sticky;
        top: 0;
        z-index: 50;
    }
    .bal-mobile-bar__hamburger {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        width: 40px; height: 40px;
        border-radius: 10px;
        border: 1px solid var(--hairline);
        background: transparent;
        color: var(--ink);
        cursor: pointer;
    }
    .bal-mobile-bar__brand-mark {
        width: 26px; height: 26px;
        flex-shrink: 0;
    }
    .bal-mobile-bar__name {
        font-family: 'Instrument Serif', serif;
        font-size: 22px;
        color: var(--ink);
        letter-spacing: -0.3px;
    }

    /* Sidebar becomes a fixed-position overlay panel. Off-screen by
       default; .is-open slides it in. The shadow + backdrop give it
       depth so users see they're in a layer. */
    .bal-sidebar {
        position: fixed;
        inset: 0 auto 0 0;
        height: 100vh;
        width: 280px;
        max-width: 86vw;
        z-index: 100;
        transform: translateX(-100%);
        transition: transform 0.25s ease;
        box-shadow: 0 0 24px rgba(0, 0, 0, 0.16);
    }
    .bal-sidebar.is-open {
        transform: translateX(0);
    }

    .bal-sidebar-backdrop {
        display: block;
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.4);
        z-index: 99;
        opacity: 0;
        pointer-events: none;
        transition: opacity 0.25s ease;
    }
    .bal-sidebar-backdrop.is-open {
        opacity: 1;
        pointer-events: auto;
    }

    /* Main content fills full width; tighter paddings + smaller H1. */
    .bal-main { width: 100%; }
    .bal-page-header {
        flex-direction: column;
        align-items: flex-start;
        padding: 18px 16px 14px;
        gap: 14px;
    }
    .bal-page-header__right {
        flex-wrap: wrap;
        width: 100%;
    }
    .bal-h1 { font-size: 36px; line-height: 1.05; }
    .bal-page-body { padding: 0 16px 24px; }
    .bal-statstrip { margin: 0 16px 14px; flex-wrap: wrap; }

    /* Garden donut — less hero padding gives the now-responsive donut
       (width: min(320px, 100%); see .bal-garden-donut earlier in the
       file) more breathing room, and the centered number is scaled
       down so it doesn't overflow the hole at iPhone SE width. */
    .bal-garden-hero       { padding: 20px 16px; }
    .bal-garden-donut__num { font-size: 64px; letter-spacing: -1.4px; }
}

/* --- Single-area focus page (/app/area) -------------------------------- */

.bal-area-hero {
    margin: 8px 0 24px;
}
.bal-area-hero__card {
    background: var(--card);
    border: 1px solid var(--hairline2);
    border-radius: 22px;
    padding: 36px 28px 32px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 22px;
}
.bal-area-hero__ring {
    position: relative;
    width: 200px;
    height: 200px;
}
.bal-area-hero__ring svg {
    transform: rotate(-90deg);
}
/* Emoji rides centered inside the ring — matches the today.js
   ring-tile pattern (emoji-inside, value-outside). */
.bal-area-hero__emoji {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 48px;
    line-height: 1;
}
.bal-area-hero__value {
    display: flex;
    align-items: baseline;
    gap: 8px;
}
.bal-area-hero__num {
    font-family: 'Instrument Serif', serif;
    font-size: 56px;
    color: var(--ink);
    letter-spacing: -1.2px;
    line-height: 1;
}
.bal-area-hero__den {
    font-family: 'JetBrains Mono', monospace;
    font-size: 14px;
    color: var(--muted2);
}
