:root {
    --bg: #f2f1ed;
    --surface: rgba(255, 255, 255, 0.85);
    --surface-solid: #ffffff;
    --border: rgba(0,0,0,0.07);
    --border-strong: rgba(0,0,0,0.13);
    --primary: #1e2030;
    --accent: #5b5ef4;
    --accent-soft: rgba(91, 94, 244, 0.10);
    --urgent: #e5484d;
    --urgent-soft: rgba(229, 72, 77, 0.10);
    --important: #c27c2a;
    --important-soft: rgba(194, 124, 42, 0.10);
    --text-main: #1a1a2e;
    --text-secondary: #6b6b80;
    --text-muted: #a0a0b4;
    --done-opacity: 0.42;
    --radius-sm: 10px;
    --radius-md: 16px;
    --radius-lg: 20px;
    --top-bar-h: 68px;
    --bottom-nav-h: 72px;
    --font: 'DM Sans', -apple-system, BlinkMacSystemFont, sans-serif;
    --font-display: 'DM Serif Display', Georgia, serif;
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
    --shadow-md: 0 4px 16px rgba(0,0,0,0.07), 0 1px 4px rgba(0,0,0,0.04);
    --shadow-lg: 0 12px 40px rgba(0,0,0,0.12), 0 2px 8px rgba(0,0,0,0.06);
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-font-smoothing: antialiased; }

body {
    background-color: var(--bg);
    background-image:
        radial-gradient(ellipse 80% 60% at 20% -10%, rgba(91,94,244,0.07) 0%, transparent 60%),
        radial-gradient(ellipse 60% 50% at 80% 110%, rgba(194,124,42,0.06) 0%, transparent 60%);
    color: var(--text-main);
    font-family: var(--font);
    min-height: 100vh;
    overscroll-behavior: none;
}

.noise {
    position: fixed; inset: 0; pointer-events: none; z-index: 0; opacity: 0.025;
    background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 512 512' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.75' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
    background-size: 256px;
}

/* ─────────────────────────────────────────
   TOP BAR
───────────────────────────────────────── */
.top-bar {
    position: fixed;
    top: 0; left: 0; right: 0;
    height: var(--top-bar-h);
    z-index: 100;
    background: rgba(242, 241, 237, 0.88);
    backdrop-filter: blur(20px) saturate(1.4);
    -webkit-backdrop-filter: blur(20px) saturate(1.4);
    border-bottom: 1px solid var(--border);
}

.top-bar-inner {
    max-width: 720px;
    margin: 0 auto;
    padding: 0 20px;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.top-bar-eyebrow {
    display: block;
    font-size: 10px;
    font-weight: 500;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--text-muted);
    line-height: 1;
    margin-bottom: 3px;
}

.top-bar h1 {
    font-family: var(--font-display);
    font-size: 22px;
    font-weight: 400;
    letter-spacing: -0.01em;
    line-height: 1;
    color: var(--text-main);
}

.top-bar-meta {
    text-align: right;
}

.top-bar-meta #headerCount {
    font-family: var(--font-display);
    font-size: 28px;
    font-weight: 400;
    color: var(--text-main);
    line-height: 1;
    display: block;
}

.top-bar-meta-label {
    font-size: 10px;
    font-weight: 500;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--text-muted);
}

/* ─────────────────────────────────────────
   MAIN CONTENT
───────────────────────────────────────── */
.main-content {
    padding-top: calc(var(--top-bar-h) + 20px);
    padding-bottom: calc(var(--bottom-nav-h) + 24px);
}

.app-container {
    max-width: 720px;
    margin: 0 auto;
    padding: 0 16px;
    position: relative;
    z-index: 1;
}

/* ─────────────────────────────────────────
   DESKTOP CHROME (tabs + add form)
   Hidden on mobile, shown on desktop
───────────────────────────────────────── */
.desktop-chrome { display: none; margin-bottom: 16px; }

.desktop-tabs {
    display: flex;
    margin-bottom: 14px;
    background: rgba(0,0,0,0.05);
    border-radius: var(--radius-sm);
    padding: 3px;
    gap: 2px;
}

.tab-btn {
    flex: 1; padding: 9px 12px; border: none;
    background: transparent; border-radius: 8px;
    font-family: var(--font); font-size: 14px; font-weight: 500;
    color: var(--text-muted); cursor: pointer; transition: all 0.2s;
    display: flex; align-items: center; justify-content: center; gap: 7px;
}
.tab-btn.active {
    background: var(--surface-solid);
    color: var(--text-main);
    box-shadow: var(--shadow-sm);
}

.tab-count {
    background: rgba(0,0,0,0.08); font-size: 11px; font-weight: 600;
    min-width: 20px; height: 20px; border-radius: 100px;
    display: inline-flex; align-items: center; justify-content: center; padding: 0 5px;
}
.tab-btn.active .tab-count { background: var(--accent-soft); color: var(--accent); }

.add-task-container {
    background: var(--surface);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    padding: 16px 18px 13px;
    border-radius: var(--radius-lg);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-md), inset 0 1px 0 rgba(255,255,255,0.6);
    transition: box-shadow 0.2s;
}
.add-task-container:focus-within {
    box-shadow: var(--shadow-lg), 0 0 0 3px var(--accent-soft), inset 0 1px 0 rgba(255,255,255,0.6);
}

.input-row {
    display: flex; align-items: center; gap: 12px; margin-bottom: 13px;
}

#taskInputDesktop {
    flex: 1; border: none; background: transparent;
    font-family: var(--font); font-size: 15px; font-weight: 400;
    color: var(--text-main); padding: 4px 0; outline: none;
}
#taskInputDesktop::placeholder { color: var(--text-muted); font-weight: 300; }

.add-inline-btn {
    background: var(--primary); color: white; border: none;
    width: 36px; height: 36px; border-radius: 50%; cursor: pointer;
    display: flex; justify-content: center; align-items: center; flex-shrink: 0;
    box-shadow: 0 2px 8px rgba(30,32,48,0.25); transition: transform 0.15s, background 0.15s;
}
.add-inline-btn:hover { background: #2e3249; }
.add-inline-btn:active { transform: scale(0.92); }

.task-options { display: flex; gap: 8px; }

/* ─────────────────────────────────────────
   PILLS
───────────────────────────────────────── */
.pill {
    display: flex; align-items: center; gap: 6px;
    padding: 7px 13px; border-radius: 100px;
    font-size: 13px; font-weight: 500; cursor: pointer;
    background: rgba(0,0,0,0.04); border: 1px solid var(--border);
    color: var(--text-secondary); transition: all 0.2s; user-select: none;
}
.pill input { display: none; }
.pill-icon { font-size: 13px; filter: grayscale(1); transition: filter 0.2s; }
.pill:active { transform: scale(0.96); }
.pill.urgent:has(input:checked) { background: var(--urgent-soft); border-color: var(--urgent); color: var(--urgent); }
.pill.urgent:has(input:checked) .pill-icon { filter: grayscale(0); }
.pill.important:has(input:checked) { background: var(--important-soft); border-color: var(--important); color: var(--important); }
.pill.important:has(input:checked) .pill-icon { filter: grayscale(0); }

/* ─────────────────────────────────────────
   TASK LISTS
───────────────────────────────────────── */
.task-list { display: none; flex-direction: column; gap: 8px; }
.task-list.active-list { display: flex; }

.task-item {
    background: var(--surface);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    padding: 14px 14px 14px 8px;
    border-radius: var(--radius-md);
    display: flex; align-items: center; gap: 10px;
    border: 1px solid var(--border);
    box-shadow: var(--shadow-sm), inset 0 1px 0 rgba(255,255,255,0.5);
    transition: box-shadow 0.2s, opacity 0.25s;
    animation: itemIn 0.25s cubic-bezier(0.16, 1, 0.3, 1) both;
}
@keyframes itemIn {
    from { opacity: 0; transform: translateY(6px) scale(0.99); }
    to   { opacity: 1; transform: translateY(0) scale(1); }
}
.task-item:hover { box-shadow: var(--shadow-md), inset 0 1px 0 rgba(255,255,255,0.5); }
.task-item.done { opacity: var(--done-opacity); }

/* Drag handle */
.drag-handle {
    cursor: grab; color: var(--text-muted); opacity: 0.4;
    padding: 4px 6px; user-select: none; touch-action: none; flex-shrink: 0;
    transition: opacity 0.15s; display: flex; flex-direction: column;
    gap: 3px; align-items: center; justify-content: center; height: 24px;
}
.drag-handle::before, .drag-handle::after, .drag-handle span {
    content: ''; display: block; width: 12px; height: 1.5px;
    background: currentColor; border-radius: 2px;
}
.drag-handle::before { content: ''; }
.drag-handle::after  { content: ''; }
.task-item:hover .drag-handle { opacity: 0.65; }
.drag-handle:active { cursor: grabbing; opacity: 1; }
.task-item.done .drag-handle { opacity: 0; pointer-events: none; }

/* Checkbox */
.checkbox-circle {
    width: 22px; height: 22px; border: 1.8px solid var(--border-strong); border-radius: 50%;
    cursor: pointer; display: flex; align-items: center; justify-content: center;
    flex-shrink: 0; transition: all 0.2s; background: rgba(255,255,255,0.5);
}
.checkbox-circle:hover { border-color: var(--accent); background: var(--accent-soft); }
.task-item.done .checkbox-circle { background: var(--accent); border-color: var(--accent); }
.task-item.done .checkbox-circle::after {
    content: ''; width: 5px; height: 9px; border: 2px solid white;
    border-top: none; border-left: none;
    transform: rotate(45deg) translateY(-1px); display: block;
}

/* Content */
.task-content { flex: 1; display: flex; flex-direction: column; gap: 7px; min-width: 0; }

.title-input {
    width: 100%; border: none; background: transparent;
    font-family: var(--font); font-size: 15px; font-weight: 400;
    outline: none; padding: 0; color: var(--text-main); line-height: 1.3;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.title-input:focus {
    white-space: normal; overflow: visible; text-overflow: clip;
    border-bottom: 1px solid var(--border-strong); margin-bottom: -1px;
}
.task-item.done .title-input { text-decoration: line-through; color: var(--text-muted); }

/* Badges */
.badges { display: flex; gap: 5px; flex-wrap: wrap; }

.badge {
    cursor: pointer; padding: 3px 8px; border-radius: 100px;
    font-size: 10px; font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase;
    border: 1px solid transparent; transition: all 0.18s; user-select: none;
    display: inline-flex; align-items: center; gap: 3px;
}
.badge.off { background: rgba(0,0,0,0.04); border-color: rgba(0,0,0,0.07); color: var(--text-muted); filter: grayscale(1); opacity: 0.6; }
.badge.off:hover { opacity: 0.9; background: rgba(0,0,0,0.07); }
.badge.u { background: var(--urgent-soft); border-color: rgba(229,72,77,0.25); color: var(--urgent); filter: none; opacity: 1; }
.badge.i { background: var(--important-soft); border-color: rgba(194,124,42,0.25); color: var(--important); filter: none; opacity: 1; }
.badge:active { transform: scale(0.93); }

/* Delete */
.delete-btn {
    background: none; border: none; width: 28px; height: 28px; border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    color: var(--text-muted); font-size: 13px; cursor: pointer;
    opacity: 0; transition: opacity 0.15s, background 0.15s, color 0.15s; flex-shrink: 0;
}
.task-item:hover .delete-btn { opacity: 1; }
.delete-btn:hover { background: var(--urgent-soft); color: var(--urgent); }

/* Empty state */
.empty-state { text-align: center; padding: 60px 20px; color: var(--text-muted); }
.empty-icon { font-size: 28px; margin-bottom: 10px; opacity: 0.35; }
.empty-state p { font-size: 15px; font-weight: 300; }

/* Sortable */
.sortable-ghost { opacity: 0.35 !important; background: var(--accent-soft) !important; }
.sortable-drag { box-shadow: var(--shadow-lg) !important; }

/* ─────────────────────────────────────────
   BOTTOM NAV — mobile only
───────────────────────────────────────── */
.bottom-nav {
    display: none; /* shown on mobile */
    position: fixed; bottom: 0; left: 0; right: 0;
    height: var(--bottom-nav-h);
    background: rgba(242, 241, 237, 0.92);
    backdrop-filter: blur(24px) saturate(1.4);
    -webkit-backdrop-filter: blur(24px) saturate(1.4);
    border-top: 1px solid var(--border);
    z-index: 200;
    padding: 0 8px;
    padding-bottom: env(safe-area-inset-bottom);
    align-items: center;
    justify-content: space-around;
}

.nav-btn {
    flex: 1; display: flex; flex-direction: column; align-items: center;
    gap: 4px; background: none; border: none; cursor: pointer;
    padding: 10px 8px; position: relative;
    color: var(--text-muted); font-family: var(--font); font-size: 10px;
    font-weight: 500; letter-spacing: 0.03em;
    transition: color 0.2s; -webkit-tap-highlight-color: transparent;
}
.nav-btn.active { color: var(--accent); }
.nav-icon { width: 22px; height: 22px; transition: stroke 0.2s; }

.nav-badge {
    position: absolute; top: 6px; right: calc(50% - 20px);
    background: var(--accent); color: white;
    font-size: 9px; font-weight: 700; min-width: 16px; height: 16px;
    border-radius: 100px; display: flex; align-items: center; justify-content: center;
    padding: 0 4px; border: 2px solid var(--bg);
    transition: transform 0.2s;
}
.nav-badge.muted { background: var(--text-muted); }
.nav-badge[style*="display: none"] { display: none !important; }

/* FAB */
.nav-fab-wrap {
    flex: 0 0 72px;
    display: flex; align-items: center; justify-content: center;
    position: relative; top: -16px;
}

.nav-fab {
    width: 58px; height: 58px; border-radius: 50%;
    background: var(--primary); color: white; border: none;
    display: flex; align-items: center; justify-content: center;
    cursor: pointer;
    box-shadow: 0 4px 20px rgba(30,32,48,0.30), 0 1px 4px rgba(30,32,48,0.15);
    transition: transform 0.2s cubic-bezier(0.34,1.56,0.64,1), background 0.2s;
    -webkit-tap-highlight-color: transparent;
}
.nav-fab:hover { background: #2e3249; }
.nav-fab:active { transform: scale(0.91); }
.nav-fab.open {
    background: var(--urgent);
    transform: rotate(45deg);
}

/* ─────────────────────────────────────────
   BOTTOM SHEET
───────────────────────────────────────── */
.sheet-backdrop {
    display: none;
    position: fixed; inset: 0; z-index: 300;
    background: rgba(30,32,48,0.3);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    opacity: 0;
    transition: opacity 0.3s;
}
.sheet-backdrop.visible { opacity: 1; }

.sheet {
    position: fixed; bottom: 0; left: 0; right: 0; z-index: 400;
    background: var(--surface-solid);
    border-radius: 24px 24px 0 0;
    box-shadow: 0 -4px 40px rgba(30,32,48,0.14);
    transform: translateY(110%);
    transition: transform 0.4s cubic-bezier(0.16, 1, 0.3, 1);
    padding-bottom: env(safe-area-inset-bottom);
}
.sheet.open { transform: translateY(0); }

.sheet-handle-wrap { padding: 12px 0 4px; display: flex; justify-content: center; }
.sheet-handle { width: 36px; height: 4px; border-radius: 2px; background: rgba(0,0,0,0.12); }

.sheet-body { padding: 8px 24px 28px; }

.sheet-label {
    font-size: 11px; font-weight: 600; letter-spacing: 0.08em;
    text-transform: uppercase; color: var(--text-muted); margin-bottom: 14px;
}

.sheet-input {
    width: 100%; border: none; border-bottom: 1.5px solid var(--border-strong);
    background: transparent; font-family: var(--font); font-size: 18px;
    font-weight: 400; color: var(--text-main); padding: 4px 0 10px;
    outline: none; margin-bottom: 18px;
}
.sheet-input::placeholder { color: var(--text-muted); font-weight: 300; }
.sheet-input:focus { border-bottom-color: var(--accent); }

.sheet-options { display: flex; gap: 10px; margin-bottom: 22px; }

.sheet-submit {
    width: 100%; padding: 16px;
    background: var(--primary); color: white; border: none; border-radius: 14px;
    font-family: var(--font); font-size: 16px; font-weight: 500;
    cursor: pointer; transition: background 0.2s, transform 0.15s;
    box-shadow: 0 2px 12px rgba(30,32,48,0.2);
}
.sheet-submit:hover { background: #2e3249; }
.sheet-submit:active { transform: scale(0.98); }

/* ─────────────────────────────────────────
   RESPONSIVE
───────────────────────────────────────── */

/* Mobile: bottom-nav + sheet visible */
@media (max-width: 640px) {
    .bottom-nav { display: flex; }
    .main-content { padding-bottom: calc(var(--bottom-nav-h) + 40px); }
    .sheet-backdrop { display: block; }
    .delete-btn { opacity: 1; }
    .task-item { padding: 13px 10px 13px 6px; }
}

/* Desktop: hide bottom-nav, show desktop-chrome */
@media (min-width: 641px) {
    .bottom-nav { display: none !important; }
    .desktop-chrome { display: block; }
    .main-content { padding-bottom: 40px; }
    .top-bar-h: 72px;
}
