:root {
    --bg-color: #0d1117;
    --panel-bg: #161b22;
    --tile-bg: #21262d;
    --border-color: #30363d;
    --text-color: #ffffff;
    --accent-color: #58a6ff;
    --win-color: #00ff66;
    --fail-color: #ff5555;
    --modal-overlay: rgba(13, 17, 23, 0.98);
    --modal-blur: blur(8px);
    --charcoal-white: #cfd4dc;
}

body {
    background: var(--bg-color);
    color: var(--text-color);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, monospace, sans-serif;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 75px 12px 20px 12px; /* Generous top padding prevents back button collision */
    margin: 0;
    box-sizing: border-box;
    user-select: none;
    overflow-x: hidden; /* Hard block against mobile layout squashing layout breaks */
}

/* CLASSROOM LANDING HEADER */
.class-header {
    font-size: 0.9rem;
    color: var(--charcoal-white);
    letter-spacing: 3px;
    text-transform: uppercase;
    font-weight: 500;
    margin-bottom: 15px;
    opacity: 0.85;
    text-align: center;
}

/* FIXED TOP LEFT MAIN MENU NAVIGATION BUTTON */
.menu-back-btn {
    position: fixed; /* Secure lock unaffected by window scrolling */
    top: 15px;
    left: 15px;
    background: var(--tile-bg);
    color: var(--charcoal-white);
    border: 1px solid var(--border-color);
    padding: 8px 14px;
    border-radius: 4px;
    cursor: pointer;
    font-family: monospace;
    font-size: 0.8rem;
    letter-spacing: 1px;
    transition: all 0.2s;
    z-index: 2000; /* Force overlay priority above modal windows */
}
.menu-back-btn:hover {
    border-color: var(--accent-color);
    color: var(--text-color);
    background: var(--border-color);
}

/* DASHBOARD MENU SYSTEM */
.menu-view {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 80vh;
    width: 100%;
    max-width: 500px;
    box-sizing: border-box;
    animation: fadeIn 0.4s ease-out;
}

.menu-title {
    font-size: 1.8rem;
    font-weight: 300;
    letter-spacing: 6px;
    margin-bottom: 10px;
    text-align: center;
    color: var(--text-color);
}

.menu-subtitle {
    font-size: 0.85rem;
    color: #8b949e;
    margin-bottom: 40px;
    letter-spacing: 2px;
    text-transform: uppercase;
}

.menu-card {
    background: var(--panel-bg);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 24px;
    margin-bottom: 20px;
    width: 100%;
    box-sizing: border-box;
    cursor: pointer;
    transition: transform 0.2s, border-color 0.2s, box-shadow 0.2s;
    text-align: left;
}

.menu-card:hover {
    transform: translateY(-2px);
    border-color: var(--accent-color);
    box-shadow: 0 6px 20px rgba(88, 166, 255, 0.1);
}

.menu-card h2 {
    font-size: 1.15rem;
    font-weight: 400;
    letter-spacing: 2px;
    margin: 0 0 8px 0;
    color: var(--text-color);
}

.menu-card p {
    font-size: 0.85rem;
    color: #8b949e;
    line-height: 1.6;
    margin: 0;
}

.menu-card-action {
    margin-top: 15px;
    font-size: 0.75rem;
    font-family: monospace;
    font-weight: 600;
    letter-spacing: 2px;
    color: var(--accent-color);
    text-align: right;
    transition: color 0.2s;
}

.menu-card:hover .menu-card-action {
    color: var(--win-color);
    text-shadow: 0 0 8px rgba(0, 255, 102, 0.3);
}

/* GENERAL ARCHITECTURE */
.game-view-container {
    position: relative;
    display: none;
    width: 100%;
    flex-direction: column;
    align-items: center;
    animation: fadeIn 0.3s ease-out;
}

h1 {
    font-size: 1.6rem;
    font-weight: 300;
    letter-spacing: 5px;
    margin: 0 0 15px 0;
    text-align: center;
}

.instruction {
    font-size: 0.95rem;
    color: #e1b12c;
    margin-bottom: 25px;
    text-align: center;
    letter-spacing: 0.5px;
    font-weight: 500;
    max-width: 600px;
    line-height: 1.4;
}

.stats-panel {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: transparent;
    padding: 0 10px;
    width: 100%;
    max-width: 600px;
    margin-bottom: 12px;
    font-family: monospace;
    font-size: 0.95rem;
    box-sizing: border-box;
}

.controls {
    display: flex;
    justify-content: center;
    gap: 10px;
    margin-bottom: 25px;
}

.btn {
    background: var(--tile-bg);
    color: var(--text-color);
    border: 1px solid var(--border-color);
    padding: 8px 16px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.85rem;
    letter-spacing: 1px;
    transition: background 0.2s, border-color 0.2s;
}
.btn:hover, .btn:active {
    background: var(--border-color);
    border-color: #8b949e;
}

.panel-label {
    font-size: 0.75rem;
    letter-spacing: 3px;
    color: #8b949e;
    margin-bottom: 12px;
    text-transform: uppercase;
    font-weight: 600;
}

/* EQUILIBRIUM SPECIFIC STYLES */
#equilibrium-app .goals {
    background: var(--panel-bg);
    padding: 14px 20px;
    border-radius: 6px;
    border: 1px solid var(--border-color);
    text-align: center;
    margin-bottom: 10px;
    font-size: 1.15rem;
    letter-spacing: 1px;
    width: 100%;
    max-width: 520px;
    box-sizing: border-box;
}

#equilibrium-app .container {
    display: flex;
    flex-direction: row; 
    justify-content: center;
    gap: 30px;
    width: 100%;
    max-width: 540px;
}

#equilibrium-app .board-wrapper {
    display: flex;
    flex-direction: column;
    align-items: center;
    flex: 1;
}

#equilibrium-app h3 {
    font-size: 0.8rem;
    font-weight: 500;
    letter-spacing: 2px;
    margin: 0 0 10px 0;
    color: #8b949e;
}

#equilibrium-app .grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 6px;
    background: var(--panel-bg);
    padding: 8px;
    border-radius: 6px;
    border: 1px solid var(--border-color);
    width: 230px;
    height: 230px;
    box-sizing: border-box;
}

#equilibrium-app .tile {
    aspect-ratio: 1;
    background: var(--tile-bg);
    border: 1px solid transparent;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.4rem;
    font-weight: 400;
    cursor: pointer;
    border-radius: 4px;
    user-select: none;
    transition: background 0.15s, border-color 0.15s;
    -webkit-tap-highlight-color: transparent;
}
#equilibrium-app .tile:hover {
    background: #30363d;
}

#equilibrium-app .empty {
    background: transparent;
    border: 1px dashed var(--border-color);
    cursor: default;
}
#equilibrium-app .empty:hover {
    background: transparent;
}

#equilibrium-app .correct {
    border-color: rgba(0, 255, 102, 0.4);
    color: #00ff66;
    background: rgba(0, 255, 102, 0.02);
}

#equilibrium-app .status {
    margin-top: 10px;
    font-weight: 500;
    font-size: 0.75rem;
    letter-spacing: 1.5px;
}
#equilibrium-app .solved { color: #00ff66; }
#equilibrium-app .unsolved { color: #8b949e; }

/* FLOW MATRIX SPECIFIC STYLES */
#flowmatrix-app .game-container {
    display: flex;
    flex-direction: row;
    gap: 40px;
    align-items: center;
    justify-content: center;
    width: 100%;
}

/* INTERACTIVE SWIPE LAYER */
#puzzleCanvas {
    background: #10141b;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    max-width: 100%;
    height: auto !important;
    touch-action: none; /* Block browser tracking layers while moving game tiles */
}

/* BLUEPRINT CARD LAYER - AUTOMATICALLY ALLOWS SCREEN SWIPING FOR COMFORT */
#targetCanvas {
    background: #10141b;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    max-width: 100%;
    height: auto !important;
    touch-action: auto; /* Free navigation: finger lands here to slide down the window */
}

/* MODAL & OVERLAY SYSTEM */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--modal-overlay);
    backdrop-filter: var(--modal-blur);
    -webkit-backdrop-filter: var(--modal-blur);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 3000; /* Stays above the fixed back button elements */
}

.modal-content {
    background: var(--bg-color);
    border: 1px solid var(--border-color);
    padding: 35px 25px;
    border-radius: 8px;
    text-align: center;
    max-width: 380px;
    width: 85%;
    box-sizing: border-box;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.6);
}

.modal-content h2 {
    font-size: 1.1rem;
    font-weight: 400;
    letter-spacing: 3px;
    margin: 0 0 20px 0;
}

.intro-text {
    color: #8b949e;
    font-size: 0.85rem;
    line-height: 1.6;
    margin-bottom: 25px;
    letter-spacing: 0.5px;
    text-align: center;
}

.flow-step {
    display: none;
    flex-direction: column;
    gap: 12px;
}
.flow-step.active {
    display: flex;
}

.flow-btn {
    background: var(--panel-bg);
    color: var(--text-color);
    border: 1px solid var(--border-color);
    padding: 14px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.85rem;
    letter-spacing: 1px;
    transition: all 0.2s;
}
.flow-btn:hover {
    border-color: var(--accent-color);
    background: rgba(88, 166, 255, 0.04);
}

.modal-stats {
    display: flex;
    justify-content: space-around;
    font-family: monospace;
    font-size: 1rem;
    margin: 20px 0;
    color: #fff;
}

.toast {
    position: fixed;
    bottom: 30px;
    background: #fff;
    color: #111;
    padding: 10px 20px;
    border-radius: 4px;
    font-size: 0.85rem;
    letter-spacing: 1px;
    font-weight: 500;
    opacity: 0;
    transform: translateY(10px);
    transition: all 0.3s ease;
    pointer-events: none;
    z-index: 4000;
}
.toast.show {
    opacity: 1;
    transform: translateY(0);
}



/* RESPONSIVE LAYOUT CONTEXT BREAKS */
@media (max-width: 640px) {
    body {
        padding-top: 60px; /* Tighten up workspace footprint padding */
    }

    h1 {
        font-size: 1.3rem;
        margin-bottom: 4px;
        letter-spacing: 3px;
    }

    .instruction {
        font-size: 0.8rem;
        margin-bottom: 10px;
        line-height: 1.3;
    }

    .stats-panel {
        margin-bottom: 6px;
        font-size: 0.85rem;
    }

    .controls {
        margin-bottom: 12px;
        gap: 8px;
    }

    .btn {
        padding: 6px 12px;
        font-size: 0.8rem;
    }

    /* Flip boards vertically and force adaptive auto-scaling heights */
    #flowmatrix-app .game-container {
        flex-direction: column-reverse;
        gap: 12px;
        width: 100%;
        max-width: 280px; /* Keeps the workspace tight on thin viewports */
    }

    /* INTERACTIVE CANVAS SYSTEM AUTO-RESIZES TO GUARANTEE DISPLAY VISIBILITY */
    #flowmatrix-app #puzzleCanvas {
        max-width: 100%;
        max-height: 40vh; /* Prevents the game board from dominating the screen height */
        width: auto;
        margin: 0 auto;
    }

    /* TARGET REFERENCE SCALES SIGNIFICANTLY SMALLER THAN INTERACTIVE FIELD */
    #flowmatrix-app #targetCanvas {
        display: block;      /* Forces proper block element centering mechanics */
        max-width: 65%;      /* Scaled up from 45% to be centered and noticeably more visible */
        max-height: 20vh;    /* Expanded vertical allotment context to retain aspect ratio safely */
        width: auto;
        margin: 0 auto;
    }

    #flowmatrix-app .panel {
        width: 100%;
    }

    #flowmatrix-app .panel-label {
        margin-bottom: 3px;
        font-size: 0.6rem;
        letter-spacing: 1.5px;
    }
}

@media (max-width: 580px) {
    /* Scale the dual grids inside Movedado down so they sit on screen together */
    #equilibrium-app .container {
        flex-direction: column; 
        align-items: center;
        gap: 12px;
    }

    #equilibrium-app .grid {
        width: 170px;
        height: 170px;
        padding: 6px;
        gap: 4px;
    }

    #equilibrium-app .tile {
        font-size: 1.05rem;
    }

    #equilibrium-app h3 {
        margin-bottom: 2px;
        font-size: 0.75rem;
    }
    
    #equilibrium-app .status {
        margin-top: 4px;
        font-size: 0.7rem;
    }
}

@media (max-width: 400px) {
    h1 { font-size: 1.15rem; letter-spacing: 2px; }
    .menu-title { font-size: 1.3rem; }
    
    #flowmatrix-app .game-container {
        max-width: 240px; /* Micro-screen padding insurance */
    }
    
    #equilibrium-app .grid { 
        width: 140px; 
        height: 140px; 
        gap: 3px; 
        padding: 4px; 
    }
    #equilibrium-app .tile { font-size: 0.95rem; }
    #equilibrium-app .goals { font-size: 0.95rem; padding: 8px 12px; }
}
