* {
    box-sizing: border-box;
}

:root {
    --bg-color: #0d1117;
    --card-bg: rgba(22, 27, 34, 0.7);
    --accent-color: #58a6ff;
    --accent-glow: rgba(88, 166, 255, 0.3);
    --text-color: #c9d1d9;
    --text-dim: #8b949e;
    --glass-border: rgba(255, 255, 255, 0.1);
    --grad-primary: linear-gradient(135deg, #1f6feb 0%, #58a6ff 100%);
    --up-color: #26a69a;
    --down-color: #ef5350;
}

html {
    height: auto;
    overflow-y: auto;
}

body {
    margin: 0;
    padding: 0;
    font-family: 'Outfit', 'Inter', sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    line-height: 1.6;
    overflow-x: hidden;
    min-height: 100vh;
}

/* Dashboard mode forces a fixed viewport on desktop */
.dashboard-mode,
.dashboard-mode html {
    height: 100vh !important;
    overflow: hidden !important;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 2rem;
}

.glass-card {
    background: var(--card-bg);
    backdrop-filter: blur(10px);
    border: 1px solid var(--glass-border);
    border-radius: 16px;
    padding: 2rem;
    box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.37);
}

h1,
h2,
h3 {
    color: #fff;
    margin-top: 0;
}

.hero {
    text-align: center;
    padding: 6rem 1rem;
    background: radial-gradient(circle at top, var(--accent-glow) 0%, transparent 70%);
}

.hero h1 {
    font-size: 4rem;
    font-weight: 800;
    margin-bottom: 1.5rem;
    background: var(--grad-primary);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    letter-spacing: -2px;
}

.hero p {
    font-size: 1.25rem;
    color: var(--text-dim);
    max-width: 600px;
    margin: 0 auto 3rem;
}

.btn {
    display: inline-block;
    padding: 1rem 2.5rem;
    border-radius: 50px;
    font-weight: 600;
    text-decoration: none;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    cursor: pointer;
    border: none;
}

.btn-primary {
    background: var(--grad-primary);
    color: white;
    box-shadow: 0 4px 15px var(--accent-glow);
}

.btn-primary:hover {
    transform: translateY(-3px);
    box-shadow: 0 8px 25px var(--accent-glow);
}

.stock-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 1.5rem;
    margin-top: 2rem;
}

.stock-card {
    background: var(--card-bg);
    border: 1px solid var(--glass-border);
    border-radius: 12px;
    padding: 1.5rem;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s ease;
    text-decoration: none;
    color: inherit;
}

.stock-card:hover {
    border-color: var(--accent-color);
    background: rgba(88, 166, 255, 0.05);
    transform: scale(1.02);
}

.stock-card .symbol {
    font-size: 1.5rem;
    font-weight: 700;
    display: block;
    margin-bottom: 0.5rem;
}

#chart-container {
    height: 100%;
    width: 100%;
    min-height: 0;
}

.layout-wrapper {
    display: flex;
    flex-direction: column;
    height: 100vh;
    padding: 0.5rem;
    box-sizing: border-box;
    gap: 0.5rem;
    overflow: hidden;
}

.layout-wrapper.scrollable {
    display: block;
    height: auto;
    min-height: 100vh;
    overflow: visible;
}

.flex-fill {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
}

/* Game Dashboard Header */
.game-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1.5rem;
    padding: 1rem 1.5rem;
    margin-bottom: 0.5rem;
}

.stat-group {
    display: flex;
    gap: 2rem;
    align-items: center;
    flex: 1;
    justify-content: center;
}

.stat-item {
    display: flex;
    flex-direction: column;
}

.stat-label {
    font-size: 0.75rem;
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.stat-value {
    font-size: 1.25rem;
    font-weight: 700;
    color: #fff;
}

.stat-value.up {
    color: var(--up-color);
}

.stat-value.down {
    color: var(--down-color);
}

.agent-stat {
    font-size: 0.65rem;
    color: var(--text-dim);
    font-weight: 600;
    margin-top: 1px;
    letter-spacing: 0.02em;
    display: block;
}

.agent-stat.up {
    color: var(--up-color);
    opacity: 0.9;
}

.agent-stat.down {
    color: var(--down-color);
    opacity: 0.9;
}

/* Game Controls Overlay */
.side-controls {
    margin-top: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.side-controls .btn-game {
    width: 100%;
    margin: 0;
    padding: 0.75rem;
    font-size: 0.85rem;
    border-radius: 8px;
}

.side-controls .btn-next {
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
}

.control-row {
    display: flex;
    gap: 0.75rem;
}

.control-row .btn-game {
    flex: 1;
}

.btn-game {
    padding: 0.75rem 2rem;
    border-radius: 100px;
    font-weight: 700;
    font-size: 1rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    border: none;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.btn-buy {
    background: var(--up-color);
    color: white;
    box-shadow: 0 4px 15px rgba(38, 166, 154, 0.3);
}

.btn-buy:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(38, 166, 154, 0.5);
}

.btn-sell {
    background: var(--down-color);
    color: white;
    box-shadow: 0 4px 15px rgba(239, 83, 80, 0.3);
}

.btn-sell:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(239, 83, 80, 0.5);
}

.btn-next {
    background: #30363d;
    color: #fff;
    border: 1px solid #484f58;
}

.btn-next:hover:not(:disabled) {
    background: #3d444d;
    transform: scale(1.05);
}

.btn-game:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    transform: none !important;
}

.main-content {
    display: flex;
    flex: 1;
    gap: 0.5rem;
    min-height: 0;
}

/* Sidebar Panels */
.side-panel {
    display: flex;
    flex-direction: column;
    width: 320px;
    flex-shrink: 0;
    gap: 0.5rem;
    min-height: 0;
    /* Enable shrinking/scrolling children */
}

.card-title {
    font-size: 0.8rem;
    font-weight: 700;
    margin-bottom: 1rem;
    color: var(--text-dim);
    display: flex;
    justify-content: space-between;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.position-card {
    flex: 0 0 auto;
    padding: 1rem;
    background: rgba(22, 27, 34, 0.4);
}

.pos-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

.pos-item {
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
}

.pos-label {
    font-size: 0.7rem;
    color: var(--text-dim);
}

.pos-value {
    font-size: 1rem;
    font-weight: 600;
    color: #fff;
}

.pos-value.up {
    color: var(--up-color);
}

.pos-value.down {
    color: var(--down-color);
}

.val-badge {
    padding: 0.2rem 0.5rem;
    border-radius: 4px;
    font-size: 0.7rem;
    font-weight: 800;
    color: white !important;
}

.val-badge.up {
    background: var(--up-color);
}

.val-badge.down {
    background: var(--down-color);
}

.history-card {
    flex: 1.5;
    /* Slightly less than before to give chart more room if needed */
    display: flex;
    flex-direction: column;
    min-height: 0;
    /* CRITICAL: enable shrinking below content height */
    padding: 1rem;
}

.history-list {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    padding-right: 5px;
    /* Removed mask-image to prevent scroll interaction issues */
}

.history-item {
    background: rgba(255, 255, 255, 0.03);
    border-radius: 8px;
    padding: 0.75rem;
    font-size: 0.85rem;
    border-left: 3px solid transparent;
}

.history-item.win {
    border-left-color: var(--up-color);
}

.history-item.loss {
    border-left-color: var(--down-color);
}

.history-row {
    display: flex;
    justify-content: space-between;
    margin-bottom: 0.25rem;
}

.history-date {
    font-size: 0.75rem;
    color: var(--text-dim);
}

.history-pnl {
    font-weight: 700;
}

/* Custom Scrollbar */
.history-list::-webkit-scrollbar {
    width: 4px;
}

.history-list::-webkit-scrollbar-track {
    background: transparent;
}

.history-list::-webkit-scrollbar-thumb {
    background: #30363d;
    border-radius: 10px;
}

/* Tabs Implementation */
.tab-container {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1rem;
    border-bottom: 1px solid var(--glass-border);
}

.tab {
    padding: 0.5rem 1rem;
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--text-dim);
    cursor: pointer;
    text-transform: uppercase;
    transition: all 0.2s ease;
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
}

.tab:hover {
    color: #fff;
}

.tab.active {
    color: var(--accent-color);
    border-bottom-color: var(--accent-color);
}

.tab-badge {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-dim);
    padding: 2px 6px;
    border-radius: 10px;
    font-size: 0.65rem;
    margin-left: 4px;
    transition: all 0.2s ease;
}

.tab.active .tab-badge {
    background: var(--accent-color);
    color: white;
}

.tab-content {
    display: none;
    flex: 1;
    min-height: 0;
    flex-direction: column;
}

.tab-content.active {
    display: flex;
}

/* Animations */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(20px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.animate-fade {
    animation: fadeIn 0.8s ease-out forwards;
}

/* Mobile Responsiveness */
@media (max-width: 768px) {

    /* Global layout overrides for mobile (allow vertical scrolling) */
    html,
    body,
    body.dashboard-mode,
    body.dashboard-mode html {
        height: auto !important;
        overflow: visible !important;
    }

    .layout-wrapper {
        height: auto !important;
        overflow: visible !important;
        display: flex !important;
        flex-direction: column !important;
        padding: 0.5rem;
    }

    .layout-wrapper.scrollable {
        display: block !important;
    }

    /* Rules for all headers on mobile */
    .game-header {
        flex-direction: column !important;
        align-items: center !important;
        gap: 1rem !important;
        text-align: center !important;
        padding: 1rem !important;
    }

    .game-header>div {
        justify-content: center !important;
    }

    /* Simulation Chart specific responsive behavior */
    .stat-group {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 0.75rem;
        width: 100%;
        text-align: left;
    }

    .stat-item {
        background: rgba(255, 255, 255, 0.03);
        padding: 0.5rem 0.75rem;
        border-radius: 8px;
        border: 1px solid rgba(255, 255, 255, 0.05);
    }

    .stat-value {
        font-size: 1.1rem !important;
    }

    .stat-label {
        font-size: 0.6rem !important;
        opacity: 0.6;
    }

    .main-content {
        flex-direction: column;
        height: auto;
        min-height: 0;
        flex: 1;
    }

    .main-content.flex-fill {
        height: auto;
        flex: 1;
        display: flex;
        flex-direction: column;
    }

    #chart-container {
        height: 400px;
        /* Fixed height for chart visibility on mobile */
        flex: none;
    }

    .side-panel {
        width: 100%;
        height: auto;
        border-left: none;
        border-top: 1px solid var(--glass-border);
        flex: none;
        display: flex;
        flex-direction: column;
    }

    .history-card {
        flex: none;
        height: auto;
    }

    .history-list {
        height: 400px;
        overflow-y: auto;
        mask-image: none;
    }

    /* General Mobile Padding */
    .hero h1 {
        font-size: 2.5rem;
    }

    .container {
        padding: 1rem;
    }

    .glass-card {
        padding: 1rem;
    }
}

@media (max-width: 480px) {
    .stat-group {
        grid-template-columns: 1fr;
    }

    .game-header {
        text-align: center;
        align-items: center;
    }

    .side-controls .control-row {
        flex-direction: column;
    }
}

/* Global Color Status Overrides */
.up,
.stat-value.up,
.agent-stat.up {
    color: var(--up-color) !important;
}

.down,
.stat-value.down,
.agent-stat.down {
    color: var(--down-color) !important;
}