:root {
    --bg-1: #090a16;
    --bg-2: #14122b;
    --bg-3: #1a0f22;
    --panel: rgba(15, 16, 32, 0.78);
    --panel-border: rgba(153, 225, 255, 0.28);
    --text: #f4f8ff;
    --muted: #b5bfd6;
    --accent: #6de5ff;
    --accent-2: #ffca5f;
    --danger: #ff5774;
    --heal: #63ffa0;
    --shadow: 0 16px 48px rgba(0, 0, 0, 0.45);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    color: var(--text);
    font-family: "Trebuchet MS", "Lucida Sans Unicode", "Lucida Grande", sans-serif;
    background: radial-gradient(circle at 20% 20%, #1f2a55 0%, transparent 35%),
        radial-gradient(circle at 85% 30%, #3a174f 0%, transparent 36%),
        linear-gradient(135deg, var(--bg-1), var(--bg-2) 55%, var(--bg-3));
    overflow-x: hidden;
}

.magic-bg {
    position: fixed;
    inset: 0;
    pointer-events: none;
    background-image:
        radial-gradient(2px 2px at 20% 40%, rgba(255, 255, 255, 0.8), transparent),
        radial-gradient(1px 1px at 50% 70%, rgba(109, 229, 255, 0.8), transparent),
        radial-gradient(1.5px 1.5px at 80% 20%, rgba(255, 202, 95, 0.7), transparent),
        radial-gradient(2px 2px at 75% 85%, rgba(255, 255, 255, 0.75), transparent);
    opacity: 0.35;
    animation: twinkle 7s linear infinite;
}

@keyframes twinkle {
    0% {
        transform: translateY(0);
    }

    50% {
        transform: translateY(-8px);
    }

    100% {
        transform: translateY(0);
    }
}

.game-shell {
    position: relative;
    z-index: 1;
    width: min(1120px, 94vw);
    margin: 0 auto;
    padding: 24px 0 40px;
}

.game-header {
    text-align: center;
    margin-bottom: 20px;
}

.game-header h1 {
    margin: 10px 0 8px;
    font-size: clamp(2rem, 4vw, 3rem);
    letter-spacing: 0.06em;
    text-transform: uppercase;
    text-shadow: 0 0 12px rgba(109, 229, 255, 0.7), 0 0 34px rgba(109, 229, 255, 0.3);
}

.game-header p {
    margin: 0;
    color: var(--muted);
}

.screen {
    display: none;
}

.screen.active {
    display: block;
    animation: rise 0.45s ease;
}

@keyframes rise {
    from {
        transform: translateY(14px);
        opacity: 0;
    }

    to {
        transform: translateY(0);
        opacity: 1;
    }
}

#selection-screen h2,
.spell-panel h2 {
    margin-top: 0;
    text-align: center;
    letter-spacing: 0.04em;
}

.character-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 14px;
}

.character-card {
    padding: 16px;
    background: linear-gradient(160deg, rgba(20, 24, 45, 0.93), rgba(19, 15, 36, 0.93));
    border: 1px solid rgba(139, 220, 255, 0.27);
    border-radius: 14px;
    box-shadow: var(--shadow);
    cursor: pointer;
    transition: transform 0.25s ease, border-color 0.25s ease, box-shadow 0.25s ease;
}

.character-card:hover {
    transform: translateY(-5px);
    border-color: rgba(255, 202, 95, 0.8);
    box-shadow: 0 16px 48px rgba(3, 11, 32, 0.8), 0 0 22px rgba(255, 202, 95, 0.25);
}

.character-avatar {
    font-size: 2.2rem;
    margin-bottom: 8px;
}

.character-card h3 {
    margin: 0 0 6px;
}

.character-card p {
    margin: 0;
    color: var(--muted);
    font-size: 0.95rem;
    line-height: 1.4;
}

.battle-top {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    gap: 14px;
    align-items: center;
    margin-bottom: 16px;
}

.wizard-card,
.spell-panel,
.end-card {
    background: var(--panel);
    border: 1px solid var(--panel-border);
    border-radius: 16px;
    box-shadow: var(--shadow);
    backdrop-filter: blur(6px);
}

.wizard-card {
    padding: 16px;
}

.versus {
    font-weight: bold;
    letter-spacing: 0.1em;
    font-size: 1.35rem;
    color: var(--accent-2);
    text-shadow: 0 0 12px rgba(255, 202, 95, 0.45);
}

.avatar {
    font-size: 3rem;
    margin: 8px 0;
}

.trait {
    margin: 0 0 12px;
    color: var(--muted);
}

.health-wrap {
    margin-top: 12px;
}

.health-label-row {
    display: flex;
    justify-content: space-between;
    color: var(--muted);
    font-size: 0.92rem;
    margin-bottom: 6px;
}

.health-bar-outer {
    width: 100%;
    height: 14px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.18);
    overflow: hidden;
}

.health-bar {
    width: 100%;
    height: 100%;
    transition: width 0.35s ease;
}

.player-bar {
    background: linear-gradient(90deg, #63ffa0, #30d7c6);
}

.enemy-bar {
    background: linear-gradient(90deg, #ff8b72, #ff5774);
}

.spell-panel {
    padding: 18px;
}

.spell-buttons {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 10px;
    margin-bottom: 16px;
}

.spell-btn {
    border: 1px solid rgba(109, 229, 255, 0.68);
    border-radius: 999px;
    padding: 11px 10px;
    background: linear-gradient(135deg, rgba(36, 21, 62, 0.95), rgba(20, 43, 74, 0.96));
    color: #effaff;
    font-size: 1rem;
    letter-spacing: 0.02em;
    cursor: pointer;
    transition: transform 0.2s ease, box-shadow 0.2s ease, filter 0.2s ease;
    box-shadow: inset 0 0 12px rgba(109, 229, 255, 0.25), 0 0 14px rgba(109, 229, 255, 0.23);
}

.spell-btn:hover:not(:disabled) {
    transform: translateY(-2px) scale(1.01);
    box-shadow: inset 0 0 12px rgba(255, 202, 95, 0.18), 0 0 24px rgba(109, 229, 255, 0.5);
    filter: brightness(1.06);
}

.spell-btn:disabled {
    cursor: not-allowed;
    opacity: 0.55;
}

.typing-zone {
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 12px;
    padding: 12px;
    background: rgba(7, 9, 20, 0.5);
}

.typing-title {
    margin: 0 0 6px;
    color: var(--accent);
    font-weight: bold;
}

.challenge-row {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    align-items: center;
}

.challenge-string {
    margin: 0;
    font-family: "Courier New", Courier, monospace;
    color: #ffe9b2;
    font-size: 1.03rem;
    min-height: 1.5em;
}

.timer-wrap {
    display: grid;
    justify-items: end;
    color: var(--muted);
}

.timer {
    font-size: 1.5rem;
    color: var(--accent-2);
    font-weight: bold;
}

#typing-input {
    margin-top: 10px;
    width: 100%;
    background: rgba(3, 5, 14, 0.95);
    color: var(--text);
    border: 1px solid rgba(109, 229, 255, 0.4);
    border-radius: 10px;
    padding: 11px 12px;
    font-size: 1rem;
}

#typing-input:focus {
    outline: 2px solid rgba(109, 229, 255, 0.38);
    outline-offset: 2px;
}

.battle-message {
    min-height: 1.5em;
    margin-bottom: 0;
    margin-top: 14px;
    color: #f4d48d;
}

.end-card {
    max-width: 560px;
    margin: 24px auto;
    padding: 22px;
    text-align: center;
}

.end-card h2 {
    margin-top: 4px;
    font-size: 2rem;
}

.end-card p {
    color: var(--muted);
}

.end-actions {
    display: flex;
    justify-content: center;
    gap: 12px;
    flex-wrap: wrap;
}

.action-btn {
    border: 0;
    border-radius: 10px;
    padding: 11px 16px;
    font-size: 0.98rem;
    cursor: pointer;
    background: linear-gradient(130deg, #5ad2f5, #3b80f7);
    color: #051229;
    font-weight: 700;
}

.action-btn.secondary {
    background: linear-gradient(130deg, #ffca5f, #ff9b5a);
}

.shake {
    animation: shake 0.42s linear;
}

@keyframes shake {

    0%,
    100% {
        transform: translateX(0);
    }

    20% {
        transform: translateX(-6px);
    }

    40% {
        transform: translateX(6px);
    }

    60% {
        transform: translateX(-4px);
    }

    80% {
        transform: translateX(4px);
    }
}

@media (max-width: 860px) {
    .battle-top {
        grid-template-columns: 1fr;
    }

    .versus {
        text-align: center;
        margin: 4px 0;
    }

    .spell-buttons {
        grid-template-columns: 1fr;
    }
}