:root {
    --bg-primary: #f0f4f8;
    --bg-secondary: #ffffff;
    --bg-tertiary: #f8fafc;
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --text-tertiary: #94a3b8;
    --border-color: #e2e8f0;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -2px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -4px rgba(0, 0, 0, 0.1);
    --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 8px 10px -6px rgba(0, 0, 0, 0.1);
    --blob-1: rgba(56, 189, 248, 0.15);
    --blob-2: rgba(168, 85, 247, 0.15);
    --blob-3: rgba(236, 72, 153, 0.15);
    --glass-bg: rgba(255, 255, 255, 0.7);
    --glass-border: rgba(255, 255, 255, 0.5);
    --accent: #3b82f6;
    --accent-hover: #2563eb;
    --accent-light: rgba(59, 130, 246, 0.1);
}

[data-theme="dark"] {
    --bg-primary: #0f172a;
    --bg-secondary: #1e293b;
    --bg-tertiary: #162032;
    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    --text-tertiary: #64748b;
    --border-color: #334155;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.4), 0 2px 4px -2px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.4), 0 4px 6px -4px rgba(0, 0, 0, 0.3);
    --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.5), 0 8px 10px -6px rgba(0, 0, 0, 0.4);
    --blob-1: rgba(56, 189, 248, 0.2);
    --blob-2: rgba(168, 85, 247, 0.2);
    --blob-3: rgba(236, 72, 153, 0.2);
    --glass-bg: rgba(30, 41, 59, 0.7);
    --glass-border: rgba(51, 65, 85, 0.5);
    --accent: #60a5fa;
    --accent-hover: #93bbfd;
    --accent-light: rgba(96, 165, 250, 0.15);
}

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

html { font-size: 16px; scroll-behavior: smooth; }

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    line-height: 1.6;
    transition: background 0.3s ease, color 0.3s ease;
    overflow-x: hidden;
}

.bg-decoration {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    pointer-events: none; z-index: 0; overflow: hidden;
}

.blob {
    position: absolute; border-radius: 50%; filter: blur(80px);
    animation: blobFloat 20s ease-in-out infinite;
}

.blob-1 { width: 400px; height: 400px; background: var(--blob-1); top: -100px; right: -100px; }
.blob-2 { width: 350px; height: 350px; background: var(--blob-2); bottom: -80px; left: -80px; animation-delay: -7s; }
.blob-3 { width: 300px; height: 300px; background: var(--blob-3); top: 50%; left: 50%; transform: translate(-50%, -50%); animation-delay: -14s; }

@keyframes blobFloat {
    0%, 100% { transform: translate(0, 0) scale(1); }
    25% { transform: translate(30px, -30px) scale(1.05); }
    50% { transform: translate(-20px, 20px) scale(0.95); }
    75% { transform: translate(20px, 10px) scale(1.02); }
}

.app { position: relative; z-index: 1; max-width: 800px; margin: 0 auto; padding: 0 1.5rem 3rem; }

.header {
    padding: 1.5rem 0; position: sticky; top: 0; z-index: 100;
    backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
}

.header-content {
    display: flex; justify-content: space-between; align-items: center;
    padding: 0.75rem 1rem; border-radius: 16px;
    background: var(--glass-bg); border: 1px solid var(--glass-border);
}

.logo { display: flex; align-items: center; gap: 0.75rem; }
.logo-icon { width: 32px; height: 32px; color: var(--accent); }
.logo h1 { font-size: 1.25rem; font-weight: 700; letter-spacing: -0.025em; }

.header-actions { display: flex; gap: 0.5rem; }

.btn-icon {
    display: flex; align-items: center; justify-content: center;
    width: 40px; height: 40px; border: none; border-radius: 12px;
    background: var(--bg-secondary); color: var(--text-secondary);
    cursor: pointer; transition: all 0.2s ease; box-shadow: var(--shadow-sm);
}
.btn-icon:hover { background: var(--accent-light); color: var(--accent); transform: translateY(-1px); box-shadow: var(--shadow-md); }
.btn-icon svg { width: 20px; height: 20px; }

.btn-theme .icon-moon { display: none; }
[data-theme="dark"] .btn-theme .icon-sun { display: none; }
[data-theme="dark"] .btn-theme .icon-moon { display: block; }

.stats-section { padding: 1rem 0; }
.stats-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 1rem; }

.stat-card {
    display: flex; align-items: center; gap: 0.75rem; padding: 1rem;
    border-radius: 16px; background: var(--bg-secondary);
    border: 1px solid var(--border-color); box-shadow: var(--shadow-sm);
    transition: all 0.3s ease;
}
.stat-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }

.stat-icon {
    display: flex; align-items: center; justify-content: center;
    width: 44px; height: 44px; border-radius: 12px;
    background: var(--accent-light); color: var(--accent); flex-shrink: 0;
}
.stat-icon svg { width: 22px; height: 22px; }

.stat-info { display: flex; flex-direction: column; min-width: 0; }
.stat-value { font-size: 1.25rem; font-weight: 700; line-height: 1.2; letter-spacing: -0.025em; }
.stat-label { font-size: 0.75rem; color: var(--text-secondary); font-weight: 500; }

.add-section { padding: 1rem 0; }

.btn-add {
    display: flex; align-items: center; justify-content: center; gap: 0.5rem;
    width: 100%; padding: 1rem; border: 2px dashed var(--border-color);
    border-radius: 16px; background: var(--bg-secondary); color: var(--text-secondary);
    font-family: inherit; font-size: 1rem; font-weight: 600; cursor: pointer;
    transition: all 0.3s ease;
}
.btn-add:hover {
    border-color: var(--accent); color: var(--accent);
    background: var(--accent-light); transform: translateY(-2px); box-shadow: var(--shadow-md);
}
.btn-add svg { width: 20px; height: 20px; }

.habits-container { padding: 0.5rem 0 2rem; display: flex; flex-direction: column; gap: 0.75rem; }

.habit-card {
    display: flex; align-items: center; gap: 1rem; padding: 1rem 1.25rem;
    border-radius: 16px; background: var(--bg-secondary);
    border: 1px solid var(--border-color); box-shadow: var(--shadow-sm);
    transition: all 0.3s ease; animation: slideIn 0.3s ease;
}
.habit-card:hover { box-shadow: var(--shadow-md); transform: translateY(-1px); }
.habit-card.completed { opacity: 0.78; }
.habit-card.completed .habit-name { text-decoration: line-through; color: var(--text-tertiary); }

@keyframes slideIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.habit-checkbox { position: relative; width: 28px; height: 28px; flex-shrink: 0; }
.habit-checkbox input { position: absolute; opacity: 0; width: 100%; height: 100%; cursor: pointer; z-index: 2; }

.habit-checkbox .checkmark {
    position: absolute; top: 0; left: 0; width: 28px; height: 28px;
    border: 2px solid var(--border-color); border-radius: 8px;
    transition: all 0.2s ease; display: flex; align-items: center; justify-content: center;
}
.habit-checkbox .checkmark svg { width: 16px; height: 16px; opacity: 0; transform: scale(0.5); transition: all 0.2s ease; color: white; }
.habit-checkbox input:checked + .checkmark {
    background: var(--habit-color, var(--accent));
    border-color: var(--habit-color, var(--accent));
}
.habit-checkbox input:checked + .checkmark svg { opacity: 1; transform: scale(1); }

.habit-info { flex: 1; min-width: 0; }
.habit-name { font-size: 1rem; font-weight: 600; margin-bottom: 0.25rem; transition: all 0.2s ease; }
.habit-meta { display: flex; align-items: center; gap: 0.75rem; flex-wrap: wrap; }

.habit-streak { display: flex; align-items: center; gap: 0.25rem; font-size: 0.8rem; color: var(--text-secondary); font-weight: 500; }
.habit-streak svg { width: 14px; height: 14px; }

.habit-category {
    display: inline-flex; align-items: center; gap: 0.25rem; font-size: 0.75rem;
    padding: 0.15rem 0.5rem; border-radius: 20px;
    background: var(--bg-tertiary); color: var(--text-secondary); font-weight: 500;
}

.habit-week { display: flex; gap: 3px; }
.habit-week .day { width: 8px; height: 8px; border-radius: 50%; background: var(--border-color); transition: background 0.2s ease; }
.habit-week .day.filled { background: var(--habit-color, var(--accent)); }

.habit-actions { display: flex; gap: 0.25rem; flex-shrink: 0; }
.habit-actions .btn-action {
    display: flex; align-items: center; justify-content: center;
    width: 32px; height: 32px; border: none; border-radius: 8px;
    background: transparent; color: var(--text-tertiary); cursor: pointer; transition: all 0.2s ease;
}
.habit-actions .btn-action:hover { background: var(--bg-tertiary); color: var(--text-primary); }
.habit-actions .btn-action.delete:hover { background: rgba(239, 68, 68, 0.1); color: #ef4444; }
.habit-actions .btn-action svg { width: 16px; height: 16px; }

.empty-state {
    display: none; flex-direction: column; align-items: center; justify-content: center;
    padding: 4rem 2rem; text-align: center; animation: fadeIn 0.5s ease;
}
.empty-state.visible { display: flex; }
.empty-state svg { width: 64px; height: 64px; color: var(--text-tertiary); margin-bottom: 1rem; }
.empty-state h3 { font-size: 1.25rem; font-weight: 600; margin-bottom: 0.5rem; }
.empty-state p { color: var(--text-secondary); font-size: 0.9rem; }

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.modal-overlay {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0, 0, 0, 0.5); backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px);
    display: flex; align-items: center; justify-content: center; z-index: 1000;
    opacity: 0; visibility: hidden; transition: all 0.3s ease;
}
.modal-overlay.active { opacity: 1; visibility: visible; }

.modal {
    background: var(--bg-secondary); border-radius: 20px; padding: 2rem;
    width: 90%; max-width: 440px; box-shadow: var(--shadow-xl);
    transform: translateY(20px) scale(0.95); transition: all 0.3s ease;
}
.modal-overlay.active .modal { transform: translateY(0) scale(1); }

.modal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1.5rem; }
.modal-header h2 { font-size: 1.25rem; font-weight: 700; }

.btn-close {
    display: flex; align-items: center; justify-content: center;
    width: 32px; height: 32px; border: none; border-radius: 8px;
    background: var(--bg-tertiary); color: var(--text-secondary); cursor: pointer; transition: all 0.2s ease;
}
.btn-close:hover { background: var(--accent-light); color: var(--accent); }
.btn-close svg { width: 18px; height: 18px; }

.form-group { display: flex; flex-direction: column; gap: 0.5rem; margin-bottom: 1.15rem; }
.form-group label { font-size: 0.875rem; font-weight: 600; color: var(--text-secondary); }
.form-group input, .form-group select {
    padding: 0.75rem 1rem; border: 1px solid var(--border-color); border-radius: 12px;
    background: var(--bg-tertiary); color: var(--text-primary);
    font-family: inherit; font-size: 1rem; transition: all 0.2s ease;
}
.form-group input:focus, .form-group select:focus {
    outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-light);
}
.form-group input::placeholder { color: var(--text-tertiary); }

.color-picker { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.color-option {
    width: 32px; height: 32px; border-radius: 50%; border: 3px solid transparent;
    cursor: pointer; transition: all 0.2s ease; padding: 0;
}
.color-option:hover { transform: scale(1.1); }
.color-option.selected { border-color: var(--text-primary); box-shadow: 0 0 0 2px var(--bg-secondary); }

.form-actions { display: flex; gap: 0.75rem; margin-top: 0.5rem; }

.btn {
    flex: 1; padding: 0.75rem 1rem; border: none; border-radius: 12px;
    font-family: inherit; font-size: 1rem; font-weight: 600; cursor: pointer; transition: all 0.2s ease;
}
.btn-primary { background: var(--accent); color: white; }
.btn-primary:hover { background: var(--accent-hover); transform: translateY(-1px); box-shadow: var(--shadow-md); }
.btn-secondary { background: var(--bg-tertiary); color: var(--text-secondary); }
.btn-secondary:hover { background: var(--border-color); color: var(--text-primary); }

.toast-container {
    position: fixed; bottom: 1.5rem; right: 1.5rem; z-index: 2000;
    display: flex; flex-direction: column; gap: 0.5rem;
}
.toast {
    display: flex; align-items: center; gap: 0.75rem; padding: 0.85rem 1.1rem;
    border-radius: 12px; background: var(--bg-secondary); border: 1px solid var(--border-color);
    box-shadow: var(--shadow-lg); animation: slideInRight 0.3s ease;
    min-width: 240px; font-size: 0.9rem; font-weight: 500; color: var(--text-primary);
}
.toast.success { border-left: 3px solid #10b981; }
.toast.error { border-left: 3px solid #ef4444; }
.toast.info { border-left: 3px solid var(--accent); }

@keyframes slideInRight {
    from { opacity: 0; transform: translateX(100%); }
    to { opacity: 1; transform: translateX(0); }
}

@media (max-width: 768px) {
    .stats-grid { grid-template-columns: repeat(2, 1fr); }
    .header-content { padding: 0.5rem 0.75rem; }
    .logo h1 { font-size: 1.1rem; }
    .modal { width: 95%; padding: 1.5rem; }
}

@media (max-width: 480px) {
    .app { padding: 0 1rem 2rem; }
    .stats-grid { grid-template-columns: repeat(2, 1fr); gap: 0.75rem; }
    .stat-card { padding: 0.75rem; }
    .stat-value { font-size: 1.1rem; }
    .habit-card { padding: 0.75rem 1rem; }
    .habit-meta { gap: 0.5rem; }
    .habit-week { display: none; }
    .toast-container { left: 1rem; right: 1rem; }
    .toast { min-width: auto; }
}
