:root {
    --bg: #222222;
    --surface: #2c2c2c;
    --border: #3a3a3a;
    --text: #d4d0ca;
    --text-dim: #A2998B;
    --accent: #B31B1B;
    --accent-dim: #8f1515;
    --accent-light: #d42a2a;
    --danger: #EF4035;
    --warning: #F8981D;
    --success: #6EB43F;
    --model-a: #006699;
    --model-b: #F8981D;
    --gold: #F8981D;
    --silver: #A2998B;
    --bronze: #8f6a2a;
    --mono: 'SF Mono', 'Fira Code', 'JetBrains Mono', 'Cascadia Code', monospace;
    --serif: 'Libre Baskerville', Georgia, 'Palatino Linotype', Palatino, serif;
    --sans: 'Source Sans 3', 'Helvetica Neue', Helvetica, Arial, sans-serif;
}

[data-theme="light"] {
    --bg: #f5f3ef;
    --surface: #ffffff;
    --border: #ddd8d0;
    --text: #2c2c2c;
    --text-dim: #7a7265;
    --accent: #B31B1B;
    --accent-dim: #8f1515;
    --accent-light: #d42a2a;
    --danger: #d32f2f;
    --warning: #e67e00;
    --success: #558b2f;
    --model-a: #005580;
    --model-b: #d47a00;
    --gold: #d47a00;
    --silver: #7a7265;
    --bronze: #8f6a2a;
}

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

body {
    background: var(--bg);
    color: var(--text);
    font-family: var(--sans);
    font-size: 14px;
    line-height: 1.6;
    min-height: 100vh;
    display: flex;
    justify-content: center;
    padding: 1rem 1rem;
}

.container {
    width: 100%;
    max-width: 1100px;
    position: relative;
}

/* Top Nav */
.top-nav-left {
    position: absolute;
    top: 0;
    left: 0;
}

.top-nav-left a {
    color: var(--accent);
    text-decoration: none;
    font-family: var(--mono);
    font-size: 0.7rem;
    letter-spacing: 0.05em;
    padding: 0.3rem 0.6rem;
    border: 1px solid var(--accent);
    border-radius: 3px;
    transition: all 0.15s;
}

.top-nav-left a:hover {
    background: rgba(179, 27, 27, 0.15);
}

.top-nav {
    position: absolute;
    top: 0;
    right: 0;
    display: flex;
    gap: 0.8rem;
}

.top-nav a {
    color: var(--text-dim);
    text-decoration: none;
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    padding: 0.3rem 0.6rem;
    border: 1px solid transparent;
    border-radius: 3px;
    transition: all 0.15s;
}

.top-nav a:hover, .top-nav a.active {
    color: var(--accent);
    border-color: var(--accent);
}

/* Arena centered layout */
.arena-centered {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 80vh;
}

/* Hero */
.hero {
    text-align: center;
    margin-bottom: 2.5rem;
}

.logo {
    font-family: var(--sans);
    font-size: 1.4rem;
    font-weight: 700;
    letter-spacing: 0.15em;
    color: var(--accent);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
}

.tower-icon {
    color: var(--accent);
    opacity: 0.85;
}

.hero-tagline {
    font-family: var(--serif);
    font-size: 2.4rem;
    font-weight: 400;
    color: var(--text);
    margin-top: 0.8rem;
}

.hero-tagline .highlight {
    background: var(--accent);
    color: #fff;
    padding: 0.05em 0.3em;
    border-radius: 4px;
    font-style: italic;
}

/* Prompt Card */
.prompt-card {
    width: 100%;
    max-width: 800px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    overflow: hidden;
}

.prompt-card #prompt {
    border: none;
    border-radius: 0;
    background: transparent;
    min-height: 80px;
    resize: none;
}

.prompt-card #prompt:focus {
    box-shadow: none;
}

/* Toolbar bar (below prompt) */
.toolbar-bar {
    width: 100%;
    max-width: 800px;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 0.6rem 0;
    margin-top: 0.5rem;
    gap: 0.5rem;
}

.toolbar-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.toolbar-actions {
    display: flex;
    align-items: center;
    gap: 0.8rem;
}

.vs-label {
    color: var(--text-dim);
    font-size: 0.65rem;
    font-style: italic;
}

.btn-battle {
    padding: 0.45rem 1.2rem;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: 20px;
    font-family: var(--mono);
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 0.05em;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-battle:hover {
    background: var(--accent-dim);
    box-shadow: 0 0 15px rgba(179, 27, 27, 0.3);
}

.btn-battle:disabled { opacity: 0.5; cursor: not-allowed; }

/* Stats inline */
.stats-inline {
    margin-top: 1.5rem;
    font-size: 0.7rem;
    color: var(--text-dim);
    display: flex;
    gap: 0.4rem;
}

.stats-inline .stat-value {
    color: var(--text);
    font-family: var(--mono);
    font-weight: 600;
}

.stats-inline .dot {
    color: var(--border);
}

/* Leaderboard disclaimer */
.lb-disclaimer {
    text-align: center;
    font-size: 0.7rem;
    font-style: italic;
    color: var(--text-dim);
    max-width: 600px;
    margin: 2.5rem auto 0.5rem;
    line-height: 1.5;
}

/* Controls (leaderboard) */
.controls {
    display: flex;
    gap: 1.5rem;
    margin: 0.5rem 0;
    flex-wrap: wrap;
    align-items: flex-end;
    justify-content: center;
}

.control-group {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

.control-group label {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.15em;
    color: var(--text-dim);
}

.btn-group {
    display: flex;
    gap: 0;
}

.btn-option {
    background: var(--bg);
    border: 1px solid var(--border);
    color: var(--text-dim);
    font-family: var(--mono);
    font-size: 0.7rem;
    padding: 0.3rem 0.6rem;
    cursor: pointer;
    transition: all 0.15s;
}

.btn-option:first-child { border-radius: 3px 0 0 3px; }
.btn-option:last-child { border-radius: 0 3px 3px 0; }
.btn-option:not(:last-child) { border-right: none; }
.btn-option:hover { color: var(--text); background: #363636; }

.btn-option.active {
    background: var(--accent);
    color: var(--bg);
    border-color: var(--accent);
    font-weight: 600;
}

.model-select {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 3px;
    color: var(--text);
    font-family: var(--mono);
    font-size: 0.7rem;
    padding: 0.3rem 0.5rem;
    outline: none;
    cursor: pointer;
    min-width: 120px;
}

.model-select:focus {
    border-color: var(--accent);
}

/* Textarea */
#prompt {
    width: 100%;
    min-height: 80px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 4px;
    color: var(--text);
    font-family: var(--mono);
    font-size: 14px;
    padding: 1rem;
    resize: none;
    outline: none;
    transition: border-color 0.2s;
}

#prompt:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 1px rgba(179, 27, 27, 0.2);
}

#prompt::placeholder { color: var(--text-dim); }

.btn-secondary {
    padding: 0.6rem 1.2rem;
    background: var(--surface);
    color: var(--accent);
    border: 1px solid var(--accent);
    border-radius: 4px;
    font-family: var(--mono);
    font-size: 0.8rem;
    font-weight: 600;
    letter-spacing: 0.05em;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-secondary:hover { background: rgba(179, 27, 27, 0.15); }

/* Prompt Display (battle/reveal) */
.prompt-display {
    margin-top: 3rem;
    padding: 0.6rem 1rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 4px;
    font-family: var(--mono);
    font-size: 0.8rem;
    color: var(--text-dim);
    white-space: pre-wrap;
    word-wrap: break-word;
    max-height: 120px;
    overflow-y: auto;
}

.prompt-display::before {
    content: 'PROMPT: ';
    color: var(--accent);
    font-weight: 600;
    font-size: 0.65rem;
    letter-spacing: 0.1em;
}

/* Battle View — Split Panel */
.battle-panels {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
    margin: 1rem 0;
}

.panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 4px;
    overflow: hidden;
}

.panel-header {
    padding: 0.5rem 1rem;
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 0.15em;
    text-transform: uppercase;
    border-bottom: 1px solid var(--border);
}

.panel.side-a .panel-header {
    color: var(--model-a);
    border-bottom-color: rgba(0, 102, 153, 0.4);
}

.panel.side-b .panel-header {
    color: var(--model-b);
    border-bottom-color: rgba(248, 152, 29, 0.4);
}

.panel-body {
    padding: 1rem;
    min-height: 200px;
    max-height: 500px;
    overflow-y: auto;
    font-family: var(--sans);
    font-size: 13px;
    line-height: 1.7;
    white-space: pre-wrap;
    word-wrap: break-word;
}

.panel-footer {
    padding: 0.4rem 1rem;
    font-family: var(--mono);
    font-size: 0.7rem;
    color: var(--text-dim);
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
}

.panel-body .typing-cursor {
    display: inline-block;
    width: 8px;
    height: 1em;
    background: var(--accent-light);
    animation: blink 0.7s step-end infinite;
    vertical-align: text-bottom;
    margin-left: 2px;
}

/* Streaming status */
.streaming-indicator {
    color: var(--accent);
    animation: pulse 1.5s ease-in-out infinite;
}

/* Vote buttons */
.vote-section {
    display: flex;
    justify-content: center;
    gap: 1rem;
    margin: 1.5rem 0;
}

.vote-btn {
    padding: 0.7rem 2rem;
    background: var(--surface);
    border: 2px solid var(--border);
    border-radius: 4px;
    font-family: var(--mono);
    font-size: 0.85rem;
    font-weight: 700;
    letter-spacing: 0.1em;
    cursor: pointer;
    transition: all 0.2s;
}

.vote-btn:hover { transform: translateY(-2px); }

.vote-btn.vote-a {
    color: var(--model-a);
    border-color: var(--model-a);
}
.vote-btn.vote-a:hover {
    background: rgba(0, 102, 153, 0.2);
    box-shadow: 0 4px 15px rgba(0, 102, 153, 0.25);
}

.vote-btn.vote-tie {
    color: var(--text-dim);
    border-color: var(--text-dim);
}
.vote-btn.vote-tie:hover {
    background: rgba(255, 255, 255, 0.05);
    color: var(--text);
}

.vote-btn.vote-b {
    color: var(--model-b);
    border-color: var(--model-b);
}
.vote-btn.vote-b:hover {
    background: rgba(248, 152, 29, 0.15);
    box-shadow: 0 4px 15px rgba(248, 152, 29, 0.2);
}

.vote-btn:disabled {
    opacity: 0.3;
    cursor: not-allowed;
    transform: none;
}

.skip-section {
    text-align: center;
    margin-top: 0.3rem;
}

.skip-section .btn-link {
    font-size: 0.65rem;
    color: var(--text-dim);
    opacity: 0.6;
}

.skip-section .btn-link:hover {
    opacity: 1;
}

/* Reveal */
.reveal-name {
    font-size: 1rem;
    font-weight: 700;
    text-align: center;
    padding: 0.5rem;
    animation: slideIn 0.4s ease-out;
}

.panel.side-a .reveal-name { color: var(--model-a); }
.panel.side-b .reveal-name { color: var(--model-b); }

.reveal-meta {
    text-align: center;
    font-size: 0.7rem;
    color: var(--text-dim);
    padding: 0.3rem;
}

.reveal-meta .cost { color: var(--warning); }

.provider-badge {
    display: inline-block;
    padding: 0.15rem 0.4rem;
    border-radius: 3px;
    font-size: 0.65rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.provider-badge.gateway {
    background: rgba(0, 102, 153, 0.2);
    color: var(--model-a);
}

.provider-badge.local {
    background: rgba(248, 152, 29, 0.15);
    color: var(--model-b);
}

/* ELO change badge */
.elo-change {
    font-size: 0.75rem;
    font-weight: 600;
}
.elo-change.positive { color: var(--success); }
.elo-change.negative { color: var(--danger); }
.elo-change.neutral { color: var(--text-dim); }

/* Leaderboard */
.leaderboard-table {
    width: 100%;
    border-collapse: collapse;
    margin: 1rem 0;
}

.leaderboard-table th {
    text-align: left;
    padding: 0.6rem 0.8rem;
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--text-dim);
    border-bottom: 1px solid var(--border);
}

.leaderboard-table td {
    padding: 0.6rem 0.8rem;
    border-bottom: 1px solid var(--border);
    font-size: 0.8rem;
    font-family: var(--mono);
}

.leaderboard-table tr:hover td {
    background: rgba(255, 255, 255, 0.02);
}

.rank-1 .rank-num { color: var(--gold); font-weight: 700; }
.rank-2 .rank-num { color: var(--silver); font-weight: 700; }
.rank-3 .rank-num { color: var(--bronze); font-weight: 700; }

.elo-bar {
    height: 6px;
    background: var(--border);
    border-radius: 3px;
    overflow: hidden;
    min-width: 80px;
}

.elo-bar-fill {
    height: 100%;
    border-radius: 3px;
    background: var(--accent);
    transition: width 0.5s ease;
}


/* Export bar */
.export-bar {
    display: flex;
    justify-content: center;
    gap: 0.8rem;
    margin: 1.5rem 0;
}

/* Template bar */
.template-bar {
    display: none;
    gap: 0.5rem;
    align-items: center;
    width: 100%;
    max-width: 800px;
    margin-top: 0.3rem;
}

.template-bar.visible {
    display: flex;
}

.btn-link {
    background: none;
    border: none;
    color: var(--text-dim);
    font-family: var(--mono);
    font-size: 0.7rem;
    cursor: pointer;
    padding: 0;
    transition: color 0.15s;
}

.btn-link:hover {
    color: var(--accent);
}

.template-bar select {
    flex: 1;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 3px;
    color: var(--text);
    font-family: var(--mono);
    font-size: 0.75rem;
    padding: 0.4rem 0.6rem;
    outline: none;
    cursor: pointer;
}

.template-bar select:focus {
    border-color: var(--accent);
}

.btn-icon {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 3px;
    color: var(--text-dim);
    font-family: var(--mono);
    font-size: 0.65rem;
    font-weight: 600;
    letter-spacing: 0.05em;
    padding: 0.4rem 0.6rem;
    cursor: pointer;
    transition: all 0.15s;
}

.btn-icon:hover {
    color: var(--accent);
    border-color: var(--accent);
}

.btn-icon.btn-danger:hover {
    color: var(--danger);
    border-color: var(--danger);
}

/* Animations */
@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

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

@keyframes slideIn {
    from { opacity: 0; transform: translateY(-10px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.fade-in { animation: fadeIn 0.4s ease-out; }
.hidden { display: none !important; }

/* Theme toggle */
.theme-toggle {
    background: none;
    border: 1px solid var(--border);
    border-radius: 3px;
    color: var(--text-dim);
    font-size: 0.8rem;
    padding: 0.2rem 0.5rem;
    cursor: pointer;
    transition: all 0.15s;
    line-height: 1;
}

.theme-toggle:hover {
    border-color: var(--accent);
    color: var(--text);
}

/* Light theme code block override */
[data-theme="light"] .panel-body pre {
    background: #f6f8fa;
    border: 1px solid var(--border);
    border-radius: 4px;
}

[data-theme="light"] .panel-body pre code {
    color: #24292e;
}

/* Scrollbar */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-dim); }

/* Mobile/Desktop toggle */
.mobile-only { display: none; }

/* Responsive */
@media (max-width: 768px) {
    body { padding: 0.5rem; }

    .container { max-width: 100%; }

    /* Nav */
    .top-nav { position: relative; justify-content: flex-end; margin-bottom: 0.5rem; }
    .top-nav-left { position: relative; margin-bottom: 0.5rem; }

    /* Hero */
    .logo { font-size: 1rem; }
    .hero-tagline { font-size: 1.4rem; }
    .hero { margin-bottom: 1.5rem; }
    .arena-centered { min-height: auto; padding-top: 1rem; }

    /* Prompt */
    .prompt-card { max-width: 100%; }

    /* Show/hide mobile vs desktop elements */
    .desktop-only { display: none !important; }
    .mobile-only { display: block !important; }

    /* Toolbar */
    .toolbar-bar { max-width: 100%; }
    .toolbar-row { flex-wrap: wrap; justify-content: center; }
    .model-select { min-width: 100px; font-size: 0.65rem; }

    /* Battle panels — stack vertically */
    .battle-panels { grid-template-columns: 1fr; margin-top: 1rem; }
    .panel-body { max-height: 350px; }

    /* Vote */
    .vote-section { flex-direction: column; align-items: center; }
    .vote-btn { width: 80%; text-align: center; }

    /* Leaderboard */
    .controls { flex-direction: column; }
    .lb-disclaimer { margin-top: 1rem; }
    .leaderboard-table { font-size: 0.7rem; display: block; overflow-x: auto; }
    .leaderboard-table th, .leaderboard-table td { padding: 0.4rem; white-space: nowrap; }
    .export-bar { flex-direction: column; align-items: center; }
}
