/* Apply default font only to game elements, not landing page */
#gameView,
#gameView * {
    font-family: sans-serif;
    font-size: 14px;
}

/* Keep font-family global but not font-size */
* {
    font-family: sans-serif;
}

html,
body {
    background-color: #222;
    overflow: hidden;
}

html,
body {
    width: 100%;
    height: 100%;
    margin: 0;
}

/* Mobile fullscreen optimizations */
@supports (-webkit-touch-callout: none) {
    /* iOS Safari specific fixes */
    html,
    body {
        height: -webkit-fill-available;
        min-height: -webkit-fill-available;
    }
}

/* Prevent pull-to-refresh and overscroll bounce on mobile */
html {
    overscroll-behavior: none;
    -webkit-overflow-scrolling: touch;
}

body {
    overscroll-behavior: none;
    width: 100%;
    height: 100%;
}

/* Only apply fixed positioning during gameplay */
body.in-game {
    position: fixed;
}

/* Handle safe areas for notched devices (iPhone X, etc.) */
/* Only apply safe areas when NOT in game mode - game should be fullscreen */
@supports (padding: max(0px)) {
    body:not(.in-game) {
        padding-left: max(0px, env(safe-area-inset-left));
        padding-right: max(0px, env(safe-area-inset-right));
        padding-top: max(0px, env(safe-area-inset-top));
        padding-bottom: max(0px, env(safe-area-inset-bottom));
    }
}

canvas {
    display: block;
    margin: 0;
    position: absolute;
    top: 0;
    left: 0;
    z-index: 1;
    padding: 0;
    background: rgba(0, 0, 0, 0.4);
}

div {
    -webkit-user-select: none; /* webkit (safari, chrome) browsers */
    -moz-user-select: none; /* mozilla browsers */
    -khtml-user-select: none; /* webkit (konqueror) browsers */
    -ms-user-select: none; /* IE10+ */
}

#split {
    position: absolute;
    bottom: 10px;
    left: 10px;
    width: 70px;
    height: 70px;
    padding: 5px;
    border: none;
    z-index: 1000;
    -webkit-tap-highlight-color: transparent;
    outline: none;
    user-select: none;
    -webkit-user-select: none;
    pointer-events: auto;
    touch-action: auto;
    background: #d3d3d3;
    border-radius: 50%;
    opacity: 0.5;
}

#split:focus,
#split:active {
    outline: none;
}

#feed {
    position: absolute;
    bottom: 90px; /* 10px bottom + 70px split + 10px gap */
    left: 10px;
    width: 70px;
    height: 70px;
    padding: 5px;
    border: none;
    z-index: 1000;
    -webkit-tap-highlight-color: transparent;
    outline: none;
    user-select: none;
    -webkit-user-select: none;
    pointer-events: auto;
    touch-action: auto;
    background: #d3d3d3;
    border-radius: 50%;
    opacity: 0.5;
}

#feed:focus,
#feed:active {
    outline: none;
}

#exit {
    position: absolute;
    bottom: 170px; /* 10px bottom + 70px split + 10px gap + 70px feed + 10px gap */
    left: 10px;
    width: 70px;
    height: 70px;
    padding: 5px;
    border: none;
    z-index: 1000;
    -webkit-tap-highlight-color: transparent;
    outline: none;
    user-select: none;
    -webkit-user-select: none;
    pointer-events: auto;
    touch-action: auto;
    background: #d3d3d3;
    border-radius: 50%;
    opacity: 0.5;
}

#exit:focus,
#exit:active {
    outline: none;
}

/* Fullscreen button - Hidden as devices provide native fullscreen controls */
.fullscreen-btn {
    display: none !important;
}

#fpsCounter {
    position: fixed;
    bottom: 20px;
    right: 20px;
    padding: 10px 16px;
    background: rgba(0, 0, 0, 0.75);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    color: #fff;
    font-size: 12px;
    font-weight: 600;
    font-family: 'SF Pro Display', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3),
                0 0 1px rgba(255, 255, 255, 0.1) inset;
    z-index: 1000;
    user-select: none;
    display: none;
    white-space: nowrap;
    letter-spacing: 0.3px;
    /* Removed transition for instant updates */
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
}

#fpsCounter:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.4),
                0 0 1px rgba(255, 255, 255, 0.15) inset;
}

#fpsCounter.low {
    background: linear-gradient(135deg, rgba(220, 38, 38, 0.85), rgba(185, 28, 28, 0.85));
    border-color: rgba(220, 38, 38, 0.3);
    animation: pulseRed 2s ease-in-out infinite;
}

#fpsCounter.medium {
    background: linear-gradient(135deg, rgba(245, 158, 11, 0.85), rgba(217, 119, 6, 0.85));
    border-color: rgba(245, 158, 11, 0.3);
}

#fpsCounter.high {
    background: linear-gradient(135deg, rgba(34, 197, 94, 0.85), rgba(22, 163, 74, 0.85));
    border-color: rgba(34, 197, 94, 0.3);
}

@keyframes pulseRed {
    0%, 100% {
        box-shadow: 0 4px 12px rgba(220, 38, 38, 0.4),
                    0 0 1px rgba(255, 255, 255, 0.1) inset;
    }
    50% {
        box-shadow: 0 4px 20px rgba(220, 38, 38, 0.6),
                    0 0 1px rgba(255, 255, 255, 0.1) inset;
    }
}

#status {
    position: absolute;
    padding: 12px 15px;
    background: linear-gradient(135deg, rgba(20, 20, 20, 0.95), rgba(30, 30, 30, 0.9));
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
    color: #fff;
    font-size: 14px;
    top: 10px;
    right: 10px;
    z-index: 100;
    width: 250px;
    max-width: 250px;
    overflow-x: hidden;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    cursor: pointer;
    user-select: none;
    box-sizing: border-box;
}

#status:hover {
    border-color: rgba(255, 255, 255, 0.2);
    /* Removed transform for instant response */
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.4);
}

#status.expanded {
    max-height: 400px;
    overflow-y: auto;
    overflow-x: hidden;
}

.leaderboard-header {
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    color: rgba(255, 255, 255, 0.7);
    margin-bottom: 10px;
    padding-bottom: 8px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.expand-icon {
    font-size: 10px;
    margin-left: 8px;
    opacity: 0.7;
}

.leaderboard-more {
    font-size: 11px;
    color: rgba(255, 255, 255, 0.5);
    text-align: center;
    padding: 6px 0 2px 0;
    font-style: italic;
}

.leaderboard-content {
    overflow-x: hidden;
    width: 100%;
}

.leaderboard-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
    overflow-x: hidden;
}

.leaderboard-entry {
    display: flex;
    align-items: center;
    padding: 4px 0;
    overflow: hidden;
}

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

.leaderboard-entry .rank {
    width: 28px;
    font-weight: 600;
    font-size: 14px;
    text-align: center;
}

.leaderboard-entry .name {
    flex: 1;
    font-size: 13px;
    margin-left: 8px;
    font-weight: 500;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    min-width: 0;
}

.leaderboard-entry .score {
    font-size: 13px;
    font-weight: 600;
    color: rgba(255, 255, 255, 0.8);
    margin-left: 8px;
    flex-shrink: 0;
}

.leaderboard-entry.top3 .score {
    color: #ffd700;
}

.leaderboard-entry.me {
    background: linear-gradient(90deg, rgba(255, 107, 107, 0.15), rgba(255, 136, 136, 0.1));
    border-radius: 6px;
    padding: 4px 6px;
    margin: 0 -6px;
}

.leaderboard-entry.me .name,
.leaderboard-entry.me .score {
    color: #ff8888;
    font-weight: 700;
}

/* Fun Player Score Display at Bottom Center */
#playerScore {
    position: fixed;
    bottom: 50px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 1000;
    text-align: center;
    pointer-events: none;
    user-select: none;
    width: auto;
    min-width: 300px;  /* Ensure enough width for score + $ */
    max-width: 90vw;
}

/* MASSIVE colorful money score with animated counting */
.score-value {
    font-size: 66px !important;  /* Large money display */
    font-weight: 900;
    background: linear-gradient(45deg, #00FF00, #00CC00, #FFD700, #00FF00, #32CD32, #00FF7F);
    background-size: 300% 300%;
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    text-shadow: 0 0 80px rgba(0, 255, 0, 0.8), 0 0 40px rgba(255, 215, 0, 0.6);
    font-family: 'Arial Black', 'Impact', 'Helvetica', sans-serif;
    animation: gradientShift 3s ease infinite;
    letter-spacing: -2px;  /* Less tight spacing to avoid cutoff */
    line-height: 1;
    display: inline-block;
    margin: 0;
    padding: 0 10px;  /* Add horizontal padding to prevent cutoff */
    white-space: nowrap;  /* Prevent wrapping */
}

/* Gradient animation for fun effect */
@keyframes gradientShift {
    0% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
    100% { background-position: 0% 50%; }
}

/* Score change and medal animations removed - no longer needed */

/* Counting animation */
@keyframes countUp {
    from { opacity: 0.8; }
    to { opacity: 1; }
}

.score-value.counting {
    animation: countUp 0.05s ease;
}

#startMenu {
    position: relative;
    margin: auto;
    margin-top: 100px;
    width: 350px;
    padding: 20px;
    border-radius: 5px;
    -moz-border-radius: 5px;
    -webkit-border-radius: 5px;
    background-color: white;
    box-sizing: border-box;
}

#startMenu p {
    padding: 0;
    text-align: center;
    font-size: x-large;
    font-weight: bold;
}

#playerNameInput {
    width: 100%;
    text-align: center;
    padding: 10px;
    border: solid 1px #dcdcdc;
    transition: box-shadow 0.3s, border 0.3s;
    box-sizing: border-box;
    border-radius: 5px;
    -moz-border-radius: 5px;
    -webkit-border-radius: 5px;
    margin-bottom: 10px;
    outline: none;
}

#playerNameInput:focus,
#playerNameInput.focus {
    border: solid 1px #cccccc;
    box-shadow: 0 0 3px 1px #dddddd;
}

#startButton,
#spectateButton {
    position: relative;
    margin: auto;
    margin-top: 10px;
    width: 100%;
    height: 40px;
    box-sizing: border-box;
    font-size: large;
    color: white;
    text-align: center;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.25);
    background: #2ecc71;
    border: 0;
    border-bottom: 2px solid #28be68;
    cursor: pointer;
    -webkit-box-shadow: inset 0 -2px #28be68;
    box-shadow: inset 0 -2px #28be68;
    border-radius: 5px;
    -moz-border-radius: 5px;
    -webkit-border-radius: 5px;
    margin-bottom: 10px;
}

#spectateButton:active,
#spectateButton:hover,
#startButton:active,
#startButton:hover {
    top: 1px;
    background: #55d88b;
    outline: none;
    -webkit-box-shadow: none;
    box-shadow: none;
}

#settingsButton {
    position: relative;
    margin: auto;
    margin-top: 10px;
    width: 100%;
    height: 40px;
    box-sizing: border-box;
    font-size: large;
    color: white;
    text-align: center;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.25);
    background: #2ecc71;
    border: 0;
    border-bottom: 2px solid #28be68;
    cursor: pointer;
    -webkit-box-shadow: inset 0 -2px #28be68;
    box-shadow: inset 0 -2px #28be68;
    border-radius: 5px;
    -moz-border-radius: 5px;
    -webkit-border-radius: 5px;
    margin-bottom: 10px;
}

#settingsButton:active,
#settingsButton:hover {
    top: 1px;
    background: #55d88b;
    outline: none;
    -webkit-box-shadow: none;
    box-shadow: none;
}

#settings,
#startMenuWrapper {
    -webkit-transition: max-height 1s;
    -moz-transition: max-height 1s;
    -ms-transition: max-height 1s;
    -o-transition: max-height 1s;
    transition: max-height 1s;
    overflow: hidden;
}

#settings {
    max-height: 0;
}

#startMenu h3 {
    padding-bottom: 0;
    margin-bottom: 0;
}

#startMenu ul {
    margin: 10px;
    padding: 10px;
    margin-top: 0;
}

#startMenu .input-error {
    color: red;
    opacity: 0;
    font-size: 12px;
}

#startMenuWrapper {
    z-index: 2;
}

#gameAreaWrapper {
    position: absolute !important;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    opacity: 0;
    pointer-events: auto;
}

/* Hide mobile controls on desktop - use class-based detection */
body:not(.mobile-device) #mobile {
    display: none;
}

/* Fallback for older browsers using screen width */
@media only screen and (min-width: 1024px) {
    #mobile {
        display: none;
    }
}

/* Mobile responsive styles for leaderboard and player score */
/* Use JavaScript-based mobile detection for reliability in all orientations */
/* Status element now shows compact rank display on mobile, so don't hide it */

.mobile-device #playerScore {
    top: 10px !important;
    left: 10px !important;
    bottom: auto !important;
    transform: none !important;
    max-width: 200px !important;
    background: none !important;
    backdrop-filter: none !important;
    padding: 0 !important;
    border-radius: 0 !important;
    border: none !important;
    box-shadow: none !important;
    text-align: left !important;
}

.mobile-device .score-value {
    font-size: 36px !important;
    font-weight: 900 !important;
    background: linear-gradient(45deg, #00FF00, #00CC00, #FFD700, #00FF00, #32CD32, #00FF7F) !important;
    background-size: 300% 300% !important;
    -webkit-background-clip: text !important;
    background-clip: text !important;
    -webkit-text-fill-color: transparent !important;
    animation: gradientShift 3s ease infinite !important;
    letter-spacing: -1px !important;
    padding: 0 !important;
    text-shadow: none !important;
}

input [type="image"]:focus {
    border: none;
    outline: 1px solid transparent;
    border-style: none;
}

*:focus {
    outline: 1px solid transparent;
    border-style: none;
}

/* Game Settings Button - Hidden for now */
#landingView .game-settings-btn {
    display: none;
}

/* Exit countdown is now drawn on canvas, no HTML element needed */

/* Collapsed state styles for all devices */
#status.collapsed .leaderboard-content {
    display: none;
}

#status.collapsed {
    padding: 8px 12px;
}

/* Make leaderboard clickable on all devices */
#status {
    cursor: pointer;
    user-select: none;
}

/* Desktop hover effect - only for non-mobile devices */
body:not(.mobile-device) #status:hover {
    background: linear-gradient(135deg, rgba(25, 25, 25, 0.98), rgba(35, 35, 35, 0.95));
}

/* Limit max height on desktop when expanded */
body:not(.mobile-device) #status.expanded .leaderboard-content {
    max-height: 400px;
    overflow-y: auto;
}

/* Custom scrollbar for desktop */
body:not(.mobile-device) #status.expanded .leaderboard-content::-webkit-scrollbar {
    width: 4px;
}

body:not(.mobile-device) #status.expanded .leaderboard-content::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.05);
    border-radius: 2px;
}

body:not(.mobile-device) #status.expanded .leaderboard-content::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
    border-radius: 2px;
}

body:not(.mobile-device) #status.expanded .leaderboard-content::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.3);
}

/* Orientation-specific adjustments for mobile gameplay */
@media (orientation: landscape) and (max-width: 896px) {
    /* Landscape mobile - optimize space */
    #status {
        top: 5px;
        right: 5px;
        padding: 6px 10px;
    }

    #playerScore {
        top: 5px !important;
        left: 5px !important;
    }

    .score-value {
        font-size: 28px !important;
    }

    /* Move control buttons for landscape */
    #split, #feed, #exit {
        transform: scale(0.85);
    }

    #split {
        bottom: 5px;
        left: 5px;
    }

    #feed {
        bottom: 80px;
        left: 5px;
    }

    #exit {
        bottom: 155px;
        left: 5px;
    }
}

@media (orientation: portrait) and (max-width: 768px) {
    /* Portrait mobile - current layout works well */
    .mobile-rank-display {
        font-size: 13px !important;
    }
}

/* Small landscape screens (phones in landscape) */
@media (orientation: landscape) and (max-height: 500px) {
    #status {
        max-height: 40vh;
    }

    .mobile-rank-display {
        padding: 5px 12px !important;
        font-size: 12px !important;
    }
}

/* Waiting room and countdown animations */
@keyframes pulse {
    0% {
        transform: translate(-50%, -50%) scale(1);
        opacity: 1;
    }
    50% {
        transform: translate(-50%, -50%) scale(1.1);
        opacity: 0.8;
    }
    100% {
        transform: translate(-50%, -50%) scale(1);
        opacity: 1;
    }
}
