:root {
    --bg-base: #09090b; --bg-surface: #18181b; --bg-elevated: #27272a;
    --text-primary: #f4f4f5; --text-secondary: #a1a1aa; --border: #3f3f46;
    --accent-blue: #3b82f6; --accent-blue-hover: #2563eb;
    --accent-green: #10b981; --accent-red: #ef4444; --accent-orange: #f59e0b;
    --radius: 8px; --font-sans: 'Inter', sans-serif; --font-mono: 'JetBrains Mono', monospace;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: var(--font-sans); background-color: var(--bg-base); color: var(--text-primary); height: 100vh; overflow: hidden; }
.hidden { display: none !important; }
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

/* Modals (Lobby & Problem Selector) */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,0.8); backdrop-filter: blur(4px); display: none; align-items: center; justify-content: center; z-index: 100; }
.modal.active { display: flex; animation: fadeIn 0.25s ease-out; }
.modal-content { background: var(--bg-surface); border: 1px solid var(--border); padding: 30px; border-radius: 12px; width: 90%; max-width: 600px; text-align: center; }
.modal-content.large { max-width: 800px; height: 80vh; display: flex; flex-direction: column; text-align: left; padding: 0; }
.modal-header { padding: 20px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; }
.subtitle { color: var(--text-secondary); margin-bottom: 20px; }

#problem-modal { align-items: stretch; justify-content: stretch; backdrop-filter: blur(8px); }
#problem-modal.active { animation: none; }
#problem-modal .modal-content.large {
    width: 100vw;
    max-width: none;
    height: 100vh;
    border-radius: 0;
    border: none;
    background:
        radial-gradient(circle at 15% 20%, rgba(59, 130, 246, 0.14), transparent 38%),
        radial-gradient(circle at 85% 80%, rgba(16, 185, 129, 0.1), transparent 42%),
        var(--bg-surface);
}
#problem-modal .modal-header {
    position: sticky;
    top: 0;
    z-index: 5;
    background: rgba(24, 24, 27, 0.88);
    backdrop-filter: blur(10px);
}

/* Lobby Cards */
.lobby-actions { display: flex; gap: 20px; margin-top: 20px; text-align: left; }
.card { flex: 1; background: var(--bg-elevated); padding: 20px; border-radius: var(--radius); border: 1px solid var(--border); }
.card h3 { margin-bottom: 10px; color: var(--accent-blue); }
.card p { color: var(--text-secondary); font-size: 0.85rem; margin-bottom: 15px; }
.card input { width: 100%; padding: 10px; background: var(--bg-base); border: 1px solid var(--border); color: white; border-radius: 6px; margin-bottom: 10px; font-family: var(--font-mono); font-size: 1.2rem; text-align: center; text-transform: uppercase; outline: none;}

#main-menu {
    background: rgba(0, 0, 0, 0.78);
}

.main-menu-content {
    max-width: 1080px;
    width: min(94vw, 1080px);
    min-height: min(78vh, 640px);
    display: grid;
    grid-template-columns: 1.05fr 1fr;
    gap: 20px;
    padding: 26px;
    text-align: left;
    background: var(--bg-surface);
    box-shadow: 0 16px 38px rgba(0, 0, 0, 0.25);
}

.main-hero {
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 28px;
    background: var(--bg-base);
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}

.hero-kicker {
    color: var(--accent-blue);
    letter-spacing: 0.08em;
    text-transform: uppercase;
    font-size: 0.75rem;
    font-weight: 600;
    margin-bottom: 10px;
}

.main-hero h1 {
    font-size: clamp(2rem, 3.4vw, 2.8rem);
    line-height: 1;
    margin-bottom: 14px;
}

.main-menu-art {
    width: 100%;
    max-height: 300px;
    object-fit: cover;
    border-radius: 12px;
    border: 1px solid var(--border);
    margin-bottom: 16px;
}

.hero-note { color: var(--text-secondary); font-size: 0.9rem; margin: 6px 0 16px; }

.main-actions {
    display: grid;
    gap: 16px;
    align-content: center;
}

.main-actions .card {
    padding: 24px;
    border-radius: 12px;
    background: var(--bg-elevated);
    transition: border-color 0.18s ease;
}

.action-art {
    width: 100%;
    height: 120px;
    object-fit: cover;
    border-radius: 10px;
    border: 1px solid var(--border);
    margin-bottom: 14px;
}

.main-actions .card:hover {
    border-color: var(--accent-blue);
}

@media (max-width: 920px) {
    .main-menu-content {
        grid-template-columns: 1fr;
        min-height: auto;
        max-height: 92vh;
        overflow-y: auto;
    }
    .main-hero { padding: 20px; }
    .problem-picker-layout { grid-template-columns: 1fr; }
    .queue-panel { border-left: none; border-top: 1px solid var(--border); max-height: 36vh; }
}

#room-code-display { margin-top: 15px; background: var(--bg-base); padding: 15px; border-radius: 8px; text-align: center; border: 1px dashed var(--accent-green); }
#room-code-text { font-family: var(--font-mono); letter-spacing: 3px; color: var(--accent-green); margin: 5px 0; }
.waiting-text { font-size: 0.8rem; color: var(--text-secondary); }

/* Problem List */
.problem-list { overflow-y: auto; padding: 20px; flex: 1; display: flex; flex-direction: column; gap: 10px; }
.problem-picker-layout { display: grid; grid-template-columns: 1fr 320px; min-height: 0; flex: 1; }
.prob-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px;
    background: linear-gradient(135deg, var(--bg-elevated), #22222a);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    cursor: pointer;
    transition: border-color 0.18s ease, box-shadow 0.18s ease;
}
.prob-item:hover {
    border-color: var(--accent-blue);
    box-shadow: 0 10px 22px rgba(0, 0, 0, 0.22);
}
.prob-item-main { min-width: 0; }
.prob-item-main h4 { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.prob-item-add { margin-left: 12px; }
.prob-item h4 { margin-bottom: 5px; }
.prob-item-tags { display: flex; gap: 5px; }
.queue-panel {
    border-left: 1px solid var(--border);
    background: rgba(9, 9, 11, 0.55);
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.queue-panel-header { display: flex; justify-content: space-between; align-items: center; }
.queue-list { flex: 1; overflow-y: auto; text-align: left; padding-right: 6px; }
.queue-row { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 8px; border: 1px solid var(--border); border-radius: 8px; margin-bottom: 8px; background: var(--bg-surface); }
.queue-row.active { border-color: var(--accent-blue); }
.queue-title { font-size: 0.85rem; color: var(--text-primary); }
.queue-remove { font-size: 0.75rem; padding: 4px 8px; }

/* Navbar & Match UI */
.navbar { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; padding: 0 20px; height: 64px; background-color: var(--bg-surface); border-bottom: 1px solid var(--border); }
.logo { font-size: 1.25rem; font-weight: 600; display: flex; align-items: center; gap: 8px; }
.badge { font-size: 0.7rem; background: var(--bg-elevated); padding: 3px 8px; border-radius: 12px; font-family: var(--font-mono); border: 1px solid var(--border); }
.match-scoreboard { display: flex; align-items: center; gap: 30px; }
.header-actions { display: flex; gap: 10px; justify-self: end; }
.player { display: flex; align-items: center; gap: 12px; }
.player-info { display: flex; flex-direction: column; gap: 4px; }
.player-info.right { align-items: flex-end; }
.player .name { font-size: 0.85rem; font-weight: 500; }
.player.you .name { color: var(--accent-green); }
.player.opponent .name { color: var(--accent-orange); }
.avatar { width: 36px; height: 36px; border-radius: 50%; border: 2px solid var(--border); }
.progress-bar { width: 100px; height: 6px; background: var(--bg-elevated); border-radius: 3px; overflow: hidden; }
.progress-bar .fill { height: 100%; transition: width 0.3s ease; }
.my-progress { background: var(--accent-green); }
.opp-progress { background: var(--accent-orange); }

.timer-container { display: flex; flex-direction: column; align-items: center; }
#timer { font-family: var(--font-mono); font-size: 1.25rem; font-weight: 600; }
.match-status { font-size: 0.7rem; color: var(--text-secondary); text-transform: uppercase; }

/* Buttons & Layout */
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 8px 16px; border: none; border-radius: var(--radius); font-size: 0.875rem; font-weight: 500; cursor: pointer; transition: 0.2s; font-family: var(--font-sans); }
.btn-primary { background-color: var(--accent-blue); color: #fff; }
.btn-primary:hover { background-color: var(--accent-blue-hover); }
.btn-secondary { background-color: var(--bg-elevated); color: var(--text-primary); border: 1px solid var(--border); }
.btn-secondary:hover { background-color: var(--border); }
.btn-run { background-color: var(--bg-elevated); color: var(--accent-green); border: 1px solid var(--border); }
.icon-btn { background: transparent; color: var(--text-primary); border: none; cursor: pointer; display: flex; }
.editor-header { justify-content: flex-start; }
.editor-actions { margin-left: auto; display: flex; gap: 8px; }

.results-leaderboard {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.leaderboard-head,
.leaderboard-row {
    display: grid;
    grid-template-columns: 56px 1fr 110px 110px;
    align-items: center;
    gap: 10px;
    text-align: left;
}

.leaderboard-head {
    font-size: 0.78rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding: 0 8px;
}

.leaderboard-row {
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 10px 8px;
    background: var(--bg-surface);
}

.leaderboard-row.winner {
    border-color: var(--accent-green);
    box-shadow: inset 0 0 0 1px rgba(16, 185, 129, 0.25);
}

.workspace { display: flex; padding: 12px; gap: 0; height: calc(100vh - 64px); }
.pane { background-color: var(--bg-surface); border: 1px solid var(--border); border-radius: var(--radius); display: flex; flex-direction: column; overflow: hidden; }
.problem-pane { width: 50%; min-width: 280px; }
.editor-pane { width: 50%; min-width: 320px; }
.pane-resizer { background: var(--bg-base); position: relative; z-index: 2; }
.pane-resizer.vertical { width: 10px; margin: 0 6px; border-left: 1px solid var(--border); border-right: 1px solid var(--border); cursor: col-resize; }
.pane-resizer.horizontal { height: 8px; border-top: 1px solid var(--border); border-bottom: 1px solid var(--border); cursor: row-resize; }
.pane-resizer:hover { background: #1f2937; }
.pane-header { background-color: var(--bg-base); border-bottom: 1px solid var(--border); padding: 0 16px; height: 48px; display: flex; align-items: center; justify-content: space-between; }
.tab { color: var(--text-secondary); font-size: 0.875rem; font-weight: 500; padding: 0 4px; height: 100%; display: flex; align-items: center; border-bottom: 2px solid transparent; }
.tab.active { color: var(--text-primary); border-bottom-color: var(--accent-blue); }

.problem-content { padding: 24px; overflow-y: auto; flex: 1; }
.problem-content h1 { font-size: 1.5rem; margin-bottom: 12px; }
.tags { display: flex; gap: 8px; margin-bottom: 24px; }
.tag { font-size: 0.75rem; padding: 4px 10px; border-radius: 12px; background: var(--bg-elevated); }
.tag.easy { color: var(--accent-green); background: rgba(16, 185, 129, 0.1); }
.tag.medium { color: var(--accent-orange); background: rgba(245, 158, 11, 0.1); }
.tag.hard { color: var(--accent-red); background: rgba(239, 68, 68, 0.1); }
.prob-desc { color: #d4d4d8; line-height: 1.6; font-size: 0.95rem; }
.prob-desc pre { background: var(--bg-base); border: 1px solid var(--border); padding: 16px; border-radius: var(--radius); font-family: var(--font-mono); margin: 16px 0; overflow-x: auto; }
.prob-desc code { font-family: var(--font-mono); background: var(--bg-elevated); padding: 2px 6px; border-radius: 4px; }

.lang-dropdown { background: var(--bg-elevated); color: var(--text-primary); border: 1px solid var(--border); padding: 6px; border-radius: 6px; }
.live-status { display: flex; align-items: center; gap: 8px; font-size: 0.8rem; color: var(--text-secondary); }
.status-dot { width: 8px; height: 8px; background: var(--accent-green); border-radius: 50%; }
.blinking { animation: pulse 1.5s infinite; }

#editor-container { flex: 1; overflow: hidden; }
.editor-layout { display: flex; flex-direction: column; flex: 1; min-height: 0; }
.CodeMirror { height: 100% !important; font-family: var(--font-mono) !important; font-size: 14px; background: transparent !important; }
.CodeMirror-gutters { border-right: 1px solid var(--border); background: var(--bg-base); }
.CodeMirror-linenumber { min-width: 32px; padding: 0 10px 0 8px; color: var(--text-secondary); }
.CodeMirror pre.CodeMirror-line,
.CodeMirror pre.CodeMirror-line-like { padding-left: 8px; }

.terminal { flex: 0 0 35%; min-height: 130px; display: flex; flex-direction: column; border-top: 1px solid var(--border); background-color: var(--bg-base); }
.terminal-header { display: flex; justify-content: space-between; align-items: center; padding: 8px 16px; border-bottom: 1px solid var(--border); }
.terminal-content { flex: 1; overflow-y: auto; padding: 16px; font-family: var(--font-mono); font-size: 0.875rem; }
.terminal-tabs { display: flex; gap: 8px; }
.terminal-tab { background: var(--bg-elevated); color: var(--text-primary); border: 1px solid var(--border); padding: 6px 10px; border-radius: 6px; font-size: 0.85rem; cursor: pointer; }
.terminal-tab.active { border-color: var(--accent-blue); box-shadow: inset 0 0 0 1px rgba(59, 130, 246, 0.35); }
.terminal-panel { display: none; }
.terminal-panel.active { display: block; }
.empty-state { color: var(--text-secondary); text-align: center; margin-top: 20px; }
.test-case { background: var(--bg-surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px; margin-bottom: 10px; }
.pass-text { color: var(--accent-green); }
.fail-text { color: var(--accent-red); }

@keyframes pulse { 0% { opacity: 0.4; } 50% { opacity: 1; } 100% { opacity: 0.4; } }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes modalRise { from { transform: translateY(14px); opacity: 0.7; } to { transform: translateY(0); opacity: 1; } }
@keyframes cardIn { from { transform: translateY(6px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

/* Add to existing CSS */
.engine-loading { margin-top: 20px; font-size: 0.85rem; color: var(--accent-orange); text-align: center; font-family: var(--font-mono); }
.lc-badge { background: #ffa116 !important; color: black !important; }

/* Pre-Game Lobby Styles */
.lobby-status-box { background: var(--bg-elevated); padding: 20px; border-radius: var(--radius); border: 1px solid var(--border); margin: 20px 0; text-align: left; display: flex; flex-direction: column; gap: 15px; }
.player-status { display: flex; align-items: center; gap: 10px; font-weight: 500; }
.dot { width: 12px; height: 12px; border-radius: 50%; }
.host-dot { background: var(--accent-green); }
.opp-dot { background: var(--accent-orange); }
.opp-dot.connected { background: var(--accent-blue); animation: none; }

.lobby-problem-box { background: var(--bg-elevated); padding: 20px; border-radius: var(--radius); border: 1px solid var(--border); margin-bottom: 20px; text-align: left; }
.queued-prob { font-size: 1.1rem; font-weight: 600; color: var(--accent-blue); margin: 10px 0; padding: 10px; background: var(--bg-base); border-radius: 6px; border: 1px dashed var(--border); }
.lobby-footer { margin-top: 20px; display: flex; flex-direction: column; align-items: center; gap: 10px; }

.engine-loading { margin-top: 20px; font-size: 0.85rem; color: var(--accent-orange); text-align: center; font-family: var(--font-mono); }
.lc-badge { background: #ffa116 !important; color: black !important; }