.ds-tool {
    max-width: 1440px;
    padding-top: 18px;
}

.ds-tool p {
    padding-inline: 0;
    letter-spacing: 0;
}

.ds-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
    margin-bottom: 16px;
    font-size: 1rem;
    text-align: left;
}

.ds-header h1 {
    margin: 0 0 6px;
    color: var(--text-primary);
    font-size: clamp(1.8rem, 3vw, 2.5rem);
    line-height: 1.1;
}

.ds-header p {
    max-width: 780px;
    margin: 0;
    color: var(--text-secondary);
    font-size: 1rem;
    line-height: 1.45;
}

.course-link {
    flex: 0 0 auto;
    padding: 9px 12px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: var(--surface-elevated);
    color: var(--text-primary);
    font-size: 0.92rem;
    font-weight: 700;
    text-decoration: none;
}

.ds-dashboard {
    display: grid;
    grid-template-columns: minmax(280px, 310px) minmax(0, 1fr) minmax(220px, 260px);
    gap: 12px;
    align-items: start;
}

.control-panel,
.log-panel {
    display: grid;
    gap: 12px;
}

.control-card,
.visual-workspace {
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: var(--surface-color);
    box-shadow: var(--shadow-sm);
}

.control-card {
    padding: 14px;
}

.control-card h2 {
    margin: 0 0 10px;
    color: var(--text-primary);
    font-size: 1rem;
}

.field-label {
    display: block;
    margin-bottom: 6px;
    color: var(--text-secondary);
    font-size: 0.8rem;
    font-weight: 800;
}

.field-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

.type-field {
    display: block;
    margin-top: 10px;
}

.ds-tool select,
.ds-tool input {
    box-sizing: border-box;
    width: 100%;
    min-height: 40px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: var(--surface-elevated);
    color: var(--text-primary);
    padding: 8px 10px;
}

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

.ds-tool button {
    min-height: 40px;
    border-radius: 8px;
}

.action-button,
.ghost-action {
    border: 1px solid var(--border-color);
    background: var(--surface-elevated);
    color: var(--text-primary);
    font-weight: 800;
}

.action-button.primary {
    border-color: var(--primary-color);
    background: var(--primary-color);
    color: #fff;
}

.action-button.danger {
    border-color: rgba(239, 68, 68, 0.55);
    color: #ef4444;
}

.action-button.active {
    box-shadow: 0 0 0 2px var(--primary-light);
    transform: translateY(-1px);
}

.utility-row {
    display: flex;
    gap: 8px;
    margin-top: 10px;
}

.utility-row button {
    flex: 1;
}

.selected-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.selected-heading h2 {
    margin: 0;
}

#selected-type {
    padding: 4px 7px;
    border-radius: 999px;
    background: var(--primary-light);
    color: var(--primary-color);
    font-size: 0.72rem;
    font-weight: 900;
}

.selected-card p {
    min-height: 38px;
    margin: 8px 0 12px;
    color: var(--text-secondary);
    font-size: 0.86rem;
    line-height: 1.35;
}

.selected-card:not(.has-selection) input,
.selected-card:not(.has-selection) button {
    opacity: 0.58;
}

.complexity-list {
    display: grid;
    gap: 8px;
}

.complexity-card {
    display: grid;
    gap: 6px;
    padding: 10px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: var(--surface-elevated);
}

.complexity-card.active {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px var(--primary-light);
}

.complexity-top {
    display: flex;
    justify-content: space-between;
    gap: 10px;
    color: var(--text-primary);
    font-weight: 800;
}

.complexity-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 6px;
}

.complexity-grid span {
    padding: 6px;
    border-radius: 6px;
    background: var(--surface-color);
    color: var(--text-secondary);
    font-size: 0.78rem;
    text-align: center;
}

.visual-workspace {
    min-width: 0;
    padding: 14px;
}

.workspace-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 14px;
    margin-bottom: 12px;
}

.workspace-header h2 {
    margin: 0 0 4px;
    color: var(--text-primary);
    font-size: 1.2rem;
}

.workspace-header p {
    margin: 0;
    color: var(--text-secondary);
    line-height: 1.4;
}

.size-pill {
    flex: 0 0 auto;
    padding: 7px 10px;
    border-radius: 999px;
    background: var(--primary-light);
    color: var(--primary-color);
    font-weight: 900;
}

.visual-stage {
    position: relative;
    min-height: 390px;
    overflow: auto;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background:
        linear-gradient(var(--border-color) 1px, transparent 1px),
        linear-gradient(90deg, var(--border-color) 1px, transparent 1px),
        var(--surface-elevated);
    background-size: 44px 44px;
}

.structure-visual {
    position: relative;
    min-width: 100%;
    min-height: 390px;
    padding: 22px;
}

.link-layer {
    position: absolute;
    inset: 0;
    z-index: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

.ds-node,
.ds-cell,
.bucket-label,
.tree-node,
.graph-node,
.trie-node {
    position: relative;
    z-index: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 48px;
    min-height: 42px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: var(--surface-color);
    color: var(--text-primary);
    font-weight: 900;
    box-shadow: var(--shadow-sm);
    transition: transform 180ms ease, border-color 180ms ease, background 180ms ease;
}

.selectable {
    cursor: pointer;
    gap: 3px;
    flex-direction: column;
    padding: 6px 9px;
    line-height: 1.05;
}

.selectable:hover {
    border-color: var(--primary-color);
    transform: translateY(-2px);
}

.selectable span:first-child {
    max-width: 9ch;
    overflow: hidden;
    text-overflow: ellipsis;
}

.type-badge {
    max-width: 9ch;
    overflow: hidden;
    padding: 2px 5px;
    border-radius: 999px;
    background: var(--surface-elevated);
    color: var(--text-secondary);
    font-size: 0.58rem;
    font-weight: 900;
    text-transform: uppercase;
}

.is-hit,
.is-new {
    border-color: #10b981 !important;
    background: rgba(16, 185, 129, 0.16) !important;
}

.is-scan {
    border-color: var(--primary-color) !important;
    background: var(--primary-light) !important;
    transform: translateY(-2px);
}

.is-remove {
    border-color: #ef4444 !important;
    background: rgba(239, 68, 68, 0.14) !important;
}

.is-selected {
    border-color: #2563eb !important;
    background: rgba(37, 99, 235, 0.13) !important;
    box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.18), var(--shadow-sm);
}

.operation-meter {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 10px;
    margin-top: 12px;
    padding: 12px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: var(--surface-elevated);
}

.operation-meter > div:not(.meter-track) {
    display: grid;
    gap: 3px;
}

.metric-label {
    color: var(--text-secondary);
    font-size: 0.72rem;
    font-weight: 900;
    text-transform: uppercase;
}

.operation-meter strong {
    color: var(--text-primary);
    font-size: 0.95rem;
}

.meter-track {
    grid-column: 1 / -1;
    height: 8px;
    overflow: hidden;
    border-radius: 999px;
    background: var(--surface-color);
}

.meter-track span,
.comparison-track span {
    display: block;
    height: 100%;
    border-radius: inherit;
    background: linear-gradient(90deg, var(--primary-color), #10b981);
}

.array-row,
.list-row,
.queue-row,
.deque-row {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: max-content;
    padding: 44px 16px;
}

.array-item {
    display: grid;
    gap: 6px;
    text-align: center;
}

.index-label,
.role-label {
    color: var(--text-muted);
    font-size: 0.72rem;
    font-weight: 800;
}

.arrow {
    color: var(--primary-color);
    font-weight: 900;
}

.stack-wrap {
    display: flex;
    min-height: 340px;
    align-items: flex-end;
    justify-content: center;
    padding: 28px;
}

.stack-column {
    display: flex;
    flex-direction: column-reverse;
    align-items: stretch;
    gap: 8px;
    width: min(240px, 100%);
}

.stack-cell {
    width: 100%;
}

.bucket-table {
    display: grid;
    gap: 9px;
    min-width: 560px;
    padding: 22px;
}

.bucket-row {
    display: grid;
    grid-template-columns: 72px 1fr;
    gap: 10px;
    align-items: center;
}

.bucket-label {
    min-width: 0;
    min-height: 34px;
    color: var(--text-secondary);
}

.bucket-chain {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    min-height: 42px;
    padding: 7px;
    border: 1px dashed var(--border-color);
    border-radius: 8px;
    background: color-mix(in srgb, var(--surface-color) 72%, transparent);
}

.tree-canvas,
.graph-canvas,
.trie-canvas {
    position: relative;
    min-width: 760px;
    min-height: 390px;
}

.tree-node,
.graph-node,
.trie-node {
    position: absolute;
}

.tree-node {
    width: 62px;
    height: 48px;
}

.heap-array {
    position: absolute;
    left: 22px;
    right: 22px;
    bottom: 18px;
    display: flex;
    gap: 6px;
    overflow-x: auto;
}

.heap-array .ds-cell {
    min-width: 50px;
    min-height: 40px;
    font-size: 0.88rem;
}

.graph-node {
    width: 66px;
    height: 58px;
    border-radius: 8px;
}

.trie-node {
    min-width: 54px;
    height: 44px;
}

.empty-state {
    display: flex;
    min-height: 300px;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    font-weight: 800;
}

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

.insight-grid article {
    padding: 12px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: var(--surface-elevated);
}

.insight-grid h3 {
    margin: 0 0 6px;
    color: var(--text-primary);
    font-size: 0.9rem;
    text-align: left;
}

.insight-grid p {
    margin: 0;
    color: var(--text-secondary);
    font-size: 0.86rem;
    line-height: 1.4;
}

.trace-list {
    display: grid;
    gap: 7px;
    max-height: 360px;
    overflow: auto;
    margin: 0;
    padding-left: 18px;
}

.trace-list li {
    margin: 0;
    color: var(--text-secondary);
    line-height: 1.35;
}

.plan-list {
    max-height: 170px;
}

.comparison-list {
    display: grid;
    gap: 9px;
}

.comparison-row {
    display: grid;
    gap: 6px;
    padding: 9px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: var(--surface-elevated);
}

.comparison-row.active {
    border-color: var(--primary-color);
}

.comparison-row > div:first-child {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.comparison-row strong {
    color: var(--text-primary);
    font-size: 0.86rem;
}

.comparison-row span {
    color: var(--text-secondary);
    font-size: 0.78rem;
    font-weight: 900;
}

.comparison-track {
    height: 7px;
    overflow: hidden;
    border-radius: 999px;
    background: var(--surface-color);
}

#model-view {
    max-height: 240px;
    overflow: auto;
    margin: 0;
    color: var(--text-secondary);
    white-space: pre-wrap;
}

@supports not (color: color-mix(in srgb, white, black)) {
    .bucket-chain {
        background: var(--surface-color);
    }
}

@media (max-width: 1180px) {
    .ds-dashboard {
        grid-template-columns: 320px minmax(0, 1fr);
    }

    .log-panel {
        grid-column: 1 / -1;
        grid-template-columns: 1fr 1fr;
    }
}

@media (max-width: 820px) {
    .ds-header,
    .ds-dashboard,
    .log-panel,
    .insight-grid {
        grid-template-columns: 1fr;
    }

    .ds-header {
        display: grid;
    }

    .course-link {
        width: fit-content;
    }

    .visual-stage,
    .structure-visual {
        min-height: 340px;
    }

    .operation-meter {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (max-width: 520px) {
    .ds-tool {
        padding-inline: 12px;
    }

    .field-grid,
    .action-grid,
    .utility-row {
        grid-template-columns: 1fr;
        display: grid;
    }

    .workspace-header {
        display: grid;
    }

    .size-pill {
        width: fit-content;
    }

    .operation-meter {
        grid-template-columns: 1fr;
    }
}
