/* ==========================================================================
   DIGITAL OMR PRO — EXAM BLUE DESIGN SYSTEM (LIGHT & DARK THEMES)
   Zero external CSS frameworks required. 100% responsive & touch-optimized.
   ========================================================================== */

:root {
    /* Exam Blue Palette - Light Mode */
    --theme-mode: 'light';
    --bg-main: #f0f4fa;
    --bg-card: #ffffff;
    --bg-card-subtle: #f8fafc;
    --bg-hover: #e2e8f0;
    --border-color: #cbd5e1;
    --border-subtle: #e2e8f0;
    
    /* Academic Blue Ink Colors */
    --primary-blue: #1d4ed8;
    --primary-blue-hover: #1e40af;
    --primary-blue-light: #eff6ff;
    --primary-blue-glow: rgba(29, 78, 216, 0.18);
    --secondary-blue: #0284c7;

    /* Text Colors */
    --text-primary: #0f172a;
    --text-secondary: #475569;
    --text-muted: #64748b;
    --text-inverse: #ffffff;

    /* Performance Status Colors */
    --color-correct: #16a34a;
    --color-correct-bg: #f0fdf4;
    --color-correct-border: #bbf7d0;

    --color-wrong: #dc2626;
    --color-wrong-bg: #fef2f2;
    --color-wrong-border: #fecaca;

    --color-unattempted: #d97706;
    --color-unattempted-bg: #fffbeb;
    --color-unattempted-border: #fde68a;

    --color-multi: #9333ea;
    --color-multi-bg: #faf5ff;
    --color-multi-border: #e9d5ff;

    /* Bubble Styles */
    --bubble-border: #94a3b8;
    --bubble-bg: #ffffff;
    --bubble-text: #475569;
    --bubble-selected-bg: #1e3a8a;
    --bubble-selected-border: #1e3a8a;
    --bubble-selected-text: #ffffff;

    /* Elevation & Shadows */
    --shadow-sm: 0 1px 3px rgba(15, 23, 42, 0.06), 0 1px 2px rgba(15, 23, 42, 0.04);
    --shadow-md: 0 4px 6px -1px rgba(15, 23, 42, 0.08), 0 2px 4px -2px rgba(15, 23, 42, 0.05);
    --shadow-lg: 0 10px 15px -3px rgba(15, 23, 42, 0.08), 0 4px 6px -4px rgba(15, 23, 42, 0.04);
}

/* Dark Mode Theme */
[data-theme="dark"] {
    --theme-mode: 'dark';
    --bg-main: #0a0f1d;
    --bg-card: #111827;
    --bg-card-subtle: #1a2234;
    --bg-hover: #242e42;
    --border-color: #27354f;
    --border-subtle: #1e293b;

    /* Sapphire Glow Blue */
    --primary-blue: #3b82f6;
    --primary-blue-hover: #60a5fa;
    --primary-blue-light: rgba(59, 130, 246, 0.15);
    --primary-blue-glow: rgba(59, 130, 246, 0.35);
    --secondary-blue: #38bdf8;

    /* Text Colors */
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    --text-inverse: #0f172a;

    /* Performance Status Colors */
    --color-correct: #22c55e;
    --color-correct-bg: rgba(34, 197, 94, 0.12);
    --color-correct-border: rgba(34, 197, 94, 0.3);

    --color-wrong: #ef4444;
    --color-wrong-bg: rgba(239, 68, 68, 0.12);
    --color-wrong-border: rgba(239, 68, 68, 0.3);

    --color-unattempted: #f59e0b;
    --color-unattempted-bg: rgba(245, 158, 11, 0.12);
    --color-unattempted-border: rgba(245, 158, 11, 0.3);

    --color-multi: #a855f7;
    --color-multi-bg: rgba(168, 85, 247, 0.12);
    --color-multi-border: rgba(168, 85, 247, 0.3);

    /* Bubble Styles */
    --bubble-border: #334155;
    --bubble-bg: #111827;
    --bubble-text: #cbd5e1;
    --bubble-selected-bg: #2563eb;
    --bubble-selected-border: #60a5fa;
    --bubble-selected-text: #ffffff;

    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 10px 20px -3px rgba(0, 0, 0, 0.5);
}

/* ==========================================================================
   BASE & RESET
   ========================================================================== */

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

html, body {
    width: 100%;
    min-height: 100vh;
    font-family: 'Comfortaa', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    font-size: 16px;
    background-color: var(--bg-main);
    color: var(--text-primary);
    line-height: 1.6;
    touch-action: manipulation;
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
    overflow-x: hidden;
    transition: background-color 0.25s ease, color 0.25s ease;
}

/* Container */
.omr-app-wrapper {
    max-width: 1200px;
    margin: 0 auto;
    padding: 1rem 1rem 4rem 1rem;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

@media (min-width: 768px) {
    .omr-app-wrapper {
        padding: 1.5rem 2rem 5rem 2rem;
    }
}

/* ==========================================================================
   HEADER & TOP BAR
   ========================================================================== */

.omr-top-nav {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.nav-link-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    min-height: 44px;
    border-radius: 8px;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 0.8rem;
    font-weight: 700;
    white-space: nowrap;
    transition: all 0.2s ease;
    box-shadow: var(--shadow-sm);
}

.nav-link-btn:hover {
    color: var(--primary-blue);
    border-color: var(--primary-blue);
}

.nav-actions-group {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.theme-toggle-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    padding: 0.5rem 1rem;
    min-height: 44px;
    border-radius: 8px;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 0.8rem;
    font-weight: 700;
    white-space: nowrap;
    transition: all 0.2s ease;
    box-shadow: var(--shadow-sm);
}

.theme-toggle-btn:hover {
    border-color: var(--primary-blue);
    color: var(--primary-blue);
}

/* Main Card */
.omr-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    padding: 1.25rem;
    box-shadow: var(--shadow-md);
    transition: background-color 0.25s ease, border-color 0.25s ease;
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
    overflow-x: hidden;
}

/* Explicit Bold Typography for Comfortaa Titles & Action Elements */
h1, h2, h3, h4, h5, h6,
.hero-title-wrap h1,
.modal-title,
.config-label,
.stat-cell-title,
.history-title,
#sheetModeTitle,
.nav-link-btn,
.btn-primary,
.btn-secondary,
.btn-danger,
.hud-badge,
.filter-tab-btn,
.pill-btn,
.progress-header,
.q-num-box,
strong,
b {
    font-weight: 700 !important;
}

@media (min-width: 768px) {
    .omr-card {
        padding: 1.75rem;
        border-radius: 20px;
    }
}

/* Header Content */
.header-hero {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

@media (min-width: 768px) {
    .header-hero {
        flex-direction: row;
        align-items: center;
        justify-content: space-between;
    }
}

.hero-info-box {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.exam-seal-badge {
    width: 48px;
    height: 48px;
    min-width: 48px;
    border-radius: 12px;
    background: var(--primary-blue-light);
    color: var(--primary-blue);
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--primary-blue-glow);
}

.exam-seal-badge svg {
    width: 26px;
    height: 26px;
}

.hero-title-wrap h1 {
    font-size: 1.35rem;
    font-weight: 800;
    letter-spacing: -0.02em;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.mode-tag {
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    padding: 0.2rem 0.55rem;
    border-radius: 6px;
    background: var(--primary-blue);
    color: #ffffff;
    letter-spacing: 0.05em;
}

.hero-subtitle {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-top: 0.2rem;
}

/* Header Action Controls */
.header-meta-controls {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.timer-pill {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    background: var(--bg-card-subtle);
    border: 1px solid var(--border-color);
    padding: 0.5rem 1rem;
    border-radius: 10px;
    font-family: monospace;
    font-size: 1.15rem;
    font-weight: 700;
    color: var(--primary-blue);
    letter-spacing: 0.05em;
}

.timer-pill.timer-danger {
    color: var(--color-wrong);
    border-color: var(--color-wrong);
    background: var(--color-wrong-bg);
    animation: pulseTimer 1s infinite alternate;
}

@keyframes pulseTimer {
    0% { transform: scale(1); }
    100% { transform: scale(1.03); }
}

/* ==========================================================================
   CONFIG & SCHEME SELECTOR
   ========================================================================== */

.config-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1rem;
    margin-top: 1.25rem;
    padding-top: 1.25rem;
    border-top: 1px solid var(--border-subtle);
}

@media (min-width: 640px) {
    .config-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (min-width: 1024px) {
    .config-grid {
        grid-template-columns: 1.3fr 1fr 1fr 1fr;
    }
}

.config-item {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

.config-label {
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
}

.form-select, .form-input {
    width: 100%;
    padding: 0.65rem 0.85rem;
    border-radius: 10px;
    border: 1px solid var(--border-color);
    background: var(--bg-card);
    color: var(--text-primary);
    font-size: 0.88rem;
    font-weight: 500;
    outline: none;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.form-select:focus, .form-input:focus {
    border-color: var(--primary-blue);
    box-shadow: 0 0 0 3px var(--primary-blue-glow);
}

.button-group-pills {
    display: flex;
    background: var(--bg-card-subtle);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    padding: 3px;
    gap: 3px;
}

.pill-btn {
    flex: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.5rem 1rem;
    min-height: 44px;
    border: none;
    border-radius: 7px;
    background: transparent;
    color: var(--text-secondary);
    font-size: 0.8rem;
    font-weight: 700;
    cursor: pointer;
    text-align: center;
    white-space: nowrap;
    transition: all 0.15s ease;
}

.pill-btn.active {
    background: var(--primary-blue);
    color: #ffffff;
    box-shadow: var(--shadow-sm);
}

.pill-q-count {
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: var(--bg-card);
}

/* Custom Marking Controls */
.custom-marking-drawer {
    grid-column: 1 / -1;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 0.75rem;
    background: var(--bg-card-subtle);
    padding: 1rem;
    border-radius: 12px;
    border: 1px solid var(--border-color);
}

.custom-marking-drawer.hidden {
    display: none;
}

/* Start Button Bar */
.config-cta-bar {
    grid-column: 1 / -1;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    margin-top: 0.5rem;
}

@media (min-width: 640px) {
    .config-cta-bar {
        flex-direction: row;
        justify-content: flex-end;
    }
}

.btn-primary {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.75rem 1.5rem;
    min-height: 44px;
    border-radius: 12px;
    background: var(--primary-blue);
    color: #ffffff;
    font-size: 0.92rem;
    font-weight: 700;
    white-space: nowrap;
    border: none;
    cursor: pointer;
    box-shadow: 0 4px 12px var(--primary-blue-glow);
    transition: all 0.2s ease;
}

.btn-primary:hover {
    background: var(--primary-blue-hover);
    transform: translateY(-1px);
}

.btn-primary:active {
    transform: translateY(0);
}

.btn-secondary {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.75rem 1.5rem;
    min-height: 44px;
    border-radius: 12px;
    background: var(--bg-card-subtle);
    color: var(--text-secondary);
    font-size: 0.88rem;
    font-weight: 700;
    white-space: nowrap;
    border: 1px solid var(--border-color);
    cursor: pointer;
    transition: all 0.2s ease;
}

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

.btn-danger {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.75rem 1.5rem;
    min-height: 44px;
    border-radius: 12px;
    background: var(--color-wrong-bg);
    color: var(--color-wrong);
    font-size: 0.88rem;
    font-weight: 700;
    white-space: nowrap;
    border: 1px solid var(--color-wrong-border);
    cursor: pointer;
    transition: all 0.2s ease;
}

.btn-danger:hover {
    background: var(--color-wrong);
    color: #ffffff;
}

/* ==========================================================================
   ACTIVE TEST STICKY BAR (Mobile First)
   ========================================================================== */

.active-hud-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 14px;
    box-shadow: var(--shadow-sm);
    flex-wrap: wrap;
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
}

.hud-stat-group {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.85rem;
    flex-wrap: wrap;
    max-width: 100%;
}

.hud-badge {
    padding: 0.3rem 0.65rem;
    border-radius: 8px;
    font-weight: 700;
    font-size: 0.75rem;
    background: var(--primary-blue-light);
    color: var(--primary-blue);
    border: 1px solid var(--primary-blue-glow);
    white-space: nowrap;
}

.hud-badge.hud-badge-amber {
    background: var(--color-unattempted-bg);
    color: var(--color-unattempted);
    border-color: var(--color-unattempted-border);
}

/* Filter pills */
.bubble-filter-tabs {
    display: flex;
    gap: 0.4rem;
    flex-wrap: wrap;
}

.filter-tab-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.5rem 1rem;
    min-height: 44px;
    border-radius: 8px;
    font-size: 0.75rem;
    font-weight: 700;
    white-space: nowrap;
    background: var(--bg-card-subtle);
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.15s ease;
}

.filter-tab-btn.active {
    background: var(--primary-blue);
    color: #ffffff;
    border-color: var(--primary-blue);
}

/* ==========================================================================
   OMR SHEET BUBBLE GRID
   ========================================================================== */

.omr-grid-container {
    display: grid;
    grid-template-columns: 1fr;
    gap: 0.65rem;
    margin-top: 0.75rem;
}

@media (min-width: 640px) {
    .omr-grid-container {
        grid-template-columns: repeat(2, 1fr);
        gap: 0.85rem;
    }
}

@media (min-width: 1024px) {
    .omr-grid-container {
        grid-template-columns: repeat(3, 1fr);
        gap: 0.85rem;
    }
}

@media (min-width: 1200px) {
    .omr-grid-container {
        grid-template-columns: repeat(4, 1fr);
    }
}

/* Individual Question Row */
.omr-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.6rem 0.85rem;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    box-shadow: var(--shadow-sm);
    transition: border-color 0.15s ease, transform 0.1s ease;
}

.omr-row:hover {
    border-color: var(--primary-blue);
}

.omr-row.row-multi-fill {
    border-color: var(--color-multi);
    background: var(--color-multi-bg);
}

.q-num-box {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--text-muted);
    min-width: 44px;
    user-select: none;
}

.q-status-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--border-color);
}

.q-status-dot.filled {
    background: var(--primary-blue);
}

.q-status-dot.multi {
    background: var(--color-multi);
}

.bubbles-group {
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

@media (min-width: 400px) {
    .bubbles-group {
        gap: 0.55rem;
    }
}

/* The Bubble itself - Strict Mobile Touch standard: 38-44px fluid */
.bubble {
    width: clamp(38px, 9vw, 44px);
    height: clamp(38px, 9vw, 44px);
    min-width: 38px;
    min-height: 38px;
    border-radius: 50%;
    border: 2px solid var(--bubble-border);
    background: var(--bubble-bg);
    color: var(--bubble-text);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: clamp(0.78rem, 2.2vw, 0.88rem);
    font-weight: 700;
    cursor: pointer;
    user-select: none;
    transition: all 0.15s ease;
    touch-action: manipulation;
}

.bubble:hover {
    border-color: var(--primary-blue);
    transform: scale(1.05);
}

.bubble:active {
    transform: scale(0.95);
}

.bubble.selected {
    background: var(--bubble-selected-bg);
    border-color: var(--bubble-selected-border);
    color: var(--bubble-selected-text);
    box-shadow: 0 0 10px var(--primary-blue-glow);
}

/* Key Mode Bubbles (When editing Answer Key) */
.bubble.key-selected {
    background: var(--secondary-blue);
    border-color: var(--secondary-blue);
    color: #ffffff;
}

/* Result Mode Bubbles */
.bubble.result-correct {
    background: var(--color-correct) !important;
    border-color: var(--color-correct) !important;
    color: #ffffff !important;
    box-shadow: 0 0 8px rgba(34, 197, 94, 0.4);
}

.bubble.result-wrong {
    background: var(--color-wrong) !important;
    border-color: var(--color-wrong) !important;
    color: #ffffff !important;
    box-shadow: 0 0 8px rgba(239, 68, 68, 0.4);
}

.bubble.result-expected {
    background: transparent !important;
    border: 2px dashed var(--color-correct) !important;
    color: var(--color-correct) !important;
    font-weight: 900;
}

.bubble.result-multi {
    background: var(--color-multi) !important;
    border-color: var(--color-multi) !important;
    color: #ffffff !important;
}

.bubble.result-unfilled {
    opacity: 0.4;
}

/* ==========================================================================
   EVALUATION & RESULT SCORECARD
   ========================================================================== */

.score-hero-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 1.5rem;
    margin-bottom: 1.5rem;
}

.score-hero-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
    gap: 1rem;
    text-align: center;
}

.score-stat-cell {
    padding: 1rem;
    background: var(--bg-card-subtle);
    border-radius: 8px;
    border: 1px solid var(--border-subtle);
    box-shadow: var(--shadow-sm);
}

.stat-cell-title {
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    margin-bottom: 0.35rem;
    white-space: nowrap;
}

.stat-cell-value {
    font-size: 1.85rem;
    font-weight: 900;
    letter-spacing: -0.02em;
    line-height: 1.1;
    color: var(--text-primary);
}

.stat-cell-value.text-blue { color: var(--primary-blue); }
.stat-cell-value.text-green { color: var(--color-correct); }
.stat-cell-value.text-red { color: var(--color-wrong); }
.stat-cell-value.text-amber { color: var(--color-unattempted); }
.stat-cell-value.text-purple { color: var(--color-multi); }

.stat-cell-sub {
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--text-muted);
    margin-top: 0.35rem;
    white-space: nowrap;
}

/* Progress bar container */
.score-progress-wrap {
    margin-top: 1.25rem;
    padding: 1rem;
    background: var(--bg-card-subtle);
    border-radius: 8px;
    border: 1px solid var(--border-subtle);
}

.progress-header {
    display: flex;
    justify-content: space-between;
    font-size: 0.8rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
    color: var(--text-secondary);
}

.segmented-progress-bar {
    width: 100%;
    height: 14px;
    border-radius: 10px;
    background: var(--bg-card-subtle);
    display: flex;
    overflow: hidden;
    box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.1);
}

.bar-segment {
    height: 100%;
    transition: width 0.6s ease;
}

.bar-segment.correct { background: var(--color-correct); }
.bar-segment.wrong { background: var(--color-wrong); }
.bar-segment.multi { background: var(--color-multi); }
.bar-segment.blank { background: var(--color-unattempted); }

/* ==========================================================================
   QUESTION BY QUESTION AUDIT TABLE
   ========================================================================== */

.table-responsive-wrapper {
    width: 100%;
    overflow-x: auto;
    border-radius: 14px;
    border: 1px solid var(--border-color);
    background: var(--bg-card);
    box-shadow: var(--shadow-sm);
    margin-top: 1rem;
}

.audit-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.82rem;
    text-align: left;
}

.audit-table th {
    background: var(--bg-card-subtle);
    padding: 0.75rem 1rem;
    font-weight: 700;
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border-color);
    white-space: nowrap;
}

.audit-table td {
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--border-subtle);
    color: var(--text-primary);
    white-space: nowrap;
}

.audit-table tr:last-child td {
    border-bottom: none;
}

.audit-table tr:hover {
    background: var(--bg-card-subtle);
}

.badge-tag {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.25rem 0.55rem;
    border-radius: 6px;
    font-size: 0.72rem;
    font-weight: 700;
    white-space: nowrap;
}

.badge-tag.correct {
    background: var(--color-correct-bg);
    color: var(--color-correct);
    border: 1px solid var(--color-correct-border);
}

.badge-tag.wrong {
    background: var(--color-wrong-bg);
    color: var(--color-wrong);
    border: 1px solid var(--color-wrong-border);
}

.badge-tag.blank {
    background: var(--color-unattempted-bg);
    color: var(--color-unattempted);
    border: 1px solid var(--color-unattempted-border);
}

.badge-tag.multi {
    background: var(--color-multi-bg);
    color: var(--color-multi);
    border: 1px solid var(--color-multi-border);
}

.badge-tag.unkeyed {
    background: rgba(100, 116, 139, 0.12);
    color: #64748b;
    border: 1px solid rgba(100, 116, 139, 0.25);
}

/* Editing State & Incomplete Key Banners */
.editing-state-banner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    margin-bottom: 1.25rem;
    border-radius: 12px;
    background: rgba(2, 132, 199, 0.1);
    border: 1px solid rgba(2, 132, 199, 0.35);
    color: var(--text-primary);
    font-size: 0.82rem;
    font-weight: 600;
    flex-wrap: wrap;
}

.partial-key-alert-banner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.85rem;
    padding: 0.85rem 1.1rem;
    margin-bottom: 1.25rem;
    border-radius: 12px;
    background: rgba(245, 158, 11, 0.12);
    border: 1.5px solid rgba(245, 158, 11, 0.35);
    color: var(--text-primary);
    font-size: 0.82rem;
    flex-wrap: wrap;
}

/* ==========================================================================
   SAVED HISTORY CARDS
   ========================================================================== */

.history-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1rem;
}

@media (min-width: 640px) {
    .history-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

.history-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    padding: 1.25rem;
    box-shadow: var(--shadow-sm);
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    gap: 1rem;
    transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.history-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
    border-color: var(--primary-blue);
}

.history-card-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 0.75rem;
}

.history-title {
    font-size: 1.05rem;
    font-weight: 800;
    color: var(--text-primary);
}

.history-date {
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--text-muted);
}

.history-score-badge {
    text-align: right;
}

.history-score-num {
    font-size: 1.5rem;
    font-weight: 900;
    color: var(--primary-blue);
    line-height: 1;
}

.history-score-max {
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--text-muted);
}

.history-details-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 0.75rem;
    font-weight: 600;
    padding: 0.5rem 0;
    border-top: 1px solid var(--border-subtle);
    border-bottom: 1px solid var(--border-subtle);
    color: var(--text-secondary);
}

.history-card-actions {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    flex-wrap: wrap;
}

/* ==========================================================================
   MODALS
   ========================================================================== */

.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.6);
    backdrop-filter: blur(4px);
    z-index: 999;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}

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

.modal-dialog {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    width: 100%;
    max-width: 540px;
    padding: 1.5rem;
    box-shadow: var(--shadow-lg);
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
    animation: modalPop 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes modalPop {
    0% { transform: scale(0.95); opacity: 0; }
    100% { transform: scale(1); opacity: 1; }
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-title {
    font-size: 1.2rem;
    font-weight: 800;
    color: var(--text-primary);
}

.modal-close-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 1.2rem;
    cursor: pointer;
    padding: 0.25rem;
}

.modal-close-btn:hover {
    color: var(--text-primary);
}

.modal-body {
    display: flex;
    flex-direction: column;
    gap: 0.85rem;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 0.75rem;
}

/* Utilities */
.hidden {
    display: none !important;
}

/* Print Optimization */
@media print {
    body {
        background: #ffffff !important;
        color: #000000 !important;
    }
    .omr-top-nav, .config-cta-bar, .modal-backdrop, .theme-toggle-btn {
        display: none !important;
    }
    .omr-card {
        box-shadow: none !important;
        border: 1px solid #000000 !important;
    }
}

/* ==========================================================================
   TOAST NOTIFICATION SYSTEM (Iframe-Safe, High-DPI Accessible)
   ========================================================================== */
.toast-container {
    position: fixed;
    bottom: 1.5rem;
    right: 1.5rem;
    z-index: 10000;
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
    pointer-events: none;
    max-width: calc(100vw - 2rem);
}

.toast {
    pointer-events: auto;
    display: inline-flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1.25rem;
    border-radius: 12px;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-lg);
    font-size: 0.85rem;
    font-weight: 700 !important;
    color: var(--text-primary);
    animation: toastSlideUp 0.25s cubic-bezier(0.16, 1, 0.3, 1);
    transition: opacity 0.25s ease, transform 0.25s ease;
}

.toast.toast-success {
    border-color: var(--color-correct);
    background: var(--color-correct-bg);
    color: var(--color-correct);
}

.toast.toast-warning {
    border-color: var(--color-unattempted);
    background: var(--color-unattempted-bg);
    color: var(--color-unattempted);
}

.toast.toast-error {
    border-color: var(--color-wrong);
    background: var(--color-wrong-bg);
    color: var(--color-wrong);
}

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