/* CSS Variables for Theming */
:root {
    /* ----- Light Mode (Default) ----- */
    --bg-color: #f6f8fa;
    --surface-color: #ffffff;
    --surface-hover: #f3f4f6;
    --text-main: #24292f;
    --text-muted: #57606a;
    --border-color: #d0d7de;

    /* Base Colors (Ocean default) */
    --primary-color: #0969da;
    --primary-hover: #0349b4;
    --success-color: #1a7f37;
    --success-hover: #116329;
    --danger-color: #cf222e;
    --danger-hover: #a40e26;

    --gradient-start: #0969da;
    --gradient-end: #8250df;

    /* Layout & Fonts */
    --border-radius: 12px;
    --transition-speed: 0.3s;
    --font-family: 'Outfit', sans-serif;
}

/* ----- Dark Mode Overrides ----- */
[data-theme="dark"] {
    --bg-color: #0d1117;
    --surface-color: #161b22;
    --surface-hover: #21262d;
    --text-main: #c9d1d9;
    --text-muted: #8b949e;
    --border-color: #30363d;

    --primary-color: #58a6ff;
    --primary-hover: #3182ce;
    --success-color: #238636;
    --success-hover: #2ea043;
    --danger-color: #da3633;
    --danger-hover: #f85149;
    --gradient-start: #58a6ff;
    --gradient-end: #a371f7;
}

/* ----- Forest Preset ----- */
:root[data-color="forest"] {
    --primary-color: #1a7f37;
    --primary-hover: #116329;
    --gradient-start: #1a7f37;
    --gradient-end: #9e6a03;
}

[data-theme="dark"][data-color="forest"] {
    --primary-color: #3fb950;
    --primary-hover: #2ea043;
    --gradient-start: #3fb950;
    --gradient-end: #d29922;
}

/* ----- Ocean Preset ----- */
:root[data-color="ocean"] {
    --primary-color: #0969da;
    --primary-hover: #0349b4;
    --gradient-start: #0969da;
    --gradient-end: #8250df;
}

[data-theme="dark"][data-color="ocean"] {
    --primary-color: #58a6ff;
    --primary-hover: #3182ce;
    --gradient-start: #58a6ff;
    --gradient-end: #a371f7;
}

/* ----- Sunset Preset ----- */
:root[data-color="sunset"] {
    --primary-color: #e34c26;
    --primary-hover: #c93c1b;
    --gradient-start: #e34c26;
    --gradient-end: #bf3989;
}

[data-theme="dark"][data-color="sunset"] {
    --primary-color: #ff7b72;
    --primary-hover: #f85149;
    --gradient-start: #ff7b72;
    --gradient-end: #ffa657;
}

/* Global Reset & Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    scroll-behavior: smooth;
}

body {
    font-family: var(--font-family);
    background-color: var(--bg-color);
    color: var(--text-main);
    line-height: 1.6;
    min-height: 100vh;
    display: flex;
    justify-content: center;
    background-image:
        radial-gradient(circle at 15% 50%, color-mix(in srgb, var(--primary-color) 5%, transparent), transparent 25%),
        radial-gradient(circle at 85% 30%, color-mix(in srgb, var(--success-color) 5%, transparent), transparent 25%);
    transition: background-color var(--transition-speed), color var(--transition-speed);
    overflow-x: hidden;
}

.app-container {
    width: 100%;
    max-width: 800px;
    padding: 2rem;
    display: flex;
    flex-direction: column;
    gap: 2rem;
}

/* Typography */
h1 {
    font-size: 2.5rem;
    font-weight: 700;
    background: linear-gradient(90deg, var(--gradient-start), var(--gradient-end));
    background-clip: text;
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    margin-bottom: 0.5rem;
}

h2 {
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--text-main);
}

p {
    color: var(--text-muted);
}

/* Header & Theme Controls */
.app-header {
    text-align: center;
    margin-bottom: 1rem;
    animation: fadeInDown 0.8s ease-out;
    position: relative;
}

.header-content {
    position: relative;
    z-index: 1;
}

/* Gamification UI */
.user-stats-container {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 2rem;
    margin-top: 1.5rem;
    background-color: var(--surface-color);
    padding: 1rem 2rem;
    border-radius: var(--border-radius);
    border: 1px solid var(--border-color);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

.level-badge {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 1.2rem;
    font-weight: 700;
    color: #e3b341;
}

.level-badge i {
    text-shadow: 0 0 10px rgba(227, 179, 65, 0.5);
}

.xp-bar-container {
    flex: 1;
    max-width: 300px;
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

.xp-info {
    display: flex;
    justify-content: space-between;
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-main);
}

.xp-track {
    width: 100%;
    height: 8px;
    background-color: var(--bg-color);
    border-radius: 4px;
    overflow: hidden;
    border: 1px solid var(--border-color);
}

.xp-fill {
    height: 100%;
    width: 0%; /* Dynamic */
    background: linear-gradient(90deg, var(--primary-color), #a371f7);
    border-radius: 4px;
    transition: width 0.5s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Header Top */
.header-top {
    display: flex;
    justify-content: flex-end;
    margin-bottom: 1.5rem;
}

.theme-controls {
    display: flex;
    align-items: center;
    gap: 1.5rem;
    background-color: var(--surface-color);
    padding: 0.6rem 1.2rem;
    border-radius: 20px;
    border: 1px solid var(--border-color);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.preset-selector {
    display: flex;
    gap: 0.5rem;
}

/* Preset Buttons */
.theme-preset-btn {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    border: 2px solid transparent;
    cursor: pointer;
    transition: transform var(--transition-speed);
    padding: 0;
}

.theme-preset-btn:hover {
    transform: scale(1.1);
}

.theme-preset-btn.active {
    border-color: var(--text-main);
    transform: scale(1.15);
}

/* Base button colors for presets */
.theme-preset-btn[data-theme="forest"] {
    background: linear-gradient(135deg, #1a7f37, #9e6a03);
}

[data-theme="dark"] .theme-preset-btn[data-theme="forest"] {
    background: linear-gradient(135deg, #3fb950, #d29922);
}

.theme-preset-btn[data-theme="ocean"] {
    background: linear-gradient(135deg, #0969da, #8250df);
}

[data-theme="dark"] .theme-preset-btn[data-theme="ocean"] {
    background: linear-gradient(135deg, #58a6ff, #a371f7);
}

.theme-preset-btn[data-theme="sunset"] {
    background: linear-gradient(135deg, #e34c26, #bf3989);
}

[data-theme="dark"] .theme-preset-btn[data-theme="sunset"] {
    background: linear-gradient(135deg, #ff7b72, #ffa657);
}

/* Toggle Switch Styles */
.theme-toggle-wrapper {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.switch {
    position: relative;
    display: inline-block;
    width: 48px;
    height: 24px;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: var(--border-color);
    transition: var(--transition-speed);
    border-radius: 24px;
}

.slider:before {
    position: absolute;
    content: "";
    height: 18px;
    width: 18px;
    left: 3px;
    bottom: 3px;
    background-color: #ffffff;
    transition: var(--transition-speed);
    border-radius: 50%;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

/* Light/Dark Mode Icons */
.slider-icon {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    font-size: 0.7rem;
    color: var(--text-muted);
    transition: opacity var(--transition-speed);
}

.slider-icon.fa-sun {
    left: 6px;
    opacity: 0;
}

.slider-icon.fa-moon {
    right: 6px;
    opacity: 1;
}

input:checked+.slider {
    background-color: var(--primary-color);
}

input:focus+.slider {
    box-shadow: 0 0 1px var(--primary-color);
}

input:checked+.slider:before {
    transform: translateX(24px);
}

input:checked+.slider .fa-sun {
    opacity: 1;
    color: #ffd700;
}

input:checked+.slider .fa-moon {
    opacity: 0;
}

/* Add Habit Form */
.add-habit-section {
    background-color: var(--surface-color);
    padding: 1.5rem;
    border-radius: var(--border-radius);
    border: 1px solid var(--border-color);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
    animation: fadeIn 0.8s ease-out 0.2s both;
}

.input-group {
    display: flex;
    gap: 1rem;
}

input[type="text"] {
    flex: 1;
    background-color: var(--bg-color);
    border: 1px solid var(--border-color);
    color: var(--text-main);
    padding: 0.8rem 1.2rem;
    border-radius: var(--border-radius);
    font-family: var(--font-family);
    font-size: 1rem;
    transition: border-color var(--transition-speed), box-shadow var(--transition-speed);
}

input[type="text"]:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(88, 166, 255, 0.1);
}

/* Buttons */
button {
    cursor: pointer;
    font-family: var(--font-family);
    font-weight: 600;
    font-size: 1rem;
    border: none;
    border-radius: var(--border-radius);
    transition: all var(--transition-speed);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}

.btn-primary {
    background-color: var(--primary-color);
    color: #ffffff;
    padding: 0.8rem 1.5rem;
    position: relative;
    overflow: hidden;
}

.btn-primary::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.3);
    transform: translate(-50%, -50%);
    transition: width 0.6s, height 0.6s;
}

.btn-primary:hover::before {
    width: 300px;
    height: 300px;
}

.btn-primary:hover {
    background-color: var(--primary-hover);
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(88, 166, 255, 0.4);
}

.btn-primary:active {
    transform: translateY(0);
    box-shadow: 0 2px 8px rgba(88, 166, 255, 0.3);
}

/* Improved Delete Button */
.btn-icon {
    background: transparent;
    color: var(--text-muted);
    padding: 0.5rem;
    font-size: 1.2rem;
    transition: all 0.3s ease;
}

.btn-icon:hover {
    color: var(--danger-color);
    transform: scale(1.15) rotate(10deg);
    background-color: rgba(207, 34, 46, 0.1);
    border-radius: 50%;
}

.btn-icon:active {
    transform: scale(1.05) rotate(5deg);
}

/* Actions */
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background-color: var(--surface-hover);
    border: 2px solid var(--border-color);
    color: transparent;
    font-size: 1rem;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.btn-check:hover {
    transform: scale(1.1) rotate(5deg);
    border-color: var(--success-color);
}

.btn-check.completed {
    background-color: var(--success-color);
    border-color: var(--success-color);
    color: white;
    box-shadow: 0 0 20px rgba(35, 134, 54, 0.5);
    animation: checkPulse 0.6s ease-out;
}

@keyframes checkPulse {
    0% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.2);
    }
    100% {
        transform: scale(1);
    }
}

/* Habits Section */
.habits-section {
    margin-top: 2.5rem;
    animation: fadeIn 0.8s ease-out 0.4s both;
}

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

.date-display {
    color: var(--primary-color);
    font-weight: 500;
    background-color: rgba(88, 166, 255, 0.1);
    padding: 0.4rem 0.8rem;
    border-radius: 20px;
    font-size: 0.9rem;
}

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

.habit-card {
    background-color: var(--surface-color);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 1.2rem;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    overflow: hidden;
    animation: slideInUp 0.5s ease-out backwards;
}

.habit-card:nth-child(1) { animation-delay: 0.1s; }
.habit-card:nth-child(2) { animation-delay: 0.2s; }
.habit-card:nth-child(3) { animation-delay: 0.3s; }
.habit-card:nth-child(4) { animation-delay: 0.4s; }
.habit-card:nth-child(5) { animation-delay: 0.5s; }

.habit-main {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.habit-history {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-top: 1rem;
    border-top: 1px solid var(--border-color);
}

.history-label {
    font-size: 0.85rem;
    color: var(--text-muted);
    font-weight: 500;
}

.history-days {
    display: flex;
    gap: 8px;
}

.history-day {
    width: 28px;
    height: 28px;
    border-radius: 8px;
    background-color: var(--bg-color);
    border: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-muted);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    cursor: default;
}

.history-day:hover {
    transform: translateY(-2px);
}

.history-day.active {
    background-color: var(--success-color);
    border-color: var(--success-color);
    color: white;
    box-shadow: 0 0 12px rgba(35, 134, 54, 0.4);
    transform: scale(1.05);
}

.history-day.today {
    border-color: var(--primary-color);
    border-width: 2px;
    box-shadow: 0 0 8px rgba(88, 166, 255, 0.3);
}

.habit-card:hover {
    transform: translateY(-5px) scale(1.01);
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.15), 0 2px 8px rgba(0, 0, 0, 0.1);
    border-color: var(--primary-color);
}

.habit-card:active {
    transform: translateY(-2px) scale(1.005);
}

/* A slight gradient glow indicating active state */
.habit-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 4px;
    height: 100%;
    background: var(--border-color);
    transition: background var(--transition-speed);
}

.habit-card.completed-today::before {
    background: var(--success-color);
}

.habit-info {
    flex: 1;
    margin-left: 1rem;
}

.habit-name {
    font-size: 1.2rem;
    font-weight: 600;
    margin-bottom: 0.2rem;
}

.habit-streak {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.9rem;
    color: var(--text-muted);
}

.streak-icon {
    color: #e3b341;
}

.streak-count {
    font-weight: 600;
    color: var(--text-main);
}

/* Actions */
.habit-actions {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.btn-check {

/* Empty State */
.empty-state {
    text-align: center;
    padding: 3rem 0;
    color: var(--text-muted);
}

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

.empty-icon {
    font-size: 3rem;
    margin-bottom: 1rem;
    color: var(--primary-color);
    opacity: 0.5;
}

/* Toast Notification */
.toast-container {
    position: fixed;
    bottom: 20px;
    right: 20px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    z-index: 1000;
}

.toast {
    background-color: var(--surface-color);
    border-left: 4px solid var(--primary-color);
    color: var(--text-main);
    padding: 1rem;
    border-radius: 4px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    display: flex;
    align-items: center;
    gap: 0.8rem;
    animation: slideInRight 0.3s ease-out forwards;
}

.toast.success {
    border-left-color: var(--success-color);
}

.toast.error {
    border-left-color: var(--danger-color);
}

.toast.hiding {
    animation: fadeOut 0.3s ease-out forwards;
}

/* Animations */
@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

@keyframes fadeInDown {
    from {
        opacity: 0;
        transform: translateY(-20px);
    }

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

@keyframes slideInRight {
    from {
        opacity: 0;
        transform: translateX(50px);
    }

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

@keyframes fadeOut {
    from {
        opacity: 1;
    }

    to {
        opacity: 0;
    }
}

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

@keyframes shimmer {
    0% {
        background-position: -1000px 0;
    }
    100% {
        background-position: 1000px 0;
    }
}

/* Responsive */
@media (max-width: 600px) {
    .app-container {
        padding: 1rem;
    }

    h1 {
        font-size: 2rem;
    }

    .input-group {
        flex-direction: column;
    }

    .habit-card {
        flex-direction: column;
        align-items: flex-start;
        gap: 1rem;
    }

    .habit-actions {
        width: 100%;
        justify-content: space-between;
        margin-top: 0.5rem;
    }

    .user-stats-container {
        flex-direction: column;
        gap: 1rem;
        padding: 1rem;
    }

    .xp-bar-container {
        max-width: 100%;
    }

    .theme-controls {
        flex-direction: column;
        gap: 1rem;
    }

    .history-days {
        gap: 6px;
    }

    .history-day {
        width: 24px;
        height: 24px;
        font-size: 0.7rem;
    }
}

/* Modal Styles */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 2000;
}

.modal-overlay.hidden {
    display: none;
}

.modal-content {
    background: var(--surface-color);
    padding: 2rem;
    border-radius: var(--border-radius);
    border: 1px solid var(--border-color);
    width: 90%;
    max-width: 400px;
    text-align: center;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
}

.btn-secondary {
    background-color: var(--surface-hover);
    color: var(--text-main);
    border: 1px solid var(--border-color);
    padding: 0.6rem 1.2rem;
}

.btn-secondary:hover {
    background-color: var(--border-color);
}

/* Loading Skeleton */
.skeleton {
    background: linear-gradient(
        90deg,
        var(--surface-color) 0%,
        var(--surface-hover) 50%,
        var(--surface-color) 100%
    );
    background-size: 1000px 100%;
    animation: shimmer 2s infinite linear;
    border-radius: var(--border-radius);
}

.skeleton-card {
    height: 120px;
    margin-bottom: 1rem;
}

/* Improved Focus States */
button:focus-visible,
input:focus-visible {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
}

/* Smooth Transitions for Theme Changes */
* {
    transition: background-color 0.3s ease, color 0.3s ease, border-color 0.3s ease;
}

/* Improved Delete Button */
.btn-icon {
    background: transparent;
    color: var(--text-muted);
    padding: 0.5rem;
    font-size: 1.2rem;
    transition: all 0.3s ease;
}

.btn-icon:hover {
    color: var(--danger-color);
    transform: scale(1.15) rotate(10deg);
    background-color: rgba(207, 34, 46, 0.1);
    border-radius: 50%;
}

.btn-icon:active {
    transform: scale(1.05) rotate(5deg);
}