* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
}

:root {
    --primary: #ff4757;
    --primary-glow: rgba(255, 71, 87, 0.4);
    --gold: #ffa502;
    --gold-glow: rgba(255, 165, 2, 0.5);
    --sky-top: #3742fa;
    --sky-bottom: #70a1ff;
    --card-bg: rgba(25, 25, 45, 0.88);
    --card-border: rgba(255, 255, 255, 0.15);
    --text-light: #f1f2f6;
}

body, html {
    width: 100%;
    height: 100%;
    height: 100dvh;
    overflow: hidden;
    background: #0f1423;
    font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    color: var(--text-light);
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Responsive edge-to-edge viewport on all displays (Smart TV 1080p/4K, Desktop, Tablet, Mobile) */
#game-wrapper {
    position: relative;
    width: 100vw;
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
    background: #000;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* TV & Keyboard Focus ring for smart TV remote navigation (compatible with older Chromium on Tizen) */
button:focus, .char-tab-btn:focus, .btn:focus, .icon-btn:focus {
    outline: 3px solid #38bdf8 !important;
    outline-offset: 3px !important;
    box-shadow: 0 0 24px rgba(56, 189, 248, 0.85) !important;
    transform: scale(1.06);
}

button:focus-visible, .char-tab-btn:focus-visible, .btn:focus-visible, .icon-btn:focus-visible {
    outline: 3px solid #38bdf8 !important;
    outline-offset: 3px !important;
    box-shadow: 0 0 24px rgba(56, 189, 248, 0.85) !important;
    transform: scale(1.06);
}

canvas#gameCanvas {
    width: 100%;
    height: 100%;
    display: block;
    touch-action: none;
}

/* HUD Overlay */
#hud {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    padding: 12px 14px;
    padding: max(12px, env(safe-area-inset-top, 12px)) max(14px, env(safe-area-inset-right, 14px)) 12px max(14px, env(safe-area-inset-left, 14px));
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    pointer-events: none;
    z-index: 10;
}

.hud-left {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.hud-pill {
    background: rgba(15, 20, 35, 0.8);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.15);
    padding: 6px 14px;
    border-radius: 999px;
    display: flex;
    align-items: center;
    gap: 10px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.25);
}

.lives-container {
    display: flex;
    gap: 4px;
}

.heart-icon {
    font-size: 20px;
    color: #ff4757;
    filter: drop-shadow(0 0 6px rgba(255, 71, 87, 0.8));
    transition: transform 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.heart-icon.lost {
    color: #57606f;
    filter: none;
    opacity: 0.35;
    transform: scale(0.8);
}

.score-box {
    font-size: 22px;
    font-weight: 800;
    color: #ffffff;
    display: flex;
    align-items: baseline;
    gap: 6px;
}

.score-box .label {
    font-size: 11px;
    text-transform: uppercase;
    font-weight: 700;
    color: #a4b0be;
    letter-spacing: 1px;
}

.score-val {
    color: #ffd32a;
    text-shadow: 0 0 10px rgba(255, 211, 42, 0.6);
}

.combo-badge {
    display: inline-block;
    padding: 3px 10px;
    font-size: 13px;
    font-weight: 800;
    border-radius: 12px;
    background: linear-gradient(135deg, #ff4757, #ff6b81);
    color: white;
    box-shadow: 0 0 12px rgba(255, 71, 87, 0.6);
    opacity: 0;
    transform: scale(0.8);
    transition: all 0.2s ease;
}

.combo-badge.active {
    opacity: 1;
    transform: scale(1);
}

/* Power Up Bar */
.power-container {
    position: absolute;
    bottom: 18px;
    bottom: max(18px, env(safe-area-inset-bottom, 18px));
    left: 50%;
    transform: translateX(-50%);
    width: 240px;
    max-width: 60vw;
    width: min(240px, 60vw);
    background: rgba(15, 20, 35, 0.85);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 20px;
    padding: 6px 12px;
    display: none;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    z-index: 10;
    box-shadow: 0 0 20px rgba(255, 107, 129, 0.4);
}

.power-container.active {
    display: flex;
}

.power-label {
    font-size: 11px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: #fffa65;
    text-shadow: 0 0 8px rgba(255, 250, 101, 0.8);
    white-space: nowrap;
}

.power-bar-bg {
    width: 100%;
    height: 8px;
    background: rgba(255, 255, 255, 0.15);
    border-radius: 999px;
    overflow: hidden;
}

.power-bar-fill {
    height: 100%;
    width: 100%;
    background: linear-gradient(90deg, #ff4757, #ffa502, #2ed573, #1e90ff, #9b59b6);
    border-radius: 999px;
    transition: width 0.1s linear;
}

.hud-right {
    display: flex;
    align-items: center;
    gap: 10px;
    pointer-events: auto;
}

.icon-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: rgba(15, 20, 35, 0.8);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.18);
    color: white;
    font-size: 17px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
    transition: all 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    touch-action: manipulation;
}

.icon-btn:hover {
    transform: scale(1.08);
    background: rgba(255, 255, 255, 0.2);
}

.icon-btn:active {
    transform: scale(0.92);
}

/* Modals & Overlays */
.overlay-screen {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    height: 100%;
    inset: 0;
    background: #0a0c16;
    background: rgba(10, 12, 22, 0.95);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 20;
    padding: 16px;
    padding: max(16px, env(safe-area-inset-top, 16px)) max(16px, env(safe-area-inset-right, 16px)) max(16px, env(safe-area-inset-bottom, 16px)) max(16px, env(safe-area-inset-left, 16px));
    text-align: center;
    overflow: hidden !important;
    transition: opacity 0.3s ease;
}

.hidden, #hud.hidden, .overlay-screen.hidden, .hero-preview-badge.hidden, .stage-banner.hidden {
    display: none !important;
    visibility: hidden !important;
    opacity: 0 !important;
    pointer-events: none !important;
}

.hero-preview-badge {
    position: relative;
    width: 58px;
    height: 58px;
    width: clamp(48px, 9vw, 68px);
    height: clamp(48px, 9vw, 68px);
    max-width: 68px;
    max-height: 68px;
    margin-bottom: 12px;
    flex-shrink: 0;
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.hero-preview-row.single-hero .hero-preview-badge {
    width: 96px;
    height: 96px;
    width: clamp(80px, 18vw, 115px);
    height: clamp(80px, 18vw, 115px);
    max-width: 115px;
    max-height: 115px;
}

.hero-avatar-img {
    width: 58px;
    height: 58px;
    width: 100%;
    height: 100%;
    max-width: 100%;
    max-height: 100%;
    border-radius: 50%;
    object-fit: cover;
    display: block;
    border: 3.5px solid #ffd32a;
    box-shadow: 0 0 30px rgba(255, 211, 42, 0.6), inset 0 0 20px rgba(0, 0, 0, 0.5);
    animation: floatHero 3s ease-in-out infinite;
}

.hero-cape-glow {
    position: absolute;
    top: -8px;
    left: -8px;
    right: -8px;
    bottom: -8px;
    border-radius: 50%;
    border: 2px dashed rgba(255, 71, 87, 0.7);
    animation: rotateCape 12s linear infinite;
}

@keyframes floatHero {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-6px); }
}

@keyframes rotateCape {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

.game-title {
    font-size: 34px;
    font-size: clamp(26px, 7vw, 42px);
    font-weight: 900;
    letter-spacing: -0.5px;
    margin-bottom: 6px;
    background: linear-gradient(135deg, #ffd32a 0%, #ff6b81 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    text-shadow: 0 4px 20px rgba(255, 107, 129, 0.3);
}

.subtitle {
    font-size: 14px;
    font-size: clamp(13px, 3.5vw, 16px);
    color: #a4b0be;
    margin-bottom: 10px;
    max-width: 440px;
    line-height: 1.4;
}

.instructions-grid {
    display: flex;
    gap: 8px;
    margin-bottom: 14px;
    flex-wrap: wrap;
    justify-content: center;
    max-width: 480px;
}

.instruction-tag {
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.12);
    padding: 6px 12px;
    border-radius: 12px;
    font-size: 12px;
    font-size: clamp(11px, 2.8vw, 13px);
    display: flex;
    align-items: center;
    gap: 6px;
}

.instruction-tag kbd {
    background: rgba(255, 255, 255, 0.2);
    padding: 2px 6px;
    border-radius: 6px;
    font-weight: 700;
    font-size: 11px;
}

.action-btn {
    background: linear-gradient(135deg, #ff4757, #ff6b81);
    color: white;
    border: none;
    min-height: 54px;
    padding: 16px 42px;
    padding: clamp(14px, 3.5vw, 20px) clamp(32px, 8vw, 56px);
    font-size: 20px;
    font-size: clamp(18px, 4vw, 24px);
    font-weight: 800;
    border-radius: 999px;
    cursor: pointer;
    box-shadow: 0 8px 25px rgba(255, 71, 87, 0.45);
    transition: all 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    letter-spacing: 0.5px;
    touch-action: manipulation;
    pointer-events: auto !important;
    position: relative;
    z-index: 30;
}

.action-btn:hover {
    transform: translateY(-2px) scale(1.02);
    box-shadow: 0 12px 28px rgba(255, 71, 87, 0.6);
}

.action-btn:active {
    transform: translateY(1px) scale(0.96);
}

/* Game Over Stats */
.game-over-stats {
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 16px;
    padding: 12px 24px;
    margin-bottom: 20px;
    display: flex;
    gap: 28px;
    gap: clamp(20px, 6vw, 36px);
}

.stat-item {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.stat-item .stat-label {
    font-size: 12px;
    text-transform: uppercase;
    color: #a4b0be;
    font-weight: 700;
}

.stat-item .stat-value {
    font-size: 28px;
    font-size: clamp(24px, 6vw, 32px);
    font-weight: 900;
    color: #ffd32a;
}

.new-best-flag {
    color: #2ed573;
    font-size: 12px;
    font-weight: 800;
    margin-top: 4px;
    animation: pulseBest 1.5s ease-in-out infinite;
}

@keyframes pulseBest {
    0%, 100% { opacity: 0.8; transform: scale(1); }
    50% { opacity: 1; transform: scale(1.08); }
}

/* Mobile Controls Overlay */
#touch-controls {
    position: absolute;
    bottom: 16px;
    left: 16px;
    right: 16px;
    bottom: max(16px, env(safe-area-inset-bottom, 16px));
    left: max(16px, env(safe-area-inset-left, 16px));
    right: max(16px, env(safe-area-inset-right, 16px));
    display: none;
    justify-content: space-between;
    align-items: flex-end;
    pointer-events: none;
    z-index: 15;
}

@media (pointer: coarse), (max-width: 900px) {
    #touch-controls {
        display: flex;
    }
}

.touch-btn {
    pointer-events: auto;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.22);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 2px solid rgba(255, 255, 255, 0.35);
    color: white;
    font-size: 22px;
    display: flex;
    align-items: center;
    justify-content: center;
    touch-action: none;
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.35);
}

.touch-btn:active {
    background: rgba(255, 71, 87, 0.65);
    transform: scale(0.92);
}

.boost-btn {
    width: 78px;
    height: 78px;
    font-size: 15px;
    font-weight: 900;
    letter-spacing: 0.5px;
    text-transform: uppercase;
    background: linear-gradient(135deg, rgba(255, 71, 87, 0.85), rgba(255, 107, 129, 0.95));
    border-color: rgba(255, 211, 42, 0.7);
    box-shadow: 0 8px 24px rgba(255, 71, 87, 0.5);
}

/* Stage Pill in HUD */
.stage-pill {
    background: rgba(30, 41, 59, 0.85);
    border: 1px solid rgba(148, 163, 184, 0.3);
    padding: 3px 10px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 800;
    letter-spacing: 0.5px;
    color: #67e8f9;
    text-shadow: 0 0 8px rgba(103, 232, 249, 0.5);
}

/* Stage Level-up Animated Banner */
.stage-banner {
    position: absolute;
    top: 25%;
    left: 50%;
    transform: translate(-50%, -50%) scale(1);
    background: rgba(15, 23, 42, 0.92);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    border: 2px solid #ffd32a;
    box-shadow: 0 0 35px rgba(255, 211, 42, 0.6);
    border-radius: 20px;
    padding: 16px 36px;
    text-align: center;
    z-index: 18;
    pointer-events: none;
    animation: bannerPop 2.8s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}

.stage-banner.hidden {
    display: none;
}

.banner-title {
    font-size: 26px;
    font-size: clamp(22px, 5vw, 32px);
    font-weight: 900;
    background: linear-gradient(135deg, #ffd32a, #ff6b81);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    letter-spacing: 0.5px;
}

.banner-sub {
    font-size: 14px;
    font-size: clamp(13px, 3.2vw, 16px);
    color: #f1f5f9;
    margin-top: 4px;
    font-weight: 700;
}

@keyframes bannerPop {
    0% { opacity: 0; transform: translate(-50%, -50%) scale(0.6); }
    15% { opacity: 1; transform: translate(-50%, -50%) scale(1.05); }
    25% { transform: translate(-50%, -50%) scale(1); }
    80% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
    100% { opacity: 0; transform: translate(-50%, -60%) scale(0.9); }
}

/* Character Selector Tabs */
.character-select {
    display: flex;
    gap: 6px;
    background: rgba(15, 23, 42, 0.75);
    border: 1px solid rgba(255, 255, 255, 0.16);
    border-radius: 16px;
    padding: 6px;
    margin-bottom: 12px;
    max-width: 560px;
    max-width: min(96vw, 560px);
    flex-wrap: wrap;
    justify-content: center;
}

.char-tab-btn {
    background: transparent;
    border: 1px solid transparent;
    color: #94a3b8;
    padding: 6px 11px;
    border-radius: 12px;
    font-size: 12px;
    font-size: clamp(10.5px, 2.5vw, 12.5px);
    font-weight: 800;
    cursor: pointer;
    transition: all 0.2s ease;
    touch-action: manipulation;
    white-space: nowrap;
}

.char-tab-btn:hover {
    color: #ffffff;
    background: rgba(255, 255, 255, 0.08);
}

.char-tab-btn.active {
    background: linear-gradient(135deg, #3b82f6, #06b6d4);
    border-color: rgba(255, 255, 255, 0.25);
    color: #ffffff;
    box-shadow: 0 4px 14px rgba(59, 130, 246, 0.45);
}

/* Hero Preview Row */
.hero-preview-row {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    gap: clamp(6px, 1.6vw, 14px);
    margin-bottom: 10px;
    max-width: 98%;
    flex-wrap: wrap;
}

.hero-preview-badge.hidden {
    display: none;
}

.police-glow {
    border-color: #38bdf8 !important;
    animation: rotatePolice 3s linear infinite !important;
}

@keyframes rotatePolice {
    0% { border-color: #ef4444; box-shadow: 0 0 15px rgba(239, 68, 68, 0.7); }
    50% { border-color: #3b82f6; box-shadow: 0 0 15px rgba(59, 130, 246, 0.7); }
    100% { border-color: #ef4444; box-shadow: 0 0 15px rgba(239, 68, 68, 0.7); }
}

.hero-name-tag {
    position: absolute;
    bottom: -6px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(15, 23, 42, 0.9);
    border: 1px solid rgba(255, 255, 255, 0.25);
    padding: 2px 8px;
    border-radius: 8px;
    font-size: 10px;
    font-weight: 800;
    color: #ffd32a;
    letter-spacing: 0.5px;
    white-space: nowrap;
}

.david-glow {
    border-color: #10b981 !important;
    animation: rotateDavid 4s linear infinite !important;
}

@keyframes rotateDavid {
    0% { border-color: #10b981; box-shadow: 0 0 16px rgba(16, 185, 129, 0.7); }
    50% { border-color: #fbbf24; box-shadow: 0 0 16px rgba(251, 191, 36, 0.7); }
    100% { border-color: #10b981; box-shadow: 0 0 16px rgba(16, 185, 129, 0.7); }
}

.ari-glow {
    border-color: #c084fc !important;
    animation: rotateAri 4s linear infinite !important;
}

@keyframes rotateAri {
    0% { border-color: #c084fc; box-shadow: 0 0 16px rgba(192, 132, 252, 0.7); }
    50% { border-color: #f472b6; box-shadow: 0 0 16px rgba(244, 114, 182, 0.7); }
    100% { border-color: #c084fc; box-shadow: 0 0 16px rgba(192, 132, 252, 0.7); }
}

.frank-glow {
    border-color: #f59e0b !important;
    animation: rotateFrank 4s linear infinite !important;
}

@keyframes rotateFrank {
    0% { border-color: #f59e0b; box-shadow: 0 0 16px rgba(245, 158, 11, 0.7); }
    50% { border-color: #ef4444; box-shadow: 0 0 16px rgba(239, 68, 68, 0.7); }
    100% { border-color: #f59e0b; box-shadow: 0 0 16px rgba(245, 158, 11, 0.7); }
}

.julia-glow {
    border-color: #f43f5e !important;
    animation: rotateJulia 4s linear infinite !important;
}

@keyframes rotateJulia {
    0% { border-color: #f43f5e; box-shadow: 0 0 16px rgba(244, 63, 94, 0.75); }
    50% { border-color: #fda4af; box-shadow: 0 0 16px rgba(253, 164, 175, 0.75); }
    100% { border-color: #f43f5e; box-shadow: 0 0 16px rgba(244, 63, 94, 0.75); }
}

/* Victory & Win Tracker Styles */
.win-tracker {
    background: rgba(245, 158, 11, 0.25);
    border: 1px solid rgba(251, 191, 36, 0.6);
    color: #fef08a;
    padding: 4px 10px;
    border-radius: 999px;
    font-size: 11px;
    font-size: clamp(10px, 2.4vw, 12px);
    font-weight: 800;
    letter-spacing: 0.3px;
    box-shadow: 0 0 10px rgba(245, 158, 11, 0.3);
    white-space: nowrap;
}

.victory-title {
    font-size: 34px;
    font-size: clamp(26px, 6.5vw, 42px);
    font-weight: 900;
    letter-spacing: -0.5px;
    margin-bottom: 6px;
    background: linear-gradient(135deg, #ffd32a 0%, #38bdf8 50%, #f43f5e 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    text-shadow: 0 0 25px rgba(255, 211, 42, 0.5);
}

.victory-badge {
    animation: victoryDance 1.6s ease-in-out infinite alternate !important;
}

@keyframes victoryDance {
    0% { transform: translateY(0) rotate(-4deg); }
    100% { transform: translateY(-10px) rotate(4deg); }
}


