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

:root {
    --nav-bg: #1a1b1e;
    --nav-border: #2a2b2e;
    --bg-primary: #0e0f11;
    --bg-secondary: #16171a;
    --bg-card: #1e1f23;
    --bg-card-hover: #252629;
    --text-primary: #f0f0f0;
    --text-secondary: #9a9ba0;
    --accent-green: #00d17a;
    --accent-green-hover: #00e88a;
    --accent-blue: #00a2ff;
    --accent-red: #ff4757;
    --accent-yellow: #ffc312;
    --accent-purple: #a855f7;
    --berry-pink: #ff6b9d;
    --card-radius: 10px;
}

body {
    font-family: 'IBM Plex Sans', sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    overflow-x: hidden;
    min-height: 100vh;
}

#app-container {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

/* NAVBAR */
#navbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 20px;
    height: 56px;
    background: var(--nav-bg);
    border-bottom: 1px solid var(--nav-border);
    position: sticky;
    top: 0;
    z-index: 100;
}

#logo {
    font-family: 'Bungee', cursive;
    font-size: 22px;
    color: var(--accent-green);
    cursor: pointer;
    letter-spacing: 2px;
    transition: color 0.2s;
    text-shadow: 0 0 20px rgba(0,209,122,0.3);
}

#logo:hover {
    color: var(--accent-green-hover);
}

#nav-right {
    display: flex;
    align-items: center;
    gap: 16px;
}

#berries-display {
    background: linear-gradient(135deg, #2a1020, #1a0515);
    border: 1px solid #ff6b9d44;
    padding: 6px 14px;
    border-radius: 20px;
    font-weight: 700;
    font-size: 14px;
    color: var(--berry-pink);
}

#user-area {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    padding: 4px 10px;
    border-radius: 8px;
    transition: background 0.2s;
}

#user-area:hover {
    background: var(--bg-card);
}

#username-display {
    font-weight: 600;
    font-size: 14px;
    color: var(--text-secondary);
}

#mini-avatar {
    border-radius: 4px;
    image-rendering: pixelated;
}

/* PROFILE SIDEBAR */
#profile-sidebar {
    position: fixed;
    right: 0;
    top: 56px;
    width: 320px;
    height: calc(100vh - 56px);
    background: var(--bg-secondary);
    border-left: 1px solid var(--nav-border);
    z-index: 99;
    overflow-y: auto;
    padding: 24px;
    animation: slideIn 0.25s ease;
}

@keyframes slideIn {
    from { transform: translateX(100%); }
    to { transform: translateX(0); }
}

#profile-header {
    text-align: center;
    margin-bottom: 20px;
}

#profile-avatar {
    border-radius: 8px;
    image-rendering: pixelated;
    border: 3px solid var(--accent-green);
}

#profile-username {
    font-family: 'Bungee', cursive;
    font-size: 18px;
    margin-top: 10px;
    color: var(--text-primary);
}

#profile-berries {
    color: var(--berry-pink);
    font-weight: 600;
    margin-top: 4px;
}

#profile-stats, #profile-customization, #profile-creations {
    margin-top: 20px;
}

#profile-stats h3, #profile-customization h3, #profile-creations h3 {
    font-size: 14px;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 10px;
}

.stat-row {
    display: flex;
    justify-content: space-between;
    padding: 8px 0;
    border-bottom: 1px solid var(--nav-border);
    font-size: 14px;
}

.stat-row span:last-child {
    font-weight: 700;
    color: var(--accent-blue);
}

#color-picker {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.color-swatch {
    width: 36px;
    height: 36px;
    border-radius: 6px;
    cursor: pointer;
    border: 3px solid transparent;
    transition: all 0.15s;
}

.color-swatch:hover, .color-swatch.active {
    border-color: white;
    transform: scale(1.15);
}

.sidebar-close {
    width: 100%;
    margin-top: 24px;
    padding: 10px;
    background: var(--bg-card);
    color: var(--text-secondary);
    border: 1px solid var(--nav-border);
    border-radius: 8px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
}

.sidebar-close:hover {
    background: var(--bg-card-hover);
}

/* HOME SCREEN */
#home-screen {
    flex: 1;
    max-width: 1100px;
    margin: 0 auto;
    padding: 24px 20px;
    width: 100%;
}

#search-area {
    margin-bottom: 24px;
}

#search-bar {
    width: 100%;
    padding: 14px 20px;
    background: var(--bg-card);
    border: 1px solid var(--nav-border);
    border-radius: 12px;
    color: var(--text-primary);
    font-size: 16px;
    font-family: 'IBM Plex Sans', sans-serif;
    outline: none;
    transition: border-color 0.2s;
}

#search-bar:focus {
    border-color: var(--accent-green);
}

#search-bar::placeholder {
    color: var(--text-secondary);
}

/* HERO BANNER */
#hero-banner {
    background: linear-gradient(135deg, #0a2a1a 0%, #1a0a2a 50%, #2a0a1a 100%);
    border: 1px solid var(--nav-border);
    border-radius: 16px;
    padding: 32px;
    margin-bottom: 32px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 24px;
    position: relative;
    overflow: hidden;
}

#hero-banner::before {
    content: '';
    position: absolute;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: radial-gradient(circle at 30% 50%, rgba(0,209,122,0.08) 0%, transparent 50%);
    pointer-events: none;
}

#hero-badge {
    display: inline-block;
    background: var(--accent-yellow);
    color: #000;
    padding: 4px 12px;
    border-radius: 4px;
    font-weight: 700;
    font-size: 11px;
    letter-spacing: 1px;
    margin-bottom: 12px;
}

#hero-title {
    font-family: 'Bungee', cursive;
    font-size: 28px;
    margin-bottom: 8px;
    line-height: 1.2;
}

#hero-desc {
    color: var(--text-secondary);
    font-size: 15px;
    margin-bottom: 16px;
}

.hero-play {
    font-size: 16px !important;
    padding: 12px 32px !important;
}

#hero-canvas {
    border-radius: 10px;
    flex-shrink: 0;
}

#games-heading {
    font-family: 'Bungee', cursive;
    font-size: 20px;
    margin-bottom: 16px;
    color: var(--text-secondary);
}

/* GAME GRID */
#game-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 20px;
    margin-bottom: 40px;
}

.game-card {
    background: var(--bg-card);
    border: 1px solid var(--nav-border);
    border-radius: var(--card-radius);
    overflow: hidden;
    transition: all 0.25s;
    cursor: pointer;
    position: relative;
}

.game-card:hover {
    border-color: var(--accent-green);
    transform: translateY(-4px);
    box-shadow: 0 8px 30px rgba(0,209,122,0.15);
}

.game-card.hidden-card {
    display: none;
}

.card-thumbnail {
    width: 100%;
    overflow: hidden;
}

.thumb-canvas {
    width: 100%;
    height: 170px;
    display: block;
}

.card-info {
    padding: 14px 16px 8px;
}

.card-info h3 {
    font-weight: 700;
    font-size: 16px;
    margin-bottom: 6px;
}

.card-stats {
    font-size: 12px;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.card-tag {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 4px;
    font-size: 12px;
    font-weight: 600;
}

.tag-fighting { background: #ff475720; color: var(--accent-red); }
.tag-roleplay { background: #00a2ff20; color: var(--accent-blue); }
.tag-creation { background: #a855f720; color: var(--accent-purple); }

.play-btn {
    display: block;
    width: calc(100% - 32px);
    margin: 8px 16px 16px;
    padding: 10px;
    background: var(--accent-green);
    color: #000;
    border: none;
    border-radius: 8px;
    font-family: 'Bungee', cursive;
    font-size: 14px;
    letter-spacing: 1px;
    cursor: pointer;
    transition: all 0.2s;
}

.play-btn:hover {
    background: var(--accent-green-hover);
    box-shadow: 0 4px 20px rgba(0,209,122,0.4);
}

/* GAME SCREEN */
#game-screen {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: #000;
}

#game-topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 16px;
    background: var(--nav-bg);
    border-bottom: 1px solid var(--nav-border);
    z-index: 10;
}

#back-btn {
    background: var(--bg-card);
    color: var(--text-primary);
    border: 1px solid var(--nav-border);
    padding: 8px 16px;
    border-radius: 8px;
    cursor: pointer;
    font-family: 'IBM Plex Sans', sans-serif;
    font-weight: 600;
    font-size: 13px;
    transition: all 0.2s;
}

#back-btn:hover {
    background: var(--bg-card-hover);
    border-color: var(--accent-green);
}

#game-hud {
    display: flex;
    gap: 12px;
    align-items: center;
    font-weight: 700;
    font-size: 14px;
    flex-wrap: wrap;
}

.hud-item {
    background: var(--bg-card);
    padding: 6px 14px;
    border-radius: 6px;
    border: 1px solid var(--nav-border);
    white-space: nowrap;
}

.hud-score { color: var(--accent-yellow); }
.hud-timer { color: var(--accent-red); }
.hud-info { color: var(--accent-blue); }
.hud-rocket { color: #ff8c42; }
.hud-health { color: #ff6b9d; }

#game-canvas {
    flex: 1;
    display: block;
    background: #111;
    image-rendering: pixelated;
}

#game-ui-overlay {
    position: absolute;
    bottom: 80px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 20;
    pointer-events: none;
}

/* BUILDER SPECIFIC */
.builder-palette {
    position: fixed;
    left: 10px;
    top: 50%;
    transform: translateY(-50%);
    background: var(--bg-card);
    border: 1px solid var(--nav-border);
    border-radius: 10px;
    padding: 10px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    z-index: 50;
}

.palette-color {
    width: 36px;
    height: 36px;
    border-radius: 6px;
    cursor: pointer;
    border: 2px solid transparent;
    transition: all 0.15s;
}

.palette-color:hover, .palette-color.active {
    border-color: white;
    transform: scale(1.1);
}

.builder-tools {
    position: fixed;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    background: var(--bg-card);
    border: 1px solid var(--nav-border);
    border-radius: 10px;
    padding: 10px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    z-index: 50;
}

.tool-btn {
    width: 42px;
    height: 42px;
    border-radius: 6px;
    border: 2px solid transparent;
    background: var(--bg-secondary);
    color: var(--text-primary);
    cursor: pointer;
    font-size: 18px;
    transition: all 0.15s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.tool-btn:hover, .tool-btn.active {
    border-color: var(--accent-green);
    background: var(--accent-green);
    color: #000;
}

.builder-bottom-bar {
    position: fixed;
    bottom: 10px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 8px;
    z-index: 50;
}

.builder-action-btn {
    padding: 10px 20px;
    border-radius: 8px;
    border: none;
    font-weight: 700;
    font-size: 13px;
    cursor: pointer;
    font-family: 'IBM Plex Sans', sans-serif;
    transition: all 0.2s;
}

.btn-test { background: var(--accent-green); color: #000; }
.btn-save { background: var(--accent-blue); color: #fff; }
.btn-load { background: var(--accent-purple); color: #fff; }
.btn-export { background: var(--accent-yellow); color: #000; }
.btn-clear { background: var(--accent-red); color: #fff; }

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

/* BROOKHAVEN UI */
.brook-ui {
    position: fixed;
    bottom: 80px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 10px;
    z-index: 50;
    flex-wrap: wrap;
    justify-content: center;
}

.brook-btn {
    padding: 8px 16px;
    border-radius: 8px;
    border: 1px solid var(--nav-border);
    background: var(--bg-card);
    color: var(--text-primary);
    cursor: pointer;
    font-weight: 600;
    font-size: 13px;
    transition: all 0.2s;
}

.brook-btn:hover {
    border-color: var(--accent-blue);
    background: var(--bg-card-hover);
}

/* Chat input for Brookhaven */
#chat-input-container {
    position: fixed;
    bottom: 10px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 60;
    display: none;
}

#chat-input {
    padding: 10px 16px;
    width: 300px;
    border-radius: 20px;
    border: 1px solid var(--accent-blue);
    background: var(--bg-card);
    color: var(--text-primary);
    font-size: 14px;
    outline: none;
    font-family: 'IBM Plex Sans', sans-serif;
}

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

#dpad {
    position: relative;
    width: 130px;
    height: 130px;
    pointer-events: auto;
}

.dpad-btn {
    position: absolute;
    width: 44px;
    height: 44px;
    background: rgba(255,255,255,0.15);
    border: 1px solid rgba(255,255,255,0.25);
    border-radius: 8px;
    color: white;
    font-size: 18px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

.dpad-btn:active {
    background: rgba(255,255,255,0.35);
}

.dpad-up { top: 0; left: 43px; }
.dpad-down { bottom: 0; left: 43px; }
.dpad-left { top: 43px; left: 0; }
.dpad-right { top: 43px; right: 0; }

#action-buttons {
    display: flex;
    gap: 10px;
    align-items: flex-end;
    pointer-events: auto;
}

.action-btn {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: rgba(0,209,122,0.3);
    border: 2px solid rgba(0,209,122,0.5);
    color: white;
    font-size: 20px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

.action-btn:active {
    background: rgba(0,209,122,0.6);
}

/* FOOTER */
#app-footer {
    text-align: center;
    padding: 24px;
    color: var(--text-secondary);
    font-size: 13px;
    border-top: 1px solid var(--nav-border);
    background: var(--nav-bg);
}

#app-footer a {
    color: var(--accent-green);
    text-decoration: none;
    font-weight: 600;
    margin-left: 8px;
}

#app-footer a:hover {
    text-decoration: underline;
}

.hidden {
    display: none !important;
}

/* RESPONSIVE */
@media (max-width: 768px) {
    #hero-banner {
        flex-direction: column;
        padding: 20px;
    }
    #hero-visual { display: none; }
    #hero-title { font-size: 22px; }
    #game-grid {
        grid-template-columns: 1fr;
    }
    #profile-sidebar {
        width: 100%;
    }
    .builder-palette, .builder-tools {
        flex-direction: row;
    }
    .builder-palette {
        left: 50%;
        top: auto;
        bottom: 120px;
        transform: translateX(-50%) translateY(0);
    }
    .builder-tools {
        right: 50%;
        top: auto;
        bottom: 60px;
        transform: translateX(50%) translateY(0);
    }
    #game-hud {
        gap: 6px;
        font-size: 11px;
    }
    .hud-item {
        padding: 4px 8px;
        font-size: 11px;
    }
}

@media (min-width: 769px) {
    #mobile-controls {
        display: none !important;
    }
}