:root {
    --blue: #2563eb;
    --blue-light: #bfdbfe;
    --green: #22c55e;
    --red: #ef4444;
    --yellow: #fbbf24;
    --gray: #e5e7eb;
    --bg: #ffffff;
    --text: #111827;
    --muted: #4b5563;
}

/* =====================================================
   BASE LAYOUT
   ===================================================== */
.stdy-quiz-shell {
    margin: 1.5rem 0;
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    color: var(--text);
}

.stdy-layout {
    display: flex;
    gap: 16px;
    max-width: 1000px;
    margin: 0 auto;
    align-items: flex-start;
}

.stdy-main {
    flex: 1 1 auto;
    min-width: 0;
}

/* =====================================================
   QUESTION CARD
   ===================================================== */
.stdy-card {
    background: var(--bg);
    border: 1px solid var(--blue);
    border-radius: 8px;
    padding: 16px;
    box-shadow: 0 1px 2px rgba(15,23,42,0.06);
}

.stdy-question {
    margin-bottom: 10px;
}

.stdy-options {
    margin-bottom: 12px;
}

.stdy-opt {
    border: 1px solid var(--blue);
    padding: 8px 10px;
    border-radius: 6px;
    margin-bottom: 8px;
    display: block;
    cursor: pointer;
}

.stdy-opt:hover {
    background: #eff6ff;
}

.stdy-opt.is-correct {
    background: #dcfce7;
    border-color: var(--green);
}

.stdy-opt.is-wrong {
    background: #fee2e2;
    border-color: var(--red);
}

/* =====================================================
   BUTTONS & ACTIONS
   ===================================================== */
.stdy-btn {
    padding: 8px 14px;
    border-radius: 6px;
    border: 1px solid #d1d5db;
    background: #e8f5e9;
    border-color: #81c784;
    color: #2e7d32;
    cursor: pointer;
    font-size: 14px;
}

.stdy-btn-primary {
    background: var(--blue);
    border-color: var(--blue);
    color: #fff;
}

.stdy-btn:disabled {
    opacity: .6;
    cursor: not-allowed;
}

.study-quiz-btn {
    width: auto;
    min-width: 180px;
    padding: 12px 28px;
    font-size: 16px;
    border-radius: 8px;
    background: var(--blue);
    color: #fff;
    border: none;
    cursor: pointer;
    display: inline-block;
    margin: 20px auto 0;
}

.study-quiz-btn:hover {
    background: #1d4ed8;
}

/* =====================================================
   SIDE PANEL
   ===================================================== */
.ssc-side {
    width: 240px;
    flex-shrink: 0;
    border-left: 1px solid var(--gray);
    padding-left: 12px;
    font-size: 14px;
}

.ssc-mark-toggle-btn {
    background: #fde68a;
    border-color: var(--yellow);
    color: #92400e;
}

.ssc-mark-toggle-btn.is-marked {
    background: #fef3c7;
    opacity: 0.7;
}

.ssc-qno,
.ssc-timer,
.ssc-count,
.ssc-part-title {
    font-weight: 600;
    margin-bottom: 6px;
}

.ssc-timer {
    color: #b91c1c;
}

/* =====================================================
   QUESTION GRID
   ===================================================== */
.ssc-grid {
    display: grid !important;
    grid-template-columns: repeat(auto-fit, minmax(32px, 32px)) !important;
    gap: 8px !important;
    padding: 6px !important;
    justify-content: flex-start !important;
    align-items: start !important;
}

.ssc-grid .ssc-q-btn {
    all: unset;
    width: 32px !important;
    height: 32px !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    border-radius: 5px !important;
    font-size: 12px !important;
    font-weight: 600 !important;
    cursor: pointer !important;
    box-sizing: border-box !important;
    line-height: 1 !important;
    position: relative;
}

.ssc-grid .ssc-q-btn.not-visited { background: var(--blue) !important; color: #fff !important; }
.ssc-grid .ssc-q-btn.answered { background: var(--green) !important; color: #fff !important; }
.ssc-grid .ssc-q-btn.answered-marked { background: var(--yellow) !important; color: #000 !important; }
.ssc-grid .ssc-q-btn.marked { background: var(--red) !important; color: #fff !important; }

.ssc-grid .ssc-q-btn .dot {
    position: absolute !important;
    bottom: 3px !important;
    right: 3px !important;
    width: 6px !important;
    height: 6px !important;
    border-radius: 50% !important;
    background: #000 !important;
}

/* =====================================================
   TOP BAR
   ===================================================== */
.ssc-topbar {
    display: flex !important;
    flex-direction: column !important;
    gap: 10px !important;
    margin-bottom: 8px;
}

.ssc-topbar .ssc-parts {
    display: flex !important;
    flex-wrap: wrap !important;
    justify-content: flex-start !important;
    gap: 8px !important;
    overflow: visible !important;
}

.ssc-topbar .ssc-part-btn {
    flex: 0 0 auto !important;
    width: auto !important;
    padding: 8px 12px !important;
    font-size: 14px !important;
    border-radius: 8px !important;
    white-space: nowrap !important;
    cursor: pointer;
}

.ssc-part-btn.active,
.ssc-part-btn.is-active {
    background: var(--green);
    border-color: var(--green);
    color: #fff;
}

.ssc-topbar .ssc-actions {
    display: flex !important;
    justify-content: flex-end !important;
    gap: 8px !important;
    flex-wrap: wrap !important;
}

/* =====================================================
   TABLES
   ===================================================== */
.ssc-analysis,
.ssc-modal-table,
.ssc-result-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 8px;
}

.ssc-analysis td,
.ssc-modal-table td,
.ssc-result-table th,
.ssc-result-table td {
    border: 1px solid #e5e7eb;
    padding: 4px 6px;
}

.ssc-modal-table td {
    padding: 6px 8px;
}

.ssc-result-table th,
.ssc-result-table td {
    padding: 8px;
    text-align: center;
}

.ssc-result-table th {
    background: #eef4ff;
}

.ssc-start-table {
    width: auto;
    min-width: 300px;
    margin-bottom: 15px;
    border-collapse: collapse;
    font-size: 14px;
}

.ssc-start-table th,
.ssc-start-table td {
    white-space: nowrap;
    padding: 8px 16px;
    border: 1px solid #e5e7eb;
    text-align: center;
}

.ssc-start-table th {
    background: #eef4ff;
}

/* =====================================================
   MODAL & SUBMIT
   ===================================================== */
.ssc-final-submit-wrap {
    margin-top: 10px;
    text-align: center;
}

.ssc-modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.45);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
}

.ssc-modal {
    background: #fff;
    width: 90%;
    max-width: 380px;
    border-radius: 10px;
    padding: 18px;
    box-shadow: 0 10px 25px rgba(0,0,0,0.2);
}

.ssc-modal-actions {
    display: flex;
    gap: 10px;
    justify-content: center;
}

/* =====================================================
   RESULTS
   ===================================================== */
.ssc-result-sheet {
    max-width: 900px;
    margin: auto;
}

.ssc-score-card {
    background: var(--blue);
    color: #fff;
    padding: 20px;
    border-radius: 12px;
    text-align: center;
    margin-bottom: 14px;
}

.ssc-score {
    font-size: 36px;
    font-weight: 700;
}

.ssc-score-label {
    font-size: 14px;
    opacity: 0.9;
}

.ssc-result-grid,
.stdy-summary-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: 10px;
    margin-bottom: 14px;
}

.ssc-card {
    background: #fff;
    border-radius: 10px;
    padding: 12px;
    text-align: center;
    border: 1px solid #e5e7eb;
}

.ssc-card strong {
    display: block;
    font-size: 20px;
}

.ssc-card span {
    font-size: 13px;
    color: #555;
}

.ssc-marks-box {
    background: #f8fafc;
    padding: 12px;
    border-radius: 10px;
    margin-bottom: 16px;
}

.ssc-result-actions {
    text-align: center;
    margin-top: 16px;
}

/* =====================================================
   REVIEW & EXPLANATIONS
   ===================================================== */
.stdy-review-item {
    border: 1px solid #ddd;
    padding: 14px;
    margin-bottom: 12px;
    border-radius: 6px;
}

.stdy-answer-correct { color: #28a745; font-weight: 600; }
.stdy-answer-wrong { color: #dc3545; font-weight: 600; }
.stdy-answer-skipped { color: #6c757d; }

.stdy-explain-toggle {
    margin-top: 8px;
    background: #fafaff;
    padding: 10px 12px;
    border-radius: 5px;
    border-left: 3px solid #0d6efd;
}

.stdy-explain-toggle summary {
    cursor: pointer;
    margin-top: 10px;
    padding: 6px 0;
    list-style: none;
}

.stdy-explain-toggle summary::-webkit-details-marker { 
    display: none; 
}

.stdy-explain-toggle summary strong {
    font-weight: 600;
    color: #0d6efd;
}

.stdy-explain-toggle summary:hover strong {
    text-decoration: underline;
}

.stdy-explain-box {
    margin-top: 8px;
    padding-top: 6px;
    line-height: 1.6;
    color: #333;
}

.stdy-explain-toggle[open] summary strong::after {
    content: " (Hide)";
    font-weight: normal;
    color: #6c757d;
}

/* =====================================================
   START SCREEN
   ===================================================== */
.study-quiz-start {
    padding: 12px;
    max-width: 550px;
    margin: auto;
}

.ssc-info-list {
    padding-left: 18px;
}



/* =====================================================
   UTILITIES
   ===================================================== */
.no-adsense, .no-adsense * { 
    max-height: none !important; 
}

.no-adsense ins, 
.no-adsense iframe, 
.no-adsense .adsbygoogle { 
    display: none !important; 
}

/* =====================================================
   RESPONSIVE
   ===================================================== */
@media (max-width: 768px) {
    .stdy-layout { 
        flex-direction: column; 
    }
    
    .ssc-side {
        width: 100%;
        border-left: none;
        border-top: 1px solid var(--gray);
        padding-left: 0;
        padding-top: 10px;
        margin-top: 10px;
    }
}

@media (max-width: 600px) {
    .stdy-card {
        overflow-x: auto;
    }
    
    .ssc-start-table {
        min-width: 480px;
    }
}

@media (max-width: 480px) {
    .ssc-grid {
        grid-template-columns: repeat(auto-fit, minmax(36px, 36px)) !important;
    }
    
    .ssc-grid .ssc-q-btn {
        width: 36px !important;
        height: 36px !important;
        font-size: 13px !important;
    }
    
    .ssc-topbar .ssc-part-btn {
        font-size: 12px !important;
        padding: 6px 8px !important;
    }
    
    .ssc-topbar .stdy-btn {
        font-size: 13px !important;
        padding: 6px 10px !important;
    }
    
    .study-quiz-btn {
        min-width: 160px;
        padding: 10px 24px;
        font-size: 15px;
    }
    
    .stdy-summary-grid,
    .ssc-result-grid {
        grid-template-columns: 1fr;
    }
    
    .stdy-card {
        padding: 14px;
        border-radius: 10px;
    }
    
    .stdy-card h3 {
        font-size: 17px;
    }
    
    .stdy-summary-grid strong {
        font-size: 16px;
    }
    
    .stdy-summary-grid span {
        font-size: 12px;
    }
    
    .study-quiz-btn {
        width: 100%;
        padding: 14px 0;
        font-size: 16px;
    }
}

/* =====================================================
   COMPACT QUIZ START SCREEN - FIXED VERSION
   ===================================================== */
.study-quiz-start {
    padding: 20px;
    max-width: 900px;
    margin: 0 auto;
    background: linear-gradient(135deg, #f8fafc 0%, #f1f5f9 100%);
    border-radius: 16px;
}

.stdy-start-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 16px; /* Reduced from 20px */
}

/* ---------- CARD DESIGN ---------- */
.stdy-card {
    background: white;
    border-radius: 12px;
    padding: 20px; /* Reduced from 24px */
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.06);
    border: 1px solid #e2e8f0;
    transition: all 0.25s ease;
}

.stdy-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.1);
    border-color: #c7d2fe;
}

.stdy-card h3 {
    font-size: 1.1rem; /* Reduced from 1.25rem */
    font-weight: 700;
    color: #1e293b;
    margin-bottom: 16px; /* Reduced from 20px */
    display: flex;
    align-items: center;
    gap: 8px; /* Reduced from 10px */
}

/* ---------- COMPACT TEST OVERVIEW ---------- */
.stdy-summary-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 12px; /* Reduced from 16px */
}

.stdy-summary-grid > div {
    background: #f8fafc;
    padding: 12px 8px; /* More compact padding */
    border-radius: 8px; /* Reduced from 10px */
    border: 1px solid #e2e8f0;
    transition: all 0.2s ease;
    text-align: center;
}

.stdy-summary-grid > div:hover {
    background: #ffffff;
    border-color: #2563eb;
    transform: translateY(-1px);
}

.stdy-summary-grid span {
    display: block;
    font-size: 0.75rem; /* Reduced from 0.85rem */
    color: #64748b;
    margin-bottom: 6px; /* Reduced from 8px */
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.02em;
}

.stdy-summary-grid strong {
    display: block;
    font-size: 1.25rem; /* Reduced from 1.5rem */
    color: #1e293b;
    font-weight: 800;
    line-height: 1.2;
}

/* ---------- COMPACT SECTION DETAILS ---------- */
.stdy-sections-card {
    padding: 20px; /* Reduced from 24px */
}

.stdy-sections-container {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); /* Reduced from 300px */
    gap: 12px; /* Reduced from 16px */
}

.stdy-section-item {
    background: #f8fafc;
    border-radius: 8px; /* Reduced from 10px */
    padding: 16px; /* Reduced from 20px */
    border: 1px solid #e2e8f0;
    transition: all 0.2s ease;
    display: flex;
    flex-direction: column;
}

.stdy-section-item:hover {
    background: #ffffff;
    border-color: #10b981;
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(16, 185, 129, 0.1);
}

.stdy-section-header {
    display: flex;
    align-items: center;
    gap: 10px; /* Reduced from 12px */
    margin-bottom: 12px; /* Reduced from 16px */
    padding-bottom: 8px; /* Reduced from 12px */
    border-bottom: 1px solid #e2e8f0; /* Reduced from 2px */
    flex-wrap: nowrap; /* Prevent wrapping */
}

.stdy-section-part {
    font-weight: 800;
    color: #2563eb;
    font-size: 0.95rem; /* Reduced from 1.1rem */
    background: #dbeafe;
    padding: 4px 10px; /* Reduced from 6px 14px */
    border-radius: 4px; /* Reduced from 6px */
    min-width: 70px; /* Reduced from 80px */
    text-align: center;
    flex-shrink: 0; /* Prevent shrinking */
    white-space: nowrap; /* Prevent text wrapping */
}

.stdy-section-name {
    font-weight: 600;
    color: #475569;
    font-size: 0.9rem; /* Reduced from 1rem */
    flex: 1;
    white-space: nowrap; /* Prevent text wrapping */
    overflow: hidden;
    text-overflow: ellipsis; /* Add ellipsis if text is too long */
}

.stdy-section-details {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px; /* Reduced from 12px */
}

.stdy-detail {
    background: white;
    padding: 10px; /* Reduced from 12px */
    border-radius: 6px; /* Reduced from 8px */
    border: 1px solid #e2e8f0;
    text-align: center;
    transition: all 0.2s ease;
}

.stdy-detail:hover {
    border-color: #2563eb;
    transform: translateY(-1px);
}

.stdy-detail-label {
    display: block;
    font-size: 0.75rem; /* Reduced from 0.8rem */
    color: #64748b;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    margin-bottom: 4px; /* Reduced from 6px */
}

.stdy-detail-value {
    display: block;
    font-size: 1.1rem; /* Reduced from 1.3rem */
    color: #1e293b;
    font-weight: 800;
}

/* ---------- INSTRUCTIONS (UNCHANGED) ---------- */
.stdy-instructions-list {
    list-style: none;
    padding: 0;
    margin: 0;
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
}

.stdy-instructions-list li {
    background: #f8fafc;
    border-radius: 10px;
    padding: 14px 16px 14px 48px;
    position: relative;
    font-size: 0.9rem;
    color: #475569;
    line-height: 1.4;
    border: 1px solid #e2e8f0;
    transition: all 0.2s ease;
}

.stdy-instructions-list li:hover {
    background: #ffffff;
    border-color: #f59e0b;
}

.stdy-instructions-list li::before {
    content: "✓";
    position: absolute;
    left: 16px;
    top: 50%;
    transform: translateY(-50%);
    width: 24px;
    height: 24px;
    background: #10b981;
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.8rem;
    font-weight: bold;
}

.stdy-instructions-list strong {
    color: #1e293b;
    font-weight: 700;
}

/* ---------- START BUTTON - FIXED ---------- */
.stdy-start-action {
    margin-top: 20px;
    padding: 20px;
    background: white;
    border-radius: 12px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.06);
    border: 2px dashed #c7d2fe;
    text-align: center;
    transition: all 0.3s ease;
}

.stdy-start-action:hover {
    border-color: #2563eb;
    background: #f8fafc;
}

.start-quiz-btn {
    background: linear-gradient(135deg, #2563eb 0%, #1d4ed8 100%);
    color: white;
    border: none;
    padding: 18px 40px;
    font-size: 1.1rem;
    font-weight: 800;
    border-radius: 50px;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 6px 16px rgba(37, 99, 235, 0.25);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    min-width: 240px;
    position: relative;
    overflow: hidden;
}

.start-quiz-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 10px 24px rgba(37, 99, 235, 0.35);
    background: linear-gradient(135deg, #1d4ed8 0%, #1e40af 100%);
}

.start-quiz-btn:active {
    transform: translateY(0);
    box-shadow: 0 4px 12px rgba(37, 99, 235, 0.25);
}

.start-quiz-btn .btn-icon {
    font-size: 1.4rem;
    transition: transform 0.3s ease;
}

.start-quiz-btn:hover .btn-icon {
    transform: translateX(4px);
}

.btn-text {
    position: relative;
    z-index: 1;
}

/* ---------- RESPONSIVE DESIGN ---------- */
@media (max-width: 768px) {
    .study-quiz-start {
        padding: 16px;
    }
    
    .stdy-card {
        padding: 16px; /* Reduced from 20px */
    }
    
    .stdy-card h3 {
        font-size: 1rem; /* Reduced from 1.1rem */
        margin-bottom: 14px;
    }
    
    .stdy-summary-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 10px; /* Reduced from 12px */
    }
    
    .stdy-summary-grid > div {
        padding: 10px 6px; /* More compact */
    }
    
    .stdy-summary-grid span {
        font-size: 0.7rem; /* Reduced */
    }
    
    .stdy-summary-grid strong {
        font-size: 1.1rem; /* Reduced */
    }
    
    .stdy-sections-container {
        grid-template-columns: 1fr;
        gap: 10px; /* Reduced from 12px */
    }
    
    .stdy-section-item {
        padding: 14px; /* Reduced from 16px */
    }
    
    /* FIX: Keep header items on same line in mobile */
    .stdy-section-header {
        flex-wrap: nowrap; /* Prevent wrapping */
        align-items: center;
        gap: 8px; /* Slightly reduced gap */
        overflow: hidden; /* Prevent overflow issues */
    }
    
    .stdy-section-part {
        font-size: 0.85rem; /* Reduced */
        min-width: 65px; /* Slightly reduced from 70px */
        padding: 3px 8px; /* Reduced */
        flex-shrink: 0; /* Prevent shrinking */
    }
    
    .stdy-section-name {
        font-size: 0.85rem; /* Reduced */
        white-space: nowrap; /* Prevent wrapping */
        overflow: hidden;
        text-overflow: ellipsis; /* Show ellipsis for very long names */
    }
    
    .stdy-section-details {
        gap: 6px; /* Reduced from 8px */
    }
    
    .stdy-detail {
        padding: 8px; /* Reduced from 10px */
    }
    
    .stdy-detail-label {
        font-size: 0.7rem; /* Reduced */
    }
    
    .stdy-detail-value {
        font-size: 1rem; /* Reduced */
    }
    
    .stdy-instructions-list {
        grid-template-columns: 1fr;
        gap: 10px;
    }
    
    .start-quiz-btn {
        padding: 16px 32px;
        font-size: 1rem;
        min-width: 200px;
        width: 100%;
        max-width: 280px;
    }
}

@media (max-width: 576px) {
    .stdy-start-grid {
        gap: 12px; /* Reduced from 16px */
    }
    
    .stdy-card {
        padding: 14px; /* More compact */
    }
    
    .stdy-summary-grid {
        gap: 8px; /* More compact */
    }
    
    .stdy-summary-grid > div {
        padding: 8px 4px; /* More compact */
    }
    
    .stdy-summary-grid span {
        font-size: 0.65rem; /* More compact */
        margin-bottom: 4px;
    }
    
    .stdy-summary-grid strong {
        font-size: 1rem; /* More compact */
    }
    
    .stdy-section-item {
        padding: 12px; /* More compact */
    }
    
    /* FIX: Keep items on same line even on very small screens */
    .stdy-section-header {
        flex-direction: row; /* Keep as row, not column */
        align-items: center;
        gap: 6px; /* Reduced from 8px */
        flex-wrap: nowrap; /* Prevent wrapping */
    }
    
    .stdy-section-part {
        min-width: 60px; /* Reduced but still visible */
        padding: 3px 6px; /* More compact */
        font-size: 0.8rem; /* Slightly smaller */
    }
    
    .stdy-section-name {
        font-size: 0.8rem; /* Slightly smaller */
        white-space: nowrap; /* Prevent wrapping */
        overflow: hidden;
        text-overflow: ellipsis;
    }
    
    .stdy-start-action {
        padding: 16px;
    }
}

/* Extra small devices fix */
@media (max-width: 400px) {
    .stdy-section-header {
        gap: 4px; /* Even smaller gap */
    }
    
    .stdy-section-part {
        min-width: 55px; /* Minimal width */
        padding: 2px 5px;
        font-size: 0.75rem;
    }
    
    .stdy-section-name {
        font-size: 0.75rem;
    }
}