html, body {
    height: 100%;
    margin: 0;
    padding: 0;
    overflow: hidden;
    box-sizing: border-box;
}

body {
    font-family: 'Fredoka', system-ui, -apple-system, sans-serif;
    background-color: #18181b;
    color: #f4f4f5;
    display: flex;
    flex-direction: column;
}

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

.leaderboard-panel {
    display: none;
}

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

footer {
    flex-shrink: 0;
    padding: 1rem;
    padding-top: 0;
    box-sizing: border-box;
    width: 100%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 0.4rem;
}

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

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

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

.footer-legal {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.9rem;
    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;
}

.canvas-container {
    position: relative;
    width: 100%;
    flex-grow: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 0;
    touch-action: none;
}

canvas {
    background: radial-gradient(circle at 50% 50%, #0d1b2a 0%, #08101a 100%);
    border-radius: 0.75rem;
    cursor: crosshair;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.6), 0 0 25px rgba(6, 182, 212, 0.2);
    transition: box-shadow 0.3s ease-in-out;
    max-width: 100%;
    max-height: 100%;
    aspect-ratio: 16 / 9;
    touch-action: none;
}

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

.hud-element {
    font-family: 'Fredoka', sans-serif;
    font-size: 0.95rem;
    font-weight: 700;
    background: rgba(24, 24, 27, 0.85);
    backdrop-filter: blur(6px);
    padding: 0.45rem 0.8rem;
    border-radius: 0.75rem;
    border: 2px solid #52525b;
    letter-spacing: 0.5px;
    transition: color 0.3s, border-color 0.3s, transform 0.2s, background 0.3s;
    white-space: nowrap;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.hud-oxygen-button {
    cursor: pointer;
    border-color: #06b6d4;
    color: #e0f2fe;
    box-shadow: 0 4px 12px rgba(6, 182, 212, 0.25);
    user-select: none;
    outline: none;
    transition: transform 0.15s, background 0.2s, border-color 0.2s, box-shadow 0.2s;
}

.hud-oxygen-button:hover:not(.disabled) {
    background: rgba(6, 182, 212, 0.2);
    transform: scale(1.04);
}

.hud-oxygen-button:active:not(.disabled) {
    transform: scale(0.96);
}

.hud-oxygen-button.cooldown {
    opacity: 0.65;
    cursor: default;
    border-color: #4b5563;
}

.placard-picker {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 45;
    width: 19rem;
    max-width: 92%;
    background: rgba(13, 17, 26, 0.96);
    border: 2px solid rgba(251, 191, 36, 0.55);
    border-radius: 1rem;
    padding: 0.85rem 0.95rem;
    box-shadow: 0 16px 40px rgba(0, 0, 0, 0.65), 0 0 20px rgba(251, 191, 36, 0.15);
    font-family: 'Fredoka', sans-serif;
    box-sizing: border-box;
}

.placard-picker.hidden {
    display: none !important;
}

.placard-picker-head {
    text-align: center;
    margin-bottom: 0.6rem;
}

.placard-picker-title {
    font-size: 1.05rem;
    font-weight: 700;
    color: #fbbf24;
    letter-spacing: 0.5px;
}

.placard-picker-sub {
    font-size: 0.72rem;
    font-weight: 600;
    color: #a1a1aa;
    margin-top: 0.1rem;
}

.placard-era-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.4rem;
}

.era-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.1rem;
    padding: 0.5rem 0.3rem;
    border-radius: 0.65rem;
    border: 1.5px solid rgba(56, 189, 248, 0.35);
    background: rgba(255, 255, 255, 0.05);
    color: #f4f4f5;
    font-family: 'Fredoka', sans-serif;
    cursor: pointer;
    transition: transform 0.15s, background 0.2s, border-color 0.2s, box-shadow 0.2s;
}

.era-btn:hover {
    background: rgba(56, 189, 248, 0.18);
    border-color: #38bdf8;
    transform: translateY(-2px) scale(1.03);
    box-shadow: 0 4px 14px rgba(56, 189, 248, 0.3);
}

.era-btn:active {
    transform: scale(0.96);
}

.era-btn .era-name {
    font-size: 0.85rem;
    font-weight: 700;
}

.era-btn .era-age {
    font-size: 0.62rem;
    font-weight: 600;
    color: #94a3b8;
}

.placard-cancel {
    display: block;
    margin: 0.6rem auto 0 auto;
    background: none;
    border: none;
    color: #94a3b8;
    font-family: 'Fredoka', sans-serif;
    font-size: 0.72rem;
    font-weight: 600;
    text-decoration: underline;
    cursor: pointer;
    padding: 0.1rem 0.4rem;
}

.placard-cancel:hover {
    color: #ffffff;
}

@media screen and (max-height: 640px), (max-width: 900px) {
    .placard-picker {
        padding: 0.4rem 0.55rem;
        width: 15rem;
        border-radius: 0.7rem;
    }
    .placard-picker-title {
        font-size: 0.8rem;
    }
    .placard-picker-sub {
        font-size: 0.58rem;
    }
    .placard-era-grid {
        gap: 0.25rem;
    }
    .era-btn {
        padding: 0.28rem 0.2rem;
        border-radius: 0.45rem;
    }
    .era-btn .era-name {
        font-size: 0.66rem;
    }
    .era-btn .era-age {
        font-size: 0.5rem;
    }
    .placard-cancel {
        font-size: 0.6rem;
        margin-top: 0.3rem;
    }
}

.hud-funds {
    color: #fbbf24;
    border-color: rgba(251, 191, 36, 0.55);
}

.integrity-button {
    cursor: pointer;
    background: rgba(24, 24, 27, 0.55);
    border: 2px solid transparent;
    border-radius: 0.6rem;
    padding: 0.15rem 0.4rem;
    font-family: 'Fredoka', sans-serif;
    color: inherit;
    transition: box-shadow 0.2s, border-color 0.2s, transform 0.15s;
}

.integrity-button:hover {
    border-color: rgba(74, 222, 128, 0.5);
    transform: scale(1.02);
}

.integrity-button:active {
    transform: scale(0.97);
}

.integrity-button.care-pulse {
    animation: care-glow 1.4s infinite alternate;
    border-color: rgba(74, 222, 128, 0.65);
}

.integrity-button.care-cooldown {
    opacity: 0.6;
    cursor: default;
    animation: none;
}

@keyframes care-glow {
    0% { box-shadow: 0 0 6px rgba(74, 222, 128, 0.25); }
    100% { box-shadow: 0 0 16px rgba(74, 222, 128, 0.6); }
}

.shop-btn.active {
    background: rgba(74, 222, 128, 0.22);
    border-color: #4ade80;
    box-shadow: 0 0 12px rgba(74, 222, 128, 0.45);
    animation: care-glow 1.2s infinite alternate;
}

.tool-hint {
    position: absolute;
    bottom: 86px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 19;
    font-family: 'Fredoka', sans-serif;
    font-size: 0.8rem;
    font-weight: 700;
    color: #fde68a;
    background: rgba(10, 14, 20, 0.82);
    border: 1.5px solid rgba(251, 191, 36, 0.5);
    border-radius: 9999px;
    padding: 0.3rem 0.9rem;
    white-space: nowrap;
    pointer-events: none;
    backdrop-filter: blur(4px);
}

.tool-hint.hidden {
    display: none !important;
}

.hud-end-button {
    cursor: pointer;
    color: #f87171;
    border-color: #ef4444;
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.45rem 0.75rem;
}

.hud-end-button:hover {
    background: rgba(239, 68, 68, 0.2);
    border-color: #f87171;
    color: #ffffff;
    transform: scale(1.05);
}

.integrity-container, .frenzy-container {
    flex-grow: 1;
    text-align: center;
    min-width: 80px;
}

.hud-label {
    font-family: 'Fredoka', sans-serif;
    font-size: 0.78rem;
    font-weight: 600;
    display: block;
    margin-bottom: 0.2rem;
    letter-spacing: 0.5px;
    color: #e4e4e7;
}

.integrity-bar, .frenzy-bar {
    width: 100%;
    height: 1.25rem;
    background-color: rgba(0, 0, 0, 0.6);
    border: 2px solid #52525b;
    border-radius: 0.5rem;
    padding: 2px;
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.5);
}

.integrity-fill {
    height: 100%;
    width: 100%;
    background-color: #22c55e;
    border-radius: 0.25rem;
    transition: width 0.3s ease-in-out, background-color 0.3s ease-in-out;
}

.frenzy-fill {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, #f59e0b 0%, #ec4899 50%, #8b5cf6 100%);
    border-radius: 0.25rem;
    transition: width 0.2s ease-out;
    box-shadow: 0 0 10px rgba(236, 72, 153, 0.5);
}

.shop-bar-container {
    position: absolute;
    bottom: 10px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 20;
    display: flex;
    align-items: center;
    gap: 0.25rem;
    max-width: 98%;
    pointer-events: auto;
}

.shop-scroll-btn {
    width: 1.85rem;
    height: 1.85rem;
    border-radius: 50%;
    background: rgba(15, 23, 42, 0.9);
    border: 1.5px solid rgba(56, 189, 248, 0.4);
    color: #38bdf8;
    font-size: 1.35rem;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
    transition: background 0.15s, transform 0.15s, border-color 0.15s, opacity 0.15s;
    user-select: none;
    outline: none;
    padding-bottom: 2px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
}

.shop-scroll-btn:hover {
    background: rgba(56, 189, 248, 0.25);
    border-color: #38bdf8;
    transform: scale(1.1);
}

.shop-scroll-btn:active {
    transform: scale(0.95);
}

.shop-scroll-btn.disabled {
    opacity: 0.3;
    pointer-events: none;
}

.shop-bar {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    background: rgba(15, 23, 42, 0.9);
    backdrop-filter: blur(10px);
    padding: 0.25rem 0.5rem;
    border-radius: 9999px;
    border: 1.5px solid rgba(56, 189, 248, 0.35);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5), 0 0 15px rgba(6, 182, 212, 0.15);
    overflow-x: auto;
    overflow-y: hidden;
    scroll-behavior: smooth;
    -ms-overflow-style: none;
    scrollbar-width: none;
    touch-action: pan-x !important;
    user-select: none;
    max-width: 100%;
}

.shop-bar::-webkit-scrollbar {
    display: none;
}

.shop-btn {
    display: flex;
    align-items: center;
    gap: 0.3rem;
    background: rgba(255, 255, 255, 0.05);
    border: 1.5px solid rgba(255, 255, 255, 0.15);
    border-radius: 9999px;
    padding: 0.2rem 0.45rem;
    cursor: pointer;
    font-family: 'Fredoka', sans-serif;
    transition: transform 0.15s, background 0.2s, border-color 0.2s, box-shadow 0.2s;
    user-select: none;
    white-space: nowrap;
    outline: none;
    flex-shrink: 0;
}

.shop-btn:hover:not(.disabled) {
    background: rgba(56, 189, 248, 0.2);
    border-color: #38bdf8;
    transform: translateY(-2px) scale(1.04);
    box-shadow: 0 4px 12px rgba(56, 189, 248, 0.3);
}

.shop-btn:active:not(.disabled) {
    transform: scale(0.96);
}

.shop-btn.disabled {
    opacity: 0.45;
    border-color: rgba(255, 255, 255, 0.08);
}

.shop-btn-icon-wrap {
    width: 1.45rem;
    height: 1.45rem;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.shop-btn-img {
    width: 1.15rem;
    height: 1.15rem;
    object-fit: contain;
}

.shop-btn-info {
    display: flex;
    flex-direction: column;
    text-align: left;
    line-height: 1.1;
}

.shop-btn-name {
    font-size: 0.68rem;
    font-weight: 700;
    color: #f1f5f9;
}

.shop-btn-cost {
    font-size: 0.6rem;
    font-weight: 600;
    color: #fbbf24;
}

.shop-feedback-toast {
    position: absolute;
    bottom: 54px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(239, 68, 68, 0.95);
    color: #ffffff;
    font-family: 'Fredoka', sans-serif;
    font-size: 0.85rem;
    font-weight: 700;
    padding: 0.35rem 0.95rem;
    border-radius: 9999px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
    z-index: 30;
    pointer-events: none;
    letter-spacing: 0.3px;
    animation: toast-fade 1.7s ease-out forwards;
}

@keyframes toast-fade {
    0% { opacity: 0; transform: translate(-50%, -6px); }
    15% { opacity: 1; transform: translate(-50%, 0); }
    80% { opacity: 1; transform: translate(-50%, 0); }
    100% { opacity: 0; transform: translate(-50%, -10px); }
}

.frenzy-announcement {
    position: absolute;
    top: 40%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-family: 'Fredoka', sans-serif;
    font-size: 2.75rem;
    font-weight: 700;
    color: #fde047;
    text-shadow: 0 0 15px #f59e0b, 0 0 30px #ec4899;
    pointer-events: none;
    z-index: 50;
    letter-spacing: 1px;
    animation: frenzy-pulse 0.7s infinite alternate;
}

@keyframes frenzy-pulse {
    0% { transform: translate(-50%, -50%) scale(0.95); }
    100% { transform: translate(-50%, -50%) scale(1.1); }
}

#waveWarning {
    position: absolute;
    top: 50%;
    left: 0;
    width: 100%;
    transform: translateY(-50%);
    text-align: center;
    font-size: 3.2rem;
    font-weight: 700;
    color: #ef4444;
    font-family: 'Fredoka', sans-serif;
    letter-spacing: 1px;
    text-shadow: 0 0 10px #f87171, 0 0 25px #ef4444;
    pointer-events: none;
    z-index: 100;
    animation: wave-pulse 1s infinite;
}

@keyframes wave-pulse {
    0%, 100% { transform: translateY(-50%) scale(1); opacity: 1; }
    50% { transform: translateY(-50%) scale(1.08); opacity: 0.85; }
}

#comboMeter {
    position: absolute;
    bottom: 64px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 2rem;
    font-weight: 700;
    color: #f59e0b;
    font-family: 'Fredoka', sans-serif;
    letter-spacing: 0.5px;
    text-shadow: 0 0 8px #fde047, 0 0 15px #f59e0b;
    pointer-events: none;
    z-index: 100;
    transition: opacity 0.3s, transform 0.2s;
}

.score-pop {
    position: absolute;
    font-size: 1.35rem;
    font-weight: 700;
    pointer-events: none;
    font-family: 'Fredoka', sans-serif;
    z-index: 101;
    animation: score-pop-animation 0.9s ease-out forwards;
}

.score-positive {
    color: #fde047;
    text-shadow: 0 0 6px #f59e0b;
}

.score-negative {
    color: #f87171;
    text-shadow: 0 0 6px #ef4444;
}

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

.modal {
    position: absolute;
    inset: 0;
    background-color: rgba(10, 10, 14, 0.94);
    backdrop-filter: blur(12px);
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 1rem;
    border-radius: 0.75rem;
    z-index: 40;
}

#factModal, #howToModal, #scienceInfoModal, #mainLeaderboardModal, #endRunConfirmModal, #victoryModal {
    position: fixed !important;
    inset: 0 !important;
    z-index: 100 !important;
    background: rgba(10, 10, 14, 0.92) !important;
    backdrop-filter: blur(12px) !important;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    box-sizing: border-box;
}

#startContent {
    display: flex;
    flex-direction: column;
    flex-grow: 1;
    min-height: 0;
    width: 100%;
}

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

.modal-title {
    font-family: 'Fredoka', sans-serif;
    font-size: 2.25rem;
    font-weight: 700;
    color: #facc15;
    margin: 0;
    letter-spacing: 0.5px;
}

.modal-subtitle {
    font-family: 'Fredoka', sans-serif;
    font-size: 1rem;
    font-weight: 600;
    color: #94a3b8;
    margin: 0.2rem 0 0 0;
}

.modal-body {
    flex-grow: 1;
    overflow-y: auto;
    width: 100%;
    min-height: 0;
}

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

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

.btn-primary {
    font-family: 'Fredoka', sans-serif;
    font-size: 1.1rem;
    font-weight: 700;
    background: linear-gradient(135deg, #22c55e 0%, #16a34a 100%);
    color: #ffffff;
    border: none;
    border-radius: 0.75rem;
    padding: 0.6rem 1.4rem;
    cursor: pointer;
    box-shadow: 0 4px 14px rgba(34, 197, 94, 0.4);
    transition: transform 0.2s, box-shadow 0.2s;
    flex: 1;
}

.btn-primary:hover {
    transform: scale(1.04);
    box-shadow: 0 6px 20px rgba(34, 197, 94, 0.6);
}

.btn-secondary {
    font-family: 'Fredoka', sans-serif;
    font-size: 1.1rem;
    font-weight: 700;
    background: rgba(39, 39, 42, 0.9);
    color: #e4e4e7;
    border: 2px solid #52525b;
    border-radius: 0.75rem;
    padding: 0.6rem 1.4rem;
    cursor: pointer;
    transition: transform 0.2s, border-color 0.2s, background 0.2s;
    flex: 1;
}

.btn-secondary:hover {
    border-color: #38bdf8;
    color: #ffffff;
    background: rgba(56, 189, 248, 0.15);
    transform: scale(1.04);
}

.player-name-input {
    width: 100%;
    max-width: 24rem;
    margin-bottom: 0.6rem;
    font-family: 'Fredoka', sans-serif;
    font-size: 1.05rem;
    font-weight: 600;
    text-align: center;
    background: rgba(24, 24, 27, 0.9);
    border: 2px solid #52525b;
    border-radius: 0.75rem;
    padding: 0.55rem 1rem;
    color: #ffffff;
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.player-name-input:focus {
    border-color: #facc15;
    box-shadow: 0 0 12px rgba(250, 204, 21, 0.35);
}

.intro-box {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.cards-hint {
    text-align: center;
    font-size: 0.85rem;
    font-weight: 600;
    color: #38bdf8;
    letter-spacing: 0.3px;
}

.cards-grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 0.45rem;
    width: 100%;
}

.character-card {
    background: rgba(255, 255, 255, 0.04);
    border-radius: 0.85rem;
    padding: 0.55rem 0.4rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    cursor: pointer;
    transition: transform 0.2s, border-color 0.2s, box-shadow 0.2s;
    border: 1.5px solid transparent;
}

.character-card:hover {
    transform: translateY(-4px) scale(1.03);
    animation: wiggle 0.4s ease-in-out;
}

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

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

.card-hero {
    border-color: rgba(34, 211, 238, 0.4);
}
.card-hero:hover {
    border-color: #22d3ee;
    box-shadow: 0 0 15px rgba(34, 211, 238, 0.25);
}

.card-ally {
    border-color: rgba(56, 189, 248, 0.35);
}
.card-ally:hover {
    border-color: #38bdf8;
    box-shadow: 0 0 15px rgba(56, 189, 248, 0.2);
}

.card-bonus {
    border-color: rgba(251, 191, 36, 0.35);
}
.card-bonus:hover {
    border-color: #fbbf24;
    box-shadow: 0 0 15px rgba(251, 191, 36, 0.2);
}

.card-threat {
    border-color: rgba(248, 113, 113, 0.35);
}
.card-threat:hover {
    border-color: #f87171;
    box-shadow: 0 0 15px rgba(248, 113, 113, 0.2);
}

.card-caution {
    border-color: rgba(74, 222, 128, 0.35);
}
.card-caution:hover {
    border-color: #4ade80;
    box-shadow: 0 0 15px rgba(74, 222, 128, 0.2);
}

.card-badge {
    font-size: 0.62rem;
    font-weight: 700;
    text-transform: uppercase;
    padding: 0.15rem 0.5rem;
    border-radius: 9999px;
    margin-bottom: 0.35rem;
    letter-spacing: 0.4px;
}

.badge-hero {
    background: rgba(34, 211, 238, 0.2);
    color: #22d3ee;
}
.badge-ally {
    background: rgba(56, 189, 248, 0.2);
    color: #38bdf8;
}
.badge-bonus {
    background: rgba(251, 191, 36, 0.2);
    color: #fbbf24;
}
.badge-threat {
    background: rgba(248, 113, 113, 0.2);
    color: #f87171;
}
.badge-caution {
    background: rgba(74, 222, 128, 0.2);
    color: #4ade80;
}

.icon-container {
    width: 2.75rem;
    height: 2.75rem;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 0.25rem;
}

.card-img {
    max-width: 100%;
    max-height: 100%;
    transition: transform 0.2s;
}

.character-card:hover .card-img {
    transform: scale(1.1);
}

.card-name {
    font-size: 0.78rem;
    font-weight: 700;
    margin-bottom: 0.15rem;
}

.card-ability {
    font-size: 0.66rem;
    color: #94a3b8;
    line-height: 1.2;
}

.game-over-title {
    font-size: 2.5rem;
    color: #ef4444;
}

.final-score-text {
    margin-top: 0.25rem;
    font-weight: 600;
}

.leaderboard-rank-text {
    font-size: 1rem;
    color: #facc15;
    font-weight: 700;
    margin-top: 0.2rem;
}

.game-over-fact-card {
    background: linear-gradient(180deg, rgba(56, 189, 248, 0.12) 0%, rgba(24, 24, 27, 0.95) 100%);
    border: 1.5px solid rgba(56, 189, 248, 0.45);
    border-radius: 1rem;
    padding: 0.85rem 1.15rem;
    max-width: 26rem;
    width: 100%;
    margin-top: 0.4rem;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4), 0 0 15px rgba(56, 189, 248, 0.2);
}

.game-over-fact-header {
    text-align: center;
    margin-bottom: 0.35rem;
}

.game-over-fact-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: 0.4rem;
}

.game-over-fact-portrait {
    width: 3.25rem;
    height: 3.25rem;
    border-radius: 50%;
    background: radial-gradient(circle, rgba(56, 189, 248, 0.2) 0%, rgba(0, 0, 0, 0.5) 100%);
    border: 2px solid rgba(56, 189, 248, 0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0.2rem;
}

.game-over-fact-title {
    font-size: 1.05rem;
    font-weight: 700;
    margin: 0;
}

.game-over-fact-text {
    font-size: 0.82rem;
    color: #cbd5e1;
    margin: 0.2rem 0 0 0;
    line-height: 1.35;
}

.fact-card, .how-to-card, .science-info-card, .confirm-card {
    background: rgba(24, 24, 27, 0.98);
    border: 2px solid #52525b;
    border-radius: 1rem;
    padding: 1.25rem;
    max-width: 32rem;
    width: 90%;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.6);
    animation: fact-pop 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes fact-pop {
    0% { transform: scale(0.85); opacity: 0; }
    100% { transform: scale(1); opacity: 1; }
}

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

.fact-close-btn {
    background: none;
    border: none;
    color: #94a3b8;
    font-size: 1.5rem;
    cursor: pointer;
    line-height: 1;
}

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

.fact-portrait {
    width: 5.5rem;
    height: 5.5rem;
    margin-bottom: 0.5rem;
    animation: wiggle 2s infinite ease-in-out;
}

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

.fact-text {
    font-size: 0.95rem;
    color: #e2e8f0;
    line-height: 1.45;
    margin-bottom: 1rem;
}

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

.tutorial-corner-btn, .science-corner-btn {
    position: absolute;
    top: 0.75rem;
    display: flex;
    align-items: center;
    gap: 0.35rem;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 9999px;
    padding: 0.35rem 0.75rem;
    font-family: 'Fredoka', sans-serif;
    font-size: 0.78rem;
    font-weight: 600;
    color: #f4f4f5;
    cursor: pointer;
    transition: background 0.2s, transform 0.2s;
    z-index: 10;
}

.tutorial-corner-btn { left: 0.75rem; }
.science-corner-btn { right: 0.75rem; }

.tutorial-corner-btn:hover, .science-corner-btn:hover {
    background: rgba(255, 255, 255, 0.18);
    transform: scale(1.05);
}

.how-to-card {
    max-width: 48rem;
    max-height: 88vh;
    overflow-y: auto;
}

.how-to-header-badge {
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    background: rgba(34, 211, 238, 0.2);
    color: #22d3ee;
    padding: 0.2rem 0.7rem;
    border-radius: 9999px;
    display: inline-block;
    margin-bottom: 0.25rem;
}

.tutorial-cards {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.65rem;
    margin: 0.75rem 0 1rem 0;
    width: 100%;
}

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

.tutorial-step {
    position: absolute;
    top: -0.45rem;
    left: -0.45rem;
    width: 1.4rem;
    height: 1.4rem;
    border-radius: 50%;
    background: #06b6d4;
    color: #ffffff;
    font-size: 0.75rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
}

.tutorial-step-img {
    width: 2.75rem;
    height: 2.75rem;
    margin-bottom: 0.35rem;
}

.tutorial-title {
    font-size: 0.82rem;
    font-weight: 700;
    margin-bottom: 0.2rem;
}

.tutorial-desc {
    font-size: 0.7rem;
    color: #cbd5e1;
    line-height: 1.25;
}

.science-info-card {
    max-width: 44rem;
    max-height: 85vh;
    overflow-y: auto;
    text-align: left;
}

.science-info-body {
    font-size: 0.88rem;
    color: #e2e8f0;
    line-height: 1.5;
}

.science-info-body p {
    margin-bottom: 0.65rem;
}

.science-info-body h3 {
    font-size: 1.05rem;
    font-weight: 700;
    color: #38bdf8;
    margin: 0.75rem 0 0.35rem 0;
}

.science-info-body ul {
    list-style-type: disc;
    padding-left: 1.25rem;
    margin-bottom: 0.65rem;
}

.science-info-body li {
    margin-bottom: 0.25rem;
}

.science-info-body a {
    color: #22d3ee;
    text-decoration: underline;
}

.confirm-stats {
    background: rgba(0, 0, 0, 0.4);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 0.75rem;
    padding: 0.75rem 1.25rem;
    width: 100%;
    margin: 0.75rem 0 1rem 0;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.confirm-stat-row {
    display: flex;
    justify-content: space-between;
    font-size: 1rem;
    font-weight: 600;
}

.confirm-stat-value {
    font-weight: 700;
}

.leaderboard-box {
    display: flex;
    flex-direction: column;
    gap: 0.45rem;
    overflow-y: auto;
    max-height: 380px;
    padding-right: 0.25rem;
}

.leaderboard-podium-card {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.45rem 0.75rem;
    border-radius: 0.65rem;
    background: rgba(255, 255, 255, 0.04);
    border: 1.5px solid transparent;
}

.podium-rank-1 {
    border-color: rgba(250, 204, 21, 0.5);
    background: linear-gradient(90deg, rgba(250, 204, 21, 0.12) 0%, rgba(255, 255, 255, 0.02) 100%);
}
.podium-rank-2 {
    border-color: rgba(226, 232, 240, 0.4);
    background: linear-gradient(90deg, rgba(226, 232, 240, 0.1) 0%, rgba(255, 255, 255, 0.02) 100%);
}
.podium-rank-3 {
    border-color: rgba(249, 115, 22, 0.4);
    background: linear-gradient(90deg, rgba(249, 115, 22, 0.1) 0%, rgba(255, 255, 255, 0.02) 100%);
}

.leaderboard-player {
    display: flex;
    align-items: center;
    gap: 0.55rem;
}

.podium-badge {
    width: 1.5rem;
    height: 1.5rem;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    font-weight: 700;
}

.podium-badge.rank-1 { background: #facc15; color: #000000; }
.podium-badge.rank-2 { background: #cbd5e1; color: #000000; }
.podium-badge.rank-3 { background: #f97316; color: #ffffff; }

.podium-player-info {
    display: flex;
    flex-direction: column;
}

.player-name {
    font-size: 0.88rem;
    font-weight: 700;
    color: #f4f4f5;
}

.player-name-empty {
    color: #71717a;
}

.podium-rank-tag {
    font-size: 0.58rem;
    font-weight: 700;
    color: #94a3b8;
    letter-spacing: 0.5px;
}

.player-score {
    font-size: 0.95rem;
    font-weight: 700;
    color: #facc15;
}

.player-score-empty {
    color: #71717a;
}

.score-glow-1 { color: #facc15; text-shadow: 0 0 8px rgba(250, 204, 21, 0.5); }
.score-glow-2 { color: #e2e8f0; text-shadow: 0 0 6px rgba(226, 232, 240, 0.4); }
.score-glow-3 { color: #fb923c; text-shadow: 0 0 6px rgba(249, 115, 22, 0.4); }

.leaderboard-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.35rem 0.65rem;
    border-radius: 0.5rem;
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid rgba(255, 255, 255, 0.06);
}

.rank-badge {
    width: 1.35rem;
    height: 1.35rem;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.08);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.72rem;
    font-weight: 600;
    color: #94a3b8;
}

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

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

.leaderboard-empty-title {
    font-size: 0.9rem;
    font-weight: 700;
    color: #facc15;
}

.leaderboard-subtext {
    font-size: 0.75rem;
    color: #71717a;
    margin-top: 0.2rem;
}

.hud-mute-button svg.hidden,
#soundOffIcon.hidden,
#soundOnIcon.hidden,
#factModal.hidden,
#howToModal.hidden,
#scienceInfoModal.hidden,
#mainLeaderboardModal.hidden,
#endRunConfirmModal.hidden,
#victoryModal.hidden,
.hidden {
    display: none !important;
}

#rotate-warning {
    display: none;
    position: fixed;
    inset: 0;
    background: #09090b;
    z-index: 99999;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    padding: 1.5rem;
    text-align: center;
}

.rotate-icon {
    width: 4rem;
    height: 4rem;
    animation: phone-rotate 2s ease-in-out infinite;
}

@keyframes phone-rotate {
    0%, 100% { transform: rotate(0deg); }
    50% { transform: rotate(-90deg); }
}

@media (min-width: 1024px) {
    .page-container {
        display: grid;
        grid-template-columns: minmax(0, 3.2fr) minmax(0, 1fr);
        gap: 1.25rem;
        align-items: stretch;
    }

    #leaderboardBtn, #leaderboardGameOverBtn {
        display: none !important;
    }

    .leaderboard-panel {
        display: flex;
        flex-direction: column;
        background: rgba(24, 24, 27, 0.85);
        border: 2px solid #3f3f46;
        border-radius: 1rem;
        padding: 0.95rem;
        min-height: 0;
        box-shadow: 0 10px 25px rgba(0, 0, 0, 0.4);
    }

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

    .leaderboard-tip {
        margin-top: auto;
        padding-top: 0.75rem;
        display: flex;
        align-items: center;
        gap: 0.6rem;
        font-size: 0.75rem;
        color: #94a3b8;
        border-top: 1px solid rgba(255, 255, 255, 0.08);
    }

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

@media (max-height: 640px), (max-width: 900px) {
    .page-container {
        padding: 0.2rem 0.4rem;
    }

    footer, .leaderboard-panel {
        display: none !important;
    }

    .hud {
        margin-bottom: 0.2rem;
        gap: 0.25rem;
    }

    .hud-element {
        font-size: 0.68rem;
        padding: 0.18rem 0.4rem;
        border-radius: 0.4rem;
        border-width: 1px;
    }

    .hud-label {
        font-size: 0.6rem;
        margin-bottom: 0.05rem;
    }

    .integrity-bar, .frenzy-bar {
        height: 0.65rem;
    }

    .shop-bar-container {
        bottom: 3px;
        max-width: 99%;
        gap: 0.12rem;
    }

    .tool-hint {
        bottom: 58px;
        font-size: 0.62rem;
        padding: 0.18rem 0.6rem;
    }

    .shop-scroll-btn {
        width: 1.4rem;
        height: 1.4rem;
        font-size: 1rem;
    }

    .shop-bar {
        padding: 0.12rem 0.3rem;
        gap: 0.2rem;
    }

    .shop-btn {
        padding: 0.1rem 0.3rem;
        gap: 0.18rem;
    }

    .shop-btn-icon-wrap {
        width: 1.2rem;
        height: 1.2rem;
    }

    .shop-btn-img {
        width: 0.9rem;
        height: 0.9rem;
    }

    .shop-btn-name {
        font-size: 0.58rem;
    }

    .shop-btn-cost {
        font-size: 0.5rem;
    }

    .modal {
        padding: 0.4rem 0.75rem;
    }

    .modal-header {
        padding-bottom: 0.15rem;
    }

    .modal-title {
        font-size: 1.25rem;
    }

    .modal-subtitle {
        font-size: 0.68rem;
        margin-top: 0.05rem;
    }

    .cards-hint {
        font-size: 0.62rem;
        margin-bottom: 0.15rem;
    }

    .cards-grid {
        grid-template-columns: repeat(5, 1fr) !important;
        gap: 0.2rem;
    }

    .character-card {
        padding: 0.2rem 0.15rem;
        border-radius: 0.4rem;
    }

    .icon-container {
        width: 1.85rem;
        height: 1.85rem;
        margin-bottom: 0.1rem;
    }

    .card-badge {
        font-size: 0.48rem;
        padding: 0.05rem 0.25rem;
        margin-bottom: 0.1rem;
    }

    .card-name {
        font-size: 0.62rem;
    }

    .card-ability {
        font-size: 0.52rem;
        line-height: 1.1;
    }

    .modal-footer {
        padding-top: 0.25rem;
    }

    .modal-footer-buttons {
        gap: 0.35rem;
        max-width: 18rem;
    }

    .btn-primary, .btn-secondary {
        font-size: 0.78rem;
        padding: 0.28rem 0.75rem;
        border-radius: 0.5rem;
        box-shadow: none;
    }

    .player-name-input {
        font-size: 0.75rem;
        padding: 0.22rem 0.5rem;
        margin-bottom: 0.25rem;
        max-width: 14rem;
        border-radius: 0.5rem;
    }

    .tutorial-corner-btn, .science-corner-btn {
        top: 0.35rem;
        padding: 0.2rem 0.45rem;
        font-size: 0.65rem;
        border-radius: 0.4rem;
        gap: 0.25rem;
    }

    .tutorial-corner-btn svg, .science-corner-btn svg {
        width: 0.75rem;
        height: 0.75rem;
    }

    .tutorial-cards {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 0.45rem;
    }

    .frenzy-announcement {
        font-size: 1.4rem;
    }

    .game-over-fact-card {
        padding: 0.35rem 0.65rem;
        max-width: 26rem;
    }

    .game-over-fact-content {
        flex-direction: row !important;
        align-items: center !important;
        text-align: left !important;
        gap: 0.45rem !important;
    }

    .game-over-fact-portrait {
        width: 2rem !important;
        height: 2rem !important;
        flex-shrink: 0 !important;
    }

    .game-over-fact-info {
        flex: 1 1 auto !important;
        text-align: left !important;
    }

    .game-over-fact-title {
        font-size: 0.78rem;
    }

    .game-over-fact-text {
        font-size: 0.62rem;
        line-height: 1.2;
    }
}

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