:root {
    --game-primary: #c90c0f;
    --game-secondary: #f4c430;
    --mi-space: #07101c;
    --mi-space-mid: #102038;
    --mi-neon: #f4c430;
    --mi-laser: #7dd3fc;
}

body.mi-page {
    margin: 0;
    min-height: 100vh;
    font-family: "Rockwell", "Rockwell Nova", "Roboto Slab", serif;
    color: #f8fafc;
    background:
        radial-gradient(circle at 12% 8%, rgba(244, 196, 48, 0.16), transparent 40%),
        radial-gradient(circle at 88% 12%, rgba(201, 12, 15, 0.28), transparent 46%),
        linear-gradient(180deg, #050b14 0%, #0d1a2e 52%, #07101c 100%);
}

body.mi-page.game-menu-active {
    overflow-y: auto;
    overflow-x: hidden;
}

body.mi-page.game-menu-active #game-header {
    display: none !important;
}

.mi-page .game-screen {
    display: none;
    min-height: 100vh;
}

.mi-page .game-screen.active {
    display: block;
}

body.mi-page.with-game-header .mi-shell {
    padding-top: 5.5rem;
}

.mi-shell {
    max-width: min(760px, 96vw);
    margin: 0 auto;
    padding: 0.85rem 0.7rem 1.4rem;
}

.mi-hud {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.45rem;
    flex-wrap: wrap;
    margin: 0 auto 0.7rem;
    padding: 0.45rem 0.6rem;
    background: linear-gradient(180deg, #1a2740, #0c1628);
    border: 3px solid #07101c;
    border-radius: 12px;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.1), 0 10px 24px rgba(0, 0, 0, 0.4);
}

.mi-lcd {
    min-width: 5.4rem;
    padding: 0.15rem 0.4rem;
    background: #04080f;
    color: #f4c430;
    font-family: "Courier New", ui-monospace, monospace;
    font-size: 1.1rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-align: center;
    border-radius: 6px;
    box-shadow: inset 0 0 0 2px #7f1d1d, inset 0 8px 16px rgba(0, 0, 0, 0.45);
}

.mi-lcd span {
    display: block;
    font-size: 0.58rem;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: #fca5a5;
}

.mi-chip {
    padding: 0.4rem 0.65rem;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.08);
    color: #fde68a;
    font-weight: 700;
    font-size: 0.88rem;
}

.mi-lives {
    display: flex;
    gap: 0.28rem;
    color: #c90c0f;
    font-size: 1.15rem;
}

.mi-lives i.is-lost {
    color: #334155;
}

.mi-tool-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.45rem 0.7rem;
    border-radius: 999px;
    border: 1px solid rgba(244, 196, 48, 0.4);
    background: rgba(7, 16, 28, 0.85);
    color: #f8fafc;
    font-weight: 700;
    cursor: pointer;
}

.mi-tool-btn:hover {
    border-color: #f4c430;
    color: #fde68a;
    background: #1a2740;
}

.mi-arena {
    display: flex;
    flex-direction: column;
    gap: 0.65rem;
}

.mi-playfield {
    position: relative;
    height: min(52vh, 460px);
    min-height: 280px;
    overflow: hidden;
    border-radius: 16px;
    border: 4px solid #1e3a5f;
    background:
        radial-gradient(circle at 20% 30%, rgba(125, 211, 252, 0.08), transparent 36%),
        linear-gradient(180deg, #0a1628, #07101c 70%);
    box-shadow: inset 0 0 40px rgba(0, 0, 0, 0.45), 0 16px 32px rgba(0, 0, 0, 0.35);
}

.mi-stars {
    position: absolute;
    inset: 0;
    background-image:
        radial-gradient(1.5px 1.5px at 12% 18%, #f8fafc 40%, transparent 41%),
        radial-gradient(1px 1px at 38% 8%, #93c5fd 40%, transparent 41%),
        radial-gradient(1.5px 1.5px at 72% 14%, #fde68a 40%, transparent 41%),
        radial-gradient(1px 1px at 88% 28%, #f8fafc 40%, transparent 41%),
        radial-gradient(1px 1px at 22% 62%, #93c5fd 40%, transparent 41%),
        radial-gradient(1.5px 1.5px at 64% 48%, #f8fafc 40%, transparent 41%),
        radial-gradient(1px 1px at 8% 82%, #fde68a 40%, transparent 41%),
        radial-gradient(1px 1px at 92% 78%, #f8fafc 40%, transparent 41%);
    pointer-events: none;
    opacity: 0.7;
}

.mi-danger {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 52px;
    height: 3px;
    background: repeating-linear-gradient(90deg, #c90c0f 0 12px, transparent 12px 20px);
    opacity: 0.85;
    pointer-events: none;
}

.mi-cannon {
    position: absolute;
    left: 50%;
    bottom: 6px;
    width: 54px;
    height: 46px;
    transform: translateX(-50%);
    transform-origin: 50% 80%;
    z-index: 4;
    pointer-events: none;
    transition: transform 0.12s ease-out;
}

.mi-cannon-barrel {
    position: absolute;
    left: 50%;
    bottom: 18px;
    width: 10px;
    height: 22px;
    margin-left: -5px;
    border-radius: 4px 4px 2px 2px;
    background: linear-gradient(180deg, #fde68a, #c90c0f);
    box-shadow: 0 0 8px rgba(244, 196, 48, 0.45);
}

.mi-cannon-base {
    position: absolute;
    left: 50%;
    bottom: 0;
    width: 42px;
    height: 18px;
    margin-left: -21px;
    border-radius: 8px 8px 4px 4px;
    background: linear-gradient(180deg, #c90c0f, #7f0508);
    border: 2px solid #f4c430;
}

.mi-invader {
    position: absolute;
    top: 0;
    left: 0;
    width: min(28%, 132px);
    min-width: 92px;
    transform: translate(-50%, 0);
    z-index: 3;
    padding: 0.55rem 0.4rem 0.45rem;
    border-radius: 12px;
    background: linear-gradient(180deg, #1d4ed8, #1e3a8a);
    border: 3px solid #fde68a;
    color: #fff;
    text-align: center;
    box-shadow: 0 8px 18px rgba(0, 0, 0, 0.35), inset 0 1px 0 rgba(255, 255, 255, 0.2);
    will-change: transform;
}

.mi-invader[data-op="mul"] {
    background: linear-gradient(180deg, #c90c0f, #7f0508);
    border-color: #f4c430;
}

.mi-invader[data-op="add"] {
    background: linear-gradient(180deg, #0f766e, #115e59);
    border-color: #5eead4;
}

.mi-invader[data-op="sub"] {
    background: linear-gradient(180deg, #6d28d9, #4c1d95);
    border-color: #c4b5fd;
}

.mi-invader__eq {
    display: block;
    font-size: clamp(1.35rem, 4.4vw, 1.85rem);
    font-weight: 800;
    letter-spacing: 0.02em;
    line-height: 1.1;
    color: #fff;
    text-shadow: 0 2px 0 rgba(0, 0, 0, 0.35);
}

.mi-invader.is-urgent {
    box-shadow: 0 0 0 3px #fde68a, 0 0 18px rgba(244, 196, 48, 0.55);
}

.mi-invader.is-hit {
    animation: mi-pop 0.28s ease-out forwards;
    pointer-events: none;
}

.mi-invader.is-leak {
    animation: mi-leak 0.32s ease-in forwards;
    pointer-events: none;
}

.mi-laser {
    position: absolute;
    width: 5px;
    background: linear-gradient(180deg, #fff, #7dd3fc 40%, #f4c430);
    border-radius: 999px;
    transform-origin: bottom center;
    z-index: 5;
    pointer-events: none;
    box-shadow: 0 0 10px #7dd3fc;
    animation: mi-shot 0.18s ease-out forwards;
}

.mi-banner {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 6;
    font-size: clamp(2rem, 8vw, 3.4rem);
    font-weight: 800;
    letter-spacing: 0.12em;
    color: #fde68a;
    text-shadow: 0 0 18px rgba(244, 196, 48, 0.65), 0 4px 0 #7f0508;
    pointer-events: none;
}

.mi-playfield.is-shake {
    animation: mi-shake 0.28s ease-in-out;
}

.mi-controls {
    display: flex;
    flex-direction: column;
    gap: 0.55rem;
}

.mi-answer-row {
    display: flex;
    gap: 0.45rem;
    align-items: stretch;
}

.mi-combo {
    min-width: 3.4rem;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 10px;
    background: #f4c430;
    color: #1e1b4b;
    font-weight: 800;
    font-size: 1.1rem;
}

.mi-combo[hidden] {
    display: none !important;
}

.mi-answer {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    padding: 0.35rem 0.7rem;
    border-radius: 12px;
    background: #04080f;
    border: 3px solid #f4c430;
    color: #fde68a;
    box-shadow: inset 0 8px 16px rgba(0, 0, 0, 0.45);
}

.mi-answer.is-wrong {
    border-color: #c90c0f;
    animation: mi-shake 0.28s ease-in-out;
}

.mi-answer-label {
    font-size: 0.62rem;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: #fca5a5;
}

.mi-answer strong {
    font-family: "Courier New", ui-monospace, monospace;
    font-size: 1.85rem;
    line-height: 1.1;
    color: #f4c430;
}

.mi-shoot-btn {
    min-width: 7.2rem;
    border: 0;
    border-radius: 12px;
    background: #c90c0f;
    color: #fff;
    font-weight: 800;
    font-size: 1.05rem;
    cursor: pointer;
    box-shadow: 0 4px 0 #7f0508;
}

.mi-shoot-btn:hover,
.mi-shoot-btn:focus-visible {
    background: #a00a0c;
    color: #fff;
}

.mi-shoot-btn:active {
    transform: translateY(2px);
    box-shadow: 0 2px 0 #7f0508;
}

.mi-pad {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.4rem;
}

.mi-pad-btn {
    min-height: 48px;
    border-radius: 10px;
    border: 2px solid #f4c430;
    background: #0f1b2e;
    color: #f8fafc;
    font-size: 1.35rem;
    font-weight: 800;
    cursor: pointer;
    touch-action: manipulation;
}

.mi-pad-btn:hover,
.mi-pad-btn:focus-visible {
    background: #1e3a5f;
    color: #fde68a;
}

.mi-pad-btn--edit {
    background: #1e293b;
    color: #fde68a;
}

.mi-pad-btn--enter {
    background: #c90c0f;
    color: #fff;
    border-color: #c90c0f;
}

.mi-pad-btn--enter:hover,
.mi-pad-btn--enter:focus-visible {
    background: #a00a0c;
    color: #fff;
}

.mi-hint {
    margin: 0;
    text-align: center;
    color: #fde68a;
    font-size: 0.92rem;
}

.mi-settings-panel {
    margin-top: 0.4rem;
    padding: 0.9rem 1rem;
    background: rgba(15, 23, 42, 0.45);
    border: 1px solid rgba(244, 196, 48, 0.22);
    border-radius: 12px;
}

.mi-settings-panel__title {
    font-weight: 700;
    margin-bottom: 0.55rem;
    color: #f5c518;
}

.mi-settings-panel__label {
    margin: 0.35rem 0 0.4rem;
    font-weight: 600;
}

.mi-settings-panel__buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 0.45rem;
    margin-bottom: 0.75rem;
}

.mi-settings-panel__note {
    margin: 0;
    color: #cbd5e1;
    font-size: 0.9rem;
}

.mi-page .difficulty-pill {
    border: 1px solid rgba(255, 255, 255, 0.14);
    border-radius: 999px;
    padding: 0.5rem 0.85rem;
    background: rgba(255, 255, 255, 0.05);
    color: #f8fafc;
    font-weight: 600;
    cursor: pointer;
}

.mi-page .difficulty-pill:hover {
    border-color: #f4c430;
    color: #fde68a;
    background: rgba(201, 12, 15, 0.22);
}

.mi-page .difficulty-pill.is-selected {
    background: #f4c430;
    color: #1e1b4b;
    border-color: #f4c430;
}

.mi-pause {
    position: fixed;
    inset: 0;
    z-index: 11000;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(4, 8, 15, 0.72);
    padding: 1rem;
}

.mi-pause[hidden] {
    display: none !important;
}

.mi-pause-card {
    width: min(420px, 92vw);
    padding: 1.4rem 1.5rem;
    border-radius: 16px;
    background: #fff;
    color: #1a1a1a;
    text-align: center;
}

.mi-pause-card h2 {
    margin: 0 0 0.4rem;
    color: #c90c0f;
}

.mi-pause-actions {
    display: flex;
    justify-content: center;
    gap: 0.6rem;
    margin-top: 1rem;
}

.mi-page .modal {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.72);
    z-index: 12000;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}

.mi-page .modal.active {
    display: flex;
}

.mi-page .modal-content {
    background: #fff;
    color: #1a1a1a;
    border-radius: 1rem;
    max-width: 640px;
    width: 100%;
    max-height: 90vh;
    overflow-y: auto;
}

.mi-page .modal-large { max-width: 760px; }

.mi-page .modal-header,
.mi-page .modal-footer {
    padding: 1.1rem 1.4rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
}

.mi-page .modal-header { border-bottom: 2px solid #eee; }
.mi-page .modal-header h2 { margin: 0; color: #c90c0f; font-size: 1.35rem; }

.mi-page .modal-close {
    background: #fff;
    border: 2px solid #c90c0f;
    color: #c90c0f;
    border-radius: 8px;
    cursor: pointer;
    padding: 0.35rem 0.55rem;
}

.mi-page .modal-close:hover {
    background: #c90c0f;
    color: #fff;
}

.mi-page .modal-body { padding: 1.2rem 1.4rem; }
.mi-page .modal-footer { border-top: 2px solid #eee; justify-content: flex-end; }

.mi-page .help-section { margin-bottom: 1.1rem; }
.mi-page .help-section h3 { color: #c90c0f; margin: 0 0 0.4rem; }
.mi-page .help-section ul { margin: 0.3rem 0 0; padding-left: 1.2rem; }

.mi-page .stats-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.75rem;
    margin-bottom: 1rem;
}

.mi-page .stat-card {
    background: #f8fafc;
    border-radius: 12px;
    padding: 0.85rem;
    text-align: center;
}

.mi-page .stat-value { font-size: 1.6rem; color: #c90c0f; font-weight: 700; }
.mi-page .stat-label { color: #64748b; font-size: 0.85rem; }

.mi-page .win-stats {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.6rem;
    text-align: center;
}

.mi-page .win-stat strong { display: block; font-size: 1.35rem; color: #c90c0f; }
.mi-page .win-stat span { color: #64748b; font-size: 0.82rem; }

.mi-page .result-message { font-size: 1.05rem; margin: 0 0 1rem; }

.mi-page .btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    padding: 0.65rem 1.1rem;
    border-radius: 0.55rem;
    border: 2px solid transparent;
    font-weight: 700;
    cursor: pointer;
}

.mi-page .btn-primary {
    background: #c90c0f;
    color: #fff;
}

.mi-page .btn-primary:hover {
    background: #a00a0c;
    color: #fff;
}

.mi-page .btn-secondary {
    background: #fff;
    color: #c90c0f;
    border-color: #c90c0f;
}

.mi-page .btn-secondary:hover {
    background: #c90c0f;
    color: #fff;
}

.mi-page .difficulty-stats {
    display: grid;
    gap: 0.45rem;
}

.mi-page .difficulty-stats div {
    display: flex;
    justify-content: space-between;
    padding: 0.45rem 0.6rem;
    background: #f8fafc;
    border-radius: 8px;
}

@keyframes mi-pop {
    0% { transform: translate(-50%, var(--y, 0px)) scale(1); opacity: 1; }
    55% { transform: translate(-50%, var(--y, 0px)) scale(1.18); opacity: 1; }
    100% { transform: translate(-50%, var(--y, 0px)) scale(0.2); opacity: 0; }
}

@keyframes mi-leak {
    0% { transform: translate(-50%, var(--y, 0px)) scale(1); opacity: 1; }
    100% { transform: translate(-50%, calc(var(--y, 0px) + 28px)) scale(0.85); opacity: 0; }
}

@keyframes mi-shot {
    0% { opacity: 1; }
    100% { opacity: 0; }
}

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

@media (prefers-reduced-motion: reduce) {
    .mi-invader.is-hit,
    .mi-invader.is-leak,
    .mi-laser,
    .mi-playfield.is-shake,
    .mi-answer.is-wrong {
        animation: none;
    }
}

@media (max-width: 640px) {
    .mi-tool-btn span { display: none; }
    .mi-lcd { min-width: 4.2rem; font-size: 1rem; }
    .mi-playfield { height: min(44vh, 380px); min-height: 240px; }
    .mi-combo { min-height: 2.2rem; }
    .mi-pad-btn { min-height: 46px; }
}

@media (min-width: 900px) {
    .mi-playfield { height: min(56vh, 520px); }
}

#settingsModal .mi-settings-panel__title {
    color: #c90c0f;
}
#settingsModal .mi-settings-panel__label,
#settingsModal .mi-settings-panel__note {
    color: #1a1a1a;
}
#settingsModal .difficulty-pill {
    background: #f1f5f9;
    color: #0f172a;
    border-color: #cbd5e1;
}
#settingsModal .difficulty-pill:hover {
    background: #e2e8f0;
    color: #0f172a;
    border-color: #c90c0f;
}
#settingsModal .difficulty-pill.is-selected {
    background: #c90c0f;
    color: #fff;
    border-color: #c90c0f;
}
