/* ================================================================
   TWITCH TRACKER — Terminal Aesthetic
   Dark, monospace, minimal. Data-first.
   ================================================================ */

:root {
    --bg:          #0a0a0a;
    --bg-surface:  #111111;
    --bg-elevated: #1a1a1a;
    --bg-hover:    #1e1e1e;
    --border:      #2a2a2a;
    --border-light:#333333;

    --text:        #b0b0b0;
    --text-bright: #e0e0e0;
    --text-muted:  #555555;
    --text-dim:    #3a3a3a;

    --green:       #00ff41;
    --green-dim:   #00aa2a;
    --red:         #ff3333;
    --red-dim:     #aa2222;
    --cyan:        #00d4ff;
    --cyan-dim:    #0099bb;
    --yellow:      #ffcc00;
    --purple:      #9147ff;

    --font-mono:   "JetBrains Mono", "Fira Code", "Cascadia Code",
                   "SF Mono", "Consolas", monospace;
    --font-size:   13px;
    --radius:      3px;
}

/* ── Reset ─────────────────────────────────────────────────────── */

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

html { font-size: var(--font-size); }

body {
    font-family: var(--font-mono);
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    min-height: 100vh;
}

a { color: var(--cyan); text-decoration: none; }
a:hover { color: var(--text-bright); text-decoration: underline; }

img { max-width: 100%; }

/* ── Layout ────────────────────────────────────────────────────── */

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

.page {
    padding: 2rem 0 4rem;
}

/* ── Navigation ────────────────────────────────────────────────── */

nav {
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border);
    padding: 0;
    position: sticky;
    top: 0;
    z-index: 100;
}

nav .container {
    display: flex;
    align-items: center;
    height: 48px;
    gap: 0;
}

nav .brand {
    color: var(--green);
    font-weight: bold;
    font-size: 1rem;
    letter-spacing: 0.5px;
    margin-right: 2rem;
    white-space: nowrap;
}

nav .brand span {
    color: var(--text-muted);
    font-weight: normal;
}

nav .links {
    display: flex;
    gap: 0;
    flex: 1;
    overflow-x: auto;
}

nav .links a {
    color: var(--text-muted);
    padding: 0.85rem 1rem;
    font-size: 0.85rem;
    white-space: nowrap;
    border-bottom: 2px solid transparent;
    transition: color 0.15s, border-color 0.15s;
}

nav .links a:hover {
    color: var(--text);
    text-decoration: none;
}

nav .links a.active {
    color: var(--green);
    border-bottom-color: var(--green);
}

nav .search-box {
    margin-left: auto;
}

nav .search-box input {
    background: var(--bg);
    border: 1px solid var(--border);
    color: var(--text);
    font-family: var(--font-mono);
    font-size: 0.85rem;
    padding: 0.35rem 0.75rem;
    border-radius: var(--radius);
    width: 180px;
    outline: none;
}

nav .search-box input:focus {
    border-color: var(--cyan-dim);
}

nav .search-box input::placeholder {
    color: var(--text-dim);
}

/* ── Page Header ───────────────────────────────────────────────── */

.page-header {
    margin-bottom: 2rem;
}

.page-header h1 {
    color: var(--text-bright);
    font-size: 1.4rem;
    font-weight: bold;
    margin-bottom: 0.25rem;
}

.page-header .subtitle {
    color: var(--text-muted);
    font-size: 0.85rem;
}

/* ── Stat Cards ────────────────────────────────────────────────── */

.stat-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
    margin-bottom: 2rem;
}

.stat-card {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem;
}

.stat-card .label {
    color: var(--text-muted);
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 0.5rem;
}

.stat-card .value {
    color: var(--green);
    font-size: 1.8rem;
    font-weight: bold;
    line-height: 1.2;
}

.stat-card .value.neutral { color: var(--text-bright); }
.stat-card .value.negative { color: var(--red); }

.stat-card .detail {
    color: var(--text-muted);
    font-size: 0.75rem;
    margin-top: 0.35rem;
}

/* ── Tables ────────────────────────────────────────────────────── */

.data-table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 2rem;
}

.data-table th {
    color: var(--text-muted);
    font-size: 0.75rem;
    font-weight: normal;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    text-align: left;
    padding: 0.75rem 0.75rem;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

.data-table th a {
    color: var(--text-muted);
}

.data-table th a:hover {
    color: var(--cyan);
    text-decoration: none;
}

.data-table th.active {
    color: var(--cyan);
}

.data-table th.num,
.data-table td.num {
    text-align: right;
}

.data-table td {
    padding: 0.6rem 0.75rem;
    border-bottom: 1px solid var(--bg-elevated);
    vertical-align: middle;
    white-space: nowrap;
}

.data-table tr:hover td {
    background: var(--bg-hover);
}

.data-table .rank {
    color: var(--text-dim);
    width: 3rem;
}

.data-table .channel-name {
    font-weight: bold;
    color: var(--text-bright);
}

.data-table .channel-name a {
    color: var(--text-bright);
}

.data-table .channel-name a:hover {
    color: var(--cyan);
}

.data-table .muted {
    color: var(--text-muted);
}

.data-table .truncate {
    max-width: 250px;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ── Sections ──────────────────────────────────────────────────── */

.section {
    margin-bottom: 3rem;
}

.section-header {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    margin-bottom: 1rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--border);
}

.section-header h2 {
    color: var(--text-bright);
    font-size: 1rem;
    font-weight: bold;
}

.section-header .more {
    color: var(--text-muted);
    font-size: 0.8rem;
}

/* ── Charts ────────────────────────────────────────────────────── */

.chart-container {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.5rem;
    margin-bottom: 2rem;
}

.chart-container .chart-title {
    color: var(--text-muted);
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 1rem;
}

.chart-container canvas {
    width: 100% !important;
    max-height: 300px;
}

/* ── Status Badges ─────────────────────────────────────────────── */

.badge {
    display: inline-block;
    font-size: 0.7rem;
    padding: 0.15rem 0.5rem;
    border-radius: 2px;
    font-weight: bold;
    letter-spacing: 0.5px;
    text-transform: uppercase;
}

.badge-live {
    background: var(--green);
    color: var(--bg);
}

.badge-offline {
    background: var(--border);
    color: var(--text-muted);
}

/* ── Change Indicators ─────────────────────────────────────────── */

.change-up { color: var(--green); }
.change-down { color: var(--red); }
.change-flat { color: var(--text-muted); }

/* ── Channel Header (detail page) ──────────────────────────────── */

.channel-header {
    display: flex;
    align-items: flex-start;
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.channel-header .info {
    flex: 1;
}

.channel-header .info h1 {
    color: var(--text-bright);
    font-size: 1.6rem;
    margin-bottom: 0.25rem;
}

.channel-header .info .meta {
    color: var(--text-muted);
    font-size: 0.85rem;
    display: flex;
    gap: 1.5rem;
    flex-wrap: wrap;
}

.channel-header .info .meta .followers {
    color: var(--text);
}

.channel-header .live-status {
    text-align: right;
}

.channel-header .live-status .viewer-count {
    font-size: 2rem;
    font-weight: bold;
    color: var(--green);
    line-height: 1;
}

.channel-header .live-status .game {
    color: var(--text-muted);
    font-size: 0.85rem;
    margin-top: 0.25rem;
}

/* ── Two Column Layout ─────────────────────────────────────────── */

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

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

/* ── Comparison Table ──────────────────────────────────────────── */

.compare-table {
    width: 100%;
    border-collapse: collapse;
}

.compare-table th {
    color: var(--text-bright);
    font-weight: bold;
    text-align: center;
    padding: 0.75rem;
    border-bottom: 1px solid var(--border);
}

.compare-table td {
    padding: 0.6rem 0.75rem;
    border-bottom: 1px solid var(--bg-elevated);
    text-align: center;
}

.compare-table td:first-child {
    text-align: left;
    color: var(--text-muted);
    font-size: 0.85rem;
}

/* ── Language Bars ─────────────────────────────────────────────── */

.lang-bar-container {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.lang-bar {
    height: 8px;
    background: var(--green-dim);
    border-radius: 1px;
    min-width: 2px;
}

/* ── Pagination ────────────────────────────────────────────────── */

.pagination {
    display: flex;
    gap: 0.5rem;
    justify-content: center;
    margin: 2rem 0;
}

.pagination a,
.pagination span {
    padding: 0.4rem 0.8rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-muted);
    font-size: 0.85rem;
}

.pagination a:hover {
    background: var(--bg-elevated);
    color: var(--text);
    text-decoration: none;
}

.pagination .current {
    background: var(--bg-elevated);
    color: var(--green);
    border-color: var(--green-dim);
}

/* ── Search Page ───────────────────────────────────────────────── */

.search-form {
    margin-bottom: 2rem;
}

.search-form input[type="text"] {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    color: var(--text-bright);
    font-family: var(--font-mono);
    font-size: 1rem;
    padding: 0.75rem 1rem;
    border-radius: var(--radius);
    width: 100%;
    max-width: 500px;
    outline: none;
}

.search-form input[type="text"]:focus {
    border-color: var(--cyan-dim);
}

.search-form input[type="text"]::placeholder {
    color: var(--text-dim);
}

/* ── 404 Page ──────────────────────────────────────────────────── */

.error-page {
    text-align: center;
    padding: 6rem 0;
}

.error-page .code {
    font-size: 6rem;
    color: var(--text-dim);
    font-weight: bold;
    line-height: 1;
}

.error-page .message {
    color: var(--text-muted);
    margin-top: 1rem;
    font-size: 1rem;
}

/* ── Live Pulse Animation ──────────────────────────────────────── */

.badge-live {
    position: relative;
    padding-left: 1.2em;
}

.badge-live::before {
    content: '';
    position: absolute;
    left: 0.4em;
    top: 50%;
    transform: translateY(-50%);
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--bg);
    animation: pulse 1.5s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; transform: translateY(-50%) scale(1); }
    50% { opacity: 0.4; transform: translateY(-50%) scale(0.6); }
}

/* ── Avatars & Box Art ─────────────────────────────────────────── */

.avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    border: 1px solid var(--border);
    vertical-align: middle;
    background: var(--bg-elevated);
    flex-shrink: 0;
}

.avatar-sm {
    width: 22px;
    height: 22px;
}

.avatar-lg {
    width: 80px;
    height: 80px;
    border-width: 2px;
    font-size: 2rem !important;
}

/* Letter placeholder when no profile image is available */
.avatar-placeholder {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: var(--bg);
    font-weight: bold;
    font-size: 0.7rem;
    line-height: 1;
    text-transform: uppercase;
}

.box-art {
    width: 30px;
    height: 40px;
    border-radius: 2px;
    border: 1px solid var(--border);
    vertical-align: middle;
    margin-right: 0.5rem;
    background: var(--bg-elevated);
    object-fit: cover;
}

.box-art-sm {
    width: 24px;
    height: 32px;
}

.channel-cell {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.game-cell {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

/* ── Blinking Cursor ───────────────────────────────────────────── */

nav .brand::after {
    content: '█';
    color: var(--green);
    animation: blink-cursor 1s step-end infinite;
    margin-left: 2px;
    font-size: 0.85em;
}

@keyframes blink-cursor {
    0%, 100% { opacity: 1; }
    50% { opacity: 0; }
}

/* ── Stream Thumbnails ─────────────────────────────────────────── */

.stream-thumb {
    border-radius: 2px;
    border: 1px solid var(--border);
    background: var(--bg-elevated);
    object-fit: cover;
}

.stream-thumb-sm {
    width: 120px;
    height: 68px;
}

.stream-thumb-lg {
    width: 100%;
    max-width: 640px;
    height: auto;
    aspect-ratio: 16/9;
    margin-bottom: 1.5rem;
}

/* ── Game Cards ────────────────────────────────────────────────── */

.game-cards {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 1rem;
    margin-bottom: 2rem;
}

.game-card {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    display: flex;
    gap: 0.75rem;
    padding: 0.75rem;
    transition: border-color 0.15s;
}

.game-card:hover {
    border-color: var(--border-light);
}

.game-card a {
    text-decoration: none;
}

.game-card .box-art-card {
    width: 48px;
    height: 64px;
    border-radius: 2px;
    border: 1px solid var(--border);
    background: var(--bg-elevated);
    object-fit: cover;
    flex-shrink: 0;
}

.game-card .game-info {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.game-card .game-info .name {
    color: var(--text-bright);
    font-weight: bold;
    font-size: 0.85rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.game-card .game-info .viewers {
    color: var(--green);
    font-size: 1rem;
    font-weight: bold;
}

.game-card .game-info .channels {
    color: var(--text-muted);
    font-size: 0.75rem;
}

/* ── Heatmap Grid ──────────────────────────────────────────────── */

.heatmap {
    display: grid;
    grid-template-columns: repeat(24, 1fr);
    gap: 2px;
    margin-bottom: 0.5rem;
}

.heatmap-cell {
    aspect-ratio: 1;
    border-radius: 2px;
    position: relative;
    min-height: 28px;
}

.heatmap-labels {
    display: grid;
    grid-template-columns: repeat(24, 1fr);
    gap: 2px;
    margin-bottom: 1rem;
}

.heatmap-labels span {
    text-align: center;
    color: var(--text-dim);
    font-size: 0.6rem;
}

/* ── Tag Cloud ─────────────────────────────────────────────────── */

.tag-cloud {
    line-height: 2.2;
    text-align: center;
    padding: 1rem;
}

.tag-cloud .tag {
    display: inline-block;
    padding: 0.15rem 0.5rem;
    margin: 0.15rem;
    border-radius: 2px;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    white-space: nowrap;
    transition: border-color 0.15s, color 0.15s;
}

.tag-cloud .tag:hover {
    border-color: var(--cyan-dim);
    color: var(--cyan);
}

/* ── Treemap ───────────────────────────────────────────────────── */

.treemap-container {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem;
    margin-bottom: 2rem;
}

.treemap-container canvas {
    width: 100% !important;
    max-height: 400px;
}

/* ── Change Magnitude Bars (trending) ──────────────────────────── */

.change-bar-container {
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.change-bar {
    height: 6px;
    border-radius: 1px;
    min-width: 2px;
}

.change-bar.up { background: var(--green-dim); }
.change-bar.down { background: var(--red-dim); }

/* ── Compare Winner Highlight ──────────────────────────────────── */

.compare-table td.winner {
    color: var(--green);
    font-weight: bold;
}

/* ── Time Range Tabs ───────────────────────────────────────────── */

.time-tabs {
    display: inline-flex;
    gap: 0;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    margin-bottom: 0.5rem;
}

.time-tabs a {
    padding: 0.35rem 0.8rem;
    font-size: 0.8rem;
    color: var(--text-muted);
    border-right: 1px solid var(--border);
}

.time-tabs a:last-child { border-right: none; }

.time-tabs a:hover {
    background: var(--bg-elevated);
    text-decoration: none;
    color: var(--text);
}

.time-tabs a.active {
    background: var(--bg-elevated);
    color: var(--green);
}

/* ── Game Header (detail page) ─────────────────────────────────── */

.game-header {
    display: flex;
    align-items: flex-start;
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.game-header .box-art-lg {
    width: 120px;
    height: 160px;
    border-radius: 3px;
    border: 1px solid var(--border);
    background: var(--bg-elevated);
    object-fit: cover;
    flex-shrink: 0;
}

.game-header .info h1 {
    color: var(--text-bright);
    font-size: 1.6rem;
    margin-bottom: 0.25rem;
}

.game-header .info .meta {
    color: var(--text-muted);
    font-size: 0.85rem;
}

/* ── Footer ────────────────────────────────────────────────────── */

footer {
    border-top: 1px solid var(--border);
    padding: 1.5rem 0;
    margin-top: 4rem;
    color: var(--text-dim);
    font-size: 0.75rem;
    text-align: center;
}

/* ── Mobile Search Toggle ───────────────────────────────────────── */

.nav-search-toggle {
    display: none;
    background: none;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-muted);
    font-size: 0.85rem;
    padding: 0.3rem 0.6rem;
    cursor: pointer;
    margin-left: auto;
    line-height: 1;
}

.nav-search-toggle:hover {
    color: var(--text);
    border-color: var(--border-light);
}

/* ── Responsive ────────────────────────────────────────────────── */

@media (max-width: 768px) {
    .grid-2, .grid-3 { grid-template-columns: 1fr; }
    .stat-cards { grid-template-columns: repeat(2, 1fr); }
    .channel-header { flex-direction: column; }
    .data-table { font-size: 0.8rem; }

    /* Hide desktop search, show toggle button */
    nav .search-box { display: none; }
    .nav-search-toggle { display: block; }

    /* When search is toggled open (via JS or :focus-within) */
    nav .container.search-open .search-box {
        display: block;
        position: absolute;
        top: 48px;
        left: 0;
        right: 0;
        padding: 0.5rem 1rem;
        background: var(--bg-surface);
        border-bottom: 1px solid var(--border);
        z-index: 101;
    }
    nav .container.search-open .search-box input {
        width: 100%;
    }

    /* Horizontal scroll for nav links */
    nav .links {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
    }
    nav .links::-webkit-scrollbar { display: none; }
    nav .links a { padding: 0.85rem 0.6rem; font-size: 0.8rem; }

    /* Shrink stream thumbnails on mobile */
    .stream-thumb-sm { width: 80px; height: 45px; }

    /* Tighter truncation */
    .data-table .truncate { max-width: 120px; }
}

@media (max-width: 480px) {
    .stat-cards { grid-template-columns: 1fr; }
    .stream-thumb-sm { width: 60px; height: 34px; }
}
