/* ================================================================
   ВИЗУАЛИЗАТОР АЛГОРИТМОВ
   Отдельный файл — не смешивать с tools.css
   ================================================================ */

:root {
    --av-bar:         #6B3FA0;
    --av-bar-2:       #7E4FB5;
    --av-compare:     #FFD23F;
    --av-swap:        #E85D75;
    --av-sorted:      #C6F432;
    --av-pf-start:    #43A047;
    --av-pf-end:      #E53935;
    --av-pf-wall:     #2A1745;
    --av-pf-visited:  #B39DDB;
    --av-pf-frontier: #FFD54F;
    --av-pf-path:     #FFD23F;
    --av-pf-empty:    #FAF6F0;
}

.av-root {
    padding: 28px 32px;
}

@media (max-width: 640px) {
    .av-root { padding: 18px 14px; }
}

/* ============================================================
   ТАБЫ
   ============================================================ */
.av-tabs {
    display: flex;
    gap: 6px;
    margin-bottom: 22px;
    padding: 5px;
    background: var(--cream, #FAF6F0);
    border: 1px solid var(--line, #E8E2DA);
    border-radius: 999px;
    width: fit-content;
    max-width: 100%;
}

.av-tab {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 20px;
    border: none;
    background: transparent;
    border-radius: 999px;
    font-family: 'Manrope', sans-serif;
    font-size: 14px;
    font-weight: 600;
    color: #6B6470;
    cursor: pointer;
    transition: background .2s, color .2s;
    white-space: nowrap;
}

.av-tab:hover {
    color: #2A1745;
}

.av-tab.is-active {
    background: #2A1745;
    color: #FFD23F;
}

.av-tab__icon {
    font-size: 16px;
    line-height: 1;
}

@media (max-width: 480px) {
    .av-tabs { width: 100%; }
    .av-tab { flex: 1; justify-content: center; padding: 10px 12px; font-size: 13px; }
    .av-tab__icon { display: none; }
}

/* ============================================================
   ПАНЕЛЬ
   ============================================================ */
.av-panel[hidden] { display: none; }

/* ============================================================
   ТУЛБАР
   ============================================================ */
.av-toolbar {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 14px;
    align-items: end;
    margin-bottom: 18px;
    padding: 18px 20px;
    background: #FAF6F0;
    border: 1px solid #E8E2DA;
    border-radius: 16px;
}

@media (max-width: 640px) {
    .av-toolbar {
        grid-template-columns: 1fr;
        padding: 14px;
    }
}

.av-control {
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-width: 0;
}

.av-control label {
    font-family: 'JetBrains Mono', monospace;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: .1em;
    color: #2A1745;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.av-control label span {
    color: #6B3FA0;
    font-weight: 700;
}

.av-control select {
    width: 100%;
    padding: 10px 14px;
    border: 1.5px solid #E8E2DA;
    background: #fff;
    border-radius: 10px;
    font-family: 'Manrope', sans-serif;
    font-size: 14px;
    color: #1A1420;
    outline: none;
    cursor: pointer;
    transition: border-color .2s;
}

.av-control select:focus {
    border-color: #6B3FA0;
}

.av-control input[type="range"] {
    width: 100%;
    accent-color: #6B3FA0;
    cursor: pointer;
}

.av-control--check {
    justify-content: flex-end;
}

.av-check {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 14px;
    border: 1.5px solid #E8E2DA;
    background: #fff;
    border-radius: 10px;
    cursor: pointer;
    font-family: 'Manrope', sans-serif;
    font-size: 14px;
    font-weight: 500;
    color: #1A1420;
    transition: border-color .2s, background .2s;
    margin: 0;
}

.av-check:hover {
    border-color: #6B3FA0;
}

.av-check:has(input:checked) {
    background: #EDE4FF;
    border-color: #6B3FA0;
    font-weight: 600;
}

.av-check input[type="checkbox"] {
    width: 16px;
    height: 16px;
    accent-color: #6B3FA0;
    cursor: pointer;
}

.av-buttons {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    grid-column: 1 / -1;
    justify-content: flex-end;
}

@media (max-width: 640px) {
    .av-buttons {
        justify-content: stretch;
    }
    .av-buttons .btn {
        flex: 1;
        min-width: 0;
        padding: 11px 14px;
        font-size: 13.5px;
    }
}

.av-buttons .btn {
    padding: 11px 20px;
    font-size: 14px;
}

/* ============================================================
   СТАТИСТИКА
   ============================================================ */
.av-stats {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
    margin-bottom: 18px;
}

@media (max-width: 640px) {
    .av-stats { grid-template-columns: repeat(2, 1fr); }
}

.av-stat {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 12px 14px;
    background: #fff;
    border: 1px solid #E8E2DA;
    border-radius: 12px;
    text-align: center;
}

.av-stat__label {
    font-family: 'JetBrains Mono', monospace;
    font-size: 10.5px;
    text-transform: uppercase;
    letter-spacing: .1em;
    color: #6B6470;
}

.av-stat__value {
    font-family: 'Fraunces', serif;
    font-weight: 900;
    font-size: 22px;
    line-height: 1.1;
    letter-spacing: -.02em;
    color: #2A1745;
    font-variant-numeric: tabular-nums;
}

.av-stat__value--text {
    font-family: 'Manrope', sans-serif;
    font-size: 14px;
    font-weight: 700;
    padding-top: 4px;
}

/* ============================================================
   СОРТИРОВКИ — КАНВА
   ============================================================ */
.av-sort-canvas {
    position: relative;
    width: 100%;
    aspect-ratio: 16 / 8;
    min-height: 280px;
    max-height: 460px;
    background: linear-gradient(180deg, #FFFFFF 0%, #FAF6F0 100%);
    border: 1px solid #E8E2DA;
    border-radius: 16px;
    padding: 16px;
    margin-bottom: 14px;
    overflow: hidden;
}

.av-sort-bars {
    position: relative;
    width: 100%;
    height: 100%;
}

.av-bar {
    position: absolute;
    bottom: 0;
    background: var(--av-bar);
    border-radius: 3px 3px 0 0;
    transition: left .12s ease, height .12s ease, background .12s ease;
    will-change: left, height, background;
}

.av-bar[data-state="compare"] {
    background: var(--av-compare);
    box-shadow: 0 0 12px rgba(255, 210, 63, .6);
}

.av-bar[data-state="swap"] {
    background: var(--av-swap);
    box-shadow: 0 0 12px rgba(232, 93, 117, .6);
}

.av-bar[data-state="sorted"] {
    background: var(--av-sorted);
    box-shadow: 0 0 8px rgba(198, 244, 50, .4);
}

/* ============================================================
   ЛЕГЕНДА
   ============================================================ */
.av-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 14px 20px;
    padding: 10px 4px;
    font-size: 13px;
    color: #6B6470;
}

.av-legend__item {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    white-space: nowrap;
}

.av-legend__item i {
    display: inline-block;
    width: 14px;
    height: 14px;
    border-radius: 4px;
    border: 1px solid rgba(0, 0, 0, .06);
}

/* ============================================================
   ПОИСК ПУТИ — СЕТКА
   ============================================================ */
.av-pf-grid-wrap {
    width: 100%;
    padding: 12px;
    background: linear-gradient(180deg, #FFFFFF 0%, #FAF6F0 100%);
    border: 1px solid #E8E2DA;
    border-radius: 16px;
    margin-bottom: 14px;
    overflow-x: auto;
}

.av-pf-grid {
    display: grid;
    gap: 1px;
    background: #E8E2DA;
    width: 100%;
    max-width: 900px;
    margin: 0 auto;
    aspect-ratio: 30 / 18;
    user-select: none;
    touch-action: none;
}

.av-pf-cell {
    background: var(--av-pf-empty, #FAF6F0);
    transition: background .15s;
    cursor: crosshair;
}

.av-pf-cell:hover {
    background: #EDE4FF;
}

.av-pf-cell[data-state="wall"] {
    background: var(--av-pf-wall, #2A1745);
}

.av-pf-cell[data-state="start"] {
    background: var(--av-pf-start, #43A047);
    box-shadow: inset 0 0 0 2px #2E7D32;
}

.av-pf-cell[data-state="end"] {
    background: var(--av-pf-end, #E53935);
    box-shadow: inset 0 0 0 2px #B71C1C;
}

.av-pf-cell[data-state="visited"] {
    background: var(--av-pf-visited, #B39DDB);
    animation: avCellPop .3s ease;
}

.av-pf-cell[data-state="path"] {
    background: var(--av-pf-path, #FFD23F);
    box-shadow: inset 0 0 0 1px #F57F17;
    animation: avCellPop .25s ease;
}

.av-pf-cell[data-state="frontier"] {
    background: var(--av-pf-frontier, #FFD54F);
}

@keyframes avCellPop {
    0%   { transform: scale(.4); border-radius: 50%; }
    100% { transform: scale(1); border-radius: 0; }
}

@media (max-width: 640px) {
    .av-pf-grid-wrap { padding: 8px; }
}

/* ============================================================
   ПОДСКАЗКА
   ============================================================ */
.av-hint {
    padding: 12px 16px;
    background: #FFF8E1;
    border-left: 4px solid #FFD23F;
    border-radius: 10px;
    font-size: 13.5px;
    line-height: 1.5;
    color: #1A1420;
    margin: 0;
}

.av-hint b {
    color: #2A1745;
}

/* ============================================================
   ПЕЧАТЬ
   ============================================================ */
@media print {
    .av-toolbar,
    .av-tabs,
    .av-buttons,
    .tool-details,
    .cell--wide,
    .cell--section-title .tag,
    .cell--section-title p,
    .cell--section-title a {
        display: none !important;
    }
}