/* ===== CodingBat Exercises — Gamified Theme ===== */

:root {
    --bg-primary: #0f0f1a;
    --bg-secondary: #161625;
    --bg-tertiary: #1c1c30;
    --bg-hover: #252540;
    --bg-active: #2a2a4a;
    --bg-sidebar: #12121f;
    --bg-editor: #1a1a2e;
    --bg-console: #141422;
    --border-color: rgba(255, 255, 255, 0.06);
    --border-active: #6c5ce7;
    --text-primary: #c8c8e0;
    --text-secondary: #8888aa;
    --text-bright: #eeeef5;
    --text-muted: #555570;
    --accent: #6c5ce7;
    --accent-light: #a29bfe;
    --accent-glow: rgba(108, 92, 231, 0.3);
    --green: #00b894;
    --green-light: #55efc4;
    --green-bg: rgba(0, 184, 148, 0.1);
    --green-border: rgba(0, 184, 148, 0.3);
    --red: #ff6b6b;
    --red-bg: rgba(255, 107, 107, 0.1);
    --red-border: rgba(255, 107, 107, 0.3);
    --yellow: #ffeaa7;
    --orange: #fdcb6e;
    --pink: #fd79a8;
    --blue: #74b9ff;
    --teal: #81ecec;
    --xp-gradient: linear-gradient(135deg, #6c5ce7, #a29bfe);
    --card-gradient: linear-gradient(135deg, rgba(108, 92, 231, 0.08), rgba(162, 155, 254, 0.04));
    --scrollbar-bg: transparent;
    --scrollbar-thumb: rgba(108, 92, 231, 0.3);
    --font-code: 'JetBrains Mono', 'Fira Code', 'Consolas', monospace;
    --font-ui: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    --radius: 12px;
    --radius-sm: 8px;
    --radius-lg: 16px;
}

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

html,
body {
    height: 100%;
    overflow: hidden;
    font-family: var(--font-ui);
    background: var(--bg-primary);
    color: var(--text-primary);
}

/* ===== Scrollbar ===== */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--scrollbar-thumb);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(108, 92, 231, 0.5);
}

/* ===== Confetti ===== */
#confetti-canvas {
    position: fixed;
    inset: 0;
    z-index: 9999;
    pointer-events: none;
}

/* ===== Top Bar ===== */
.topbar {
    height: 52px;
    background: linear-gradient(180deg, rgba(25, 25, 45, 0.95), rgba(15, 15, 26, 0.98));
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    z-index: 100;
    user-select: none;
    backdrop-filter: blur(20px);
}

.topbar-left {
    display: flex;
    align-items: center;
    gap: 16px;
}

.back-link {
    color: var(--text-secondary);
    font-size: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: var(--radius-sm);
    transition: all 0.2s;
    text-decoration: none;
}

.back-link:hover {
    background: var(--bg-hover);
    color: var(--text-bright);
    transform: translateX(-2px);
}

.topbar-title {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 700;
    font-size: 15px;
    color: var(--text-bright);
}

.topbar-logo {
    font-size: 20px;
}

.topbar-center {
    display: flex;
    align-items: center;
    gap: 16px;
}

.lang-toggle {
    background: rgba(108, 92, 231, 0.1);
    color: var(--accent-light);
    border: 1px solid rgba(108, 92, 231, 0.3);
    padding: 6px 12px;
    border-radius: 20px;
    font-size: 13px;
    font-family: var(--font-main);
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: all 0.2s ease;
}

.lang-toggle:hover {
    background: rgba(108, 92, 231, 0.2);
    transform: translateY(-1px);
}

.xp-display {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 5px 14px;
    border-radius: 20px;
    background: var(--xp-gradient);
    color: white;
    font-weight: 700;
    font-size: 13px;
    box-shadow: 0 2px 12px var(--accent-glow);
    transition: transform 0.2s;
}

.xp-display:hover {
    transform: scale(1.05);
}

.xp-icon {
    font-size: 14px;
}

.streak-display {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 5px 12px;
    border-radius: 20px;
    background: rgba(253, 203, 110, 0.15);
    border: 1px solid rgba(253, 203, 110, 0.2);
    color: var(--orange);
    font-weight: 700;
    font-size: 13px;
}

.streak-icon {
    font-size: 14px;
}

.topbar-right {
    display: flex;
    align-items: center;
}

.pyodide-status {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: var(--text-secondary);
    padding: 5px 12px;
    border-radius: 20px;
    background: rgba(255, 255, 255, 0.04);
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--green);
    transition: background 0.3s;
}

.status-dot.loading {
    background: var(--orange);
    animation: pulse 1.5s ease infinite;
}

.status-dot.error {
    background: var(--red);
}

@keyframes pulse {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0.3;
    }
}

/* ===== App Layout ===== */
.categories-bar {
    height: 56px;
    background: var(--bg-sidebar);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 0 20px;
    overflow-x: auto;
    scrollbar-width: thin;
    scrollbar-color: var(--scrollbar-thumb) transparent;
}

.categories-bar::-webkit-scrollbar {
    height: 4px;
}

.category-tab {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    border-radius: 20px;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid transparent;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
    user-select: none;
}

.category-tab:hover {
    background: var(--bg-hover);
    border-color: rgba(255, 255, 255, 0.1);
}

.category-tab.active {
    background: var(--card-gradient);
    border-color: rgba(108, 92, 231, 0.3);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

.category-tab .cat-emoji {
    font-size: 16px;
}

.category-tab .cat-name {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
}

.category-tab.active .cat-name {
    color: var(--text-bright);
}

.category-tab .cat-progress {
    font-size: 11px;
    color: var(--text-muted);
    background: rgba(0, 0, 0, 0.2);
    padding: 2px 6px;
    border-radius: 10px;
}

.app-layout {
    display: flex;
    height: calc(100vh - 108px);
    /* 52px topbar + 56px categories-bar */
}

/* ===== Sidebar ===== */
.sidebar {
    width: 240px;
    min-width: 240px;
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: transform 0.3s ease;
}

.sidebar-header {
    padding: 18px 18px 14px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.level-badge {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 14px;
    border-radius: 20px;
    background: var(--card-gradient);
    border: 1px solid rgba(108, 92, 231, 0.15);
    width: fit-content;
}

.level-icon {
    font-size: 16px;
}

.level-text {
    font-size: 13px;
    font-weight: 700;
    color: var(--accent-light);
}

.overall-progress {
    display: flex;
    align-items: center;
    gap: 10px;
}

.progress-bar-mini {
    flex: 1;
    height: 6px;
    background: rgba(255, 255, 255, 0.06);
    border-radius: 3px;
    overflow: hidden;
}

.progress-fill-mini {
    height: 100%;
    width: 0%;
    background: var(--xp-gradient);
    border-radius: 3px;
    transition: width 0.5s ease;
}

.progress-text {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    white-space: nowrap;
}

.problems-list-container {
    overflow-y: auto;
    flex: 1;
    padding: 12px;
}

/* ===== Problem List ===== */
.problems-list-container {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.problem-item {
    padding: 10px 14px;
    font-size: 13px;
    cursor: pointer;
    color: var(--text-secondary);
    transition: all 0.15s;
    display: flex;
    align-items: center;
    gap: 8px;
    border-radius: 6px;
    margin: 1px 0;
}

.problem-item:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.problem-item.active {
    background: rgba(108, 92, 231, 0.15);
    color: var(--accent-light);
    border-left: none;
}

.problem-item.solved {
    color: var(--green);
}

.problem-item .solve-icon {
    font-size: 14px;
    flex-shrink: 0;
}

.problem-item.solved .solve-icon {
    color: var(--green-light);
}

/* ===== Main Content ===== */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    overflow: hidden;
}

/* ===== Description Panel ===== */
.description-panel {
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    padding: 16px 24px;
    max-height: 180px;
    overflow-y: auto;
    flex-shrink: 0;
}

/* RTL Support - Mixing LTR Code inside RTL Context */
.rtl-text {
    direction: rtl;
    text-align: right;
    font-family: "Inter", "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
}

.rtl-text code {
    direction: ltr;
    display: inline-block;
    unicode-bidi: bidi-override;
}

.rtl-text .desc-examples {
    direction: ltr;
    text-align: left;
}

.desc-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 8px;
}

.desc-title-row {
    display: flex;
    align-items: center;
    gap: 10px;
}

.problem-emoji {
    font-size: 22px;
}

.desc-header h2 {
    font-size: 18px;
    font-weight: 700;
    color: var(--text-bright);
}

.desc-badges {
    display: flex;
    gap: 8px;
}

.badge-difficulty {
    font-size: 11px;
    padding: 3px 10px;
    border-radius: 20px;
    font-weight: 600;
}

.badge-difficulty.easy {
    background: rgba(0, 184, 148, 0.15);
    color: var(--green-light);
    border: 1px solid var(--green-border);
}

.badge-difficulty.medium {
    background: rgba(253, 203, 110, 0.15);
    color: var(--orange);
    border: 1px solid rgba(253, 203, 110, 0.3);
}

.badge-difficulty.hard {
    background: rgba(255, 107, 107, 0.15);
    color: var(--red);
    border: 1px solid var(--red-border);
}

.badge-tests {
    font-size: 11px;
    padding: 3px 10px;
    border-radius: 20px;
    background: rgba(108, 92, 231, 0.12);
    color: var(--accent-light);
    font-weight: 600;
    border: 1px solid rgba(108, 92, 231, 0.2);
}

.desc-body {
    font-size: 14px;
    line-height: 1.65;
    color: var(--text-primary);
}

.welcome-msg {
    font-size: 15px;
    color: var(--text-secondary);
}

.desc-examples {
    margin-top: 10px;
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.example-chip {
    font-family: var(--font-code);
    font-size: 12px;
    padding: 4px 12px;
    border-radius: 20px;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    transition: all 0.2s;
}

.example-chip:hover {
    background: rgba(108, 92, 231, 0.1);
    border-color: rgba(108, 92, 231, 0.2);
}

.example-chip .arrow {
    color: var(--accent-light);
    margin: 0 4px;
}

.example-chip .expected {
    color: var(--green-light);
    font-weight: 600;
}

/* ===== Workspace ===== */
.workspace {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

/* ===== Editor ===== */
.editor-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 200px;
}

.editor-toolbar {
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--bg-tertiary);
    border-bottom: 1px solid var(--border-color);
    padding: 0 12px;
}

.toolbar-tabs {
    display: flex;
    align-items: center;
    height: 100%;
}

.toolbar-tab {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 0 14px;
    height: 100%;
    font-size: 13px;
    color: var(--text-primary);
    font-weight: 500;
}

.toolbar-tab.active {
    background: var(--bg-editor);
    color: var(--text-bright);
    border-top: 2px solid var(--accent);
}

.tab-icon {
    font-size: 16px;
}

.toolbar-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.btn-reset {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 5px 12px;
    border: 1px solid var(--border-color);
    background: transparent;
    color: var(--text-secondary);
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 12px;
    font-family: var(--font-ui);
    transition: all 0.2s;
}

.btn-reset:hover {
    background: var(--bg-hover);
    color: var(--text-bright);
    border-color: rgba(255, 255, 255, 0.12);
}

.btn-run {
    display: flex;
    align-items: center;
    gap: 7px;
    padding: 6px 18px;
    border: none;
    background: var(--xp-gradient);
    color: white;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 13px;
    font-weight: 700;
    font-family: var(--font-ui);
    transition: all 0.2s;
    box-shadow: 0 2px 10px var(--accent-glow);
}

.btn-run:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 16px rgba(108, 92, 231, 0.5);
}

.btn-run:active {
    transform: translateY(0);
}

.btn-run.running {
    opacity: 0.7;
    pointer-events: none;
}

.btn-run i {
    font-size: 11px;
}

#monaco-editor {
    flex: 1;
    min-height: 0;
}

/* ===== Console ===== */
.console-container {
    height: 200px;
    min-height: 120px;
    display: flex;
    flex-direction: column;
    border-top: 1px solid var(--border-color);
}

.console-header {
    height: 34px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--bg-tertiary);
    padding: 0 14px;
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
}

.console-tab {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: var(--text-primary);
    font-weight: 600;
}

.btn-clear-console {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 26px;
    height: 26px;
    border: none;
    background: transparent;
    color: var(--text-muted);
    border-radius: 6px;
    cursor: pointer;
    font-size: 11px;
    transition: all 0.15s;
}

.btn-clear-console:hover {
    background: var(--bg-hover);
    color: var(--text-secondary);
}

.console-output {
    flex: 1;
    overflow-y: auto;
    padding: 10px 14px;
    font-family: var(--font-code);
    font-size: 11px;
    line-height: 1.5;
    background: var(--bg-console);
    display: flex;
    flex-direction: column;
}

.test-results-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(360px, 1fr));
    gap: 12px;
    margin-bottom: 14px;
}

.console-placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--text-muted);
    text-align: center;
    gap: 6px;
}

.placeholder-icon {
    font-size: 30px;
}

.console-placeholder p {
    font-family: var(--font-ui);
    font-size: 13px;
}

.placeholder-hint {
    font-size: 12px !important;
    color: var(--text-muted) !important;
}

kbd {
    display: inline-block;
    padding: 2px 8px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    font-family: var(--font-ui);
    font-size: 11px;
    color: var(--accent-light);
}

/* ===== Test Results ===== */
.test-line {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 6px 12px;
    border-radius: var(--radius-sm);
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    animation: slideIn 0.25s ease;
}

.test-line.test-pass {
    background: rgba(85, 239, 196, 0.05);
    border-color: rgba(85, 239, 196, 0.2);
}

.test-line.test-fail {
    background: rgba(255, 107, 107, 0.05);
    border-color: rgba(255, 107, 107, 0.2);
}

.test-line.test-error {
    background: rgba(253, 203, 110, 0.05);
    border-color: rgba(253, 203, 110, 0.2);
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateX(-8px);
    }

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

.test-line .icon {
    flex-shrink: 0;
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    font-size: 14px;
    background: rgba(255, 255, 255, 0.05);
}

.test-pass .icon {
    background: rgba(85, 239, 196, 0.15);
    color: var(--green-light);
}

.test-fail .icon {
    background: rgba(255, 107, 107, 0.15);
    color: var(--red);
}

.test-error .icon {
    background: rgba(253, 203, 110, 0.15);
    color: var(--orange);
}

.test-line .detail {
    flex: 1;
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 6px;
    font-size: 13px;
    color: var(--text-primary);
}

.test-line code {
    background: rgba(0, 0, 0, 0.25);
    padding: 3px 8px;
    border-radius: 6px;
    color: var(--text-bright);
}

.test-pass .detail {
    color: var(--text-bright);
}

.test-fail .detail {
    color: var(--text-bright);
}

.test-error .detail {
    color: var(--text-bright);
}

.expected-box,
.actual-box {
    display: inline-flex;
    align-items: center;
    padding: 2px 8px;
    border-radius: 4px;
    font-family: var(--font-code);
    font-weight: 600;
}

.expected-box {
    background: rgba(85, 239, 196, 0.1);
    color: var(--green-light);
    border: 1px dashed var(--green-border);
}

.actual-box {
    background: rgba(255, 107, 107, 0.1);
    color: var(--red);
    border: 1px dashed var(--red-border);
}

.test-summary {
    margin-top: 14px;
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    font-family: var(--font-ui);
    font-weight: 700;
    font-size: 14px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.test-summary.all-pass {
    color: var(--green-light);
    background: var(--green-bg);
    border: 1px solid var(--green-border);
}

.test-summary.has-fail {
    color: var(--red);
    background: var(--red-bg);
    border: 1px solid var(--red-border);
}

.test-summary i {
    font-size: 18px;
}

.xp-earned {
    margin-left: auto;
    font-size: 13px;
    padding: 2px 10px;
    border-radius: 12px;
    background: var(--xp-gradient);
    color: white;
    animation: popIn 0.4s ease;
}

@keyframes popIn {
    0% {
        transform: scale(0.5);
        opacity: 0;
    }

    70% {
        transform: scale(1.15);
    }

    100% {
        transform: scale(1);
        opacity: 1;
    }
}

/* ===== Sidebar Toggle (Mobile) ===== */
.sidebar-toggle {
    display: none;
    position: fixed;
    top: 60px;
    left: 8px;
    z-index: 200;
    width: 38px;
    height: 38px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-color);
    background: var(--bg-tertiary);
    color: var(--text-primary);
    font-size: 16px;
    cursor: pointer;
    align-items: center;
    justify-content: center;
    transition: all 0.15s;
}

.sidebar-toggle:hover {
    background: var(--bg-hover);
}

/* ===== Responsive ===== */
@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        top: 52px;
        left: 0;
        height: calc(100vh - 52px);
        z-index: 150;
        transform: translateX(-100%);
        box-shadow: 4px 0 24px rgba(0, 0, 0, 0.5);
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .sidebar-toggle {
        display: flex;
    }

    .topbar-title span {
        display: none;
    }

    .description-panel {
        padding: 12px 16px;
    }

    .xp-display,
    .streak-display {
        display: none;
    }
}

/* ===== XP Animation ===== */
.xp-float {
    position: fixed;
    z-index: 9998;
    font-weight: 800;
    font-size: 18px;
    color: var(--accent-light);
    pointer-events: none;
    animation: floatUp 1.2s ease-out forwards;
    text-shadow: 0 0 10px var(--accent-glow);
}

@keyframes floatUp {
    0% {
        opacity: 1;
        transform: translateY(0) scale(1);
    }

    100% {
        opacity: 0;
        transform: translateY(-60px) scale(1.3);
    }
}