:root {
    --bg: #e8edf1;
    --surface: #f7f9fb;
    --ink: #16212b;
    --muted: #5b6875;
    --line: #c8d1d9;
    --edge: #93a1ae;
    --trust: #3a3fd0;
    --trust-soft: #3a3fd01f;
    --seed: #c98a0e;
    --error: #b8412f;
    --focus: #3a3fd0;
    color-scheme: light;
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --bg: #0f151b;
        --surface: #151e27;
        --ink: #e3e9ee;
        --muted: #8d9aa6;
        --line: #2a3642;
        --edge: #4b5a68;
        --trust: #8e93ff;
        --trust-soft: #8e93ff24;
        --seed: #f0b43c;
        --error: #ef7b66;
        --focus: #8e93ff;
        color-scheme: dark;
    }
}

:root[data-theme="dark"] {
    --bg: #0f151b;
    --surface: #151e27;
    --ink: #e3e9ee;
    --muted: #8d9aa6;
    --line: #2a3642;
    --edge: #4b5a68;
    --trust: #8e93ff;
    --trust-soft: #8e93ff24;
    --seed: #f0b43c;
    --error: #ef7b66;
    --focus: #8e93ff;
    color-scheme: dark;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--ink);
    font: 400 15px/1.5 "Schibsted Grotesk", system-ui, sans-serif;
    display: flex;
    flex-direction: column;
}

a { color: inherit; }

:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

button, select, input, textarea { font: inherit; color: inherit; }

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 20px;
}

.brand {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 700;
    font-size: 17px;
    letter-spacing: -0.01em;
    text-decoration: none;
}
.brand-seed { fill: var(--seed); }
.brand-trust { fill: var(--trust); }
.brand-edge { stroke: var(--trust); stroke-width: 2.5; }

.links { display: flex; align-items: center; gap: 20px; }
.profiles { display: flex; align-items: center; gap: 14px; padding-left: 20px; border-left: 1px solid var(--line); }
.icon-link { display: inline-flex; padding: 2px; }
.icon-link svg { display: block; }
.links a { color: var(--muted); text-decoration: none; }
.links a:hover { color: var(--ink); }

.app {
    flex: 1;
    min-height: 0;
    display: grid;
    grid-template-columns: minmax(0, 1fr) 380px;
    gap: 0;
}

/* stage */

.stage { position: relative; min-height: 0; overflow: hidden; }

#graph { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; cursor: default; }

.intro {
    position: absolute;
    top: 8px;
    left: 20px;
    max-width: 30rem;
    pointer-events: none;
    z-index: 1;
}
.intro h1 {
    margin: 0 0 6px;
    font-size: clamp(26px, 3.2vw, 40px);
    line-height: 1.05;
    letter-spacing: -0.025em;
    font-weight: 700;
    text-wrap: balance;
}
.intro p { margin: 0; color: var(--muted); max-width: 26rem; }

.stage-note {
    position: absolute;
    inset: 50% auto auto 50%;
    transform: translate(-50%, -50%);
    max-width: 22rem;
    text-align: center;
    color: var(--muted);
    z-index: 1;
}

.stage-tools {
    position: absolute;
    left: 20px;
    bottom: 16px;
    display: flex;
    gap: 8px;
    z-index: 1;
}

.legend {
    position: absolute;
    right: 20px;
    bottom: 20px;
    display: flex;
    gap: 16px;
    font-size: 13px;
    color: var(--muted);
    z-index: 1;
}
.legend span { display: flex; align-items: center; gap: 6px; }
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.dot.seed { border: 2.5px solid var(--seed); }
.dot.trust { background: var(--trust); }
.legend .line { width: 18px; height: 2px; background: var(--edge); display: inline-block; }

/* buttons */

button, .file {
    border: 1px solid var(--line);
    background: var(--surface);
    border-radius: 999px;
    padding: 6px 14px;
    cursor: pointer;
    font-size: 14px;
    line-height: 1.4;
}
button:hover, .file:hover { border-color: var(--muted); }
button.primary { background: var(--trust); border-color: var(--trust); color: #fff; font-weight: 600; }
button.primary:hover { filter: brightness(1.08); }
button:disabled { opacity: .55; cursor: progress; }
button.link { border: 0; background: none; padding: 0; color: var(--trust); border-radius: 0; }

.file input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.file { position: relative; font-size: 13px; padding: 2px 10px; }
.file:focus-within { outline: 2px solid var(--focus); outline-offset: 2px; }

/* panel */

.panel {
    background: var(--surface);
    border-left: 1px solid var(--line);
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.tabs { display: flex; gap: 4px; padding: 12px 16px 0; border-bottom: 1px solid var(--line); }
.tabs button {
    border: 0;
    border-bottom: 2px solid transparent;
    border-radius: 0;
    background: none;
    padding: 8px 10px 10px;
    color: var(--muted);
    font-weight: 500;
}
.tabs button[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--trust); }

.view { padding: 16px 20px; overflow-y: auto; flex: 1; min-height: 0; }

.field { margin-bottom: 18px; }
.field > label, .field-row label:first-child { display: block; font-weight: 600; margin-bottom: 6px; }
.field-row { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.alpha-sym { font-weight: 400; color: var(--muted); }
output { font-weight: 600; color: var(--trust); }

select {
    width: 100%;
    padding: 7px 10px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--bg);
}

input[type="range"] { width: 100%; accent-color: var(--trust); }

.hint { color: var(--muted); font-size: 13.5px; margin: 6px 0 0; }
.hint code, .selected code { font: 12.5px "JetBrains Mono", ui-monospace, monospace; }

textarea {
    width: 100%;
    font: 12.5px/1.55 "JetBrains Mono", ui-monospace, monospace;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--bg);
    padding: 10px;
    resize: vertical;
}

.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.error { color: var(--error); font-size: 14px; }

/* selected peer */

.selected {
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 12px 14px;
    margin-bottom: 18px;
    background: var(--bg);
}
.selected h3 { margin: 0; font-size: 17px; }
.selected .sel-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; margin-bottom: 8px; }
.selected .sel-score { color: var(--trust); font-weight: 600; }
.selected .sel-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 10px; }
.selected .sel-actions button { font-size: 13px; padding: 3px 11px; }
.selected .seed-on { border-color: var(--seed); color: var(--seed); font-weight: 600; }
.selected h4 { margin: 8px 0 4px; font-size: 13px; color: var(--muted); font-weight: 500; }
.edges { list-style: none; margin: 0; padding: 0; }
.edges li { display: grid; grid-template-columns: 1fr 64px auto; gap: 8px; align-items: center; padding: 3px 0; }
.edges input { width: 64px; padding: 2px 6px; border: 1px solid var(--line); border-radius: 6px; background: var(--surface); }
.edges button { border: 0; background: none; color: var(--muted); padding: 2px 4px; font-size: 13px; }
.edges button:hover { color: var(--error); }
.add-edge { display: flex; gap: 6px; margin-top: 8px; }
.add-edge select { flex: 1; padding: 4px 8px; }
.add-edge button { font-size: 13px; padding: 3px 11px; }
.empty-note { color: var(--muted); font-size: 13.5px; margin: 2px 0; }

/* ranking */

.ranking-head { display: flex; justify-content: space-between; align-items: baseline; margin-top: 6px; }
.ranking-head h2 { font-size: 15px; margin: 0 0 6px; }
.stats { color: var(--muted); font-size: 13px; }

.ranking { list-style: none; margin: 0; padding: 0; }
.ranking li button {
    width: 100%;
    display: grid;
    grid-template-columns: 26px 1fr 90px 64px;
    align-items: center;
    gap: 8px;
    border: 0;
    border-radius: 6px;
    background: none;
    padding: 4px 6px;
    text-align: left;
    font-size: 14px;
}
.ranking li button:hover, .ranking li button.is-selected { background: var(--trust-soft); }
.ranking .rank { color: var(--muted); font-size: 12.5px; }
.ranking .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ranking .name.is-seed::after { content: ""; display: inline-block; width: 7px; height: 7px; margin-left: 6px; border-radius: 50%; border: 2px solid var(--seed); vertical-align: 1px; }
.ranking .bar { height: 6px; border-radius: 3px; background: var(--line); overflow: hidden; }
.ranking .bar i { display: block; height: 100%; background: var(--trust); border-radius: 3px; transition: width .35s ease; }
.ranking .score { text-align: right; font-size: 13px; }
.ranking-more { color: var(--muted); font-size: 13px; padding: 6px; }

.bench-out { margin-top: 18px; }
.bench-out .big { font-size: 34px; font-weight: 700; letter-spacing: -0.02em; line-height: 1.1; }
.bench-out p { margin: 4px 0 12px; color: var(--muted); }

.engine { border-top: 1px solid var(--line); padding: 10px 20px; color: var(--muted); font-size: 13px; }

@media (max-width: 860px) {
    html, body { height: auto; }
    .app { display: block; }
    .stage { height: 68vh; min-height: 460px; }
    .panel { border-left: 0; border-top: 1px solid var(--line); }
    .view { overflow: visible; }
    .intro { left: 16px; right: 16px; }
    .intro p { font-size: 14px; }
    .stage-tools { left: 16px; bottom: 12px; }
    .legend { display: none; }
    .topbar { padding: 12px 16px; }
    .view { flex: none; }
}

@media (prefers-reduced-motion: reduce) {
    .ranking .bar i { transition: none; }
}
