/* ========================================= */
/* 1. GLOBAL VARIABLES & RESET               */
/* ========================================= */
:root {
    /* Brand Colors */
    --maroon: #800000;
    --maroon-light: #9a1a1a;
    --red: #D32F2F;
    --orange: #FB8C00;
    --yellow: #FBC02D;
    --black: #1a1a1a;
    
    /* UI Colors */
    --text-main: #2d3436;
    --text-muted: #636e72;
    --bg-body: #f4f6f8; 
    --bg-shell: #ffffff;
    --border-light: #e0e0e0;
    --success: #00b894;
    --error: #d63031;
    
    /* Spacing & Layout */
    --app-max-width: 500px;
    --header-height: 64px;
    --radius-l: 20px;
    --radius-m: 12px;
    --radius-s: 8px;
    
    /* Shadows */
    --shadow-sm: 0 2px 8px rgba(0,0,0,0.04);
    --shadow-md: 0 8px 24px rgba(0,0,0,0.08);
    --shadow-lg: 0 15px 35px rgba(0,0,0,0.1);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html { 
    height: 100%; 
    font-size: 16px;
    -webkit-text-size-adjust: 100%; /* Prevent font scaling in landscape */
}

body {
    font-family: 'Poppins', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background-color: var(--bg-body);
    color: var(--text-main);
    min-height: 100vh;
    min-height: 100dvh; 
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
    /* FIX: Removed flex display here to allow natural scrolling */
    display: block;
}

/* --- Background Animation --- */
.background-shapes {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    overflow: hidden; z-index: -1; pointer-events: none;
    background: radial-gradient(circle at top left, #fff0f0 0%, transparent 40%);
}

.shape {
    position: absolute; 
    color: var(--maroon);
    opacity: 0.03;
    font-weight: 800; 
    animation: float 25s infinite linear;
    user-select: none;
}
.shape:nth-child(1) { top: 10%; left: 10%; font-size: 4rem; animation-duration: 30s; }
.shape:nth-child(2) { top: 20%; left: 80%; font-size: 2rem; animation-duration: 25s; animation-delay: -5s; }
.shape:nth-child(3) { top: 60%; left: 15%; font-size: 5rem; animation-duration: 35s; animation-delay: -10s; }
.shape:nth-child(4) { top: 80%; left: 70%; font-size: 3rem; animation-duration: 28s; animation-delay: -2s; }
.shape:nth-child(5) { top: 40%; left: 45%; font-size: 2.5rem; animation-duration: 32s; animation-delay: -15s; }

@keyframes float {
    0% { transform: translateY(0) rotate(0deg); }
    100% { transform: translateY(-100vh) rotate(360deg); }
}

/* ========================================= */
/* 2. APP SHELL                              */
/* ========================================= */
.app-shell {
    position: relative;
    width: 100%;
    max-width: var(--app-max-width);
    min-height: 100vh;
    min-height: 100dvh;
    background-color: var(--bg-shell);
    box-shadow: var(--shadow-md);
    display: flex;
    flex-direction: column;
    /* FIX: This centers the app on desktop screens */
    margin: 0 auto;
}

/* ========================================= */
/* 3. HEADER                                 */
/* ========================================= */
.site-header {
    height: var(--header-height);
    padding: 0 20px;
    background-color: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border-light);
    position: sticky;
    top: 0;
    z-index: 100;
    display: flex;
    align-items: center;
}

.main-nav, .landing-nav {
    display: flex; 
    justify-content: space-between; 
    align-items: center; 
    width: 100%;
}

.nav-link, .nav-link-back {
    text-decoration: none; color: var(--text-main); 
    font-weight: 600; font-size: 0.95rem;
    transition: color 0.2s; cursor: pointer; border: none; background: none;
    padding: 10px 5px; 
}
.nav-link:hover { color: var(--maroon); }

.nav-link-back { 
    font-size: 1.1rem; 
    display: flex; align-items: center; gap: 5px;
    color: var(--text-muted);
}

.nav-tools { display: flex; gap: 10px; }
.tool-btn {
    background: #f1f2f6; 
    border: none;
    border-radius: 12px;
    width: 42px; height: 42px;
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    transition: all 0.2s ease;
    color: var(--text-muted);
}
.tool-btn svg { width: 22px; height: 22px; stroke-width: 2px; }
.tool-btn:active { transform: scale(0.95); background: #e1e2e6; }

/* ========================================= */
/* 4. LANDING PAGE                           */
/* ========================================= */
body.page-landing .site-header { background: transparent; border: none; }
body.page-landing .app-shell { box-shadow: none; background: transparent; }

.landing-container {
    flex: 1;
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    padding: 20px; gap: 2rem;
    /* FIX: Removed negative margin that broke mobile layout */
    margin-top: 0;
    padding-top: 40px; 
}

.organization-title {
    font-size: clamp(2rem, 6vw, 3rem);
    font-weight: 800;
    letter-spacing: 0.5rem;
    text-transform: uppercase;
    color: var(--text-muted);
    margin-bottom: -1.5rem;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 5px;
}
.organization-title span { display: inline-block; }

.title-container {
    display: flex; gap: 8px; justify-content: center; align-items: center;
    flex-wrap: nowrap; 
}

.title-letter {
    display: flex; justify-content: center; align-items: center;
    font-weight: 700; color: white;
    border-radius: 12px;
    width: 50px; height: 50px;
    font-size: 1.8rem;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.15);
    flex-shrink: 0; /* Prevent squishing */
}

.bg-maroon { background-color: var(--maroon); }
.bg-red { background-color: var(--red); }
.bg-orange { background-color: var(--orange); }
.bg-black { background-color: var(--black); }

.title-letter-x {
    font-size: 3.5rem; font-weight: 800; color: var(--maroon);
    margin-left: 10px;
    text-shadow: 2px 2px 0px rgba(0,0,0,0.1);
}

.button-group { 
    display: flex; flex-direction: column; gap: 15px; 
    width: 100%; max-width: 320px; 
}

.credits-section {
    position: absolute; bottom: 30px;
    text-align: center; width: 100%;
}
.made-by { font-size: 0.9rem; color: var(--text-muted); margin-bottom: 2px; }
.role-title { font-size: 0.75rem; color: var(--maroon); font-weight: 700; text-transform: uppercase; letter-spacing: 1px; }

/* ========================================= */
/* 5. BUTTONS                                */
/* ========================================= */
.button {
    border: none; border-radius: 14px;
    font-weight: 600; font-size: 1rem;
    cursor: pointer; padding: 16px 20px;
    text-decoration: none; text-align: center;
    display: inline-block; transition: all 0.2s ease;
    box-shadow: var(--shadow-sm);
    -webkit-tap-highlight-color: transparent;
}
.button:active { transform: scale(0.98); }

.button-primary {
    background: linear-gradient(135deg, var(--maroon) 0%, var(--maroon-light) 100%);
    color: white;
}

.button-secondary {
    background: white; border: 2px solid #f0f0f0; color: var(--text-main);
}
.button-secondary:active { background-color: #f5f5f5; }

.button-danger { background: #ffebee; color: var(--error); }
.button-small { padding: 8px 16px; font-size: 0.85rem; border-radius: 10px; }
.full-width-btn { width: 100%; }

/* ========================================= */
/* 6. PUZZLE & GAME LAYOUT                   */
/* ========================================= */
.puzzle-container { 
    flex: 1; padding: 25px; 
    display: flex; flex-direction: column; 
    animation: fadeIn 0.4s ease-out;
}
@keyframes fadeIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }

.gate-content { 
    text-align: center; padding: 40px 20px; 
    background: white; border-radius: var(--radius-l);
    border: 1px solid var(--border-light);
    box-shadow: var(--shadow-sm);
    width: 100%;
}
.gate-content h1 { color: var(--maroon); font-size: 2rem; margin-bottom: 10px; }
.gate-content p { color: var(--text-muted); margin-bottom: 25px; }

.player-input, .answer-field {
    width: 100%; 
    box-sizing: border-box;
    padding: 15px; 
    font-size: 16px; 
    margin-bottom: 15px; 
    text-align: center;
    border: 2px solid var(--border-light); 
    border-radius: 14px;
    background: #f9f9f9; 
    color: var(--text-main); 
    outline: none; 
    font-weight: 600;
    -webkit-appearance: none; appearance: none;
}
.player-input:focus, .answer-field:focus { 
    border-color: var(--maroon); 
    background: #ffffff;
    box-shadow: 0 4px 12px rgba(128, 0, 0, 0.1); 
}
.player-input::placeholder, .answer-field::placeholder { color: #999; font-weight: 400; }

.puzzle-body { padding-bottom: 100px; } 

.puzzle-question {
    font-size: 1.1rem; line-height: 1.6; color: var(--text-main);
    margin-bottom: 25px; font-weight: 500;
    background: white; padding: 20px; border-radius: var(--radius-l);
    box-shadow: var(--shadow-sm); border: 1px solid rgba(0,0,0,0.03);
    word-wrap: break-word;
}

/* FIX: Footer Class for Game Pages */
.puzzle-footer {
    position: fixed; bottom: 0; 
    left: 50%; transform: translateX(-50%); /* Center horizontally */
    width: 100%; max-width: var(--app-max-width);
    padding: 15px 20px; 
    background: white; 
    border-top: 1px solid #eee; 
    display: flex; justify-content: space-between; align-items: center;
    z-index: 90;
    box-shadow: 0 -4px 10px rgba(0,0,0,0.05);
}

.mcq-grid { display: grid; gap: 12px; }
.button-mcq {
    display: flex; align-items: center; width: 100%; padding: 16px;
    text-align: left; font-size: 1rem; border-radius: 14px;
    border: 2px solid transparent; background: white;
    box-shadow: var(--shadow-sm); color: var(--text-main);
    cursor: pointer; transition: all 0.2s;
    -webkit-tap-highlight-color: transparent;
}
.button-mcq:active { background-color: #f8f8f8; transform: scale(0.99); border-color: var(--border-light); }

.mcq-letter {
    background: #f0f2f5; color: var(--black); 
    width: 28px; height: 28px; display: flex; align-items: center; justify-content: center;
    border-radius: 8px; margin-right: 15px; font-weight: 700; font-size: 0.85rem;
    flex-shrink: 0;
}

.difficulty-badge {
    display: inline-block; font-size: 0.7rem; font-weight: 800;
    color: white; padding: 4px 10px; border-radius: 6px;
    text-transform: uppercase; letter-spacing: 1px;
}
.difficulty-badge.easy { background-color: var(--success); }
.difficulty-badge.medium { background-color: var(--orange); }
.difficulty-badge.hard { background-color: var(--red); }

/* ========================================= */
/* 7. LEADERBOARD                            */
/* ========================================= */
.leaderboard-container { padding: 30px 20px; width: 100%; }
.leaderboard-item {
    display: flex; align-items: center; background: white; padding: 15px;
    margin-bottom: 12px; border-radius: 16px;
    box-shadow: var(--shadow-sm);
}
.rank-box {
    width: 35px; height: 35px; display: flex; justify-content: center; align-items: center;
    font-weight: 700; font-size: 1rem; color: #666; background: #f5f6fa;
    border-radius: 50%; margin-right: 12px;
}

/* ========================================= */
/* 8. MODALS & OVERLAYS                      */
/* ========================================= */
.modal-overlay {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.5); z-index: 2000;
    display: none; justify-content: center; align-items: center;
    backdrop-filter: blur(5px);
    padding: 20px;
}
.modal-open { display: flex; animation: fadeIn 0.2s; }

.modal-content {
    background: white; width: 100%; max-width: 380px;
    padding: 30px; border-radius: 24px; text-align: center;
    box-shadow: var(--shadow-lg); position: relative;
    max-height: 90vh; overflow-y: auto;
}
.modal-close { position: absolute; top: 15px; right: 20px; font-size: 2rem; background: none; border: none; cursor: pointer; color: #999; }

.explanation-sheet {
    position: fixed; bottom: -100%; 
    left: 50%; transform: translateX(-50%); /* Centered sheet */
    width: 100%; max-width: var(--app-max-width);
    background: white; border-radius: 24px 24px 0 0;
    box-shadow: 0 -10px 40px rgba(0,0,0,0.15); z-index: 1000;
    transition: bottom 0.4s cubic-bezier(0.2, 0.8, 0.2, 1);
    display: flex; flex-direction: column; max-height: 85vh;
}
.explanation-sheet.active { bottom: 0; }

/* ========================================= */
/* 9. MEDIA QUERIES (MOBILE)                 */
/* ========================================= */
/* Fix for very small screens (iPhone SE, etc) */
@media (max-width: 380px) {
    .title-letter { width: 40px; height: 40px; font-size: 1.4rem; }
    .title-letter-x { font-size: 2.5rem; }
    .organization-title { font-size: 1.5rem; letter-spacing: 0.3rem; }
    .button { padding: 14px; font-size: 0.95rem; }
    .gate-content h1 { font-size: 1.6rem; }
    .nav-link { font-size: 0.85rem; }
    .puzzle-question { font-size: 1rem; padding: 15px; }
}
/* ========================================= */
/*  LEADERBOARD ENHANCEMENTS                 */
/* ========================================= */

/* Tab Switcher (Segmented Control) */
.leaderboard-tabs {
    display: flex;
    background: #e0e0e0;
    padding: 4px;
    border-radius: 16px;
    margin-bottom: 25px;
    position: relative;
}

.tab-button {
    flex: 1;
    padding: 10px;
    border: none;
    background: transparent;
    color: #666;
    font-weight: 600;
    font-size: 0.9rem;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.3s ease;
    z-index: 2;
}

.tab-button.active {
    background: white;
    color: var(--maroon);
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

/* Header Row */
.leaderboard-header-row {
    display: flex;
    justify-content: space-between;
    padding: 0 15px 10px 15px;
    color: #999;
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1px;
}

/* List Items */
.leaderboard-list {
    list-style: none;
    padding: 0;
}

.leaderboard-item {
    display: flex;
    align-items: center;
    background: white;
    padding: 16px;
    margin-bottom: 10px;
    border-radius: 18px;
    box-shadow: 0 2px 5px rgba(0,0,0,0.03);
    transition: transform 0.2s;
    border: 1px solid transparent;
}

/* Rank Circle */
.rank-box {
    width: 32px; height: 32px;
    display: flex; justify-content: center; align-items: center;
    font-weight: 700; font-size: 0.9rem;
    color: #777;
    background: #f0f2f5;
    border-radius: 50%;
    margin-right: 15px;
    flex-shrink: 0;
}

/* Top 3 Styling (Gold, Silver, Bronze) */
.leaderboard-item:nth-child(1) { border: 1px solid #FFD700; background: linear-gradient(to right, #fff, #fffdf0); }
.leaderboard-item:nth-child(1) .rank-box { background: #FFD700; color: white; text-shadow: 0 1px 2px rgba(0,0,0,0.2); }

.leaderboard-item:nth-child(2) { border: 1px solid #C0C0C0; }
.leaderboard-item:nth-child(2) .rank-box { background: #C0C0C0; color: white; }

.leaderboard-item:nth-child(3) { border: 1px solid #CD7F32; }
.leaderboard-item:nth-child(3) .rank-box { background: #CD7F32; color: white; }

/* Player Name & Score */
.player-info {
    flex: 1;
    display: flex;
    flex-direction: column;
}
.player-name { font-weight: 600; color: var(--text-main); font-size: 1rem; }
.player-sub { font-size: 0.8rem; color: #999; }

.score-display {
    font-family: 'Courier New', monospace; /* Monospace for number alignment */
    font-weight: 700;
    font-size: 1.1rem;
    color: var(--maroon);
}


/* ========================================= */
/*  INFO PAGE ENHANCEMENTS                   */
/* ========================================= */

.info-header {
    text-align: center;
    margin-bottom: 30px;
}
.info-icon {
    font-size: 3rem;
    margin-bottom: 10px;
    display: inline-block;
    background: white;
    width: 80px; height: 80px;
    line-height: 80px;
    border-radius: 50%;
    box-shadow: var(--shadow-md);
}

.info-card {
    background: white;
    border-radius: 16px;
    padding: 25px;
    margin-bottom: 20px;
    box-shadow: var(--shadow-sm);
    border-left: 5px solid var(--maroon); /* Brand Accent */
    transition: transform 0.2s;
}
.info-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }

.info-card h2 {
    font-size: 1.1rem;
    color: var(--black);
    margin-bottom: 10px;
    display: flex; align-items: center; gap: 8px;
}

.info-card p {
    font-size: 0.95rem;
    line-height: 1.6;
    color: #555;
}

.creator-badge {
    display: flex;
    align-items: center;
    gap: 15px;
    margin-top: 15px;
    background: #f9f9f9;
    padding: 10px;
    border-radius: 12px;
}
.creator-avatar {
    width: 40px; height: 40px;
    background: var(--maroon);
    color: white;
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-weight: bold;
}
/* --- SCRATCHPAD BUTTON FIX --- */
.fab-scratchpad {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background-color: var(--maroon);
    color: white;
    font-size: 1.5rem;
    border: none;
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
    cursor: pointer;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s;
}

.fab-scratchpad:active {
    transform: scale(0.9);
}

.scratchpad-overlay {
    display: none;
    position: fixed;
    top: 0; left: 0;
    width: 100vw; height: 100vh;
    background: rgba(0,0,0,0.85);
    z-index: 2100; /* Above modals */
}

.scratchpad-header {
    position: absolute;
    top: 20px;
    left: 20px;
    right: 20px;
    display: flex;
    justify-content: space-between;
    pointer-events: none; /* Let clicks pass through to canvas if needed, but buttons catch them */
}

.scratchpad-header button {
    pointer-events: auto;
}

#scratchpad-canvas {
    display: block;
    width: 100%;
    height: 100%;
    cursor: crosshair;
}
/* Add to style.css */
.puzzle-context {
    background-color: #f8f9fa;
    border-left: 4px solid var(--maroon);
    padding: 15px;
    margin-bottom: 15px;
    font-size: 0.95rem;
    line-height: 1.6;
    color: #333;
    border-radius: 4px;
    font-family: 'Georgia', serif; /* Reading passages look better in Serif */
    text-align: left;
    white-space: pre-wrap; /* Preserves paragraphs */
}

.puzzle-question-text {
    font-weight: 600;
    font-size: 1.1rem;
    margin-bottom: 15px;
    color: var(--black);
}
/* --- DRAGGABLE DESMOS MODAL --- */
#desmos-modal {
    background: transparent; /* No dark backdrop */
    pointer-events: none;    /* Allow clicking the question behind the empty space */
    justify-content: flex-end; /* Default to right side */
    align-items: flex-start;   /* Default to top */
    padding: 20px;
}

#desmos-modal .modal-content {
    pointer-events: auto; /* Re-enable clicking on the calculator itself */
    width: 90vw;
    max-width: 500px;
    height: 400px; /* Smaller default height so it doesn't cover everything */
    border: 2px solid var(--maroon);
    box-shadow: 0 10px 30px rgba(0,0,0,0.3);
    position: absolute; /* Needed for dragging */
    top: 60px; /* Initial position */
    right: 20px;
    resize: both; /* Allow resizing */
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

/* The Handle Bar */
.desmos-header-handle {
    background: var(--maroon);
    color: white;
    padding: 8px 15px;
    cursor: move; /* Shows move cursor */
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.9rem;
    font-weight: bold;
    user-select: none;
}

.desmos-header-handle:active {
    cursor: grabbing;
}
/* ========================================= */
/* 10. EXPLANATION STEPS AESTHETIC           */
/* ========================================= */
.explanation-container {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-top: 10px;
    text-align: left;
}

.step-card {
    background: white;
    border: 1px solid #eee;
    border-radius: 12px;
    padding: 12px 16px;
    display: flex;
    align-items: flex-start;
    gap: 12px;
    box-shadow: 0 2px 5px rgba(0,0,0,0.03);
    transition: transform 0.2s;
}

.step-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0,0,0,0.05);
}

.step-badge {
    background: var(--maroon);
    color: white;
    font-weight: 700;
    font-size: 0.8rem;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    margin-top: 2px;
}

.step-text {
    font-size: 0.95rem;
    color: #444;
    line-height: 1.5;
}

/* Conclusion Card (Green) */
.step-card.conclusion {
    background: #f0fdf4; /* Light Green */
    border-color: var(--success);
}

.step-card.conclusion .step-badge {
    background: var(--success);
}
--- START OF FILE style.css ---

/* ========================================= */
/* 1. GLOBAL VARIABLES & RESET               */
/* ========================================= */
:root {
    /* Brand Colors */
    --maroon: #800000;
    --maroon-light: #9a1a1a;
    --red: #D32F2F;
    --orange: #FB8C00;
    --yellow: #FBC02D;
    --black: #1a1a1a;
    
    /* UI Colors */
    --text-main: #2d3436;
    --text-muted: #636e72;
    --bg-body: #f4f6f8; 
    --bg-shell: #ffffff;
    --border-light: #e0e0e0;
    --success: #00b894;
    --error: #d63031;
    
    /* Spacing & Layout */
    --app-max-width: 500px;
    --header-height: 64px;
    --radius-l: 20px;
    --radius-m: 12px;
    --radius-s: 8px;
    
    /* Shadows */
    --shadow-sm: 0 2px 8px rgba(0,0,0,0.04);
    --shadow-md: 0 8px 24px rgba(0,0,0,0.08);
    --shadow-lg: 0 15px 35px rgba(0,0,0,0.1);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html { 
    height: 100%; 
    font-size: 16px;
    -webkit-text-size-adjust: 100%; /* Prevent font scaling in landscape */
}

body {
    font-family: 'Poppins', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background-color: var(--bg-body);
    color: var(--text-main);
    min-height: 100vh;
    min-height: 100dvh; 
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
    /* FIX: Removed flex display here to allow natural scrolling */
    display: block;
}

/* --- Background Animation --- */
.background-shapes {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    overflow: hidden; z-index: -1; pointer-events: none;
    background: radial-gradient(circle at top left, #fff0f0 0%, transparent 40%);
}

.shape {
    position: absolute; 
    color: var(--maroon);
    opacity: 0.03;
    font-weight: 800; 
    animation: float 25s infinite linear;
    user-select: none;
}
.shape:nth-child(1) { top: 10%; left: 10%; font-size: 4rem; animation-duration: 30s; }
.shape:nth-child(2) { top: 20%; left: 80%; font-size: 2rem; animation-duration: 25s; animation-delay: -5s; }
.shape:nth-child(3) { top: 60%; left: 15%; font-size: 5rem; animation-duration: 35s; animation-delay: -10s; }
.shape:nth-child(4) { top: 80%; left: 70%; font-size: 3rem; animation-duration: 28s; animation-delay: -2s; }
.shape:nth-child(5) { top: 40%; left: 45%; font-size: 2.5rem; animation-duration: 32s; animation-delay: -15s; }

@keyframes float {
    0% { transform: translateY(0) rotate(0deg); }
    100% { transform: translateY(-100vh) rotate(360deg); }
}

/* ========================================= */
/* 2. APP SHELL                              */
/* ========================================= */
.app-shell {
    position: relative;
    width: 100%;
    max-width: var(--app-max-width);
    min-height: 100vh;
    min-height: 100dvh;
    background-color: var(--bg-shell);
    box-shadow: var(--shadow-md);
    display: flex;
    flex-direction: column;
    /* FIX: This centers the app on desktop screens */
    margin: 0 auto;
}

/* ========================================= */
/* 3. HEADER                                 */
/* ========================================= */
.site-header {
    height: var(--header-height);
    padding: 0 20px;
    background-color: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border-light);
    position: sticky;
    top: 0;
    z-index: 100;
    display: flex;
    align-items: center;
}

.main-nav, .landing-nav {
    display: flex; 
    justify-content: space-between; 
    align-items: center; 
    width: 100%;
}

.nav-link, .nav-link-back {
    text-decoration: none; color: var(--text-main); 
    font-weight: 600; font-size: 0.95rem;
    transition: color 0.2s; cursor: pointer; border: none; background: none;
    padding: 10px 5px; 
}
.nav-link:hover { color: var(--maroon); }

.nav-link-back { 
    font-size: 1.1rem; 
    display: flex; align-items: center; gap: 5px;
    color: var(--text-muted);
}

.nav-tools { display: flex; gap: 10px; }
.tool-btn {
    background: #f1f2f6; 
    border: none;
    border-radius: 12px;
    width: 42px; height: 42px;
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    transition: all 0.2s ease;
    color: var(--text-muted);
}
.tool-btn svg { width: 22px; height: 22px; stroke-width: 2px; }
.tool-btn:active { transform: scale(0.95); background: #e1e2e6; }

/* ========================================= */
/* 4. LANDING PAGE                           */
/* ========================================= */
body.page-landing .site-header { background: transparent; border: none; }
body.page-landing .app-shell { box-shadow: none; background: transparent; }

.landing-container {
    flex: 1;
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    padding: 20px; gap: 2rem;
    /* FIX: Removed negative margin that broke mobile layout */
    margin-top: 0;
    padding-top: 40px; 
}

.organization-title {
    font-size: clamp(2rem, 6vw, 3rem);
    font-weight: 800;
    letter-spacing: 0.5rem;
    text-transform: uppercase;
    color: var(--text-muted);
    margin-bottom: -1.5rem;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 5px;
}
.organization-title span { display: inline-block; }

.title-container {
    display: flex; gap: 8px; justify-content: center; align-items: center;
    flex-wrap: nowrap; 
}

.title-letter {
    display: flex; justify-content: center; align-items: center;
    font-weight: 700; color: white;
    border-radius: 12px;
    width: 50px; height: 50px;
    font-size: 1.8rem;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.15);
    flex-shrink: 0; /* Prevent squishing */
}

.bg-maroon { background-color: var(--maroon); }
.bg-red { background-color: var(--red); }
.bg-orange { background-color: var(--orange); }
.bg-black { background-color: var(--black); }

.title-letter-x {
    font-size: 3.5rem; font-weight: 800; color: var(--maroon);
    margin-left: 10px;
    text-shadow: 2px 2px 0px rgba(0,0,0,0.1);
}

.button-group { 
    display: flex; flex-direction: column; gap: 15px; 
    width: 100%; max-width: 320px; 
}

.credits-section {
    position: absolute; bottom: 30px;
    text-align: center; width: 100%;
}
.made-by { font-size: 0.9rem; color: var(--text-muted); margin-bottom: 2px; }
.role-title { font-size: 0.75rem; color: var(--maroon); font-weight: 700; text-transform: uppercase; letter-spacing: 1px; }

/* ========================================= */
/* 5. BUTTONS                                */
/* ========================================= */
.button {
    border: none; border-radius: 14px;
    font-weight: 600; font-size: 1rem;
    cursor: pointer; padding: 16px 20px;
    text-decoration: none; text-align: center;
    display: inline-block; transition: all 0.2s ease;
    box-shadow: var(--shadow-sm);
    -webkit-tap-highlight-color: transparent;
}
.button:active { transform: scale(0.98); }

.button-primary {
    background: linear-gradient(135deg, var(--maroon) 0%, var(--maroon-light) 100%);
    color: white;
}

.button-secondary {
    background: white; border: 2px solid #f0f0f0; color: var(--text-main);
}
.button-secondary:active { background-color: #f5f5f5; }

.button-danger { background: #ffebee; color: var(--error); }
.button-small { padding: 8px 16px; font-size: 0.85rem; border-radius: 10px; }
.full-width-btn { width: 100%; }

/* ========================================= */
/* 6. PUZZLE & GAME LAYOUT                   */
/* ========================================= */
.puzzle-container { 
    flex: 1; padding: 25px; 
    display: flex; flex-direction: column; 
    animation: fadeIn 0.4s ease-out;
}
@keyframes fadeIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }

.gate-content { 
    text-align: center; padding: 40px 20px; 
    background: white; border-radius: var(--radius-l);
    border: 1px solid var(--border-light);
    box-shadow: var(--shadow-sm);
    width: 100%;
}
.gate-content h1 { color: var(--maroon); font-size: 2rem; margin-bottom: 10px; }
.gate-content p { color: var(--text-muted); margin-bottom: 25px; }

.player-input, .answer-field {
    width: 100%; 
    box-sizing: border-box;
    padding: 15px; 
    font-size: 16px; 
    margin-bottom: 15px; 
    text-align: center;
    border: 2px solid var(--border-light); 
    border-radius: 14px;
    background: #f9f9f9; 
    color: var(--text-main); 
    outline: none; 
    font-weight: 600;
    -webkit-appearance: none; appearance: none;
}
.player-input:focus, .answer-field:focus { 
    border-color: var(--maroon); 
    background: #ffffff;
    box-shadow: 0 4px 12px rgba(128, 0, 0, 0.1); 
}
.player-input::placeholder, .answer-field::placeholder { color: #999; font-weight: 400; }

.puzzle-body { padding-bottom: 100px; } 

.puzzle-question {
    font-size: 1.1rem; line-height: 1.6; color: var(--text-main);
    margin-bottom: 25px; font-weight: 500;
    background: white; padding: 20px; border-radius: var(--radius-l);
    box-shadow: var(--shadow-sm); border: 1px solid rgba(0,0,0,0.03);
    word-wrap: break-word;
}

/* FIX: Footer Class for Game Pages */
.puzzle-footer {
    position: fixed; bottom: 0; 
    left: 50%; transform: translateX(-50%); /* Center horizontally */
    width: 100%; max-width: var(--app-max-width);
    padding: 15px 20px; 
    background: white; 
    border-top: 1px solid #eee; 
    display: flex; justify-content: space-between; align-items: center;
    z-index: 90;
    box-shadow: 0 -4px 10px rgba(0,0,0,0.05);
}

.mcq-grid { display: grid; gap: 12px; }
.button-mcq {
    display: flex; align-items: center; width: 100%; padding: 16px;
    text-align: left; font-size: 1rem; border-radius: 14px;
    border: 2px solid transparent; background: white;
    box-shadow: var(--shadow-sm); color: var(--text-main);
    cursor: pointer; transition: all 0.2s;
    -webkit-tap-highlight-color: transparent;
}
.button-mcq:active { background-color: #f8f8f8; transform: scale(0.99); border-color: var(--border-light); }

.mcq-letter {
    background: #f0f2f5; color: var(--black); 
    width: 28px; height: 28px; display: flex; align-items: center; justify-content: center;
    border-radius: 8px; margin-right: 15px; font-weight: 700; font-size: 0.85rem;
    flex-shrink: 0;
}

.difficulty-badge {
    display: inline-block; font-size: 0.7rem; font-weight: 800;
    color: white; padding: 4px 10px; border-radius: 6px;
    text-transform: uppercase; letter-spacing: 1px;
}
.difficulty-badge.easy { background-color: var(--success); }
.difficulty-badge.medium { background-color: var(--orange); }
.difficulty-badge.hard { background-color: var(--red); }

/* ========================================= */
/* 7. LEADERBOARD                            */
/* ========================================= */
.leaderboard-container { padding: 30px 20px; width: 100%; }
.leaderboard-item {
    display: flex; align-items: center; background: white; padding: 15px;
    margin-bottom: 12px; border-radius: 16px;
    box-shadow: var(--shadow-sm);
}
.rank-box {
    width: 35px; height: 35px; display: flex; justify-content: center; align-items: center;
    font-weight: 700; font-size: 1rem; color: #666; background: #f5f6fa;
    border-radius: 50%; margin-right: 12px;
}

/* ========================================= */
/* 8. MODALS & OVERLAYS                      */
/* ========================================= */
.modal-overlay {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.5); z-index: 2000;
    display: none; justify-content: center; align-items: center;
    backdrop-filter: blur(5px);
    padding: 20px;
}
.modal-open { display: flex; animation: fadeIn 0.2s; }

.modal-content {
    background: white; width: 100%; max-width: 380px;
    padding: 30px; border-radius: 24px; text-align: center;
    box-shadow: var(--shadow-lg); position: relative;
    max-height: 90vh; overflow-y: auto;
}
.modal-close { position: absolute; top: 15px; right: 20px; font-size: 2rem; background: none; border: none; cursor: pointer; color: #999; }

.explanation-sheet {
    position: fixed; bottom: -100%; 
    left: 50%; transform: translateX(-50%); /* Centered sheet */
    width: 100%; max-width: var(--app-max-width);
    background: white; border-radius: 24px 24px 0 0;
    box-shadow: 0 -10px 40px rgba(0,0,0,0.15); z-index: 1000;
    transition: bottom 0.4s cubic-bezier(0.2, 0.8, 0.2, 1);
    display: flex; flex-direction: column; max-height: 85vh;
}
.explanation-sheet.active { bottom: 0; }

/* ========================================= */
/* 9. MEDIA QUERIES (MOBILE)                 */
/* ========================================= */
/* Fix for very small screens (iPhone SE, etc) */
@media (max-width: 380px) {
    .title-letter { width: 40px; height: 40px; font-size: 1.4rem; }
    .title-letter-x { font-size: 2.5rem; }
    .organization-title { font-size: 1.5rem; letter-spacing: 0.3rem; }
    .button { padding: 14px; font-size: 0.95rem; }
    .gate-content h1 { font-size: 1.6rem; }
    .nav-link { font-size: 0.85rem; }
    .puzzle-question { font-size: 1rem; padding: 15px; }
}
/* ========================================= */
/*  LEADERBOARD ENHANCEMENTS                 */
/* ========================================= */

/* Tab Switcher (Segmented Control) */
.leaderboard-tabs {
    display: flex;
    background: #e0e0e0;
    padding: 4px;
    border-radius: 16px;
    margin-bottom: 25px;
    position: relative;
}

.tab-button {
    flex: 1;
    padding: 10px;
    border: none;
    background: transparent;
    color: #666;
    font-weight: 600;
    font-size: 0.9rem;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.3s ease;
    z-index: 2;
}

.tab-button.active {
    background: white;
    color: var(--maroon);
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

/* Header Row */
.leaderboard-header-row {
    display: flex;
    justify-content: space-between;
    padding: 0 15px 10px 15px;
    color: #999;
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1px;
}

/* List Items */
.leaderboard-list {
    list-style: none;
    padding: 0;
}

.leaderboard-item {
    display: flex;
    align-items: center;
    background: white;
    padding: 16px;
    margin-bottom: 10px;
    border-radius: 18px;
    box-shadow: 0 2px 5px rgba(0,0,0,0.03);
    transition: transform 0.2s;
    border: 1px solid transparent;
}

/* Rank Circle */
.rank-box {
    width: 32px; height: 32px;
    display: flex; justify-content: center; align-items: center;
    font-weight: 700; font-size: 0.9rem;
    color: #777;
    background: #f0f2f5;
    border-radius: 50%;
    margin-right: 15px;
    flex-shrink: 0;
}

/* Top 3 Styling (Gold, Silver, Bronze) */
.leaderboard-item:nth-child(1) { border: 1px solid #FFD700; background: linear-gradient(to right, #fff, #fffdf0); }
.leaderboard-item:nth-child(1) .rank-box { background: #FFD700; color: white; text-shadow: 0 1px 2px rgba(0,0,0,0.2); }

.leaderboard-item:nth-child(2) { border: 1px solid #C0C0C0; }
.leaderboard-item:nth-child(2) .rank-box { background: #C0C0C0; color: white; }

.leaderboard-item:nth-child(3) { border: 1px solid #CD7F32; }
.leaderboard-item:nth-child(3) .rank-box { background: #CD7F32; color: white; }

/* Player Name & Score */
.player-info {
    flex: 1;
    display: flex;
    flex-direction: column;
}
.player-name { font-weight: 600; color: var(--text-main); font-size: 1rem; }
.player-sub { font-size: 0.8rem; color: #999; }

.score-display {
    font-family: 'Courier New', monospace; /* Monospace for number alignment */
    font-weight: 700;
    font-size: 1.1rem;
    color: var(--maroon);
}


/* ========================================= */
/*  INFO PAGE ENHANCEMENTS                   */
/* ========================================= */

.info-header {
    text-align: center;
    margin-bottom: 30px;
}
.info-icon {
    font-size: 3rem;
    margin-bottom: 10px;
    display: inline-block;
    background: white;
    width: 80px; height: 80px;
    line-height: 80px;
    border-radius: 50%;
    box-shadow: var(--shadow-md);
}

.info-card {
    background: white;
    border-radius: 16px;
    padding: 25px;
    margin-bottom: 20px;
    box-shadow: var(--shadow-sm);
    border-left: 5px solid var(--maroon); /* Brand Accent */
    transition: transform 0.2s;
}
.info-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }

.info-card h2 {
    font-size: 1.1rem;
    color: var(--black);
    margin-bottom: 10px;
    display: flex; align-items: center; gap: 8px;
}

.info-card p {
    font-size: 0.95rem;
    line-height: 1.6;
    color: #555;
}

.creator-badge {
    display: flex;
    align-items: center;
    gap: 15px;
    margin-top: 15px;
    background: #f9f9f9;
    padding: 10px;
    border-radius: 12px;
}
.creator-avatar {
    width: 40px; height: 40px;
    background: var(--maroon);
    color: white;
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-weight: bold;
}
/* --- SCRATCHPAD BUTTON FIX --- */
.fab-scratchpad {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background-color: var(--maroon);
    color: white;
    font-size: 1.5rem;
    border: none;
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
    cursor: pointer;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s;
}

.fab-scratchpad:active {
    transform: scale(0.9);
}

.scratchpad-overlay {
    display: none;
    position: fixed;
    top: 0; left: 0;
    width: 100vw; height: 100vh;
    background: rgba(0,0,0,0.85);
    z-index: 2100; /* Above modals */
}

.scratchpad-header {
    position: absolute;
    top: 20px;
    left: 20px;
    right: 20px;
    display: flex;
    justify-content: space-between;
    pointer-events: none; /* Let clicks pass through to canvas if needed, but buttons catch them */
}

.scratchpad-header button {
    pointer-events: auto;
}

#scratchpad-canvas {
    display: block;
    width: 100%;
    height: 100%;
    cursor: crosshair;
}
/* Add to style.css */
.puzzle-context {
    background-color: #f8f9fa;
    border-left: 4px solid var(--maroon);
    padding: 15px;
    margin-bottom: 15px;
    font-size: 0.95rem;
    line-height: 1.6;
    color: #333;
    border-radius: 4px;
    font-family: 'Georgia', serif; /* Reading passages look better in Serif */
    text-align: left;
    white-space: pre-wrap; /* Preserves paragraphs */
}

.puzzle-question-text {
    font-weight: 600;
    font-size: 1.1rem;
    margin-bottom: 15px;
    color: var(--black);
}
/* --- DRAGGABLE DESMOS MODAL --- */
#desmos-modal {
    background: transparent; /* No dark backdrop */
    pointer-events: none;    /* Allow clicking the question behind the empty space */
    justify-content: flex-end; /* Default to right side */
    align-items: flex-start;   /* Default to top */
    padding: 20px;
}

#desmos-modal .modal-content {
    pointer-events: auto; /* Re-enable clicking on the calculator itself */
    width: 90vw;
    max-width: 500px;
    height: 400px; /* Smaller default height so it doesn't cover everything */
    border: 2px solid var(--maroon);
    box-shadow: 0 10px 30px rgba(0,0,0,0.3);
    position: absolute; /* Needed for dragging */
    top: 60px; /* Initial position */
    right: 20px;
    resize: both; /* Allow resizing */
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

/* The Handle Bar */
.desmos-header-handle {
    background: var(--maroon);
    color: white;
    padding: 8px 15px;
    cursor: move; /* Shows move cursor */
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.9rem;
    font-weight: bold;
    user-select: none;
}

.desmos-header-handle:active {
    cursor: grabbing;
}
/* ========================================= */
/* 10. EXPLANATION STEPS AESTHETIC           */
/* ========================================= */
.explanation-container {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-top: 10px;
    text-align: left;
}

.step-card {
    background: white;
    border: 1px solid #eee;
    border-radius: 12px;
    padding: 12px 16px;
    display: flex;
    align-items: flex-start;
    gap: 12px;
    box-shadow: 0 2px 5px rgba(0,0,0,0.03);
    transition: transform 0.2s;
}

.step-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0,0,0,0.05);
}

.step-badge {
    background: var(--maroon);
    color: white;
    font-weight: 700;
    font-size: 0.8rem;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    margin-top: 2px;
}

.step-text {
    font-size: 0.95rem;
    color: #444;
    line-height: 1.5;
}

/* Conclusion Card (Green) */
.step-card.conclusion {
    background: #f0fdf4; /* Light Green */
    border-color: var(--success);
}

.step-card.conclusion .step-badge {
    background: var(--success);
}
/* ====================================================== */
/*  RESPONSIVE PATCH (ADD TO BOTTOM OF STYLE.CSS)         */
/*  Adapts layout for Mobile (SE/Fold), Tablet, & Desktop */
/* ====================================================== */

:root {
    /* Updates max-width to be fluid on mobile but constrained on desktop */
    --app-max-width: min(100vw, 550px);
    --header-height: clamp(56px, 8vh, 64px);
}

/* 1. FLUID VIEWPORT & CENTERING */
html, body {
    /* Fixes scrolling issues on mobile browsers with dynamic toolbars */
    min-height: 100vh;
    min-height: 100dvh; 
}

body {
    /* Centers the app on large desktop screens like a mobile app */
    display: flex;
    flex-direction: column;
    align-items: center;
    background-color: var(--bg-body); /* Ensures edges aren't white */
}

/* 2. APP SHELL CONSTRAINTS */
.app-shell {
    width: 100%;
    max-width: var(--app-max-width);
    /* Shadow only visible on Desktop */
    box-shadow: 0 0 40px rgba(0,0,0,0.1); 
    min-height: 100dvh;
}

/* 3. FLUID TYPOGRAPHY (Scales text between Phone and Desktop sizes) */
html { font-size: 16px; }

h1 { font-size: clamp(1.5rem, 6vw, 2.2rem); }
h2 { font-size: clamp(1.2rem, 5vw, 1.6rem); }
p, .puzzle-question { font-size: clamp(0.95rem, 3vw, 1.1rem); }
.button { font-size: clamp(0.9rem, 3vw, 1rem); padding: clamp(12px, 2vh, 16px) 20px; }

/* 4. PREVENT ZOOM ON INPUTS (iOS Fix) */
input, textarea, .player-input, .answer-field {
    font-size: 16px !important; /* Prevents auto-zoom on focus */
}

/* 5. MINESWEEPER GRID FIXES */
/* Force the grid to fit the screen, ignoring the JS 32px hardcoding */
.ms-grid {
    width: 100% !important;
    max-width: 380px !important;
    margin: 0 auto;
    /* Forces columns to equal fraction widths instead of fixed px */
    grid-template-columns: repeat(10, 1fr) !important; 
    aspect-ratio: 10/12; /* Keeps cells square based on standard 10x12 grid */
    height: auto !important;
}

.ms-cell {
    width: auto !important;
    height: auto !important;
    aspect-ratio: 1/1; /* Forces perfect squares */
    font-size: clamp(0.8rem, 4vw, 1.2rem) !important;
}

.game-board-container {
    padding: 0 10px;
    overflow: hidden; /* Prevents scrollbars */
}

/* 6. MODAL & SHEET RESPONSIVENESS */
.modal-content {
    width: 90%;
    max-width: 400px;
    max-height: 85dvh; /* Fits within mobile viewports */
    overflow-y: auto;
}

.explanation-sheet {
    max-width: var(--app-max-width);
    /* Ensures it doesn't stretch full width on desktop */
    left: 50%;
    transform: translateX(-50%) translateY(110%);
}
.explanation-sheet.sheet-open {
    transform: translateX(-50%) translateY(0);
}

.puzzle-footer {
    width: 100%;
    max-width: var(--app-max-width);
    left: 50%;
    transform: translateX(-50%);
}

/* 7. LANDSCAPE MODE FIXES (For Phones turned sideways) */
@media (max-height: 500px) and (orientation: landscape) {
    .site-header { height: 45px; }
    .landing-container { padding-top: 10px; gap: 10px; }
    .organization-title { font-size: 1.5rem; margin: 0; }
    .title-container { transform: scale(0.8); }
    .button-group { flex-direction: row; flex-wrap: wrap; justify-content: center; }
    .button { padding: 8px 16px; }
    .shape { display: none; } /* Hide background animations to save space */
    .modal-content { 
        display: grid; 
        grid-template-columns: 1fr 1fr; 
        gap: 15px; 
        align-items: center;
    }
}
/* ========================================= */
/*  FORMULA SHEET & MODAL STYLING            */
/* ========================================= */

.ref-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    margin-bottom: 20px;
}

.ref-card {
    background: #ffffff;
    border: 1px solid #e0e0e0;
    padding: 12px;
    border-radius: 12px;
    text-align: left;
    display: flex;
    flex-direction: column;
    justify-content: center;
    box-shadow: 0 2px 5px rgba(0,0,0,0.02);
    transition: transform 0.2s;
}

.ref-card:active {
    transform: scale(0.98);
}

.ref-title {
    font-size: 0.75rem;
    font-weight: 700;
    color: #888;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 4px;
    display: block;
}

.ref-content {
    font-size: 1rem;
    color: var(--black);
}

/* Ensure MathJax fits inside cards */
mjx-container {
    font-size: 1.1rem !important;
}