* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Inter', 'Segoe UI', Arial, sans-serif;
    background: linear-gradient(135deg, #1a1d2e 0%, #2d3548 100%);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
}

.game-container {
    width: 90%;
    max-width: 900px;
    background: rgba(45, 53, 72, 0.95);
    border-radius: 15px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.4);
    padding: 20px;
    color: #e8eaed;
}

/* Top Bar */
.top-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    padding: 15px;
    background: rgba(33, 40, 55, 0.8);
    border-radius: 8px;
    font-size: 1.2rem;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.top-bar select, .top-bar button {
    padding: 8px 16px;
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 5px;
    font-size: 1rem;
    cursor: pointer;
    background: rgba(45, 53, 72, 0.9);
    color: #e8eaed;
    transition: all 0.2s ease;
}

.top-bar select:hover, .top-bar button:hover {
    background: rgba(58, 68, 90, 0.9);
    border-color: rgba(255, 255, 255, 0.3);
    transform: translateY(-1px);
}

/* Equation Bar */
.equation-bar {
    background: rgba(33, 40, 55, 0.8);
    padding: 15px;
    border-radius: 8px;
    margin-bottom: 20px;
    text-align: center;
    border: 1px solid rgba(255, 255, 255, 0.1);
    min-height: 110px;
}

.equation-bar h3 {
    margin-bottom: 10px;
    color: #e8eaed;
    font-size: 1.1rem;
}

.active-equation {
    font-size: 1.5rem;
    font-weight: bold;
    color: #e8eaed;
    height: 80px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-wrap: wrap;
    gap: 10px;
    padding: 10px;
    border-radius: 5px;
    background: rgba(45, 53, 72, 0.5);
    overflow-y: visible;
}

.equation-bar button {
    margin-top: 10px;
    padding: 8px 16px;
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 5px;
    cursor: pointer;
    background: rgba(45, 53, 72, 0.9);
    color: #e8eaed;
    transition: all 0.2s ease;
}

#clear-equation {
    background: rgba(220, 53, 69, 0.8);
}

#clear-equation:hover {
    background: rgba(220, 53, 69, 1);
    transform: translateY(-1px);
}

/* Game Board */
.game-board {
    flex: 1;
    margin-bottom: 20px;
}

/* Block grid */
.block-container {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 8px;
}

/* Blocks */
.block {
    background: rgba(55, 65, 85, 0.9);
    color: #e8eaed;
    padding: 12px 6px;
    border-radius: 8px;
    cursor: pointer;
    text-align: center;
    font-size: 0.95rem;
    font-weight: bold;
    transition: all 0.2s ease;
    border: 2px solid rgba(255, 255, 255, 0.08);
    min-height: 55px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.block:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    filter: brightness(1.12);
    border-color: rgba(255, 255, 255, 0.25);
}

/* Role colors (difficulty aid): muted accents from the app's own palette, layered as a
   soft tint OVER the slate base so a block's role reads at a glance without looking neon.
   role-f = function/source (amber), role-fp = derivative/answer (blue),
   role-mid = middle step of 3-block modes (green), role-mix = usable either way. */
.block.role-f {
    background-color: rgba(55, 65, 85, 0.9);
    background-image: linear-gradient(rgba(210, 165, 70, 0.22), rgba(210, 165, 70, 0.22));
    border-color: rgba(230, 185, 90, 0.5);
}
.block.role-fp {
    background-color: rgba(55, 65, 85, 0.9);
    background-image: linear-gradient(rgba(70, 140, 215, 0.22), rgba(70, 140, 215, 0.22));
    border-color: rgba(110, 175, 240, 0.5);
}
.block.role-mid {
    background-color: rgba(55, 65, 85, 0.9);
    background-image: linear-gradient(rgba(80, 185, 130, 0.2), rgba(80, 185, 130, 0.2));
    border-color: rgba(120, 215, 160, 0.5);
}
/* Interchangeable block: soft diagonal split, f-amber over f'-blue. */
.block.role-mix {
    background-color: rgba(55, 65, 85, 0.9);
    background-image: linear-gradient(135deg, rgba(210, 165, 70, 0.3) 0 50%, rgba(70, 140, 215, 0.3) 50% 100%);
    border-color: rgba(200, 205, 215, 0.45);
}

/* Selection: a bright neutral ring + lift layered OVER the role color (no background
   repaint) so a picked block still shows its role. Re-click / right-click deselects. */
.block.is-selected,
.block.selected-function,
.block.selected-derivative,
.block.selected-antiderivative {
    border-color: rgba(255, 255, 255, 0.9);
    box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.4), 0 0 16px rgba(255, 255, 255, 0.3);
    filter: brightness(1.18);
    transform: translateY(-2px);
}

.block.error {
    animation: shake 0.3s ease-in-out;
    background: rgba(220, 53, 69, 0.35);
    border-color: rgba(220, 53, 69, 0.7);
}

.block.match-success {
    animation: matchPop 0.3s ease-out;
    background: rgba(40, 167, 69, 0.5);
    border-color: rgba(108, 255, 143, 0.8);
    box-shadow: 0 0 16px rgba(108, 255, 143, 0.4);
}

.block.matched {
    visibility: hidden;
    pointer-events: none;
}

@keyframes matchPop {
    0% { transform: scale(1); }
    50% { transform: scale(1.1); }
    100% { transform: scale(1); }
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-5px); }
    75% { transform: translateX(5px); }
}


.loading-msg {
    grid-column: 1 / -1;
    text-align: center;
    color: #a0a8b4;
    padding: 40px 0;
    font-size: 1rem;
}

/* Responsive */
@media (max-width: 768px) {
    .game-container {
        flex-direction: column;
    }

    .operator-panel {
        margin-left: 0;
        margin-top: 20px;
        max-width: none;
    }

    .block-container {
        grid-template-columns: repeat(3, 1fr);
    }
}

/* Overlays */
.overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(10, 15, 25, 0.95);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 2000;
}

.overlay.hidden {
    display: none;
}

.overlay-content {
    text-align: center;
    max-width: 450px;
}

.overlay-content h1 {
    color: #e8eaed;
    font-size: 2rem;
    margin-bottom: 15px;
}

.overlay-content p {
    color: #a0a8b4;
    margin-bottom: 25px;
    font-size: 1.1rem;
}

.level-btn {
    display: block;
    width: 100%;
    margin: 10px 0;
    padding: 16px 20px;
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 8px;
    font-size: 1.1rem;
    cursor: pointer;
    color: #e8eaed;
    background: rgba(45, 53, 72, 0.9);
    transition: all 0.2s ease;
}

.level-btn:hover {
    background: rgba(58, 68, 90, 0.95);
    transform: translateY(-1px);
}

.level-btn small {
    display: block;
    font-size: 0.8rem;
    opacity: 0.7;
    margin-top: 4px;
}

.easy-btn {
    background: rgba(60, 140, 220, 0.3);
}
.easy-btn:hover {
    background: rgba(60, 140, 220, 0.5);
    transform: translateY(-1px);
}

body.game-integra .easy-btn {
    background: rgba(60, 180, 140, 0.3);
}
body.game-integra .easy-btn:hover {
    background: rgba(60, 180, 140, 0.5);
}

.normal-btn {
    background: rgba(220, 160, 50, 0.3);
}
.normal-btn:hover {
    background: rgba(220, 160, 50, 0.5);
    transform: translateY(-1px);
}

body.game-integra .normal-btn {
    background: rgba(100, 180, 220, 0.3);
}
body.game-integra .normal-btn:hover {
    background: rgba(100, 180, 220, 0.5);
}

.quotient-btn {
    background: rgba(120, 90, 200, 0.3);
}
.quotient-btn:hover {
    background: rgba(120, 90, 200, 0.5);
    transform: translateY(-1px);
}

.hard-btn {
    background: rgba(220, 70, 60, 0.3);
}
.hard-btn:hover {
    background: rgba(220, 70, 60, 0.5);
    transform: translateY(-1px);
}

body.game-integra .hard-btn {
    background: rgba(200, 100, 180, 0.3);
}
body.game-integra .hard-btn:hover {
    background: rgba(200, 100, 180, 0.5);
}

#result-overlay .overlay-content h1.pass {
    color: #6cff8f;
}
#result-overlay .overlay-content h1.fail {
    color: #ff6c6c;
}

.level-label {
    font-size: 0.9rem;
    opacity: 0.7;
}

/* (Antiderivative selection is handled by the shared selection ring above, so the role
   color stays visible while a block is picked.) */

/* Game selection buttons */
.game-deriva-btn {
    background: rgba(60, 140, 220, 0.3);
    border: 1px solid rgba(100, 180, 255, 0.3);
}
.game-deriva-btn:hover {
    background: rgba(60, 140, 220, 0.5);
    transform: translateY(-1px);
}

.game-integra-btn {
    background: rgba(60, 180, 140, 0.3);
    border: 1px solid rgba(100, 210, 180, 0.3);
}
.game-integra-btn:hover {
    background: rgba(60, 180, 140, 0.5);
    transform: translateY(-1px);
}

.back-btn {
    background: rgba(80, 80, 100, 0.5);
    margin-top: 20px;
}
.back-btn:hover {
    background: rgba(100, 100, 120, 0.7);
}

/* How-to-Play instructions (in-game help overlay) */
.howto-row {
    display: flex;
    gap: 11px;
    align-items: flex-start;
    margin-top: 13px;
}
.howto-num {
    flex-shrink: 0;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: rgba(60, 140, 220, 0.3);
    color: #cfe2ff;
    font-size: 0.8rem;
    font-weight: bold;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-top: 1px;
}
.howto-row-title {
    font-size: 0.9rem;
    color: #e8eaed;
    margin-bottom: 2px;
}
.howto-row-text {
    font-size: 0.8rem;
    color: #a0a8b4;
    line-height: 1.5;
}

/* In-game help button (top bar) */
.howto-help-btn {
    width: 34px;
    height: 34px;
    padding: 0 !important;
    border-radius: 50% !important;
    font-weight: bold;
}

/* In-game help overlay: mode-specific block */
.howto-body-game {
    text-align: left;
    margin-bottom: 20px;
}
.howto-mode {
    background: rgba(45, 53, 72, 0.6);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    padding: 12px 14px;
    margin-bottom: 16px;
}
.howto-mode-title {
    font-size: 0.95rem;
    color: #e8eaed;
    font-weight: bold;
    margin-bottom: 8px;
}
.howto-steps {
    margin: 0;
    padding-left: 20px;
}
.howto-steps li {
    font-size: 0.85rem;
    color: #c3cad6;
    line-height: 1.6;
}
.howto-general-label {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: #8a93a6;
    margin: 0 0 2px;
}

/* Color legend (role key), shown above the block grid. Mode-aware; empty = hidden. */
.color-legend {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    align-items: center;
    gap: 8px 16px;
    margin-bottom: 14px;
    font-size: 0.82rem;
    color: #c3cad6;
}
.color-legend:empty {
    display: none;
}
.legend-item {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}
.legend-swatch {
    width: 16px;
    height: 16px;
    border-radius: 4px;
    border: 1px solid rgba(255, 255, 255, 0.25);
    background-color: rgba(55, 65, 85, 0.9);
    flex-shrink: 0;
}
.legend-swatch.role-f {
    background-image: linear-gradient(rgba(210, 165, 70, 0.6), rgba(210, 165, 70, 0.6));
    border-color: rgba(230, 185, 90, 0.7);
}
.legend-swatch.role-fp {
    background-image: linear-gradient(rgba(70, 140, 215, 0.6), rgba(70, 140, 215, 0.6));
    border-color: rgba(110, 175, 240, 0.7);
}
.legend-swatch.role-mid {
    background-image: linear-gradient(rgba(80, 185, 130, 0.6), rgba(80, 185, 130, 0.6));
    border-color: rgba(120, 215, 160, 0.7);
}
.legend-swatch.role-mix {
    background-image: linear-gradient(135deg, rgba(210, 165, 70, 0.7) 0 50%, rgba(70, 140, 215, 0.7) 50% 100%);
    border-color: rgba(200, 205, 215, 0.6);
}

/* Footer credit */
.site-footer {
    text-align: center;
    margin-top: 18px;
    font-size: 0.8rem;
    color: #8a93a6;
}
.site-footer a {
    color: #a0a8b4;
    text-decoration: none;
    border-bottom: 1px solid rgba(160, 168, 180, 0.3);
    transition: color 0.2s ease, border-color 0.2s ease;
}
.site-footer a:hover {
    color: #e8eaed;
    border-color: rgba(232, 234, 237, 0.6);
}

