:root {
    color-scheme: light;
    --bg: #f4f8fc;
    --bg-2: #e7eef6;
    --panel: #ffffff;
    --panel-2: #f3f7fb;
    --ink: #102033;
    --muted: #4d5f73;
    --line: #c5d2e0;
    --accent: #08779c;
    --accent-dim: rgba(8, 119, 156, 0.12);
    --teal: #18866d;
    --warn: #c45c26;
    --signal: #7a4fb0;
    --shadow: 0 8px 24px rgba(16, 32, 51, 0.08);
    --radius: 0;
    --text: 12px;
    --text-sm: 11px;
    --text-xs: 10px;
    font-family: "Sora", "Avenir Next", sans-serif;
    font-size: var(--text);
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body,
body.theme-light {
    margin: 0;
    height: 100vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    background: #f3f6fa;
    color: var(--ink);
    font-size: var(--text);
    line-height: 1.35;
}

body.is-loading #map,
body.is-loading #graph-view {
    opacity: 0.55;
}

button, input, select { font: inherit; color: inherit; border-radius: var(--radius); }

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    border: 0;
}

header {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    align-items: center;
    padding: 6px 12px;
    border-bottom: 0;
    background: #fff;
    min-height: 0;
}

.header-tools {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: nowrap;
    justify-content: flex-end;
}

header form {
    display: flex;
    gap: 0;
    min-width: 0;
    width: min(280px, 42vw);
}

.brand {
    display: flex;
    align-items: baseline;
    gap: 10px;
    min-width: 0;
}

.brand h1 {
    margin: 0;
    font-size: 13px;
    letter-spacing: -0.02em;
    font-weight: 600;
    line-height: 1.2;
    white-space: nowrap;
}

.eyebrow {
    margin: 0;
    font-family: "IBM Plex Mono", ui-monospace, monospace;
    font-size: var(--text-xs);
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--accent);
}

.lede {
    margin: 0;
    color: var(--muted);
    font-size: var(--text-xs);
    line-height: 1.3;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: min(420px, 36vw);
}

.demo-pick {
    display: flex;
    align-items: center;
    margin: 0;
}

.demo-pick select,
input[type="search"] {
    text-transform: none;
    letter-spacing: 0;
    font-family: "Sora", "Avenir Next", sans-serif;
    font-size: var(--text-sm);
    background: var(--panel);
    color: var(--ink);
    border: 1px solid var(--line);
    padding: 4px 8px;
    height: 26px;
}

input:focus, button:focus-visible, select:focus {
    outline: 1px solid var(--accent);
    outline-offset: 1px;
}

form button, .zoom, #copy {
    background: var(--accent);
    color: #fff;
    border: 1px solid var(--accent);
    padding: 4px 10px;
    font-size: var(--text-sm);
    font-weight: 600;
    cursor: pointer;
    height: 26px;
}

form button { border-left: 0; }

.view-tabs {
    display: flex;
    gap: 0;
    margin-top: 10px;
    padding: 0 12px;
    border-bottom: 0;
    background: transparent;
}

.view-tabs .tab {
    background: transparent;
    border: 1px solid transparent;
    border-bottom: 0;
    padding: 5px 10px;
    color: var(--muted);
    cursor: pointer;
    font-size: 11px;
    font-weight: 600;
}

.view-tabs .tab[aria-selected="true"] {
    background: var(--panel);
    color: var(--ink);
    border-color: var(--line);
}

main {
    flex: 1;
    min-height: 0;
    display: grid;
    grid-template-columns: minmax(0, 30%) minmax(0, 1fr) minmax(0, 20%);
    gap: 8px;
    padding: 8px;
}

.navigator {
    min-width: 0;
    min-height: 0;
    display: grid;
    grid-template-rows: minmax(0, 1fr);
}

.workspace {
    min-width: 0;
    min-height: 0;
    display: grid;
    grid-template-rows: minmax(0, 1fr);
}

.canvas-slot {
    position: relative;
    min-height: 0;
}

.canvas-slot > .stage {
    position: absolute;
    inset: 0;
}

.stage { min-height: 0; height: 100%; }

.stage.is-hidden { display: none; }

#map, #graph-view {
    position: relative;
    height: 100%;
    overflow: hidden;
    background:
        linear-gradient(rgba(18, 32, 51, 0.04) 1px, transparent 1px),
        linear-gradient(90deg, rgba(18, 32, 51, 0.04) 1px, transparent 1px),
        #f8fbff;
    background-size: 40px 40px;
    border: 1px solid var(--line);
    cursor: grab;
    touch-action: none;
}

#map.is-panning, #graph-view.is-panning { cursor: grabbing; }

#world {
    position: absolute;
    top: 0;
    left: 0;
    transform-origin: 0 0;
}

#graph-canvas {
    width: 100%;
    height: 100%;
    display: block;
}

.graph-legend {
    position: absolute;
    top: 10px;
    left: 10px;
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    z-index: 2;
    max-width: 70%;
}

.graph-legend span {
    background: rgba(255, 255, 255, 0.92);
    border: 1px solid var(--line);
    padding: 2px 6px;
    font-size: var(--text-xs);
    font-family: "IBM Plex Mono", ui-monospace, monospace;
}

.graph-legend [data-kind="machine"] { border-left: 3px solid #122033; }
.graph-legend [data-kind="area"] { border-left: 3px solid var(--accent); }
.graph-legend [data-kind="picture"] { border-left: 3px solid var(--teal); }
.graph-legend [data-kind="part"] { border-left: 3px solid var(--warn); }
.graph-legend [data-kind="signal"] { border-left: 3px solid var(--signal); }

.district {
    position: absolute;
    border: 1px dashed color-mix(in srgb, var(--district, var(--accent)) 70%, transparent);
    background: color-mix(in srgb, var(--district, var(--accent)) 8%, white);
}

.district-title {
    position: absolute;
    left: 8px;
    top: 6px;
    font-family: "IBM Plex Mono", ui-monospace, monospace;
    font-size: 13px;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--district, var(--accent));
    white-space: nowrap;
}

.screen {
    position: absolute;
    background: #dce3eb;
    border: 1px solid #7d8794;
    box-shadow: var(--shadow);
    overflow: hidden;
}

.screen.is-pending {
    background:
        linear-gradient(135deg, rgba(255,255,255,0.55), transparent 40%),
        #d5dde7;
}

.surface-stub {
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    color: #5b6b7c;
    font-size: 14px;
    letter-spacing: 0.04em;
    pointer-events: none;
}

.surface {
    position: absolute;
    left: 0;
    top: 0;
    background: #cfd5dd;
    transform-origin: 0 0;
}

.surface.nested {
    position: absolute;
    pointer-events: none;
    background: #d7dde5;
}

.surface-wallpaper {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: fill;
    pointer-events: none;
}

.screen.is-hot { outline: 3px solid var(--teal); outline-offset: 3px; }

.screen-title {
    position: absolute;
    left: 0;
    top: 0;
    z-index: 3;
    max-width: 70%;
    padding: 1px 5px;
    background: rgba(255, 255, 255, 0.92);
    border-bottom: 1px solid #c5d2e0;
    border-right: 1px solid #c5d2e0;
    font-size: 12px;
    color: var(--ink);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    pointer-events: none;
}

.picture-drawing {
    display: block;
    background: #d5dbe3;
}

.picture-drawing .is-selected {
    stroke: #08779c;
    stroke-width: 2.5;
}

.picture-drawing .is-related {
    stroke: #c45c26;
    stroke-width: 2;
}

.shape {
    position: absolute;
    box-sizing: border-box;
    border: 1px solid rgba(40, 52, 68, 0.35);
    background: rgba(255, 255, 255, 0.28);
    color: #152033;
    overflow: hidden;
}

.shape.decoration {
    border-color: rgba(40, 52, 68, 0.45);
    background: rgba(255, 255, 255, 0.12);
    pointer-events: none;
}

.shape[data-part-id] {
    pointer-events: auto;
    cursor: pointer;
}

.shape[data-kind="Line"],
.shape.is-line {
    border: 0;
    background: #3a4654;
    box-shadow: none;
    padding: 0;
}

.shape[data-kind="Circle"] {
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.2);
    border-color: #4a5563;
}

.shape[data-kind="Rectangle"],
.shape[data-kind="Rounded rectangle"] {
    background: rgba(230, 236, 242, 0.55);
    border-color: #5b6b7c;
}

.shape[data-kind="Imported graphic"],
.shape[data-kind="Graphic"] {
    background: rgba(255, 255, 255, 0.15);
    border-color: rgba(40, 52, 68, 0.28);
}

.shape.has-image {
    z-index: 6;
    background: transparent !important;
    border-color: transparent;
}

.shape.has-polygon {
    z-index: 2;
    overflow: visible;
}

.polygon-svg {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    overflow: visible;
    pointer-events: none;
}

.shape.nested-shape { pointer-events: none; }

.shape[data-kind="Picture window"] {
    border-color: #0b7ea4;
    background: rgba(11, 126, 164, 0.08);
}
.shape[data-kind="Button"] {
    border-color: #4a5563;
    background: linear-gradient(#ffffff, #d7dde6);
    box-shadow: inset 0 1px 0 #fff, inset 0 -1px 0 #9aa5b3;
}
.shape[data-kind="Control"] {
    border-color: #c45c26;
    background: rgba(196, 92, 38, 0.12);
}
.shape[data-kind="Text"], .shape[data-kind="I/O field"] {
    background: transparent;
    border-color: transparent;
}

.shape img {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: fill;
    image-rendering: auto;
    pointer-events: none;
}

.shape .caption {
    position: relative;
    z-index: 1;
    display: block;
    padding: 1px 3px;
    font-size: 10px;
    line-height: 1.2;
    color: #152033;
    white-space: pre-wrap;
    pointer-events: none;
}

.shape[data-kind="Button"] .caption {
    text-align: center;
    font-weight: 600;
    font-size: 10px;
}

.shape .caption.muted { color: #5b6b7c; font-size: 9px; font-weight: 500; }

.shape.is-related { border-style: dashed; border-width: 2px; }
.shape.is-selected {
    border-color: var(--accent);
    border-width: 2px;
    background: var(--accent-dim);
    z-index: 5;
}

.group-box {
    position: absolute;
    border: 2px solid var(--accent);
    background: rgba(11, 126, 164, 0.05);
    pointer-events: none;
    z-index: 4;
}

.group-box b {
    position: absolute;
    left: 0;
    top: calc(-14px / var(--k, 1));
    font-size: calc(9px / var(--k, 1));
    font-weight: 600;
    color: var(--accent);
    white-space: nowrap;
}

.map-tools {
    position: absolute;
    top: 8px;
    right: 8px;
    display: flex;
    gap: 4px;
    z-index: 2;
}

.map-tools button {
    width: 26px;
    height: 26px;
    border: 1px solid var(--line);
    background: rgba(255, 255, 255, 0.94);
    font-size: var(--text-sm);
    cursor: pointer;
}

.map-hint {
    position: absolute;
    left: 8px;
    bottom: 8px;
    margin: 0;
    color: var(--muted);
    font-size: var(--text-xs);
    z-index: 2;
    pointer-events: none;
    background: rgba(255, 255, 255, 0.82);
    padding: 2px 6px;
    border: 1px solid var(--line);
}

.columns {
    height: 100%;
    margin: 0;
    overflow: auto;
    border: 1px solid var(--line);
    background: var(--panel);
    padding: 4px 0;
}

.tree-line {
    display: flex;
    align-items: stretch;
    min-width: 0;
}

.twist {
    flex: 0 0 16px;
    width: 16px;
    border: 0;
    background: transparent;
    color: var(--muted);
    cursor: pointer;
    padding: 0;
    font-size: 11px;
}

.twist:disabled { cursor: default; }

.row {
    flex: 1;
    min-width: 0;
    text-align: left;
    background: transparent;
    border: 0;
    border-left: 2px solid transparent;
    padding: 3px 6px;
    cursor: pointer;
    display: block;
    font-size: var(--text-sm);
}

.row:hover { background: var(--panel-2); }

.row[aria-current="true"] {
    background: var(--accent-dim);
    border-left-color: var(--accent);
}

.row strong,
.row em {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.row strong { font-weight: 600; font-size: var(--text-sm); }

.row em {
    margin-top: 1px;
    color: var(--teal);
    font-style: normal;
    font-size: var(--text-xs);
}

.empty {
    color: var(--muted);
    padding: 6px 8px 12px;
    font-size: var(--text-sm);
}

aside {
    background: var(--panel);
    border: 1px solid var(--line);
    padding: 10px;
    overflow: auto;
    min-height: 0;
    min-width: 0;
}

.crumb {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 4px;
    margin: 4px 0 8px;
}

.crumb .sep {
    color: var(--accent);
    font-size: var(--text-xs);
    font-weight: 600;
}

.crumb button {
    background: transparent;
    border: 0;
    border-bottom: 1px solid var(--line);
    padding: 0 0 1px;
    font-size: var(--text-xs);
    cursor: pointer;
}

.level-pill {
    display: inline-block;
    margin: 0 0 4px;
    padding: 1px 6px;
    border: 1px solid var(--line);
    background: var(--panel-2);
    font-family: "IBM Plex Mono", ui-monospace, monospace;
    font-size: 9px;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--accent);
}

aside h2 {
    margin: 0 0 4px;
    font-size: 15px;
    letter-spacing: -0.02em;
    font-weight: 600;
}

.detail { color: var(--muted); line-height: 1.35; margin: 0 0 8px; font-size: var(--text-sm); }

.zoom { margin-bottom: 8px; }

.guide {
    display: grid;
    gap: 8px;
    margin: 0 0 10px;
}

.guide section {
    border: 1px solid var(--line);
    background: var(--panel-2);
    padding: 6px 8px;
}

.guide h3 {
    margin: 0 0 3px;
    font-size: 9px;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    font-family: "IBM Plex Mono", ui-monospace, monospace;
    color: var(--accent);
    font-weight: 500;
}

.guide p {
    margin: 0;
    font-size: var(--text-sm);
    line-height: 1.4;
    color: var(--ink);
}

.aside-actions {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
    margin-top: 8px;
}

#copy { padding: 3px 8px; height: 24px; font-size: var(--text-xs); }

.status { color: var(--muted); font-size: var(--text-xs); }

footer {
    padding: 0 12px 8px;
    color: var(--muted);
    font-size: var(--text-xs);
}

@media (max-width: 1100px) {
    body { overflow: auto; height: auto; }
    main { display: block; }
    main { grid-template-columns: 1fr; }
    .navigator { height: 280px; }
    .workspace { height: 68vh; }
    .canvas-slot { height: 100%; }
    header { flex-wrap: wrap; }
    .lede { max-width: 100%; white-space: normal; }
    aside { max-height: none; }
}
