.monka-modal {
    position: fixed; inset: 0; z-index: 100; overflow: hidden; color: #fff; outline: none;
    font-family: "Exo 2", sans-serif;
    background: #01060c;
}
.monka-modal[hidden], .monka-modal [hidden] { display: none !important; }

.monka-stage {
    position: absolute; inset: 0; overflow: hidden;
    /* The gradient shows while the image loads (or if it fails). */
    background:
        url('../../assets/images/monkaSpeedster/background.webp') center / cover no-repeat,
        linear-gradient(180deg, #0b3fa8 0%, #082a7a 35%, #051a52 68%, #020a26 100%);
}
.monka-bubbles, .monka-words { position: absolute; inset: 0; }

@keyframes monkaFloat { from { transform: translateY(0); } to { transform: translateY(-120vh); } }
@keyframes monkaFade { to { opacity: 0; } }
@keyframes monkaCredits { from { bottom: -100%; } to { bottom: 100%; } }
@keyframes monkaRainbow { to { background-position: -200% 50%; } }
@keyframes monkaToast { 0%, 100% { opacity: 0; } 10%, 90% { opacity: 1; } }

.monka-bubble {
    position: absolute; bottom: -50px; border-radius: 9999px;
    background: linear-gradient(45deg, teal, white); will-change: transform;
}

.monka-word, .monka-credit {
    font-family: "Source Code Pro", ui-monospace, Consolas, "Courier New", monospace; font-style: italic; font-weight: 700;
    -webkit-background-clip: text; background-clip: text; color: transparent;
    user-select: none; white-space: nowrap;
    /* The gradient only paints inside the box, and italic glyphs lean past it - pad so no letter is cropped. */
    padding: 0.1em 0.3em;
}
.monka-word { position: absolute; background-image: linear-gradient(180deg, lime, orange); will-change: transform; }
.monka-word.is-timed {
    background-image: linear-gradient(#fcf803, #b866ff);
    filter: drop-shadow(0 0 6px rgba(255, 60, 60, 0.7));
}

.monka-credits { position: absolute; bottom: -100%; width: max-content; text-align: center; }
.monka-credit { font-size: 30px; line-height: 1.5; }
.monka-credit.is-heading { font-size: 40px; background-image: radial-gradient(yellow 13%, red 53%, crimson 34%); }
.monka-credit.is-studio { font-size: 35px; background-image: conic-gradient(blue, aqua, lime, yellow); }
.monka-credit.is-dev { background-image: repeating-conic-gradient(aqua 20%, fuchsia 30%); }
.monka-credit.is-heading-alt { font-size: 40px; margin-top: 1em; background-image: repeating-conic-gradient(red 10%, orange 20%); }
.monka-credit.is-supporter { background-image: radial-gradient(fuchsia 10%, blueviolet 40%, violet 50%); }

.monka-hud {
    position: absolute; top: 0; left: 0; padding: 0.5rem 0.75rem; z-index: 2;
    font-size: 24px; font-weight: 700; line-height: 1.35;
    text-shadow: 0 2px 6px rgba(0, 0, 0, 0.6);
}
.monka-points { color: #b6ff3c; }
.monka-points span { color: #ff8a2a; }
.monka-hp { color: #f5a3e6; }
.monka-combo { color: #ffc93c; }
.monka-hud-buttons { display: flex; align-items: center; gap: 0.5rem; margin-top: 0.4rem; }

.monka-btn {
    font: inherit; font-size: 1rem; font-weight: 700; color: #fff; cursor: pointer;
    padding: 0.45rem 0.9rem; border-radius: 0.4rem;
    background: rgba(59, 130, 246, 0.75); border: 1px solid rgba(59, 130, 246, 0.9);
    transition: background-color 0.2s, transform 0.15s;
}
.monka-btn:hover { background: rgba(59, 130, 246, 1); }
.monka-btn:active { transform: scale(0.95); }
.monka-btn:focus-visible, .monka-difficulty:focus-visible, .monka-close:focus-visible { outline: 2px solid #00f5ff; outline-offset: 3px; }
.monka-music-btn { font-size: 1.5rem; padding: 0.2rem 0.6rem; background: rgba(98, 0, 128, 0.7); border-color: rgba(168, 85, 247, 0.9); }
.monka-music-btn:hover { background: rgba(115, 52, 216, 0.9); }

.monka-music {
    margin-top: 0.5rem; width: 220px; padding: 0.75rem; border-radius: 0.6rem;
    background: rgba(98, 0, 128, 0.85); box-shadow: 2px 2px 10px rgba(0, 0, 0, 0.3);
    font-size: 0.85rem; font-weight: 500; text-shadow: none;
    display: flex; flex-direction: column; gap: 0.5rem;
}
.monka-music .monka-btn { background: rgba(126, 34, 206, 0.9); border-color: transparent; }
.monka-music-nav { display: flex; justify-content: space-between; }
.monka-music-nav .monka-btn { background: none; font-size: 1.25rem; padding: 0.1rem 0.6rem; }
.monka-volume { display: flex; flex-direction: column; gap: 0.25rem; }
.monka-volume input { width: 100%; accent-color: #0084ff; }
.monka-now { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; opacity: 0.85; }

.monka-close {
    position: absolute; top: 0.5rem; right: 0.75rem; z-index: 4;
    width: 2.5rem; height: 2.5rem; border-radius: 9999px; cursor: pointer;
    font-size: 1.75rem; line-height: 1; color: #fff;
    background: rgba(0, 0, 0, 0.55); border: 1px solid rgba(255, 255, 255, 0.3);
}
.monka-close:hover { background: rgba(255, 255, 255, 0.2); }

.monka-toast {
    position: absolute; top: 1rem; left: 50%; transform: translateX(-50%); z-index: 2;
    max-width: calc(100% - 8rem); padding: 0.5rem 1rem; border-radius: 0.4rem;
    background: rgba(168, 85, 247, 0.8); animation: monkaToast 5s ease-in-out forwards;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* Achievement popup: centre of the screen, above the menus, never in the way of typing. */
@keyframes monkaAchievement {
    0% { opacity: 0; transform: translate(-50%, -50%) scale(0.6); }
    12% { opacity: 1; transform: translate(-50%, -50%) scale(1.06); }
    20%, 82% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
    100% { opacity: 0; transform: translate(-50%, -50%) scale(0.95); }
}
.monka-achievement {
    position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); z-index: 5;
    width: max-content; max-width: calc(100% - 2rem); padding: 1rem 2rem; text-align: center;
    border-radius: 0.75rem; pointer-events: none;
    background: rgba(2, 10, 24, 0.96); border: 2px solid #ffd53c;
    box-shadow: 0 0 28px rgba(255, 213, 60, 0.55), inset 0 0 18px rgba(255, 213, 60, 0.15);
    animation: monkaAchievement 3.5s ease-out forwards;
}
.monka-achievement-avatar { margin-top: 0.15rem; font-size: 0.85rem; color: #7fe9ff; }
.monka-achievement-icon { display: block; width: 96px; height: 96px; margin: 0 auto 0.4rem; image-rendering: pixelated; }
.monka-achievement-label { font-family: "Orbitron", sans-serif; font-size: 0.8rem; letter-spacing: 0.2em; text-transform: uppercase; color: #ffd53c; }
.monka-achievement-name { font-family: "Orbitron", sans-serif; font-size: 2rem; font-weight: 800; line-height: 1.25; color: #fff; text-shadow: 0 0 14px rgba(255, 213, 60, 0.8); }
.monka-achievement-goal { color: #cbd5e1; font-size: 1rem; }
.monka-achievement-prize { margin-top: 0.35rem; font-weight: 700; font-size: 1.1rem; color: #b6ff3c; }
@media (prefers-reduced-motion: reduce) {
    .monka-achievement { animation-name: monkaToast; }
}

.monka-overlay {
    position: absolute; inset: 0; z-index: 3; padding: 1rem; overflow-y: auto;
    display: flex; align-items: center; justify-content: center; background: rgba(0, 0, 0, 0.55);
}
.monka-panel {
    width: min(100%, 440px); padding: 1.5rem; text-align: center; border-radius: 0.75rem;
    background: rgba(0, 0, 0, 0.88); border: 1px solid #69ff00;
}
.monka-title { font-family: "Orbitron", sans-serif; font-size: 1.75rem; font-weight: 800; color: #b6ff3c; margin-bottom: 0.75rem; }
.monka-help { color: #cbd5e1; font-size: 0.95rem; line-height: 1.5; margin-bottom: 0.75rem; }
.monka-best span { color: #ff8a2a; font-weight: 700; }
.monka-keyboard-note { margin: 0.75rem 0 0; font-size: 0.8rem; color: #94a3b8; }

.monka-difficulties { display: flex; flex-direction: column; gap: 0.6rem; }
.monka-difficulty {
    padding: 0.6rem; border: 0; border-radius: 0.3rem; cursor: pointer;
    font: inherit; font-size: 30px; font-weight: 700; color: #fff;
    text-shadow: -2px -2px 0 #000, 2px -2px 0 #000, -2px 2px 0 #000, 2px 2px 0 #000;
    transition: background-color 0.2s;
}
.monka-difficulty.is-ultimate { background: #8000cb; }
.monka-difficulty.is-hard { background: #ff0000; }
.monka-difficulty.is-normal { background: #00c800; }
.monka-difficulty:hover { background: #009bff; }

.monka-pb { color: #00f5ff; font-family: "Orbitron", sans-serif; font-size: 0.8rem; letter-spacing: 0.15em; text-transform: uppercase; margin-bottom: 0.75rem; }
.monka-stats { display: grid; gap: 0.5rem; margin-bottom: 1rem; }
.monka-stats > div { display: flex; justify-content: space-between; align-items: center; padding: 0.5rem 0.75rem; border-radius: 0.3rem; background: rgba(255, 255, 255, 0.06); }
.monka-stats dt { color: #9ca3af; font-size: 0.9rem; }
.monka-stats dd { margin: 0; font-weight: 700; color: #b6ff3c; }
.monka-primary { background: rgba(0, 200, 0, 0.8); border-color: #69ff00; padding: 0.6rem 1.5rem; }
.monka-primary:hover { background: rgba(0, 200, 0, 1); }

.monka-rainbow, .monka-hall-row.is-rank-1 .monka-hall-name {
    background-image: linear-gradient(to right, #ff0000 0%, #ff9a00 12.5%, #ffff00 25%, #4fdc4a 37.5%, #3fdad8 50%, #2fc9e2 62.5%, #ba0cf8 75%, #fb07d9 87.5%, #ff0000 100%);
    background-size: 200% 100%; -webkit-background-clip: text; background-clip: text; color: transparent;
    animation: monkaRainbow 15s linear infinite;
}
.monka-hall-list { list-style: none; margin: 0 0 1rem; padding: 0; text-align: left; }
.monka-hall-tabs { display: inline-flex; gap: 0.25rem; padding: 0.25rem; margin-bottom: 0.75rem; border-radius: 0.5rem; border: 1px solid rgba(105, 255, 0, 0.35); }
.monka-hall-tab {
    font: inherit; font-size: 0.8rem; font-weight: 700; color: #9ca3af; cursor: pointer;
    padding: 0.3rem 0.8rem; border-radius: 0.35rem; background: none; border: 1px solid transparent;
}
.monka-hall-tab[aria-pressed="true"] { color: #b6ff3c; background: rgba(105, 255, 0, 0.15); border-color: rgba(105, 255, 0, 0.5); }
.monka-hall-tab:disabled { opacity: 0.5; cursor: not-allowed; }
.monka-hall-tab:focus-visible { outline: 2px solid #00f5ff; outline-offset: 2px; }
.monka-hall-row { display: flex; align-items: center; gap: 0.6rem; padding: 0.4rem 0; border-bottom: 1px solid rgba(255, 255, 255, 0.2); font-weight: 600; }
.monka-hall-row:last-child { border-bottom: 0; }
.monka-hall-rank { color: #ffc93c; min-width: 1.6rem; }
.monka-hall-avatar { flex-shrink: 0; }
.monka-hall-avatar:empty { display: none; }
.monka-hall-name { color: #ffc93c; flex: 1; min-width: 0; overflow-wrap: anywhere; }
.monka-hall-row.is-rank-2 .monka-hall-name, .monka-hall-row.is-rank-2 .monka-hall-rank { color: #ff9a00; }
.monka-hall-row.is-rank-3 .monka-hall-name, .monka-hall-row.is-rank-3 .monka-hall-rank { color: #40e0d0; }
.monka-hall-score { color: lime; }
.monka-hall-empty { color: #9ca3af; text-align: center; padding: 0.75rem 0; }

@media (max-width: 640px) {
    .monka-hud { font-size: 18px; }
    .monka-difficulty { font-size: 24px; }
}
@media (prefers-reduced-motion: reduce) {
    .monka-rainbow, .monka-hall-row.is-rank-1 .monka-hall-name { animation: none; }
}
