
        :root {
            --accent: #4facfe;
            --accent-2: #9479ff;
            --accent-warm: #f97316;
            --success: #34d399;
            --warning: #f59e0b;
            --danger: #ef4444;
            --glass-bg: rgba(6, 12, 24, 0.75);
            --glass-border: rgba(79, 172, 254, 0.22);
            --shadow-lg: 0 45px 120px rgba(15, 23, 42, 0.45);
            --text-primary: #f8fafc;
            --text-muted: rgba(248, 250, 252, 0.7);
        }

        * {
            box-sizing: border-box;
        }

        body {
            margin: 0;
            font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Noto Sans SC', 'PingFang SC', 'Microsoft YaHei', sans-serif;
            background: radial-gradient(circle at top left, rgba(79, 172, 254, 0.18), transparent 45%),
                radial-gradient(circle at top right, rgba(148, 121, 255, 0.2), transparent 50%),
                linear-gradient(165deg, #050811 0%, #01030a 100%);
            color: var(--text-primary);
            min-height: 100dvh;
        }

        a {
            color: inherit;
            text-decoration: none;
        }

        .habits-container {
            max-width: 1200px;
            margin: 0 auto;
            padding: clamp(2rem, 4vw, 3.5rem) 1.6rem 4rem;
            display: flex;
            flex-direction: column;
            gap: 2rem;
        }

        /* R7: page-head canonical flat header (no glass card wrap).
         * Legacy glass-card .habits-header rule retired — the page-head
         * design system (app-shell.css) wins. The old flex-direction:column
         * + card padding was forcing actions to wrap below the description
         * even at 1440px (target mock 16-app-habits.png shows side-by-side). */
        .habits-header {
            background: transparent;
            border: 0;
            border-radius: 0;
            box-shadow: none;
            padding: 0;
        }

        .habits-hero-top {
            display: flex;
            align-items: center;
            justify-content: space-between;
            gap: 1rem;
            flex-wrap: wrap;
        }

        .brand-chip {
            display: inline-flex;
            align-items: center;
            gap: 0.75rem;
            padding: 0.6rem 1.35rem;
            border-radius: 999px;
            background: rgba(15, 23, 42, 0.78);
            border: 1px solid rgba(79, 172, 254, 0.4);
            box-shadow: 0 18px 44px rgba(79, 172, 254, 0.28);
            color: var(--text-primary);
            font-weight: 600;
            letter-spacing: 0.04em;
        }

        .brand-chip img {
            width: 42px;
            height: 42px;
            border-radius: 14px;
            object-fit: cover;
            border: 1px solid rgba(79, 172, 254, 0.35);
            box-shadow: 0 12px 28px rgba(79, 172, 254, 0.3);
        }

        .brand-chip-text {
            font-size: 1.2rem;
            font-weight: 700;
            background: linear-gradient(135deg, var(--accent), var(--accent-2));
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
            background-clip: text;
        }

        .habits-hero-actions {
            display: flex;
            gap: 0.75rem;
            flex-wrap: wrap;
        }

        .btn,
        .btn-primary,
        .btn-secondary,
        .btn-outline {
            display: inline-flex;
            align-items: center;
            justify-content: center;
            gap: 0.5rem;
            padding: 0.65rem 1.6rem;
            border-radius: 999px;
            border: none;
            font-weight: 600;
            letter-spacing: 0.01em;
            cursor: pointer;
            transition: all 0.25s ease;
            background: rgba(5, 10, 20, 0.65);
            color: var(--text-primary);
            box-shadow: 0 18px 42px rgba(15, 23, 42, 0.35);
        }

        .btn:hover,
        .btn-primary:hover,
        .btn-secondary:hover,
        .btn-outline:hover {
            transform: translateY(-2px);
            box-shadow: 0 26px 58px rgba(79, 172, 254, 0.28);
        }

        .btn-primary {
            background: var(--gradient-brand, linear-gradient(135deg, #2563EB 0%, #7C3AED 100%)) !important;
            color: #fff !important;
            box-shadow: 0 24px 60px rgba(148, 121, 255, 0.35);
        }

        .btn-secondary {
            background: linear-gradient(135deg, #667eea, #764ba2);
            color: #05070f;
            box-shadow: 0 22px 52px rgba(102, 126, 234, 0.28);
        }

        .btn-outline {
            background: rgba(5, 10, 20, 0.65);
            border: 1px solid rgba(79, 172, 254, 0.35);
        }

        .btn-outline:hover {
            border-color: rgba(148, 121, 255, 0.5);
            box-shadow: 0 22px 52px rgba(79, 172, 254, 0.28);
        }

        .habits-header h1 {
            margin: 0 0 6px;
            font-size: 32px;
            line-height: 1.15;
            letter-spacing: -0.02em;
            font-weight: 600;
        }
        @media (max-width: 720px) {
            .habits-header h1 { font-size: 26px; }
        }

        .habits-header p {
            margin: 0;
            color: var(--text-muted);
            font-size: 14px;
            max-width: 460px;
            line-height: 1.55;
        }

        .habits-info,
        .daily-challenge {
            background: rgba(5, 10, 20, 0.65);
            border: 1px solid rgba(79, 172, 254, 0.18);
            border-radius: 24px;
            box-shadow: 0 20px 48px rgba(15, 23, 42, 0.32);
            padding: clamp(1.6rem, 3vw, 2.2rem);
            text-align: center;
        }

        .daily-challenge {
            background: linear-gradient(135deg, rgba(249, 115, 22, 0.35), rgba(239, 68, 68, 0.35)), rgba(5, 10, 20, 0.65);
            border: 1px solid rgba(249, 115, 22, 0.35);
        }

        .challenge-title {
            margin: 0 0 0.5rem 0;
            font-size: 1.3rem;
            font-weight: 600;
        }

        .challenge-description {
            margin: 0 0 0.75rem 0;
            color: var(--text-muted);
        }

        .challenge-reward {
            margin: 0 0 1rem 0;
            font-weight: 600;
            color: var(--accent-warm);
        }

        .habits-actions {
            display: flex;
            justify-content: center;
            gap: 0.75rem;
            flex-wrap: wrap;
        }

        .gamification-dashboard {
            background: var(--glass-bg);
            border: 1px solid var(--glass-border);
            border-radius: 32px;
            box-shadow: var(--shadow-lg);
            padding: clamp(1.8rem, 4vw, 2.6rem);
            display: flex;
            flex-direction: column;
            gap: 2rem;
        }

        .dashboard-header {
            text-align: left;
        }

        .dashboard-header h2 {
            margin: 0 0 0.35rem 0;
            font-size: 1.5rem;
        }

        .dashboard-header p {
            margin: 0;
            color: var(--text-muted);
        }

        .dashboard-stats {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
            gap: 1.2rem;
        }

        .stat-card {
            background: rgba(5, 10, 20, 0.72);
            border-radius: 24px;
            border: 1px solid rgba(79, 172, 254, 0.24);
            padding: 1.4rem 1.5rem;
            box-shadow: 0 22px 48px rgba(15, 23, 42, 0.28);
            text-align: left;
        }

        .stat-value {
            font-size: 2.1rem;
            font-weight: 700;
            margin: 0 0 0.35rem 0;
        }

        .stat-label {
            color: var(--text-muted);
            font-size: 0.9rem;
        }

        .level-progress {
            background: rgba(5, 10, 20, 0.6);
            border-radius: 999px;
            height: 8px;
            overflow: hidden;
            margin: 0.9rem 0;
        }

        .level-progress-fill {
            height: 100%;
            background: linear-gradient(90deg, var(--success), #0ea5e9);
            transition: width 0.3s ease;
        }

        .dashboard-actions {
            display: flex;
            gap: 0.75rem;
            flex-wrap: wrap;
        }

        .dashboard-btn {
            padding: 0.65rem 1.6rem;
            border-radius: 999px;
            border: 1px solid rgba(79, 172, 254, 0.35);
            background: rgba(5, 10, 20, 0.65);
            color: var(--text-primary);
            font-weight: 600;
            cursor: pointer;
            transition: all 0.25s ease;
        }

        .dashboard-btn:hover {
            transform: translateY(-2px);
            border-color: rgba(148, 121, 255, 0.45);
            box-shadow: 0 18px 40px rgba(79, 172, 254, 0.25);
        }

        .habit-streaks,
        .achievement-badges {
            display: flex;
            flex-wrap: wrap;
            gap: 0.5rem;
        }

        .achievement-badge {
            display: inline-flex;
            align-items: center;
            gap: 0.35rem;
            padding: 0.35rem 0.85rem;
            border-radius: 999px;
            background: rgba(79, 172, 254, 0.18);
            border: 1px solid rgba(79, 172, 254, 0.3);
            color: var(--text-primary);
            font-weight: 600;
            font-size: 0.8rem;
        }

        .achievement-badge.gold {
            background: rgba(255, 215, 0, 0.25);
            border-color: rgba(255, 215, 0, 0.35);
            color: #fef3c7;
        }

        .achievement-badge.silver {
            background: rgba(192, 192, 192, 0.25);
            border-color: rgba(192, 192, 192, 0.35);
            color: #e5e7eb;
        }

        .achievement-badge.bronze {
            background: rgba(205, 127, 50, 0.25);
            border-color: rgba(205, 127, 50, 0.35);
            color: #fde68a;
        }

        .habits-grid {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
            gap: 1.5rem;
        }

        .habit-card {
            background: linear-gradient(145deg, rgba(79, 172, 254, 0.18), rgba(148, 121, 255, 0.22));
            border-radius: 24px;
            border: 1px solid rgba(79, 172, 254, 0.32);
            padding: 1.6rem;
            box-shadow: 0 26px 60px rgba(15, 23, 42, 0.38);
            display: flex;
            flex-direction: column;
            gap: 1.2rem;
            transition: all 0.3s ease;
        }

        .habit-card.inactive {
            opacity: 0.6;
        }

        .habit-card:hover {
            transform: translateY(-4px);
            border-color: rgba(148, 121, 255, 0.45);
            box-shadow: 0 36px 82px rgba(79, 172, 254, 0.28);
        }

        .habit-header {
            display: flex;
            justify-content: space-between;
            gap: 0.75rem;
            align-items: flex-start;
        }

        .habit-title {
            margin: 0;
            font-size: 1.15rem;
            font-weight: 600;
        }

        .habit-category {
            padding: 0.35rem 0.75rem;
            border-radius: 999px;
            background: rgba(5, 10, 20, 0.65);
            border: 1px solid rgba(79, 172, 254, 0.28);
            font-size: 0.75rem;
            text-transform: capitalize;
        }

        .habit-description {
            color: rgba(248, 250, 252, 0.88);
            line-height: 1.6;
        }

        .habit-details {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
            gap: 0.75rem;
        }

        .habit-detail {
            background: rgba(5, 10, 20, 0.6);
            border-radius: 18px;
            border: 1px solid rgba(79, 172, 254, 0.2);
            padding: 0.75rem 1rem;
            display: flex;
            flex-direction: column;
            gap: 0.25rem;
        }

        .habit-detail-label {
            color: var(--text-muted);
            font-size: 0.75rem;
            letter-spacing: 0.08em;
            text-transform: uppercase;
        }

        .habit-detail-value {
            font-weight: 600;
        }

        .habit-level-info {
            display: flex;
            align-items: center;
            justify-content: space-between;
            gap: 0.75rem;
        }

        .habit-level {
            padding: 0.35rem 0.75rem;
            border-radius: 999px;
            background: rgba(79, 172, 254, 0.2);
            border: 1px solid rgba(79, 172, 254, 0.3);
            font-weight: 600;
            font-size: 0.85rem;
        }

        .habit-progress {
            display: flex;
            flex-direction: column;
            gap: 0.4rem;
        }

        .habit-progress-bar {
            width: 100%;
            height: 6px;
            border-radius: 999px;
            background: rgba(5, 10, 20, 0.6);
            overflow: hidden;
        }

        .habit-progress-fill {
            height: 100%;
            background: linear-gradient(90deg, var(--success), #22d3ee);
            transition: width 0.3s ease;
        }

        .habit-progress-label {
            color: var(--text-muted);
            font-size: 0.85rem;
        }

        .habit-actions {
            display: flex;
            gap: 0.6rem;
            flex-wrap: wrap;
            padding-top: 0.8rem;
            border-top: 1px solid rgba(79, 172, 254, 0.15);
            margin-top: auto;
        }

        .habit-action-btn {
            padding: 0.55rem 1.1rem;
            border-radius: 999px;
            border: 1px solid rgba(79, 172, 254, 0.3);
            background: rgba(5, 10, 20, 0.65);
            color: var(--text-primary);
            font-weight: 600;
            cursor: pointer;
            transition: all 0.25s ease;
        }

        .habit-action-btn:hover {
            transform: translateY(-2px);
            box-shadow: 0 18px 40px rgba(79, 172, 254, 0.25);
        }

        .habit-action-btn.btn-checkin {
            border-color: rgba(34, 211, 238, 0.4);
            background: rgba(34, 211, 238, 0.18);
        }

        .habit-action-btn.btn-edit {
            border-color: rgba(148, 121, 255, 0.4);
            background: rgba(148, 121, 255, 0.18);
        }

        .habit-action-btn.btn-toggle {
            border-color: rgba(249, 115, 22, 0.4);
            background: rgba(249, 115, 22, 0.18);
        }

        .habit-action-btn.btn-delete {
            border-color: rgba(239, 68, 68, 0.4);
            background: rgba(239, 68, 68, 0.18);
        }

        .habits-empty {
            grid-column: 1 / -1;
            text-align: center;
            padding: 2.5rem 1.5rem;
            border-radius: 24px;
            background: rgba(5, 10, 20, 0.6);
            border: 1px dashed rgba(79, 172, 254, 0.24);
            color: var(--text-muted);
        }

        .habits-empty h3 {
            margin: 0 0 0.75rem 0;
            color: var(--text-primary);
        }

        .modal {
            position: fixed;
            inset: 0;
            background: rgba(5, 10, 20, 0.9);
            backdrop-filter: blur(16px);
            display: none;
            align-items: center;
            justify-content: center;
            padding: 2rem;
            z-index: 24000;
        }

        .modal.show {
            display: flex;
        }

        .modal-content {
            background: linear-gradient(160deg, rgba(15, 23, 42, 0.95), rgba(10, 15, 28, 0.92));
            border-radius: 28px;
            border: 1px solid rgba(79, 172, 254, 0.32);
            max-width: min(95vw, 760px);
            width: 100%;
            max-height: 90vh;
            overflow-y: auto;
            box-shadow: 0 55px 120px rgba(15, 23, 42, 0.5);
            position: relative;
        }

        .modal-header {
            padding: 1.8rem 2.2rem 1.2rem;
            border-bottom: 1px solid rgba(79, 172, 254, 0.22);
        }

        .modal-title {
            margin: 0;
            font-size: 1.4rem;
        }

        .modal-close {
            position: absolute;
            top: 1rem;
            right: 1rem;
            width: 44px;
            height: 44px;
            border-radius: 14px;
            border: 1px solid rgba(79, 172, 254, 0.35);
            background: rgba(5, 10, 20, 0.65);
            color: rgba(248, 250, 252, 0.8);
            font-size: 1.4rem;
            cursor: pointer;
            display: inline-flex;
            align-items: center;
            justify-content: center;
            transition: all 0.25s ease;
        }

        .modal-close:hover {
            color: #ffffff;
            transform: translateY(-2px);
            box-shadow: 0 18px 44px rgba(79, 172, 254, 0.28);
        }

        .modal-body {
            padding: 2rem 2.2rem;
            color: var(--text-primary);
        }

        .modal-body label {
            color: var(--text-primary);
            font-weight: 600;
        }

        .modal-body input,
        .modal-body select,
        .modal-body textarea {
            width: 100%;
            padding: 0.75rem 1rem;
            border-radius: 14px;
            border: 1px solid rgba(79, 172, 254, 0.28);
            background: rgba(5, 10, 20, 0.7);
            color: var(--text-primary);
            /* 16px floor: iOS Safari auto-zooms on focus when computed
               font-size is <16px. !important needed because styles.css
               ships `select:not(.brand-select):not(.filter-select)…` at
               specificity (0,7,1) that outscores `.modal-body select` (0,1,1). */
            font-size: 16px !important;
            margin-top: 0.35rem;
            margin-bottom: 0.9rem;
        }

        .habit-form-grid {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
            gap: 1rem;
        }

        .habit-progress-snapshot {
            display: grid;
            gap: 0.75rem;
        }

        .habit-progress-snapshot .snapshot-card {
            background: rgba(5, 10, 20, 0.6);
            border-radius: 18px;
            border: 1px solid rgba(79, 172, 254, 0.2);
            padding: 0.9rem 1rem;
            display: flex;
            justify-content: space-between;
            align-items: center;
        }


        .achievements-container,
        .activity-patterns {
            display: flex;
            flex-direction: column;
            gap: 1.2rem;
        }

        .achievements-list,
        .pattern-items {
            display: grid;
            gap: 0.75rem;
        }

        .achievement-item,
        .pattern-item,
        .habit-pattern {
            background: rgba(5, 10, 20, 0.6);
            border-radius: 18px;
            border: 1px solid rgba(79, 172, 254, 0.2);
            padding: 0.85rem 1rem;
            box-shadow: 0 14px 32px rgba(15, 23, 42, 0.28);
        }

        .achievement-item {
            display: flex;
            align-items: center;
            justify-content: space-between;
            gap: 0.75rem;
        }

        .achievement-details {
            display: flex;
            flex-direction: column;
            gap: 0.25rem;
            color: var(--text-muted);
        }

        .habit-pattern h4 {
            margin: 0 0 0.6rem 0;
        }

        .pattern-items {
            grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
        }

        .pattern-item {
            display: flex;
            flex-direction: column;
            gap: 0.35rem;
        }

        .social-tabs {
            display: flex;
            gap: 0.6rem;
            flex-wrap: wrap;
            margin-bottom: 1.2rem;
        }

        .tab-button {
            padding: 0.55rem 1.2rem;
            border-radius: 999px;
            border: 1px solid rgba(79, 172, 254, 0.28);
            background: rgba(5, 10, 20, 0.6);
            color: var(--text-muted);
            font-weight: 600;
            cursor: pointer;
            transition: all 0.25s ease;
        }

        .tab-button:hover {
            border-color: rgba(148, 121, 255, 0.45);
            color: var(--text-primary);
        }

        .tab-button.active {
            background: linear-gradient(135deg, var(--accent), var(--accent-2));
            color: #05070f;
            border: none;
        }

        .social-content {
            display: grid;
            gap: 1rem;
        }

        .loading {
            text-align: center;
            padding: 2rem;
            border-radius: 20px;
            background: rgba(5, 10, 20, 0.6);
            border: 1px dashed rgba(79, 172, 254, 0.24);
            color: var(--text-muted);
        }

        .error {
            text-align: center;
            padding: 1.5rem;
            border-radius: 18px;
            background: rgba(239, 68, 68, 0.12);
            border: 1px solid rgba(239, 68, 68, 0.4);
            color: #fca5a5;
            font-weight: 600;
        }

        @media (max-width: 900px) {
            .brand-chip {
                display: none;
            }

            .habits-hero-top,
            .habits-hero-actions,
            .habits-actions,
            .dashboard-actions {
                flex-direction: column;
                align-items: stretch;
            }

            .btn,
            .btn-outline,
            .btn-primary,
            .btn-secondary,
            .dashboard-btn {
                width: 100%;
                justify-content: center;
            }

            .habits-grid {
                grid-template-columns: 1fr;
            }
        }

        @media (max-width: 600px) {
            .habits-container {
                padding: 1.5rem 1rem 3rem;
            }

            .modal {
                padding: 1.25rem;
            }

            .modal-content {
                border-radius: 26px;
            }
        }

        /* D-04: proper switch with visible on/off state */
        .toggle-switch {
            display: inline-flex;
            align-items: center;
            gap: 0.6rem;
            cursor: pointer;
            user-select: none;
            font-size: 0.85rem;
            color: rgba(248, 250, 252, 0.85);
        }
        .toggle-switch input[type="checkbox"] {
            position: absolute;
            opacity: 0;
            width: 0;
            height: 0;
            pointer-events: none;
        }
        .toggle-track {
            position: relative;
            display: inline-block;
            width: 38px;
            height: 22px;
            background: rgba(148, 163, 184, 0.35);
            border: 1px solid rgba(148, 163, 184, 0.5);
            border-radius: 999px;
            transition: background 0.2s ease, border-color 0.2s ease;
            flex-shrink: 0;
        }
        .toggle-thumb {
            position: absolute;
            top: 2px;
            left: 2px;
            width: 16px;
            height: 16px;
            background: #ffffff;
            border-radius: 50%;
            box-shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
            transition: transform 0.2s ease;
        }
        .toggle-switch input[type="checkbox"]:checked + .toggle-track {
            background: #4facfe;
            border-color: #4facfe;
        }
        .toggle-switch input[type="checkbox"]:checked + .toggle-track .toggle-thumb {
            transform: translateX(16px);
        }
        .toggle-switch input[type="checkbox"]:focus-visible + .toggle-track {
            outline: 2px solid #4facfe;
            outline-offset: 2px;
        }
    