/* ================= BASE ================= */
html, body {
    margin: 0;
    padding: 0;
    height: 100%;
    overflow-x: hidden;
}

body {
    font-family: 'Inter', 'Segoe UI', sans-serif;
    background: linear-gradient(135deg, #e0eafc, #cfdef3);
    font-size: 16px;
    line-height: 1.5;
}

/* ================= ROOT APP WRAPPER ================= */
#quiz-app {
    width: 100%;
    max-width: 100%;
    margin: 0 auto;
    padding: 10px;
    box-sizing: border-box;
    position: relative;
    overflow-x: hidden;
}

/* Force #quiz to control width and alignment */
#quiz {
    width: 100%;
    max-width: 100%;
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    align-items: stretch;
}

/* ================= PREMIUM TOP BAR ================= */
.header {
    position: relative;
    z-index: 999;
    background: transparent;
    width: 100%;
    box-sizing: border-box;
    padding: 0;
}

.top-bar {
    position: sticky;
    top: 0;
    z-index: 999;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: rgba(255, 255, 255, 0.92);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    background: rgba(255, 255, 255, 0.95);
    padding: 12px 10px;
    border-bottom: 1px solid rgba(229, 231, 235, 0.6);
    border-radius: 25px 25px 25px 25px;
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.05);
    transition: all 0.2s ease;
    min-height: 56px;
    box-sizing: border-box;
    margin: 0;
    width: 100%;
    margin: 0;
    border-radius: 0;
}

.top-bar * {
    box-sizing: border-box;
}

.top-left {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

#chapter-name {
    font-size: 15px;
    font-weight: 700;
    color: #111827;
}

#level-name {
    font-size: 12px;
    color: #6b7280;
}

.top-center {
    width: 35%;
    text-align: center;
}

.progress-wrap {
    width: 100%;
    height: 6px;
    background: #e5e7eb;
    border-radius: 999px;
    overflow: hidden;
}

#progress-bar {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, #22c55e, #16a34a);
    transition: width 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

#progress-text {
    font-size: 11px;
    margin-top: 4px;
    color: #374151;
}

.top-right {
    background: #fee2e2;
    color: #b91c1c;
    padding: 6px 14px;
    border-radius: 999px;
    font-weight: 700;
    font-size: 13px;
    transition: all 0.2s;
}

.top-right.warning {
    background: #ef4444;
    color: white;
    animation: pulse 1s infinite;
}

@keyframes pulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.05); }
    100% { transform: scale(1); }
}

/* ================= MAIN ================= */
.main {
    display: flex;
    gap: 10px;
    align-items: flex-start;
    margin-top: 24px;
    width: 100%;
    box-sizing: border-box;
    padding: 0 10px;
}

/* ================= QUIZ CONTAINER - WIDE ================= */
.quiz-container {
    flex: 3.2;
    min-width: 0;
    max-width: none;
    background: white;
    padding: 24px;
    border-radius: 20px;
    box-shadow: 0 15px 35px rgba(0,0,0,0.1);
    transition: 0.3s;
    scroll-margin-top: 80px;
}

.quiz-container.fade {
    animation: fadeIn 0.25s ease;
}

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

/* ================= SIDEBAR - FIXED WIDTH ================= */
.sidebar {
    flex: 1;
    min-width: 280px;
    max-width: 360px;
    background: #ffffff;
    padding: 20px;
    border-radius: 18px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.08);
    position: sticky;
    top: 80px;
}

/* ================= QUESTION ================= */
#question {
    font-size: 22px;
    font-weight: 700;
    margin-bottom: 25px;
    line-height: 1.3;
}

/* ================= OPTIONS ================= */
.option {
    padding: 14px;
    margin: 12px 0;
    border-radius: 12px;
    background: #f8fafc;
    border: 1px solid #e5e7eb;
    cursor: pointer;
    transition: all 0.25s ease;
    position: relative;
    font-size: 16px;
    line-height: 1.4;
}

.option:hover {
    background: #eef2ff;
    border-color: #4f46e5;
}

.option.selected {
    background: #e0e7ff;
    border: 2px solid #4f46e5;
    font-weight: 600;
}

.option.selected::after {
    content: "✔";
    position: absolute;
    right: 12px;
    font-size: 14px;
    color: #4f46e5;
    font-weight: bold;
}

.option:active {
    transform: scale(0.98);
}

/* ================= ACTION BUTTONS ================= */
.exam-actions {
    display: flex;
    gap: 12px;
    margin-top: 25px;
}

.exam-actions button {
    flex: 1;
    padding: 14px;
    border-radius: 12px;
    border: none;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.25s ease;
    font-size: 14px;
}

.exam-actions button:nth-child(1) {
    background: linear-gradient(135deg, #10b981, #059669);
    color: white;
}

.exam-actions button:nth-child(2) {
    background: linear-gradient(135deg, #f59e0b, #d97706);
    color: white;
}

.exam-actions button:nth-child(3) {
    background: linear-gradient(135deg, #6b7280, #4b5563);
    color: white;
}

.exam-actions button:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 20px rgba(0,0,0,0.15);
}



/* ================= SUBMIT ================= */
.submit-btn {
    width: 100%;
    padding: 16px;
    margin-top: 25px;
    background: linear-gradient(135deg, #ef4444, #dc2626);
    color: white;
    border: none;
    border-radius: 14px;
    font-size: 17px;
    font-weight: bold;
    cursor: pointer;
    transition: 0.3s;
}

.submit-btn:hover {
    transform: scale(1.03);
    box-shadow: 0 10px 25px rgba(239,68,68,0.4);
}

.submit-btn:active {
    transform: scale(0.96);
}

/* ================= SIDEBAR LEVELS ================= */
.side-level {
    background: #3b82f6;
    color: white;
    padding: 12px;
    border-radius: 12px;
    margin-bottom: 10px;
    cursor: pointer;
    display: flex;
    align-items: center;
    font-size: 14px;
}

.side-level .lvl-title::after {
    content: "|";
    margin: 0 10px;
    opacity: 0.7;
}

.side-level .lvl-sub:empty {
    display: none;
}

.side-level.active {
    background: #facc15;
    color: black;
}

/* ================= QUESTION GRID (PALETTE) ================= */
#question-grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 8px;
    margin-top: 15px;
    width: 100%;
    box-sizing: border-box;
}

.q-box {
    width: 100%;
    aspect-ratio: 1;
    max-width: 44px;
    border-radius: 50%;
    border: 2px solid #ef4444;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    background: white;
    transition: all 0.2s ease;
    font-weight: 500;
    font-size: 13px;
    box-sizing: border-box;
    margin: 0 auto;
}

.q-box:hover {
    transform: scale(1.1);
}

.q-box:active {
    transform: scale(0.9);
}

.q-box.answered {
    border-color: #22c55e;
    background: #dcfce7;
    color: #166534;
}

.q-box.not-answered,
.q-box.not-visited {
    background: #fee2e2;
    border-color: #ef4444;
    color: #991b1b;
}

.q-box.review {
    background: #f3e8ff;
    border-color: #9333ea;
    color: #4c1d95;
}

.q-box.answered-review {
    background: #fef08a;
    border-color: #eab308;
    color: #854d0e;
}

.q-box.active {
    background: #2563eb;
    color: white;
    border-color: #2563eb;
    transform: scale(1.05);
    font-weight: bold;
    box-shadow: 0 0 0 2px #2563eb inset;
}

/* ================= LEGEND ================= */
.quiz-legend {
    margin-top: 16px;
    display: flex;
    flex-wrap: wrap;
    gap: 8px 12px;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 12px;
    color: #374151;
    white-space: nowrap;
}

.legend-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    flex-shrink: 0;
    border: 2px solid transparent;
}

.legend-dot.answered     { background: #dcfce7; border-color: #22c55e; }
.legend-dot.not-answered { background: #fee2e2; border-color: #ef4444; }
.legend-dot.marked       { background: #f3e8ff; border-color: #9333ea; }
.legend-dot.ans-marked   { background: #fef08a; border-color: #eab308; }

.result-card {
    padding: 15px;
    margin: 10px 0;
    border-radius: 10px;
}

.correct { background: #d4edda; }
.wrong { background: #f8d7da; }
.skipped { background: #fff3cd; }

/* ================= LEVEL SELECTION GRID ================= */
#level-buttons {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 15px;
    margin-top: 10px;
    padding: 10px;
}

.level-card {
    background: #e5e7eb;
    padding: 20px;
    border-radius: 12px;
    cursor: pointer;
    transition: 0.3s;
    text-align: left;
}

.level-card:hover {
    transform: translateY(-3px);
    background: #dbeafe;
}

.level-title {
    font-size: 18px;
    font-weight: 700;
    margin-bottom: 5px;
}

.level-sub {
    font-size: 16px;
    font-weight: 500;
    color: #555;
}

.level-card:nth-child(1) {
    background: #fde68a;
}

.level-card:nth-child(2),
.level-card:nth-child(3),
.level-card:nth-child(4) {
    background: #3b82f6;
    color: white;
}

.level-card:nth-child(2) .level-sub,
.level-card:nth-child(3) .level-sub,
.level-card:nth-child(4) .level-sub {
    color: #e0e7ff;
}

#level-selection {
    margin: 20px;
}

/* ================= POPUP ================= */
.popup {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
}

.popup-box {
    background: white;
    padding: 30px;
    border-radius: 16px;
    text-align: center;
    max-width: 360px;
    width: 90%;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.2);
}

.popup-box h3 {
    margin-top: 0;
    margin-bottom: 10px;
    font-size: 20px;
    color: #111827;
}

.popup-box p {
    color: #6b7280;
    margin-bottom: 20px;
}

.popup-box button {
    padding: 10px 20px;
    margin: 5px;
    border-radius: 10px;
    border: none;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

.popup-box button:nth-child(1) {
    background: #ef4444;
    color: white;
}

.popup-box button:nth-child(2) {
    background: #e5e7eb;
    color: #111827;
}

.popup-box button:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}

/* ================= PREMIUM UX FEEDBACK ================= */
button:active {
    transform: scale(0.97);
}

button:focus {
    outline: 2px solid #2563eb;
    outline-offset: 2px;
}

.flash {
    animation: flashEffect 0.3s ease;
}

@keyframes flashEffect {
    0% { transform: scale(1); }
    50% { transform: scale(1.2); background: #93c5fd; }
    100% { transform: scale(1); }
}

button[data-tip] {
    position: relative;
}

button[data-tip]:hover::before {
    content: attr(data-tip);
    position: absolute;
    top: -28px;
    left: 50%;
    transform: translateX(-50%);
    background: #111;
    color: white;
    font-size: 11px;
    padding: 4px 8px;
    border-radius: 4px;
    white-space: nowrap;
}

/* ================= RESPONSIVE TABLES – NO OVERFLOW ================= */
/* Containers that may hold tables get horizontal scroll if needed */
.quiz-container,
.sidebar,
.result-card,
.level-selection,
#quiz .results-area,
[class*="result"] {
    overflow-x: auto;
    max-width: 100%;
    -webkit-overflow-scrolling: touch;
}

/* Base table styles – clean, readable, and safe */
table {
    width: 100%;
    border-collapse: collapse;
    margin: 1em 0;
    font-size: 0.95rem;
    background: #fff;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}

th, td {
    padding: 10px 12px;
    text-align: left;
    border-bottom: 1px solid #e2e8f0;
    word-break: break-word;
}

th {
    background: #f8fafc;
    font-weight: 600;
    color: #0f172a;
}

/* Make tables readable on small devices */
@media (max-width: 768px) {
    table, th, td {
        font-size: 13px;
    }
    th, td {
        padding: 8px 6px;
    }
}

@media (max-width: 480px) {
    table, th, td {
        font-size: 12px;
    }
    th, td {
        padding: 6px 4px;
    }
    /* Slightly reduce spacing for very narrow screens */
    table {
        margin: 0.75em 0;
    }
}

/* ================= RESPONSIVE (TABLET) ================= */
@media (max-width: 992px) {
    .main {
        flex-wrap: wrap;
        margin-top: 16px;
        gap: 16px;
        padding: 0;
    }

    .header {
        padding: 0;
    }

    .top-bar {
        width: 100%;
        margin: 0;
        padding: 0;
        border-radius: 20px 20px 20px 20px;
    }

    .quiz-container {
        flex: auto;
        width: 100%;
        min-width: auto;
    }

    .sidebar {
        max-width: 100%;
        width: 100%;
        position: relative;
        top: 0;
        margin-top: 20px;
    }

    .exam-actions {
        flex-direction: column;
    }

    .q-box {
        width: 35px;
        height: 35px;
    }
}

/* ================= RESPONSIVE (MOBILE) - PREMIUM APP STYLE ================= */
@media (max-width: 576px) {
    /* Remove outer padding to maximize screen usage */
    #quiz-app {
        padding: 0;
    }

    .header {
        padding: 0 !important;
    }

    .main {
        padding: 0 12px !important;
        margin-top: 12px;
        gap: 16px;
    }

    /* ===== OPTIMIZED TOP BAR FOR MOBILE ===== */
    .top-bar {
        width: 100% !important;
        margin: 0 !important;
        border-radius: 20px 20px 20px 20px;
        padding: 10px 16px !important;
        position: sticky;
        top: 0;
        flex-wrap: wrap;
        gap: 8px;
        background: rgba(255, 255, 255, 0.98);
        backdrop-filter: blur(20px);
        -webkit-backdrop-filter: blur(20px);
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
    }

    /* Left section - chapter and level */
    .top-left {
        flex: 1;
        gap: 4px;
    }

    #chapter-name {
        font-size: 14px;
        font-weight: 700;
        line-height: 1.3;
    }

    #level-name {
        font-size: 11px;
        opacity: 0.8;
    }

    /* Center section - progress (moved below on wrap) */
    .top-center {
        width: 100%;
        order: 3;
        margin-top: 4px;
    }

    .progress-wrap {
        height: 5px;
        background: #e2e8f0;
    }

    #progress-text {
        font-size: 10px;
        margin-top: 3px;
        color: #475569;
    }

    /* Right section - question counter */
    .top-right {
        font-size: 12px;
        padding: 4px 12px;
        background: #fee2e2;
        border-radius: 40px;
        font-weight: 600;
        white-space: nowrap;
    }

    /* Ensure sticky works smoothly */
    .top-bar {
        transition: all 0.2s ease;
    }

    /* Optional: add a subtle border when scrolled (via JS or just keep it clean) */
    .top-bar.scrolled {
        background: rgba(255, 255, 255, 0.98);
        box-shadow: 0 8px 20px rgba(0, 0, 0, 0.08);
    }

    /* Quiz container - full width, no extra margins */
    .quiz-container {
        width: 100%;
        padding: 20px 16px;
        border-radius: 20px;
        margin: 0;
        box-sizing: border-box;
    }

    /* Sidebar - full width, fits perfectly */
    .sidebar {
        width: 100%;
        max-width: 100%;
        min-width: auto;
        padding: 18px 16px;
        margin: 0;
        border-radius: 20px;
        position: relative;
        top: 0;
        box-sizing: border-box;
    }

    /* Fluid typography */
    body {
        font-size: clamp(14px, 4vw, 16px);
    }

    #question {
        font-size: clamp(18px, 6vw, 22px);
        margin-bottom: 18px;
    }

    .option {
        font-size: clamp(14px, 4.5vw, 16px);
        padding: 12px 14px;
        margin: 10px 0;
    }

    .exam-actions {
        flex-direction: column;
        gap: 10px;
    }

    .exam-actions button {
        font-size: clamp(13px, 4vw, 14px);
        padding: 12px;
    }

    .exam-actions button::after {
        font-size: 10px;
    }

    .submit-btn {
        font-size: clamp(15px, 5vw, 17px);
        padding: 14px;
    }

    .top-left #chapter-name {
        font-size: clamp(13px, 4vw, 15px);
    }

    .top-left #level-name {
        font-size: clamp(10px, 3.5vw, 12px);
    }

    .top-right {
        font-size: clamp(11px, 3.8vw, 13px);
        padding: 5px 12px;
    }

    .side-level {
        font-size: clamp(12px, 4vw, 14px);
        padding: 10px;
    }

    .legend-item {
        font-size: clamp(10px, 3.5vw, 12px);
    }

    /* Question grid: adjust size and spacing for mobile */
    #question-grid {
        gap: 6px;
    }

    .q-box {
        font-size: clamp(11px, 3.8vw, 13px);
        max-width: 38px;
        width: 100%;
    }

    /* Level selection grid: single column, better touch */
    #level-buttons {
        grid-template-columns: 1fr;
        gap: 12px;
        padding: 0;
    }

    .level-card {
        padding: 16px;
    }

    .level-title {
        font-size: clamp(15px, 5vw, 18px);
    }

    .level-sub {
        font-size: clamp(13px, 4.5vw, 16px);
    }

    /* Popup adjustments */
    .popup-box {
        padding: 24px;
        width: 85%;
    }

    .popup-box h3 {
        font-size: clamp(18px, 5vw, 20px);
    }

    .popup-box p {
        font-size: clamp(13px, 4vw, 14px);
    }

    .popup-box button {
        font-size: clamp(13px, 4vw, 14px);
        padding: 8px 16px;
    }

    /* Fix any hidden overflow */
    .quiz-container,
    .sidebar,
    .main,
    .top-bar {
        overflow-x: hidden;
    }
}

/* ================= WORDPRESS WPAUTOP FIX ================= */
#quiz p,
#quiz br,
#quiz-app > p,
#quiz-app > br,
.top-bar > p,
.top-bar > br,
.main > p,
.main > br,
.quiz-container > p,
.quiz-container > br,
.header > p,
.header > br,
.exam-actions br {
    display: none !important;
    margin: 0 !important;
    padding: 0 !important;
    height: 0 !important;
    width: 0 !important;
    line-height: 0 !important;
    font-size: 0 !important;
}

.header,
.top-bar,
.main,
#quiz-app,
#quiz {
    box-sizing: border-box;
}