/* =====================
   CSS RESET & VARIABLES
===================== */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

:root {
    --bg: #f9fafb;
    --card: #ffffff;
    --primary: #6366f1;
    --primary-hover: #4f46e5;
    --danger: #ef4444;
    --text: #111827;
    --muted: #6b7280;
    --border: #e5e7eb;
    --radius: 10px;
    --shadow: 0 10px 25px rgba(0, 0, 0, 0.06);
    --transition: 0.2s ease;
}

/* =====================
   DARK MODE VARIABLES
===================== */
[data-theme="dark"] {
    --bg: #0f172a;
    --card: #1e293b;
    --text: #e5e7eb;
    --muted: #94a3b8;
    --border: #334155;

    --primary: #818cf8;
    --primary-hover: #6366f1;
    --danger: #f87171;

    --shadow: 0 20px 40px rgba(0, 0, 0, 0.45);
}

body {
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
        sans-serif;

    background: linear-gradient(120deg,
            var(--bg),
            color-mix(in srgb, var(--primary) 8%, var(--bg)),
            var(--bg));

    background-size: 300% 300%;
    animation: gradientShift 18s ease infinite;

    color: var(--text);
    line-height: 1.6;
}

body::before {
    content: "";
    position: fixed;
    inset: 0;

    background: var(--bg);
    pointer-events: none;
    z-index: 9999;

    opacity: 0;
    transition: opacity 0.35s ease;
}

body.theme-transition::before {
    opacity: 1;
}

@keyframes gradientShift {
    0% {
        background-position: 0% 50%;
    }

    50% {
        background-position: 100% 50%;
    }

    100% {
        background-position: 0% 50%;
    }
}

[data-theme="dark"] body {
    background: linear-gradient(120deg,
            #020617,
            color-mix(in srgb, var(--primary) 12%, #020617),
            #020617);

    background-size: 300% 300%;
}


/* =====================
   APP CONTAINER
===================== */
.app {
    max-width: 520px;
    margin: 4rem auto;
    background: var(--card);
    padding: 2rem;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

/* =====================
   HEADER
===================== */
.app-header {
    text-align: center;
    margin-bottom: 2rem;
}

.app-header h1 {
    font-size: 2rem;
    font-weight: 700;
}

.subtitle {
    font-size: 0.95rem;
    color: var(--muted);
    margin-top: 0.25rem;
}

/* =====================
   INPUT FORM
===================== */
.task-input form {
    display: flex;
    gap: 0.5rem;
}

.task-input input {
    flex: 1;
    padding: 0.65rem 0.75rem;
    border-radius: var(--radius);

    background-color: var(--card);
    color: var(--text);
    border: 1px solid var(--border);

    font-size: 0.95rem;
    caret-color: var(--primary);

    transition:
        background-color var(--transition),
        color var(--transition),
        border-color var(--transition);
}

.task-input input::placeholder {
    color: var(--muted);
}

.task-input input:focus {
    outline: none;
    border-color: var(--primary);
}

/* Disable animation during theme cross-fade */
body.theme-transition .task-input input {
    transition: none;
}


.task-input button {
    padding: 0.65rem 1rem;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: var(--radius);
    cursor: pointer;
    transition: background var(--transition);
}

.task-input button:hover {
    background: var(--primary-hover);
}

/* =====================
   SEARCH BAR
===================== */
.task-search {
    margin-top: 1rem;
}

.task-search input {
    width: 100%;
    padding: 0.6rem 0.75rem;
    font-size: 0.9rem;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    background: transparent;
    color: var(--text);
    transition: border var(--transition), box-shadow var(--transition);
}

.task-search input::placeholder {
    color: var(--muted);
}

.task-search input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.15);
}

/* =====================
   TASK COUNTER
===================== */
.task-counter {
    margin-top: 0.75rem;
    text-align: center;
    font-size: 0.85rem;
    color: var(--muted);
}

.task-counter span {
    font-weight: 600;
    color: var(--text);
}


/* =====================
   FILTER BUTTONS
===================== */
.filters {
    display: flex;
    justify-content: center;
    gap: 0.5rem;
    margin: 1.5rem 0;
}

.filter-btn {
    padding: 0.4rem 0.9rem;
    font-size: 0.85rem;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: transparent;
    cursor: pointer;
    color: var(--muted);
    transition: background 0.2s ease, color 0.2s ease, transform 0.15s ease;
}

.filter-btn.active {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
    transform: scale(0.95);
}

/* =====================
   TASK LIST
===================== */
.task-list ul {
    list-style: none;
}

@keyframes slideFadeIn {
    from {
        opacity: 0;
        transform: translateY(-6px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.task-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.65rem 0.75rem;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    margin-bottom: 0.5rem;
    transition: background var(--transition);
    animation: slideFadeIn 0.25s ease-out;
}

.task-item:hover {
    background: #f3f4f6;
}

.task-item.completed {
    background: #f0fdf4;
    border-color: #bbf7d0;
    transition: background 0.25s ease, border 0.25s ease;
}

.task-item.completed .task-title {
    text-decoration: line-through;
    color: var(--muted);
    transition: color 0.25s ease;
}

/* =====================
   TASK CONTENT
===================== */
.task-title {
    font-size: 0.95rem;
    word-break: break-word;
}

.task-actions {
    display: flex;
    gap: 0.4rem;
}

.task-actions button {
    border: none;
    background: transparent;
    cursor: pointer;
    font-size: 0.9rem;
    opacity: 0.75;
    transition: opacity var(--transition), transform var(--transition);
}

.task-actions button:hover {
    opacity: 1;
    transform: scale(1.1);
}

.task-actions button:active {
    transform: scale(0.92);
}


.delete-btn:hover {
    color: var(--danger);
}

/* =====================
   EDIT INPUT
===================== */
@keyframes editPulse {
    from {
        background: rgba(99, 102, 241, 0.15);
    }

    to {
        background: var(--card);
    }
}

.edit-input {
    width: 100%;
    font-size: 0.95rem;
    padding: 0.3rem 0.4rem;
    border-radius: 6px;
    border: 1px solid var(--primary);
    outline: none;

    background: var(--card);
    color: var(--text);

    animation: editPulse 0.15s ease-out;
}


/* =====================
   EMPTY STATE
===================== */
.empty-state {
    text-align: center;
    color: var(--muted);
    margin-top: 1.5rem;
    font-size: 0.9rem;
}

/* =====================
   THEME TOGGLE
===================== */
.theme-toggle {
    position: absolute;
    top: 1.25rem;
    right: 1.25rem;

    width: 38px;
    height: 38px;

    display: flex;
    align-items: center;
    justify-content: center;

    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 50%;

    cursor: pointer;
    box-shadow: var(--shadow);

    transition:
        background var(--transition),
        border var(--transition),
        transform 0.45s cubic-bezier(.4, .0, .2, 1);
}


.theme-toggle:hover {
    transform: scale(1.08) rotate(8deg);
}

/* Default (light) */
[data-theme="light"] .theme-toggle {
    transform: rotate(0deg);
}

/* Dark mode → rotate */
[data-theme="dark"] .theme-toggle {
    transform: rotate(180deg);
}

.theme-toggle span {
    position: absolute;
    transition:
        opacity 0.25s ease,
        transform 0.25s ease;
}

/* Light */
[data-theme="light"] .icon-sun {
    opacity: 1;
    transform: rotate(0deg) scale(1);
}

[data-theme="light"] .icon-moon {
    opacity: 0;
    transform: scale(0.5);
}

/* Dark */
[data-theme="dark"] .icon-sun {
    opacity: 0;
    transform: scale(0.5);
}

[data-theme="dark"] .icon-moon {
    opacity: 1;
    transform: rotate(-180deg) scale(1);
}



/* =====================
   RESPONSIVE
===================== */
/* =====================
   MOBILE FIX ONLY
===================== */
@media (max-width: 480px) {

    /* App container */
    .app {
        margin: 1.5rem 0.75rem;
        padding: 1.25rem;
    }

    /* Header */
    .app-header h1 {
        font-size: 1.6rem;
    }

    .subtitle {
        font-size: 0.85rem;
    }

    /* Input + button stack */
    .task-input form {
        flex-direction: column;
        gap: 0.6rem;
    }

    .task-input input,
    .task-input button {
        width: 100%;
        min-height: 48px;
        /* thumb-friendly */
        font-size: 1rem;
    }

    /* Search bar */
    .task-search input {
        min-height: 46px;
        font-size: 0.95rem;
    }

    /* Filters wrap nicely */
    .filters {
        gap: 0.4rem;
    }

    .filter-btn {
        flex: 1;
        text-align: center;
        min-height: 36px;
        font-size: 0.8rem;
        padding: 0.4rem 0.5rem;
    }

    /* Task item spacing */
    .task-item {
        padding: 0.75rem 0.7rem;
    }

    .task-title {
        font-size: 0.9rem;
    }

    /* Actions bigger tap area */
    .task-actions button {
        font-size: 1rem;
        padding: 0.25rem;
    }

    /* Theme toggle reposition */
    .theme-toggle {
        position: fixed;
        bottom: 1rem;
        right: 1rem;
        top: auto;

        width: 46px;
        height: 46px;

        z-index: 1000;

        box-shadow:
            0 10px 25px rgba(0, 0, 0, 0.25),
            0 0 0 6px color-mix(in srgb, var(--bg) 85%, transparent);
    }
}


@media (prefers-reduced-motion: reduce) {
    body {
        animation: none;
    }

    body::before {
        transition: none;
    }

    .theme-toggle {
        transition: none;
    }
}