/* ==========================================================================
   Chemo Crossroads - Stylesheet
   Designed with Fredoka typography, storybook watercolor aesthetics,
   and the Science Games Lab Immune Rush UI standard.
   ========================================================================== */

* {
    box-sizing: border-box;
}

html, body {
    height: 100%;
    margin: 0;
    padding: 0;
    overflow: hidden;
    background-color: #0f172a;
    color: #f8fafc;
    font-family: 'Fredoka', sans-serif;
    user-select: none;
    -webkit-user-select: none;
    display: flex;
    flex-direction: column;
}

/* --------------------------------------------------------------------------
   Layout Structure (Immune Rush Baseline)
   -------------------------------------------------------------------------- */

.page-container {
    width: 100%;
    flex: 1 1 auto;
    display: flex;
    flex-direction: column;
    padding: 0.75rem 1rem;
    box-sizing: border-box;
    min-height: 0;
}

.game-wrapper {
    width: 100%;
    max-width: 64rem;
    margin: 0 auto;
    flex: 1 1 auto;
    display: flex;
    flex-direction: column;
    min-height: 0;
    position: relative;
}

.leaderboard-panel {
    display: none;
}

/* Centered Footer with Science Games Lab Logo */
footer {
    flex-shrink: 0;
    padding: 0.5rem 1rem 0.85rem 1rem;
    box-sizing: border-box;
    width: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
}

.footer-content {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1.5rem;
}

.footer-content img,
.footer-logo {
    height: 3.75rem;
    max-height: 64px;
    width: auto;
    object-fit: contain;
    transition: transform 0.2s ease-in-out, opacity 0.2s ease;
    opacity: 0.9;
}

.footer-content a:hover img,
.footer-logo:hover {
    transform: scale(1.05);
    opacity: 1;
}

@media (min-width: 768px) {
    .footer-content img,
    .footer-logo {
        height: 4rem;
    }
}

/* --------------------------------------------------------------------------
   Desktop 2-Column Grid Layout
   -------------------------------------------------------------------------- */

@media (min-width: 1024px) {
    .page-container {
        display: grid;
        grid-template-columns: minmax(0, 3.2fr) minmax(0, 1fr);
        width: 100%;
        max-width: 86rem;
        margin: 0 auto;
        padding: 0.75rem 1rem;
        gap: 1.25rem;
        flex: 1 1 auto;
        min-height: 0;
        box-sizing: border-box;
        align-items: stretch;
    }

    .game-wrapper {
        max-width: 100%;
        margin: 0;
        padding: 0;
    }

    .leaderboard-panel {
        display: flex !important;
        flex-direction: column;
        background: rgba(15, 23, 42, 0.85);
        backdrop-filter: blur(12px);
        border: 2px solid rgba(56, 189, 248, 0.25);
        border-radius: 1rem;
        padding: 1rem;
        min-height: 0;
        box-shadow: 0 10px 25px rgba(0, 0, 0, 0.4);
    }
}

/* --------------------------------------------------------------------------
   Compact HUD (Positioned Directly Over Game Area)
   -------------------------------------------------------------------------- */

.hud {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
    flex-shrink: 0;
}

.hud-element {
    background: rgba(15, 23, 42, 0.85);
    backdrop-filter: blur(8px);
    padding: 0.4rem 0.85rem;
    border-radius: 0.75rem;
    border: 1.5px solid rgba(148, 163, 184, 0.3);
    font-size: 0.9rem;
    font-weight: 700;
    letter-spacing: 0.3px;
    white-space: nowrap;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 2.35rem;
}

.hud-center {
    flex: 1 1 auto;
    max-width: 14rem;
    min-width: 9rem;
}

.toxicity-container {
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
    width: 100%;
}

.toxicity-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.75rem;
    font-weight: 700;
    padding: 0 0.2rem;
}

.toxicity-bar {
    width: 100%;
    height: 0.65rem;
    background: rgba(0, 0, 0, 0.5);
    border: 1px solid rgba(244, 63, 94, 0.4);
    border-radius: 9999px;
    overflow: hidden;
    padding: 1px;
}

.toxicity-bar-fill {
    height: 100%;
    background: linear-gradient(90deg, #f43f5e 0%, #e11d48 100%);
    border-radius: 9999px;
    transition: width 0.25s ease-out;
    box-shadow: 0 0 8px rgba(244, 63, 94, 0.5);
}

.hud-combo {
    color: #facc15;
    border-color: rgba(250, 204, 21, 0.45);
    min-width: 6.5rem;
    text-align: center;
}

.hud-combo.combo-pulse {
    animation: combo-pulse-anim 0.3s ease-out;
}

@keyframes combo-pulse-anim {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.18); border-color: #facc15; }
}

.hud-phase-container {
    display: flex;
    align-items: center;
}

.hud-phase {
    font-size: 0.85rem;
    font-weight: 700;
    letter-spacing: 0.5px;
    padding: 0.4rem 0.9rem;
    border-radius: 0.75rem;
    transition: all 0.3s ease;
}

.phase-treatment {
    background: rgba(239, 68, 68, 0.2);
    color: #f87171;
    border-color: rgba(239, 68, 68, 0.6);
    box-shadow: 0 0 10px rgba(239, 68, 68, 0.25);
}

.phase-recovery {
    background: rgba(34, 197, 94, 0.2);
    color: #4ade80;
    border-color: rgba(34, 197, 94, 0.6);
    box-shadow: 0 0 10px rgba(34, 197, 94, 0.25);
}

.hud-mute-button {
    cursor: pointer;
    background: rgba(15, 23, 42, 0.85);
    border: 1.5px solid rgba(148, 163, 184, 0.3);
    color: #94a3b8;
    padding: 0.4rem 0.6rem;
    border-radius: 0.75rem;
    transition: all 0.2s ease;
}

.hud-mute-button:hover {
    color: #38bdf8;
    border-color: rgba(56, 189, 248, 0.6);
    transform: scale(1.05);
}

/* --------------------------------------------------------------------------
   Game Area Wrapper & Canvas Container
   -------------------------------------------------------------------------- */

.game-area-wrapper {
    position: relative;
    width: 100%;
    flex: 1 1 auto;
    aspect-ratio: 16 / 9;
    max-height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 1rem;
    overflow: hidden;
    background: radial-gradient(circle at center, #1e1b4b 0%, #090d16 100%);
    border: 2px solid rgba(56, 189, 248, 0.3);
    box-shadow: 0 12px 30px rgba(0, 0, 0, 0.5), inset 0 0 40px rgba(15, 23, 42, 0.6);
    transition: border-color 0.3s ease, box-shadow 0.3s ease;
}

.game-area-wrapper.crisis {
    border-color: #ef4444;
    animation: pulse-border-crisis 1s infinite;
}

.game-area-wrapper.nausea {
    animation: nausea-wave 0.6s infinite ease-in-out;
}

@keyframes pulse-border-crisis {
    50% { box-shadow: 0 0 25px rgba(239, 68, 68, 0.6), inset 0 0 20px rgba(239, 68, 68, 0.3); }
}

@keyframes nausea-wave {
    0%, 100% { transform: skewX(0deg) rotate(0deg); }
    25% { transform: skewX(1deg) rotate(0.4deg); }
    75% { transform: skewX(-1deg) rotate(-0.4deg); }
}

#game-container {
    width: 100%;
    height: 100%;
    position: relative;
    box-sizing: border-box;
    overflow: hidden;
    cursor: crosshair;
}

#sickly-overlay {
    position: absolute;
    inset: 0;
    background: radial-gradient(circle, rgba(16, 185, 129, 0.15) 0%, rgba(244, 63, 94, 0.25) 100%);
    backdrop-filter: blur(2px);
    z-index: 40;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.4s ease;
}

#sickly-overlay.active {
    opacity: 1;
}

/* --------------------------------------------------------------------------
   In-Game Entities (Ship, Shots, Cells)
   -------------------------------------------------------------------------- */

#player {
    position: absolute;
    width: 84px;
    height: 70px;
    background-image: url('img/dose_ship.png');
    background-size: contain;
    background-repeat: no-repeat;
    background-position: center;
    bottom: 12px;
    left: 0;
    will-change: transform;
    z-index: 30;
    transition: filter 0.2s ease;
}

#player.shield-active {
    filter: drop-shadow(0 0 10px #34d399);
}

#player.targeted-active {
    filter: drop-shadow(0 0 10px #38bdf8);
}

#player.heroic {
    filter: drop-shadow(0 0 14px #facc15) brightness(1.2);
}

.chemo-shot {
    position: absolute;
    width: 8px;
    height: 18px;
    background-image: url('img/chemo_shot.png');
    background-size: contain;
    background-repeat: no-repeat;
    background-position: center;
    will-change: transform;
    z-index: 20;
    filter: drop-shadow(0 0 6px #fde047);
}

.chemo-shot.targeted-active {
    filter: drop-shadow(0 0 8px #38bdf8);
}

.cell {
    position: absolute;
    width: 44px;
    height: 44px;
    user-select: none;
    will-change: transform;
    z-index: 15;
    transition: transform 0.1s ease;
}

.cell.hit {
    transform: scale(0.85);
}

.cell.recovery-safe {
    filter: drop-shadow(0 0 8px rgba(74, 222, 128, 0.6));
}

.sprite {
    width: 100%;
    height: 100%;
    background-size: contain;
    background-position: center;
    background-repeat: no-repeat;
}

.sprite.cancer { background-image: url('img/cancer_cell.png'); animation: pulse-bad 1.2s infinite ease-in-out; }
.sprite.resistant-cancer { background-image: url('img/resistant_cancer_cell.png'); animation: pulse-resistant 0.8s infinite ease-in-out; }
.sprite.metastasis { background-image: url('img/metastasis_cluster.png'); animation: pulse-resistant 0.6s infinite ease-in-out; }
.sprite.hair-follicle { background-image: url('img/hair_follicle_cell.png'); }
.sprite.stomach-lining { background-image: url('img/stomach_lining_cell.png'); }
.sprite.blood-cell { background-image: url('img/red_blood_cell.png'); }
.sprite.nerve { background-image: url('img/nerve_cell.png'); }
.sprite.stomach-protector { background-image: url('img/stomach_protector.png'); animation: float-powerup 1.4s infinite ease-in-out; }
.sprite.targeted-therapy { background-image: url('img/targeted_therapy.png'); animation: float-powerup 1.4s infinite ease-in-out; }
.sprite.hydration { background-image: url('img/hydration_boost.png'); animation: float-powerup 1.2s infinite ease-in-out; }

@keyframes pulse-bad {
    0%, 100% { transform: scale(1); filter: drop-shadow(0 0 4px rgba(244, 63, 94, 0.3)); }
    50% { transform: scale(1.06); filter: drop-shadow(0 0 10px rgba(244, 63, 94, 0.7)); }
}

@keyframes pulse-resistant {
    0%, 100% { transform: scale(1); filter: drop-shadow(0 0 6px rgba(217, 70, 239, 0.4)); }
    50% { transform: scale(1.08); filter: drop-shadow(0 0 14px rgba(217, 70, 239, 0.8)); }
}

@keyframes float-powerup {
    0%, 100% { transform: translateY(0) scale(1); }
    50% { transform: translateY(-4px) scale(1.08); filter: drop-shadow(0 0 10px rgba(56, 189, 248, 0.7)); }
}

/* --------------------------------------------------------------------------
   Metastasis Mini-Boss
   -------------------------------------------------------------------------- */

.metastasis-cluster {
    position: absolute;
    width: 104px;
    height: 104px;
    user-select: none;
    will-change: transform;
    z-index: 25;
    transition: transform 0.1s ease;
}

.metastasis-cluster.hit {
    transform: scale(0.95);
}

.cluster-health-bar {
    position: absolute;
    bottom: -16px;
    left: 5%;
    width: 90%;
    height: 10px;
    background-color: rgba(15, 23, 42, 0.8);
    border: 1.5px solid rgba(244, 63, 94, 0.6);
    border-radius: 9999px;
    padding: 1px;
}

.cluster-health-fill {
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, #f43f5e, #be123c);
    border-radius: 9999px;
    transition: width 0.2s ease-out;
}

/* --------------------------------------------------------------------------
   Floating Score Pops and Notifications
   -------------------------------------------------------------------------- */

#score-pop-container {
    position: absolute;
    inset: 0;
    pointer-events: none;
    overflow: hidden;
    z-index: 50;
}

.score-pop {
    position: absolute;
    font-size: 1.15rem;
    font-weight: 700;
    pointer-events: none;
    z-index: 55;
    animation: score-pop-anim 0.9s ease-out forwards;
}

.score-positive {
    color: #fde047;
    text-shadow: 0 0 8px rgba(234, 179, 8, 0.7);
}

.score-negative {
    color: #f87171;
    text-shadow: 0 0 8px rgba(239, 68, 68, 0.7);
}

.score-combo {
    color: #38bdf8;
    font-size: 1.35rem;
    text-shadow: 0 0 12px rgba(56, 189, 248, 0.8);
}

@keyframes score-pop-anim {
    0% { transform: translate(-50%, 0) scale(0.8); opacity: 1; }
    50% { transform: translate(-50%, -25px) scale(1.15); opacity: 1; }
    100% { transform: translate(-50%, -45px) scale(1); opacity: 0; }
}

#notification-container {
    position: absolute;
    top: 30%;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    pointer-events: none;
    z-index: 60;
}

.notification-item {
    font-size: 1.4rem;
    font-weight: 700;
    letter-spacing: 0.5px;
    padding: 0.4rem 1.2rem;
    border-radius: 9999px;
    background: rgba(15, 23, 42, 0.85);
    border: 1.5px solid rgba(255, 255, 255, 0.2);
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.5);
    animation: notif-in 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
    opacity: 1;
    transition: opacity 0.4s ease, transform 0.4s ease;
}

.notification-item.fade-out {
    opacity: 0;
    transform: translateY(-15px) scale(0.9);
}

@keyframes notif-in {
    from { opacity: 0; transform: translateY(20px) scale(0.8); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

/* --------------------------------------------------------------------------
   Aspect-Ratio Preserving Sprite Containers
   -------------------------------------------------------------------------- */

.icon-container {
    width: 3.25rem;
    height: 3.25rem;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.08);
    border-radius: 0.65rem;
    padding: 0.35rem;
    box-sizing: border-box;
    transition: transform 0.2s ease, background-color 0.2s ease;
}

.icon-container img,
.card-portrait img,
.tutorial-icon-box img {
    max-width: 100%;
    max-height: 100%;
    width: auto;
    height: auto;
    object-fit: contain;
    display: block;
}

/* --------------------------------------------------------------------------
   Modals & Character Trading Cards
   -------------------------------------------------------------------------- */

.modal {
    position: absolute;
    inset: 0;
    background: rgba(10, 15, 30, 0.88);
    backdrop-filter: blur(10px);
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 1rem;
    z-index: 100;
    box-sizing: border-box;
    overflow-y: auto;
}

.modal-header {
    flex-shrink: 0;
    padding-bottom: 0.5rem;
    text-align: center;
}

.modal-title {
    font-size: 2rem;
    font-weight: 700;
    color: #ffffff;
    margin: 0 0 0.25rem 0;
    letter-spacing: 0.5px;
    text-shadow: 0 2px 10px rgba(0, 0, 0, 0.5);
}

.modal-subtitle {
    font-size: 1rem;
    font-weight: 600;
    color: #38bdf8;
    margin: 0;
}

.modal-body {
    flex-grow: 1;
    overflow-y: auto;
    width: 100%;
    min-height: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    padding: 0.25rem 0;
}

.modal-footer {
    display: flex;
    flex-direction: column;
    align-items: center;
    flex-shrink: 0;
    padding-top: 0.75rem;
    width: 100%;
}

/* Compact Intro Box and Hint */
.intro-box {
    width: 100%;
    max-width: 58rem;
    margin: 0 auto;
    padding: 0.6rem;
    background-color: rgba(15, 23, 42, 0.65);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 0.85rem;
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    box-sizing: border-box;
}

.cards-hint {
    text-align: center;
    font-size: 0.8rem;
    font-weight: 500;
    color: #94a3b8;
    letter-spacing: 0.3px;
}

/* Responsive Grid for Character Cards */
.cards-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.45rem;
    width: 100%;
}

@media (min-width: 540px) {
    .cards-grid {
        grid-template-columns: repeat(3, 1fr);
    }
}

@media (min-width: 768px) {
    .cards-grid {
        grid-template-columns: repeat(4, 1fr);
    }
}

@media (min-width: 1024px) {
    .cards-grid {
        grid-template-columns: repeat(6, 1fr);
    }
}

/* Compact Card Styling */
.character-card {
    position: relative;
    background: rgba(255, 255, 255, 0.04);
    border: 1.5px solid rgba(255, 255, 255, 0.12);
    border-radius: 0.85rem;
    padding: 0.55rem 0.45rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    cursor: pointer;
    user-select: none;
    transition: transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.2s ease, border-color 0.2s ease, background 0.2s ease;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3);
    overflow: hidden;
}

.character-card:hover {
    animation: wiggle 0.4s ease-in-out;
    transform: translateY(-4px) scale(1.03);
    background: rgba(255, 255, 255, 0.08);
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.45);
}

.character-card:active {
    transform: scale(0.96);
}

@keyframes wiggle {
    0%, 100% { transform: translateY(-4px) rotate(0deg) scale(1.03); }
    25% { transform: translateY(-4px) rotate(-3deg) scale(1.03); }
    75% { transform: translateY(-4px) rotate(3deg) scale(1.03); }
}

/* 4-Sided Border Roles */
.card-hero { border-color: rgba(34, 211, 238, 0.4); }
.card-hero:hover { border-color: #22d3ee; box-shadow: 0 8px 24px rgba(34, 211, 238, 0.3); }

.card-threat { border-color: rgba(244, 63, 94, 0.4); }
.card-threat:hover { border-color: #f43f5e; box-shadow: 0 8px 24px rgba(244, 63, 94, 0.3); }

.card-bystander { border-color: rgba(251, 191, 36, 0.35); }
.card-bystander:hover { border-color: #fbbf24; box-shadow: 0 8px 24px rgba(251, 191, 36, 0.25); }

.card-powerup { border-color: rgba(56, 189, 248, 0.4); }
.card-powerup:hover { border-color: #38bdf8; box-shadow: 0 8px 24px rgba(56, 189, 248, 0.3); }

.card-badge {
    font-size: 0.65rem;
    font-weight: 700;
    padding: 0.15rem 0.55rem;
    border-radius: 9999px;
    letter-spacing: 0.5px;
    text-transform: uppercase;
    margin-bottom: 0.3rem;
    line-height: 1.2;
}

.badge-hero { background: rgba(34, 211, 238, 0.2); color: #67e8f9; border: 1px solid rgba(34, 211, 238, 0.4); }
.badge-threat { background: rgba(244, 63, 94, 0.2); color: #fda4af; border: 1px solid rgba(244, 63, 94, 0.4); }
.badge-bystander { background: rgba(251, 191, 36, 0.2); color: #fde68a; border: 1px solid rgba(251, 191, 36, 0.4); }
.badge-critical { background: rgba(239, 68, 68, 0.25); color: #fca5a5; border: 1px solid rgba(239, 68, 68, 0.5); }
.badge-powerup { background: rgba(52, 211, 153, 0.2); color: #6ee7b7; border: 1px solid rgba(52, 211, 153, 0.4); }
.badge-support { background: rgba(56, 189, 248, 0.2); color: #7dd3fc; border: 1px solid rgba(56, 189, 248, 0.4); }

.card-portrait {
    width: 3.25rem;
    height: 3.25rem;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.3);
    border-radius: 0.65rem;
    padding: 0.3rem;
    box-sizing: border-box;
    margin-bottom: 0.3rem;
    transition: transform 0.2s ease;
}

.character-card:hover .card-portrait {
    transform: scale(1.08);
}

.card-name {
    font-size: 0.85rem;
    font-weight: 700;
    line-height: 1.2;
    margin-bottom: 0.15rem;
}

.card-ability {
    font-size: 0.7rem;
    color: #cbd5e1;
    line-height: 1.25;
    font-weight: 500;
}

.treatment-cycle-hint {
    text-align: center;
    font-size: 0.8rem;
    color: #94a3b8;
    margin: 0.4rem 0 0 0;
}

/* --------------------------------------------------------------------------
   Buttons & Inputs
   -------------------------------------------------------------------------- */

.player-name-input {
    background-color: rgba(30, 41, 59, 0.9);
    color: white;
    width: 100%;
    max-width: 22rem;
    text-align: center;
    padding: 0.55rem 1rem;
    border-radius: 0.65rem;
    border: 1.5px solid rgba(148, 163, 184, 0.4);
    margin-bottom: 0.75rem;
    font-family: 'Fredoka', sans-serif;
    font-size: 1rem;
    font-weight: 600;
    transition: border-color 0.2s ease;
}

.player-name-input:focus {
    outline: none;
    border-color: #38bdf8;
    box-shadow: 0 0 12px rgba(56, 189, 248, 0.3);
}

.player-name-input.shake-input {
    animation: input-shake 0.4s ease-in-out;
}

@keyframes input-shake {
    10%, 90% { transform: translateX(-4px); }
    20%, 80% { transform: translateX(4px); }
    30%, 50%, 70% { transform: translateX(-4px); }
    40%, 60% { transform: translateX(4px); }
}

.btn-primary, .btn-secondary {
    font-family: 'Fredoka', sans-serif;
    color: white;
    font-weight: 700;
    padding: 0.65rem 1.5rem;
    border-radius: 0.65rem;
    font-size: 1rem;
    letter-spacing: 0.3px;
    border: none;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    cursor: pointer;
    transition: transform 0.15s ease, box-shadow 0.15s ease, background-color 0.2s;
}

.btn-primary {
    background: linear-gradient(135deg, #10b981 0%, #059669 100%);
}

.btn-primary:hover {
    transform: translateY(-2px) scale(1.02);
    box-shadow: 0 6px 18px rgba(16, 185, 129, 0.4);
}

.btn-primary:active {
    transform: translateY(1px) scale(0.98);
}

.btn-secondary {
    background: linear-gradient(135deg, #0284c7 0%, #0369a1 100%);
}

.btn-secondary:hover {
    transform: translateY(-2px) scale(1.02);
    box-shadow: 0 6px 18px rgba(2, 132, 199, 0.4);
}

.btn-secondary:active {
    transform: translateY(1px) scale(0.98);
}

.modal-footer-buttons {
    display: flex;
    flex-direction: row;
    justify-content: center;
    gap: 0.75rem;
    width: 100%;
    max-width: 24rem;
}

/* --------------------------------------------------------------------------
   How to Play Corner Button & Centered Modal
   -------------------------------------------------------------------------- */

.tutorial-corner-btn {
    position: absolute;
    top: 0.85rem;
    left: 0.85rem;
    right: auto;
    z-index: 20;
    display: flex;
    align-items: center;
    gap: 0.4rem;
    background: rgba(255, 255, 255, 0.08);
    border: 1.5px solid rgba(56, 189, 248, 0.4);
    border-radius: 9999px;
    padding: 0.35rem 0.85rem;
    font-family: 'Fredoka', sans-serif;
    font-weight: 600;
    font-size: 0.8rem;
    color: #a5f3fc;
    cursor: pointer;
    backdrop-filter: blur(6px);
    transition: all 0.2s ease;
}

.tutorial-corner-btn:hover {
    background: rgba(56, 189, 248, 0.2);
    border-color: rgba(56, 189, 248, 0.8);
    transform: translateY(-2px) scale(1.03);
}

.how-to-card {
    position: relative;
    width: 100%;
    max-width: 44rem;
    max-height: 90vh;
    margin: auto;
    overflow-y: auto;
    background: linear-gradient(135deg, rgba(15, 23, 42, 0.98) 0%, rgba(10, 15, 30, 0.98) 100%);
    border: 2px solid rgba(56, 189, 248, 0.45);
    border-radius: 1.25rem;
    padding: 1.25rem 1.5rem;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.7), 0 0 30px rgba(56, 189, 248, 0.2);
    text-align: center;
    box-sizing: border-box;
}

.how-to-header-badge {
    font-size: 0.75rem;
    font-weight: 700;
    background: rgba(56, 189, 248, 0.2);
    color: #7dd3fc;
    border: 1px solid rgba(56, 189, 248, 0.4);
    border-radius: 9999px;
    padding: 0.2rem 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.how-to-title {
    font-size: 1.6rem;
    font-weight: 700;
    color: white;
    margin: 0.5rem 0 0.25rem 0;
}

.how-to-subtitle {
    font-size: 0.85rem;
    color: #94a3b8;
    margin: 0 0 1rem 0;
}

.tutorial-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 0.75rem;
    margin-bottom: 1rem;
}

@media (min-width: 640px) {
    .tutorial-grid {
        grid-template-columns: repeat(3, 1fr);
    }
}

.tutorial-card {
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 0.85rem;
    padding: 0.85rem 0.65rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
}

.tutorial-icon-box {
    width: 3.5rem;
    height: 3.5rem;
    margin-bottom: 0.5rem;
    background: rgba(0, 0, 0, 0.3);
    border-radius: 0.75rem;
}

.tutorial-step-title {
    font-size: 0.95rem;
    font-weight: 700;
    color: #f8fafc;
    margin-bottom: 0.25rem;
}

.tutorial-step-desc {
    font-size: 0.75rem;
    color: #cbd5e1;
    line-height: 1.3;
}

/* --------------------------------------------------------------------------
   Science Fact Modal
   -------------------------------------------------------------------------- */

.fact-card {
    position: relative;
    width: 100%;
    max-width: 28rem;
    background: linear-gradient(135deg, rgba(15, 23, 42, 0.98) 0%, rgba(10, 15, 30, 0.98) 100%);
    border: 2px solid rgba(56, 189, 248, 0.45);
    border-radius: 1.25rem;
    padding: 1.25rem;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.7), 0 0 30px rgba(56, 189, 248, 0.25);
    text-align: center;
    box-sizing: border-box;
    margin: auto;
}

.fact-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    margin-bottom: 0.75rem;
}

.fact-close-btn {
    background: transparent;
    border: none;
    color: #94a3b8;
    font-size: 1.5rem;
    font-weight: 700;
    cursor: pointer;
    line-height: 1;
    transition: color 0.2s ease;
}

.fact-close-btn:hover {
    color: #f43f5e;
}

.fact-portrait {
    width: 5rem;
    height: 5rem;
    margin: 0 auto 0.75rem auto;
    background: rgba(0, 0, 0, 0.35);
    border-radius: 1rem;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.fact-title {
    font-size: 1.35rem;
    font-weight: 700;
    color: #ffffff;
    margin: 0 0 0.4rem 0;
}

.fact-text {
    font-size: 0.85rem;
    color: #cbd5e1;
    line-height: 1.4;
    margin: 0 0 1rem 0;
}

.fact-btn {
    width: 100%;
    max-width: 12rem;
    margin: 0 auto;
}

.fact-card-small {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 0.85rem;
    padding: 0.85rem 1rem;
    max-width: 28rem;
    margin: 0 auto;
}

/* --------------------------------------------------------------------------
   Game Over Modal
   -------------------------------------------------------------------------- */

.game-over-title {
    font-size: 1.85rem;
    color: #facc15;
}

.failure-title {
    color: #f43f5e;
}

.final-score-text {
    font-size: 1.2rem;
    color: #f8fafc;
    font-weight: 700;
    margin: 0.25rem 0;
}

.leaderboard-rank-text {
    font-size: 1rem;
    font-weight: 600;
    color: #38bdf8;
    margin: 0.25rem 0;
}

/* --------------------------------------------------------------------------
   Leaderboard Podium Styling
   -------------------------------------------------------------------------- */

.leaderboard-panel-title {
    font-size: 1.35rem;
    font-weight: 700;
    text-align: center;
    color: #facc15;
    margin: 0 0 0.75rem 0;
    letter-spacing: 0.5px;
}

#desktopLeaderboardList {
    overflow-y: auto;
    flex-grow: 1;
    min-height: 0;
    background: transparent;
    border: none;
    padding: 0;
    max-width: 100%;
}

.leaderboard-box {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    overflow-y: auto;
}

.leaderboard-player {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    min-width: 0;
}

.leaderboard-podium-card {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.55rem 0.75rem;
    margin-bottom: 0.5rem;
    border-radius: 0.65rem;
    background: rgba(255, 255, 255, 0.04);
    transition: transform 0.15s ease-out;
}

.leaderboard-podium-card:hover {
    transform: translateX(2px);
}

.podium-rank-1 {
    background: linear-gradient(90deg, rgba(250, 204, 21, 0.2) 0%, rgba(35, 12, 50, 0.7) 100%);
    border: 1.5px solid rgba(250, 204, 21, 0.6);
    box-shadow: 0 4px 15px rgba(250, 204, 21, 0.2);
}

.podium-rank-2 {
    background: linear-gradient(90deg, rgba(203, 213, 225, 0.16) 0%, rgba(35, 12, 50, 0.7) 100%);
    border: 1.5px solid rgba(203, 213, 225, 0.5);
    box-shadow: 0 3px 12px rgba(203, 213, 225, 0.15);
}

.podium-rank-3 {
    background: linear-gradient(90deg, rgba(217, 119, 6, 0.16) 0%, rgba(35, 12, 50, 0.7) 100%);
    border: 1.5px solid rgba(217, 119, 6, 0.5);
    box-shadow: 0 3px 12px rgba(217, 119, 6, 0.15);
}

.podium-badge {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: 'Fredoka', sans-serif;
    font-weight: 700;
    font-size: 0.95rem;
    flex-shrink: 0;
}

.podium-badge.rank-1 {
    background: linear-gradient(135deg, #facc15 0%, #ca8a04 100%);
    color: #1e092b;
    box-shadow: 0 0 10px rgba(250, 204, 21, 0.6);
}

.podium-badge.rank-2 {
    background: linear-gradient(135deg, #f1f5f9 0%, #94a3b8 100%);
    color: #0f172a;
    box-shadow: 0 0 10px rgba(203, 213, 225, 0.5);
}

.podium-badge.rank-3 {
    background: linear-gradient(135deg, #f59e0b 0%, #b45309 100%);
    color: #ffffff;
    box-shadow: 0 0 10px rgba(217, 119, 6, 0.5);
}

.podium-player-info {
    display: flex;
    flex-direction: column;
    gap: 0.1rem;
    min-width: 0;
}

.podium-player-info .player-name {
    font-weight: 700;
    font-size: 0.95rem;
    color: #ffffff;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.podium-rank-tag {
    font-family: 'Fredoka', sans-serif;
    font-size: 0.62rem;
    font-weight: 700;
    letter-spacing: 0.5px;
    color: #a1a1aa;
    text-transform: uppercase;
}

.podium-open {
    border-style: dashed;
    opacity: 0.55;
}

.player-name-empty {
    color: #71717a;
    font-style: italic;
    font-size: 0.85rem;
}

.player-score-empty {
    color: #52525b;
}

.score-glow-1 {
    color: #facc15;
    font-weight: 700;
    text-shadow: 0 0 10px rgba(250, 204, 21, 0.4);
}

.score-glow-2 {
    color: #e2e8f0;
    font-weight: 700;
}

.score-glow-3 {
    color: #fbbf24;
    font-weight: 700;
}

.leaderboard-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.45rem 0.75rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    transition: background-color 0.15s;
}

.leaderboard-row:hover {
    background-color: rgba(255, 255, 255, 0.03);
}

.leaderboard-row .rank-badge {
    width: 22px;
    height: 22px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: 'Fredoka', sans-serif;
    font-weight: 700;
    font-size: 0.85rem;
    color: #9ca3af;
    flex-shrink: 0;
}

.leaderboard-row .player-name {
    font-size: 0.88rem;
    color: #e4e4e7;
    font-weight: 600;
}

.leaderboard-row .player-score {
    font-family: 'Fredoka', sans-serif;
    font-size: 0.95rem;
    font-weight: 700;
    color: #cbd5e1;
}

.leaderboard-tip {
    margin-top: 0.75rem;
    padding: 0.65rem 0.75rem;
    background: rgba(250, 204, 21, 0.08);
    border: 1px dashed rgba(250, 204, 21, 0.35);
    border-radius: 0.65rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-family: 'Fredoka', sans-serif;
    font-size: 0.75rem;
    color: #fef08a;
    line-height: 1.3;
}

.leaderboard-tip-icon {
    width: 1.5rem;
    height: 1.5rem;
    flex-shrink: 0;
}

.leaderboard-empty {
    padding: 1.5rem 0.5rem;
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.4rem;
}

.leaderboard-trophy-badge {
    margin-bottom: 0.25rem;
}

.leaderboard-empty-title {
    font-family: 'Fredoka', sans-serif;
    font-size: 0.9rem;
    font-weight: 700;
    color: #facc15;
    letter-spacing: 0.5px;
}

.leaderboard-subtext {
    font-size: 0.8rem;
    color: #a1a1aa;
}

/* --------------------------------------------------------------------------
   Rotate Warning & Mobile Responsiveness
   -------------------------------------------------------------------------- */

/* --------------------------------------------------------------------------
   Strict Visibility Enforcement
   -------------------------------------------------------------------------- */

.hidden,
.modal.hidden,
#loading-modal.hidden,
#start-modal.hidden,
#howToModal.hidden,
#factModal.hidden,
#game-over-modal.hidden,
#mainLeaderboardModal.hidden,
#soundOffIcon.hidden,
#soundOnIcon.hidden {
    display: none !important;
}
@media (min-width: 1024px) {
    #leaderboardBtn,
    #leaderboardGameOverBtn {
        display: none !important;
    }
}

.hud-mute-button {
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0.5rem;
    transition: transform 0.15s ease, background-color 0.2s, border-color 0.2s;
}

.hud-mute-button:hover {
    transform: scale(1.06);
    background: rgba(39, 39, 42, 0.95);
    border-color: #a1a1aa;
}

.hud-mute-button:active {
    transform: scale(0.95);
}

.hud-mute-button svg {
    width: 1.25rem;
    height: 1.25rem;
    display: block;
}

#rotate-warning {
    display: none;
    position: fixed;
    inset: 0;
    background-color: #18181b;
    color: #f4f4f5;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    text-align: center;
    z-index: 200;
    padding: 1.5rem;
    font-family: 'Fredoka', sans-serif;
}

.rotate-icon {
    width: 4.5rem;
    height: 4.5rem;
    margin-bottom: 1.25rem;
    color: #38bdf8;
    animation: rotate-pulse 2s infinite ease-in-out;
}

@keyframes rotate-pulse {
    0%, 100% { transform: rotate(0deg) scale(1); }
    50% { transform: rotate(90deg) scale(1.08); }
}

@media screen and (max-width: 1023px) and (orientation: portrait) {
    .page-container, footer {
        display: none !important;
    }
    #rotate-warning {
        display: flex !important;
    }
}

@media screen and (max-height: 540px) and (orientation: landscape) {
    footer {
        display: none !important;
    }
    .page-container {
        padding: 0.25rem 0.5rem;
    }
    .game-wrapper {
        max-width: 100%;
        height: 100%;
    }
    .leaderboard-panel {
        display: none !important;
    }
    .hud {
        display: flex !important;
        flex-direction: row !important;
        justify-content: space-between !important;
        align-items: center !important;
        margin-bottom: 0.25rem !important;
        gap: 0.35rem !important;
    }
    .hud-element {
        font-size: 0.78rem;
        padding: 0.2rem 0.5rem;
        border-radius: 0.5rem;
    }
    .hud-label {
        display: none !important;
    }
    .integrity-container {
        min-width: 70px;
        max-width: 180px;
        flex-grow: 1;
    }
    .integrity-bar {
        height: 0.95rem;
        border-radius: 0.35rem;
    }
    .hud-mute-button {
        display: flex !important;
        padding: 0.2rem 0.4rem;
    }
    .canvas-container,
    .game-area-wrapper,
    #game-container {
        min-height: 0;
        flex: 1 1 auto;
    }
    canvas {
        max-height: 100%;
        max-width: 100%;
    }
    .modal {
        padding: 0.35rem 0.6rem;
    }
    .modal-header {
        padding-bottom: 0.15rem;
    }
    .modal-title {
        font-size: 1.3rem;
        line-height: 1.1;
    }
    .modal-subtitle {
        font-size: 0.7rem;
        margin: 0;
    }
    .tutorial-corner-btn {
        top: 0.35rem;
        left: 0.35rem;
        right: auto !important;
        padding: 0.2rem 0.5rem;
        font-size: 0.7rem;
    }
    .intro-box {
        padding: 0.3rem 0.4rem;
        margin-bottom: 0.25rem;
    }
    .cards-hint {
        font-size: 0.65rem;
        margin-bottom: 0.15rem;
    }
    .cards-grid {
        grid-template-columns: repeat(5, 1fr) !important;
        gap: 0.25rem;
    }
    .character-card {
        padding: 0.25rem 0.2rem;
        border-radius: 0.5rem;
    }
    .card-badge {
        font-size: 0.5rem;
        padding: 0.05rem 0.25rem;
        margin-bottom: 0.15rem;
    }
    .card-portrait, .icon-container {
        width: 2rem;
        height: 2rem;
        padding: 0.15rem;
        margin-bottom: 0.15rem;
    }
    .card-name {
        font-size: 0.65rem;
        margin-bottom: 0.05rem;
    }
    .card-ability {
        font-size: 0.56rem;
        line-height: 1.1;
    }
    .modal-footer {
        padding-top: 0.25rem;
    }
    .player-name-input {
        padding: 0.3rem 0.6rem;
        font-size: 0.85rem;
        max-width: 16rem;
        border-radius: 0.5rem;
    }
    .modal-footer-buttons {
        margin-top: 0.25rem;
        gap: 0.5rem;
    }
    .btn-primary, .btn-secondary {
        padding: 0.35rem 1rem;
        font-size: 0.88rem;
        border-radius: 0.5rem;
    }
    .game-over-title {
        font-size: 1.3rem;
    }
    .game-over-fact-card {
        padding: 0.35rem 0.6rem;
        max-width: 22rem;
        margin: 0.2rem auto;
    }
    .game-over-fact-portrait {
        width: 2.75rem;
        height: 2.75rem;
        margin-bottom: 0.2rem;
    }
    .game-over-fact-title {
        font-size: 0.95rem;
        margin-bottom: 0.15rem;
    }
    .game-over-fact-text {
        font-size: 0.72rem;
        line-height: 1.25;
    }
    #mainLeaderboardModal .modal-body,
    .how-to-card,
    .fact-card {
        max-height: 85vh;
        overflow-y: auto;
    }
    .tutorial-cards {
        grid-template-columns: repeat(3, 1fr) !important;
        gap: 0.35rem;
    }
    .tutorial-card {
        padding: 0.4rem;
    }
    .tutorial-step-img {
        width: 2rem;
        height: 2rem;
    }
}

.science-corner-btn {
    position: absolute;
    top: 1rem;
    left: auto;
    right: 1rem;
    z-index: 20;
    display: flex;
    align-items: center;
    gap: 0.4rem;
    font-family: 'Fredoka', sans-serif;
    font-size: 0.85rem;
    font-weight: 700;
    letter-spacing: 0.5px;
    color: #f4f4f5;
    background: rgba(5, 150, 105, 0.35);
    border: 1.5px solid #34d399;
    border-radius: 9999px;
    padding: 0.35rem 1rem;
    cursor: pointer;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
    transition: all 0.2s;
}
.science-corner-btn:hover {
    background: #059669;
    color: #ffffff;
    box-shadow: 0 0 15px rgba(52, 211, 153, 0.6);
    transform: translateY(-1px);
}
#scienceInfoModal {
    position: fixed;
    inset: 0;
    z-index: 110;
    background: rgba(10, 10, 15, 0.85);
    backdrop-filter: blur(12px);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.5rem 1rem;
    box-sizing: border-box;
}
#scienceInfoModal.hidden {
    display: none !important;
}
.science-info-card {
    position: relative;
    background: #18181b;
    border: 2px solid #34d399;
    border-radius: 1.25rem;
    padding: 1.5rem;
    max-width: 48rem;
    width: 100%;
    max-height: 90vh;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    box-shadow: 0 20px 45px rgba(0, 0, 0, 0.65);
    margin: auto;
}
.science-info-body {
    text-align: left;
    color: #d4d4d8;
    font-family: 'Fredoka', sans-serif;
    font-size: 0.85rem;
    line-height: 1.55;
    width: 100%;
}
.science-info-body h3 {
    color: #6ee7b7;
    font-size: 0.95rem;
    font-weight: 700;
    margin: 1rem 0 0.4rem 0;
}
.science-info-body p { margin: 0.5rem 0; }
.science-info-body ul {
    margin: 0.3rem 0 0.6rem 1.1rem;
    list-style: disc;
}
.science-info-body li { margin: 0.2rem 0; }
.science-info-body a {
    color: #38bdf8;
    text-decoration: underline;
}
.science-info-body a:hover { color: #7dd3fc; }
.science-grade { font-size: 0.8rem; color: #a1a1aa; }
@media (max-width: 1024px) {
    .science-corner-btn {
        top: 0.35rem;
        right: 0.35rem;
        left: auto !important;
        padding: 0.2rem 0.5rem;
        font-size: 0.7rem;
    }
}

.footer-legal {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.9rem;
    margin-top: 0.4rem;
    font-family: 'Fredoka', sans-serif;
    font-size: 0.7rem;
}
.footer-legal a, .footer-legal-btn {
    color: #71717a;
    text-decoration: none;
    background: none;
    border: none;
    padding: 0;
    font: inherit;
    cursor: pointer;
}
.footer-legal a:hover, .footer-legal-btn:hover { color: #34d399; }

footer {
    flex-direction: column;
    gap: 0.4rem;
}
