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

:root {
    --bg: #1f1d19;
    --bg-accent: #2a271f;
    --panel: rgba(43, 40, 35, 0.9);
    --panel-strong: rgba(36, 34, 30, 0.96);
    --border: rgba(255, 255, 255, 0.1);
    --text: #f1ede4;
    --muted: #a9a293;
    --bar: #726f67;
    --compare: #4687f4;
    --swap: #ef4d4d;
    --sorted: #2fd06b;
    --shadow: 0 18px 50px rgba(0, 0, 0, 0.28);
}

body {
    min-height: 100vh;
    overflow-x: hidden;
    background:
        radial-gradient(circle at top left, rgba(137, 110, 58, 0.08), transparent 38%),
        radial-gradient(circle at bottom right, rgba(255, 255, 255, 0.04), transparent 30%),
        linear-gradient(180deg, #24211c 0%, var(--bg) 100%);
    color: var(--text);
    font-family: Bahnschrift, "Trebuchet MS", "Segoe UI", sans-serif;
}

button,
input,
output {
    font: inherit;
}

button {
    cursor: pointer;
    border: 1px solid var(--border);
    color: var(--text);
    background: rgba(255, 255, 255, 0.02);
    transition: transform 0.18s ease, border-color 0.18s ease, background-color 0.18s ease;
}

button:hover:not(:disabled) {
    transform: translateY(-1px);
    border-color: rgba(255, 255, 255, 0.2);
    background: rgba(255, 255, 255, 0.06);
}

button:disabled {
    opacity: 0.65;
    cursor: not-allowed;
}

.app-shell {
    width: min(1240px, calc(100% - 32px));
    margin: 0 auto;
    padding: 28px 0 36px;
}

.topbar {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 24px;
    padding-bottom: 20px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.09);
}

.brand-line {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 12px;
}

.brand h1 {
    font-size: clamp(2rem, 2.6vw, 2.6rem);
    line-height: 1;
    letter-spacing: -0.04em;
}

.brand p {
    color: var(--muted);
    font-size: 1.05rem;
}

.algorithm-nav {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 10px;
    width: min(860px, 100%);
    align-items: stretch;
}

.nav-pill {
    width: 100%;
    min-height: 76px;
    padding: 14px 18px;
    border-radius: 16px;
    font-size: 1.45rem;
    font-weight: 700;
    background: var(--panel-strong);
    text-align: center;
    white-space: normal;
    overflow-wrap: anywhere;
}

.nav-pill.is-active,
.tab-btn.is-active {
    border-color: rgba(255, 255, 255, 0.28);
    background: rgba(255, 255, 255, 0.08);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.06);
}

.dashboard {
    display: grid;
    grid-template-columns: minmax(0, 1.55fr) minmax(320px, 1fr);
    gap: 20px;
    padding-top: 20px;
}

.left-column {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.panel {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 22px;
    box-shadow: var(--shadow);
}

.visualizer-panel {
    padding: 18px 18px 14px;
}

.visualizer-container {
    height: 360px;
    display: flex;
    align-items: flex-end;
    gap: 6px;
    padding: 18px 8px 0;
    overflow: hidden;
}

.bar {
    flex: 1 1 0;
    min-width: 22px;
    border-radius: 10px 10px 4px 4px;
    background: linear-gradient(180deg, #7a766e 0%, #5f5b55 100%);
    position: relative;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    padding-top: 10px;
    color: rgba(255, 255, 255, 0.74);
    font-size: 0.88rem;
    font-weight: 700;
    letter-spacing: 0.02em;
    transition: height 0.18s ease, background 0.18s ease, transform 0.18s ease, box-shadow 0.18s ease;
}

.bar.is-comparing {
    background: linear-gradient(180deg, #5e99ff 0%, #3670d4 100%);
    box-shadow: 0 0 0 1px rgba(102, 163, 255, 0.22);
    transform: translateY(-3px);
}

.bar.is-swapping {
    background: linear-gradient(180deg, #ff6d6d 0%, #d84141 100%);
    box-shadow: 0 0 0 1px rgba(255, 110, 110, 0.2);
    transform: translateY(-4px);
}

.bar.is-sorted {
    background: linear-gradient(180deg, #4de28a 0%, #22bb62 100%);
    box-shadow: 0 0 0 1px rgba(77, 226, 138, 0.22);
}

.bar-value {
    pointer-events: none;
    opacity: 0.88;
}

.legend {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 18px;
    padding: 14px 8px 0;
    color: #d5d0c6;
}

.legend-item {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-size: 0.95rem;
}

.legend-swatch {
    width: 12px;
    height: 12px;
    border-radius: 2px;
    display: inline-block;
}

.legend-swatch.comparing {
    background: var(--compare);
}

.legend-swatch.swapping {
    background: var(--swap);
}

.legend-swatch.sorted {
    background: var(--sorted);
}

.legend-swatch.default {
    background: var(--bar);
}

.controls-panel {
    padding: 16px 18px 18px;
}

.learning-panel {
    padding: 16px 18px 18px;
    border-color: rgba(255, 255, 255, 0.08);
}

.learning-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 16px;
}

.learning-eyebrow {
    color: #e7d59b;
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.learning-status {
    display: block;
    margin-top: 6px;
    font-size: 1.05rem;
}

.learning-toggle {
    min-width: 200px;
}

.learning-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 14px;
}

.learning-tag {
    display: inline-flex;
    align-items: center;
    min-height: 34px;
    padding: 0 12px;
    border-radius: 999px;
    border: 1px solid rgba(255, 255, 255, 0.08);
    background: rgba(255, 255, 255, 0.04);
    color: #ddd6c7;
    font-size: 0.92rem;
    font-weight: 700;
}

.learning-copy {
    margin-top: 14px;
    color: #ded7ca;
    font-size: 1rem;
    line-height: 1.6;
}

.learning-panel[data-tone="compare"] .learning-tag:first-child {
    border-color: rgba(94, 153, 255, 0.34);
    background: rgba(94, 153, 255, 0.14);
}

.learning-panel[data-tone="swap"] .learning-tag:first-child,
.learning-panel[data-tone="overwrite"] .learning-tag:first-child {
    border-color: rgba(255, 109, 109, 0.34);
    background: rgba(255, 109, 109, 0.14);
}

.learning-panel[data-tone="complete"] .learning-tag:first-child {
    border-color: rgba(77, 226, 138, 0.34);
    background: rgba(77, 226, 138, 0.14);
}

.learning-panel[data-tone="overview"] .learning-tag:first-child {
    border-color: rgba(231, 213, 155, 0.3);
    background: rgba(231, 213, 155, 0.11);
}

.actions-row {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
}

.control-btn {
    min-width: 132px;
    min-height: 52px;
    padding: 0 18px;
    border-radius: 14px;
    background: var(--panel-strong);
    font-size: 1.05rem;
    font-weight: 700;
}

.control-btn.primary {
    background: rgba(255, 255, 255, 0.07);
}

.range-row {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 24px;
    margin-top: 12px;
}

.range-group {
    display: grid;
    grid-template-columns: auto 1fr auto;
    align-items: center;
    gap: 10px;
}

.range-group label {
    color: var(--muted);
    font-weight: 700;
}

.range-group output {
    min-width: 30px;
    color: #dcd6c9;
    font-weight: 700;
}

input[type="range"] {
    width: 100%;
    accent-color: #8c877c;
}

.stats-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) minmax(0, 1.9fr);
    gap: 16px;
}

.stat-card,
.complexity-card {
    padding: 16px 18px;
}

.stat-card strong {
    display: block;
    margin-top: 8px;
    font-size: 3rem;
    line-height: 1;
}

.card-label {
    color: #cfc8bb;
    font-size: 0.95rem;
}

.complexity-card {
    grid-column: span 1;
}

.complexity-values {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 12px;
    margin-top: 12px;
}

.complexity-values span {
    display: block;
    color: var(--muted);
    margin-bottom: 2px;
}

.complexity-values strong {
    font-size: 1.55rem;
}

.scroll-cue {
    width: 52px;
    height: 52px;
    margin: -4px auto 0;
    display: grid;
    place-items: center;
    border: 1px solid rgba(255, 255, 255, 0.14);
    border-radius: 999px;
    color: #cbc4b7;
    font-size: 1.6rem;
    background: rgba(255, 255, 255, 0.03);
}

.code-panel {
    display: flex;
    flex-direction: column;
    padding: 18px;
    min-height: 100%;
}

.language-tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.tab-btn {
    flex: 1 1 120px;
    min-height: 44px;
    border-radius: 12px;
    background: var(--panel-strong);
    font-size: 0.98rem;
    font-weight: 700;
}

.snippet-shell {
    margin-top: 16px;
    border-radius: 16px;
    background: rgba(18, 18, 18, 0.28);
    border: 1px solid rgba(255, 255, 255, 0.05);
    padding: 0;
    flex: 1 1 auto;
    min-height: 420px;
    overflow: hidden;
}

.code-snippet {
    height: 100%;
    padding: 18px;
    overflow: auto;
    white-space: pre;
    color: #f4eee1;
    font-size: 0.96rem;
    line-height: 1.6;
    font-family: Consolas, "Courier New", monospace;
    max-width: 100%;
    word-break: break-word;
}

.tip-box {
    margin-top: 14px;
    padding-top: 14px;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.tip-title {
    color: #e7d59b;
    font-size: 0.9rem;
    text-transform: lowercase;
}

.tip-copy {
    margin-top: 8px;
    color: #d9d1c2;
    font-size: 1rem;
    line-height: 1.5;
}

.code-snippet::-webkit-scrollbar {
    width: 10px;
}

.code-snippet::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.05);
}

.code-snippet::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.25);
    border-radius: 999px;
}

@media (max-width: 1080px) {
    .topbar {
        flex-direction: column;
    }

    .algorithm-nav {
        width: 100%;
    }

    .dashboard {
        grid-template-columns: 1fr;
    }

    .code-panel {
        min-height: 680px;
    }
}

@media (max-width: 760px) {
    .app-shell {
        width: min(100%, calc(100% - 20px));
        padding-top: 18px;
    }

    .left-column,
    .visualizer-panel,
    .visualizer-container,
    .code-panel,
    .snippet-shell {
        min-width: 0;
    }

    .brand-line {
        gap: 8px;
    }

    .brand p {
        font-size: 0.95rem;
    }

    .algorithm-nav {
        grid-template-columns: 1fr;
        gap: 8px;
    }

    .nav-pill {
        min-height: 56px;
        padding: 12px 14px;
        font-size: 1rem;
        line-height: 1.3;
    }

    .visualizer-container {
        height: 280px;
        gap: 4px;
        padding-inline: 0;
    }

    .bar {
        min-width: 0;
        flex: 1 1 0;
        font-size: 0.72rem;
        padding-top: 8px;
    }

    .range-row,
    .stats-grid,
    .complexity-values {
        grid-template-columns: 1fr;
    }

    .range-group {
        grid-template-columns: auto 1fr auto;
    }

    .actions-row,
    .language-tabs {
        flex-direction: column;
    }

    .learning-header {
        flex-direction: column;
    }

    .control-btn,
    .tab-btn {
        min-width: 0;
        width: 100%;
    }

    .snippet-shell {
        min-height: 340px;
    }

    .code-snippet {
        white-space: pre-wrap;
    }
}
