:root {
    --bg-color: #f0f2f5;
    --card-bg: #ffffff;
    --primary: #3b82f6;
    --text-main: #1f2937;
    --text-muted: #6b7280;
    --red: #ef4444;
    --green: #22c55e;
    --yellow: #eab308;
    --blue: #3b82f6;

    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-color);
    color: var(--text-main);
    height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
}

.app-container {
    width: 100%;
    height: 100%;
    max-width: 1200px;
    position: relative;
}

.screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    transition: opacity 0.3s ease;
}

.screen.hidden {
    opacity: 0;
    pointer-events: none;
    z-index: -1;
}

.screen.active {
    opacity: 1;
    pointer-events: all;
    z-index: 10;
}

/* Generic utility to hide elements (like metrics container) */
.hidden {
    display: none !important;
}

.glass-panel {
    background: rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(10px);
    padding: 2rem;
    border-radius: 1rem;
    box-shadow: var(--shadow-lg);
    width: 100%;
    /* Fluid width */
    max-width: 900px;
    /* Cap at 900px */
    text-align: center;
    margin: 0 auto;
    /* Center it */
}

h1 {
    font-size: 1.5rem;
    margin-bottom: 1rem;
    color: var(--text-main);
}

p {
    margin-bottom: 1.5rem;
    line-height: 1.6;
    color: var(--text-muted);
}

.primary-btn {
    background-color: var(--primary);
    color: white;
    border: none;
    padding: 0.75rem 1.5rem;
    border-radius: 0.5rem;
    font-weight: 600;
    cursor: pointer;
    transition: background-color 0.2s;
}

.primary-btn:hover {
    background-color: #2563eb;
}

.instruction-preview {
    display: block;
    max-width: 100%;
    height: auto;
    margin: 1.5rem auto;
    border-radius: 0.5rem;
    box-shadow: var(--shadow-sm);
    max-height: 200px;
    object-fit: contain;
}

/* GAME BOARD */
/* GAME BOARD - Specific adjustments removed to enforce global .screen alignment */
/* All screens now follow the .screen class rules for consistency */

/* Secondary Button (for PDF) */
/* Secondary Button (for PDF) */
.secondary-btn {
    background-color: transparent;
    color: var(--primary);
    border: 2px solid var(--primary);
    padding: 1rem 2rem;
    /* Increased from 0.75rem 1.5rem */
    border-radius: 0.5rem;
    font-weight: 700;
    /* Bolder */
    font-size: 1.1rem;
    /* Larger text */
    cursor: pointer;
    transition: all 0.2s;
    margin-top: 1rem;
    background: rgba(255, 255, 255, 0.8);
}

.secondary-btn:hover {
    background-color: var(--primary);
    color: white;
}

/* GAME BOARD - Grid Layout */
.game-board-container {
    display: flex;
    justify-content: center;
    gap: 4rem;
    width: 100%;
    margin-top: 1rem;
}

.grid-section {
    text-align: center;
}

.grid-section h3 {
    margin-bottom: 1rem;
    color: var(--text-muted);
    font-size: 1rem;
}

.number-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: repeat(4, 1fr);
    gap: 1rem;
    background: white;
    padding: 1rem;
    border-radius: 1rem;
    box-shadow: var(--shadow-md);
}

.grid-cell {
    width: 60px;
    height: 60px;
    display: flex;
    justify-content: center;
    align-items: center;
    background: var(--bg-color);
    border-radius: 0.5rem;
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-main);
    cursor: pointer;
    transition: all 0.2s;
    border: 2px solid transparent;
    user-select: none;
}

.grid-cell:hover {
    background: #e5e7eb;
    transform: translateY(-2px);
}

.grid-cell.selected {
    background: var(--primary);
    color: white;
    border-color: var(--blue);
    box-shadow: var(--shadow-md);
}

/* .grid-cell.completed removed as per user request to not show used numbers */

.grid-cell.disabled {
    opacity: 0.5;
    pointer-events: none;
}

/* Responsive Grids */
@media (max-width: 768px) {
    .game-board-container {
        flex-direction: column;
        align-items: center;
        gap: 2rem;
    }

    .number-grid {
        gap: 0.5rem;
    }

    .grid-cell {
        width: 50px;
        height: 50px;
        font-size: 1.25rem;
    }
}

/* Feedback Layout Container - Reserves space */
#feedback-container {
    height: 60px;
    width: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    margin-bottom: 2rem;
}

/* Feedback Overlay - The actual pill */
.feedback-overlay {
    padding: 0.5rem 2rem;
    border-radius: 99px;
    font-weight: 700;
    font-size: 1.25rem;
    color: white;
    box-shadow: var(--shadow-md);
    opacity: 0;
    transition: opacity 0.2s;
}

.feedback-overlay.active {
    opacity: 1;
}

.feedback-correct {
    background-color: var(--green);
}

.feedback-wrong {
    background-color: var(--red);
}

@keyframes popIn {
    from {
        transform: translate(-50%, -50%) scale(0.5);
        opacity: 0;
    }

    to {
        transform: translate(-50%, -50%) scale(1);
        opacity: 1;
    }
}

/* Card Flip Animation */
@keyframes flipIn {
    0% {
        transform: scale(1.1) rotateY(90deg);
        opacity: 0;
    }

    100% {
        transform: scale(1.1) rotateY(0);
        opacity: 1;
    }
}

.flip-in {
    animation: flipIn 0.6s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
    backface-visibility: hidden;
}

/* Results Grid */
.metrics-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
    margin-top: 1.5rem;
    text-align: left;
}

.metric-item {
    background: #f9fafb;
    padding: 0.75rem;
    border-radius: 0.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
}

/* Actionable items with hover effect */
.metric-item.actionable {
    cursor: pointer;
    transition: background-color 0.2s, transform 0.1s;
}

.metric-item.actionable:hover {
    background-color: #eff6ff;
    transform: translateY(-2px);
    box-shadow: var(--shadow-sm);
}

.metric-item label {
    font-size: 0.875rem;
    color: var(--text-muted);
}

/* Add visual cue for clickable items */
.metric-item.actionable label::after {
    content: ' ⓘ';
    font-size: 0.8em;
    opacity: 0.6;
    margin-left: 4px;
}

/* Tooltip Modal Styling */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 10000;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.modal.visible {
    opacity: 1;
    pointer-events: all;
}

.modal-content {
    background-color: white;
    padding: 2rem;
    border-radius: 1rem;
    max-width: 500px;
    width: 90%;
    box-shadow: var(--shadow-lg);
    position: relative;
    transform: translateY(20px);
    transition: transform 0.3s ease;
    text-align: left;
}

#tooltip-title {
    margin-bottom: 1rem;
}

.modal.visible .modal-content {
    transform: translateY(0);
}

.close-modal {
    position: absolute;
    top: 1rem;
    right: 1.5rem;
    font-size: 2rem;
    cursor: pointer;
    color: var(--text-muted);
    line-height: 1;
}

.close-modal:hover {
    color: var(--text-main);
}

/* --- GLOBAL LAYOUT (Sidebar by Default) --- */
body {
    display: flex;
    flex-direction: row;
    align-items: stretch;
    overflow: hidden;
    /* Main scroll handled inside containers */
}

/* SIDEBAR FOOTER (Left Column) */
.app-footer {
    position: relative !important;
    order: -1;
    /* Move to start (Left) */
    width: 320px !important;
    /* Fixed width sidebar */
    min-width: 320px;
    height: 100vh !important;
    /* Full height */
    max-width: none !important;
    margin: 0 !important;
    padding: 2rem !important;

    /* Styling */
    background: #f9fafb;
    /* Slight grey to distinguish */
    border-top: none;
    border-right: 1px solid rgba(0, 0, 0, 0.1);
    border-radius: 0;
    text-align: left !important;

    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    /* Align to top to match glass panel */
    /* Center content vertically */
    overflow-y: auto;
    /* Scroll if refs are long */
    overflow-x: hidden;
    /* Prevent horizontal scroll */
    z-index: 10;
    left: auto !important;
    bottom: auto !important;
    transform: none !important;
}

/* REFERENCES Styling */
.references-section {
    display: block;
    margin-top: 1rem;
    font-size: 12px !important;
    /* Increased to 12px */
    line-height: 1.4;
    word-wrap: break-word;
    /* Ensure text wraps */
    overflow-wrap: break-word;
    /* Modern wrapping */
}

.references-section p {
    margin-bottom: 0.5rem;
}

.references-section a {
    word-break: break-all;
    /* Force break long URLs */
    display: inline-block;
    /* Ensure break works */
}

/* APP CONTAINER (Right Column) */
.app-container {
    flex: 1;
    /* Take remaining space */
    height: 100vh;
    position: relative;
    overflow: hidden;
    /* Screens scroll inside */
    padding-bottom: 0 !important;
    display: flex;
    /* Ensure it acts as a flex parent */
    justify-content: center;
    align-items: center;
}

/* SCROLLABLE SCREENS */
.screen {
    overflow-y: auto !important;
    height: 100% !important;
    width: 100% !important;
    /* Ensure full width for centering */
    display: flex !important;
    /* Flex to center internal content */
    flex-direction: column;
    align-items: center;
    /* Horizontal center */
    justify-content: flex-start;
    /* START from top, don't center vertically */
    padding-top: 2rem;
    /* Consistent top spacing */
    padding-bottom: 4rem;
}

/* Specific Screen overrides if content is too tall?
   No, let them flex-start if too tall via auto margins,
   but default should be center.
*/

.screen>* {
    margin-left: auto;
    margin-right: auto;
    flex-shrink: 0;
    /* Prevent flex children from squashing to screen height */
}

/* Ensure Game Title/Header isn't squashed */
#game-screen {
    padding-top: 4rem;
    /* Match others */
}

/* COMPACT STACKED LAYOUT FOR CONTENT */
.glass-panel {
    max-width: 900px;
    padding: 1rem 2rem;
}

/* --- RESPONSIVE DESIGN --- */

/* 2. TABLETS & PORTRAIT (Narrower Width) */
@media (max-width: 1024px) {
    .glass-panel {
        padding: 1.5rem;
        width: 95%;
        max-width: 900px;
        /* Reset wide panel */
    }

    /* Revert float for narrower screens where side-by-side sucks */
    .instruction-preview {
        float: none;
        width: auto;
        max-width: 100%;
        margin: 1.5rem auto;
    }

    /* Cards slightly smaller */
    .card-slot {
        width: 100px;
        height: 150px;
    }

    .wcst-card svg {
        width: 35px;
        height: 35px;
    }
}

/* GLOBAL OVERRIDE to ensure scrolling works on all heights */
.screen {
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 50px;
    /* Safe space */
}

/* 3. MOBILE DEVICES (Phones) - Revert to Stacked */
@media (max-width: 768px) {
    body {
        display: block;
        /* Stack vertically */
        overflow-y: auto;
    }

    .app-footer {
        width: 100% !important;
        height: auto !important;
        position: relative !important;
        order: 0;
        /* Move back to bottom */
        border-right: none;
        border-top: 1px solid rgba(0, 0, 0, 0.1);
        padding: 1rem !important;
        border-radius: 0;
        text-align: center !important;
        font-size: 12px !important;
    }

    .app-container {
        height: 100vh;
        /* Fixed viewport height to act as container for absolute screens */
        min-height: 100vh;
        overflow: hidden;
        /* Screens scroll inside */
        padding-bottom: 0;
        position: relative;
    }

    /* Screens handle the scrolling */
    .screen {
        position: absolute;
        top: 0;
        left: 0;
        width: 100% !important;
        height: 100% !important;
        padding-top: 1rem;
        padding-bottom: 120px;
        /* EXTRA space for buttons at bottom on mobile */
    }

    .glass-panel {
        padding: 1rem;
        margin-top: 0;
        margin-bottom: 2rem;
        width: 95%;
        /* Safe margin */
    }

    .instruction-preview {
        float: none;
        width: 100%;
    }

    h1 {
        font-size: 1.25rem;
    }

    .metrics-grid {
        grid-template-columns: 1fr;
    }

    .stimulus-area {
        gap: 0.5rem;
        margin-bottom: 2rem;
        flex-wrap: nowrap;
        justify-content: center;
    }

    /* Strict VW sizing for phones */
    .card-slot {
        width: 18vw;
        height: 27vw;
        max-width: 100px;
        max-height: 150px;
    }

    .wcst-card svg {
        width: 45%;
        /* Increased from 30% */
        height: auto;
    }

    .layout-2,
    .layout-3,
    .layout-4 {
        gap: 2px;
    }

    .references-section {
        display: block;
        font-size: 8px;
    }
}