/*
    EyePop brand, dark. Colours and type from www.eyepop.ai's stylesheet:
    navy #0b0a33 (primary-1), call-to-action #1d47b3 / #3963ce, deep sky blue
    #30a7d7, secondary #8fdfff, neutral #9aa3bc; Poppins for headings and
    controls, Nunito for text; the 90deg #1d47b3 -> #30a7d7 gradient.
 */
:root {
    --navy: #0b0a33;
    --cta: #1d47b3;
    --cta-2: #3963ce;
    --sky: #30a7d7;
    --secondary: #8fdfff;
    --gradient: linear-gradient(90deg, #1d47b3, #30a7d7);

    --page: #020110; /* behind the panels: darker than anything in them */
    --bg: #07062a;
    --surface: #0f0e3d;
    --surface-2: #16154c;
    --surface-3: #1e1d5c;
    --border: #28276b;
    --border-strong: #3a3a86;
    --text: #f3f5ff;
    --muted: #9aa3bc;
    --faint: #6c7393;
    --accent: #30a7d7;
    --accent-soft: rgba(48, 167, 215, 0.14);
    --danger: #ff6b7f;
    --danger-soft: rgba(255, 107, 127, 0.14);
    --warn: #ffc65c;
    --warn-soft: rgba(255, 198, 92, 0.14);
    --ok: #4ade80;

    --t-inference: #30a7d7;
    --t-tracking: #b48cff;
    --t-forward: #9aa3bc;
    --t-contour_finder: #ff9f5c;
    --t-component_finder: #ff7cc1;

    --radius: 14px;
    --radius-sm: 8px;
    --pill: 2rem;
    --mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    --heading: Poppins, system-ui, sans-serif;
    --body: Nunito, system-ui, sans-serif;
    --header-h: 56px;
    --footer-h: 28px;
    color-scheme: dark;
}

* {
    box-sizing: border-box;
}

html,
body,
#root {
    height: 100%;
    margin: 0;
}

body {
    background: var(--page);
    color: var(--text);
    font: 14px/1.45 var(--body);
    overflow: hidden;
}

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

[hidden] {
    display: none !important;
}

h1,
h2,
h3,
h4 {
    font-family: var(--heading);
    font-weight: 600;
    margin: 0;
}

a {
    color: var(--secondary);
}

code,
.mono {
    font-family: var(--mono);
    font-size: 12px;
}

/* --- buttons ------------------------------------------------------------ */

.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    border: 1px solid var(--border-strong);
    background: var(--surface-2);
    border-radius: var(--pill);
    padding: 5px 14px;
    font-family: var(--heading);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    white-space: nowrap;
    transition: background 0.12s, border-color 0.12s;
}

.btn:hover:not(:disabled) {
    background: var(--surface-3);
    border-color: var(--sky);
}

.btn:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

.btn.primary {
    background: var(--gradient);
    border-color: transparent;
    color: #fff;
}

.btn.primary:hover:not(:disabled) {
    filter: brightness(1.12);
}

.btn.ghost {
    background: transparent;
    border-color: transparent;
}

.btn.ghost:hover:not(:disabled) {
    background: var(--surface-2);
    border-color: var(--border);
}

.btn.danger {
    color: var(--danger);
}

.btn.small {
    padding: 2px 10px;
    font-size: 12px;
}

.icon-btn {
    display: inline-grid;
    place-items: center;
    width: 30px;
    height: 30px;
    border-radius: var(--radius-sm);
    border: 1px solid transparent;
    background: transparent;
    cursor: pointer;
    color: var(--muted);
}

.icon-btn:hover:not(:disabled) {
    background: var(--surface-2);
    border-color: var(--border);
    color: var(--text);
}

.icon-btn.active {
    color: var(--secondary);
    background: var(--accent-soft);
    border-color: var(--sky);
}

.icon-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.icon-btn svg,
.btn svg {
    width: 16px;
    height: 16px;
    flex: none;
}

/* --- app frame ------------------------------------------------------------ */

.app {
    display: grid;
    grid-template-rows: var(--header-h) 1fr var(--footer-h);
    height: 100%;
}

.header {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 0 16px;
    background: var(--navy);
    border-bottom: 1px solid var(--border);
}

.header .logo {
    height: 26px;
}

.header .title {
    font-family: var(--heading);
    font-weight: 500;
    color: var(--muted);
    font-size: 15px;
    padding-left: 14px;
    border-left: 1px solid var(--border-strong);
}

.header .spacer {
    flex: 1;
}

.segmented {
    display: inline-flex;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--pill);
    padding: 3px;
    gap: 2px;
}

.segmented button {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    border: 0;
    background: transparent;
    padding: 4px 12px;
    border-radius: var(--pill);
    cursor: pointer;
    color: var(--muted);
    font-family: var(--heading);
    font-size: 12px;
}

.segmented button svg {
    width: 16px;
    height: 16px;
}

.segmented button.on {
    background: var(--gradient);
    color: #fff;
}

.segmented button:hover:not(.on) {
    color: var(--text);
}

.apply-group {
    display: flex;
    align-items: center;
    gap: 8px;
}

.apply-group .apply-error {
    max-width: 320px;
}

.error-badge {
    display: inline-block;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    cursor: help;
}

.error-badge.run-error {
    max-width: 50%;
}

.error-pop {
    border-color: rgba(255, 107, 127, 0.5);
}

.error-pop p {
    margin: 0;
    white-space: pre-wrap;
    word-break: break-word;
}

.apply-btn .dirty-dot {
    background: #fff;
    box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.25);
}

.pane-head .apply-group {
    margin-left: 4px;
    padding-left: 10px;
    border-left: 1px solid var(--border);
}

.dirty-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--warn);
    box-shadow: 0 0 0 3px var(--warn-soft);
}

.env-badge {
    font-family: var(--heading);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    padding: 2px 8px;
    border-radius: var(--pill);
    border: 1px solid var(--border-strong);
    color: var(--muted);
}

.env-badge.staging {
    color: var(--warn);
    border-color: var(--warn);
}

.footer {
    display: flex;
    align-items: center;
    gap: 18px;
    padding: 0 16px;
    font-size: 12px;
    color: var(--muted);
    background: var(--navy);
    border-top: 1px solid var(--border);
    white-space: nowrap;
    overflow: hidden;
}

.footer .err {
    color: var(--danger);
    overflow: hidden;
    text-overflow: ellipsis;
}

.footer .spacer {
    flex: 1;
}

.status-dot {
    display: inline-block;
    width: 7px;
    height: 7px;
    border-radius: 50%;
    margin-right: 6px;
    background: var(--faint);
}

.status-dot.ok {
    background: var(--ok);
}

.status-dot.busy {
    background: var(--sky);
    animation: pulse 1s infinite;
}

.status-dot.error {
    background: var(--danger);
}

@keyframes pulse {
    50% {
        opacity: 0.3;
    }
}

/* --- main area & panes ------------------------------------------------------ */

.main {
    position: relative;
    min-height: 0;
    display: flex;
    padding: 10px;
    gap: 0;
}

.split {
    flex: 1;
    display: flex;
    min-width: 0;
    min-height: 0;
}

.split > .pane-slot {
    min-width: 0;
    min-height: 0;
    display: flex;
}

.splitter {
    flex: none;
    width: 10px;
    cursor: col-resize;
    position: relative;
}

.splitter::after {
    content: '';
    position: absolute;
    left: 4px;
    top: 30%;
    bottom: 30%;
    width: 2px;
    border-radius: 2px;
    background: var(--border);
}

.splitter:hover::after,
.splitter.dragging::after {
    background: var(--sky);
}

.pane {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    min-height: 0;
    background: var(--surface);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius);
    box-shadow: 0 0 0 1px rgba(143, 223, 255, 0.04), 0 10px 32px rgba(0, 0, 0, 0.55);
    overflow: hidden;
}

.pane-head {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 8px 6px 14px;
    min-height: 44px;
    border-bottom: 1px solid var(--border);
    background: var(--surface);
}

.pane-head h2 {
    font-size: 14px;
    font-weight: 600;
}

.pane-head .spacer {
    flex: 1;
}

.pane-body {
    flex: 1;
    min-height: 0;
    position: relative;
    display: flex;
}

.badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    font-size: 11px;
    font-family: var(--heading);
    padding: 2px 9px;
    border-radius: var(--pill);
    border: 1px solid var(--border-strong);
    color: var(--muted);
    white-space: nowrap;
}

.badge.ok {
    color: var(--ok);
    border-color: rgba(74, 222, 128, 0.45);
}

.badge.warn {
    color: var(--warn);
    border-color: rgba(255, 198, 92, 0.5);
    background: var(--warn-soft);
}

.badge.error {
    color: var(--danger);
    border-color: rgba(255, 107, 127, 0.5);
    background: var(--danger-soft);
}

/* layout 3: floating preview */

.floating {
    position: absolute;
    z-index: 30;
    display: flex;
    min-width: 360px;
    min-height: 280px;
    box-shadow: 0 18px 50px rgba(0, 0, 0, 0.55);
    border-radius: var(--radius);
    resize: both;
    overflow: hidden;
}

.floating .pane-head {
    cursor: move;
}

.floating-launcher {
    position: absolute;
    right: 22px;
    bottom: 22px;
    z-index: 30;
}

/* --- sign in ------------------------------------------------------------- */

.signin {
    height: 100%;
    display: grid;
    place-items: center;
    background: radial-gradient(1200px 600px at 20% -10%, rgba(48, 167, 215, 0.18), transparent), radial-gradient(900px 500px at 110% 120%, rgba(29, 71, 179, 0.3), transparent), var(--bg);
}

.signin-card {
    width: min(440px, calc(100vw - 32px));
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 32px;
    display: grid;
    gap: 18px;
}

.signin-card .logo {
    height: 34px;
}

.signin-card h1 {
    font-size: 22px;
}

.signin-card p {
    margin: 0;
    color: var(--muted);
}

.signin-card .btn.primary {
    justify-content: center;
    padding: 10px 18px;
    font-size: 15px;
}

details.token summary {
    cursor: pointer;
    color: var(--muted);
    font-size: 12px;
}

/* --- form controls --------------------------------------------------------- */

.field {
    display: grid;
    gap: 4px;
}

.field > label,
.field-label {
    font-size: 12px;
    color: var(--muted);
    font-family: var(--heading);
    display: flex;
    align-items: center;
    gap: 6px;
}

.field .hint {
    font-size: 11px;
    color: var(--faint);
}

.input,
.select,
.textarea {
    width: 100%;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 6px 9px;
    outline: none;
    min-width: 0;
}

.input:focus,
.select:focus,
.textarea:focus {
    border-color: var(--sky);
    box-shadow: 0 0 0 3px var(--accent-soft);
}

.input.invalid,
.textarea.invalid {
    border-color: var(--danger);
}

.textarea {
    font-family: var(--mono);
    font-size: 12px;
    resize: vertical;
    min-height: 70px;
}

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

.row > * {
    min-width: 0;
}

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

.grid4 {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
}

.check {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    font-size: 13px;
}

.check input {
    accent-color: var(--sky);
}

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

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

.chips {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
}

.chip {
    border: 1px solid var(--border-strong);
    background: var(--surface-2);
    border-radius: var(--pill);
    padding: 1px 9px;
    font-size: 12px;
    cursor: pointer;
    color: var(--muted);
}

.chip.on {
    background: var(--accent-soft);
    border-color: var(--sky);
    color: var(--secondary);
}

.chip .x {
    margin-left: 4px;
    opacity: 0.7;
}

.section {
    border-top: 1px solid var(--border);
    padding: 12px 14px;
    display: grid;
    gap: 10px;
}

.section > h3,
.section > summary {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--faint);
    font-weight: 600;
    font-family: var(--heading);
}

details.section > summary {
    cursor: pointer;
    list-style: none;
}

details.section > summary::before {
    content: '▸ ';
}

details.section[open] > summary::before {
    content: '▾ ';
}

details.section[open] > summary {
    margin-bottom: 4px;
}

.note {
    font-size: 12px;
    color: var(--muted);
    margin: 0;
}

.issue-list {
    display: grid;
    gap: 4px;
    margin: 0;
    padding: 0;
    list-style: none;
}

.issue {
    font-size: 12px;
    padding: 4px 8px;
    border-radius: 6px;
    display: flex;
    gap: 6px;
    cursor: default;
}

.issue.error {
    background: var(--danger-soft);
    color: var(--danger);
}

.issue.warning {
    background: var(--warn-soft);
    color: var(--warn);
}

.issue[role='button'] {
    cursor: pointer;
}

.issue .where {
    color: var(--faint);
    font-family: var(--mono);
    font-size: 11px;
}

/* --- graph editor --------------------------------------------------------- */

.graph-wrap {
    flex: 1;
    display: flex;
    min-width: 0;
    min-height: 0;
    position: relative;
}

/*
    The details of the selection float in the canvas's top-right corner:
    a compact bar when collapsed, a panel down the right side when expanded.
 */

.details {
    position: absolute;
    top: 10px;
    right: 10px;
    z-index: 10;
    display: flex;
    flex-direction: column;
    max-width: calc(100% - 200px);
    max-height: calc(100% - 20px);
    background: rgba(15, 14, 61, 0.96);
    border: 1px solid var(--border-strong);
    border-radius: 12px;
    box-shadow: 0 14px 40px rgba(0, 0, 0, 0.45);
    backdrop-filter: blur(6px);
}

.details.open {
    width: 360px;
    max-width: calc(100% - 20px);
}

.details-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 5px 6px 5px 4px;
    min-height: 44px;
}

.details-bar .spacer {
    flex: 1;
}

.details-toggle {
    display: flex;
    align-items: center;
    gap: 7px;
    background: none;
    border: 0;
    padding: 4px 6px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    min-width: 0;
    flex: 0 1 auto;
    white-space: nowrap;
}

.details-toggle:hover {
    background: var(--surface-2);
}

.details-toggle strong {
    font-family: var(--heading);
    font-weight: 600;
}

.details-toggle .chevron {
    color: var(--faint);
    width: 10px;
}

.details-toggle .sub {
    color: var(--muted);
    font-size: 12px;
    overflow: hidden;
    text-overflow: ellipsis;
    display: none;
}

.details.open .details-bar {
    flex-wrap: wrap;
}

.details.open .details-toggle .sub {
    display: inline;
}

.details-primary {
    flex: 1 1 220px;
    width: 260px;
    min-width: 160px;
}

.details.open .details-primary {
    width: auto;
    flex-basis: 100%;
    order: 5;
    padding: 0 6px 4px;
}

.details-primary .field {
    gap: 0;
}

.details-body {
    overflow-y: auto;
    min-height: 0;
    border-top: 1px solid var(--border);
}

.details-body > .section:first-child {
    border-top: 0;
}

.path-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: grid;
    gap: 4px;
}

.path-item {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 4px 8px;
    cursor: pointer;
    text-align: left;
    font-size: 12px;
}

.path-item:hover {
    border-color: var(--sky);
}

.graph-canvas {
    flex: 1;
    min-width: 0;
    position: relative;
}

.palette {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 5px;
    max-width: 100%;
    padding: 5px;
    background: rgba(15, 14, 61, 0.88);
    border: 1px solid var(--border);
    border-radius: 12px;
    backdrop-filter: blur(4px);
}

.palette-item {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 3px 10px 3px 6px;
    border-radius: var(--pill);
    border: 1px dashed var(--border-strong);
    background: var(--surface-2);
    cursor: grab;
    font-size: 12px;
    font-family: var(--heading);
    user-select: none;
}

.palette-item:hover {
    border-color: var(--sky);
}

.type-dot {
    width: 9px;
    height: 9px;
    border-radius: 3px;
    flex: none;
}

.inspector {
    width: 310px;
    flex: none;
    border-left: 1px solid var(--border);
    background: var(--surface);
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}

.inspector-head {
    padding: 12px 14px;
    display: grid;
    gap: 2px;
}

.inspector-head h3 {
    font-size: 15px;
    display: flex;
    gap: 8px;
    align-items: center;
}

.inspector-head .sub {
    color: var(--muted);
    font-size: 12px;
}

.inspector-empty {
    padding: 18px 14px;
    color: var(--muted);
    font-size: 13px;
}

/* react flow, themed */

.react-flow {
    --xy-background-color: var(--bg);
    --xy-edge-stroke: #4c5491;
    --xy-edge-stroke-selected: var(--secondary);
    --xy-connectionline-stroke: var(--sky);
    --xy-handle-background-color: var(--surface-3);
    --xy-handle-border-color: var(--sky);
    --xy-controls-button-background-color: var(--surface-2);
    --xy-controls-button-background-color-hover: var(--surface-3);
    --xy-controls-button-color: var(--text);
    --xy-controls-button-border-color: var(--border);
    --xy-minimap-background-color: var(--surface);
    --xy-attribution-background-color: transparent;
    --xy-selection-background-color: rgba(48, 167, 215, 0.08);
    --xy-selection-border: 1px dashed var(--sky);
}

.react-flow__edge-path {
    stroke-width: 2;
}

.pp-node {
    width: 210px;
    height: 86px;
    background: var(--surface-2);
    border: 1px solid var(--border-strong);
    border-radius: 12px;
    padding: 8px 10px 8px 14px;
    position: relative;
    display: grid;
    grid-template-rows: auto auto 1fr;
    gap: 2px;
    /* no overflow: hidden: it would clip the connection handles on the edges */
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.25);
}

.pp-node::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 4px;
    background: var(--type-color);
    border-radius: 12px 0 0 12px;
}

.pp-node.selected {
    border-color: var(--secondary);
    box-shadow: 0 0 0 2px rgba(143, 223, 255, 0.35), 0 6px 18px rgba(0, 0, 0, 0.3);
}

.pp-node.has-error {
    border-color: var(--danger);
}

.pp-node .kind {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--type-color);
    font-family: var(--heading);
    font-weight: 600;
}

.pp-node .kind .id {
    margin-left: auto;
    color: var(--faint);
    letter-spacing: 0;
}

.pp-node .name {
    font-family: var(--heading);
    font-weight: 500;
    font-size: 13px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.pp-node .meta {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    align-content: flex-start;
    overflow: hidden;
}

.pp-node .meta span {
    font-size: 10.5px;
    color: var(--muted);
    background: var(--bg);
    border-radius: 5px;
    padding: 0 5px;
    white-space: nowrap;
}

.pp-node .problems {
    position: absolute;
    top: 6px;
    right: 8px;
    display: flex;
    gap: 3px;
}

.pp-node .problems span {
    font-size: 10px;
    border-radius: var(--pill);
    padding: 0 6px;
    font-weight: 700;
}

.pp-node .problems .e {
    background: var(--danger);
    color: var(--navy);
}

.pp-node .problems .w {
    background: var(--warn);
    color: var(--navy);
}

.pp-frame {
    width: 96px;
    height: 64px;
    border-radius: 32px;
    background: var(--navy);
    border: 1px solid var(--sky);
    display: grid;
    place-items: center;
    font-family: var(--heading);
    font-size: 12px;
    color: var(--secondary);
    text-align: center;
    line-height: 1.2;
}

.pp-frame.selected {
    box-shadow: 0 0 0 2px rgba(143, 223, 255, 0.35);
}

.pp-frame small {
    display: block;
    color: var(--faint);
    font-size: 10px;
}

/*
    Connection handles: 16 px to see, about 44 px to hit. Prefixed with
    .react-flow to win over React Flow's own stylesheet, which loads later. The ::before ring is
    invisible but part of the handle, so a press anywhere in it starts a
    connection; dropping snaps to a handle within connectionRadius (GraphEditor).
 */
.react-flow .react-flow__handle {
    width: 16px;
    height: 16px;
    border-width: 3px;
    background: var(--surface);
    border-color: var(--sky);
    transition: transform 0.1s, background 0.1s, box-shadow 0.1s;
}

.react-flow .react-flow__handle::before {
    content: '';
    position: absolute;
    inset: -14px;
    border-radius: 50%;
}

.react-flow .react-flow__handle:hover,
.react-flow .react-flow__handle.connectingfrom,
.react-flow .react-flow__handle.connectingto {
    background: var(--sky);
    box-shadow: 0 0 0 6px rgba(48, 167, 215, 0.25);
}

.react-flow .react-flow__handle-left:hover,
.react-flow .react-flow__handle-left.connectingto,
.react-flow .react-flow__handle-left.connectingfrom {
    transform: translate(-50%, -50%) scale(1.3);
}

.react-flow .react-flow__handle-right:hover,
.react-flow .react-flow__handle-right.connectingto,
.react-flow .react-flow__handle-right.connectingfrom {
    transform: translate(50%, -50%) scale(1.3);
}

.react-flow .react-flow__handle.connectingto.valid {
    background: var(--ok);
    border-color: var(--ok);
    box-shadow: 0 0 0 8px rgba(74, 222, 128, 0.25);
}


.edge-label {
    position: absolute;
    pointer-events: all;
    font-family: var(--heading);
    font-size: 10.5px;
    padding: 1px 8px;
    border-radius: var(--pill);
    background: var(--navy);
    border: 1px solid #4c5491;
    color: var(--muted);
    cursor: pointer;
    white-space: nowrap;
}

.edge-label.selected {
    border-color: var(--secondary);
    color: var(--secondary);
}

.edge-label.select-op {
    border-color: var(--t-tracking);
    color: var(--t-tracking);
}

.drop-hint {
    position: absolute;
    left: 50%;
    bottom: 16px;
    transform: translateX(-50%);
    font-size: 12px;
    color: var(--muted);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--pill);
    padding: 3px 12px;
    z-index: 5;
    pointer-events: none;
}

/* ability picker */

.picker {
    position: relative;
}

.picker-button {
    width: 100%;
    text-align: left;
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 6px 9px;
    cursor: pointer;
}

.picker-button .v {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-family: var(--mono);
    font-size: 12px;
}

.picker-pop {
    position: absolute;
    z-index: 50;
    left: 0;
    right: 0;
    top: calc(100% + 4px);
    background: var(--surface-2);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    box-shadow: 0 14px 40px rgba(0, 0, 0, 0.5);
    display: flex;
    flex-direction: column;
    max-height: 420px;
}

.picker-pop .input {
    border-radius: 0;
    border: 0;
    border-bottom: 1px solid var(--border);
    background: transparent;
}

.picker-tabs {
    display: flex;
    border-bottom: 1px solid var(--border);
}

.picker-tabs button {
    flex: 1;
    background: none;
    border: 0;
    padding: 6px;
    font-size: 12px;
    color: var(--muted);
    cursor: pointer;
    font-family: var(--heading);
    border-bottom: 2px solid transparent;
}

.picker-tabs button.on {
    color: var(--secondary);
    border-bottom-color: var(--sky);
}

.picker-list {
    overflow-y: auto;
    padding: 4px;
}

.picker-group {
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--faint);
    padding: 8px 8px 2px;
    font-family: var(--heading);
}

.picker-item {
    display: block;
    width: 100%;
    text-align: left;
    background: none;
    border: 0;
    border-radius: 6px;
    padding: 5px 8px;
    cursor: pointer;
}

.picker-item:hover,
.picker-item.active {
    background: var(--accent-soft);
}

.picker-item .a {
    font-family: var(--mono);
    font-size: 12px;
}

.picker-item .d {
    font-size: 11px;
    color: var(--muted);
}

.picker-empty {
    padding: 10px;
    color: var(--muted);
    font-size: 12px;
}

/* prompts editor */

.prompts {
    display: grid;
    gap: 5px;
}

.prompt-row {
    display: grid;
    grid-template-columns: 1fr 0.7fr 26px;
    gap: 5px;
}

/* --- code editor ----------------------------------------------------------- */

.code-wrap {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.code-editor {
    flex: 1;
    min-height: 0;
}

.code-issues {
    max-height: 30%;
    overflow-y: auto;
    border-top: 1px solid var(--border);
    padding: 8px;
}

.code-banner {
    padding: 6px 12px;
    font-size: 12px;
    background: var(--warn-soft);
    color: var(--warn);
    border-bottom: 1px solid rgba(255, 198, 92, 0.3);
}

/* --- preview --------------------------------------------------------------- */

.preview {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
    min-width: 0;
}

.source-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    align-items: center;
    padding: 8px 10px;
    border-bottom: 1px solid var(--border);
}

.source-bar .label {
    color: var(--muted);
    font-size: 12px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 220px;
}

.stage {
    flex: 1;
    min-height: 220px;
    position: relative;
    background: repeating-conic-gradient(#0c0b33 0% 25%, #0a0930 0% 50%) 50% / 24px 24px;
    overflow: hidden;
}

.stage.drag-over {
    outline: 2px dashed var(--sky);
    outline-offset: -8px;
}

.stage-media,
.stage-overlay,
.stage-roi {
    position: absolute;
}

.stage-overlay {
    pointer-events: none;
}

.stage-roi {
    cursor: crosshair;
}

.stage-empty {
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    text-align: center;
    color: var(--muted);
    padding: 20px;
}

.stage-empty .big {
    font-family: var(--heading);
    font-size: 16px;
    color: var(--text);
    margin-bottom: 6px;
}

.stage-status {
    position: absolute;
    left: 10px;
    top: 10px;
    z-index: 3;
    display: flex;
    gap: 6px;
}

.stage-hint {
    position: absolute;
    left: 50%;
    bottom: 12px;
    transform: translateX(-50%);
    background: var(--navy);
    border: 1px solid var(--sky);
    border-radius: var(--pill);
    padding: 3px 12px;
    font-size: 12px;
    z-index: 4;
}

.preview-panels {
    border-top: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    max-height: 36%;
    min-height: 0;
    flex: none;
}

.preview-panels.collapsed {
    max-height: none;
}

.tabs {
    display: flex;
    align-items: center;
    gap: 2px;
    padding: 4px 8px;
}

.tabs button {
    background: none;
    border: 0;
    padding: 4px 10px;
    border-radius: var(--pill);
    cursor: pointer;
    color: var(--muted);
    font-family: var(--heading);
    font-size: 12px;
}

.tabs button.on {
    background: var(--surface-3);
    color: var(--text);
}

.tabs .spacer {
    flex: 1;
}

.panel-body {
    overflow: auto;
    min-height: 0;
    padding: 4px 12px 12px;
}

.json-view {
    margin: 0;
    font-family: var(--mono);
    font-size: 11.5px;
    white-space: pre;
    color: #c9d4ff;
}

.metrics {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
    gap: 8px;
}

.metric {
    background: var(--surface-2);
    border-radius: 10px;
    padding: 8px 10px;
}

.metric .k {
    font-size: 11px;
    color: var(--muted);
}

.metric .v {
    font-family: var(--heading);
    font-size: 17px;
    font-weight: 600;
}

.tracks {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
}

.tracks th {
    text-align: left;
    color: var(--faint);
    font-weight: 600;
    font-family: var(--heading);
    font-size: 11px;
    padding: 4px 6px;
    position: sticky;
    top: 0;
    background: var(--surface);
}

.tracks td {
    padding: 4px 6px;
    border-top: 1px solid var(--border);
    vertical-align: top;
}

.tracks tr.ended td {
    color: var(--faint);
}

.track-swatch {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 2px;
    margin-right: 6px;
}

.selection {
    display: grid;
    gap: 2px;
}

.selection .cls {
    color: var(--secondary);
}

.selection .sel-time {
    justify-self: start;
    padding: 0;
    border: 0;
    background: none;
    color: var(--sky);
    font: inherit;
    text-decoration: underline dotted;
    text-underline-offset: 3px;
    cursor: pointer;
}

.selection .sel-time:hover {
    color: var(--secondary);
    text-decoration-style: solid;
}

.selection .sel-time:disabled {
    color: var(--faint);
    text-decoration: none;
    cursor: default;
}

.selection .no-label {
    color: var(--warn);
    font-style: italic;
}

.advanced {
    border-bottom: 1px solid var(--border);
    max-height: 40%;
    overflow-y: auto;
    flex: none;
}

.advanced > summary {
    padding: 7px 12px;
    cursor: pointer;
    font-family: var(--heading);
    font-size: 12px;
    color: var(--muted);
    list-style: none;
    display: flex;
    align-items: center;
    gap: 8px;
}

.advanced > summary::before {
    content: '▸';
}

.advanced[open] > summary::before {
    content: '▾';
}

.advanced-body {
    padding: 4px 12px 12px;
    display: grid;
    gap: 12px;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    align-items: start;
}

.advanced-body > .note {
    grid-column: 1 / -1;
}

.advanced-body fieldset {
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 8px 10px 10px;
    margin: 0;
    display: grid;
    gap: 8px;
    min-width: 0;
}

.advanced-body legend {
    font-family: var(--heading);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--faint);
    padding: 0 4px;
}

.menu {
    position: absolute;
    z-index: 60;
    background: var(--surface-2);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    padding: 4px;
    box-shadow: 0 14px 40px rgba(0, 0, 0, 0.5);
    min-width: 220px;
}

.menu button {
    display: block;
    width: 100%;
    text-align: left;
    background: none;
    border: 0;
    padding: 6px 10px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 13px;
}

.menu button:hover {
    background: var(--accent-soft);
}

.scroll-thin {
    scrollbar-width: thin;
    scrollbar-color: var(--border-strong) transparent;
}

/* --- video playback --------------------------------------------------------- */

.video-controls {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    height: 44px;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 0 12px 0 6px;
    background: rgba(11, 10, 51, 0.92);
    border-top: 1px solid var(--border);
    z-index: 3;
}

.vc-time {
    font-family: var(--mono);
    font-size: 12px;
    color: var(--muted);
    white-space: nowrap;
}

.vc-track {
    position: relative;
    flex: 1;
    height: 22px;
    cursor: pointer;
    touch-action: none;
}

.vc-rail,
.vc-received,
.vc-played {
    position: absolute;
    left: 0;
    top: 50%;
    height: 6px;
    margin-top: -3px;
    border-radius: 3px;
}

.vc-rail {
    right: 0;
    background: var(--surface-3);
}

.vc-play.buffering {
    color: var(--warn);
}

/* buffering: a ring turning in the play button's place */
.vc-spinner {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    border: 2px solid rgba(255, 198, 92, 0.25);
    border-top-color: var(--warn);
    animation: vc-spin 0.8s linear infinite;
}

@keyframes vc-spin {
    to {
        transform: rotate(360deg);
    }
}

/* predictions received: under the played part */
.vc-received {
    background: rgba(143, 223, 255, 0.38);
    transition: width 0.12s linear;
}

.vc-played {
    background: var(--gradient);
}

.vc-head {
    position: absolute;
    top: 50%;
    width: 14px;
    height: 14px;
    margin: -7px 0 0 -7px;
    border-radius: 50%;
    background: #fff;
    box-shadow: 0 0 0 3px rgba(48, 167, 215, 0.45);
}

.vc-status {
    font-size: 12px;
    color: var(--faint);
    min-width: 120px;
    text-align: right;
    white-space: nowrap;
}

.vc-status.waiting {
    color: var(--warn);
}

/* --- 3D world view ----------------------------------------------------------- */

.stage-world {
    position: absolute;
    left: 0;
    right: 0;
    top: 0;
    z-index: 2;
}

.world-view {
    position: absolute;
    inset: 0;
}

.world-canvas {
    position: absolute;
    inset: 0;
    outline: none;
}

.world-canvas canvas {
    width: 100%;
    height: 100%;
    display: block;
    cursor: grab;
}

.world-legend {
    position: absolute;
    left: 10px;
    top: 10px;
    max-width: min(320px, 60%);
    max-height: calc(100% - 70px);
    overflow-y: auto;
    display: grid;
    gap: 3px;
    padding: 6px;
    background: rgba(11, 10, 51, 0.82);
    border: 1px solid var(--border);
    border-radius: 10px;
    backdrop-filter: blur(4px);
}

.world-series {
    display: grid;
    grid-template-columns: 12px 1fr auto auto;
    align-items: center;
    gap: 7px;
    padding: 3px 6px;
    background: none;
    border: 0;
    border-radius: 6px;
    cursor: pointer;
    font-size: 12px;
    text-align: left;
}

.world-series:hover {
    background: var(--surface-2);
}

.world-series.off {
    opacity: 0.4;
}

.world-swatch {
    width: 10px;
    height: 10px;
    border-radius: 3px;
}

.world-label {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.world-kind {
    color: var(--muted);
    white-space: nowrap;
}

.world-count {
    color: var(--faint);
    font-family: var(--mono);
    font-size: 11px;
}

.world-empty {
    font-size: 12px;
    color: var(--muted);
    padding: 4px 6px;
    max-width: 280px;
}

.world-tools {
    position: absolute;
    right: 10px;
    bottom: 10px;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 5px 8px;
    background: rgba(11, 10, 51, 0.82);
    border: 1px solid var(--border);
    border-radius: 10px;
    font-size: 12px;
}

.world-frame {
    color: var(--faint);
}

.world-size {
    display: flex;
    align-items: center;
    gap: 6px;
    color: var(--muted);
    cursor: default;
}

.world-size input {
    width: 90px;
    accent-color: var(--sky, #30a7d7);
}

.world-size span {
    min-width: 34px;
    font-variant-numeric: tabular-nums;
}

/* info tips: a short extract from the docs, with a link */
.info-tip {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: none;
    width: 14px;
    height: 14px;
    margin-left: 6px;
    border-radius: 50%;
    border: 1px solid var(--border-strong);
    color: var(--muted);
    font: italic 600 9px/1 Georgia, serif;
    cursor: help;
    vertical-align: middle;
    user-select: none;
}

.info-tip:hover,
.info-tip:focus-visible,
.info-tip.open {
    color: var(--navy);
    background: var(--secondary);
    border-color: var(--secondary);
    outline: none;
}

.info-pop {
    position: fixed;
    z-index: 1000;
    padding: 10px 12px;
    background: var(--surface-2);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.6);
    font: 12.5px/1.45 var(--body);
    color: var(--text);
}

.info-pop p {
    margin: 0 0 8px;
}

.info-pop a {
    color: var(--secondary);
    font-weight: 600;
    text-decoration: none;
}

.info-pop a:hover {
    text-decoration: underline;
}

.details-primary {
    display: flex;
    align-items: center;
}

.details-primary > :first-child {
    flex: 1;
    min-width: 0;
}

/* a selection's detail: its first attribute, the whole answer on hover */
.selection .detail-line {
    justify-self: start;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--text);
    border-bottom: 1px dotted var(--border-strong);
    cursor: help;
}

.selection .detail-line:hover,
.selection .detail-line:focus-visible {
    color: var(--secondary);
    outline: none;
}

.json-pop pre {
    margin: 0;
    max-height: 50vh;
    overflow: auto;
    font: 12px/1.45 var(--mono, ui-monospace, monospace);
    white-space: pre-wrap;
    word-break: break-word;
}

/* a node dragged over another: where it will be forwarded from */
.react-flow .react-flow__node.drop-target > * {
    outline: 2px dashed var(--secondary);
    outline-offset: 4px;
    box-shadow: 0 0 0 6px rgba(143, 223, 255, 0.12);
}
