/* --- GLOBAL STYLES --- */
body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    margin: 0;
    padding: 20px;
    background-color: #f4f4f9;
}
/* --- Add these to your existing style.css --- */

/* New Control Buttons */
button.save-btn { background: #ffc107; color: #000; }
button.save-btn:hover { background: #e0a800; }

button.regen-btn { background: #6c757d; }
button.regen-btn:hover { background: #5a6268; }

/* Individual Cell Regenerate Button */
.btn-regenerate-cell {
    position: absolute;
    top: 5px;
    right: 5px;
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1.1rem;
    opacity: 0.3;
    transition: opacity 0.2s, transform 0.2s;
    z-index: 10;
    padding: 2px;
}
.btn-regenerate-cell:hover {
    opacity: 1;
    transform: rotate(90deg);
}

/* Ensure the "(Click)" text doesn't overlap with the print area or new icons */
.q-content::after {
    content: "(Click)";
    position: absolute;
    bottom: 4px;
    right: 6px;
    font-size: 0.7rem;
    color: #bbb;
    pointer-events: none;
}
/* --- CONTROL PANEL --- */
#controls {
    background: white;
    padding: 15px 20px;
    border-radius: 8px;
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
    margin-bottom: 20px;
    display: flex;
    flex-wrap: wrap;
    gap: 20px;
    align-items: center;
}
.control-group { display: flex; align-items: center; gap: 8px; }

select, input[type="number"] {
    padding: 6px;
    border: 1px solid #ccc;
    border-radius: 4px;
    font-size: 1rem;
}
input[type="number"] { width: 60px; }

button {
    padding: 8px 16px;
    background: #007bff;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-weight: bold;
}
button:hover { background: #0056b3; }
button.print-btn { background: #28a745; }
button.print-btn:hover { background: #1e7e34; }
#page-indicator { font-weight: bold; min-width: 80px; text-align: center; }


/* --- GRID LAYOUT (Screen View) --- */
#starter-container {
    width: 99%;           
    height: 88vh;         /* Maximized height */
    margin: 0 auto;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    grid-template-rows: 1fr 1fr; /* Two equal rows */
    gap: 8px;            
    border: 2px solid #ccc;
    background: white;
}

.q-cell {
    border: 1px solid #ccc;
    display: flex;
    position: relative;
    overflow: hidden;
    cursor: pointer;
    transition: background 0.2s;
}
.q-cell:hover { background: #f8f9fa; }

/* The Number Bar */
.q-number {
    width: 35px;
    background: #e0e0e0;
    display: flex;
    justify-content: center;
    align-items: center;
    font-weight: bold;
    font-size: 1.4rem;
    border-right: 1px solid #ccc;
    flex-shrink: 0;
}

/* The Content Area - Layout Update */
.q-content {
    flex-grow: 1;
    width: 100%;
    /* Minimal padding to maximize space */
    padding: 8px 8px 4px 8px; 
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    /* Pushes content apart: Label at top, Math in middle/expanded */
    justify-content: flex-start; 
    align-items: center;
    text-align: center;
    font-size: 1.4rem; 
}

/* Label: Top-Left alignment */
.q-text-label {
    align-self: flex-start; /* Snap to left */
    font-size: 1.1rem;
    font-weight: 700;
    font-family: 'Segoe UI', sans-serif;
    color: #444;
    margin-bottom: 5px;
    text-align: left;
    width: 100%;
}

/* Container for the actual math/diagram to ensure centering */
.q-content > div:not(.q-text-label), 
.q-content > svg {
    flex-grow: 1; /* Take up all remaining space */
    display: flex;
    align-items: center; /* Vertically center */
    justify-content: center; /* Horizontally center */
    width: 100%;
}

/* "Click for answer" - tucked tightly in corner */
.q-content::after {
    content: "(Click)";
    position: absolute;
    bottom: 2px;
    right: 4px;
    font-size: 0.6rem;
    color: #ccc;
    pointer-events: none;
}

/* --- SVG & Diagram Maximization --- */
svg {
    width: 100%;
    height: auto; 
    max-height: 100%; 
    display: block;
}

.q-content svg text {
    font-size: 14px;
    font-weight: 600;
    paint-order: stroke;
    stroke: #ffffff;
    stroke-width: 3px; 
    stroke-linejoin: round;
}

/* Tighter Math spacing */
.katex-display { margin: 0.2em 0 !important; }


/* --- PRINT STYLES --- */
#print-container { display: none; }

/* --- PRINT STYLES --- */
#print-container { display: none; }

@media print {
    body { background: white; padding: 0; margin: 0; }
    #controls, #starter-container { display: none !important; }
    #print-container { display: block; }

    /* FORCED PORTRAIT: Matches your Word-style mockup */
    @page { 
        size: A4 portrait; 
        margin: 10mm; 
    }

    /* Stack 4 strips vertically per page */
    .print-page {
        width: 100%;
        display: flex;
        flex-direction: column;
        gap: 15mm; /* Nice big gap between strips for cutting */
        box-sizing: border-box;
    }

    /* THE STRIP (Full page width, calculated height to fit 4 exactly) */
    .print-card {
        width: 100%;
        height: 60mm; /* Fixed height guarantees 4 fit on A4 without pushing to next page */
        display: grid;
        grid-template-columns: repeat(4, 1fr);
        grid-template-rows: repeat(2, 1fr); 
        box-sizing: border-box;
        page-break-inside: avoid;
        background: white;
        
        /* Outer Top & Left Borders (cells handle right & bottom to prevent double lines) */
        border-top: 1px solid #000;
        border-left: 1px solid #000;
    }

    /* THE CELL */
    .print-cell {
        border-right: 1px solid #000;
        border-bottom: 1px solid #000;
        display: flex;
        flex-direction: row; 
        overflow: hidden;
    }

    /* GREY NUMBER BAR - Exactly like the mockup */
    .print-number {
        width: 22px; /* Fixed narrow width */
        background: #e6e6e6 !important; /* Solid light grey */
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
        border-right: 1px solid #000;
        display: flex;
        justify-content: flex-start; /* Aligned left */
        align-items: flex-start;     /* Aligned top */
        padding: 4px 0 0 4px;        /* Padding to place number in top-left */
        font-size: 10pt; 
        font-weight: bold;
        flex-shrink: 0;
    }

    /* CONTENT AREA - Centered and readable */
    .print-content {
        flex-grow: 1;
        padding: 4px 8px; 
        display: flex;
        flex-direction: column;
        justify-content: center; /* Centers vertically */
        align-items: center;     /* Centers horizontally */
        text-align: center;
        font-size: 9.5pt;        /* Highly readable size for A4 strips */
        line-height: 1.2;
    }

    /* OPTIONAL LABELS (e.g., "Solve:") */
    .q-text-label {
        font-size: 9.5pt;
        font-weight: normal; /* Removed bold to match mockup style */
        align-self: center;
        text-align: center;
        margin-bottom: 2px;
        width: 100%;
        color: #000;
    }

    /* DIAGRAMS & SVGS */
    .print-content > div:not(.q-text-label),
    .print-content > svg {
        flex-grow: 1;
        display: flex;
        align-items: center;
        justify-content: center;
        width: 100%;
    }

    .print-content svg {
        width: auto;
        height: auto;
        max-width: 95%;
        max-height: 95%; 
    }
    
    .print-content svg text {
        font-size: 14px !important; 
        font-weight: normal;
    }

    /* MATH FORMULAS */
    .katex-display { margin: 0.1em 0 !important; }
    .katex { font-size: 1.1em !important; }
}

/* --- OVERFLOW AND WRAPPING FIXES --- */
.q-content, .print-content {
    word-wrap: break-word !important;
    overflow-wrap: break-word !important;
    max-width: 100%;
}

.katex-display, .katex {
    white-space: normal !important;
    word-break: break-word !important;
    max-width: 100%;
}

/* --- SPECIAL TARGET FORMAT (Web UI) --- */
#starter-container.special-layout {
    display: flex; 
    justify-content: center; 
    align-items: flex-start; 
    padding-top: 4vh;
    border: none;
    background: transparent;
}

.special-wrapper {
    width: 90%;
    max-width: 650px;
    background: #fff;
    border: 3px dashed #007bff;
    border-radius: 12px;
    padding: 30px;
    text-align: center;
    box-shadow: 0 5px 15px rgba(0,0,0,0.08);
    position: relative;
    display: flex;
    flex-direction: column;
}

.special-wrapper h1 {
    font-size: 2.5rem;
    margin: 0 0 10px 0;
    color: #2c3e50;
}

.special-rules {
    font-size: 1.2rem;
    color: #555;
    margin-bottom: 25px;
    line-height: 1.5;
}

.special-input-group {
    display: flex;
    gap: 10px;
    justify-content: center;
    margin-bottom: 10px;
}

#special-input {
    flex-grow: 1;
    font-size: 1.3rem;
    padding: 12px 15px;
    border: 2px solid #ccc;
    border-radius: 6px;
    transition: border-color 0.2s;
}

#special-input:focus {
    border-color: #007bff;
    outline: none;
}

.special-input-group button {
    font-size: 1.2rem;
    padding: 10px 25px;
}

.special-error {
    color: #dc3545;
    font-weight: bold;
    min-height: 24px;
    margin-bottom: 20px;
    font-size: 1.1rem;
}

.special-entries-list {
    list-style: none;
    padding: 0;
    margin: 0;
    max-height: 300px;
    overflow-y: auto;
    border-top: 2px solid #eee;
    padding-top: 15px;
}

.special-entries-list li {
    font-size: 1.5rem;
    font-weight: bold;
    color: #28a745;
    padding: 10px;
    border-bottom: 1px solid #f0f0f0;
    background: #f8fdf9;
    margin-bottom: 6px;
    border-radius: 6px;
    letter-spacing: 1px;
}

.btn-regen-special {
    position: absolute;
    top: 15px;
    right: 15px;
    background: #e9ecef;
    color: #495057;
    border: none;
    padding: 8px 12px;
    border-radius: 5px;
    cursor: pointer;
    font-size: 0.95rem;
    font-weight: bold;
    transition: background 0.2s;
}

.btn-regen-special:hover {
    background: #dee2e6;
}

/* --- SPECIAL TARGET FORMAT (Print View) --- */
@media print {
    .special-print-cell {
        /* Override standard grid spanning to force this cell to take the entire block */
        grid-column: 1 / span 4;
        grid-row: 1 / span 2;
        padding: 20px !important;
        text-align: left !important;
        display: flex !important;
        border: none !important; /* Cleanup inner borders */
    }

    .special-print-workspace {
        flex-grow: 1;
        width: 100%;
        border: 2px dashed #bbb;
        border-radius: 8px;
        margin-top: 15px;
        min-height: 100px;
    }
}
/* --- SPECIAL TARGET: Timer & End-Game Formatting --- */

.special-timer {
    position: absolute;
    top: 15px;
    left: 20px;
    font-size: 1.8rem;
    font-weight: bold;
    font-family: monospace;
    color: #2c3e50;
    background: #f8f9fa;
    padding: 5px 15px;
    border-radius: 8px;
    border: 2px solid #dee2e6;
    transition: color 0.3s;
}

.special-timer.danger {
    color: #dc3545;
    animation: pulse 1s infinite alternate;
}

@keyframes pulse {
    from { transform: scale(1); }
    to { transform: scale(1.05); }
}

.special-finished-msg {
    color: #d32f2f;
    font-size: 1.8rem;
    margin: 10px 0 25px 0;
    background: #ffebee;
    padding: 15px;
    border-radius: 8px;
    border: 2px solid #ef9a9a;
}

/* Grid View triggered when the timer ends */
.special-entries-list.grid-view {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 10px;
    padding-top: 10px;
    border-top: none;
    max-height: 50vh;
}

.special-entries-list.grid-view li {
    font-size: 1.2rem;
    margin-bottom: 0;
    background: #e8f5e9;
    border-color: #c8e6c9;
    text-align: center;
}

/* --- VIEW MODES LOGIC --- */
body.view-dashboard #app-view { display: none; }
body.view-dashboard #dashboard-view { display: block; }

body.view-editing #dashboard-view { display: none; }
body.view-editing #app-view { display: block; }
body.view-editing #presenting-header { display: none !important; }

/* Presenting Mode: Lock to 100vh and use Flexbox to squeeze the grid on screen */
body.view-presenting {
    margin: 0;
    padding: 0;
    height: 100vh;
    overflow: hidden; 
}
body.view-presenting #dashboard-view { display: none; }
body.view-presenting #controls { display: none; }

body.view-presenting #app-view { 
    display: flex; 
    flex-direction: column; 
    height: 100vh; 
    box-sizing: border-box; 
}

body.view-presenting #presenting-header { display: flex; }

/* In Presenting Mode, remove grey borders, and force it to dynamically fill remaining space */
body.view-presenting #starter-container { 
    border: none; 
    flex-grow: 1; 
    height: auto; 
    padding: 0 20px 20px 20px; 
    box-sizing: border-box; 
}
body.view-presenting .q-cell { 
    border-color: #e0e0e0; 
    border-radius: 8px; 
    box-shadow: 0 2px 4px rgba(0,0,0,0.05); 
    margin: 4px; 
}
body.view-presenting .btn-regenerate-cell { display: none; } 

/* Push the special target layout up slightly in presenting mode so it centres perfectly */
body.view-presenting #starter-container.special-layout { padding-top: 2vh; }


/* --- PRESENTING HEADER --- */
#presenting-header {
    justify-content: space-between;
    align-items: flex-end; /* Keeps the bottom of the Title and Date aligned */
    padding: 40px 40px 20px 40px; 
    border-bottom: 3px solid #2c3e50;
    margin-bottom: 20px;
    color: #2c3e50;
    flex-shrink: 0; 
}

#ph-title-container {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
}

#ph-subheading {
    margin: 0 0 20px 0; /* Space between Classwork and Title */
    font-size: 2.2rem; 
    font-weight: normal;
    text-decoration: underline;
    text-underline-offset: 6px; /* Pushes the underline down slightly so it looks cleaner */
    line-height: 1;
}

#ph-title { 
    margin: 0; 
    font-size: 5rem; 
    font-weight: bold; 
    line-height: 1; 
    text-decoration: underline;
    text-underline-offset: 8px;
}

#ph-date { 
    margin: 0; 
    font-size: 3rem; 
    font-weight: normal; 
    color: #666; 
    line-height: 1; 
    text-decoration: underline;
    text-underline-offset: 6px;
}

/* --- ANSWER BANNER (LOWER THIRD) --- */
.q-answer-banner {
    position: absolute;
    bottom: 0;
    left: 0; 
    width: 100%;
    min-height: 45%; 
    max-height: 100%; 
    
    background: rgba(44, 62, 80, 0.95);
    border-top: 5px solid #27ae60;
    color: #ffffff;
    
    padding: 10px 20px;
    box-sizing: border-box;
    z-index: 15; 
    
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    text-align: center;
    
    font-size: 2.2rem; 
    font-weight: bold;
    box-shadow: 0 -4px 10px rgba(0,0,0,0.15);

    /* NEW: Hide it using transform and opacity by default */
    transform: translateY(100%);
    opacity: 0;
    pointer-events: none; /* Prevents invisible banner from blocking clicks */
    transition: transform 0.25s cubic-bezier(0.25, 0.8, 0.25, 1), opacity 0.2s ease;
}

/* NEW: The class toggled by JS to slide the banner up */
.q-answer-banner.show {
    transform: translateY(0);
    opacity: 1;
}

/* Ensure Math / KaTeX renders properly in white on the dark background */
.q-answer-banner .katex-display {
    margin: 0 !important;
}
.q-answer-banner .katex {
    color: #ffffff !important;
    text-shadow: 1px 1px 2px rgba(0,0,0,0.5);
}

/* --- VISUAL PAGE INDICATOR (TAB TRIGGER) --- */
#page-squares-indicator {
    position: fixed;
    top: 25px;
    right: 30px;
    display: flex;
    gap: 10px;
    z-index: 2000;
    opacity: 0;
    pointer-events: none; /* So you can click through it if it overlaps anything */
    transition: opacity 0.2s ease-in-out;
}

#page-squares-indicator.show {
    opacity: 1;
}

.page-square {
    width: 35px;
    height: 35px;
    border: 2px solid #2c3e50;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    font-size: 1.2rem;
    color: #2c3e50;
    background: rgba(255, 255, 255, 0.9);
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}

.page-square.active {
    background: #2c3e50;
    color: #ffffff;
    border-color: #2c3e50;
}