:root {
    /* Dark Mode (Default) */
    --bg-color: #050510;
    --card-bg: rgba(10, 10, 31, 0.6);
    --header-bg: rgba(5, 5, 16, 0.6);
    --text-primary: #e0e0e0;
    --text-secondary: #8a8a8a;
    --neon-cyan: #00f3ff;
    --neon-pink: #ff00ff;
    --neon-green: #00ff9d;
    --neon-red: #ff3e3e;
    --border-color: rgba(0, 243, 255, 0.2);
    --ad-bg: rgba(17, 17, 17, 0.5);
    --font-main: 'Rajdhani', sans-serif;
    --font-display: 'Orbitron', sans-serif;
    --hover-bg: rgba(0, 243, 255, 0.1);
    --shadow-color: rgba(0, 243, 255, 0.2);
}

.light-mode {
    /* Light Mode Overrides - Cool Smooth Gradients */
    --bg-color: #f0f2f5;
    --card-bg: rgba(255, 255, 255, 0.6);
    --header-bg: rgba(255, 255, 255, 0.6);
    --text-primary: #1a1a1a;
    --text-secondary: #555555;
    --neon-cyan: #0077b6;
    --neon-pink: #d000d0;
    --neon-green: #008f58;
    --neon-red: #d60000;
    --border-color: rgba(0, 0, 0, 0.1);
    --ad-bg: rgba(224, 224, 224, 0.5);
    --hover-bg: rgba(0, 0, 0, 0.05);
    --shadow-color: rgba(0, 0, 0, 0.1);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    background-color: var(--bg-color);
    color: var(--text-primary);
    font-family: var(--font-main);
    overflow-x: hidden;
    transition: color 0.3s;
    position: relative;
    min-height: 100vh;
}

/* --- New Animated Gradient Background --- */
.bg-gradient-anim {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    z-index: -2;
    background-size: 400% 400%;
    animation: gradientBG 20s ease infinite;
}

/* Dark Mode Gradient - Deep, rich, smooth */
body:not(.light-mode) .bg-gradient-anim {
    background-image: linear-gradient(-45deg, #020024, #0f0c29, #302b63, #24243e, #000000);
}

/* Light Mode Gradient - Soft, airy, premium */
.light-mode .bg-gradient-anim {
    background-image: linear-gradient(-45deg, #e0c3fc, #8ec5fc, #e0c3fc, #cfdef3);
}

@keyframes gradientBG {
    0% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
    100% { background-position: 0% 50%; }
}

/* --- Superfine Grain Effect Overlay (UPDATED) --- */
.bg-grain-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: -1;
    opacity: 0.04; /* Slightly increased opacity for visibility */
    pointer-events: none;
    /* Increased baseFrequency to 3.5 for ultrafine grain */
    background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noiseFilter'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='3.5' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noiseFilter)'/%3E%3C/svg%3E");
}

.light-mode .bg-grain-overlay {
    opacity: 0.06;
    mix-blend-mode: multiply;
}

/* --- Breathing Animation (Enhanced) --- */
@keyframes breathe {
    0% { box-shadow: inset 0 0 80px rgba(0, 243, 255, 0.08); }
    50% { box-shadow: inset 0 0 250px rgba(0, 243, 255, 0.25); }
    100% { box-shadow: inset 0 0 80px rgba(0, 243, 255, 0.08); }
}

@keyframes breathe-light {
    0% { box-shadow: inset 0 0 80px rgba(0, 119, 182, 0.08); }
    50% { box-shadow: inset 0 0 250px rgba(0, 119, 182, 0.2); }
    100% { box-shadow: inset 0 0 80px rgba(0, 119, 182, 0.08); }
}

body {
    animation: breathe 6s infinite ease-in-out; /* Faster cycle for more "alive" feel */
}

.light-mode {
    animation: breathe-light 6s infinite ease-in-out;
}

/* --- Side Banners --- */
.side-banner {
    position: fixed;
    top: 50%;
    transform: translateY(-50%);
    width: 120px;
    height: 60vh;
    background: var(--ad-bg);
    border: 1px dashed var(--text-secondary);
    z-index: 90;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    backdrop-filter: blur(5px);
    transition: all 0.3s;
    overflow: hidden;
}

.side-banner:hover {
    border-color: var(--neon-cyan);
    background: var(--hover-bg);
    box-shadow: 0 0 20px var(--shadow-color);
}

.left-banner { left: 20px; }
.right-banner { right: 20px; }

.ad-content {
    writing-mode: vertical-rl;
    text-orientation: mixed;
    transform: rotate(180deg);
    color: var(--text-secondary);
    font-family: var(--font-display);
    letter-spacing: 4px;
    font-size: 0.9rem;
    display: flex;
    gap: 20px;
    align-items: center;
}

.click-hint {
    font-size: 0.7rem;
    opacity: 0.6;
    color: var(--neon-cyan);
    animation: pulse 2s infinite;
}

@media (max-width: 1600px) {
    .side-banner { display: none; } /* Hide on smaller screens */
}

/* --- Header & Logo --- */
header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px 40px;
    border-bottom: 1px solid var(--border-color);
    background: var(--header-bg);
    backdrop-filter: blur(15px);
    position: sticky;
    top: 0;
    z-index: 100;
    gap: 20px;
    box-shadow: 0 5px 20px var(--shadow-color);
    transition: background 0.3s;
}

.header-left { flex-shrink: 0; }

.logo-container {
    display: flex;
    align-items: center;
    gap: 15px;
}

/* Animated Logo */
.logo-wrapper {
    perspective: 1000px;
}

.logo-tv {
    display: inline-block;
    font-family: var(--font-display);
    font-weight: 900;
    font-size: 2rem;
    color: #fff; /* Always white text on logo */
    background: var(--neon-cyan);
    padding: 2px 12px;
    border-radius: 4px;
    box-shadow: 0 0 20px var(--neon-cyan);
    animation: logoSpin 5s infinite linear;
    transform-style: preserve-3d;
    position: relative;
}

/* Adding a blink effect overlay */
.logo-tv::after {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    background: white;
    opacity: 0;
    animation: logoBlink 3s infinite;
    mix-blend-mode: overlay;
}

@keyframes logoSpin {
    0% { transform: rotateY(0deg); }
    10% { transform: rotateY(360deg); } /* Quick spin */
    100% { transform: rotateY(360deg); } /* Pause */
}

@keyframes logoBlink {
    0%, 90%, 100% { opacity: 0; }
    92%, 96% { opacity: 0.8; }
    94%, 98% { opacity: 0; }
}

.logo-text {
    font-family: var(--font-display);
    font-size: 1.2rem;
    color: var(--text-primary);
    text-transform: uppercase;
    letter-spacing: 4px;
    text-shadow: 0 0 10px var(--shadow-color);
    display: none;
}

@media (min-width: 768px) { .logo-text { display: block; } }

/* Search Bar */
.search-container {
    flex-grow: 1;
    max-width: 600px;
    margin: 0 20px;
}

.search-wrapper { position: relative; width: 100%; }

.search-icon {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-secondary);
}

#searchInput {
    width: 100%;
    background: rgba(0,0,0,0.05);
    border: 1px solid var(--border-color);
    border-radius: 20px;
    padding: 10px 10px 10px 40px;
    color: var(--text-primary);
    font-family: var(--font-main);
    font-size: 1rem;
    outline: none;
    transition: all 0.3s;
}

.light-mode #searchInput {
    background: rgba(255,255,255,0.5);
}

#searchInput:focus {
    border-color: var(--neon-cyan);
    box-shadow: 0 0 15px var(--shadow-color);
    background: var(--card-bg);
}

/* Controls */
.controls {
    display: flex;
    align-items: center;
    gap: 15px;
    flex-shrink: 0;
}

.last-updated {
    font-size: 0.8rem;
    color: var(--neon-cyan);
    font-family: var(--font-display);
    margin-right: 10px;
    display: none;
    text-shadow: 0 0 5px var(--shadow-color);
}

@media (min-width: 1024px) { .last-updated { display: block; } }

.icon-btn {
    background: rgba(0,0,0,0.05);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    padding: 8px 15px; /* Wider for text */
    border-radius: 4px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: all 0.3s;
    font-family: var(--font-display);
    font-size: 0.8rem;
    font-weight: bold;
}

.light-mode .icon-btn {
    background: rgba(255,255,255,0.5);
}

.icon-btn:hover {
    border-color: var(--neon-cyan);
    color: var(--neon-cyan);
    box-shadow: 0 0 15px var(--shadow-color);
    transform: scale(1.05);
}

.moon-icon { display: block; }
.sun-icon { display: none; }
.light-mode .moon-icon { display: none; }
.light-mode .sun-icon { display: block; }

/* View Toggle Button */
.view-toggle-container {
    margin-right: 10px;
}

.active-view {
    background: var(--hover-bg) !important;
    border-color: var(--neon-cyan) !important;
    box-shadow: 0 0 10px var(--shadow-color);
}

/* Layout */
.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 20px;
}

/* Stats Bar */
.stats-bar {
    display: flex;
    justify-content: space-around;
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    padding: 15px;
    margin-bottom: 20px;
    border-radius: 8px;
    box-shadow: 0 0 20px var(--shadow-color);
    backdrop-filter: blur(5px);
    animation: pulseBorder 4s infinite;
}

@keyframes pulseBorder {
    0% { border-color: var(--border-color); }
    50% { border-color: var(--neon-cyan); }
    100% { border-color: var(--border-color); }
}

.stat-item { text-align: center; }
.stat-item .label { font-size: 0.7rem; color: var(--text-secondary); letter-spacing: 1px; }
/* Reduced font size for stats to prevent overflow */
.stat-item .value { font-family: var(--font-display); font-size: 1rem; color: var(--neon-cyan); text-shadow: 0 0 5px var(--shadow-color); }

/* Compact List View */
.list-header {
    display: grid;
    grid-template-columns: 50px 2fr 1.5fr 1fr 1.5fr 1.5fr;
    padding: 15px;
    font-size: 0.8rem;
    color: var(--text-secondary);
    border-bottom: 1px solid var(--border-color);
    font-weight: bold;
    background: rgba(0,0,0,0.05);
    border-radius: 8px 8px 0 0;
}

.light-mode .list-header { background: rgba(238, 238, 255, 0.5); }

.coin-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin-bottom: 20px;
}

.coin-row {
    display: grid;
    grid-template-columns: 50px 2fr 1.5fr 1fr 1.5fr 1.5fr;
    align-items: center;
    background: var(--card-bg);
    padding: 12px 15px;
    border-bottom: 1px solid var(--border-color);
    cursor: pointer;
    transition: all 0.2s;
    backdrop-filter: blur(5px);
}

.coin-row:hover {
    background: var(--hover-bg);
    transform: translateX(5px);
    border-left: 2px solid var(--neon-cyan);
}

.coin-info { display: flex; align-items: center; gap: 12px; }
.coin-icon-sm { width: 28px; height: 28px; border-radius: 50%; }
.coin-symbol { font-size: 0.8rem; color: var(--text-secondary); }
.row-price { font-family: var(--font-display); font-size: 0.95rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-change { font-size: 0.9rem; font-weight: bold; }
.row-mcap { font-size: 0.9rem; color: var(--text-secondary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-chart { height: 35px; width: 100%; }

.positive { color: var(--neon-green); text-shadow: 0 0 5px rgba(0, 255, 157, 0.3); }
.negative { color: var(--neon-red); text-shadow: 0 0 5px rgba(255, 62, 62, 0.3); }

/* Bubble View */
.bubble-view-container {
    width: 100%;
    height: 80vh;
    position: relative;
    background: transparent; /* Let body bg show through */
    border: 1px solid var(--border-color);
    border-radius: 8px;
    overflow: hidden;
    margin-bottom: 20px;
    box-shadow: inset 0 0 50px var(--shadow-color);
}

#bubbleCanvasWrapper {
    width: 100%;
    height: 100%;
}

.bubble-instructions {
    position: absolute;
    bottom: 10px;
    left: 50%;
    transform: translateX(-50%);
    color: var(--text-secondary);
    font-family: var(--font-display);
    font-size: 0.8rem;
    pointer-events: none;
    background: var(--card-bg);
    padding: 5px 15px;
    border-radius: 20px;
    border: 1px solid var(--border-color);
    box-shadow: 0 5px 15px rgba(0,0,0,0.2);
}

/* Load More */
.load-more-container { display: flex; justify-content: center; margin: 20px 0; }

.cyber-btn-sm {
    background: transparent;
    border: 1px solid var(--neon-cyan);
    color: var(--neon-cyan);
    padding: 8px 20px;
    font-family: var(--font-display);
    font-size: 0.8rem;
    cursor: pointer;
    transition: all 0.3s;
    display: flex;
    align-items: center;
    gap: 8px;
    text-transform: uppercase;
}

.cyber-btn-sm:hover {
    background: var(--neon-cyan);
    color: #fff;
    box-shadow: 0 0 20px var(--neon-cyan);
}

/* Ads */
.ad-container { display: flex; justify-content: center; margin: 20px 0; cursor: pointer; }
.mid-content-ads { display: flex; justify-content: center; gap: 20px; flex-wrap: wrap; margin: 40px 0; }

.ad-slot {
    background: var(--ad-bg);
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px dashed var(--text-secondary);
    color: var(--text-secondary);
    font-family: var(--font-display);
    letter-spacing: 2px;
    position: relative;
    overflow: hidden;
    backdrop-filter: blur(5px);
    transition: all 0.3s;
}

.ad-slot:hover {
    border-color: var(--neon-cyan);
    box-shadow: 0 0 15px var(--shadow-color);
    background: var(--hover-bg);
}

.ad-leaderboard { width: 728px; height: 90px; }
.ad-rect { width: 300px; height: 250px; }
.ad-label { opacity: 0.5; animation: pulse 2s infinite; }

@keyframes pulse {
    0% { opacity: 0.3; }
    50% { opacity: 0.7; }
    100% { opacity: 0.3; }
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.85);
    backdrop-filter: blur(8px);
    z-index: 1000;
    justify-content: center;
    align-items: center;
}

.light-mode .modal {
    background: rgba(255,255,255,0.85);
}

.modal-content {
    background: var(--bg-color);
    width: 90%;
    max-width: 1000px;
    max-height: 90vh;
    overflow-y: auto;
    padding: 30px;
    border: 1px solid var(--neon-cyan);
    box-shadow: 0 0 50px var(--shadow-color);
    position: relative;
    border-radius: 8px;
}

.small-modal {
    max-width: 500px;
    max-height: 400px;
}

.contact-box {
    background: var(--card-bg);
    padding: 20px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    margin-top: 20px;
}

.close-modal {
    position: absolute;
    top: 20px; right: 20px;
    font-size: 2rem;
    color: var(--text-secondary);
    cursor: pointer;
    transition: color 0.3s;
    z-index: 10;
}

.close-modal:hover { color: var(--neon-red); text-shadow: 0 0 10px var(--neon-red); }

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    margin-bottom: 20px;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 20px;
}

.coin-identity { display: flex; align-items: center; gap: 20px; }
.coin-icon-lg { width: 64px; height: 64px; filter: drop-shadow(0 0 10px var(--shadow-color)); }

.coin-price-large { text-align: right; }
#modalPrice {
    display: block;
    /* Responsive font size to prevent overflow */
    font-size: clamp(2rem, 4vw, 3.5rem);
    font-family: var(--font-display);
    color: var(--text-primary);
    text-shadow: 0 0 15px var(--shadow-color);
}

/* Chart Tabs */
.chart-tabs {
    display: flex;
    gap: 10px;
    margin-bottom: 15px;
}

.tab-btn {
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    padding: 10px 20px;
    font-family: var(--font-display);
    cursor: pointer;
    border-radius: 4px;
    transition: all 0.3s;
    flex: 1;
}

.tab-btn.active {
    background: var(--neon-cyan);
    color: #000;
    border-color: var(--neon-cyan);
    box-shadow: 0 0 15px var(--shadow-color);
    font-weight: bold;
}

.tab-btn:hover:not(.active) {
    border-color: var(--neon-cyan);
    color: var(--neon-cyan);
}

.chart-container {
    height: 500px; /* Increased height for better TV chart */
    margin-bottom: 30px;
    background: rgba(128,128,128,0.05);
    padding: 5px;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    position: relative;
}

.chart-view {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
}

#tradingviewContainer {
    width: 100%;
    height: 100%;
}

#tradingview_widget {
    width: 100%;
    height: 100%;
}

.metrics-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 20px;
    margin-bottom: 30px;
}

.metric-card {
    background: var(--card-bg);
    padding: 15px;
    border-left: 3px solid var(--neon-pink);
    box-shadow: 0 5px 15px var(--shadow-color);
}

.metric-card h4 { color: var(--text-secondary); font-size: 0.8rem; margin-bottom: 5px; }
.metric-card p { font-family: var(--font-display); font-size: 0.85rem; color: var(--text-primary); }

.analysis-section {
    background: var(--hover-bg);
    padding: 20px;
    border-radius: 4px;
    border: 1px solid var(--border-color);
    box-shadow: inset 0 0 20px var(--shadow-color);
}

.typing-text {
    font-family: 'Courier New', monospace;
    color: var(--neon-cyan);
    line-height: 1.6;
    text-shadow: 0 0 3px var(--neon-cyan);
}

/* Footer */
footer {
    text-align: center;
    padding: 40px 0;
    color: var(--text-secondary);
    font-size: 0.8rem;
    border-top: 1px solid var(--border-color);
    margin-top: 40px;
    background: var(--header-bg);
}

/* --- Responsive Design (Mobile Improvements) --- */
@media (max-width: 768px) {
    /* Header Layout: Stacked for better mobile experience */
    header {
        flex-direction: column;
        padding: 15px;
        gap: 15px;
        position: sticky;
        height: auto;
    }

    .header-left {
        width: 100%;
        display: flex;
        justify-content: center;
        margin-bottom: 5px;
    }

    .logo-text {
        display: block; /* Show logo text on mobile now */
        font-size: 1.2rem;
    }

    .search-container {
        width: 100%;
        max-width: 100%;
        margin: 0;
        order: 3; /* Move search to bottom of header */
    }

    .controls {
        width: 100%;
        justify-content: space-between;
        gap: 10px;
        order: 2;
    }

    .icon-btn {
        flex: 1; /* Distribute space evenly */
        padding: 10px;
        justify-content: center;
    }
    
    .icon-btn span {
        display: none; /* Keep text hidden on mobile buttons */
    }

    /* Stats Bar */
    .stats-bar {
        padding: 10px;
        gap: 5px;
    }
    
    .stat-item .label { font-size: 0.6rem; }
    .stat-item .value { font-size: 0.9rem; }

    /* List View */
    .list-header, .coin-row {
        grid-template-columns: 40px 2fr 1.5fr 1fr; /* Removed chart/mcap cols */
        padding: 10px;
        gap: 5px;
    }
    
    .col-mcap, .row-mcap, .col-chart, .row-chart { display: none; }
    
    .coin-icon-sm { width: 24px; height: 24px; }
    .coin-symbol { font-size: 0.7rem; }
    .row-price { font-size: 0.85rem; }

    /* Bubble View */
    .bubble-view-container {
        height: 65vh; /* Slightly taller */
        border-radius: 0;
        border-left: none;
        border-right: none;
    }

    .bubble-instructions {
        width: 90%;
        text-align: center;
        font-size: 0.7rem;
        bottom: 20px;
    }

    /* Modal Mobile */
    .modal-content {
        width: 100%;
        height: 100%;
        max-height: 100vh;
        border-radius: 0;
        padding: 20px;
    }

    .modal-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 15px;
    }

    .coin-price-large { text-align: left; }
    #modalPrice { font-size: 2.5rem; }

    .chart-container {
        height: 350px; /* Shorter chart on mobile */
        padding: 5px;
    }

    .metrics-grid {
        grid-template-columns: 1fr 1fr; /* 2 columns */
        gap: 10px;
    }

    .metric-card {
        padding: 10px;
    }
    
    .metric-card p { font-size: 1rem; }

    /* Ads */
    .ad-leaderboard { width: 100%; height: auto; min-height: 50px; }
    .ad-rect { width: 100%; max-width: 300px; }
}