* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Arial', sans-serif;
    overflow: hidden;
    background: #2C3E50;
    color: #ECF0F1;
}

#game-canvas {
    display: block;
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    cursor: crosshair;
}

/* Screens */
.screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    background: rgba(44, 62, 80, 0.95);
    z-index: 1000;
    opacity: 0;
    transition: opacity 0.5s ease-in-out;
}

.screen.visible {
    opacity: 1;
}

/* Loading Screen */
#loading-screen h1 {
    font-size: 48px;
    animation: pulse 1.5s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

/* Menu Screen */
#menu-screen {
    /* Snake skin background - full width on desktop (rotated 90 deg) */
    background:
        /* Vignette - darker edges */
        radial-gradient(ellipse at center, transparent 0%, rgba(5, 10, 15, 0.4) 50%, rgba(5, 10, 15, 0.9) 100%),
        /* Dark overlay for subtler background */
        linear-gradient(180deg, rgba(5, 10, 15, 0.8) 0%, rgba(10, 20, 30, 0.7) 50%, rgba(5, 10, 15, 0.8) 100%),
        /* Snake skin pattern */
        url('assets/snake-skin-bg-desktop.jpg');
    background-size: 100% 100%, 100% 100%, cover;
    background-position: center center;
    background-repeat: no-repeat;
}

/* Mobile: use original orientation */
@media (max-width: 768px) {
    #menu-screen {
        background:
            radial-gradient(ellipse at center, transparent 0%, rgba(5, 10, 15, 0.4) 50%, rgba(5, 10, 15, 0.9) 100%),
            linear-gradient(180deg, rgba(5, 10, 15, 0.8) 0%, rgba(10, 20, 30, 0.7) 50%, rgba(5, 10, 15, 0.8) 100%),
            url('assets/snake-skin-bg-mobile.jpg');
        background-size: 100% 100%, 100% 100%, cover;
        background-position: center center;
        background-repeat: no-repeat;
    }
}

/* Menu Screen Layout */
#menu-screen {
    flex-direction: column;
    padding: 20px;
}

.menu-layout {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 100%;
    max-width: 400px;
}

.menu-content {
    text-align: center;
    max-width: 350px;
    width: 100%;
}

/* Title Container */
.title-container {
    display: inline-block;
    margin-bottom: 40px;
    margin-top: -80px;
}

/* Animated Snake Title - Full Width */
.snake-title {
    font-size: clamp(28px, 5vw, 52px);
    font-weight: 900;
    margin-bottom: 5px;
    line-height: 1.4;
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    align-items: baseline;
    gap: 0;
    padding: 0 20px;
}

.title-letter {
    display: inline-block;
    background: linear-gradient(90deg, #2ECC71, #3498DB, #1ABC9C, #2ECC71);
    background-size: 300% 100%;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    animation: snake-wave 3.5s ease-in-out infinite, gradient-shift 8s linear infinite;
    filter: drop-shadow(2px 2px 0 rgba(0, 0, 0, 0.8)) drop-shadow(-1px -1px 0 rgba(0, 0, 0, 0.5));
}

.title-letter.snake-letter {
    font-size: clamp(36px, 7vw, 72px);
    background: linear-gradient(90deg, #27AE60, #2ECC71, #58D68D, #1ABC9C, #27AE60);
    background-size: 300% 100%;
    -webkit-background-clip: text;
    background-clip: text;
    filter: drop-shadow(3px 3px 0 rgba(0, 50, 0, 0.9)) drop-shadow(-1px -1px 0 rgba(0, 30, 0, 0.6));
}

.title-letter.domain-letter {
    background: linear-gradient(90deg, #7F8C8D, #95A5A6, #BDC3C7, #95A5A6, #7F8C8D);
    background-size: 300% 100%;
    -webkit-background-clip: text;
    background-clip: text;
    font-size: clamp(18px, 3vw, 36px);
    filter: drop-shadow(1px 1px 0 rgba(0, 0, 0, 0.6));
}

@keyframes snake-wave {
    0%, 100% {
        transform: translateY(0);
    }
    25% {
        transform: translateY(-35px);
    }
    75% {
        transform: translateY(35px);
    }
}

@keyframes gradient-shift {
    0% {
        background-position: 0% 50%;
    }
    100% {
        background-position: 300% 50%;
    }
}

/* Short URL below title */
.short-url {
    text-align: right;
    padding-right: 20px;
}

.short-url-letter {
    display: inline-block;
    font-size: clamp(14px, 2vw, 20px);
    font-weight: 600;
    color: #6a9a7a;
    animation: snake-wave-subtle 3.5s ease-in-out infinite;
    filter: drop-shadow(1px 1px 0 rgba(0, 0, 0, 0.6));
}

@keyframes snake-wave-subtle {
    0%, 100% {
        transform: translateY(0);
    }
    25% {
        transform: translateY(-12px);
    }
    75% {
        transform: translateY(12px);
    }
}

@keyframes snake-wave-mobile {
    0%, 100% {
        transform: translateY(0);
    }
    25% {
        transform: translateY(-8px);
    }
    75% {
        transform: translateY(8px);
    }
}

@keyframes snake-wave-mobile-subtle {
    0%, 100% {
        transform: translateY(0);
    }
    25% {
        transform: translateY(-4px);
    }
    75% {
        transform: translateY(4px);
    }
}

.menu-form {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

#nickname-input {
    padding: 15px;
    font-size: 18px;
    border: 2px solid #3498DB;
    border-radius: 10px;
    background: rgba(44, 62, 80, 0.8);
    color: #ECF0F1;
    text-align: center;
    outline: none;
    transition: all 0.3s;
}

#nickname-input:focus {
    border-color: #5DADE2;
    box-shadow: 0 0 15px rgba(52, 152, 219, 0.5);
}

.skin-selector {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 15px;
}

.skin-preview {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: linear-gradient(135deg, #3498DB, #2980B9);
    border: 3px solid #ECF0F1;
    box-shadow: 0 0 20px rgba(52, 152, 219, 0.6);
}

.btn {
    padding: 15px 30px;
    font-size: 18px;
    font-weight: bold;
    border: none;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.3s;
    background: #34495E;
    color: #ECF0F1;
}

.btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
}

.btn-primary {
    background: linear-gradient(135deg, #3498DB, #2980B9);
    font-size: 24px;
    padding: 20px 40px;
}

.btn-primary:hover {
    background: linear-gradient(135deg, #5DADE2, #3498DB);
}

/* Death Screen */
.death-container {
    text-align: center;
    max-width: 400px;
    padding: 40px;
    background: rgba(52, 73, 94, 0.95);
    border-radius: 20px;
    box-shadow: 0 10px 50px rgba(0, 0, 0, 0.5);
}

.death-title {
    font-size: 48px;
    color: #E74C3C;
    margin-bottom: 20px;
}

.death-stats {
    margin: 30px 0;
    font-size: 20px;
}

.death-stats p {
    margin: 10px 0;
}

.death-stats span {
    color: #3498DB;
    font-weight: bold;
    font-size: 24px;
}

.death-buttons {
    display: flex;
    flex-direction: column;
    gap: 15px;
    margin-top: 20px;
}

/* Game HUD */
#game-hud {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 100;
}

.hud-score {
    position: absolute;
    top: 20px;
    left: 20px;
    background: rgba(44, 62, 80, 0.8);
    padding: 15px 25px;
    border-radius: 10px;
    text-align: center;
}

.score-label {
    font-size: 14px;
    opacity: 0.7;
    text-transform: uppercase;
}

.score-value {
    font-size: 32px;
    font-weight: bold;
    color: #3498DB;
}

.hud-leaderboard {
    position: absolute;
    top: 20px;
    right: 20px;
    background: rgba(44, 62, 80, 0.8);
    padding: 15px;
    border-radius: 10px;
    min-width: 200px;
}

.leaderboard-title {
    font-size: 16px;
    font-weight: bold;
    text-align: center;
    margin-bottom: 10px;
    color: #3498DB;
    text-transform: uppercase;
}

.leaderboard-list {
    font-size: 14px;
}

.leaderboard-item {
    padding: 5px 10px;
    margin: 3px 0;
    border-radius: 5px;
    display: flex;
    justify-content: space-between;
}

.leaderboard-item.player {
    background: rgba(52, 152, 219, 0.3);
    font-weight: bold;
}

.leaderboard-rank {
    color: #F39C12;
    font-weight: bold;
    margin-right: 10px;
}

.hud-minimap {
    position: absolute;
    bottom: 20px;
    right: 20px;
    background: rgba(44, 62, 80, 0.8);
    padding: 10px;
    border-radius: 10px;
}

#minimap-canvas {
    display: block;
    border: 2px solid #34495E;
    border-radius: 5px;
}

.hud-fps {
    position: absolute;
    bottom: 20px;
    left: 20px;
    background: rgba(44, 62, 80, 0.8);
    padding: 10px 15px;
    border-radius: 10px;
    font-size: 14px;
    font-family: 'Courier New', monospace;
}

/* Network Status Display */
.hud-network {
    position: absolute;
    bottom: 20px;
    left: 150px;
    background: rgba(44, 62, 80, 0.8);
    padding: 8px 15px;
    border-radius: 10px;
    font-size: 12px;
    font-family: 'Courier New', monospace;
    display: flex;
    gap: 15px;
    align-items: center;
}

.room-display {
    color: #3498DB;
    font-weight: bold;
}

.connection-status {
    color: #2ECC71;
}

.latency-display {
    color: #F39C12;
}

/* Menu Header Row - High Score and Settings */
.menu-header-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    width: 100%;
}

/* High Score Display */
.high-score-display {
    padding: 10px 0;
    text-align: left;
}

.high-score-label {
    font-size: 12px;
    opacity: 0.7;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.high-score-value {
    font-size: 36px;
    font-weight: bold;
    color: #F39C12;
    text-shadow: 0 0 10px rgba(243, 156, 18, 0.5);
    margin-top: 5px;
}

/* Home Screen Leaderboard - Fixed right, vertically centered with menu */
.leaderboard-section {
    position: fixed;
    top: 50%;
    right: 30px;
    transform: translateY(-50%);
    background: rgba(20, 35, 50, 0.85);
    padding: 20px;
    border-radius: 15px;
    min-width: 260px;
    max-width: 300px;
    max-height: calc(100vh - 60px);
    display: flex;
    flex-direction: column;
    border: 1px solid rgba(52, 152, 219, 0.3);
    z-index: 100;
}

.leaderboard-section-title {
    font-size: 18px;
    color: #3498DB;
    margin-bottom: 15px;
    text-align: center;
    text-transform: uppercase;
    letter-spacing: 2px;
    flex-shrink: 0;
}

.home-leaderboard {
    display: flex;
    flex-direction: column;
    gap: 8px;
    overflow-y: auto;
    flex: 1;
    min-height: 0;
    scrollbar-width: thin;
    scrollbar-color: rgba(52, 152, 219, 0.5) transparent;
}

.home-leaderboard::-webkit-scrollbar {
    width: 6px;
}

.home-leaderboard::-webkit-scrollbar-track {
    background: transparent;
}

.home-leaderboard::-webkit-scrollbar-thumb {
    background: rgba(52, 152, 219, 0.5);
    border-radius: 3px;
}

.home-leaderboard::-webkit-scrollbar-thumb:hover {
    background: rgba(52, 152, 219, 0.7);
}

.leaderboard-loading {
    text-align: center;
    color: #7f8c8d;
    padding: 20px;
}

.leaderboard-entry {
    display: flex;
    align-items: center;
    padding: 10px 15px;
    background: rgba(0, 0, 0, 0.3);
    border-radius: 8px;
    transition: background 0.2s;
}

.leaderboard-entry:hover {
    background: rgba(0, 0, 0, 0.5);
}

.leaderboard-entry.top-1 {
    background: linear-gradient(135deg, rgba(255, 215, 0, 0.3), rgba(255, 215, 0, 0.1));
    border: 1px solid rgba(255, 215, 0, 0.5);
}

.leaderboard-entry.top-2 {
    background: linear-gradient(135deg, rgba(192, 192, 192, 0.3), rgba(192, 192, 192, 0.1));
    border: 1px solid rgba(192, 192, 192, 0.4);
}

.leaderboard-entry.top-3 {
    background: linear-gradient(135deg, rgba(205, 127, 50, 0.3), rgba(205, 127, 50, 0.1));
    border: 1px solid rgba(205, 127, 50, 0.4);
}

.leaderboard-rank {
    font-weight: bold;
    width: 30px;
    color: #F39C12;
}

.leaderboard-name {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.leaderboard-score {
    font-weight: bold;
    color: #2ECC71;
    margin-left: 10px;
}

/* Settings Icon */
.settings-icon {
    background: rgba(44, 62, 80, 0.8);
    border: 2px solid #3498DB;
    border-radius: 50%;
    width: 50px;
    height: 50px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.3s;
    color: #3498DB;
    flex-shrink: 0;
}

.settings-icon:hover {
    background: rgba(52, 152, 219, 0.3);
    transform: rotate(45deg);
}

/* Modals */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
}

.modal-content {
    background: rgba(52, 73, 94, 0.98);
    border-radius: 20px;
    max-width: 600px;
    width: 90%;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 25px 30px;
    border-bottom: 2px solid rgba(52, 152, 219, 0.3);
}

.modal-header h2 {
    color: #3498DB;
    font-size: 28px;
    margin: 0;
}

.modal-close {
    background: none;
    border: none;
    font-size: 36px;
    color: #ECF0F1;
    cursor: pointer;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: all 0.3s;
}

.modal-close:hover {
    background: rgba(231, 76, 60, 0.3);
    color: #E74C3C;
}

.modal-body {
    padding: 30px;
}

/* Settings Section */
.settings-section {
    margin-bottom: 30px;
}

.settings-section h3 {
    color: #5DADE2;
    font-size: 20px;
    margin-bottom: 15px;
    border-bottom: 1px solid rgba(52, 152, 219, 0.2);
    padding-bottom: 10px;
}

.setting-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px;
    background: rgba(44, 62, 80, 0.5);
    border-radius: 10px;
    margin-bottom: 10px;
}

.setting-item label {
    font-size: 16px;
    font-weight: bold;
}

/* Toggle Switch */
.toggle-switch {
    width: 50px;
    height: 26px;
    appearance: none;
    background: #34495E;
    border-radius: 13px;
    position: relative;
    cursor: pointer;
    transition: background 0.3s;
}

.toggle-switch:checked {
    background: #27AE60;
}

.toggle-switch::before {
    content: '';
    position: absolute;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: white;
    top: 3px;
    left: 3px;
    transition: transform 0.3s;
}

.toggle-switch:checked::before {
    transform: translateX(24px);
}

/* Key Bind Button */
.key-bind {
    padding: 10px 20px;
    background: rgba(52, 152, 219, 0.2);
    border: 2px solid #3498DB;
    border-radius: 8px;
    color: #3498DB;
    font-size: 14px;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.3s;
    min-width: 150px;
    text-align: center;
}

.key-bind:hover {
    background: rgba(52, 152, 219, 0.4);
    transform: scale(1.05);
}

.key-bind.recording {
    background: rgba(231, 76, 60, 0.3);
    border-color: #E74C3C;
    color: #E74C3C;
    animation: pulse-border 1s infinite;
}

@keyframes pulse-border {
    0%, 100% { border-color: #E74C3C; }
    50% { border-color: #C0392B; }
}

/* Snake Preview Large */
.snake-preview-large {
    width: 200px;
    height: 200px;
    margin: 0 auto 30px;
    border-radius: 20px;
    background: rgba(44, 62, 80, 0.8);
    border: 3px solid #3498DB;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
}

/* Color Picker Grid */
.color-picker-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(50px, 1fr));
    gap: 10px;
    margin-top: 15px;
}

.color-option {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    cursor: pointer;
    border: 3px solid transparent;
    transition: all 0.3s;
    position: relative;
}

.color-option:hover {
    transform: scale(1.1);
    border-color: rgba(255, 255, 255, 0.5);
}

.color-option.selected {
    border-color: #3498DB;
    box-shadow: 0 0 20px rgba(52, 152, 219, 0.8);
}

.color-option.selected::after {
    content: '✓';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: white;
    font-size: 24px;
    font-weight: bold;
    text-shadow: 0 0 5px rgba(0, 0, 0, 0.8);
}

/* Pattern Picker Grid */
.pattern-picker-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
    gap: 15px;
    margin-top: 15px;
}

.pattern-option {
    width: 80px;
    height: 80px;
    border-radius: 10px;
    cursor: pointer;
    border: 3px solid transparent;
    transition: all 0.3s;
    background: rgba(44, 62, 80, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    text-align: center;
    padding: 5px;
}

.pattern-option:hover {
    transform: scale(1.05);
    border-color: rgba(255, 255, 255, 0.5);
}

.pattern-option.selected {
    border-color: #3498DB;
    background: rgba(52, 152, 219, 0.3);
    box-shadow: 0 0 15px rgba(52, 152, 219, 0.6);
}

/* Mobile Responsive */
@media (max-width: 768px) {
    .menu-layout {
        flex-direction: column;
        gap: 30px;
        align-items: center;
    }

    .menu-content {
        max-width: 90%;
    }

    #menu-screen {
        overflow-y: auto;
        align-items: flex-start;
        padding-top: 40px;
        padding-bottom: 40px;
    }

    .leaderboard-section {
        position: static;
        max-width: 90%;
        max-height: none;
        width: 100%;
        margin-top: 20px;
        transform: none;
    }

    .home-leaderboard {
        overflow-y: visible;
    }

    .title-container {
        margin-top: 10px;
        margin-bottom: 35px;
    }

    .snake-title {
        font-size: clamp(15px, 3.8vw, 26px);
        margin-top: 0;
        flex-wrap: nowrap;
        white-space: nowrap;
        overflow: hidden;
    }

    .title-letter {
        animation: snake-wave-mobile 3.5s ease-in-out infinite, gradient-shift 8s linear infinite;
    }

    .title-letter.snake-letter {
        font-size: clamp(19px, 5.5vw, 34px);
        animation: snake-wave-mobile 3.5s ease-in-out infinite, gradient-shift 8s linear infinite;
    }

    .title-letter.domain-letter {
        font-size: clamp(11px, 2.8vw, 18px);
        animation: snake-wave-mobile 3.5s ease-in-out infinite, gradient-shift 8s linear infinite;
    }

    .short-url-letter {
        animation: snake-wave-mobile-subtle 3.5s ease-in-out infinite;
    }

    .settings-icon {
        width: 40px;
        height: 40px;
    }

    .hud-score {
        top: 10px;
        left: 10px;
        padding: 10px 15px;
    }

    .score-value {
        font-size: 24px;
    }

    .hud-leaderboard {
        top: 10px;
        right: 10px;
        min-width: 120px;
        padding: 8px;
        font-size: 10px;
        background: rgba(44, 62, 80, 0.5);
    }

    .hud-leaderboard .leaderboard-title {
        font-size: 11px;
        margin-bottom: 5px;
    }

    .hud-leaderboard .leaderboard-item {
        padding: 3px 0;
    }

    .hud-minimap {
        bottom: 10px;
        right: 10px;
        padding: 5px;
        background: rgba(44, 62, 80, 0.5);
    }

    #minimap-canvas {
        width: 100px;
        height: 100px;
        border: 1px solid #34495E;
    }

    .modal-content {
        width: 95%;
    }

    .color-picker-grid {
        grid-template-columns: repeat(auto-fill, minmax(40px, 1fr));
    }

    .color-option {
        width: 40px;
        height: 40px;
    }

    .pattern-picker-grid {
        grid-template-columns: repeat(auto-fill, minmax(60px, 1fr));
    }

    .pattern-option {
        width: 60px;
        height: 60px;
    }
}
