:root {
    --bg-color: #0f172a;
    --card-bg: rgba(30, 41, 59, 0.7);
    --text-color: #f1f5f9;
    --text-muted: #94a3b8;
    --accent-color: #38bdf8;
    --accent-hover: #0ea5e9;
    --danger-color: #ef4444;
    --success-color: #22c55e;
    --border-color: rgba(255, 255, 255, 0.1);
    --header-height: 64px;
    --safe-area-bottom: env(safe-area-inset-bottom);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: 'Inter', -apple-system, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    line-height: 1.5;
    overflow-x: hidden;
    min-height: 100vh;
}

body.loading {
    overflow: hidden;
}

/* Glassmorphism Effect */
.glass {
    background: var(--card-bg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--border-color);
}

/* Loader */
.loader-container {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    justify-content: center;
    align-items: center;
    background: var(--bg-color);
    z-index: 1000;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 4px solid rgba(56, 189, 248, 0.1);
    border-top: 4px solid var(--accent-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% {
        transform: rotate(0deg);
    }

    100% {
        transform: rotate(360deg);
    }
}

/* Header */
header {
    position: sticky;
    top: 0;
    height: var(--header-height);
    display: flex;
    align-items: center;
    padding: 0 20px;
    z-index: 100;
    background: rgba(15, 23, 42, 0.8);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--border-color);
}

.header-content {
    display: flex;
    align-items: center;
    width: 100%;
    gap: 15px;
}

h1 {
    font-size: 1.25rem;
    font-weight: 700;
    flex-grow: 1;
}

.icon-btn {
    background: none;
    border: none;
    color: var(--text-color);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 8px;
    border-radius: 50%;
    transition: background 0.2s;
}

.icon-btn:active {
    background: rgba(255, 255, 255, 0.1);
}

/* Main Content */
main {
    padding: 20px;
    padding-bottom: 100px;
}

/* Quiz List Dashboard */
.quiz-grid {
    display: grid;
    gap: 16px;
}

.quiz-card {
    padding: 16px;
    border-radius: 16px;
    cursor: pointer;
    transition: transform 0.2s, background 0.2s;
}

.quiz-card:active {
    transform: scale(0.98);
}

.quiz-card h3 {
    font-size: 1.1rem;
    margin-bottom: 4px;
    overflow-wrap: break-word;
    word-wrap: break-word;
    word-break: break-word;
    hyphens: auto;
}

/* Validation Styles */
.input-group {
    position: relative;
    width: 100%;
}

.char-count {
    position: absolute;
    right: 8px;
    bottom: 8px;
    font-size: 0.7rem;
    color: var(--text-muted);
    background: rgba(0, 0, 0, 0.3);
    padding: 2px 4px;
    border-radius: 4px;
    pointer-events: none;
}

.input-error {
    border-color: var(--danger-color) !important;
}

.char-count.error {
    color: var(--danger-color);
    font-weight: bold;
}

.quiz-card p {
    font-size: 0.85rem;
    color: var(--text-muted);
}

/* Editor Controls */
.sticky-controls {
    position: sticky;
    top: calc(var(--header-height) + 10px);
    margin-bottom: 20px;
    z-index: 90;
}

.search-bar input {
    width: 100%;
    padding: 12px 16px;
    border-radius: 12px;
    border: 1px solid var(--border-color);
    background: rgba(30, 41, 59, 0.9);
    color: var(--text-color);
    font-size: 1rem;
    outline: none;
    transition: border-color 0.2s;
}

.search-bar input:focus {
    border-color: var(--accent-color);
}

/* Questions List */
.questions-list {
    display: grid;
    gap: 24px;
}

.question-item {
    padding: 20px;
    border-radius: 16px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.q-label {
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--accent-color);
}

textarea,
input[type="text"].option-input {
    width: 100%;
    background: rgba(15, 23, 42, 0.4);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    color: var(--text-color);
    padding: 10px;
    padding-right: 45px;
    /* Space for char counter */
    font-family: inherit;
    font-size: 0.95rem;
    outline: none;
}

textarea {
    min-height: 80px;
    resize: vertical;
}

.options-grid {
    display: grid;
    gap: 10px;
}

.option-row {
    display: flex;
    align-items: center;
    gap: 10px;
}

.option-row .indicator {
    width: 24px;
    height: 24px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.8rem;
    font-weight: 700;
    flex-shrink: 0;
}

.option-row.correct .indicator {
    background: var(--success-color);
    color: white;
}

.option-row.wrong .indicator {
    background: var(--danger-color);
    color: white;
}

/* Footer Actions */
.footer-actions {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 16px 20px calc(16px + var(--safe-area-bottom));
    background: rgba(15, 23, 42, 0.9);
    backdrop-filter: blur(10px);
    border-top: 1px solid var(--border-color);
    z-index: 200;
}

.primary-btn {
    width: 100%;
    padding: 14px;
    border-radius: 12px;
    border: none;
    background: var(--accent-color);
    color: #fff;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s, transform 0.1s;
}

.primary-btn:active {
    transform: scale(0.98);
    background: var(--accent-hover);
}

/* Empty States */
.empty-state {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-muted);
}

@keyframes pulse-border {
    0% {
        border-color: var(--accent-color);
        box-shadow: 0 0 0 0 rgba(56, 189, 248, 0.7);
    }

    70% {
        border-color: var(--accent-color);
        box-shadow: 0 0 0 10px rgba(56, 189, 248, 0);
    }

    100% {
        border-color: var(--border-color);
        box-shadow: 0 0 0 0 rgba(56, 189, 248, 0);
    }
}

.highlight-pulse {
    animation: pulse-border 2s infinite;
    border-color: var(--accent-color);
}

/* Desktop Responsiveness */
@media (min-width: 768px) {
    body {
        background-color: #0f172a;
        /* Ensure dark bg on sides */
    }

    #app {
        max-width: 800px;
        margin: 0 auto;
        border-left: 1px solid var(--border-color);
        border-right: 1px solid var(--border-color);
        min-height: 100vh;
        background-color: var(--bg-color);
        position: relative;
    }

    /* Fix fixed elements width on desktop */
    header {
        max-width: 800px;
        margin: 0 auto;
        left: 0;
        right: 0;
    }

    .footer-actions {
        max-width: 800px;
        margin: 0 auto;
        left: 0;
        right: 0;
        border-left: 1px solid var(--border-color);
        border-right: 1px solid var(--border-color);
    }

    .loader-container {
        max-width: 800px;
        margin: 0 auto;
        left: 0;
        right: 0;
    }
}