/*
 * LINC-Rings visual system
 * ------------------------
 * This stylesheet intentionally keeps the Rainbokeh palette in one place.
 * When a color repeats, prefer adding a semantic token here instead of
 * hard-coding a new value in a component. That makes the app easier to theme
 * and keeps the CRT/sidebar treatment consistent across future sections.
 */

:root {
    /* Core Rainbokeh palette from the public site and local visual refs. */
    --gold: #c49a45;
    --sage: #4d6647;
    --terracotta: #c05538;
    --cyan: #5e949a;
    --magenta: #a85472;
    --chalk: #2a2016;
    --beige: #c8b898;
    --cream: #ede4cc;
    --paper: #c8b898;
    --ink: #2a2016;
    --panel: #ede4cc;
    --panel-2: #c8b898;
    --moss: var(--sage);
    --moss-dark: #354832;
    --sun: var(--gold);
    --orange: var(--terracotta);
    --brick: #8e3d2c;
    --aqua: var(--cyan);
    --muted: rgba(42, 32, 22, 0.68);
    --dim: rgba(196, 154, 69, 0.45);
    --line: rgba(42, 32, 22, 0.22);
    --line-soft: rgba(42, 32, 22, 0.12);
    --line-subtle: rgba(42, 32, 22, 0.16);
    --line-faint: rgba(42, 32, 22, 0.08);
    --cream-soft: rgba(237, 228, 204, 0.42);
    --cream-strong: rgba(237, 228, 204, 0.96);
    --gold-soft: rgba(196, 154, 69, 0.18);
    --gold-line: rgba(196, 154, 69, 0.2);
    --panel-shadow: rgba(42, 32, 22, 0.12);
    --shadow: rgba(0, 0, 0, 0.42);

    /* Type families: Montserrat carries the site voice; Courier is used for instrument labels. */
    --mono: "Courier New", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    --sans: Montserrat, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;

    /* Shared motion and dimensional tokens. */
    --radius-card: 20px;
    --radius-control: 8px;
    --radius-pill: 100px;
    --transition-fast: 0.125s ease-in-out;
    --transition-medium: 0.22s cubic-bezier(0.33, 1, 0.68, 1);

    /* Dimensional title shadow used by Rainbokeh section headers. */
    --title-shadow:
        1px 1px 0 var(--gold),
        2px 2px 0 var(--gold),
        3px 3px 0 var(--terracotta),
        4px 4px 0 var(--terracotta),
        5px 5px 0 var(--terracotta),
        6px 6px 0 var(--chalk);
}

/* Base reset: keep it small because this app is embedded as one static page. */
* {
    box-sizing: border-box;
}

html {
    min-width: 320px;
    background: var(--chalk);
}

body {
    margin: 0;
    min-height: 100vh;
    color: var(--ink);
    background:
        radial-gradient(circle at 18% 16%, rgba(196, 154, 69, 0.32), transparent 18rem),
        radial-gradient(circle at 86% 12%, rgba(94, 148, 154, 0.24), transparent 20rem),
        radial-gradient(circle at 72% 84%, rgba(168, 84, 114, 0.18), transparent 22rem),
        linear-gradient(180deg, var(--beige) 0%, var(--cream) 55%, var(--beige) 100%);
    font-family: var(--sans);
    font-weight: 400;
    line-height: 1.6;
    overflow-x: hidden;
}

body::before {
    content: "";
    position: fixed;
    inset: 0;
    pointer-events: none;
    background:
        radial-gradient(circle at 22% 24%, rgba(237, 228, 204, 0.28) 0 0.14rem, transparent 0.18rem),
        radial-gradient(circle at 74% 18%, rgba(192, 85, 56, 0.18) 0 0.12rem, transparent 0.16rem),
        radial-gradient(circle at 68% 78%, rgba(94, 148, 154, 0.18) 0 0.16rem, transparent 0.2rem);
    background-size: 7.5rem 7.5rem, 9rem 9rem, 10rem 10rem;
    mix-blend-mode: multiply;
    opacity: 0.38;
    z-index: -1;
}

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

button {
    cursor: pointer;
}

.app-shell {
    min-height: 100vh;
    display: grid;
    grid-template-rows: auto 1fr;
}

.topbar {
    position: sticky;
    top: 0;
    z-index: 20;
    display: grid;
    grid-template-columns: minmax(150px, 230px) minmax(260px, 1fr) auto;
    gap: 18px;
    align-items: center;
    min-height: 72px;
    padding: 10px clamp(16px, 4vw, 64px);
    border-bottom: 1px solid var(--line-subtle);
    background: var(--cream-strong);
    box-shadow: 0 4px 20px rgba(42, 32, 22, 0.15);
}

.brand img {
    display: block;
    width: min(215px, 100%);
    height: auto;
}

.topbar-detail {
    min-width: 0;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 9px 14px;
    border-left: 1px solid var(--line-soft);
    border-right: 1px solid var(--line-soft);
}

.topbar-detail-title {
    flex: 0 0 auto;
    max-width: 220px;
    color: var(--sun);
    font-family: var(--mono);
    font-size: clamp(0.82rem, 1vw, 1rem);
    font-weight: 700;
    letter-spacing: 0.16em;
    text-transform: uppercase;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.topbar-detail-summary {
    min-width: 0;
    color: var(--muted);
    font-size: clamp(1rem, 1.15vw, 1.16rem);
    line-height: 1.3;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

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

.icon-button {
    width: 44px;
    height: 44px;
    display: grid;
    place-items: center;
    color: var(--ink);
    background: var(--beige);
    border: 1px solid rgba(42, 32, 22, 0.18);
    border-radius: var(--radius-pill);
    transition: transform var(--transition-fast), background var(--transition-fast), color var(--transition-fast);
}

.icon-button:hover {
    color: var(--cream);
    background: var(--terracotta);
    transform: translateY(-1px);
}

.icon-button svg {
    width: 18px;
    height: 18px;
}

.layout {
    --left-sidebar-width: clamp(280px, 18vw, 340px);
    --right-sidebar-width: clamp(300px, 20vw, 380px);
    --sidebar-tab-width: 44px;
    display: grid;
    grid-template-columns: var(--left-sidebar-width) minmax(0, 1fr) var(--right-sidebar-width);
    min-height: calc(100vh - 72px);
    transition: grid-template-columns var(--transition-medium);
}

.layout.left-collapsed {
    grid-template-columns: var(--sidebar-tab-width) minmax(0, 1fr) var(--right-sidebar-width);
}

.layout.right-collapsed {
    grid-template-columns: var(--left-sidebar-width) minmax(0, 1fr) var(--sidebar-tab-width);
}

.layout.left-collapsed.right-collapsed {
    grid-template-columns: var(--sidebar-tab-width) minmax(0, 1fr) var(--sidebar-tab-width);
}

.control-panel {
    position: relative;
    z-index: 5;
    display: flex;
    flex-direction: column;
    gap: 14px;
    padding: 18px 16px;
    border-right: 1px solid var(--line-subtle);
    background:
        radial-gradient(circle at 30% 18%, var(--cream-soft), transparent 15rem),
        var(--beige);
    box-shadow: 10px 0 24px var(--line-soft);
    overflow: visible;
    max-height: calc(100vh - 72px);
    transition: padding var(--transition-medium), box-shadow var(--transition-medium);
}

.insight-sidebar {
    position: relative;
    z-index: 5;
    display: flex;
    flex-direction: column;
    padding: 18px 16px;
    border-left: 1px solid var(--line-subtle);
    background:
        radial-gradient(circle at 70% 22%, var(--cream-soft), transparent 15rem),
        var(--beige);
    box-shadow: -10px 0 24px var(--line-soft);
    overflow: visible;
    max-height: calc(100vh - 72px);
    transition: padding var(--transition-medium), box-shadow var(--transition-medium);
}

.sidebar-handle {
    position: absolute;
    top: 24px;
    z-index: 8;
    width: 38px;
    min-height: 156px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 12px 0;
    color: var(--chalk);
    background: var(--cream);
    border: 1px solid rgba(42, 32, 22, 0.22);
    box-shadow:
        inset 0 2px 8px rgba(237, 228, 204, 0.65),
        inset 0 -3px 8px rgba(42, 32, 22, 0.1),
        0 4px 14px rgba(42, 32, 22, 0.18);
    font-family: var(--mono);
    font-size: 0.58rem;
    font-weight: 700;
    letter-spacing: 0.16em;
    text-transform: uppercase;
    transition:
        left var(--transition-medium),
        right var(--transition-medium),
        background 0.14s ease-in-out,
        color 0.14s ease-in-out,
        transform var(--transition-medium),
        box-shadow var(--transition-medium);
}

.sidebar-handle::after {
    content: "";
    position: absolute;
    bottom: 16px;
    left: 50%;
    margin-left: -5px;
    width: 10px;
    height: 10px;
    border-top: 2px solid currentColor;
    border-right: 2px solid currentColor;
    flex: 0 0 auto;
}

.sidebar-handle:hover {
    color: var(--cream);
    background: var(--terracotta);
}

.sidebar-handle span {
    min-width: 0;
    writing-mode: vertical-rl;
    text-orientation: mixed;
    overflow: visible;
    white-space: nowrap;
}

.control-panel .sidebar-handle {
    right: -19px;
    border-radius: 0 16px 16px 0;
}

.control-panel .sidebar-handle::after {
    transform: rotate(-135deg);
}

.insight-sidebar .sidebar-handle {
    left: -19px;
    border-radius: 16px 0 0 16px;
}

.insight-sidebar .sidebar-handle::after {
    transform: rotate(45deg);
}

.layout.left-collapsed .control-panel,
.layout.right-collapsed .insight-sidebar {
    padding: 18px 4px;
    overflow: visible;
    box-shadow: none;
}

.layout.left-collapsed .control-panel .panel-stack,
.layout.right-collapsed .insight-sidebar #rightSidebarContent {
    display: none;
}

.layout.left-collapsed .control-panel .sidebar-handle,
.layout.right-collapsed .insight-sidebar .sidebar-handle {
    width: 34px;
    border-radius: 16px;
}

.layout.left-collapsed .control-panel .sidebar-handle {
    right: 5px;
}

.layout.right-collapsed .insight-sidebar .sidebar-handle {
    left: 5px;
}

.layout.left-collapsed .control-panel .sidebar-handle::after {
    transform: rotate(45deg);
}

.layout.right-collapsed .insight-sidebar .sidebar-handle::after {
    transform: rotate(-135deg);
}

.stage {
    position: relative;
    min-height: calc(100vh - 72px);
    overflow: hidden;
    background:
        radial-gradient(circle at 26% 20%, rgba(237, 228, 204, 0.4), transparent 26rem),
        radial-gradient(circle at 74% 78%, rgba(94, 148, 154, 0.12), transparent 24rem),
        linear-gradient(180deg, var(--beige), var(--cream));
}

.stage::before {
    content: "";
    position: absolute;
    top: 50%;
    left: 50%;
    width: 220vmax;
    height: 340px;
    transform: translate(-50%, -50%) rotate(-33deg);
    background: linear-gradient(
        to bottom,
        var(--chalk) 0 72px,
        var(--terracotta) 72px 190px,
        var(--gold) 190px 270px,
        var(--cyan) 270px 340px
    );
    opacity: 0.26;
}

.stage::after {
    content: "";
    position: absolute;
    inset: 0;
    pointer-events: none;
    background:
        radial-gradient(circle at 24% 28%, rgba(237, 228, 204, 0.34) 0 0.18rem, transparent 0.22rem),
        radial-gradient(circle at 74% 34%, rgba(196, 154, 69, 0.24) 0 0.14rem, transparent 0.18rem),
        radial-gradient(circle at 62% 76%, rgba(168, 84, 114, 0.18) 0 0.16rem, transparent 0.2rem);
    background-size: 6rem 6rem, 8rem 8rem, 10rem 10rem;
    mix-blend-mode: multiply;
    opacity: 0.5;
}

.section {
    border: 2px solid rgba(42, 32, 22, 0.88);
    border-radius: 20px;
    background: var(--cream);
    margin-bottom: 14px;
    overflow: hidden;
    box-shadow:
        inset 0 2px 8px rgba(237, 228, 204, 0.6),
        inset 0 -4px 10px var(--line-soft),
        0 6px 20px rgba(42, 32, 22, 0.18),
        0 0 0 1px rgba(196, 154, 69, 0.15);
}

.section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 0;
    border-bottom: 5px solid rgba(42, 32, 22, 0.88);
    background: var(--beige);
}

.section-toggle {
    display: flex;
    width: 100%;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 13px 14px 10px;
    color: var(--chalk);
    background: transparent;
    border: 0;
    font: inherit;
    text-align: left;
}

.section-toggle::after {
    content: "";
    width: 12px;
    height: 12px;
    border-top: 3px solid currentColor;
    border-right: 3px solid currentColor;
    flex: 0 0 auto;
    transform: rotate(135deg);
    transition: transform 0.15s ease-in-out;
}

.section h2,
.map-title {
    margin: 0;
    color: var(--chalk);
    font-family: var(--sans);
    font-size: 1.1rem;
    font-weight: 900;
    letter-spacing: 0;
    line-height: 1.05;
    text-transform: none;
    text-shadow:
        1px 1px 0 var(--gold),
        2px 2px 0 var(--terracotta);
}

.section-header > h2 {
    display: none;
}

.section.is-collapsed .section-header {
    border-bottom: 0;
}

.section.is-collapsed .section-body {
    display: none;
}

.section.is-collapsed .section-toggle::after {
    transform: rotate(45deg);
}

.section p {
    margin: 0;
    color: var(--muted);
    font-size: 0.95rem;
    line-height: 1.6;
}

.section-body {
    padding: 14px;
}

.input-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 42px;
    gap: 8px;
    margin-bottom: 10px;
}

.input-row-spaced {
    margin-top: 12px;
}

input,
textarea,
select {
    width: 100%;
    color: var(--ink);
    background: var(--cream);
    border: 0;
    border-radius: var(--radius-control);
    padding: 11px 12px;
    outline: none;
    font-size: 1rem;
    box-shadow: inset 0 0 0 1px rgba(42, 32, 22, 0.2);
}

textarea {
    min-height: 128px;
    resize: vertical;
    line-height: 1.45;
}

input:focus,
textarea:focus,
select:focus {
    box-shadow:
        inset 0 0 0 1px var(--terracotta),
        0 0 0 3px rgba(192, 85, 56, 0.18);
}

button:focus-visible,
a:focus-visible {
    outline: 3px solid rgba(196, 154, 69, 0.62);
    outline-offset: 3px;
}

.button,
.add-btn {
    min-height: 40px;
    border: 1px solid transparent;
    border-radius: var(--radius-pill);
    padding: 0 18px;
    color: var(--cream);
    background: var(--terracotta);
    font-weight: 700;
    font-size: 0.88rem;
    text-transform: none;
    box-shadow: 0 2px 3px rgba(0, 0, 0, 0.2);
    transition: transform var(--transition-fast), background var(--transition-fast);
}

.button:hover,
.add-btn:hover {
    background: var(--magenta);
    transform: translateY(-1px);
}

.add-btn {
    padding: 0;
    color: var(--chalk);
    background: var(--gold);
    font-size: 1.2rem;
}

.button.secondary {
    color: var(--cream);
    background: var(--sage);
}

.button.accent {
    color: #fff8ec;
    background: var(--orange);
}

.button.outline {
    color: var(--ink);
    background: var(--beige);
    border-color: rgba(42, 32, 22, 0.22);
}

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

.item-list {
    display: flex;
    flex-wrap: wrap;
    gap: 7px;
    min-height: 38px;
}

.chip {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    max-width: 100%;
    min-height: 30px;
    padding: 5px 8px;
    border: 1px solid var(--line);
    border-radius: var(--radius-pill);
    background: var(--gold-soft);
    color: var(--ink);
    font-size: 0.8rem;
    font-weight: 600;
}

.chip button {
    width: 18px;
    height: 18px;
    padding: 0;
    color: var(--cream);
    background: var(--terracotta);
    border: 0;
    border-radius: 50%;
    line-height: 1;
}

.small-label {
    margin-bottom: 7px;
    color: var(--gold);
    font-family: var(--mono);
    font-size: 0.62rem;
    letter-spacing: 0.2em;
    text-transform: uppercase;
}

.small-label-spaced {
    margin-top: 12px;
}

.small-label-loose {
    margin-top: 14px;
}

.status {
    min-height: 20px;
    margin-top: 8px;
    color: var(--muted);
    font-size: 0.9rem;
    line-height: 1.35;
}

.panel-stack {
    min-width: 0;
    min-height: 0;
    max-height: calc(100vh - 108px);
    overflow-y: auto;
    padding-right: 4px;
    scrollbar-width: thin;
}

#rightSidebarContent {
    min-height: 0;
    max-height: calc(100vh - 108px);
    overflow-y: auto;
    padding-left: 4px;
    scrollbar-width: thin;
}

.feedback-section {
    position: relative;
}

.feedback-body {
    display: grid;
    gap: 10px;
}

.feedback-body-spaced {
    margin-top: 12px;
}

.feedback-card {
    border: 1px solid var(--gold-line);
    border-radius: 12px;
    padding: 12px;
    background: var(--chalk);
    color: var(--cream);
}

.feedback-card h3 {
    margin: 0 0 8px;
    color: var(--gold);
    font-family: var(--mono);
    font-size: 0.72rem;
    letter-spacing: 0.18em;
    text-transform: uppercase;
}

.feedback-card p {
    color: rgba(237, 228, 204, 0.82);
    font-size: 0.95rem;
}

.linc-grid {
    display: grid;
    gap: 7px;
    margin-top: 10px;
}

.linc-row {
    color: rgba(237, 228, 204, 0.82);
    font-size: 0.93rem;
    line-height: 1.42;
}

.linc-row strong {
    color: var(--gold);
    font-family: var(--mono);
    font-size: 0.78rem;
    text-transform: uppercase;
}

.feedback-explore {
    margin: 0;
    color: var(--muted);
    font-size: 0.98rem;
    line-height: 1.55;
}

.status.error {
    color: var(--terracotta);
}

.status.ok {
    color: var(--sage);
}

.map-wrap {
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    padding: clamp(8px, 1.5vw, 22px) clamp(16px, 2.4vw, 34px) clamp(16px, 2vw, 28px);
    z-index: 1;
}

.crt-monitor {
    position: relative;
    width: min(100%, 1220px);
    height: min(calc(100vh - 132px), 980px);
    min-height: 620px;
    display: flex;
    flex-direction: column;
    filter: drop-shadow(0 16px 36px rgba(0, 0, 0, 0.42));
}

.crt-monitor::before,
.crt-monitor::after {
    content: "";
    position: absolute;
    bottom: -14px;
    width: 20px;
    height: 28px;
    background: var(--chalk);
    border-radius: 0 0 4px 4px;
    z-index: -1;
}

.crt-monitor::before {
    left: 6%;
}

.crt-monitor::after {
    right: 6%;
}

.crt-topbar {
    height: 10px;
    margin: 0 32px;
    background: var(--chalk);
    border-radius: 10px 10px 0 0;
    flex: 0 0 auto;
}

.crt-face {
    min-height: 0;
    flex: 1 1 auto;
    border: 2px solid var(--chalk);
    border-radius: 20px;
    background: var(--cream);
    padding: 18px;
    box-shadow:
        inset 0 2px 8px rgba(237, 228, 204, 0.65),
        inset 0 -4px 10px var(--line-soft),
        0 8px 32px rgba(0, 0, 0, 0.42),
        0 0 0 1px rgba(196, 154, 69, 0.15);
}

.crt-screen-bezel {
    height: calc(100% - 58px);
    min-height: 0;
    padding: 7px;
    border: 2px solid var(--chalk);
    border-radius: 14px;
    background: var(--chalk);
    box-shadow:
        inset 0 0 22px rgba(0, 0, 0, 0.85),
        0 0 0 1px var(--chalk);
}

.map-card {
    position: relative;
    width: 100%;
    height: 100%;
    min-height: 0;
    border-radius: var(--radius-control);
    overflow: hidden;
    background:
        repeating-linear-gradient(
            to bottom,
            rgba(42, 32, 22, 0.018) 0,
            rgba(42, 32, 22, 0.018) 1px,
            transparent 1px,
            transparent 4px
        ),
        linear-gradient(180deg, #ede4cc 0%, #eee6d1 52%, #e9dfc4 100%);
}

.map-card::after {
    content: "";
    position: absolute;
    inset: 0;
    pointer-events: none;
    box-shadow: inset 0 0 34px var(--line-faint);
}

.crt-footer {
    height: 48px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    padding-top: 12px;
}

.crt-knobs {
    display: flex;
    align-items: center;
    gap: 10px;
}

.crt-knob {
    width: 24px;
    height: 24px;
    border: 1px solid rgba(42, 32, 22, 0.52);
    border-radius: 50%;
    background: radial-gradient(circle at 35% 35%, rgba(237, 228, 204, 0.88), var(--beige) 42%, var(--chalk));
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.45);
}

.crt-leds {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.crt-led {
    width: 5px;
    height: 5px;
    border-radius: 50%;
    background: var(--gold);
}

.crt-led:first-child {
    background: var(--terracotta);
    box-shadow: 0 0 5px var(--terracotta);
}

.crt-badge {
    padding: 2px 8px;
    border: 1px solid var(--gold-line);
    color: rgba(196, 154, 69, 0.52);
    font-family: var(--mono);
    font-size: 0.52rem;
    letter-spacing: 0.2em;
}

.map-heading {
    position: absolute;
    top: 14px;
    left: 22px;
    z-index: 2;
    display: flex;
    flex-direction: column;
    gap: 7px;
}

.map-title {
    color: var(--ink);
    font-family: var(--sans);
    font-weight: 900;
    font-size: clamp(1.35rem, 1.8vw, 2.15rem);
    letter-spacing: -0.02em;
    text-shadow:
        1px 1px 0 var(--gold),
        2px 2px 0 var(--cyan),
        3px 3px 0 var(--cyan),
        4px 4px 0 var(--chalk);
}

.map-actions {
    position: absolute;
    right: 18px;
    top: 16px;
    z-index: 3;
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    justify-content: flex-end;
}

#viz {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    overflow: visible;
}

.ring-band {
    fill: none;
    stroke-width: 52;
    opacity: 0.24;
}

.ring-line {
    fill: none;
    stroke: rgba(42, 32, 22, 0.26);
    stroke-width: 1;
    stroke-dasharray: 6 12;
}

.edge {
    stroke: var(--line-subtle);
    stroke-width: 1;
    vector-effect: non-scaling-stroke;
}

/* Edge color classes mirror `EDGE_COLOR_COUNT` in app.js. */
.edge-color-0 { --edge-color: #8e3d2c; }
.edge-color-1 { --edge-color: #354832; }
.edge-color-2 { --edge-color: #7a4d1f; }
.edge-color-3 { --edge-color: #2f6f78; }
.edge-color-4 { --edge-color: #7a3651; }
.edge-color-5 { --edge-color: #4f5d3f; }
.edge-color-6 { --edge-color: #5d4a2d; }
.edge-color-7 { --edge-color: #32634c; }

.edge.active {
    stroke-width: 1.2;
    stroke: var(--edge-color, var(--sun));
}

.edge-animated {
    /*
     * app.js writes `--connection-length` from the real SVG point distance.
     * Using that value for both dash length and duration makes the visible
     * line tip arrive when the matching pulse fires.
     * The draw uses linear timing because easing changes perceived tip speed;
     * the emotional accent comes from the arrival pulse.
    */
    stroke-dasharray: calc(var(--connection-length, 420) * 1px);
    stroke-dashoffset: calc(var(--connection-length, 420) * 1px);
    animation: connection-draw var(--connection-duration, 720ms) linear forwards;
}

.connection-speed-0 { --connection-duration: 240ms; }
.connection-speed-1 { --connection-duration: 380ms; }
.connection-speed-2 { --connection-duration: 560ms; }
.connection-speed-3 { --connection-duration: 800ms; }
.connection-speed-4 { --connection-duration: 1080ms; }
.connection-speed-5 { --connection-duration: 1340ms; }
.connection-speed-6 { --connection-duration: 1600ms; }

.arrival-pulse {
    fill: none;
    stroke: var(--edge-color, var(--sun));
    stroke-width: 2.5;
    opacity: 0;
    pointer-events: none;
    transform-box: fill-box;
    transform-origin: center;
    animation: connection-arrival 360ms ease-out var(--connection-duration, 720ms) both;
    filter: drop-shadow(0 0 8px color-mix(in srgb, var(--edge-color, var(--sun)) 55%, transparent));
}

.outer-node,
.inner-node {
    cursor: pointer;
}

.node-dot {
    stroke: rgba(42, 32, 22, 0.72);
    stroke-width: 2;
    transform-box: fill-box;
    transform-origin: center;
}

.node-color-0 { --node-shadow-color: var(--gold); }
.node-color-1 { --node-shadow-color: var(--sage); }
.node-color-2 { --node-shadow-color: var(--terracotta); }
.node-color-3 { --node-shadow-color: var(--cyan); }
.node-color-4 { --node-shadow-color: var(--magenta); }
.node-color-5 { --node-shadow-color: var(--beige); }
.node-color-6 { --node-shadow-color: var(--cream); }

.node-hit {
    fill: transparent;
    pointer-events: all;
}

.outer-node:focus,
.inner-node:focus {
    outline: none;
}

.outer-node:focus-visible .node-hit,
.inner-node:focus-visible .node-hit {
    fill: rgba(196, 154, 69, 0.2);
    stroke: var(--gold);
    stroke-width: 3;
}

.outer-label,
.inner-label {
    fill: var(--chalk);
    font-family: var(--mono);
    letter-spacing: 0.04em;
    paint-order: stroke;
    stroke: rgba(237, 228, 204, 0.92);
    stroke-width: 8px;
    stroke-linejoin: round;
    filter:
        drop-shadow(1px 1px 0 var(--node-shadow-color, var(--gold)))
        drop-shadow(2px 2px 0 rgba(42, 32, 22, 0.26));
}

.outer-label {
    font-size: 20px;
    font-weight: 700;
}

.inner-label {
    font-size: 21px;
    font-weight: 800;
}

.node-muted {
    opacity: 1;
}

.node-muted .node-dot {
    opacity: 0.42;
}

.node-muted .outer-label,
.node-muted .inner-label {
    opacity: 0.92;
}

.node-active .outer-label,
.node-active .inner-label {
    fill: var(--chalk);
    filter:
        drop-shadow(1px 1px 0 var(--node-shadow-color, var(--gold)))
        drop-shadow(2px 2px 0 var(--node-shadow-color, var(--gold)))
        drop-shadow(3px 3px 0 rgba(42, 32, 22, 0.58));
}

@keyframes connection-draw {
    from {
        stroke-dashoffset: calc(var(--connection-length, 420) * 1px);
    }

    to {
        stroke-dashoffset: 0;
    }
}

@keyframes connection-arrival {
    0% {
        opacity: 0.78;
        transform: scale(1);
    }

    35% {
        opacity: 0.7;
        transform: scale(1.18);
    }

    100% {
        opacity: 0;
        transform: scale(1.85);
    }
}

@media (prefers-reduced-motion: reduce) {
    .edge-animated,
    .arrival-pulse {
        animation: none;
    }

    .edge-animated {
        stroke-dashoffset: 0;
    }
}

.center-word {
    fill: rgba(42, 32, 22, 0.56);
    font-family: var(--sans);
    font-size: 20px;
    font-weight: 900;
    letter-spacing: 0;
}

.prompt-output {
    min-height: 220px;
    font-family: var(--mono);
    font-size: 0.86rem;
}

.tour-overlay {
    position: fixed;
    inset: 0;
    z-index: 80;
    cursor: pointer;
}

.tour-overlay[hidden] {
    display: none;
}

.tour-spotlight {
    position: fixed;
    left: 50%;
    top: 50%;
    width: 160px;
    height: 120px;
    border: 3px solid var(--gold);
    border-radius: 28px;
    box-shadow:
        0 0 0 9999px rgba(18, 14, 10, 0.68),
        0 0 0 8px rgba(237, 228, 204, 0.36),
        0 0 34px rgba(196, 154, 69, 0.58);
    pointer-events: none;
    transform: translateZ(0);
    transition:
        left 320ms cubic-bezier(0.33, 1, 0.68, 1),
        top 320ms cubic-bezier(0.33, 1, 0.68, 1),
        width 320ms cubic-bezier(0.33, 1, 0.68, 1),
        height 320ms cubic-bezier(0.33, 1, 0.68, 1),
        border-radius 320ms cubic-bezier(0.33, 1, 0.68, 1);
}

.tour-card {
    position: fixed;
    left: 18px;
    top: 18px;
    width: min(390px, calc(100vw - 32px));
    padding: 22px 24px 20px;
    color: var(--ink);
    background:
        repeating-linear-gradient(
            to bottom,
            rgba(42, 32, 22, 0.018) 0,
            rgba(42, 32, 22, 0.018) 1px,
            transparent 1px,
            transparent 4px
        ),
        var(--cream);
    border: 2px solid var(--ink);
    border-radius: var(--radius-card);
    box-shadow: 0 20px 48px rgba(0, 0, 0, 0.42);
    cursor: pointer;
    transition:
        left 320ms cubic-bezier(0.33, 1, 0.68, 1),
        top 320ms cubic-bezier(0.33, 1, 0.68, 1);
}

.tour-card h2 {
    margin: 4px 0 8px;
    color: var(--chalk);
    font-size: clamp(1.35rem, 2.4vw, 1.9rem);
    line-height: 1.08;
    text-shadow: var(--title-shadow);
}

.tour-card p {
    margin: 0;
    color: var(--muted);
    font-size: 1rem;
    line-height: 1.55;
}

.tour-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 14px;
    margin-top: 18px;
}

#tourProgress {
    color: var(--gold);
    font-family: var(--mono);
    font-size: 0.78rem;
    font-weight: 700;
    letter-spacing: 0.14em;
    text-transform: uppercase;
}

.import-area {
    min-height: 92px;
    font-family: var(--mono);
    font-size: 0.86rem;
}

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

@media (max-width: 1280px) {
    .layout {
        grid-template-columns: var(--left-sidebar-width) minmax(0, 1fr) var(--right-sidebar-width);
    }

    .layout.left-collapsed {
        grid-template-columns: var(--sidebar-tab-width) minmax(0, 1fr) var(--right-sidebar-width);
    }

    .layout.right-collapsed {
        grid-template-columns: var(--left-sidebar-width) minmax(0, 1fr) var(--sidebar-tab-width);
    }

    .layout.left-collapsed.right-collapsed {
        grid-template-columns: var(--sidebar-tab-width) minmax(0, 1fr) var(--sidebar-tab-width);
    }

    .control-panel {
        grid-template-columns: 1fr;
    }

    .stage,
    .crt-monitor {
        min-height: 760px;
    }
}

@media (max-width: 980px) {
    [data-action="start-tour"] {
        display: none;
    }

    .layout {
        grid-template-columns: 1fr;
    }

    .layout.left-collapsed,
    .layout.right-collapsed,
    .layout.left-collapsed.right-collapsed {
        grid-template-columns: 1fr;
    }

    .control-panel {
        max-height: none;
        border-right: 0;
        border-bottom: 1px solid var(--line-subtle);
    }

    .insight-sidebar {
        max-height: none;
        border-left: 0;
        border-top: 1px solid var(--line-subtle);
        box-shadow: 0 -10px 24px var(--line-soft);
    }

    .control-panel > .sidebar-handle,
    .insight-sidebar > .sidebar-handle {
        display: none;
    }

    .layout.left-collapsed .control-panel,
    .layout.right-collapsed .insight-sidebar {
        padding: 18px 16px;
        overflow-y: visible;
    }

    .layout.left-collapsed .control-panel .panel-stack,
    .layout.right-collapsed .insight-sidebar #rightSidebarContent {
        display: block;
    }

    .panel-stack,
    #rightSidebarContent {
        max-height: none;
        overflow: visible;
        padding-right: 0;
        padding-left: 0;
    }

    .stage,
    .crt-monitor {
        min-height: 720px;
    }
}

@media (max-width: 720px) {
    .topbar {
        grid-template-columns: 1fr auto;
        min-height: 78px;
    }

    .topbar-detail {
        grid-column: 1 / -1;
        grid-row: 2;
        padding: 8px 0 0;
        border: 0;
        order: 3;
    }

    .brand img {
        width: 190px;
    }

    .control-panel {
        padding: 14px;
    }

    .insight-sidebar {
        padding: 14px;
    }

    .crt-monitor {
        height: 690px;
        min-height: 690px;
    }

    .map-card {
        height: 100%;
        min-height: 0;
        background:
            repeating-linear-gradient(
                to bottom,
                rgba(42, 32, 22, 0.018) 0,
                rgba(42, 32, 22, 0.018) 1px,
                transparent 1px,
                transparent 4px
            ),
            linear-gradient(180deg, #ede4cc 0%, #eee6d1 52%, #e9dfc4 100%);
    }

    .map-actions {
        left: 18px;
        top: auto;
        bottom: 18px;
        justify-content: flex-start;
    }

    .outer-label {
        font-size: 14px;
    }

    .inner-label {
        font-size: 15px;
    }

    .tour-card {
        padding: 18px;
    }

    .tour-card h2 {
        font-size: 1.35rem;
    }

    .tour-card p {
        font-size: 0.95rem;
    }
}
