* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html, body {
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', sans-serif;
    touch-action: none;
    background-color: #0a0f1a;
}

#orientation-warning {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: #0a0f1a;
    color: #fff;
    z-index: 1000;
    display: none;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    text-align: center;
    padding: 20px;
}
#orientation-warning .icon {
    font-size: 12vw;
    margin-bottom: 10px;
    animation: rotateHint 2s infinite;
}
#orientation-warning h2 {
    font-size: 1.2rem;
}
#orientation-warning p {
    font-size: 0.9rem;
    opacity: 0.8;
}
@keyframes rotateHint {
    0% { transform: rotate(0deg); }
    25% { transform: rotate(-90deg); }
    50% { transform: rotate(-90deg); }
    75% { transform: rotate(0deg); }
    100% { transform: rotate(0deg); }
}

#start-menu {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: linear-gradient(135deg, #0f172a 0%, #1e293b 50%, #0f172a 100%);
    z-index: 100;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    color: white;
    transition: opacity 0.6s ease, transform 0.6s ease;
    opacity: 1;
    pointer-events: auto;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    padding: 10px;
}

#start-menu.fade-out {
    opacity: 0;
    transform: scale(1.05);
    pointer-events: none;
}
#start-menu.hidden {
    display: none;
}

.menu-container {
    width: 100%;
    max-width: 500px;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 5px 0;
    margin: auto 0;
}

.menu-header {
    text-align: center;
    margin-bottom: 8px;
    animation: fadeInDown 0.6s ease;
    width: 100%;
}

.game-title {
    font-size: clamp(1.5rem, 6vw, 2.5rem);
    font-weight: 900;
    background: linear-gradient(135deg, #fbbf24 0%, #f59e0b 50%, #dc2626 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    letter-spacing: 2px;
    line-height: 1.1;
    margin-bottom: 4px;
}

.game-title::after {
    content: '';
    display: block;
    width: 50%;
    height: 2px;
    background: linear-gradient(90deg, transparent, #fbbf24, transparent);
    margin: 6px auto 0;
}

.game-subtitle {
    font-size: clamp(0.6rem, 2.5vw, 0.9rem);
    color: #94a3b8;
    letter-spacing: 3px;
}

@keyframes fadeInDown {
    from { opacity: 0; transform: translateY(-15px); }
    to { opacity: 1; transform: translateY(0); }
}

.map-selection {
    display: flex;
    flex-direction: row;
    gap: 8px;
    margin-bottom: 10px;
    animation: fadeInUp 0.6s ease 0.1s both;
    width: 100%;
    justify-content: center;
    align-items: stretch;
}

.map-card {
    flex: 1;
    min-width: 0;
    max-width: 160px;
    background: rgba(30, 41, 59, 0.6);
    backdrop-filter: blur(8px);
    border: 1.5px solid rgba(148, 163, 184, 0.2);
    border-radius: 12px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
    position: relative;
    overflow: hidden;
    padding: 8px 4px;
}

.map-card::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    background: radial-gradient(circle at center, rgba(251, 191, 36, 0.1) 0%, transparent 70%);
    opacity: 0;
    transition: opacity 0.2s;
}

.map-card:hover, .map-card:active {
    transform: scale(1.02);
    border-color: rgba(251, 191, 36, 0.5);
}

.map-card.selected {
    border-color: #fbbf24;
    background: rgba(251, 191, 36, 0.15);
    box-shadow: 0 0 15px rgba(251, 191, 36, 0.2);
}

.map-card.selected::after {
    content: '✓';
    position: absolute;
    top: 4px;
    right: 4px;
    width: 18px;
    height: 18px;
    background: #fbbf24;
    color: #0f172a;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    font-size: 11px;
}

.map-icon {
    font-size: clamp(1.8rem, 7vw, 2.5rem);
    margin-bottom: 4px;
    line-height: 1;
}

.map-name {
    font-size: clamp(0.85rem, 3.5vw, 1.1rem);
    font-weight: 700;
    color: #e2e8f0;
    margin-bottom: 2px;
}

.map-desc {
    font-size: clamp(0.6rem, 2.5vw, 0.75rem);
    color: #94a3b8;
    text-align: center;
    line-height: 1.3;
}

@keyframes fadeInUp {
    from { opacity: 0; transform: translateY(15px); }
    to { opacity: 1; transform: translateY(0); }
}

.start-btn {
    background: linear-gradient(135deg, #f59e0b 0%, #dc2626 100%);
    border: none;
    color: white;
    font-size: clamp(1rem, 4vw, 1.3rem);
    font-weight: 800;
    padding: 12px 40px;
    border-radius: 30px;
    cursor: pointer;
    box-shadow: 0 6px 20px rgba(220, 38, 38, 0.4);
    transition: all 0.2s ease;
    letter-spacing: 2px;
    text-transform: uppercase;
    animation: fadeInUp 0.6s ease 0.2s both;
    white-space: nowrap;
    margin: 5px 0;
}

.start-btn:active {
    transform: scale(0.98);
    box-shadow: 0 4px 15px rgba(220, 38, 38, 0.5);
}

.hint-text {
    margin-top: 8px;
    color: #64748b;
    font-size: clamp(0.6rem, 2.5vw, 0.8rem);
    text-align: center;
    line-height: 1.4;
    animation: fadeInUp 0.6s ease 0.3s both;
    max-width: 95%;
}

@media (max-height: 500px) {
    .menu-container {
        padding: 2px 0;
    }
    .menu-header {
        margin-bottom: 4px;
    }
    .map-selection {
        margin-bottom: 6px;
    }
    .map-card {
        padding: 6px 4px;
    }
    .map-icon {
        font-size: 1.5rem;
        margin-bottom: 2px;
    }
    .start-btn {
        padding: 10px 30px;
        font-size: 0.95rem;
    }
    .hint-text {
        margin-top: 4px;
        font-size: 0.6rem;
    }
}

@media (max-width: 320px) {
    .game-title {
        font-size: 1.3rem;
    }
    .map-name {
        font-size: 0.8rem;
    }
    .map-desc {
        font-size: 0.55rem;
    }
}

.modal {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(8px);
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.modal:not(.hidden) {
    opacity: 1;
    pointer-events: auto;
}

.modal-content {
    background: linear-gradient(135deg, #1e293b 0%, #0f172a 100%);
    border: 2px solid rgba(251, 191, 36, 0.3);
    border-radius: 20px;
    padding: 30px;
    max-width: 90%;
    width: 400px;
    text-align: center;
    animation: scaleIn 0.3s ease;
}

@keyframes scaleIn {
    from { transform: scale(0.9); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}

.modal-content h3 {
    color: #fbbf24;
    font-size: 1.5rem;
    margin-bottom: 20px;
    text-shadow: 0 0 20px rgba(251, 191, 36, 0.3);
}

.mode-options {
    display: flex;
    gap: 15px;
    margin-bottom: 20px;
    justify-content: center;
    flex-wrap: wrap;
}

.mode-card {
    flex: 1;
    min-width: 100px;
    background: rgba(30, 41, 59, 0.8);
    border: 2px solid rgba(148, 163, 184, 0.2);
    border-radius: 15px;
    padding: 20px 10px;
    cursor: pointer;
    transition: all 0.3s ease;
    max-width: 150px;
}

.mode-card:hover {
    transform: translateY(-5px);
    border-color: #fbbf24;
    background: rgba(251, 191, 36, 0.1);
    box-shadow: 0 10px 30px rgba(251, 191, 36, 0.2);
}

.mode-icon {
    font-size: 2.5rem;
    margin-bottom: 10px;
}

.mode-name {
    color: #e2e8f0;
    font-weight: 700;
    font-size: 1.1rem;
    margin-bottom: 5px;
}

.mode-desc {
    color: #94a3b8;
    font-size: 0.8rem;
}

.back-btn {
    background: transparent;
    border: 2px solid rgba(148, 163, 184, 0.4);
    color: #94a3b8;
    padding: 10px 30px;
    border-radius: 20px;
    cursor: pointer;
    transition: all 0.3s ease;
    font-size: 0.9rem;
    margin-top: 10px;
}

.back-btn:hover {
    border-color: #fbbf24;
    color: #fbbf24;
    background: rgba(251, 191, 36, 0.1);
}

.auth-content {
    width: 350px;
}
.auth-form {
    display: flex;
    flex-direction: column;
    gap: 15px;
}
.auth-form input {
    padding: 12px 15px;
    border-radius: 30px;
    border: none;
    background: rgba(255,255,255,0.1);
    color: white;
    font-size: 1rem;
    outline: none;
    border: 1px solid rgba(255,255,255,0.2);
}
.auth-form input:focus {
    border-color: #fbbf24;
}
.auth-actions {
    display: flex;
    gap: 10px;
    justify-content: center;
}
.auth-btn {
    background: #f59e0b;
    border: none;
    color: white;
    padding: 10px 25px;
    border-radius: 30px;
    font-weight: bold;
    cursor: pointer;
    transition: 0.2s;
    flex: 1;
}
.auth-btn.secondary {
    background: transparent;
    border: 1px solid #94a3b8;
    color: #94a3b8;
}
.auth-btn:hover {
    opacity: 0.9;
}
.auth-error {
    color: #ef4444;
    font-size: 0.85rem;
    min-height: 20px;
}

#survival-timer {
    position: absolute;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(20, 30, 20, 0.9);
    border: 2px solid #ef4444;
    border-radius: 15px;
    padding: 10px 25px;
    z-index: 35;
    text-align: center;
    box-shadow: 0 0 30px rgba(239, 68, 68, 0.4);
    animation: pulse 2s infinite;
}

#survival-timer.hidden {
    display: none;
}

.timer-label {
    color: #94a3b8;
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 2px;
    margin-bottom: 2px;
}

.timer-value {
    color: #ef4444;
    font-size: 2rem;
    font-weight: 900;
    font-family: 'Courier New', monospace;
    text-shadow: 0 0 20px rgba(239, 68, 68, 0.8);
}

@keyframes pulse {
    0%, 100% { box-shadow: 0 0 20px rgba(239, 68, 68, 0.4); }
    50% { box-shadow: 0 0 40px rgba(239, 68, 68, 0.6); }
}

.timer-warning {
    animation: urgentPulse 0.5s infinite !important;
    border-color: #dc2626 !important;
}

.timer-warning .timer-value {
    color: #dc2626 !important;
    animation: blink 0.5s infinite;
}

@keyframes urgentPulse {
    0%, 100% { transform: translateX(-50%) scale(1); box-shadow: 0 0 30px rgba(220, 38, 38, 0.6); }
    50% { transform: translateX(-50%) scale(1.05); box-shadow: 0 0 50px rgba(220, 38, 38, 0.8); }
}

@keyframes blink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.6; }
}

#win-message {
    position: absolute;
    top: 30%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(30, 40, 20, 0.9);
    color: #ffd966;
    padding: 15px 30px;
    border-radius: 50px;
    font-size: clamp(1.2rem, 4vw, 1.8rem);
    font-weight: bold;
    backdrop-filter: blur(10px);
    border: 2px solid #ffd966;
    box-shadow: 0 0 40px rgba(255, 217, 102, 0.5);
    pointer-events: none;
    z-index: 40;
    display: none;
    text-align: center;
    white-space: nowrap;
    letter-spacing: 3px;
}
#win-message.show {
    display: block;
    animation: pulseMessage 1.5s infinite;
}
@keyframes pulseMessage {
    0%, 100% { transform: translate(-50%, -50%) scale(1); opacity: 0.9; }
    50% { transform: translate(-50%, -50%) scale(1.05); opacity: 1; }
}

#joystick-container {
    position: absolute;
    bottom: 20px;
    left: 20px;
    width: 120px;
    height: 120px;
    background: rgba(20, 20, 30, 0.5);
    backdrop-filter: blur(10px);
    border-radius: 50%;
    border: 2px solid rgba(255, 255, 255, 0.3);
    box-shadow: 0 8px 32px rgba(0,0,0,0.4);
    z-index: 30;
    touch-action: none;
    display: none;
}

#joystick-container.active {
    display: block;
}

.nipple {
    width: 100% !important;
    height: 100% !important;
}

.nipple .back {
    background: rgba(255, 255, 255, 0.15) !important;
    border: 2px solid rgba(255, 255, 255, 0.3) !important;
}

.nipple .front {
    background: rgba(255, 255, 255, 0.8) !important;
    box-shadow: 0 0 10px rgba(255,255,255,0.5) !important;
}

#jump-btn {
    position: absolute;
    bottom: 20px;
    right: 20px;
    width: 80px;
    height: 80px;
    background: rgba(255, 255, 255, 0.3);
    backdrop-filter: blur(10px);
    border-radius: 50%;
    border: 3px solid rgba(255, 255, 255, 0.6);
    box-shadow: 0 8px 32px rgba(0,0,0,0.4);
    z-index: 30;
    touch-action: none;
    display: none;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: transform 0.1s, opacity 0.3s;
}

#jump-btn.active {
    display: flex;
}

#jump-btn.ready {
    opacity: 1;
}

#jump-btn:not(.ready) {
    opacity: 0.5;
}

#jump-btn:active {
    transform: scale(0.9);
}

#jump-btn::after {
    content: "⬆";
    font-size: 1.8rem;
    color: rgba(255, 255, 255, 0.9);
    font-weight: bold;
}

#speed-indicator {
    position: absolute;
    bottom: 110px;
    right: 20px;
    color: #fbbf24;
    font-size: 0.9rem;
    font-weight: 800;
    text-shadow: 0 0 15px rgba(251, 191, 36, 0.8);
    z-index: 25;
    pointer-events: none;
    display: none;
}

#speed-indicator.active {
    display: block;
}

#fade-overlay {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: black;
    z-index: 90;
    opacity: 0;
    pointer-events: none;
    transition: opacity 5s ease-out;
}
#fade-overlay.active {
    opacity: 1;
}

.hidden {
    display: none !important;
}