:root {
            --bg-color: #0a0a0a;
            --card-bg: #161616;
            --accent-color: #ffffff;
            --text-dim: #a0a0a0;
            --primary-highlight: #3a86ff;
            --danger: #ff4d4d;
            --warn: #ffd166;
            --success: #06d6a0;
            --border-color: #222;
        }

        body {
            background-color: var(--bg-color);
            color: var(--accent-color);
            font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
            display: flex;
            justify-content: center;
            align-items: flex-start;
            min-height: 100vh;
            margin: 0;
            padding: 40px 20px;
        }

        .app-container {
            width: 100%;
            max-width: 600px;
            background: var(--card-bg);
            padding: 30px;
            border-radius: 40px;
            box-shadow: 0 20px 50px rgba(0,0,0,0.5);
            border: 1px solid var(--border-color);
        }

        /* Title row: h1 + header action buttons (zen / now / mode) */
        .title-row {
            display: flex;
            align-items: center;
            justify-content: space-between;
            gap: 12px;
            margin-bottom: 2rem;
        }
        h1 {
            font-weight: 600;
            font-size: 1.5rem;
            letter-spacing: -0.5px;
            margin: 0;
            text-align: center;
            text-transform: uppercase;
        }
        .header-actions { display: flex; gap: 8px; }
        .hdr-btn {
            background: #222; border: 1px solid #333; color: #ddd;
            padding: 7px 12px; border-radius: 10px; cursor: pointer;
            font-size: 0.68rem; text-transform: uppercase; letter-spacing: 0.6px; font-weight: 700;
            transition: background .2s, color .2s, border-color .2s, transform .12s;
        }
        .hdr-btn:hover { border-color: var(--primary-highlight); color: #fff; }
        .hdr-btn:active { transform: scale(0.96); }
        .hdr-btn:focus-visible { outline: 2px solid var(--primary-highlight); outline-offset: 2px; }

        .section-label {
            color: var(--text-dim);
            font-size: 0.7rem;
            text-transform: uppercase;
            margin: 32px 0 14px 0;
            letter-spacing: 1px;
            display: block;
            border-bottom: 1px solid #3a3a3a;
            padding-bottom: 5px;
        }

        .input-group { margin-bottom: 28px; }

        /* Day window: wake / bed time inputs + derived day-length readout */
        .day-window-row {
            display: flex;
            align-items: center;
            gap: 12px;
            flex-wrap: wrap;
        }
        .time-field {
            display: flex;
            flex-direction: column;
            gap: 4px;
            flex: 1;
            min-width: 110px;
        }
        .time-field-label {
            color: var(--text-dim);
            font-size: 0.62rem;
            text-transform: uppercase;
            letter-spacing: 1px;
        }
        .day-length {
            color: var(--success);
            font-size: 0.78rem;
            font-weight: 600;
            white-space: nowrap;
            margin-left: auto;
            align-self: flex-end;
            padding-bottom: 12px;
        }
        input[type="time"] {
            width: 100%;
            background: #222;
            border: 1px solid #333;
            color: white;
            padding: 12px;
            border-radius: 12px;
            font-size: 1rem;
            box-sizing: border-box;
            outline: none;
            transition: border 0.3s;
            color-scheme: dark;
        }
        input[type="time"]:focus { border-color: var(--primary-highlight); }

        input[type="text"], input[type="number"] {
            width: 100%;
            background: #222;
            border: 1px solid #333;
            color: white;
            padding: 12px;
            border-radius: 12px;
            font-size: 1rem;
            box-sizing: border-box;
            outline: none;
            transition: border 0.3s;
        }
        input:focus { border-color: var(--primary-highlight); }

        /* Multitask toggle */
        .toggle-row {
            display: flex;
            align-items: center;
            gap: 10px;
            margin: -8px 0 6px 2px;
        }
        .switch { position: relative; display: inline-block; width: 38px; height: 22px; flex: none; }
        .switch input { opacity: 0; width: 0; height: 0; }
        .switch .track {
            position: absolute; inset: 0; cursor: pointer;
            background: #333; border-radius: 22px; transition: background .25s;
        }
        .switch .track::before {
            content: ""; position: absolute; height: 16px; width: 16px; left: 3px; top: 3px;
            background: #aaa; border-radius: 50%; transition: transform .25s, background .25s;
        }
        .switch input:checked + .track { background: var(--primary-highlight); }
        .switch input:checked + .track::before { transform: translateX(16px); background: #fff; }
        .toggle-label { color: var(--text-dim); font-size: 0.78rem; }

        /* ROW STYLES */
        .category-row {
            display: grid;
            grid-template-columns: 1.6fr 0.9fr 1.35fr 84px 40px;
            gap: 10px;
            align-items: center;
            margin-bottom: 10px;
            padding: 10px;
            border-radius: 15px;
            background: #1c1c1c;
            transition: background 0.3s ease, border-color 0.3s ease, box-shadow 0.3s ease;
            border: 1px solid transparent;
            border-left: 3px solid #3a3a3a;
        }
        .category-row.is-percent { border-left: 3px dashed #2a2a2a; }
        /* Fixed rows carry an extra start-time input and a Done button: name | time |
           hrs | display | start/stop | Done | remove. */
        .category-row.is-fixed { grid-template-columns: 1.1fr 0.85fr 0.5fr 0.85fr 56px 54px 28px; }
        .category-row.done { opacity: 0.62; }
        .segment.done { opacity: 0.5; }
        .category-row.active { background: #222; }
        .category-row.alarm { animation: alarmPulse 0.9s infinite; }

        @keyframes alarmPulse {
            0%, 100% { box-shadow: 0 0 0 0 rgba(255,77,77,0); }
            50% { box-shadow: 0 0 0 4px rgba(255,77,77,0.55); border-left-color: var(--danger); }
        }

        /* Per-row progress bar: the fill IS the block's own color and grows with elapsed time.
           The unfilled track is a faded tint of that same color. */
        .progress {
            grid-column: 1 / -1;
            height: 8px;
            margin-top: 10px;
            border-radius: 6px;
            background: rgba(255,255,255,0.06);
            overflow: hidden;
        }
        .progress-fill {
            height: 100%;
            width: 0%;
            border-radius: 6px;
            transition: width 0.3s linear, background-color 0.3s ease;
        }

        .timer-display {
            display: flex;
            flex-direction: column;
            align-items: flex-end;
            text-align: right;
            line-height: 1.15;
        }
        .td-elapsed {
            font-family: 'Courier New', Courier, monospace;
            font-size: 0.85rem;
            color: var(--primary-highlight);
            transition: color 0.4s ease, opacity 0.25s ease;
        }
        .td-budget {
            font-size: 0.62rem;
            color: var(--text-dim);
            margin-top: 1px;
        }
        .category-row:not(.active) .td-elapsed { opacity: 0.5; }
        .category-row.active .td-elapsed { font-weight: 700; }

        .btn-timer {
            background: #333;
            border: none;
            color: white;
            min-height: 44px;
            padding: 10px 6px;
            border-radius: 10px;
            cursor: pointer;
            font-size: 0.78rem;
            text-transform: uppercase;
            font-weight: bold;
            transition: background 0.25s, color 0.25s;
        }
        .btn-timer.running { background: var(--accent-color); color: #111; }

        /* Done button (fixed blocks only): release leftover planned time to the splits.
           Visible in run mode too, so it stays the one explicit "I'm finished" action. */
        .btn-done {
            background: #333; border: none; color: #ddd;
            min-height: 44px; padding: 10px 4px; border-radius: 10px;
            cursor: pointer; font-size: 0.66rem; text-transform: uppercase;
            font-weight: bold; transition: background 0.25s, color 0.25s;
        }
        .btn-done:hover { background: #3a3a3a; color: #fff; }
        .btn-done.done { background: var(--success); color: #0a0a0a; }

        .btn-add {
            width: 100%;
            background: transparent;
            border: 1px dashed #444;
            color: var(--text-dim);
            padding: 12px;
            border-radius: 12px;
            cursor: pointer;
            margin-bottom: 20px;
            transition: all 0.3s;
        }
        .btn-add:hover { border-color: white; color: white; }

        .btn-remove {
            background: transparent;
            border: none;
            color: #6e6e6e;
            cursor: pointer;
            font-size: 1.2rem;
        }
        .btn-remove:hover { color: var(--danger); }

        /* VISUALIZER → wall-clock timeline (wake → bed) */
        .timeline {
            margin-top: 36px;
            width: 100%;
            position: relative;
        }
        .tl-bar {
            position: relative;
            height: 42px;
            width: 100%;
            background: #222;
            border: 1px solid #333;
            border-radius: 8px;
        }
        /* Layers inside the bar. Each is absolute inset:0 and clips its children to
           the rounded bar; the NOW line is a sibling with overflow visible so its
           dot/label can sit just outside the bar. */
        .tl-past, .tl-segs, .tl-blobs {
            position: absolute; inset: 0;
            overflow: hidden;
            border-radius: 7px;
        }
        .tl-past { background: #111; width: 0; transition: width 0.4s ease; z-index: 1; }
        .tl-segs { z-index: 2; }
        .tl-blobs { z-index: 3; pointer-events: none; }
        .segment {
            position: absolute;
            top: 0; bottom: 0;
            box-sizing: border-box;
            box-shadow: inset 1px 0 0 rgba(0,0,0,0.35);
            transition: width 0.5s cubic-bezier(0.4, 0, 0.2, 1), left 0.5s cubic-bezier(0.4, 0, 0.2, 1), background-color 0.6s ease, border-color 0.4s ease;
        }
        .segment.free {
            background: repeating-linear-gradient(45deg, #2a2a2a, #2a2a2a 4px, #232323 4px, #232323 8px) !important;
        }
        /* The bright bar inside a segment that "fills up" as time is spent against
           the budget — same look as the per-row progress pills. */
        .segment-fill {
            position: absolute;
            left: 0; top: 0; bottom: 0;
            width: 0;
            box-shadow: inset 0 0 0 1px rgba(255,255,255,0.10);
            transition: width 0.5s cubic-bezier(0.4, 0, 0.2, 1), background-color 0.4s ease;
            pointer-events: none;
            /* background-image (stripe density) set inline per tick — not transitioned. */
        }
        /* Spent-time blobs: a block's identity color, dimmed to read as history. */
        .spent-blob {
            position: absolute;
            top: 7px; bottom: 7px;
            min-width: 2px;
            border-radius: 4px;
            opacity: 0.4;
            box-shadow: inset 0 0 0 1px rgba(255,255,255,0.08);
            transition: left 0.3s linear, width 0.3s linear;
        }
        /* NOW marker: a vertical line + pulsing dot + label. It paints itself in the
           color of the currently-running timer (--now-color, set inline on #tlNow);
           green when nothing is running. color-mix derives the translucent glows. */
        .tl-now {
            position: absolute;
            top: -4px; bottom: -4px;
            width: 2px;
            background: var(--now-color, var(--success));
            transform: translateX(-50%);
            box-shadow: 0 0 10px color-mix(in srgb, var(--now-color, var(--success)) 65%, transparent);
            z-index: 6;
            transition: left 0.5s cubic-bezier(0.4, 0, 0.2, 1), background-color 0.4s ease, box-shadow 0.4s ease;
        }
        .tl-now-dot {
            position: absolute;
            top: -5px; left: 50%;
            width: 9px; height: 9px;
            transform: translateX(-50%);
            border-radius: 50%;
            background: var(--now-color, var(--success));
            box-shadow: 0 0 8px color-mix(in srgb, var(--now-color, var(--success)) 85%, transparent);
            animation: nowPulse 1.4s infinite;
        }
        .tl-now-label {
            position: absolute;
            top: -24px; left: 50%;
            transform: translateX(-50%);
            white-space: nowrap;
            font-size: 0.58rem;
            font-weight: 700;
            letter-spacing: 0.6px;
            color: var(--now-color, var(--success));
            background: #0a0a0a;
            padding: 1px 7px;
            border-radius: 8px;
            border: 1px solid color-mix(in srgb, var(--now-color, var(--success)) 45%, transparent);
        }
        /* Keep the NOW label inside the card at the very edges of the day. */
        .tl-now-label.edge-left { left: 0; transform: none; }
        .tl-now-label.edge-right { left: auto; right: 0; transform: none; }
        @keyframes nowPulse {
            0%, 100% { box-shadow: 0 0 6px color-mix(in srgb, var(--now-color, var(--success)) 60%, transparent); transform: translateX(-50%) scale(1); }
            50%      { box-shadow: 0 0 12px var(--now-color, var(--success));  transform: translateX(-50%) scale(1.25); }
        }
        /* Hour ticks beneath the bar */
        .tl-ticks {
            position: relative;
            height: 18px;
            margin-top: 6px;
            width: 100%;
        }
        .tl-tick {
            position: absolute;
            top: 0;
            transform: translateX(-50%);
            font-size: 0.58rem;
            color: var(--text-dim);
            white-space: nowrap;
        }
        .tl-tick-end { transform: translateX(-100%); }

        .results-list { margin-top: 16px; }
        .result-item {
            display: flex;
            justify-content: space-between;
            gap: 12px;
            padding: 8px 0;
            border-bottom: 1px solid #1a1a1a;
            font-size: 0.8rem;
        }
        .result-item:last-child { border-bottom: none; }
        .result-item span:last-child { text-align: right; white-space: nowrap; }
        .result-item.free-row span:first-child { font-weight: 600; }
        .time-val { font-weight: bold; color: var(--primary-highlight); }

        .total-warning {
            color: var(--danger);
            font-size: 0.8rem;
            text-align: center;
            margin-top: 10px;
            display: none;
        }
        .section-caption { color: var(--text-dim); font-size: 0.72rem; margin: -6px 0 10px 2px; }
        .viz-caption { color: var(--text-dim); font-size: 0.72rem; margin-top: 8px; }

        /* Undo / message toast */
        .toast {
            position: fixed; bottom: 24px; left: 50%;
            transform: translateX(-50%) translateY(20px);
            background: #222; border: 1px solid #333; color: #fff;
            padding: 12px 18px; border-radius: 14px;
            display: flex; gap: 16px; align-items: center;
            opacity: 0; pointer-events: none;
            transition: opacity .25s, transform .25s;
            z-index: 50; box-shadow: 0 10px 30px rgba(0,0,0,.6);
        }
        .toast.show { opacity: 1; transform: translateX(-50%) translateY(0); pointer-events: auto; }
        #toastUndo {
            background: var(--primary-highlight); border: none; color: #fff;
            padding: 6px 12px; border-radius: 8px; cursor: pointer;
            font-weight: bold; font-size: .8rem;
        }
        #toastUndo.hidden { display: none; }

        /* Reset the day */
        .btn-reset {
            width: 100%;
            background: transparent;
            border: 1px dashed #444;
            color: var(--text-dim);
            padding: 14px;
            border-radius: 14px;
            cursor: pointer;
            margin-top: 32px;
            font-size: 0.7rem;
            text-transform: uppercase;
            letter-spacing: 1px;
            font-weight: bold;
            transition: border-color 0.3s, color 0.3s, background 0.3s;
        }
        .btn-reset:hover { border-color: var(--danger); color: var(--danger); background: rgba(255,77,77,0.05); }
        .btn-reset:focus-visible { outline: 2px solid var(--primary-highlight); outline-offset: 2px; }

        /* Confirmation modal */
        .modal-backdrop {
            position: fixed; inset: 0;
            background: rgba(0,0,0,0.6);
            backdrop-filter: blur(4px);
            -webkit-backdrop-filter: blur(4px);
            display: flex; align-items: center; justify-content: center;
            padding: 20px;
            opacity: 0; pointer-events: none;
            transition: opacity 0.25s ease;
            z-index: 100;
        }
        .modal-backdrop.show { opacity: 1; pointer-events: auto; }
        .modal-card {
            background: var(--card-bg);
            border: 1px solid #333;
            border-radius: 28px;
            padding: 32px;
            max-width: 380px; width: 100%;
            box-shadow: 0 30px 80px rgba(0,0,0,0.7);
            transform: scale(0.96);
            transition: transform 0.25s cubic-bezier(0.2,0.8,0.2,1);
            text-align: center;
        }
        .modal-backdrop.show .modal-card { transform: scale(1); }
        .modal-card h2 {
            font-size: 1.25rem; font-weight: 600;
            letter-spacing: -0.3px; margin: 0 0 12px 0;
            text-transform: none; line-height: 1.3;
        }
        .modal-card p {
            color: var(--text-dim); font-size: 0.85rem;
            line-height: 1.5; margin: 0 0 24px 0;
        }
        .modal-actions { display: flex; flex-direction: column; gap: 10px; }
        .btn-cancel {
            width: 100%; background: #222; border: 1px solid #333;
            color: #fff; padding: 14px; border-radius: 14px;
            cursor: pointer; font-size: 0.8rem; font-weight: 600;
            transition: background 0.25s;
        }
        .btn-cancel:hover { background: #2a2a2a; }
        .btn-cancel:focus-visible { outline: 2px solid var(--primary-highlight); outline-offset: 2px; }

        /* Hold-to-confirm: deliberate, can't be clicked through by accident */
        .btn-confirm {
            position: relative; width: 100%;
            background: #1a1a1a; border: 1px solid var(--danger);
            color: #fff; padding: 14px; border-radius: 14px;
            cursor: pointer; font-size: 0.8rem; font-weight: 700;
            overflow: hidden;
            transition: border-color 0.3s, background 0.3s;
            -webkit-user-select: none; user-select: none;
            touch-action: none;
        }
        .btn-confirm:hover { background: #202020; }
        .btn-confirm:focus-visible { outline: 2px solid var(--primary-highlight); outline-offset: 2px; }
        .btn-confirm .htc-fill {
            position: absolute; top: 0; bottom: 0; left: 0; width: 0;
            background: var(--danger); opacity: 0.22;
            transition: width 1.3s linear;
        }
        .btn-confirm.holding .htc-fill { width: 100%; }
        .btn-confirm.complete { border-color: var(--success); background: rgba(6,214,160,0.12); }
        .btn-confirm.complete .htc-fill { background: var(--success); opacity: 0.25; }
        .btn-confirm .htc-label { position: relative; }

        /* Done slider modal (percent categories): plain click confirm, not hold-to-confirm. */
        .done-slider-row { display: flex; align-items: center; gap: 14px; margin: 0 0 24px; }
        #doneSlider { flex: 1; accent-color: var(--primary-highlight); cursor: pointer; }
        #doneVal { min-width: 72px; text-align: right; color: var(--text-dim); font-size: 0.85rem; }
        #doneConfirm { border-color: var(--primary-highlight); }
        #doneConfirm:hover { background: rgba(58,134,255,0.14); }

        /* ── RUN MODE: the home view. Strips editing UI; rows are name | remaining | Done + progress.
           Editing happens in the hold-to-edit bottom-sheet, not inline. ── */
        .app-container.mode-run .section-label,
        .app-container.mode-run .results-list,
        .app-container.mode-run .total-warning { display: none !important; }
        .app-container.mode-run .category-row {
            grid-template-columns: 1fr auto auto;
            cursor: pointer;
        }
        .app-container.mode-run .category-row input[type="number"],
        .app-container.mode-run .category-row input[type="time"],
        .app-container.mode-run .category-row .btn-timer,
        .app-container.mode-run .category-row .btn-remove { display: none; }
        .app-container.mode-run .category-row input[type="text"] {
            pointer-events: none;
            background: transparent;
            border-color: transparent;
            padding-left: 0;
        }
        .app-container.mode-run .category-row:active { transform: scale(0.985); }
        /* Sustained cue while a long-press is being captured (before the edit sheet opens). */
        .app-container.mode-run .category-row.holding { background: #242424; transform: scale(0.985); }
        .app-container.mode-run .category-row:focus-visible { outline: 2px solid var(--primary-highlight); outline-offset: 2px; }

        /* ── ZEN MODE: calm full-screen focus on the running timer(s) ── */
        .zen-overlay {
            position: fixed; inset: 0;
            background: rgba(8,8,8,0.93);
            backdrop-filter: blur(12px);
            -webkit-backdrop-filter: blur(12px);
            display: flex; flex-direction: column;
            align-items: center; justify-content: center;
            gap: 48px; padding: 40px 24px;
            opacity: 0; pointer-events: none;
            transition: opacity 0.4s ease;
            z-index: 200;
        }
        .zen-overlay.show { opacity: 1; pointer-events: auto; }
        .zen-content {
            display: flex; flex-wrap: wrap;
            align-items: center; justify-content: center;
            gap: 56px; width: 100%; max-width: 920px;
        }
        .zen-card {
            display: flex; flex-direction: column; align-items: center;
            min-width: 220px;
            border-top: 3px solid #333;
            padding-top: 20px;
        }
        .zen-name {
            color: var(--text-dim);
            font-size: 0.78rem; text-transform: uppercase; letter-spacing: 2.5px;
            margin-bottom: 20px; text-align: center; max-width: 320px;
        }
        .zen-time {
            font-family: 'Courier New', Courier, monospace;
            font-size: clamp(2.8rem, 11vw, 6.5rem);
            font-weight: 700; line-height: 1;
            transition: color 0.4s ease;
        }
        .zen-sub {
            color: var(--text-dim); font-size: 0.72rem; margin-top: 12px;
            letter-spacing: 1.5px; text-transform: uppercase;
        }
        .zen-progress {
            width: 100%; max-width: 320px; height: 4px;
            margin-top: 26px; border-radius: 4px;
            background: rgba(255,255,255,0.06); overflow: hidden;
        }
        .zen-progress-fill {
            height: 100%; width: 0%; border-radius: 4px;
            transition: width 0.3s linear, background-color 0.3s ease;
        }
        .zen-card.alarm .zen-time { animation: zenFlash 1s infinite; }
        @keyframes zenFlash { 0%, 100% { opacity: 1; } 50% { opacity: 0.35; } }
        .zen-empty { color: var(--text-dim); font-size: 0.95rem; letter-spacing: 1.5px; }
        .zen-exit {
            background: transparent; border: 1px solid #333; color: var(--text-dim);
            padding: 10px 24px; border-radius: 30px; cursor: pointer;
            font-size: 0.68rem; text-transform: uppercase; letter-spacing: 2px; font-weight: 600;
            transition: border-color 0.25s, color 0.25s;
        }
        .zen-exit:hover { border-color: var(--primary-highlight); color: #fff; }
        .zen-exit:focus-visible { outline: 2px solid var(--primary-highlight); outline-offset: 2px; }

        /* Zen button lights up while zen is active */
        .hdr-btn.active { background: var(--primary-highlight); color: #fff; border-color: var(--primary-highlight); }
        /* NOW button lights up green while the reflow is active (green = "present"). */
        #nowBtn.active { background: var(--success); color: #0a0a0a; border-color: var(--success); }

        /* Mobile expand chevron — hidden on desktop and in run mode; shown only
           inside the mobile media query for edit-mode rows. */
        .chevron { display: none; }

        @media (max-width: 520px) {
            .app-container { padding: 22px; border-radius: 28px; }

            /* Edit mode: each row becomes a compact summary (name · readout · chevron)
               that expands on tap to reveal the secondary fields at full size.
               Run mode keeps its grid (name | display | Done) and whole-row tap. */
            .app-container:not(.mode-run) .category-row {
                display: flex; flex-wrap: wrap; gap: 8px 10px; align-items: center;
            }
            /* Line 1 (always visible): name grows to fill, timer readout + chevron right. */
            .app-container:not(.mode-run) .category-row > input[type="text"] {
                flex: 1 1 auto; min-width: 0; order: 1;
            }
            .app-container:not(.mode-run) .category-row .timer-display { flex: 0 0 auto; order: 1; }
            .app-container:not(.mode-run) .chevron {
                display: inline-flex; align-items: center; justify-content: center;
                flex: 0 0 36px; min-height: 40px; order: 2;
                background: transparent; border: 1px solid #333; color: var(--text-dim);
                border-radius: 9px; cursor: pointer; font-size: 0.85rem;
                transition: transform 0.2s ease, color 0.2s ease, border-color 0.2s ease;
            }
            .app-container:not(.mode-run) .chevron:hover { color: #fff; border-color: #444; }
            .app-container:not(.mode-run) .category-row.expanded .chevron { transform: rotate(180deg); }

            /* Secondary fields: hidden while collapsed. */
            .app-container:not(.mode-run) .category-row > input[type="time"],
            .app-container:not(.mode-run) .category-row > input[type="number"],
            .app-container:not(.mode-run) .category-row .btn-timer,
            .app-container:not(.mode-run) .category-row .btn-done,
            .app-container:not(.mode-run) .category-row .btn-remove { display: none; }

            /* …revealed below when expanded. Inputs share a line; buttons share the next. */
            .app-container:not(.mode-run) .category-row.expanded > input[type="time"],
            .app-container:not(.mode-run) .category-row.expanded > input[type="number"] {
                display: block; flex: 1 1 45%; min-width: 0; order: 3;
            }
            .app-container:not(.mode-run) .category-row.is-percent.expanded > input[type="number"] {
                flex: 1 1 100%;   /* percent rows have only the % input on this line */
            }
            .app-container:not(.mode-run) .category-row.expanded .btn-timer {
                display: flex; flex: 1 1 50%; min-height: 44px; order: 4;
                align-items: center; justify-content: center;
            }
            .app-container:not(.mode-run) .category-row.expanded .btn-done {
                display: flex; flex: 0 0 76px; min-height: 44px; order: 4;
                align-items: center; justify-content: center;
            }
            .app-container:not(.mode-run) .category-row.expanded .btn-remove {
                display: flex; flex: 0 0 44px; min-height: 44px; order: 4;
                align-items: center; justify-content: center;
            }

            /* Progress bar always full-width, last. */
            .app-container:not(.mode-run) .category-row .progress { flex: 1 1 100%; order: 99; margin-top: 4px; }

            .td-elapsed { font-size: 0.8rem; }
            .td-budget { font-size: 0.58rem; }
            .day-length { margin: 0; padding: 0; align-self: center; }
        }
        @media (prefers-reduced-motion: reduce) {
            .category-row.alarm { animation: none; }
            .tl-now-dot { animation: none; }
            .progress-fill { transition: width 0.3s linear !important; }
            .segment, .tl-now, .spent-blob { transition: width 0.3s linear, left 0.3s linear !important; }
        }

        /* ── Timeline as the Day Window header (tap to edit wake/bed) ── */
        #visualizer { cursor: pointer; -webkit-tap-highlight-color: transparent; }
        #visualizer:active .tl-bar { transform: scale(0.992); }
        .tl-bar { transition: transform 0.15s ease; }
        .viz-caption { cursor: pointer; }

        /* ── Bottom sheets (per-category edit + day window) ── */
        .sheet-backdrop {
            position: fixed; inset: 0;
            background: rgba(0,0,0,0.55);
            backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px);
            opacity: 0; pointer-events: none;
            transition: opacity 0.25s ease;
            z-index: 160;
            display: flex; align-items: flex-end; justify-content: center;
        }
        .sheet-backdrop.show { opacity: 1; pointer-events: auto; }
        .sheet {
            background: var(--card-bg);
            border: 1px solid #333; border-bottom: none;
            border-top-left-radius: 26px; border-top-right-radius: 26px;
            width: 100%; max-width: 600px;
            max-height: 92vh; overflow-y: auto; overscroll-behavior: contain;
            padding: 6px 22px 30px;
            box-shadow: 0 -24px 50px rgba(0,0,0,0.6);
            transform: translateY(100%);
            transition: transform 0.32s cubic-bezier(0.2, 0.8, 0.2, 1);
        }
        .sheet-backdrop.show .sheet { transform: translateY(0); }
        .sheet-handle {
            width: 42px; height: 5px; border-radius: 3px; background: #3a3a3a;
            margin: 10px auto 4px;
        }
        .sheet-head {
            display: flex; align-items: center; justify-content: space-between;
            margin: 8px 0 14px;
        }
        .sheet-title { font-size: 1.1rem; font-weight: 600; letter-spacing: -0.3px; }
        .sheet-close {
            background: #222; border: 1px solid #333; color: #aaa;
            width: 34px; height: 34px; border-radius: 50%; cursor: pointer;
            font-size: 0.85rem; line-height: 1;
            transition: background 0.2s, color 0.2s, border-color 0.2s;
        }
        .sheet-close:hover { color: #fff; border-color: #444; }
        .sheet-close:focus-visible { outline: 2px solid var(--primary-highlight); outline-offset: 2px; }
        .sheet-body { display: flex; flex-direction: column; gap: 18px; }
        .sheet-field { display: flex; flex-direction: column; gap: 8px; }
        .sheet-label {
            color: var(--text-dim); font-size: 0.66rem; text-transform: uppercase;
            letter-spacing: 1px;
        }
        .sheet-input {
            width: 100%; box-sizing: border-box;
            background: #222; border: 1px solid #333; color: #fff;
            padding: 13px; border-radius: 12px; font-size: 1rem; outline: none;
            transition: border 0.25s;
        }
        .sheet-input:focus { border-color: var(--primary-highlight); }
        .sheet-actions { margin-top: 8px; }

        /* ── Scroll wheels (hours / minutes) ── */
        .wheel-pair { display: flex; gap: 18px; }
        .wheel-group { display: flex; flex-direction: column; gap: 6px; flex: 1; min-width: 0; }
        .wheel-wrap { position: relative; flex: 1; }
        .wheel {
            height: 200px; overflow-y: scroll;
            scroll-snap-type: y mandatory;
            -webkit-overflow-scrolling: touch;
            overscroll-behavior: contain;
            scrollbar-width: none;
            mask-image: linear-gradient(to bottom, transparent 0%, #000 26%, #000 74%, transparent 100%);
            -webkit-mask-image: linear-gradient(to bottom, transparent 0%, #000 26%, #000 74%, transparent 100%);
        }
        .wheel::-webkit-scrollbar { display: none; }
        .wheel-item {
            height: 40px; min-height: 40px;
            scroll-snap-align: center;
            display: flex; align-items: center; justify-content: center;
            font-size: 1.25rem; font-weight: 600;
            color: #5a5a5a; transition: color 0.15s;
        }
        .wheel-item.wheel-spacer { scroll-snap-align: none; }
        .wheel-band {
            position: absolute; top: 50%; left: 0; right: 0; height: 40px;
            transform: translateY(-50%);
            border-top: 1px solid #333; border-bottom: 1px solid #333;
            background: rgba(58,134,255,0.07);
            border-radius: 8px; pointer-events: none;
        }

        /* Anchor-to-start-time toggle (fixed blocks) */
        .anchor-field { gap: 10px; }
        .anchor-row { display: flex; align-items: center; gap: 10px; cursor: pointer; color: #ddd; font-size: 0.9rem; }
        .anchor-wheels { display: flex; gap: 18px; }
        .anchor-wheels.hidden { display: none; }
        .anchor-wheels .wheel-group { flex: 1; }

        /* ── Percent slider ── */
        .pct-readout {
            font-size: 2.2rem; font-weight: 700; text-align: center;
            color: var(--primary-highlight); line-height: 1;
            margin-bottom: 4px;
        }
        .pct-slider { width: 100%; accent-color: var(--primary-highlight); cursor: pointer; height: 36px; }

        /* Day window sheet extras */
        .day-readout {
            text-align: center; color: var(--success); font-weight: 600;
            font-size: 0.9rem; margin-top: -4px;
        }
        .toggle-field { flex-direction: row; align-items: center; gap: 12px; flex-wrap: wrap; }
        .toggle-field .toggle-label { flex: 1; min-width: 0; }

        .btn-danger {
            width: 100%; background: transparent;
            border: 1px solid var(--danger); color: var(--danger);
            padding: 13px; border-radius: 12px; cursor: pointer;
            font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.6px; font-weight: 700;
            transition: background 0.2s, color 0.2s;
        }
        .btn-danger:hover { background: rgba(255,77,77,0.1); }
        .btn-danger:focus-visible { outline: 2px solid var(--primary-highlight); outline-offset: 2px; }
        .btn-danger.armed { background: rgba(255,77,77,0.16); border-color: var(--danger); color: #fff; }

        @media (max-width: 520px) {
            /* Run view is always on; rows keep the clean run grid on mobile too. */
            .app-container.mode-run .category-row { grid-template-columns: 1fr auto auto; gap: 8px; }
            .td-elapsed { font-size: 0.82rem; }
            .sheet { padding: 6px 18px 26px; }
            .wheel-pair { gap: 14px; }
            .wheel-item { font-size: 1.15rem; }
        }
