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

:root {
    --primary: #6366f1;
    --primary-light: #818cf8;
    --primary-dark: #4f46e5;
    --success: #10b981;
    --success-light: #d1fae5;
    --warning: #f59e0b;
    --danger: #ef4444;
    --bg: #f8fafc;
    --card-bg: #ffffff;
    --text: #1e293b;
    --text-light: #64748b;
    --border: #e2e8f0;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 25px -5px rgba(0, 0, 0, 0.1);
    --radius: 16px;
    --radius-sm: 8px;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    min-height: 100vh;
}

.container {
    max-width: 800px;
    margin: 0 auto;
    padding: 2rem 1rem;
}

/* Header */
header {
    text-align: center;
    margin-bottom: 2rem;
}

header h1 {
    font-size: 2.5rem;
    font-weight: 700;
    background: linear-gradient(135deg, var(--primary), var(--success));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 0.5rem;
}

.subtitle {
    color: var(--text-light);
    font-size: 1.1rem;
}

/* Stats Bar */
.stats-bar {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1rem;
    margin-bottom: 2rem;
}

.stat-card {
    background: var(--card-bg);
    padding: 1.5rem 1rem;
    border-radius: var(--radius);
    text-align: center;
    box-shadow: var(--shadow);
    transition: transform 0.2s;
}

.stat-card:hover {
    transform: translateY(-2px);
}

.stat-number {
    display: block;
    font-size: 2rem;
    font-weight: 700;
    color: var(--primary);
}

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

/* Add Habit Section */
.add-habit-section {
    text-align: center;
    margin-bottom: 2rem;
}

.btn-primary {
    background: var(--primary);
    color: white;
    border: none;
    padding: 0.875rem 2rem;
    font-size: 1rem;
    font-weight: 600;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all 0.2s;
    box-shadow: 0 4px 6px -1px rgba(99, 102, 241, 0.3);
}

.btn-primary:hover {
    background: var(--primary-dark);
    transform: translateY(-1px);
    box-shadow: 0 6px 12px -2px rgba(99, 102, 241, 0.4);
}

.btn-secondary {
    background: var(--border);
    color: var(--text);
    border: none;
    padding: 0.875rem 1.5rem;
    font-size: 1rem;
    font-weight: 600;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all 0.2s;
}

.btn-secondary:hover {
    background: #cbd5e1;
}

/* Habits Container */
.habits-container {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

/* Habit Card */
.habit-card {
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 1.5rem;
    box-shadow: var(--shadow);
    transition: all 0.3s;
    animation: slideIn 0.3s ease-out;
}

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

.habit-card:hover {
    box-shadow: var(--shadow-lg);
}

.habit-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1rem;
}

.habit-info {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.habit-emoji {
    font-size: 2rem;
    width: 3rem;
    height: 3rem;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg);
    border-radius: var(--radius-sm);
}

.habit-title {
    font-size: 1.25rem;
    font-weight: 600;
}

.habit-streak {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    font-size: 0.875rem;
    color: var(--warning);
    font-weight: 600;
}

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

.icon-btn {
    background: none;
    border: none;
    width: 2rem;
    height: 2rem;
    border-radius: var(--radius-sm);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    color: var(--text-light);
}

.icon-btn:hover {
    background: var(--bg);
    color: var(--text);
}

.icon-btn.delete:hover {
    background: #fee2e2;
    color: var(--danger);
}

.icon-btn.archive:hover {
    background: #fef3c7;
    color: var(--warning);
}

/* Weekly Grid */
.weekly-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 0.5rem;
}

.day-cell {
    aspect-ratio: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-sm);
    background: var(--bg);
    cursor: pointer;
    transition: all 0.2s;
    border: 2px solid transparent;
}

.day-cell:hover {
    border-color: var(--primary-light);
    transform: scale(1.05);
}

.day-cell.completed {
    background: var(--success);
    color: white;
}

.day-cell.completed .day-name,
.day-cell.completed .day-number {
    color: white;
}

.day-name {
    font-size: 0.625rem;
    font-weight: 600;
    text-transform: uppercase;
    color: var(--text-light);
    margin-bottom: 0.25rem;
}

.day-number {
    font-size: 1rem;
    font-weight: 700;
    color: var(--text);
}

.day-cell.completed::after {
    content: '✓';
    position: absolute;
    font-size: 0.75rem;
    margin-top: 1.5rem;
}

/* Empty State */
.empty-state {
    text-align: center;
    padding: 4rem 2rem;
    color: var(--text-light);
}

.empty-icon {
    font-size: 4rem;
    margin-bottom: 1rem;
    opacity: 0.5;
}

.empty-state.hidden {
    display: none;
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1000;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(4px);
}

.modal.active {
    display: flex;
}

.modal-content {
    background: var(--card-bg);
    border-radius: var(--radius);
    width: 90%;
    max-width: 450px;
    max-height: 90vh;
    overflow-y: auto;
    animation: modalIn 0.3s ease-out;
}

@keyframes modalIn {
    from {
        opacity: 0;
        transform: scale(0.95);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.5rem;
    border-bottom: 1px solid var(--border);
}

.modal-header h2 {
    font-size: 1.25rem;
    font-weight: 600;
}

.close-btn {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--text-light);
    width: 2rem;
    height: 2rem;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-sm);
    transition: all 0.2s;
}

.close-btn:hover {
    background: var(--bg);
    color: var(--text);
}

form {
    padding: 1.5rem;
}

.form-group {
    margin-bottom: 1.5rem;
}

.form-group label {
    display: block;
    font-weight: 600;
    margin-bottom: 0.5rem;
    font-size: 0.875rem;
}

.form-group input[type="text"] {
    width: 100%;
    padding: 0.75rem 1rem;
    border: 2px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 1rem;
    transition: border-color 0.2s;
}

.form-group input[type="text"]:focus {
    outline: none;
    border-color: var(--primary);
}

.emoji-grid {
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    gap: 0.5rem;
}

.emoji-option {
    font-size: 1.5rem;
    padding: 0.5rem;
    text-align: center;
    cursor: pointer;
    border-radius: var(--radius-sm);
    transition: all 0.2s;
    user-select: none;
}

.emoji-option:hover {
    background: var(--bg);
    transform: scale(1.1);
}

.emoji-option.selected {
    background: var(--primary-light);
    transform: scale(1.1);
}

.form-actions {
    display: flex;
    gap: 1rem;
    justify-content: flex-end;
}

/* Confetti Canvas */
#confettiCanvas {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 2000;
}

/* Animations */
@keyframes streakPulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.2); }
}

.streak-animation {
    animation: streakPulse 0.5s ease-in-out;
}

/* Responsive */
@media (max-width: 600px) {
    header h1 {
        font-size: 1.875rem;
    }
    
    .stats-bar {
        grid-template-columns: 1fr;
    }
    
    .stat-card {
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 1rem 1.5rem;
    }
    
    .stat-number {
        font-size: 1.5rem;
    }
    
    .weekly-grid {
        gap: 0.25rem;
    }
    
    .day-cell {
        min-height: 3rem;
    }
    
    .emoji-grid {
        grid-template-columns: repeat(4, 1fr);
    }
}

/* Archived habits section */
.archived-section {
    margin-top: 3rem;
    padding-top: 2rem;
    border-top: 2px dashed var(--border);
}

.archived-title {
    font-size: 1rem;
    color: var(--text-light);
    margin-bottom: 1rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

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

.habit-card.archived .weekly-grid {
    pointer-events: none;
}
