:root {
    --bg: #f5f6fa;
    --ink: #101828;
    --muted: #6b7080;
    --accent: #155eef;
    --border: #d8dce6;
    --card: #ffffff;
    --chip-bg: #e6ecff;
    --chip-active-bg: #155eef;
    --chip-active-ink: #fff;
    --winner-bg: #d7f5e3;
    --winner-ink: #025333;
    --warn: #c2410c;
    --model-col: 180px;
    --winner-col: 120px;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font: 13px/1.35 "Inter", "Segoe UI", system-ui, -apple-system, sans-serif;
    background: var(--bg);
    color: var(--ink);
}

header {
    padding: 14px 20px 4px;
    background: var(--card);
    border-bottom: 1px solid var(--border);
}

header h1 {
    margin: 0 0 4px;
    font-size: 20px;
    font-weight: 600;
}

header p {
    margin: 2px 0;
    font-size: 12px;
    color: var(--muted);
}

.controls,
.panel {
    background: var(--card);
    border-bottom: 1px solid var(--border);
    padding: 10px 20px;
}

.controls {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    align-items: flex-start;
}

.control {
    min-width: 200px;
}

.control.grow {
    flex: 1 1 320px;
}

.slider-block {
    min-width: 260px;
}

label {
    display: block;
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--muted);
    margin-bottom: 3px;
}

input[type="text"],
select {
    width: 100%;
    padding: 6px 9px;
    border-radius: 6px;
    border: 1px solid var(--border);
    font-size: 13px;
    background: #fff;
}

.chip-row {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
}

.chip {
    border: none;
    border-radius: 999px;
    padding: 3px 10px;
    font-size: 12px;
    cursor: pointer;
    background: var(--chip-bg);
    color: var(--ink);
}

.chip.active {
    background: var(--chip-active-bg);
    color: var(--chip-active-ink);
}

.chip.small {
    font-size: 11px;
    padding: 3px 8px;
}

.panel.compact {
    padding: 8px 20px;
}

.panel-split {
    display: flex;
    gap: 16px;
    flex-wrap: wrap;
    align-items: center;
}

.backend-list {
    display: flex;
    flex-wrap: wrap;
    gap: 6px 14px;
}

.backend-label {
    display: flex;
    align-items: center;
    gap: 8px;
}

.backend-actions {
    display: flex;
    gap: 6px;
}

.backend-item {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: var(--ink);
    text-transform: none;
}

.backend-item input {
    transform: translateY(1px);
}

.backend-item .tag {
    font-size: 10px;
    padding: 0 6px;
    border-radius: 999px;
    background: #eef2ff;
    color: #1d3ea5;
    transform: translateY(-2px);
}

.backend-item .tag.tag-hblt0 {
    background: #e9edff;
    color: #1d3ea5;
}

.backend-item .tag.tag-rocwmma {
    background: #eef9ff;
    color: #0a517a;
}

.backend-item .tag.tag-rocwmma-improved {
    background: #faf3ff;
    color: #6b1fb7;
}

.backend-item .tag.tag-improved {
    background: #fef9e7;
    color: #8a5a00;
}

.stats-box {
    margin-left: auto;
    display: flex;
    gap: 10px;
    align-items: center;
    font-size: 12px;
    color: var(--muted);
}

#tables {
    display: grid;
    gap: 14px;
}

.test-block h2 {
    margin: 0 0 4px;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--muted);
}


.table-wrap {
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--card);
    position: relative;
    width: 100%;
    max-width: 100%;
    overflow: hidden;
}

.table-scroll {
    overflow-x: auto;
    overflow-y: hidden;
    width: 100%;
    position: relative;
    scrollbar-gutter: stable both-edges;
    display: block;
}

.table-scroll table {
    min-width: 100%;
}

table {
    border-collapse: collapse;
    font-size: 11.5px;
    width: max-content;
    min-width: 100%;
    table-layout: fixed;
}

thead {
    background: #f4f6fb;
}

th,
td {
    padding: 4px 6px;
    border-bottom: 1px solid var(--border);
    white-space: normal;
    border-right: 1px solid var(--border);
    overflow-wrap: anywhere;
}

th {
    position: relative;
    font-weight: 600;
}

th.sticky,
td.sticky {
    position: sticky;
    left: 0;
    background: inherit;
    z-index: 3;
    box-shadow: 1px 0 0 var(--border);
}

th.model,
td.model {
    width: var(--model-col);
    position: sticky;
    left: 0;
    z-index: 3;
    background: #f8f9ff;
}

th.winner,
td.winner {
    width: var(--winner-col);
    position: sticky;
    left: var(--model-col);
    z-index: 3;
    background: #f1f5ff;
}

td.model {
    min-width: 170px;
    font-weight: 500;
}

td.model .model-head {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 6px;
}

.model-pill {
    display: inline-flex;
    align-items: center;
    padding: 2px 8px;
    border-radius: 999px;
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    background: #eceff5;
    color: #27303f;
    border: 1px solid transparent;
}

.model-pill-rpc {
    background: #fdf2f8;
    border-color: #fbcfe8;
    color: #9d174d;
}

.model-pill-rocwmma {
    background: #eef9ff;
    border-color: #c7e9ff;
    color: #0a517a;
}

.legend {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-top: 8px;
}

.legend label {
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--muted);
}

.legend-pills {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.legend-pill {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    border-radius: 999px;
    border: 1px solid transparent;
    background: #e9edff;
    color: var(--ink);
}

.legend-pill-default {
    background: #e9edff;
    color: var(--ink);
}

.legend-pill-rpc {
    background: #fdf2f8;
    border-color: #fbcfe8;
    color: #9d174d;
}

.legend-pill-rocwmma {
    background: #eef9ff;
    border-color: #c7e9ff;
    color: #0a517a;
}

.legend-pill-rocwmma-improved {
    background: #faf3ff;
    border-color: #e0c8ff;
    color: #6b1fb7;
}

.modal.hidden {
    display: none;
}

.modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    z-index: 1000;
}

.modal-content {
    background: #fff;
    border-radius: 12px;
    padding: 20px 24px;
    max-width: 520px;
    width: 100%;
    box-shadow: 0 12px 50px rgba(0, 0, 0, 0.2);
    position: relative;
    font-size: 13px;
    line-height: 1.4;
}

.modal-content h2 {
    margin-top: 0;
    font-size: 16px;
}

.modal-content p {
    margin: 8px 0;
}

.modal-close {
    position: absolute;
    top: 8px;
    right: 10px;
    border: none;
    background: transparent;
    font-size: 20px;
    cursor: pointer;
    color: var(--muted);
}

.modal-close:hover {
    color: var(--ink);
}

.data-cell {
    white-space: normal;
    position: relative;
}

.data-cell[data-env]:hover::after {
    content: attr(data-env);
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    left: 50%;
    transform: translate(-50%, -120%);
    background: rgba(16, 24, 40, 0.92);
    color: #fff;
    padding: 4px 8px;
    border-radius: 6px;
    font-size: 11px;
    white-space: nowrap;
    pointer-events: none;
    z-index: 5;
}

.data-cell[data-env]:hover::before {
    content: "";
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -30%);
    border: 6px solid transparent;
    border-top-color: rgba(16, 24, 40, 0.92);
    pointer-events: none;
    z-index: 5;
}

.data-cell .measure,
.data-cell .std {
    white-space: nowrap;
}

.row-actions {
    display: flex;
    gap: 6px;
    margin-top: 4px;
    flex-wrap: wrap;
}

.row-action-btn {
    border: none;
    background: transparent;
    color: var(--accent);
    font-size: 11px;
    padding: 0;
    cursor: pointer;
    text-decoration: underline;
    text-underline-offset: 2px;
}

.row-action-btn:hover {
    color: #0d3fb8;
}

td.model .meta {
    font-size: 10px;
    color: var(--muted);
}

tbody tr:nth-child(even) td {
    background: #fafbff;
}

.measure {
    font-feature-settings: "tnum";
    font-size: 12px;
    font-weight: 600;
}

.std {
    color: var(--muted);
    font-size: 10px;
}

.winner-list {
    display: flex;
    flex-wrap: wrap;
    gap: 2px;
}

.winner-pill {
    display: inline-flex;
    align-items: center;
    padding: 2px 6px;
    border-radius: 999px;
    font-size: 10px;
    background: #dbeafe;
    color: #1e3a8a;
    margin: 1px;
    white-space: nowrap;
}

.cell-error {
    color: var(--warn);
}

.cell-empty {
    color: #c3c7d1;
}

.best {
    background: var(--winner-bg) !important;
    color: var(--winner-ink);
}

td.best .measure,
td.best .std {
    color: var(--winner-ink);
}

.resize-handle {
    position: absolute;
    top: 0;
    right: 0;
    width: 6px;
    height: 100%;
    cursor: col-resize;
}

.resize-handle::after {
    content: "";
    position: absolute;
    inset: 0;
    background: transparent;
}

th.backend-header {
    cursor: grab;
    white-space: nowrap;
}

th.backend-header.dragging {
    opacity: 0.5;
}

th.backend-header.drop-target {
    outline: 2px dashed var(--accent);
}

.resize-line {
    width: 2px;
    background: var(--accent);
    pointer-events: none;
}

.resize-overlay {
    position: absolute;
    top: 0;
    bottom: 0;
    left: 0;
    right: 0;
    pointer-events: none;
}

.resize-bar {
    position: absolute;
    top: 0;
    bottom: 0;
    width: 6px;
    cursor: col-resize;
    pointer-events: auto;
    background: transparent;
}

.tag {
    display: inline-flex;
    align-items: center;
    padding: 0 6px;
    border-radius: 999px;
    background: #f1f5ff;
    color: #1d4ed8;
    font-size: 11px;
}
.range-wrap {
    position: relative;
    height: 32px;
}

.range-wrap input[type="range"] {
    position: absolute;
    inset: 0;
    width: 100%;
    background: transparent;
    -webkit-appearance: none;
    appearance: none;
    pointer-events: none;
}

.range-wrap input[type="range"]::-webkit-slider-thumb {
    pointer-events: auto;
    -webkit-appearance: none;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--accent);
    border: 2px solid #fff;
    box-shadow: 0 0 3px rgba(0, 0, 0, 0.3);
}

.range-wrap input[type="range"]::-moz-range-thumb {
    pointer-events: auto;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--accent);
    border: 2px solid #fff;
}

.range-track {
    position: absolute;
    top: 50%;
    left: 0;
    right: 0;
    height: 6px;
    border-radius: 999px;
    background: #e3e7f1;
    transform: translateY(-50%);
    pointer-events: none;
}

.range-values {
    font-size: 11px;
    color: var(--muted);
    margin-top: 4px;
}
.modal-content code {
    font-family: "JetBrains Mono", "SFMono-Regular", Consolas, monospace;
    background: #f6f8fc;
    padding: 1px 4px;
    border-radius: 4px;
    font-size: 12px;
}
