:root {
    --font-pixel: 'Press Start 2P', monospace;

    /* Backgrounds - darker, more cinematic */
    --bg-darkest: #0c0a08;
    --bg-dark: #1a1614;
    --bg-mid: #28201a;
    --bg-surface: #322820;
    --bg-raised: #3e3228;

    /* Borders - subtle, clean */
    --border-dark: #3a3028;
    --border-mid: #504030;
    --border-light: #685840;
    --border-highlight: #806848;

    /* Text */
    --text-bright: #f0e4d0;
    --text-main: #d0c4a8;
    --text-dim: #a89070;
    --text-muted: #8a7860;

    /* Game colors */
    --green: #68a858;
    --green-dark: #3a6830;
    --green-light: #98d870;
    --red: #a84838;
    --red-light: #d86878;
    --gold: #d0a030;
    --gold-light: #e8c040;
    --gold-dark: #8a6820;
    --red-dark: #702828;
    --blue: #4070a0;
    --purple: #7050a0;

    /* Rarity colors */
    --rarity-common: #8a7860;
    --rarity-uncommon: #68a858;
    --rarity-rare: #4070a0;
    --rarity-epic: #7050a0;
    --rarity-legendary: #d0a030;

    --spacing-xs: 6px;
    --spacing-sm: 10px;
    --spacing-md: 18px;
    --spacing-lg: 28px;
    --spacing-xl: 36px;

    --safe-top: env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --safe-left: env(safe-area-inset-left, 0px);
    --safe-right: env(safe-area-inset-right, 0px);

    --top-bar-height: 52px;
    --bottom-nav-height: 64px;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

html, body {
    height: 100%;
    overflow: hidden;
    font-family: var(--font-pixel);
    background: var(--bg-darkest);
    color: var(--text-main);
    font-size: 12px;
    line-height: 1.8;
    image-rendering: pixelated;
}

#app {
    display: flex;
    flex-direction: column;
    height: 100%;
    width: 100%;
    padding: 0;
    margin: 0 auto;
}

/* --- Competition mode: hide chrome --- */
body.competition-active #top-bar,
body.competition-active #bottom-nav {
    display: none;
}

/* ==========================================================================
   TOP BAR -- Game HUD header
   ========================================================================== */

#top-bar {
    display: flex;
    align-items: stretch;
    height: var(--top-bar-height);
    padding-top: var(--safe-top);
    background: var(--bg-surface);
    border-bottom: 2px solid var(--border-highlight);
    flex-shrink: 0;
    box-shadow:
        0 2px 0 var(--border-dark),
        0 4px 16px rgba(0,0,0,0.5),
        inset 0 1px 0 rgba(255,220,140,0.06);
    position: relative;
    z-index: 10;
}

#top-bar::after {
    content: '';
    position: absolute;
    bottom: -4px;
    left: 0;
    right: 0;
    height: 2px;
    background: linear-gradient(90deg, transparent, rgba(208,160,48,0.12) 20%, rgba(208,160,48,0.12) 80%, transparent);
}

/* --- Left: profile touch target --- */

.top-bar-profile {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
    padding: 0 var(--spacing-sm);
    background: none;
    border: none;
    border-right: 1px solid var(--border-dark);
    cursor: pointer;
    transition: background 0.15s;
    flex-shrink: 0;
}

/* --- Right: status indicators --- */

.top-bar-right {
    display: flex;
    align-items: stretch;
    flex: 1;
    justify-content: flex-end;
}

.currency {
    display: inline-flex;
    align-items: center;
    font-family: var(--font-pixel);
    font-size: 10px;
    color: var(--gold-light);
    background: rgba(208,160,48,0.06);
    padding: 0 10px;
    border-left: 1px solid var(--border-dark);
}

.top-bar-water {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-family: var(--font-pixel);
    font-size: 10px;
    color: #6bb5ff;
    background: rgba(60,120,180,0.08);
    padding: 0 10px;
    cursor: pointer;
    border-left: 1px solid var(--border-dark);
    animation: water-pulse 2s ease-in-out infinite;
}

.top-bar-water:active {
    background: rgba(60,120,180,0.2);
}

.top-bar-water.hidden { display: none; }

.top-bar-water-icon {
    display: inline-flex;
    color: #6bb5ff;
}

.top-bar-water-icon svg {
    width: 14px;
    height: 14px;
}

@keyframes water-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.7; }
}

.top-bar-profile:hover {
    background: rgba(208,160,48,0.06);
}

.top-bar-profile:active {
    background: rgba(208,160,48,0.12);
}

.top-bar-profile-avatar {
    width: 36px;
    height: 36px;
    border: 2px solid var(--border-mid);
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-mid);
    flex-shrink: 0;
    image-rendering: pixelated;
}

.top-bar-profile-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    image-rendering: auto;
}

.top-bar-profile-avatar svg {
    width: 20px;
    height: 20px;
    color: var(--text-muted);
}

.top-bar-profile-info {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 2px;
    min-width: 0;
}

.top-bar-profile-name {
    font-family: var(--font-pixel);
    font-size: 10px;
    color: var(--text-bright);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 120px;
    line-height: 1;
}

.top-bar-profile-rating {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    font-family: var(--font-pixel);
    font-size: 8px;
    color: var(--gold);
    line-height: 1;
}

.top-bar-profile-rating svg {
    width: 10px;
    height: 10px;
}

.top-bar-profile-rating:empty { display: none; }

/* --- Far right: notifications bell --- */

.top-bar-notifications {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 var(--spacing-sm);
    background: none;
    border: none;
    border-left: 1px solid var(--border-dark);
    cursor: pointer;
    transition: background 0.15s;
    position: relative;
    flex-shrink: 0;
}

.top-bar-notifications:hover {
    background: rgba(208,160,48,0.06);
}

.top-bar-notifications:active {
    background: rgba(208,160,48,0.12);
}

.top-bar-notifications-icon {
    display: inline-flex;
    color: var(--text-dim);
    transition: color 0.15s;
    pointer-events: none;
}

.top-bar-notifications:hover .top-bar-notifications-icon {
    color: var(--text-main);
}

.top-bar-notifications-icon svg {
    width: 18px;
    height: 18px;
}

.top-bar-notifications-badge {
    position: absolute;
    top: 6px;
    right: 6px;
    min-width: 14px;
    height: 14px;
    padding: 0 3px;
    background: var(--red);
    color: var(--text-bright);
    font-family: var(--font-pixel);
    font-size: 6px;
    line-height: 14px;
    text-align: center;
    border: 1px solid var(--bg-surface);
    pointer-events: none;
}

.top-bar-notifications-badge.hidden { display: none; }

/* ==========================================================================
   SCREEN CONTAINER -- Textured game background
   ========================================================================== */

#screen-container {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    padding: 0 12px;
    background:
        repeating-linear-gradient(
            0deg,
            transparent,
            transparent 3px,
            rgba(255,255,255,0.008) 3px,
            rgba(255,255,255,0.008) 4px
        ),
        repeating-linear-gradient(
            90deg,
            transparent,
            transparent 3px,
            rgba(255,255,255,0.005) 3px,
            rgba(255,255,255,0.005) 4px
        ),
        radial-gradient(ellipse at 50% 0%, rgba(60,48,30,0.15) 0%, transparent 60%),
        var(--bg-darkest);
    position: relative;
}

#screen-container::before {
    content: '';
    position: sticky;
    top: 0;
    left: 0;
    right: 0;
    height: 0;
    display: block;
    box-shadow: 0 0 40px 20px rgba(0,0,0,0.4);
    z-index: 1;
    pointer-events: none;
}

#screen-container::-webkit-scrollbar { width: 6px; }
#screen-container::-webkit-scrollbar-track { background: var(--bg-darkest); }
#screen-container::-webkit-scrollbar-thumb {
    background: var(--border-mid);
    border: 1px solid var(--border-dark);
}

/* ==========================================================================
   BOTTOM NAV -- Game-style navigation panel
   ========================================================================== */

#bottom-nav {
    display: flex;
    align-items: center;
    justify-content: space-around;
    height: var(--bottom-nav-height);
    padding-bottom: var(--safe-bottom);
    background:
        linear-gradient(0deg, rgba(30,24,16,0.9) 0%, rgba(50,40,32,0.95) 40%, var(--bg-surface) 100%);
    border-top: 2px solid var(--border-highlight);
    flex-shrink: 0;
    box-shadow:
        0 -2px 0 var(--border-dark),
        0 -6px 20px rgba(0,0,0,0.5),
        inset 0 1px 0 rgba(255,220,140,0.06);
    position: relative;
    z-index: 10;
}

#bottom-nav::before {
    content: '';
    position: absolute;
    top: -4px;
    left: 0;
    right: 0;
    height: 2px;
    background: linear-gradient(90deg, transparent, rgba(208,160,48,0.12) 20%, rgba(208,160,48,0.12) 80%, transparent);
}

.nav-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    font-family: var(--font-pixel);
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 8px;
    cursor: pointer;
    padding: 8px 12px;
    min-width: 56px;
    min-height: 44px;
    transition: color 0.2s, transform 0.1s;
    position: relative;
}

.nav-btn:hover {
    color: var(--text-dim);
}

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

.nav-btn.active {
    color: var(--green-light);
}

.nav-btn.active::before {
    content: '';
    position: absolute;
    top: -2px;
    left: 50%;
    transform: translateX(-50%);
    width: 32px;
    height: 3px;
    background: var(--green);
    box-shadow: 0 0 8px rgba(104,168,88,0.5), 0 0 16px rgba(104,168,88,0.2);
}

.nav-btn.active .nav-icon {
    filter: drop-shadow(0 0 4px rgba(152,216,112,0.4));
}

.nav-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    transition: filter 0.2s;
}

.nav-icon svg { width: 100%; height: 100%; }


.nav-label {
    font-family: var(--font-pixel);
    font-size: 7px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* ==========================================================================
   GLOBAL DECORATIVE UTILITIES
   ========================================================================== */

/* Ornate panel -- used as a wrapper for major content sections */
.panel {
    background:
        linear-gradient(180deg, rgba(60,48,30,0.12) 0%, transparent 30%, transparent 70%, rgba(0,0,0,0.1) 100%),
        var(--bg-surface);
    border: 2px solid var(--border-mid);
    box-shadow:
        0 2px 8px rgba(0,0,0,0.3),
        inset 0 1px 0 rgba(255,220,140,0.04),
        inset 0 -1px 0 rgba(0,0,0,0.2);
    position: relative;
}

.panel::before {
    content: '';
    position: absolute;
    inset: 3px;
    border: 1px solid rgba(255,220,140,0.03);
    pointer-events: none;
}

/* Decorative divider */
.divider {
    height: 1px;
    background: linear-gradient(90deg, transparent, var(--border-mid) 20%, var(--border-mid) 80%, transparent);
    margin: var(--spacing-md) 0;
    position: relative;
}

.divider::after {
    content: '';
    position: absolute;
    top: -1px;
    left: 50%;
    transform: translateX(-50%);
    width: 8px;
    height: 3px;
    background: var(--gold-dark);
}

/* Shimmer animation for rare/special elements */
@keyframes shimmer {
    0%, 100% { opacity: 0; }
    50% { opacity: 1; }
}

@keyframes glow-pulse {
    0%, 100% { box-shadow: 0 0 4px rgba(208,160,48,0.1); }
    50% { box-shadow: 0 0 12px rgba(208,160,48,0.25); }
}

@keyframes subtle-float {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-2px); }
}

/* Screen title with decorative underline and corner accents */
.screen-title {
    font-family: var(--font-pixel);
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 2px;
    color: var(--text-bright);
    display: inline-block;
    padding-bottom: var(--spacing-xs);
    margin-bottom: var(--spacing-md);
    position: relative;
}

.screen-title::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 2px;
    background: linear-gradient(90deg, var(--gold), var(--gold-dark) 60%, transparent);
}

.screen-title::before {
    content: '';
    position: absolute;
    bottom: -2px;
    left: 0;
    width: 6px;
    height: 6px;
    background: var(--gold);
    box-shadow: 0 0 4px rgba(208,160,48,0.4);
}

/* --- Auth Form --- */
.auth-form {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-md);
    max-width: 320px;
    margin: var(--spacing-xl) auto;
    padding: var(--spacing-lg);
    background:
        linear-gradient(180deg, rgba(60,48,30,0.1) 0%, transparent 40%),
        var(--bg-surface);
    border: 2px solid var(--border-mid);
    box-shadow: 0 4px 16px rgba(0,0,0,0.3), inset 0 1px 0 rgba(255,220,140,0.04);
}

.auth-input {
    width: 100%;
    padding: var(--spacing-sm) var(--spacing-md);
    background: var(--bg-dark);
    border: 2px solid var(--border-dark);
    color: var(--text-bright);
    font-family: var(--font-pixel);
    font-size: 10px;
    min-height: 44px;
    line-height: 1.8;
    box-shadow: inset 0 2px 4px rgba(0,0,0,0.3);
}

.auth-input:focus {
    outline: none;
    border-color: var(--green);
    box-shadow: inset 0 2px 4px rgba(0,0,0,0.3), 0 0 8px rgba(104,168,88,0.2);
}

.auth-forgot-link {
    display: block;
    font-family: var(--font-pixel);
    font-size: 8px;
    color: var(--text-muted);
    background: none;
    border: none;
    cursor: pointer;
    text-align: center;
    padding: 6px 0;
    margin: var(--spacing-xs) auto 0;
    transition: color 0.15s;
    letter-spacing: 0.3px;
}

.auth-forgot-link:hover {
    color: var(--text-dim);
}

.auth-hint {
    font-family: var(--font-pixel);
    font-size: 9px;
    color: var(--text-dim);
    text-align: center;
    line-height: 2;
}

/* --- Empty state / loading --- */
.empty-state {
    text-align: center;
    padding: var(--spacing-xl) var(--spacing-md);
    color: var(--text-muted);
    background: var(--bg-dark);
    border: 1px dashed var(--border-dark);
    position: relative;
}

.empty-state::before {
    content: '';
    position: absolute;
    inset: 4px;
    border: 1px solid rgba(255,255,255,0.015);
    pointer-events: none;
}

.empty-state-icon {
    width: 64px;
    height: 64px;
    margin: 0 auto var(--spacing-md);
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255,255,255,0.02);
    border: 1px solid var(--border-dark);
    border-radius: 2px;
}

.loading-spinner {
    display: inline-block;
    width: 16px;
    height: 16px;
    background: var(--green);
    animation: retro-spin 1s steps(8) infinite;
    box-shadow: 0 0 8px rgba(104,168,88,0.3);
}

@keyframes retro-spin {
    to { transform: rotate(360deg); }
}

/* --- Section headers --- */
.section-header {
    font-family: var(--font-pixel);
    font-size: 12px;
    color: var(--gold);
    text-transform: uppercase;
    letter-spacing: 2px;
    margin-bottom: var(--spacing-sm);
    text-shadow: 0 0 6px rgba(208,160,48,0.2);
}

.text-muted {
    color: var(--text-muted);
    font-size: 10px;
}

/* --- Grids --- */
.grid {
    display: grid;
    gap: var(--spacing-sm);
}

.grid-1 { grid-template-columns: 1fr; }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
