:root {
    --primary-color: #6c5ce7;
    --secondary-color: #a29bfe;
    --success-color: #2ecc71;
    --background-color: #f0f8ff;
    --text-color: #2c3e50;
    --card-bg: #ffffff;
    --shadow: 0 4px 15px rgba(0, 0, 0, 0.08);
}

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

body {
    font-family: 'Noto Sans SC', 'Microsoft YaHei', sans-serif;
    background: linear-gradient(135deg, #f0f8ff 0%, #e6e6fa 100%);
    color: var(--text-color);
    line-height: 1.6;
    min-height: 100vh;
}

.app-container {
    max-width: 800px;
    margin: 0 auto;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.main-header {
    background: linear-gradient(to right, #6c5ce7, #a29bfe);
    color: white;
    padding: 1.2rem 1.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
    position: relative;
}

.brand h1 {
    font-size: 1.25rem;
    font-weight: 700;
}

.menu-toggle {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    width: 26px;
    height: 18px;
    background: transparent;
    border: none;
    cursor: pointer;
    padding: 0;
    z-index: 1000;
}

.menu-toggle span {
    width: 100%;
    height: 2px;
    background-color: white;
    border-radius: 10px;
    transition: all 0.3s ease;
}

.menu-toggle.active span:nth-child(1) {
    transform: translateY(8px) rotate(45deg);
}

.menu-toggle.active span:nth-child(2) {
    opacity: 0;
}

.menu-toggle.active span:nth-child(3) {
    transform: translateY(-8px) rotate(-45deg);
}

.user-nav {
    display: none;
    position: absolute;
    top: 100%;
    right: 0;
    width: 200px;
    background: linear-gradient(135deg, #6c5ce7, #a29bfe);
    flex-direction: column;
    padding: 0.5rem;
    box-shadow: -2px 5px 15px rgba(0,0,0,0.2);
    z-index: 999;
    border-bottom-left-radius: 15px;
}

.user-nav.active {
    display: flex;
}

.user-nav a, .user-nav span {
    display: block;
    width: 100%;
    padding: 0.8rem 1rem !important;
    color: white !important;
    text-decoration: none;
    box-sizing: border-box;
    font-size: 0.95rem;
    transition: background 0.2s;
}

.user-nav a:hover {
    background: rgba(255, 255, 255, 0.15);
}

.user-nav span {
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    font-weight: 500;
    opacity: 0.9;
}

@media (max-width: 768px) {
    .user-nav {
        width: 100%;
        border-bottom-left-radius: 0;
    }
}

.btn-logout {
    color: white;
    text-decoration: none;
    border: 1px solid rgba(255, 255, 255, 0.5);
    padding: 0.2rem 0.6rem;
    border-radius: 4px;
    transition: background 0.2s;
}

.btn-logout:hover {
    background: rgba(255, 255, 255, 0.2);
}

.content-wrapper {
    flex: 1;
    padding: 1.5rem;
}

/* Cards */
.card {
    background: var(--card-bg);
    border-radius: 12px;
    padding: 1.5rem;
    box-shadow: var(--shadow);
    margin-bottom: 1.5rem;
}

/* Login */
.login-container {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 60vh;
}

.login-card {
    width: 100%;
    max-width: 400px;
    text-align: center;
}

.subtitle {
    color: #666;
    margin-bottom: 2rem;
}

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

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
    color: #555;
}

.form-group input {
    width: 100%;
    padding: 0.8rem;
    border: 1px solid #ddd;
    border-radius: 6px;
    font-size: 1rem;
    transition: border-color 0.2s;
    /* Ensure padding doesn't affect width calculation with box-sizing */
    box-sizing: border-box;
}

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

.btn {
    display: inline-block;
    padding: 0.8rem 1.5rem;
    border: none;
    border-radius: 6px;
    font-size: 1rem;
    cursor: pointer;
    transition: background 0.2s;
    text-align: center;
}

.btn-primary {
    background-color: var(--primary-color);
    color: white;
}

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

.btn-block {
    width: 100%;
}

/* Dashboard */
.welcome-banner {
    margin-bottom: 1.5rem;
}

.date-display {
    color: #666;
    font-size: 0.9rem;
}

/* Task List */
.task-list {
    list-style: none;
}

.task-item {
    display: flex;
    align-items: center;
    padding: 1rem;
    border-bottom: 1px solid #eee;
    transition: background 0.2s;
}

.task-item:last-child {
    border-bottom: none;
}

.task-content {
    flex: 1;
    font-size: 1.05rem;
}

/* Checkbox Styling */
.task-checkbox {
    width: 24px;
    height: 24px;
    border: 2px solid #ddd;
    border-radius: 50%;
    margin-right: 1rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.task-item.completed .task-checkbox {
    background-color: var(--success-color);
    border-color: var(--success-color);
}

.task-item.completed .task-content {
    text-decoration: line-through;
    color: #888;
}

.checkmark {
    display: none;
    color: white;
    font-size: 14px;
}

.task-item.completed .checkmark {
    display: block;
}

/* Admin Specific */
.admin-controls {
    display: flex;
    gap: 0.5rem;
    margin-top: 1rem;
}

.trash-btn {
    background: none;
    border: none;
    color: #e74c3c;
    cursor: pointer;
    font-size: 0.9rem;
}

/* Progress Bar */
.progress-container {
    margin-bottom: 2rem;
    background: #fff;
    padding: 1rem;
    border-radius: 12px;
    box-shadow: var(--shadow);
}

.progress-header {
    display: flex;
    justify-content: space-between;
    margin-bottom: 0.5rem;
    font-weight: 500;
}

.progress-bar-bg {
    width: 100%;
    height: 12px;
    background-color: #eee;
    border-radius: 6px;
    overflow: hidden;
}

.progress-bar-fill {
    height: 100%;
    background-color: var(--success-color);
    width: 0%;
    transition: width 0.5s ease-in-out;
}

.encouragement-text {

    /* Templates */
    .template-chip {
        display: inline-flex;
        align-items: center;
        background: white;
        border: 1px solid #ddd;
        border-radius: 20px;
        padding: 0.3rem 0.8rem;
        font-size: 0.9rem;
        gap: 0.5rem;
        transition: all 0.2s;
    }

    .template-chip:hover {
        border-color: var(--secondary-color);
        background: #f0f8ff;
    }

    .delete-tpl {
        color: #999;
        cursor: pointer;
        font-weight: bold;
        margin-left: 0.3rem;
    }

    .delete-tpl:hover {
        color: #e74c3c;
    }

    .template-checkbox {
        cursor: pointer;
    }

    .flash-messages {
        margin-bottom: 1rem;
    }

    .flash-msg {
        padding: 0.8rem;
        border-radius: 6px;
        margin-bottom: 0.5rem;
        background: #d1ecf1;
        color: #0c5460;
    }

    .flash-msg.error {
        background: #f8d7da;
        color: #721c24;
    }

    /* =========================================
       ADMIN & MOBILE RESPONSIVE OPTIMIZATIONS
       ========================================= */

    /* Header and Navigation - Mobile First */
    @media (max-width: 768px) {
        .main-header {
            flex-direction: column;
            padding: 1rem;
            gap: 0.8rem;
        }

        .brand h1 {
            font-size: 1.1rem;
            text-align: center;
        }

        .user-nav {
            flex-direction: column;
            width: 100%;
            gap: 0.5rem;
            font-size: 0.85rem;
            align-items: stretch;
            background: transparent;
            padding: 0;
        }

        .user-nav a,
        .user-nav span {
            display: block;
            text-align: center;
            padding: 0.5rem;
            background: rgba(255, 255, 255, 0.15);
            border-radius: 6px;
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
        }

        .user-nav a {
            margin: 0 !important;
        }

        .btn-logout {
            background: rgba(255, 255, 255, 0.25);
            margin: 0 !important;
        }
    }

    /* Content and Cards - Mobile */
    @media (max-width: 600px) {
        .content-wrapper {
            padding: 0.8rem;
        }

        .card {
            padding: 0.8rem;
            margin-bottom: 1rem;
            border-radius: 8px;
        }

        .welcome-banner h2 {
            font-size: 1.3rem;
            margin-bottom: 0.8rem;
        }

        /* Date Navigator - Mobile */
        .welcome-banner>div {
            flex-direction: column !important;
            gap: 0.8rem !important;
        }

        #date-nav-form {
            width: 100%;
            flex-direction: column !important;
            gap: 0.5rem !important;
        }

        #date-nav-form label {
            font-size: 0.9rem;
        }

        #date-display {
            width: 100% !important;
            min-width: auto !important;
            padding: 0.7rem 1rem !important;
            font-size: 1rem !important;
        }

        /* Form Elements - Larger Touch Targets */
        .form-group input,
        .btn,
        button {
            min-height: 44px;
            font-size: 1rem;
        }

        .btn-primary {
            width: 100%;
            padding: 0.8rem 1rem;
        }

        /* Task Form - Mobile */
        .add-task-section h3 {
            font-size: 1.1rem;
            margin-bottom: 0.8rem;
        }

        #add-task-form {
            padding: 0.8rem !important;
        }

        /* Quill Editor - Mobile Optimization */
        #editor-container {
            height: 120px !important;
            font-size: 1rem;
        }

        .ql-toolbar {
            padding: 0.5rem !important;
        }

        .ql-toolbar button {
            width: 32px !important;
            height: 32px !important;
            padding: 4px !important;
        }

        .ql-toolbar .ql-stroke {
            stroke-width: 2.5 !important;
        }

        .ql-editor {
            padding: 0.8rem !important;
            font-size: 1rem !important;
            min-height: 80px;
        }

        /* Image Upload and Submit - Mobile */
        #add-task-form>div:last-child {
            flex-direction: column !important;
            gap: 0.8rem !important;
        }

        #add-task-form label[for="task-image"] {
            font-size: 0.85rem !important;
        }

        #task-image {
            font-size: 0.85rem !important;
            width: 100%;
        }

        /* Task List - Mobile */
        .task-list {
            padding: 0;
        }

        .task-item {
            flex-direction: column;
            align-items: flex-start !important;
            padding: 0.8rem;
            gap: 0.8rem;
        }

        .task-item>div:first-child {
            width: 100%;
        }

        .task-item>div:last-child {
            width: 100%;
            flex-direction: row;
            justify-content: space-between;
            align-items: center;
        }

        .task-content {
            font-size: 1rem !important;
        }

        .task-gallery img {
            height: 50px !important;
        }

        /* Buttons in Task List */
        .task-item button {
            padding: 0.4rem 0.8rem !important;
            font-size: 0.85rem !important;
        }

        /* Publish Button - Mobile */
        .card>div:first-child {
            flex-direction: column !important;
            gap: 0.8rem !important;
        }

        .card>div:first-child h3 {
            font-size: 1.1rem;
        }

        .card>div:first-child button,
        .card>div:first-child span {
            width: 100%;
            text-align: center;
        }
    }

    /* Extra Small Screens */
    @media (max-width: 400px) {
        .main-header {
            padding: 0.8rem;
        }

        .brand h1 {
            font-size: 1rem;
        }

        .content-wrapper {
            padding: 0.5rem;
        }

        .card {
            padding: 0.6rem;
        }

        .welcome-banner h2 {
            font-size: 1.1rem;
        }

        #editor-container {
            height: 100px !important;
        }

        .ql-toolbar button {
            width: 28px !important;
            height: 28px !important;
        }

        /* Task Library - Mobile */
        .template-grid {
            grid-template-columns: 1fr !important;
        }

        .template-card {
            flex-direction: column !important;
            align-items: flex-start !important;
            gap: 0.8rem !important;
        }

        .template-card>div:first-child {
            width: 100%;
        }

        .template-card button {
            align-self: flex-end;
        }

        #add-template-form {
            flex-direction: column !important;
        }

        #add-template-form input {
            width: 100%;
        }

        #add-template-form button {
            width: 100%;
        }

        /* User Management - Mobile */
        table {
            font-size: 0.85rem;
        }

        table th,
        table td {
            padding: 0.5rem !important;
        }

        /* Make tables scrollable on mobile */
        .card>table {
            display: block;
            overflow-x: auto;
            white-space: nowrap;
        }
    }

    /* =========================================
   STUDENT "QUEST MODE" REDESIGN
   ========================================= */

    body.student-quest-mode {
        background: linear-gradient(135deg, #fdfbfb 0%, #ebedee 100%);
        background-color: #f0f4f8;
        /* Fallback */
        background-image:
            radial-gradient(at 0% 0%, hsla(253, 16%, 7%, 1) 0, transparent 50%),
            radial-gradient(at 50% 0%, hsla(225, 39%, 30%, 1) 0, transparent 50%),
            radial-gradient(at 100% 0%, hsla(339, 49%, 30%, 1) 0, transparent 50%);
        background: #e0f7fa;
        /* Kid friendly light blue */
        background-image: linear-gradient(120deg, #e0f7fa 0%, #fff1eb 100%);
        min-height: 100vh;
    }

    .student-quest-mode .app-container {
        max-width: 900px;
    }

    /* Header Re-style */
    .student-quest-mode .main-header {
        background: transparent;
        box-shadow: none;
        padding: 1.5rem;
    }

    .student-quest-mode .brand h1 {
        color: #37474f;
        font-size: 1.8rem;
        font-family: 'Comic Sans MS', 'Chalkboard SE', sans-serif;
        /* Fun font fallback */
        text-shadow: 2px 2px 0px white;
    }

    .student-quest-mode .user-nav {
        background: rgba(255, 255, 255, 0.8);
        padding: 0.5rem 1rem;
        border-radius: 30px;
        box-shadow: 0 4px 15px rgba(0, 0, 0, 0.05);
        backdrop-filter: blur(5px);
    }

    /* Cards as Floating Islands */
    .student-quest-mode .card {
        border-radius: 24px;
        border: none;
        box-shadow: 0 10px 25px rgba(100, 149, 237, 0.15);
        background: rgba(255, 255, 255, 0.95);
        backdrop-filter: blur(10px);
        margin-bottom: 2rem;
        overflow: hidden;
        position: relative;
        transition: transform 0.3s ease;
    }

    .student-quest-mode .card:hover {
        transform: translateY(-2px);
    }

    /* Progress Bar - XP Style */
    .student-quest-mode .progress-container {
        background: linear-gradient(to right, #6a11cb 0%, #2575fc 100%);
        color: white;
        padding: 1.5rem;
        position: relative;
        overflow: hidden;
    }

    .student-quest-mode .progress-header {
        font-size: 1.2rem;
        margin-bottom: 1rem;
        z-index: 1;
        position: relative;
    }

    .student-quest-mode .progress-bar-bg {
        background: rgba(255, 255, 255, 0.3);
        height: 16px;
        border-radius: 10px;
        border: 2px solid rgba(255, 255, 255, 0.5);
    }

    .student-quest-mode .progress-bar-fill {
        background: #ffd700;
        /* Gold */
        background-image: repeating-linear-gradient(45deg,
                transparent,
                transparent 10px,
                rgba(255, 255, 255, 0.4) 10px,
                rgba(255, 255, 255, 0.4) 20px);
        box-shadow: 0 0 10px #ffd700;
    }

    .student-quest-mode .encouragement-text {
        margin-top: 1rem;
        font-weight: bold;
        text-align: center;
        font-size: 1.1rem;
        color: white;
        text-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
    }

    /* Task Item - "Mission Scroll" */
    .student-quest-mode .task-list {
        display: grid;
        gap: 1rem;
    }

    .student-quest-mode .task-item {
        background: white;
        border: 2px solid #e0e0e0;
        border-radius: 16px;
        padding: 1.2rem;
        transition: all 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
        position: relative;
    }

    .student-quest-mode .task-item:hover {
        transform: scale(1.02);
        border-color: #4facfe;
        box-shadow: 0 8px 20px rgba(79, 172, 254, 0.2);
        z-index: 1;
    }

    .student-quest-mode .task-item.completed {
        background: #f0fff4;
        border-color: #c3e6cb;
        opacity: 0.8;
        transform: scale(0.98);
    }

    /* Custom Checkbox as Star */
    .student-quest-mode .task-checkbox {
        width: 32px;
        height: 32px;
        border-radius: 50%;
        border: 2px solid #bdc3c7;
        background: white;
        margin-right: 1.2rem;
    }

    .student-quest-mode .task-item.completed .task-checkbox {
        background: #ffce00;
        border-color: #f1c40f;
        animation: popIn 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    }

    .student-quest-mode .task-item.completed .checkmark {
        color: #fff;
        font-size: 18px;
        text-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
    }

    /* Animations */
    @keyframes popIn {
        0% {
            transform: scale(0);
        }

        80% {
            transform: scale(1.2);
        }

        100% {
            transform: scale(1);
        }
    }

    @keyframes float {
        0% {
            transform: translateY(0px);
        }

        50% {
            transform: translateY(-5px);
        }

        100% {
            transform: translateY(0px);
        }
    }

    /* Confetti Container */
    #confetti-canvas {
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        pointer-events: none;
        z-index: 9999;
    }

    /* =========================================
       FLATPICKR MOBILE OPTIMIZATION
       ========================================= */

    /* Calendar container styling */
    .flatpickr-calendar {
        box-shadow: 0 12px 40px rgba(0, 0, 0, 0.2) !important;
        border-radius: 16px !important;
        border: none !important;
        font-family: 'Noto Sans SC', sans-serif !important;
    }

    /* Header styling */
    .flatpickr-months {
        background: linear-gradient(135deg, #4A90E2 0%, #357ABD 100%) !important;
        border-radius: 16px 16px 0 0 !important;
        padding: 1rem 0.5rem !important;
    }

    .flatpickr-month {
        color: white !important;
        height: auto !important;
    }

    .flatpickr-current-month {
        font-size: 1.1rem !important;
        font-weight: 600 !important;
        padding: 0.5rem 0 !important;
    }

    .flatpickr-current-month .flatpickr-monthDropdown-months {
        background: rgba(255, 255, 255, 0.2) !important;
        color: white !important;
        border-radius: 8px !important;
        padding: 0.3rem 0.5rem !important;
        font-weight: 600 !important;
    }

    .flatpickr-current-month .numInputWrapper {
        background: rgba(255, 255, 255, 0.2) !important;
        border-radius: 8px !important;
        padding: 0.3rem !important;
    }

    .flatpickr-current-month input.cur-year {
        color: white !important;
        font-weight: 600 !important;
    }

    /* Arrow buttons */
    .flatpickr-prev-month,
    .flatpickr-next-month {
        fill: white !important;
        padding: 0.5rem !important;
    }

    .flatpickr-prev-month:hover,
    .flatpickr-next-month:hover {
        background: rgba(255, 255, 255, 0.2) !important;
        border-radius: 50% !important;
    }

    /* Weekday headers */
    .flatpickr-weekdays {
        background: #f8f9fa !important;
        padding: 0.8rem 0 !important;
    }

    .flatpickr-weekday {
        color: #666 !important;
        font-weight: 600 !important;
        font-size: 0.9rem !important;
    }

    /* Days container */
    .flatpickr-days {
        padding: 0.5rem !important;
    }

    .dayContainer {
        min-width: 100% !important;
        max-width: 100% !important;
    }

    /* Individual day cells */
    .flatpickr-day {
        border-radius: 50% !important;
        font-weight: 500 !important;
        font-size: 0.95rem !important;
        color: #2c3e50 !important;
        border: none !important;
        margin: 2px !important;
        transition: all 0.2s ease !important;
    }

    .flatpickr-day:hover {
        background: #e3f2fd !important;
        border-color: #4A90E2 !important;
        transform: scale(1.05) !important;
    }

    /* Today */
    .flatpickr-day.today {
        border: 2px solid #4A90E2 !important;
        background: white !important;
        font-weight: 700 !important;
    }

    .flatpickr-day.today:hover {
        background: #e3f2fd !important;
    }

    /* Selected day */
    .flatpickr-day.selected {
        background: #4A90E2 !important;
        color: white !important;
        font-weight: 700 !important;
        box-shadow: 0 4px 12px rgba(74, 144, 226, 0.4) !important;
    }

    .flatpickr-day.selected:hover {
        background: #357ABD !important;
    }

    /* Disabled/outside month days */
    .flatpickr-day.prevMonthDay,
    .flatpickr-day.nextMonthDay {
        color: #bdc3c7 !important;
    }

    .flatpickr-day.flatpickr-disabled {
        color: #e0e0e0 !important;
    }

    /* Mobile specific optimizations */
    @media (max-width: 600px) {
        .flatpickr-calendar {
            width: 95vw !important;
            max-width: 380px !important;
            font-size: 16px !important;
        }

        .flatpickr-months {
            padding: 1.2rem 0.5rem !important;
        }

        .flatpickr-current-month {
            font-size: 1.2rem !important;
            padding: 0.6rem 0 !important;
        }

        .flatpickr-weekdays {
            padding: 1rem 0 !important;
        }

        .flatpickr-weekday {
            font-size: 1rem !important;
        }

        .flatpickr-days {
            padding: 0.8rem !important;
        }

        /* Larger touch targets for mobile */
        .flatpickr-day {
            height: 44px !important;
            line-height: 44px !important;
            max-width: 44px !important;
            font-size: 1.05rem !important;
            margin: 3px !important;
        }

        .flatpickr-prev-month,
        .flatpickr-next-month {
            padding: 0.8rem !important;
        }

        .flatpickr-prev-month svg,
        .flatpickr-next-month svg {
            width: 18px !important;
            height: 18px !important;
        }
    }

    /* Extra small screens */
    @media (max-width: 400px) {
        .flatpickr-calendar {
            width: 98vw !important;
        }

        .flatpickr-day {
            height: 40px !important;
            line-height: 40px !important;
            max-width: 40px !important;
            font-size: 1rem !important;
        }
    }