/* --- 1. GLOBAL VARIABLES & RESET --- */
:root { 
    --primary: #1e3a8a; --accent: #3b82f6; --success: #10b981; 
    --error: #ef4444; --missed: #64748b; --extra: #d97706; --bg: #f1f5f9; --active: #fef08a; 
    --disabled: #cbd5e1;
}

* { box-sizing: border-box; }
body { font-family: 'Segoe UI', sans-serif; background: var(--bg); margin: 0; padding: 0; overflow-x: hidden; }

.w-95 { width: 95%; margin: 0 auto; max-width: 1600apx; }
/* --- COMPACT ACTION ROW --- */
.header-action-row {
    display: flex;
    gap: 8px;
    align-items: stretch; /* Makes both buttons same height */
}

/* Match Settings button size to Exam button */
/* --- COMPACT HEADER LOGIC --- */
.hidden {
    display: none !important;
}
/* --- UNIFIED CENTERED HEADER --- */
.app-header {
    background: linear-gradient(135deg, var(--primary), var(--accent));
    min-height: 60px;
    display: flex !important; /* Force the bar to show */
    align-items: center;
    justify-content: center; /* Center the entire row */
    padding: 0 20px;
}

.header-content {
    display: flex !important; /* Force horizontal alignment */
    flex-direction: row;
    align-items: center;
    justify-content: center;
    gap: 25px; 
    width: 100%;
}

/* --- LOGO FIX --- */
.header-left {
    display: flex !important;
    align-items: center;
}

.header-logo {
    height: 35px !important; /* Set a specific height so it's visible */
    width: auto !important;
    display: block !important;
}

/* --- SELECTORS GROUP --- */
.header-selectors {
    display: flex;
    align-items: center;
    gap: 15px;
}

.header-item {
    display: flex;
    align-items: center;
    gap: 8px;
}

.sel-label {
    color: #ffffff !important;
    font-weight: 600;
    font-size: 0.9rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

#test-select { width: 260px; height: 34px; border-radius: 4px; border: none; font-weight: 600; padding: 0 10px; font-weight: 600;}
#time-select { width: 110px; height: 34px; border-radius: 4px; border: none; font-weight: 600; padding: 0 10px; }

/* --- BUTTONS & ICONS FIX --- */
.header-right {
    display: flex !important; /* Force icons to show */
    align-items: center;
    gap: 10px;
}

.compact-btn {
    background: rgba(255, 255, 255, 0.2) !important;
    border: 1.5px solid rgba(255, 255, 255, 0.4) !important;
    color: white !important;
    width: Auto !important;   /* Slightly larger for visibility */
    height: 36px !important;
    border-radius: 6px !important;
    cursor: pointer;
    display: flex !important;  /* CRITICAL: Must be flex to center the icon */
    align-items: center !important;
    justify-content: center !important;
    font-size: 1rem !important; /* Ensures the 🏆 and ⚙️ are big enough */
    line-height: 1 !important;
    padding: 1.5 !important;
}

.compact-btn:hover {
    background: rgba(255, 255, 255, 0.3) !important;
}
/* --- Header Mobile Fix --- */
@media (max-width: 768px) {
    .header-content {
        flex-direction: column !important; /* Stack logo and selectors */
        gap: 10px !important;
        padding: 10px 0 !important;
    }

    .header-logo {
        height: 0px !important; /* Shrink logo for mobile */
        width: 0px !important;
    }

    .header-selectors {
        flex-wrap: wrap !important; /* Allow selectors to drop to next line */
        justify-content: center !important;
        gap: 8px !important;
        width: 100% !important;
    }

    .sel-label {
        font-size: 0.8rem !important; /* Smaller text */
    }

    #test-select {
        width: 100% !important; /* Exercise takes full width on mobile */
        max-width: 300px;
    }

    #time-select {
        width: 80px !important; /* Keep time selector small */
    }
}
/* --- GAP & SUBMIT REDUCTION --- */
.btn-submit {
    width: 35% !important; /* Reduced width */
    max-width: 200px;
    padding: 6px 0 !important;
    margin: 0 !important;
}

.main-grid {
    gap: 4px !important; /* Brings boxes closer */
    margin-top: 5px;
}

.independent-wrapper {
    margin: 2px auto !important;
}


/* --- INDEPENDENT SETTINGS CONTAINER --- */
.independent-settings-container {
    width: 95%; 
    margin: 5px auto !important; /* Reduced from 30px */
    border: none; /* Removes the faint ghost line */
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
    background: rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(10px); 
    overflow: hidden;
}

/* --- THE TOGGLE BUTTON --- */
.settings-toggle-btn {
    width: 100%; 
    padding: 16px; 
    background: #0f172a; /* Dark modern slate */
    color: #f8fafc;
    border: none; 
    font-weight: 800; 
    font-size: 0.85rem; 
    letter-spacing: 2px;
    cursor: pointer; 
    text-transform: uppercase; 
    transition: all 0.3s ease;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 10px;
}

.settings-toggle-btn:hover {
    background: #1e293b;
}

/* --- HORIZONTAL ROW (PC) --- */
.settings-horizontal-row {
    display: flex; 
    flex-direction: row; 
    flex-wrap: nowrap; /* Forces one line on PC */
    gap: 12px; 
    padding: 20px; 
    background: #f8fafc;
    overflow-x: auto; /* Horizontal scroll if screen is too small */
}

/* progress logic */
/* Container inside the flex bar */
.inline-progress {
    flex-grow: 1; /* Takes up available space between buttons */
    max-width: 72%;
    height: 12px;
    background: #e2e8f0; /* Empty track color */
    border-radius: 6px;
    position: relative;
    overflow: hidden;
    border: 1px solid #cbd5e1;
    margin: 0 15px;
}

#progress-fill {
    width: 0%; /* Ensure it starts at zero */
    height: 100%;
    background: #10b981;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    transition: width 0.2s ease;
    min-width: 0; /* REMOVE any existing min-width */
}

#progress-text {
    color: white;
    font-size: 0.04rem;
    font-weight: bold;
    padding-right: 5px;
    z-index: 10; /* Ensures it stays on top */
}

/* Logic for when the bar is too small to show text inside */
.bar-low #progress-text {
    color: #1e293b;
    position: absolute;
    left: 105%; /* Pushes text outside to the right if fill is < 10% */
}

/* --- INDEPENDENT SETTINGS GROUPS --- */
.settings-group {
    flex: 1; 
    min-width: 200px; 
    padding: 18px;
    background: #ffffff;
    border-radius: 12px; 
    border: 1px solid #edf2f7;
    border-top: 5px solid #cbd5e1; /* Default border top */
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    display: flex;
    flex-direction: column;
}

.settings-group:hover { 
    transform: translateY(-4px); 
    box-shadow: 0 6px 15px rgba(0,0,0,0.08); 
}

/* --- DYNAMIC COLORFUL BORDERS --- */
.group-blue { border-top-color: #3b82f6; }   /* Visuals */
.group-green { border-top-color: #10b981; }  /* Backspace */
.group-purple { border-top-color: #8b5cf6; } /* Highlighting */
.group-teal { border-top-color: #14b8a6; }   /* Processing */
.group-orange { border-top-color: #f59e0b; } /* Exam Criteria */

/* --- VERTICAL STACKING & ALIGNMENT --- */
.group-header {
    font-size: 0.75rem; 
    font-weight: 900; 
    color: #475569;
    text-transform: uppercase; 
    margin-bottom: 15px; 
    letter-spacing: 1px;
    border-bottom: 1px solid #f1f5f9;
    padding-bottom: 8px;
    display: flex;
    align-items: center;
}

.vertical-stack { 
    display: flex; 
    flex-direction: column; 
    gap: 12px; 
    align-items: flex-start; /* Aligns all checkboxes/radios to the left */
}

/* --- INPUTS & LABELS --- */
.setting-item {
    display: flex; 
    align-items: center; 
    gap: 10px; 
    font-size: 0.85rem;
    color: #334155; 
    cursor: pointer; 
    white-space: nowrap;
    text-align: left;
}

.flex-row { 
    display: flex; 
    justify-content: space-between; 
    align-items: center; 
    width: 100%; 
    gap: 10px; 
    font-size: 0.85rem; 
}

.compact-input, .compact-select {
    padding: 4px 6px; 
    border-radius: 6px; 
    border: 1px solid #e2e8f0; 
    font-size: 0.8rem; 
    outline: none;
    background: #fff;
}

.compact-input { width: 65px; }
.compact-select { cursor: pointer; }

/* --- EXAM CRITERIA LOCK LOGIC --- */
#exam-inputs-container.exam-disabled {
    opacity: 0.4 !important;
    pointer-events: none !important;
    filter: grayscale(100%);
}

/* --- RESPONSIVENESS --- */
@media (max-width: 1200px) {
    .settings-horizontal-row { flex-wrap: wrap; }
    .settings-group { flex: 1 1 30%; }
}

@media (max-width: 768px) {
    .settings-group { flex: 1 1 45%; }
}

@media (max-width: 480px) {
    .settings-horizontal-row { flex-direction: column; }
    .settings-group { width: 100%; }
}

/* Global Hidden Class */
.hidden { display: none !important; }

    /* PROGRESS BAR */
    #progress-container { width: 100%; display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
    #progress-track { flex-grow: 1; height: 8px; background: #e2e8f0; border-radius: 4px; overflow: hidden; }
    #progress-fill { height: 100%; width: 0%; background: linear-gradient(90deg, var(--accent), var(--success)); transition: width 0.3s ease; }
    #progress-text { font-weight: bold; color: var(--primary); font-size: 0.9rem; min-width: 45px; text-align: right; }

    /* PANELS */
    .typing-panel { 
        width: 100%;
    gap: 5px; /* Space between ref box and type box */
}
    @media (min-width: 901px) {
      .exam-mode .typing-panel { width: 100%; margin-left: auto; margin-right: auto; }
      .exam-mode #exercise-display, .exam-mode .type-box { width: 100%; height: 250px; }
    }
/* --- EXAM MODE TOGGLE LOGIC --- */

/* 1. HIDE elements when active */
.exam-layout-active .app-header, 
.exam-layout-active #tools-group, 
.exam-layout-active #settings-toggle-btn {
    display: none !important;
}

/* 2. KEEP elements visible when active (Timer, Progress, Submit) */
.exam-layout-active .control-bar,
.exam-layout-active .control-flex,
.exam-layout-active #timer-display,
.exam-layout-active #progress-container,
.exam-layout-active #btn-submit {
    display: flex !important;
    visibility: visible !important;
}

/* --- BUTTONS & ANIMATIONS --- */
.btn-exit-alt {
    background: linear-gradient(135deg, #475569, #1e293b);
    color: white;
    border: 1px solid rgba(255,255,255,0.2);
}

/* --- EXAM MODE LOGIC --- */
body.exam-layout-active .app-header, 
body.exam-layout-active #tools-group, 
body.exam-layout-active #settings-toggle-btn {
    display: none !important; /* Hides header and Pause/Resize in Exam Mode */
}

body.exam-layout-active #btn-exam-exit {
    display: inline-flex !important; /* Shows Exit button next to Submit in Exam Mode */
}
/* 1. Ensure the control bar stays visible and centered in Exam Mode */
body.exam-layout-active .control-bar {
    display: block !important;
    position: sticky; /* Keep it at the top of the page scroll */
    top: 0;
    width: 100%;
    z-index: 1000;
}

/* 2. Force the action row to stay a flex-row (centered) */
body.exam-layout-active .action-row {
    display: flex !important;
    flex-direction: row !important;
    justify-content: center !important;
    align-items: center !important;
    gap: 15px;
    position: static !important; /* This cancels the "fixed" behavior */
}

/* 3. Keep the progress bar centered below the buttons */
body.exam-layout-active .control-flex {
    display: flex !important;
    flex-direction: column !important;
    align-items: center !important;
}

/* 4. Ensure the Submit and Exit buttons don't jump to corners */
body.exam-layout-active #btn-submit,
body.exam-layout-active #btn-exit-exam {
    position: static !important;
    margin: 0 !important;
}
/* --- Workspace Width Fix --- */
.independent-wrapper {
    width:99% !important; /* Full width wrapper */
    margin: 10px 0 !important;
    padding: 0 !important; /* Remove wrapper padding */
}



.hl-active, .hl-error {
    display: inline-block;
    padding: 0 2px;
    margin: 0 -2px; /* Offsets padding to keep text alignment perfect */
}
/* --- PROGRESS BAR PERCENTAGE --- */
#progress-fill {
    height: 100%;
    transition: width 0.3s ease, background-color 0.5s linear;
    display: flex;
    align-items: center;
    justify-content: center;
}

#progress-text {
    color: white;
    font-size: 0.7rem;
    font-weight: 800;
}
/* EXIT EXAM BUTTON STYLE */
.btn-exit-exam {
    background: linear-gradient(135deg, #ef4444, #991b1b) !important; /* Red color for Exit */
    color: white !important;
    border: none;
    box-shadow: 0 3px 8px rgba(239, 64, 64, 0.2);
}

/* Ensure the row doesn't wrap even with many buttons */
.action-row {
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: center;
    gap: 12px; /* Slightly reduced gap to fit all on one line */
    width: 100%;
    flex-wrap: nowrap !important; 
}

/* Logic: When exam-layout-active is on the BODY, show the Exit button */
body.exam-layout-active #btn-exit-exam {
    display: inline-flex !important;
}

/* Optional: Hide Pause and Tools in Exam Mode to save space */
body.exam-layout-active #btn-pause,
body.exam-layout-active #tools-group {
    display: none !important;
}
/* 4. RESTORATION STATE (When class is removed) */
/* Standard styles (like .app-header { display: flex }) will 
   automatically take over again as soon as .exam-layout-active is removed. */



.helper-text {
    font-size: 0.8rem;
    color: #94a3b8;
    margin-top: 8px;
}
.group-purple, .group-teal, .group-orange {
    transition: all 0.3s ease;
}
/* --- COMPACT ACTION ROW ABOVE PROGRESS (REDUCED HEIGHT) --- */
.control-bar {
    background: #ffffff;
    border-bottom: 2px solid #e2e8f0;
    padding: 6px 0; /* Reduced padding */
    position: sticky;
    top: 0;
    z-index: 1000;
}

.control-flex {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px; /* Tight vertical gap */
}

.action-row {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 12px;
    width: 95%;
    margin: 0 auto;
}

#timer-display {
    font-size: 1.4rem;
    font-weight: 800;
    color: var(--primary);
    font-variant-numeric: tabular-nums;
    min-width: 70px;
    text-align: center;
    padding: 0 10px;
    border-left: 2px solid var(--accent);
    border-right: 2px solid var(--accent);
    line-height: 28px; /* Matches button height */
}

/* Animations for the Submit button when time is low */
.timer-low #btn-submit {
    animation: pulse-red 1s infinite;
}

@keyframes pulse-red {
    0% { box-shadow: 0 0 0 0 rgba(239, 64, 64, 0.7); }
    70% { box-shadow: 0 0 0 10px rgba(239, 64, 64, 0); }
    100% { box-shadow: 0 0 0 0 rgba(239, 64, 64, 0); }
}

/* --- ANIMATED BUTTON BASE (REDUCED BY 1/4) --- */
.btn {
    padding: 6px 14px; /* Reduced from 8px 18px */
    border-radius: 5px;
    border: none;
    font-weight: 700;
    cursor: pointer;
    font-size: 0.75rem; /* Reduced from 0.85rem */
    height: 28px;      /* Reduced from 38px (Approx 1/4 reduction) */
    display: inline-flex;
    align-items: center;
    justify-content: center;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.btn:active {
    transform: scale(0.92);
}

/* --- SPECIFIC BUTTON STYLES & ANIMATIONS --- */

/* Start Button: Pulse Animation */
.btn-start {
    background: linear-gradient(135deg, var(--success), #059669);
    color: white;
    box-shadow: 0 3px 10px rgba(16, 185, 129, 0.3);
    animation: pulse-green 2s infinite;
    font-size: 1rem;
}

.btn-pause {
    background: linear-gradient(135deg, #f59e0b, #d97706);
    color: white;
}

/* Tool/Resize Buttons: Reduced Sizing */
.btn-tool {
    background: white;
    border: 1px solid var(--disabled);
    color: var(--primary);
    width: 28px; /* Matches height */
    padding: 0;
    font-size: 1rem;
}

.btn-tool:hover {
    transform: rotate(8deg) scale(1.1);
}

.btn-submit {
    width: 2px;
    background: #FA8072;
    color: White;
    box-shadow: 0 3px 10px rgba(30, 58, 138, 0.2);
}

/* --- DYNAMIC TIMER (REDUCED BY 1/4) --- */
#timer-display {
    font-size: 1.35rem; /* Reduced from 1.8rem */
    font-weight: 800;
    color: var(--primary);
    font-variant-numeric: tabular-nums;
    padding: 0 10px;
    border-left: 2px solid var(--accent);
    border-right: 2px solid var(--accent);
    line-height: 28px; /* Aligns with button height */
    animation: slideIn 0.5s ease-out;
}

/* --- COMPACT PROGRESS BAR WITH PERCENTAGE --- */
.inline-progress {
    width: 100%;
    max-width: 800px;
    height: 14px; /* Slightly increased from 8px to fit text comfortably */
    background: #e2e8f0;
    border-radius: 10px;
    overflow: hidden;
    border: 1px solid #cbd5e1;
    position: relative; /* Necessary for absolute positioning of text if needed */
}

#progress-fill {
    height: 100%;
    width: 0%; 
    /* Remove any background: blue or gradients here */
    background-color: hsl(0, 80%, 45%); /* Default starting Red */
    transition: width 0.3s ease, background-color 0.5s linear; 
    display: flex;
    align-items: center;
    justify-content: center;
}

#progress-text {
    font-size: 0.7rem;
    font-weight: 800;
    transition: color 0.3s ease;
}

/* If the progress is very low (< 5%), the text might be invisible. 
   You can add this JS-driven class if you want the text to stay dark until the bar fills up */
.bar-low #progress-text {
    color: var(--primary);
    margin-left: 40px;
}
/* --- ANIMATION KEYFRAMES --- */
@keyframes pulse-green {
    0% { box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.6); }
    70% { box-shadow: 0 0 0 8px rgba(16, 185, 129, 0); }
    100% { box-shadow: 0 0 0 0 rgba(16, 185, 129, 0); }
}

@keyframes slideIn {
    from { opacity: 0; transform: translateY(-3px); }
    to { opacity: 1; transform: translateY(0); }
}
 /* Unique Container */
.independent-container {
    margin: 20px 0;
    width: 100%;
    max-width: 800px;
}

.independent-header {
    background: #334155;
    color: white;
    padding: 8px 15px;
    font-size: 0.9rem;
    font-weight: bold;
    border-radius: 8px 8px 0 0;
}

.independent-wrapper {
    width: 100%;
   margin: 5px auto; /* Reduced from 20px */
}

/* Container to match settings panel width and centering */
.independent-wrapper {
    width: 95%; 
    margin: 20px auto; /* Centers the box and adds vertical spacing */
    max-width: 1600px;  /* Matches the .w-95 max-width */
    display: flex;
    justify-content: center;
}



/* --- UNIFIED TYPING WORKSPACE (PC) --- */
.independent-box, 
#independent-display, 
.independent-type-box {
    /* Dimensions & Layout */
    width: 70% !important; 
    max-width: 1100px !important;
    height: 220px !important; /* Taller Workspace (+20%) */
    margin: 5px auto !important;
    padding: 15px !important;
    box-sizing: border-box;
    
    /* Aesthetics */
    background: #ffffff !important;
    border: 2px solid var(--primary) !important;
    border-radius: 12px !important;
    
    /* Typography & Justification */
    font-family: 'Poppins', 'Inter', 'Segoe UI', Arial, sans-serif !important;
    font-size: 1.15rem !important;
    line-height: 1.5 !important;
    color: #1e293b !important;
    text-align: justify !important; /* Forces justification on both boxes */
    text-justify: inter-word;
    
    /* Behavior */
    overflow-y: auto !important;
    white-space: pre-wrap !important;
    word-break: normal;
    overflow-wrap: break-word;
    position: relative;
    scroll-behavior: smooth;
}

/* Specific Border Color for Type Box */
.independent-type-box {
    border-color: var(--accent) !important;
    resize: none;
    outline: none;
}

/* --- MOBILE RESPONSIVE (STRICT 97% WIDTH) --- */
@media (max-width: 768px) {
    .independent-box, 
#independent-display, 
.independent-type-box{
        width: 97% !important; /* Covers full screen as requested */
        height: 220px !important; 
        font-size: 1.1rem !important; /* Balanced for mobile */
        border-radius: 5px !important; /* Square edges for mobile */
    }
}
/* Container to match settings and reference box width */
.independent-wrapper {
    width: 95%; 
    margin: 20px auto; 
    max-width: 1600px;
    display: flex;
    justify-content: center;
}
/* Active word/letter to be typed */
.hl-active { background-color: #fef08a; color: #000; border-radius: 3px; }

/* Error highlighting */
.hl-error { background-color: #fecaca; color: #dc2626; text-decoration: underline; }

/* Correctly typed (optional, for visual feedback) */
.hl-correct { color: #10b981; }

/* Base attributes shared with the Reference Box */


/* Active State when the user is typing */
.independent-type-box:focus {
    border-color: var(--primary);
    background: #fff;
    box-shadow: 0 0 0 4px rgba(59, 130, 246, 0.1);
}

/* Disabled state before test starts */
.independent-type-box:disabled {
    background: #f1f5f9;
    cursor: not-allowed;
    border-color: #cbd5e1;
}

/* Mobile Responsiveness */
@media (max-width: 768px) {
    .independent-box,.independent-type-box {
        font-size: 1rem;
        height: 200px;
        padding: 15px;
    }
}
#independent-display {
    display: block;
    white-space: pre-wrap; /* Crucial for recognizing spaces */
}

#independent-display br {
    display: block;
    margin: 0 !important;
    padding: 0 !important;
    line-height: 0.1 !important;
}

.char {
    display: inline;
    margin: 0;
    padding: 0;
}
#independent-display, #type-box {
    transition: font-size 0.2s ease-in-out; /* Smooth resizing effect */
    line-height: 1.6; /* Keeps spacing consistent when zooming */
}
 
/* --- RESULT OVERLAY --- */
#result-panel { 
    position: absolute; top: 0; left: 0; width: 100%; 
    background: var(--bg); z-index: 2000; padding: 20px;
    display: none; justify-content: center;
}

.result-paper {
    background: white .result-paper {
    max-width: 1200px !important;
    width: 95%;
    margin: 20px auto;
    display: flex;
    flex-direction: column;
    align-items: center; /* Centers all children */
}
.res-tables-flex-container {
    display: flex;
    gap: 20px; /* This is the "Gap" property that creates space between them */
    flex-wrap: wrap; /* Ensures they stack on mobile */
    align-items: stretch;
}

.res-category-box {
    flex: 1; /* Makes both tables equal width */
    min-width: 320px; /* Prevents them from getting too thin */
}
/* Persistent Watermark */
.watermark {
    position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%) rotate(-30deg);
    font-size: 6rem; font-weight: 900; color: rgba(0,0,0,0.04) !important; 
    z-index: 0; pointer-events: none; white-space: nowrap; user-select: none;
}

.res-header-main { text-align: center; border-bottom: 2px solid var(--primary); padding-bottom: 10px; margin-bottom: 15px; }
.res-header-main h1 { margin: 0; font-size: 1.8rem; color: var(--primary); }
.section-title { text-decoration: underline; margin: 20px 0 15px 0; font-size: 1.2rem; }
.res-category-box {
    margin-bottom: 25px; /* Creates space below every box */
}

/* Or specifically for the blue one */
.cat-blue {
    margin-top: 20px; 
}
/* --- 2-COLUMN METRICS GRID --- */
.res-stats-grid {
    width: 60% !important;
    margin: 20px auto;
    display: grid !important;
    grid-template-columns: repeat(4, 1fr); 
    gap: 1px;
    background-color: #e2e8f0;
    border-radius: 10px;
    overflow: hidden;
}

.res-stat-item {
    background-color: #ffffff;
    padding: 15px 10px;
    display: flex;
    flex-direction: column; /* Label on top, Value on bottom */
    align-items: center;
    justify-content: center;
    text-align: center;
    transition: background 0.2s;
}

.res-stat-label {
    font-weight: 700;
    color: #64748b;
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 8px;
}

.res-stat-val {
    font-weight: 800;
    color: var(--text-main);
    font-size: 1.2rem;
    line-height: 1.2;
}

/* Responsive: 2 columns on tablets, 1 column on small phones */
@media (max-width: 900px) {
    .res-stats-grid {
        grid-template-columns: repeat(2, 1fr);
        width: 80% !important;
    }
}

@media (max-width: 480px) {
    .res-stats-grid {
        grid-template-columns: 1fr;
        width: 95% !important;
    }
}

/* --- SIDE-BY-SIDE TABLES --- */
.res-tables-row {
    display: flex; gap: 20px; margin-bottom: 10px; position: relative; z-index: 1;
}
.res-category-box.cat-orange, 
.res-category-box.cat-blue {
   
    width: 60% !important; 
    margin: 10px auto;
    border-radius: 12px;
    border: 1.5px solid #e2e8f0;
    background: #ffffff;
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.05);
    overflow: hidden;
}
.res-cat-label {
    display: block;
    padding: 12px 10px; /* Vertical and horizontal padding */
    color: white;
    font-weight: 700;
    text-align: center;
    text-transform: uppercase;
    font-size: 0.85rem; /* Slightly smaller to fit width */
    line-height: 1.3;   /* Allows text to wrap into 2 lines if needed */
    white-space: normal; /* Force wrapping instead of cutting */
    word-wrap: break-word;
}
/* --- (1) UPDATED CONTAINER STYLE --- */
.res-category-box {
    flex: 1;
    width: 42% !important; /* Maintaining the 42% width previously requested */
    min-width: 320px;       /* Ensuring it doesn't get too squashed on small screens */
    position: relative;    /* Required for absolute positioning of the label */
    border: 2px solid #e2e8f0;
    border-radius: 12px;
    padding: 40px 20px 20px 20px; /* Top padding increased to 40px to clear the label */
    background: white;
    margin: 40px auto;     /* Centers the box and gives space for the overlapping label */
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05);
}

/* --- (2) UPDATED CENTERED LABEL STYLE --- */
.res-cat-label {
    position: absolute;
    top: -10px;            /* Moves it up to overlap the top border */
    left: 50%;             /* Move left edge to center */
    transform: translateX(-50%); /* Shift back by 50% of own width to perfectly center */
    
    padding: 15px 20px;
    border-radius: 6px;
    color: white;
    font-weight: 700;
    font-size: 0.85rem;
    white-space: nowrap;   /* Prevents the label from breaking into two lines */
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    z-index: 10;           /* Ensures it stays above the border */
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Ensure specific colors still apply to centered labels */
.cat-orange .res-cat-label { background: #f97316; }
.cat-blue .res-cat-label { background: #2563eb; }
.cat-orange { border-color: #fdba74; }
.cat-blue { border-color: #93c5fd; }


/* Details Grid inside Category Boxes */
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; row-gap: 8px; font-size: 0.95rem; }
.dg-label { font-weight: 600; color: #555; }
.dg-val { font-weight: 700; text-align: right; }

/* --- FLEX BOX FOR METHODS --- */
.methods-flex {
    display: flex;
    gap: 20px;
    justify-content: space-between;
    margin-top: 10px;
}

.methods-flex .method-section {
    flex: 1; /* Both methods take equal width */
    background: #fcfcfc;
    padding: 10px;
    border-radius: 4px;
    border: 1px solid #f1f5f9;
}

.method-title {
    font-weight: 700;
    color: var(--primary);
    border-bottom: 2px solid #e2e8f0;
    padding-bottom: 5px;
    margin-bottom: 12px;
    font-size: 0.95rem;
}

.method-sub {
    font-size: 0.75rem;
    font-weight: 400;
    color: #64748b;
    display: block; /* Moves description to its own line for neatness */
}

/* --- RESPONSIVE FIX --- */
@media (max-width: 600px) {
    .methods-flex {
        flex-direction: column !important; /* Stack vertically on phones */
        gap: 15px;
    }
}
/* --- AHC COMPARISON TABLE --- */
.ahc-comparison-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 10px;
    background: #ffffff;
    border: 1px solid #cbd5e1;
    table-layout: fixed; /* Ensures equal width columns */
}

.ahc-comparison-table th {
    background-color: var(--primary);
    color: white;
    padding: 10px;
    font-size: 0.9rem;
    text-transform: uppercase;
    text-align: center;
    border: 1px solid #1e3a8a;
}

.ahc-comparison-table td {
    padding: 15px;
    vertical-align: top;
    border: 1px solid #e2e8f0;
}

.ahc-row {
    display: flex;
    justify-content: space-between;
    font-size: 1rem;
    margin-bottom: 8px;
    border-bottom: 1px dashed #f1f5f9;
    padding-bottom: 4px;
}

.ahc-row:last-child {
    border-bottom: none;
}

.ahc-status-cell {
    background-color: #f8fafc;
    text-align: center;
    padding: 20px !important;
}

.ahc-res-final {
    font-size: 1.2rem;
    font-weight: 800;
    text-transform: uppercase;
}

/* --- MOBILE RESPONSIVENESS --- */
@media (max-width: 600px) {
    .ahc-comparison-table thead { display: none; } /* Hide headers on tiny screens */
    .ahc-comparison-table td {
        display: block;
        width: 100%;
    }
    .ahc-comparison-table tr {
        display: flex;
        flex-direction: column;
    }
}
/* --- SCROLL-FREE COMPARISON --- */
/* --- (1 & 2) BOX BORDERS AND INTEGRATED CELL HEADERS --- */
#res-comparison-box {
    width: 95% !important;
    max-width: 1400px;
    margin: 40px auto;
}

.comparison-container {
    display: flex;
    gap: 0px; /* Removed gap to make them look like a joined table */
    width: 100%;
    align-items: stretch;
    border: 2px solid #94a3b8; /* Clear, visible border */
    border-radius: 12px;
    overflow: hidden; /* Clips the headers to the border radius */
}

.res-box-half {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    background: #ffffff;
}

/* Vertical line between the two boxes */
.res-box-half:first-child {
    border-right: 2px solid #94a3b8;
}

/* Header Cells */
.res-box-half h4 {
    margin: 0 !important;
    padding: 15px;
    background: #f1f5f9; /* Light grey cell background */
    color: var(--primary);
    text-align: center;
    font-weight: 800;
    font-size: 0.9rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    border-bottom: 2px solid #94a3b8;
}

.comparison-scroll-box {
    padding: 20px;
    height: auto !important;
    overflow: visible !important;
    font-family: 'Poppins', 'Inter', sans-serif;
    font-size: 1.1rem;
    line-height: 1.8;
    text-align: justify;
}

/* --- (3) MOBILE FRIENDLY VIEW --- */
@media (max-width: 768px) {
    #res-comparison-box {
        width: 100% !important; /* Full screen width on mobile */
        padding: 0 !important;
    }

    .comparison-container {
        flex-direction: column !important; /* Stack boxes vertically */
        border-radius: 0 !important;
        border-left: none !important;
        border-right: none !important;
    }

    .res-box-half:first-child {
        border-right: none !important;
        border-bottom: 2px solid #94a3b8 !important;
    }

    .comparison-scroll-box {
        padding: 15px !important;
        font-size: 1rem !important;
    }

    /* Mobile Result Grid Fix */
    .res-stats-grid {
        grid-template-columns: repeat(2, 1fr) !important;
        width: 100% !important;
    }

    /* Mobile Action Buttons Fix */
    .res-actions {
        flex-direction: column !important;
        align-items: center !important;
        gap: 15px !important;
        width: 100% !important;
    }

    .res-btn {
        width: 90% !important;
        justify-content: center !important;
    }
}

/* Style for words in the original box that the user never reached */
.ref-not-typed {
    color: #cbd5e1; /* Light gray / faded out */
    opacity: 0.5;
}

/* Style for skipped words (skipped during active typing) */
.cmp-skipped-text {
    color: var(--missed);
    text-decoration: line-through;
    background-color: #f1f5f9;
    padding: 0 2px;
}
/* Legend centered under 90% box */
.legend-row {
    display: flex;
    justify-content: center;
    gap: 20px;
    margin-top: 15px;
}
.cmp-correct-text { color: var(--success); }
.cmp-wrong-text { color: var(--error); text-decoration: underline; }
.cmp-extra-text { color: var(--extra); border-bottom: 2px solid var(--extra); background: #fef9c3; }
.cmp-skipped-text { color: var(--missed); opacity: 0.6; }
/* Legend & Comparison Colors */
.legend-row { display: flex; gap: 15px; margin-bottom: 10px; font-size: 0.85rem; }
.leg-item { display: flex; align-items: center; gap: 5px; }
.cmp-correct { color: #000; }
.cmp-wrong { color: var(--error); text-decoration: line-through; }
.cmp-corr-ref { color: var(--success); font-weight: bold; font-size: 0.85rem; }
.cmp-extra { color: var(--extra); text-decoration: underline; font-style: italic; }
.cmp-skipped { color: var(--missed); background: #eee; padding: 0 2px; border-radius: 2px; }


/* Print Configuration */
@media print {
    body * { visibility: hidden; }
    #result-panel, #result-panel * { visibility: visible; }
    #result-panel {
        position: absolute;
        left: 0;
        top: 0;
        width: 100%;
    }
    
    /* PC PRINT: Force Side-by-Side */
    .comparison-container {
        display: flex !important;
        flex-direction: row !important;
    }
    .res-box-half {
        flex: 1 !important;
        width: 50% !important;
    }

    .no-print, .res-actions { display: none !important; }
    /* Force colors and background in print */
    * {
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
    }
}

/* --- RESULT PANEL ACTION BUTTONS --- */
.res-actions {
    display: flex;
    justify-content: center;
    gap: 20px;
    margin-top: 40px;
    padding-bottom: 20px;
    width: 100%;
}

/* Base style for result buttons */
.res-btn {
    padding: 12px 30px;
    border-radius: 8px;
    font-weight: 700;
    font-size: 0.95rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    cursor: pointer;
    border: none;
    display: flex;
    align-items: center;
    gap: 10px;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
}

/* Reattempt / Close Button (Slate) */
.res-btn-reattempt {
    background-color: #475569;
    color: #ffffff;
}

.res-btn-reattempt:hover {
    background-color: #1e293b;
    transform: translateY(-2px);
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
}

/* Print Result Button (Primary Blue) */
.res-btn-print {
    background: linear-gradient(135deg, var(--primary), var(--accent));
    color: #ffffff;
}

.res-btn-print:hover {
    filter: brightness(1.1);
    transform: translateY(-2px);
    box-shadow: 0 10px 15px -3px rgba(30, 58, 138, 0.25);
}

/* Icon scaling for the buttons */
.res-btn i, .res-btn span {
    font-size: 1.1rem;
}

/* Hide buttons during the actual print process */
@media print {
    .res-actions {
        display: none !important;
    }
}
/* --- FINAL MOBILE REFINEMENTS --- */
@media (max-width: 768px) {
    /* (1) Force Full Width for ALL Result Elements */
    .result-paper, 
    #res-comparison-box, 
    .res-stats-grid, 
    .res-category-box {
        width: 99% !important;
        margin-left: auto !important;
        margin-right: auto !important;
        padding-left: 10px !important;
        padding-right: 10px !important;
    }

    /* (2 & 3) Stack Detailed Result Table (Grid to List) */
    .res-stats-grid {
        display: flex !important;
        flex-direction: column !important;
        background: #e2e8f0 !important;
        gap: 2px !important; /* Visible divider lines */
        border: 2px solid #e2e8f0 !important;
    }

    .res-stat-item {
        width: 100% !important;
        display: flex !important;
        justify-content: space-between !important; /* Label left, Value right */
        align-items: center !important;
        padding: 15px 20px !important;
        background: #ffffff !important;
    }

    /* Align Label and Value for the stacked look */
    .res-stat-label {
        text-align: left !important;
        margin-bottom: 0 !important;
        font-size: 0.8rem !important;
    }

    .res-stat-val {
        text-align: right !important;
        font-size: 1.1rem !important;
    }

    /* Handle the "Total Errors" row specifically */
    .res-stat-item[style*="grid-column: span 4"] {
        flex-direction: column !important; /* Stack these two vertically for emphasis */
        gap: 5px !important;
    }

    /* (1) Fix Comparison Boxes Width */
    .comparison-container {
        flex-direction: column !important;
        width: 100% !important;
    }

    .res-box-half {
        width: 100% !important;
        border-right: none !important;
    }
}
/* --- MOBILE WIDTH SYNC FIX --- */
@media (max-width: 768px) {
    /* Ensure the display box matches the type box exactly */
    #independent-display {
        width: 100% !important;
        max-width: 97% !important;
        margin-left: auto !important;
        margin-right: auto !important;
        display: block !important;
    }

    /* Remove any extra padding from the wrapper that might be squeezing the box */
    .independent-wrapper {
        width: 100% !important;
        padding: 0 !important;
        margin: 10px 0 !important;
        display: flex !important;
        justify-content: center !important;
    }

    /* Ensure the type box also maintains the same 97% standard */
    .independent-type-box {
        width: 97% !important;
        margin-left: auto !important;
        margin-right: auto !important;
    }
}