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

:root {
    --primary: #6C5CE7;
    --primary-dark: #5A4BD1;
    --accent: #00CEC9;
    --danger: #FF6B6B;
    --warning: #FDCB6E;
    --success: #00B894;
    --bg-dark: #0a0a1a;
    --bg-card: #1a1a2e;
    --text: #E0E0E0;
    --text-bright: #FFFFFF;
    --text-dim: #888;
}

html, body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    font-family: 'Inter', sans-serif;
    background: var(--bg-dark);
    color: var(--text);
}

.screen {
    display: none;
    width: 100%;
    height: 100%;
    position: absolute;
    top: 0;
    left: 0;
}

.screen.active {
    display: flex;
}

/* ========== LANDING ========== */
.landing-bg {
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, #0a0a1a 0%, #1a1a3e 50%, #0a0a1a 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    overflow: hidden;
}

.floating-icons {
    position: absolute;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

.float-icon {
    position: absolute;
    font-size: 2rem;
    left: var(--x);
    top: var(--y);
    animation: floatAnim 6s ease-in-out infinite;
    animation-delay: var(--delay);
    opacity: 0.15;
}

@keyframes floatAnim {
    0%, 100% { transform: translateY(0) rotate(0deg); }
    50% { transform: translateY(-20px) rotate(10deg); }
}

.landing-content {
    text-align: center;
    max-width: 700px;
    padding: 2rem;
    z-index: 1;
}

.landing-badge {
    display: inline-block;
    background: linear-gradient(135deg, var(--primary), var(--accent));
    color: white;
    padding: 0.3rem 1rem;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 2px;
    margin-bottom: 1.5rem;
}

.landing-title {
    font-size: 3rem;
    line-height: 1.1;
    margin-bottom: 1.5rem;
}

.title-line {
    display: block;
    font-weight: 400;
    color: var(--text-dim);
    font-size: 1.5rem;
}

.title-highlight {
    display: block;
    background: linear-gradient(90deg, var(--primary), var(--accent));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    font-weight: 900;
}

.landing-desc {
    font-size: 1rem;
    line-height: 1.7;
    color: var(--text-dim);
    margin-bottom: 2rem;
    max-width: 560px;
    margin-left: auto;
    margin-right: auto;
}

.landing-features {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    margin-bottom: 2rem;
    align-items: center;
}

.feature {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    background: rgba(108, 92, 231, 0.1);
    border: 1px solid rgba(108, 92, 231, 0.2);
    border-radius: 12px;
    padding: 0.6rem 1.2rem;
    font-size: 0.9rem;
    width: fit-content;
}

.feature-icon {
    font-size: 1.2rem;
}

.btn-start {
    background: linear-gradient(135deg, var(--primary), var(--accent));
    color: white;
    border: none;
    padding: 1rem 2.5rem;
    font-size: 1.1rem;
    font-weight: 700;
    border-radius: 16px;
    cursor: pointer;
    transition: all 0.3s;
    font-family: inherit;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
}

.btn-start:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 30px rgba(108, 92, 231, 0.4);
}

.btn-start:active {
    transform: translateY(0);
}

.btn-arrow {
    font-size: 1.3rem;
}

.btn-leader {
    display: block;
    margin: 1rem auto 0;
    background: transparent;
    color: var(--text-dim);
    border: 1px solid rgba(255,255,255,0.1);
    padding: 0.7rem 1.5rem;
    font-size: 0.9rem;
    border-radius: 12px;
    cursor: pointer;
    font-family: inherit;
    transition: all 0.3s;
}

.btn-leader:hover {
    border-color: var(--primary);
    color: var(--text);
}

/* ========== HUD ========== */
#hud {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 56px;
    background: rgba(10, 10, 26, 0.9);
    backdrop-filter: blur(10px);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1rem;
    z-index: 100;
    border-bottom: 1px solid rgba(108, 92, 231, 0.2);
}

#hud-left, #hud-right {
    display: flex;
    align-items: center;
    gap: 1rem;
    min-width: 200px;
}

#hud-right {
    justify-content: flex-end;
}

#player-name-display {
    font-weight: 700;
    color: var(--accent);
    font-size: 0.85rem;
}

#task-status {
    font-size: 0.8rem;
}

.status-label {
    color: var(--text-dim);
}

#status-text {
    color: var(--warning);
    font-weight: 600;
}

#timer-display {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-family: 'JetBrains Mono', monospace;
    font-size: 1.3rem;
    font-weight: 700;
    color: var(--text-bright);
}

.timer-icon {
    font-size: 1.1rem;
}

#path-indicator {
    font-size: 0.75rem;
    padding: 0.2rem 0.6rem;
    border-radius: 8px;
    font-weight: 600;
}

.hud-btn {
    background: rgba(108, 92, 231, 0.2);
    border: 1px solid rgba(108, 92, 231, 0.3);
    color: var(--text);
    width: 36px;
    height: 36px;
    border-radius: 10px;
    cursor: pointer;
    font-size: 1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.hud-btn:hover {
    background: rgba(108, 92, 231, 0.4);
}

/* ========== ONLINE BADGE ========== */
#online-badge {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--success);
    background: rgba(0, 184, 148, 0.1);
    border: 1px solid rgba(0, 184, 148, 0.25);
    padding: 0.25rem 0.7rem;
    border-radius: 8px;
}

.online-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--success);
    animation: onlinePulse 2s ease-in-out infinite;
}

@keyframes onlinePulse {
    0%, 100% { opacity: 1; box-shadow: 0 0 0 0 rgba(0, 184, 148, 0.4); }
    50% { opacity: 0.7; box-shadow: 0 0 8px 3px rgba(0, 184, 148, 0.2); }
}

/* ========== CANVAS ========== */
#gameCanvas {
    display: block;
    width: 100%;
    height: 100%;
    image-rendering: pixelated;
}

/* ========== MOBILE CONTROLS ========== */
#mobile-controls {
    display: none;
    position: fixed;
    bottom: 20px;
    left: 0;
    right: 0;
    padding: 0 20px;
    z-index: 100;
    justify-content: space-between;
    align-items: flex-end;
    pointer-events: none;
}

.dpad {
    display: grid;
    grid-template-columns: repeat(3, 60px);
    grid-template-rows: repeat(2, 60px);
    gap: 4px;
    pointer-events: all;
}

.dpad-btn {
    background: rgba(108, 92, 231, 0.3);
    border: 2px solid rgba(108, 92, 231, 0.4);
    color: white;
    border-radius: 14px;
    font-size: 1.2rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
    touch-action: manipulation;
}

.dpad-btn:active {
    background: rgba(108, 92, 231, 0.6);
}

.dpad-empty {
    background: transparent;
    border: none;
    pointer-events: none;
}

.interact-btn {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary), var(--accent));
    border: 3px solid rgba(255,255,255,0.2);
    color: white;
    font-size: 2rem;
    cursor: pointer;
    pointer-events: all;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
    touch-action: manipulation;
    transition: all 0.3s;
}

.interact-btn.pulse {
    animation: interactPulse 1s ease-in-out infinite;
    border-color: var(--accent);
    box-shadow: 0 0 20px rgba(0, 206, 201, 0.5);
}

.chat-btn {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    background: linear-gradient(135deg, #00B894, #00CEC9);
    border: 3px solid rgba(255,255,255,0.2);
    color: white;
    font-size: 1.6rem;
    cursor: pointer;
    pointer-events: all;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
    touch-action: manipulation;
    position: absolute;
    right: 0;
    bottom: 100px;
    animation: interactPulse 1.5s ease-in-out infinite;
    border-color: var(--accent);
    box-shadow: 0 0 20px rgba(0, 206, 201, 0.5);
}

@keyframes interactPulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.1); }
}

/* ========== INTERACTION HINT ========== */
#interact-hint {
    position: fixed;
    bottom: 120px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(10, 10, 26, 0.9);
    border: 1px solid var(--primary);
    padding: 0.5rem 1.2rem;
    border-radius: 10px;
    font-size: 0.85rem;
    z-index: 90;
    animation: hintPulse 2s ease-in-out infinite;
    white-space: nowrap;
}

@keyframes hintPulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(108, 92, 231, 0.4); }
    50% { box-shadow: 0 0 15px 5px rgba(108, 92, 231, 0.2); }
}

kbd {
    background: var(--primary);
    padding: 0.15rem 0.5rem;
    border-radius: 5px;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.8rem;
    font-weight: 700;
}

.hidden {
    display: none !important;
}

/* ========== DIALOG ========== */
#dialog-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.6);
    z-index: 200;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    padding: 2rem;
}

#dialog-box {
    background: var(--bg-card);
    border: 2px solid var(--primary);
    border-radius: 20px;
    padding: 1.5rem 2rem;
    max-width: 600px;
    width: 100%;
    position: relative;
    animation: dialogSlideUp 0.3s ease-out;
}

@keyframes dialogSlideUp {
    from { transform: translateY(40px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

#dialog-speaker {
    font-weight: 700;
    font-size: 0.85rem;
    color: var(--accent);
    margin-bottom: 0.5rem;
    text-transform: uppercase;
    letter-spacing: 1px;
}

#dialog-text {
    font-size: 1rem;
    line-height: 1.6;
    color: var(--text);
    min-height: 50px;
    margin-bottom: 1rem;
}

#dialog-input {
    width: 100%;
    padding: 0.8rem 1rem;
    background: rgba(255, 255, 255, 0.05);
    border: 2px solid var(--primary);
    border-radius: 12px;
    color: var(--text-bright);
    font-size: 1rem;
    font-family: inherit;
    outline: none;
    margin-bottom: 1rem;
    transition: border-color 0.3s;
}

#dialog-input:focus {
    border-color: var(--accent);
}

#dialog-actions {
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap;
}

#dialog-actions button {
    background: var(--primary);
    color: white;
    border: none;
    padding: 0.6rem 1.5rem;
    border-radius: 10px;
    cursor: pointer;
    font-family: inherit;
    font-size: 0.9rem;
    font-weight: 600;
    transition: all 0.2s;
}

#dialog-actions button:hover {
    background: var(--primary-dark);
    transform: translateY(-1px);
}

#dialog-actions button.accept-btn {
    background: linear-gradient(135deg, var(--success), var(--accent));
}

/* ========== COMPLETE OVERLAY ========== */
#complete-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.8);
    z-index: 300;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem;
}

.complete-box {
    background: var(--bg-card);
    border: 2px solid var(--success);
    border-radius: 24px;
    padding: 2.5rem;
    text-align: center;
    max-width: 500px;
    width: 100%;
    animation: dialogSlideUp 0.4s ease-out;
}

.complete-icon {
    font-size: 4rem;
    margin-bottom: 1rem;
}

.complete-box h2 {
    font-size: 1.8rem;
    margin-bottom: 1rem;
    color: var(--success);
}

#complete-time {
    font-family: 'JetBrains Mono', monospace;
    font-size: 2.5rem;
    font-weight: 700;
    color: var(--text-bright);
    margin-bottom: 0.5rem;
}

#complete-path {
    font-size: 0.9rem;
    color: var(--text-dim);
    margin-bottom: 1rem;
}

#complete-message {
    font-size: 1rem;
    color: var(--text);
    margin-bottom: 1.5rem;
    line-height: 1.6;
}

/* ========== LEADERBOARD ========== */
.lb-container {
    width: 100%;
    max-width: 700px;
    margin: 0 auto;
    padding: 2rem;
    overflow-y: auto;
    max-height: 100vh;
}

.back-btn {
    background: transparent;
    border: 1px solid rgba(255,255,255,0.1);
    color: var(--text-dim);
    padding: 0.5rem 1rem;
    border-radius: 10px;
    cursor: pointer;
    font-family: inherit;
    font-size: 0.85rem;
    transition: all 0.2s;
    margin-bottom: 1.5rem;
}

.back-btn:hover {
    border-color: var(--primary);
    color: var(--text);
}

.lb-title {
    font-size: 2rem;
    margin-bottom: 1.5rem;
    text-align: center;
}

.lb-tabs {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1.5rem;
    justify-content: center;
    flex-wrap: wrap;
}

.lb-tab {
    background: rgba(108, 92, 231, 0.1);
    border: 1px solid rgba(108, 92, 231, 0.2);
    color: var(--text-dim);
    padding: 0.5rem 1rem;
    border-radius: 10px;
    cursor: pointer;
    font-family: inherit;
    font-size: 0.85rem;
    transition: all 0.2s;
}

.lb-tab.active {
    background: var(--primary);
    border-color: var(--primary);
    color: white;
}

#lb-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.lb-entry {
    display: flex;
    align-items: center;
    gap: 1rem;
    background: var(--bg-card);
    border: 1px solid rgba(255,255,255,0.05);
    border-radius: 14px;
    padding: 0.8rem 1.2rem;
    transition: all 0.2s;
}

.lb-entry:hover {
    border-color: var(--primary);
}

.lb-entry.gold { border-color: #FFD700; background: rgba(255, 215, 0, 0.05); }
.lb-entry.silver { border-color: #C0C0C0; background: rgba(192, 192, 192, 0.03); }
.lb-entry.bronze { border-color: #CD7F32; background: rgba(205, 127, 50, 0.03); }

.lb-rank {
    font-weight: 900;
    font-size: 1.2rem;
    width: 40px;
    text-align: center;
    color: var(--text-dim);
}

.lb-entry.gold .lb-rank { color: #FFD700; }
.lb-entry.silver .lb-rank { color: #C0C0C0; }
.lb-entry.bronze .lb-rank { color: #CD7F32; }

.lb-info {
    flex: 1;
}

.lb-name {
    font-weight: 700;
    font-size: 1rem;
}

.lb-path-tag {
    font-size: 0.7rem;
    padding: 0.1rem 0.5rem;
    border-radius: 6px;
    margin-left: 0.5rem;
}

.lb-path-tag.traditional {
    background: rgba(253, 203, 110, 0.2);
    color: var(--warning);
}

.lb-path-tag.ai {
    background: rgba(0, 206, 201, 0.2);
    color: var(--accent);
}

.lb-time {
    font-family: 'JetBrains Mono', monospace;
    font-weight: 700;
    font-size: 1.1rem;
    color: var(--text-bright);
}

.lb-empty {
    text-align: center;
    color: var(--text-dim);
    padding: 3rem;
    font-size: 1rem;
}

/* ========== RESPONSIVE ========== */
@media (max-width: 768px) {
    .landing-title {
        font-size: 2rem;
    }

    .title-line {
        font-size: 1.2rem;
    }

    .landing-desc {
        font-size: 0.85rem;
    }

    .feature {
        font-size: 0.8rem;
        padding: 0.5rem 1rem;
    }

    #mobile-controls {
        display: flex;
    }

    #interact-hint {
        display: none !important;
    }

    #hud {
        height: 48px;
        padding: 0 0.5rem;
    }

    #timer-display {
        font-size: 1rem;
    }

    #hud-left {
        min-width: auto;
    }

    #task-status {
        display: none;
    }

    #dialog-box {
        padding: 1.2rem 1.5rem;
        border-radius: 16px;
    }

    #dialog-text {
        font-size: 0.9rem;
    }

    .dpad {
        grid-template-columns: repeat(3, 52px);
        grid-template-rows: repeat(3, 52px);
    }

    .interact-btn {
        width: 70px;
        height: 70px;
        font-size: 1.6rem;
    }

    .lb-container {
        padding: 1rem;
    }

    .lb-title {
        font-size: 1.5rem;
    }
}

@media (max-width: 400px) {
    .landing-title {
        font-size: 1.6rem;
    }

    .landing-features {
        display: none;
    }

    .dpad {
        grid-template-columns: repeat(3, 46px);
        grid-template-rows: repeat(3, 46px);
    }
}

/* ========== CHAT ========== */
#chat-hint {
    position: fixed;
    bottom: 120px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 206, 201, 0.15);
    border: 1px solid rgba(0, 206, 201, 0.4);
    color: var(--accent);
    padding: 0.5rem 1.2rem;
    border-radius: 12px;
    font-size: 0.85rem;
    backdrop-filter: blur(8px);
    z-index: 20;
    animation: hintPulse 2s ease-in-out infinite;
}

#chat-hint kbd {
    background: rgba(0, 206, 201, 0.25);
    padding: 2px 8px;
    border-radius: 4px;
    font-family: 'JetBrains Mono', monospace;
    font-weight: 700;
}

#chat-overlay {
    position: fixed;
    bottom: 80px;
    right: 20px;
    z-index: 50;
}

#chat-box {
    width: 320px;
    max-height: 400px;
    background: rgba(26, 26, 46, 0.95);
    border: 1px solid rgba(0, 206, 201, 0.3);
    border-radius: 16px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    backdrop-filter: blur(12px);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
}

#chat-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.7rem 1rem;
    background: rgba(0, 206, 201, 0.1);
    border-bottom: 1px solid rgba(0, 206, 201, 0.2);
    font-weight: 600;
    font-size: 0.85rem;
    color: var(--accent);
}

#chat-close {
    background: none;
    border: none;
    color: var(--text-dim);
    font-size: 1rem;
    cursor: pointer;
    padding: 2px 6px;
    border-radius: 4px;
}

#chat-close:hover {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text);
}

#chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 0.6rem 0.8rem;
    min-height: 200px;
    max-height: 280px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.chat-msg {
    font-size: 0.82rem;
    line-height: 1.4;
    word-break: break-word;
    padding: 3px 0;
}

.chat-msg-name {
    font-weight: 700;
    color: var(--accent);
}

#chat-input-area {
    display: flex;
    gap: 6px;
    padding: 0.6rem 0.8rem;
    border-top: 1px solid rgba(255, 255, 255, 0.06);
}

#chat-input {
    flex: 1;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 8px;
    padding: 0.5rem 0.8rem;
    color: var(--text);
    font-size: 0.82rem;
    font-family: 'Inter', sans-serif;
    outline: none;
}

#chat-input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px rgba(0, 206, 201, 0.15);
}

#chat-send {
    background: var(--accent);
    border: none;
    color: #0a0a1a;
    width: 36px;
    height: 36px;
    border-radius: 8px;
    font-size: 1rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

#chat-send:hover {
    opacity: 0.85;
}

@media (max-width: 600px) {
    #chat-overlay {
        right: 10px;
        left: 10px;
        bottom: 140px;
    }

    #chat-box {
        width: auto;
    }
}

@media (hover: none) and (pointer: coarse) {
    #mobile-controls {
        display: flex;
    }

    #chat-hint {
        display: none;
    }

    #chat-overlay {
        bottom: 160px;
    }
}
