/* ===== Reset & Base ===== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    overflow: hidden;
    background: #1a1a2e;
    font-family: 'Nunito', 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    cursor: default;
    user-select: none;
}

canvas {
    display: block;
}

/* ===== HOME SCREEN ===== */
#home-screen {
    position: fixed;
    inset: 0;
    display: flex;
    background: #191b2a;
    z-index: 1000;
    transition: opacity 0.35s ease;
    opacity: 1;
}

#home-screen.fade-out {
    opacity: 0;
    pointer-events: none;
}

#home-screen.hidden {
    display: none;
}

/* --- Sidebar --- */
.home-sidebar {
    width: 220px;
    background: #12131f;
    display: flex;
    flex-direction: column;
    border-right: 1px solid rgba(255,255,255,0.06);
    flex-shrink: 0;
}

.sidebar-logo {
    padding: 24px 20px 20px;
    font-size: 1.5rem;
    font-weight: 900;
    background: linear-gradient(135deg, #ff6b6b, #ffd93d);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    letter-spacing: 1px;
}

.sidebar-nav {
    flex: 1;
    padding: 8px 10px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.nav-btn {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    border: none;
    border-radius: 10px;
    background: transparent;
    color: rgba(255,255,255,0.5);
    font-size: 0.95rem;
    font-weight: 700;
    font-family: inherit;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
}

.nav-btn:hover {
    background: rgba(255,255,255,0.06);
    color: rgba(255,255,255,0.8);
}

.nav-btn.active {
    background: rgba(255,107,107,0.15);
    color: #ff6b6b;
}

.nav-icon {
    font-size: 1.2rem;
    width: 24px;
    text-align: center;
}

.sidebar-footer {
    padding: 16px;
    border-top: 1px solid rgba(255,255,255,0.06);
}

.sidebar-user {
    display: flex;
    align-items: center;
    gap: 10px;
}

.user-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: linear-gradient(135deg, #8B5E3C, #D4A76A);
    flex-shrink: 0;
}

.user-name {
    color: rgba(255,255,255,0.8);
    font-size: 0.9rem;
    font-weight: 700;
}

/* --- Main Content --- */
.home-main {
    flex: 1;
    overflow-y: auto;
    padding: 0;
}

.home-tab {
    display: none;
    padding: 0 32px 32px;
}

.home-tab.active {
    display: block;
}

/* --- Hero Banner --- */
.home-hero {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 50%, #ff6b6b 100%);
    border-radius: 16px;
    padding: 40px 48px;
    margin: 24px 0;
    position: relative;
    overflow: hidden;
}

.home-hero::after {
    content: '';
    position: absolute;
    top: -50%;
    right: -10%;
    width: 300px;
    height: 300px;
    border-radius: 50%;
    background: rgba(255,255,255,0.08);
}

.hero-text h1 {
    font-size: 2.2rem;
    font-weight: 900;
    color: white;
    margin-bottom: 6px;
}

.hero-text p {
    font-size: 1.1rem;
    color: rgba(255,255,255,0.8);
    font-weight: 600;
}

/* --- Section --- */
.home-section {
    margin-bottom: 32px;
}

.section-title {
    color: rgba(255,255,255,0.9);
    font-size: 1.25rem;
    font-weight: 800;
    margin-bottom: 16px;
    padding-left: 4px;
}

/* --- Game Grid --- */
.game-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 16px;
}

/* --- Game Card --- */
.game-card {
    background: #222438;
    border-radius: 14px;
    overflow: hidden;
    cursor: pointer;
    transition: transform 0.18s ease, box-shadow 0.18s ease;
    border: 2px solid transparent;
}

.game-card:hover {
    transform: translateY(-4px) scale(1.02);
    box-shadow: 0 8px 30px rgba(0,0,0,0.4);
    border-color: rgba(255,107,107,0.4);
}

.game-card-thumb {
    width: 100%;
    aspect-ratio: 16 / 10;
    position: relative;
    overflow: hidden;
}

.game-card-thumb .thumb-icon {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 3rem;
    color: rgba(255,255,255,0.4);
}

.game-card-info {
    padding: 12px 14px;
}

.game-card-title {
    color: white;
    font-size: 0.95rem;
    font-weight: 800;
    margin-bottom: 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.game-card-meta {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.game-card-players {
    color: rgba(255,255,255,0.4);
    font-size: 0.78rem;
    font-weight: 600;
}

.game-card-tag {
    font-size: 0.68rem;
    font-weight: 700;
    padding: 3px 8px;
    border-radius: 6px;
    color: white;
}

.play-btn-card {
    display: block;
    width: calc(100% - 28px);
    margin: 0 14px 12px;
    padding: 8px 0;
    border: none;
    border-radius: 8px;
    background: #4CAF50;
    color: white;
    font-size: 0.85rem;
    font-weight: 800;
    font-family: inherit;
    cursor: pointer;
    letter-spacing: 1px;
    transition: background 0.15s;
}

.play-btn-card:hover {
    background: #43A047;
}

/* --- Home Friends Tab --- */
.home-friends-list {
    max-width: 500px;
}

.home-friend-item {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 12px 16px;
    border-radius: 12px;
    margin-bottom: 4px;
    transition: background 0.15s;
}

.home-friend-item:hover {
    background: rgba(255,255,255,0.04);
}

.home-friend-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
}

.home-friend-dot.online {
    background: #4CAF50;
    box-shadow: 0 0 6px #4CAF50;
}

.home-friend-dot.offline {
    background: #555;
}

.home-friend-name {
    color: white;
    font-weight: 700;
    font-size: 0.95rem;
}

.home-friend-status {
    color: rgba(255,255,255,0.35);
    font-size: 0.78rem;
    font-weight: 600;
}

.home-friend-add {
    display: flex;
    gap: 8px;
    margin-top: 16px;
    max-width: 500px;
}

.home-friend-add input {
    flex: 1;
    padding: 10px 16px;
    border: none;
    border-radius: 10px;
    background: rgba(255,255,255,0.08);
    color: white;
    font-size: 0.9rem;
    font-family: inherit;
    outline: none;
}

.home-friend-add input::placeholder {
    color: rgba(255,255,255,0.3);
}

.home-friend-add input:focus {
    background: rgba(255,255,255,0.12);
}

.home-friend-add button {
    padding: 10px 24px;
    border: none;
    border-radius: 10px;
    background: #4CAF50;
    color: white;
    font-weight: 700;
    font-family: inherit;
    cursor: pointer;
    transition: background 0.15s;
}

.home-friend-add button:hover {
    background: #43A047;
}

/* --- Profile Tab --- */
.profile-card {
    max-width: 400px;
    margin-top: 32px;
    background: #222438;
    border-radius: 20px;
    padding: 40px;
    text-align: center;
}

.profile-avatar-large {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    background: linear-gradient(135deg, #8B5E3C, #D4A76A);
    margin: 0 auto 16px;
    border: 3px solid rgba(255,255,255,0.1);
}

.profile-card h2 {
    color: white;
    font-size: 1.5rem;
    margin-bottom: 16px;
}

.profile-stat {
    color: rgba(255,255,255,0.6);
    font-size: 0.95rem;
    margin-bottom: 8px;
    font-weight: 600;
}

.profile-joined {
    color: rgba(255,255,255,0.3);
    font-size: 0.8rem;
    margin-top: 16px;
    font-weight: 600;
}

/* --- Avatar Editor --- */
.avatar-editor {
    display: flex;
    gap: 32px;
    margin-top: 16px;
    flex-wrap: wrap;
}

.avatar-preview-container {
    background: #222438;
    border-radius: 16px;
    padding: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

#avatar-preview {
    border-radius: 12px;
    background: linear-gradient(135deg, #2C3E50, #34495E);
}

.avatar-options {
    flex: 1;
    min-width: 260px;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.avatar-option-group h3 {
    color: rgba(255,255,255,0.7);
    font-size: 0.85rem;
    font-weight: 700;
    margin-bottom: 10px;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.color-swatches {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.color-swatch {
    width: 38px;
    height: 38px;
    border-radius: 10px;
    cursor: pointer;
    border: 3px solid transparent;
    transition: transform 0.12s, border-color 0.12s;
}

.color-swatch:hover {
    transform: scale(1.12);
}

.color-swatch.selected {
    border-color: white;
    box-shadow: 0 0 10px rgba(255,255,255,0.3);
}

.hat-options {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.avatar-option-btn {
    padding: 8px 16px;
    border: 2px solid rgba(255,255,255,0.1);
    border-radius: 10px;
    background: rgba(255,255,255,0.05);
    color: rgba(255,255,255,0.7);
    font-size: 0.85rem;
    font-weight: 700;
    font-family: inherit;
    cursor: pointer;
    transition: all 0.15s;
}

.avatar-option-btn:hover {
    background: rgba(255,255,255,0.1);
    color: white;
}

.avatar-option-btn.selected {
    background: rgba(255,107,107,0.2);
    border-color: #ff6b6b;
    color: #ff6b6b;
}

/* ===== HUD ===== */
#hud {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 10;
}

#hud.hidden {
    display: none;
}

#hud-top-left {
    position: absolute;
    top: 16px;
    left: 16px;
}

#player-name {
    background: rgba(0, 0, 0, 0.55);
    color: #ffd93d;
    padding: 8px 18px;
    border-radius: 12px;
    font-size: 1rem;
    font-weight: 600;
    backdrop-filter: blur(6px);
}

#hud-top-right {
    position: absolute;
    top: 16px;
    right: 16px;
}

#area-name {
    background: rgba(0, 0, 0, 0.55);
    color: #6bcb77;
    padding: 8px 18px;
    border-radius: 12px;
    font-size: 1rem;
    font-weight: 600;
    backdrop-filter: blur(6px);
}

#hud-bottom {
    position: absolute;
    bottom: 16px;
    left: 50%;
    transform: translateX(-50%);
}

#controls-hint {
    background: rgba(0, 0, 0, 0.55);
    color: rgba(255, 255, 255, 0.8);
    padding: 8px 24px;
    border-radius: 12px;
    font-size: 0.85rem;
    backdrop-filter: blur(6px);
    white-space: nowrap;
}

/* ===== Interaction Prompt ===== */
#interact-prompt {
    position: fixed;
    bottom: 80px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 15;
    transition: opacity 0.25s;
}

#interact-prompt.hidden {
    opacity: 0;
    pointer-events: none;
}

.prompt-box {
    background: rgba(0, 0, 0, 0.7);
    color: white;
    padding: 10px 24px;
    border-radius: 12px;
    font-size: 1.1rem;
    backdrop-filter: blur(6px);
}

.prompt-box .key {
    background: #ff6b6b;
    padding: 2px 10px;
    border-radius: 6px;
    font-weight: 700;
    margin: 0 2px;
}

/* ===== Minigame HUD ===== */
#minigame-hud {
    position: fixed;
    top: 60px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 12;
    text-align: center;
}

#minigame-hud.hidden {
    display: none;
}

.mg-timer, .mg-info {
    background: rgba(0, 0, 0, 0.6);
    color: white;
    padding: 8px 20px;
    border-radius: 12px;
    font-size: 1.1rem;
    font-weight: 600;
    margin-bottom: 8px;
    backdrop-filter: blur(6px);
    display: inline-block;
}

/* ===== Tycoon HUD ===== */
.tycoon-hud {
    position: fixed;
    top: 50%;
    right: 20px;
    transform: translateY(-50%);
    z-index: 12;
    display: flex;
    flex-direction: column;
    gap: 10px;
    pointer-events: auto;
}

.tycoon-currency {
    background: rgba(0, 0, 0, 0.7);
    color: #ffd93d;
    padding: 12px 24px;
    border-radius: 14px;
    font-size: 1.4rem;
    font-weight: 700;
    text-align: center;
    backdrop-filter: blur(6px);
}

.tycoon-btn {
    padding: 12px 20px;
    border: none;
    border-radius: 14px;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.1s, opacity 0.2s;
    color: white;
    pointer-events: auto;
    font-family: inherit;
}

.tycoon-btn:hover {
    transform: scale(1.05);
}

.tycoon-btn:active {
    transform: scale(0.95);
}

.tycoon-btn:disabled {
    opacity: 0.45;
    cursor: not-allowed;
    transform: none;
}

.tycoon-btn.click-btn {
    background: #ff6b6b;
    font-size: 1.2rem;
    padding: 18px 32px;
    box-shadow: 0 4px 0 #c0392b;
}

.tycoon-btn.upgrade-btn {
    background: #4d8cf5;
    box-shadow: 0 3px 0 #2d6fd4;
}

.tycoon-btn.owned {
    background: #6bcb77;
    box-shadow: 0 3px 0 #4aa85a;
}

/* ===== Friends Panel (in-game) ===== */
#friends-panel {
    position: fixed;
    top: 0;
    right: 0;
    width: 300px;
    height: 100%;
    background: rgba(15, 15, 35, 0.92);
    backdrop-filter: blur(12px);
    z-index: 50;
    display: flex;
    flex-direction: column;
    transition: transform 0.3s ease;
    border-left: 2px solid rgba(255, 255, 255, 0.1);
}

#friends-panel.panel-hidden {
    transform: translateX(100%);
}

.panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.panel-header h2 {
    color: #ffd93d;
    font-size: 1.3rem;
}

.panel-close {
    color: rgba(255, 255, 255, 0.6);
    font-size: 1.6rem;
    cursor: pointer;
    pointer-events: auto;
    transition: color 0.15s;
}

.panel-close:hover {
    color: white;
}

#friends-list {
    flex: 1;
    overflow-y: auto;
    padding: 12px;
}

.friend-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 14px;
    border-radius: 10px;
    transition: background 0.15s;
    margin-bottom: 4px;
}

.friend-item:hover {
    background: rgba(255, 255, 255, 0.06);
}

.friend-status {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
}

.friend-status.online {
    background: #6bcb77;
    box-shadow: 0 0 6px #6bcb77;
}

.friend-status.offline {
    background: #666;
}

.friend-name {
    color: white;
    font-size: 0.95rem;
    font-weight: 500;
}

.friend-name .status-text {
    display: block;
    font-size: 0.75rem;
    color: rgba(255, 255, 255, 0.4);
    font-weight: 400;
}

.panel-footer {
    padding: 16px;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    display: flex;
    gap: 8px;
}

#friend-input {
    flex: 1;
    padding: 10px 14px;
    border: none;
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.1);
    color: white;
    font-size: 0.9rem;
    outline: none;
    pointer-events: auto;
    font-family: inherit;
}

#friend-input::placeholder {
    color: rgba(255, 255, 255, 0.35);
}

#friend-input:focus {
    background: rgba(255, 255, 255, 0.15);
}

#friend-add-btn {
    padding: 10px 18px;
    border: none;
    border-radius: 10px;
    background: #6bcb77;
    color: white;
    font-weight: 600;
    cursor: pointer;
    pointer-events: auto;
    font-family: inherit;
    transition: background 0.15s;
}

#friend-add-btn:hover {
    background: #5ab868;
}

/* ===== Countdown Overlay ===== */
#countdown-overlay {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    pointer-events: none;
}

#countdown-overlay.hidden {
    display: none;
}

#countdown-text {
    font-size: 8rem;
    font-weight: 900;
    color: white;
    text-shadow: 4px 4px 0 rgba(0,0,0,0.4);
    animation: countPulse 0.5s ease;
}

@keyframes countPulse {
    0% { transform: scale(1.6); opacity: 0; }
    50% { transform: scale(1); opacity: 1; }
    100% { transform: scale(0.95); opacity: 1; }
}

/* ===== Result Overlay ===== */
#result-overlay {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    background: rgba(0, 0, 0, 0.6);
}

#result-overlay.hidden {
    display: none;
}

#result-content {
    background: rgba(15, 15, 35, 0.95);
    padding: 40px 60px;
    border-radius: 20px;
    text-align: center;
    color: white;
    backdrop-filter: blur(10px);
    border: 2px solid rgba(255, 255, 255, 0.1);
}

#result-content h2 {
    font-size: 2.4rem;
    margin-bottom: 12px;
    color: #ffd93d;
}

#result-content p {
    font-size: 1.2rem;
    margin-bottom: 8px;
    color: rgba(255, 255, 255, 0.8);
}

#result-content .result-btn {
    margin-top: 20px;
    padding: 12px 36px;
    border: none;
    border-radius: 12px;
    background: #ff6b6b;
    color: white;
    font-size: 1.1rem;
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
    transition: transform 0.1s;
}

#result-content .result-btn:hover {
    transform: scale(1.05);
}

/* ===== Scrollbar ===== */
::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
    border-radius: 3px;
}

/* ===== Race position display ===== */
.race-position {
    font-size: 2rem;
    font-weight: 900;
    margin-bottom: 4px;
}

.race-position.first { color: #ffd93d; }
.race-position.second { color: #c0c0c0; }
.race-position.third { color: #cd7f32; }

/* ===== Lap display ===== */
.race-laps {
    font-size: 1rem;
    color: rgba(255,255,255,0.7);
}

/* ===== Balloon Game HUD ===== */
.balloon-hud {
    position: fixed;
    top: 16px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 12;
    display: flex;
    gap: 20px;
    pointer-events: none;
}

.balloon-hud-item {
    background: rgba(0,0,0,0.6);
    color: white;
    padding: 10px 20px;
    border-radius: 12px;
    font-weight: 700;
    font-size: 1.1rem;
    backdrop-filter: blur(6px);
}

.balloon-hud-item.score { color: #ffd93d; }
.balloon-hud-item.lives { color: #ff6b6b; }
.balloon-hud-item.timer { color: #74B9FF; }

#balloon-warning {
    animation: warningPulse 0.5s ease infinite alternate;
    font-size: 1.4rem !important;
    text-shadow: 0 0 20px #ff0000;
}

@keyframes warningPulse {
    0% { opacity: 0.5; transform: scale(1); }
    100% { opacity: 1; transform: scale(1.05); }
}

/* ===== Tower Defense HUD ===== */
.td-hud {
    position: fixed;
    top: 16px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 12;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    pointer-events: none;
}

.td-hud-bar {
    display: flex;
    gap: 12px;
}

.td-hud-item {
    background: rgba(0,0,0,0.6);
    color: white;
    padding: 10px 18px;
    border-radius: 12px;
    font-weight: 700;
    font-size: 1rem;
    backdrop-filter: blur(6px);
}

.td-tower-select {
    background: rgba(0,0,0,0.6);
    padding: 12px 20px;
    border-radius: 14px;
    backdrop-filter: blur(6px);
    pointer-events: auto;
    text-align: center;
}

.td-tower-label {
    color: rgba(255,255,255,0.7);
    font-size: 0.8rem;
    font-weight: 600;
    margin-bottom: 8px;
}

.td-tower-buttons {
    display: flex;
    gap: 8px;
}

.td-tower-btn {
    padding: 8px 14px;
    border: 2px solid rgba(255,255,255,0.3);
    border-radius: 10px;
    background: rgba(255,255,255,0.08);
    color: white;
    font-size: 0.8rem;
    font-weight: 700;
    font-family: inherit;
    cursor: pointer;
    transition: all 0.15s;
}

.td-tower-btn:hover {
    background: rgba(255,255,255,0.15);
}

.td-tower-btn.selected {
    background: rgba(255,255,255,0.2);
    border-color: white;
    box-shadow: 0 0 10px rgba(255,255,255,0.2);
}

.td-tower-btn small {
    display: block;
    color: #ffd93d;
    font-size: 0.7rem;
    margin-top: 2px;
}
