:root {
    --page-bg: #0b0e12;
    --panel-bg: rgba(24, 27, 30, 0.92);
    --panel-bg-strong: rgba(17, 19, 22, 0.94);
    --panel-border: rgba(255, 255, 255, 0.08);
    --text-main: #f4f6f8;
    --text-muted: #aeb8c2;
    --accent: #5fd2a7;
    --accent-strong: #27b985;
    --accent-soft: rgba(95, 210, 167, 0.18);
    --start-color: #2fe08c;
    --step-color: #4ea6ff;
    --path-color: #ffd166;
    --end-color: #ff5d73;
    --empty-color: #edf2f5;
    --wall-color: #181b1f;
    --grid-color: rgba(12, 15, 18, 0.2);
}

body {
    margin: 0;
    font-family: Poppins, sans-serif;
    color: var(--text-main);
    min-height: 100vh;
    overflow: hidden;
    background-color: var(--page-bg);
}

body::before {
    content: "";
    position: fixed;
    inset: 0;
    pointer-events: none;
    background:
        linear-gradient(rgba(255, 255, 255, 0.03) 1px, transparent 1px),
        linear-gradient(90deg, rgba(255, 255, 255, 0.03) 1px, transparent 1px);
    background-size: 48px 48px;
    opacity: 0.22;
}

.workspace-header {
    position: sticky;
    top: 0;
    z-index: 20;
    background: transparent;
}

.workspace-topbar {
    display: block;
    padding: 20px 28px 10px;
}

.workspace-heading {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    gap: 18px;
    align-items: center;
}

.back-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    min-height: 0;
    padding: 0;
    color: var(--text-main);
    text-decoration: none;
    font-size: 1rem;
    font-weight: 700;
    background: transparent;
    border: none;
    margin-top: 0;
}

.back-link::before {
    content: "<";
    font-size: 0.94rem;
}

.back-link:hover {
    color: var(--text-main);
    opacity: 0.72;
}

.workspace-copy {
    display: grid;
    gap: 0;
    max-width: 760px;
}

.group-label {
    display: inline-block;
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--text-muted);
    letter-spacing: 0.02em;
    margin-bottom: 2px;
}

.workspace-copy h1 {
    margin: 0;
    font-size: clamp(2.3rem, 3vw, 3.6rem);
    line-height: 1;
    letter-spacing: -0.03em;
}

.tool-strip,
.toggle-strip {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px;
}

.workspace-toolbar {
    padding: 0 28px 14px;
}

.toolbar-grid {
    list-style: none;
    display: grid;
    grid-template-columns: 220px minmax(320px, 1.2fr) minmax(360px, 1fr) 320px;
    gap: 0;
    margin: 0;
    padding: 14px 0 16px;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    background: transparent;
}

.control-group {
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 0 18px;
    min-width: 0;
    background: transparent;
    border: none;
    border-radius: 0;
}

.control-group + .control-group {
    border-left: 1px solid rgba(255, 255, 255, 0.06);
}

.action-group {
    margin-left: 0;
}

.nav-link,
.run-btn,
.toggle-card,
.dropdown-item {
    transition:
        background 160ms ease,
        border-color 160ms ease,
        color 160ms ease,
        box-shadow 160ms ease;
}

.nav-link {
    min-height: 48px;
    padding: 0 16px !important;
    margin: 0;
    border-radius: 2px;
    background: var(--panel-bg-strong);
    border: 1px solid rgba(255, 255, 255, 0.08);
    box-sizing: border-box;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    text-decoration: none;
    color: var(--text-main) !important;
    font-size: 0.91rem;
    font-weight: 600;
    letter-spacing: 0.01em !important;
}

.nav-link:hover {
    background: rgba(255, 255, 255, 0.08);
    border-color: rgba(255, 255, 255, 0.16);
}

.nav-link.active {
    background: rgba(95, 210, 167, 0.16);
    border-color: rgba(95, 210, 167, 0.45);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.04);
}

.algorithm-dropdown {
    position: relative;
}

.draw-group .tool-strip {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
}

.draw-group .nav-link {
    width: 100%;
}

.algorithm-dropdown .nav-link {
    gap: 10px;
    justify-content: space-between;
}

.algorithm-dropdown .dropdown-toggle::after {
    margin-left: 10px;
}

.control-label {
    margin-right: 0;
    color: var(--text-muted);
    font-size: 0.82rem;
    font-weight: 600;
    letter-spacing: 0.04em;
}

.pill {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 34px;
    padding: 0 12px;
    border-radius: 2px;
    background: rgba(255, 255, 255, 0.08);
    color: var(--text-main);
    font-size: 0.82rem;
    font-weight: 700;
}

.dropdown-menu {
    min-width: 100%;
    margin-top: 8px !important;
    padding: 8px;
    border-radius: 2px;
    border: 1px solid rgba(255, 255, 255, 0.08);
    background: rgba(18, 21, 24, 0.98);
    box-shadow: 0 10px 24px rgba(0, 0, 0, 0.24);
}

.dropdown-item {
    border-radius: 2px;
    color: var(--text-main);
    font-size: 0.96rem;
    font-weight: 600;
    padding: 10px 12px;
}

.dropdown-item:hover,
.dropdown-item:focus {
    color: var(--text-main);
    background: rgba(255, 255, 255, 0.08);
}

.slider-item {
    display: flex;
    align-items: center;
    gap: 12px;
    min-height: 48px;
    padding: 0 14px;
    border-radius: 2px;
    background: var(--panel-bg-strong);
    border: 1px solid rgba(255, 255, 255, 0.08);
}

.slider-wrap {
    display: flex;
    align-items: center;
    gap: 10px;
}

.slider-wrap input[type=range] {
    width: 180px;
    cursor: pointer;
    accent-color: var(--accent);
}

#speedValue {
    flex: 0 0 52px;
    width: 52px;
    text-align: center;
}

.toggle-card {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    min-height: 48px;
    padding: 0 14px;
    border-radius: 2px;
    background: var(--panel-bg-strong);
    border: 1px solid rgba(255, 255, 255, 0.08);
    cursor: pointer;
}

.toggle-card:hover {
    background: rgba(255, 255, 255, 0.08);
    border-color: rgba(255, 255, 255, 0.14);
}

.form-check-input {
    width: 42px;
    height: 22px;
    margin: 0;
    cursor: pointer;
    background-color: rgba(255, 255, 255, 0.2);
    border-color: rgba(255, 255, 255, 0.16);
    border-radius: 2px !important;
}

.form-check-input:checked {
    background-color: var(--accent);
    border-color: var(--accent);
}

.form-check-input:focus {
    box-shadow: 0 0 0 0.22rem rgba(95, 210, 167, 0.16);
}

.tool-strip-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    width: 100%;
    justify-content: flex-start;
}

.tool-strip-actions .nav-link,
.tool-strip-actions .run-btn {
    width: 100%;
}

.run-btn {
    display: inline-flex;
    align-items: center;
    gap: 12px;
    min-height: 48px;
    padding: 0 22px;
    border: 1px solid rgba(95, 210, 167, 0.32);
    border-radius: 2px;
    background: var(--accent);
    color: #08110c;
    font-size: 1rem;
    font-weight: 700;
    letter-spacing: 0.02em;
}

.run-btn .run-icon {
    flex: 0 0 18px;
    width: 18px;
    height: 18px;
    display: block;
    position: relative;
}

.run-btn:hover {
    background: var(--accent-strong);
}

.run-btn .run-icon::before {
    content: "";
    position: absolute;
    left: 50%;
    top: 50%;
    width: 16px;
    height: 16px;
    transform: translate(-50%, -50%);
    box-sizing: border-box;
    background: #ffffff;
    clip-path: polygon(0% 0%, 100% 50%, 0% 100%);
    transition: background 0.2s ease, clip-path 0.2s ease, border-radius 0.2s ease, border 0.2s ease, transform 0.2s ease;
    border-radius: 4px;
}

.run-btn.running {
    background: var(--panel-bg-strong);
    color: #d7f3e6;
    border-color: rgba(95, 210, 167, 0.36);
    box-shadow: none;
}

.run-btn.running .run-icon::before {
    background: transparent;
    border: 3px solid var(--accent);
    border-top-color: transparent;
    border-radius: 50%;
    clip-path: none;
    animation: spin 0.8s linear infinite;
}

.run-btn.running:hover .run-icon::before {
    animation: none;
    border: none;
    background: #ff7a7a;
    width: 14px;
    height: 14px;
    clip-path: inset(0 round 999px);
}

.run-text {
    letter-spacing: 0.02em;
}

.board-shell {
    display: flex;
    justify-content: center;
    align-items: flex-start;
    padding: 4px 0 6px;
}

table {
    display: table;
    border-collapse: separate;
    border-spacing: 1px;
}

#board {
    background: rgba(255, 255, 255, 0.05);
    padding: 9px;
    border-radius: 4px;
    box-shadow:
        0 12px 30px rgba(0, 0, 0, 0.22),
        inset 0 1px 0 rgba(255, 255, 255, 0.08);
    clip-path: inset(0 round 4px);
    animation: board-fade 520ms ease;
}

tr {
    display: table-row;
    box-sizing: border-box;
}

td {
    width: var(--board-cell-size, 30px);
    height: var(--board-cell-size, 30px);
    display: table-cell;
    border: none !important;
    background: var(--empty-color);
    box-shadow: inset 0 0 0 1px var(--grid-color);
}

.active-tick::after {
    content: "\2713";
    font-family: "Shantell Sans";
    float: right;
}

#algorithmDropdown:focus {
    outline: none;
    box-shadow: none;
}

.empty-node {
    background-color: var(--empty-color);
}

.wall-node {
    background-color: var(--wall-color);
    animation-name: path-pulse;
    animation-duration: 0.42s;
    animation-iteration-count: 1;
}

.start-node {
    background-color: var(--start-color);
    animation-name: path-pulse;
    animation-duration: 0.42s;
    animation-iteration-count: 1;
}

.end-node {
    background-color: var(--end-color);
    animation-name: path-pulse;
    animation-duration: 0.42s;
    animation-iteration-count: 1;
}

.path-node {
    background-color: var(--path-color);
    animation-name: path-pulse;
    animation-duration: 0.42s;
    animation-iteration-count: 1;
}

.step-node {
    background-color: var(--step-color);
    animation-name: step-pulse;
    animation-duration: 0.36s;
    animation-iteration-count: 1;
}

.maze-static-node {
    animation: none !important;
}

@keyframes spin {
    from { transform: translate(-50%, -50%) rotate(0deg); }
    to { transform: translate(-50%, -50%) rotate(360deg); }
}

@keyframes header-rise {
    from {
        opacity: 0;
        transform: translateY(-12px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

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

@keyframes step-pulse {
    0% { transform: scale(0.94); filter: brightness(0.9); }
    55% { transform: scale(1.12); filter: brightness(1.05); }
    100% { transform: scale(1); filter: brightness(1); }
}

@keyframes path-pulse {
    0% { transform: scale(0.9); }
    55% { transform: scale(1.12); }
    100% { transform: scale(1); }
}

@media (max-width: 1180px) {
    .toolbar-grid {
        grid-template-columns: 1fr 1fr;
    }

    .control-group + .control-group {
        border-left: none;
    }

    .control-group:nth-child(n + 2) {
        border-top: 1px solid rgba(255, 255, 255, 0.06);
    }

    .control-group:nth-child(2) {
        border-top: none;
        border-left: 1px solid rgba(255, 255, 255, 0.06);
    }

    .control-group:nth-child(4) {
        border-left: 1px solid rgba(255, 255, 255, 0.06);
    }

    .action-group {
        margin-left: 0;
    }
}

@media (max-width: 880px) {
    body {
        overflow: auto;
    }

    .workspace-topbar,
    .workspace-toolbar {
        padding-left: 18px;
        padding-right: 18px;
    }

    .workspace-heading {
        grid-template-columns: 1fr;
        gap: 14px;
    }

    .workspace-copy {
        width: 100%;
    }

    .draw-group .tool-strip {
        display: flex;
    }

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

    .control-group,
    .action-group {
        width: 100%;
    }

    .control-group:nth-child(2),
    .control-group:nth-child(4) {
        border-left: none;
    }

    .control-group:nth-child(n + 2) {
        border-top: 1px solid rgba(255, 255, 255, 0.06);
    }

    .tool-strip-actions {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        justify-content: flex-start;
    }

    .slider-item {
        width: 100%;
        justify-content: space-between;
    }

    .slider-wrap {
        width: min(100%, 320px);
        justify-content: flex-end;
    }

    .slider-wrap input[type=range] {
        width: min(100%, 180px);
    }

    .board-shell {
        padding-top: 12px;
    }
}

@media (max-width: 560px) {
    .workspace-topbar {
        padding-top: 16px;
        padding-bottom: 10px;
    }

    .back-link {
        margin-top: 0;
        width: auto;
        justify-content: flex-start;
    }

    .workspace-copy h1 {
        font-size: 1.85rem;
        line-height: 1.02;
    }

    .tool-strip,
    .toggle-strip {
        width: 100%;
    }

    .tool-strip .nav-link,
    .toggle-card,
    .run-btn {
        flex: 1 1 140px;
    }

    .tool-strip-actions {
        width: 100%;
    }

    .slider-item {
        flex-direction: column;
        align-items: flex-start;
        padding: 12px 14px;
    }

    .slider-wrap {
        width: 100%;
        justify-content: space-between;
    }

    #board {
        padding: 10px;
        border-radius: 4px;
        clip-path: inset(0 round 4px);
    }
}
