:root {
    color-scheme: dark;
    --ui-scale: 0.8;
    --bg: #0c111d;
    --panel: #131a29;
    --panel-strong: #182134;
    --panel-soft: #111827;
    --line: rgba(148, 163, 184, 0.18);
    --line-strong: rgba(148, 163, 184, 0.32);
    --text: #ecf2ff;
    --muted: #9aa9c5;
    --primary: #5b8cff;
    --primary-strong: #4476ef;
    --green: #35c87a;
    --red: #ff6d7d;
    --orange: #f7bf53;
    --purple: #a586ff;
    --shadow: 0 20px 48px rgba(0, 0, 0, 0.32);
    --radius: 16px;
    --radius-sm: 11px;
    --card-width: 292px;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    background:
        radial-gradient(circle at top, rgba(91, 140, 255, 0.16), transparent 38%),
        linear-gradient(180deg, #09101c 0%, var(--bg) 100%);
    color: var(--text);
    font-family: "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
    font-size: 14px;
}

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

button {
    cursor: pointer;
    border: none;
}

code {
    padding: 2px 6px;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.08);
    color: #dce8ff;
}

.hidden {
    display: none !important;
}

.app-shell {
    min-height: 100vh;
}

.screen {
    min-height: 100vh;
}

.welcome-screen {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 26px;
}

.welcome-card {
    width: min(736px, 100%);
    padding: 32px;
    border: 1px solid var(--line);
    border-radius: 22px;
    background: rgba(19, 26, 41, 0.88);
    backdrop-filter: blur(18px);
    box-shadow: var(--shadow);
}

.eyebrow {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 11px;
    border-radius: 999px;
    background: rgba(91, 140, 255, 0.14);
    color: #b9ceff;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.welcome-card h1 {
    margin: 14px 0 10px;
    font-size: clamp(26px, 4.8vw, 43px);
    line-height: 1.05;
}

.welcome-copy {
    max-width: 608px;
    margin: 0;
    color: var(--muted);
    line-height: 1.7;
    font-size: 13px;
}

.welcome-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 11px;
    margin: 24px 0 19px;
}

.primary-button,
.secondary-button,
.ghost-button,
.danger-button,
.palette-button {
    padding: 10px 14px;
    border-radius: 10px;
    transition: transform 0.18s ease, background 0.18s ease, border-color 0.18s ease, opacity 0.18s ease;
}

.primary-button:hover,
.secondary-button:hover,
.ghost-button:hover,
.danger-button:hover,
.palette-button:hover {
    transform: translateY(-1px);
}

.primary-button {
    background: linear-gradient(135deg, var(--primary), #7a61ff);
    color: white;
    box-shadow: 0 10px 24px rgba(91, 140, 255, 0.3);
}

.secondary-button {
    background: rgba(255, 255, 255, 0.08);
    color: var(--text);
    border: 1px solid var(--line);
}

.ghost-button {
    background: transparent;
    color: #bfd3ff;
    border: 1px dashed rgba(191, 211, 255, 0.28);
}

.danger-button {
    background: rgba(255, 109, 125, 0.14);
    color: #ffc3ca;
    border: 1px solid rgba(255, 109, 125, 0.24);
}

.drop-zone {
    display: grid;
    place-items: center;
    gap: 6px;
    min-height: 176px;
    border: 1px dashed rgba(91, 140, 255, 0.35);
    border-radius: 19px;
    background:
        linear-gradient(180deg, rgba(91, 140, 255, 0.08), rgba(91, 140, 255, 0.03)),
        rgba(15, 22, 36, 0.85);
    text-align: center;
    transition: border-color 0.18s ease, background 0.18s ease, transform 0.18s ease;
}

.drop-zone.drag-over {
    border-color: #8ab0ff;
    background:
        linear-gradient(180deg, rgba(91, 140, 255, 0.16), rgba(91, 140, 255, 0.08)),
        rgba(15, 22, 36, 0.92);
    transform: translateY(-2px);
}

.drop-zone-icon {
    font-size: 27px;
    color: #b9ceff;
}

.drop-zone-title {
    font-size: 16px;
    font-weight: 700;
}

.drop-zone-description {
    color: var(--muted);
    font-size: 12px;
}

.feature-list,
.bullet-list,
.diagnostic-list {
    margin: 0;
    padding-left: 20px;
}

.feature-list {
    margin-top: 19px;
    color: var(--muted);
    line-height: 1.7;
    font-size: 12px;
}

.editor-screen {
    display: flex;
    flex-direction: column;
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    padding: 14px 19px;
    border-bottom: 1px solid var(--line);
    background: rgba(9, 14, 24, 0.72);
    backdrop-filter: blur(14px);
    position: sticky;
    top: 0;
    z-index: 24;
}

.brand-title {
    font-size: 15px;
    font-weight: 700;
}

.brand-subtitle {
    margin-top: 5px;
    color: var(--muted);
    font-size: 11px;
}

.topbar-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: flex-end;
}

.workspace {
    display: grid;
    grid-template-columns: 224px minmax(576px, 1fr) 288px;
    gap: 14px;
    padding: 14px;
    min-height: 0;
    flex: 1;
}

.side-column,
.canvas-column {
    min-height: 0;
}

.side-column {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.panel-card {
    display: flex;
    flex-direction: column;
    gap: 11px;
    padding: 14px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: rgba(19, 26, 41, 0.9);
    box-shadow: var(--shadow);
}

.panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}

.panel-header h2 {
    margin: 0;
    font-size: 14px;
}

.panel-tip,
.canvas-stats {
    color: var(--muted);
    font-size: 10px;
}

.node-palette {
    display: grid;
    gap: 8px;
}

.palette-button {
    text-align: left;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.08);
    color: var(--text);
}

.palette-button[data-node-type="npc"] { border-left: 4px solid #5b8cff; }
.palette-button[data-node-type="player"] { border-left: 4px solid #88d8ff; }
.palette-button[data-node-type="statement"] { border-left: 4px solid #b09fff; }
.palette-button[data-node-type="choice"] { border-left: 4px solid var(--orange); }
.palette-button[data-node-type="permission"] { border-left: 4px solid var(--green); }
.palette-button[data-node-type="item"] { border-left: 4px solid #d98cff; }
.palette-button[data-node-type="vault"] { border-left: 4px solid #35c87a; }
.palette-button[data-node-type="playerpoints"] { border-left: 4px solid #52e0c4; }
.palette-button[data-node-type="command"] { border-left: 4px solid #ffb86b; }
.palette-button[data-node-type="message"] { border-left: 4px solid #78d980; }
.palette-button[data-node-type="title"] { border-left: 4px solid #f7bf53; }
.palette-button[data-node-type="actionbar"] { border-left: 4px solid #88d8ff; }
.palette-button[data-node-type="sound"] { border-left: 4px solid #ff8cc6; }
.palette-button[data-node-type="potion"] { border-left: 4px solid #a586ff; }
.palette-button[data-node-type="end"] { border-left: 4px solid #9aa9c5; }

.compact-list {
    color: var(--muted);
    line-height: 1.65;
    font-size: 12px;
}

.diagnostics-card {
    min-height: 176px;
}

.diagnostic-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding-left: 18px;
    color: var(--muted);
    line-height: 1.6;
}

.diagnostic-list li[data-level="error"] {
    color: #ffc4cb;
}

.diagnostic-list li[data-level="warning"] {
    color: #ffe0a0;
}

.canvas-panel {
    height: calc(100vh - 92px);
    min-height: 760px;
    overflow: hidden;
}

.canvas-panel-header {
    padding-bottom: 4px;
}

.canvas-frame {
    position: relative;
    flex: 1;
    min-height: 0;
}

.canvas-scroller {
    position: relative;
    width: 100%;
    height: 100%;
    overflow: auto;
    scrollbar-width: none;
    -ms-overflow-style: none;
    border-radius: 16px;
    background:
        linear-gradient(rgba(255, 255, 255, 0.025) 1px, transparent 1px),
        linear-gradient(90deg, rgba(255, 255, 255, 0.025) 1px, transparent 1px),
        radial-gradient(circle at top, rgba(91, 140, 255, 0.08), transparent 42%),
        #0c1321;
    background-size: 28px 28px, 28px 28px, auto, auto;
    border: 1px solid rgba(255, 255, 255, 0.04);
    cursor: grab;
}

.canvas-scroller::-webkit-scrollbar {
    width: 0;
    height: 0;
    display: none;
}

.canvas-scroller.panning {
    cursor: grabbing;
}

.graph-canvas {
    position: relative;
    min-width: 1800px;
    min-height: 1200px;
    --canvas-scale: 1;
    --canvas-world-width: 1800px;
    --canvas-world-height: 1200px;
}

.edge-layer,
.node-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: var(--canvas-world-width);
    height: var(--canvas-world-height);
    transform-origin: top left;
    transform: scale(var(--canvas-scale));
}

.edge-layer {
    pointer-events: auto;
    overflow: visible;
}

.edge-group {
    pointer-events: none;
}

.edge-group.interactive .edge-path,
.edge-group.interactive .edge-label {
    pointer-events: auto;
    cursor: pointer;
}

.canvas-zoom-controls {
    position: absolute;
    left: 14px;
    bottom: 14px;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 14px;
    background: rgba(10, 15, 26, 0.88);
    box-shadow: 0 14px 30px rgba(0, 0, 0, 0.28);
    z-index: 12;
}

.canvas-zoom-button {
    width: 34px;
    height: 34px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.08);
    color: var(--text);
    font-size: 20px;
    line-height: 1;
}

.canvas-zoom-button:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

.canvas-zoom-label {
    min-width: 52px;
    text-align: center;
    color: #dce8ff;
    font-size: 12px;
    font-weight: 700;
}

.node-card {
    position: absolute;
    width: var(--card-width);
    min-height: 152px;
    padding: 0;
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 20px;
    background: linear-gradient(180deg, rgba(22, 30, 48, 0.98), rgba(16, 21, 34, 0.98));
    box-shadow: 0 18px 40px rgba(0, 0, 0, 0.34);
    overflow: hidden;
    cursor: pointer;
}

.node-card.selected {
    outline: 2px solid rgba(91, 140, 255, 0.85);
    box-shadow: 0 22px 44px rgba(50, 90, 200, 0.28);
}

.node-card.start-node {
    border-color: rgba(247, 191, 83, 0.52);
}

.node-card.link-target {
    outline: 2px solid rgba(247, 191, 83, 0.82);
    box-shadow: 0 0 0 4px rgba(247, 191, 83, 0.14), 0 22px 44px rgba(50, 90, 200, 0.24);
}

.node-input-port {
    position: absolute;
    left: -7px;
    top: 50%;
    width: 14px;
    height: 14px;
    border-radius: 999px;
    background: #dce8ff;
    border: 3px solid rgba(12, 19, 33, 0.95);
    transform: translateY(-50%);
    box-shadow: 0 0 0 3px rgba(91, 140, 255, 0.12);
}

.node-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 14px 16px;
    cursor: grab;
    user-select: none;
}

.node-card-header:active {
    cursor: grabbing;
}

.node-card-header[data-type="npc"] { background: linear-gradient(135deg, rgba(91, 140, 255, 0.28), rgba(91, 140, 255, 0.12)); }
.node-card-header[data-type="player"] { background: linear-gradient(135deg, rgba(136, 216, 255, 0.26), rgba(136, 216, 255, 0.12)); }
.node-card-header[data-type="statement"] { background: linear-gradient(135deg, rgba(165, 134, 255, 0.28), rgba(165, 134, 255, 0.12)); }
.node-card-header[data-type="choice"] { background: linear-gradient(135deg, rgba(247, 191, 83, 0.28), rgba(247, 191, 83, 0.12)); }
.node-card-header[data-type="permission"] { background: linear-gradient(135deg, rgba(53, 200, 122, 0.28), rgba(53, 200, 122, 0.12)); }
.node-card-header[data-type="item"] { background: linear-gradient(135deg, rgba(217, 140, 255, 0.26), rgba(217, 140, 255, 0.12)); }
.node-card-header[data-type="vault"] { background: linear-gradient(135deg, rgba(53, 200, 122, 0.28), rgba(53, 200, 122, 0.12)); }
.node-card-header[data-type="playerpoints"] { background: linear-gradient(135deg, rgba(82, 224, 196, 0.26), rgba(82, 224, 196, 0.12)); }
.node-card-header[data-type="command"] { background: linear-gradient(135deg, rgba(255, 184, 107, 0.28), rgba(255, 184, 107, 0.12)); }
.node-card-header[data-type="message"] { background: linear-gradient(135deg, rgba(120, 217, 128, 0.26), rgba(120, 217, 128, 0.12)); }
.node-card-header[data-type="title"] { background: linear-gradient(135deg, rgba(247, 191, 83, 0.28), rgba(247, 191, 83, 0.12)); }
.node-card-header[data-type="actionbar"] { background: linear-gradient(135deg, rgba(136, 216, 255, 0.26), rgba(136, 216, 255, 0.12)); }
.node-card-header[data-type="sound"] { background: linear-gradient(135deg, rgba(255, 140, 198, 0.26), rgba(255, 140, 198, 0.12)); }
.node-card-header[data-type="potion"] { background: linear-gradient(135deg, rgba(165, 134, 255, 0.28), rgba(165, 134, 255, 0.12)); }
.node-card-header[data-type="end"] { background: linear-gradient(135deg, rgba(154, 169, 197, 0.22), rgba(154, 169, 197, 0.1)); }

.node-card-title {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.node-card-id {
    font-size: 16px;
    font-weight: 700;
}

.node-card-type {
    color: rgba(236, 242, 255, 0.74);
    font-size: 12px;
}

.node-card-badges {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: flex-end;
}

.node-badge {
    padding: 5px 10px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.02em;
    background: rgba(255, 255, 255, 0.09);
    color: #d9e5ff;
}

.node-badge.start {
    background: rgba(247, 191, 83, 0.18);
    color: #ffe5a2;
}

.node-badge.take {
    background: rgba(255, 109, 125, 0.16);
    color: #ffc9d0;
}

.node-card-body {
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.node-summary-title {
    font-size: 15px;
    font-weight: 700;
}

.node-summary-text {
    color: var(--muted);
    font-size: 13px;
    line-height: 1.65;
    white-space: pre-wrap;
    word-break: break-word;
}

.node-branches {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.branch-chip-shell {
    display: flex;
    align-items: center;
    gap: 8px;
    max-width: 100%;
}

.branch-chip-main {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    min-width: 0;
    flex: 1;
    padding: 8px 12px;
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.06);
    color: #dce8ff;
    border: 1px solid rgba(255, 255, 255, 0.08);
}

.branch-chip-main.clickable {
    cursor: pointer;
}

.branch-chip-label {
    flex: 0 0 auto;
    padding: 3px 8px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 700;
    background: rgba(255, 255, 255, 0.08);
}

.branch-chip-target {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 12px;
}

.branch-link-handle {
    width: 16px;
    height: 16px;
    flex: 0 0 16px;
    border-radius: 999px;
    background: linear-gradient(135deg, rgba(255,255,255,0.95), rgba(195, 214, 255, 0.92));
    border: 3px solid rgba(12, 19, 33, 0.95);
    box-shadow: 0 0 0 3px rgba(91, 140, 255, 0.12);
    cursor: crosshair;
    transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.branch-link-handle:hover {
    transform: scale(1.08);
    box-shadow: 0 0 0 4px rgba(91, 140, 255, 0.18);
}

.branch-chip-empty {
    display: inline-flex;
    align-items: center;
    padding: 8px 12px;
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.05);
    color: var(--muted);
    border: 1px dashed rgba(255, 255, 255, 0.08);
    font-size: 12px;
}

.branch-chip-shell[data-color="next"] .branch-chip-label { background: rgba(91, 140, 255, 0.2); color: #c5d8ff; }
.branch-chip-shell[data-color="pass"] .branch-chip-label { background: rgba(53, 200, 122, 0.2); color: #bcf3d7; }
.branch-chip-shell[data-color="fail"] .branch-chip-label { background: rgba(255, 109, 125, 0.18); color: #ffc3ca; }
.branch-chip-shell[data-color="choice"] .branch-chip-label { background: rgba(247, 191, 83, 0.2); color: #ffe2aa; }

.stack-form {
    display: flex;
    flex-direction: column;
    gap: 13px;
}

.form-grid {
    display: grid;
    gap: 11px;
}

.form-grid.two-columns {
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

.field-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.field-label {
    color: #dce7fb;
    font-size: 11px;
    font-weight: 700;
}

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

.text-input,
.select-input,
.text-area,
.number-input {
    width: 100%;
    padding: 9px 11px;
    border-radius: 10px;
    border: 1px solid rgba(255, 255, 255, 0.08);
    background: rgba(10, 15, 26, 0.92);
    color: var(--text);
    outline: none;
}

.text-input:focus,
.select-input:focus,
.text-area:focus,
.number-input:focus {
    border-color: rgba(91, 140, 255, 0.7);
    box-shadow: 0 0 0 3px rgba(91, 140, 255, 0.16);
}

.text-area {
    min-height: 94px;
    resize: vertical;
    line-height: 1.5;
}

.toggle-row {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--text);
    font-size: 12px;
}

.toggle-row input[type="checkbox"] {
    width: 15px;
    height: 15px;
    accent-color: var(--primary);
}

.section-divider {
    height: 1px;
    background: var(--line);
}

.section-title {
    margin: 0;
    color: #dce7fb;
    font-size: 13px;
    letter-spacing: 0.03em;
    text-transform: uppercase;
}

.option-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.option-card {
    padding: 11px;
    border-radius: 13px;
    border: 1px solid rgba(247, 191, 83, 0.2);
    background: rgba(247, 191, 83, 0.06);
}

.option-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 10px;
}

.option-card-title {
    font-size: 11px;
    font-weight: 700;
    color: #ffe0a0;
}

.option-card-delete {
    padding: 5px 8px;
    border-radius: 8px;
    background: rgba(255, 109, 125, 0.16);
    color: #ffc4cb;
}

.empty-state {
    color: var(--muted);
    line-height: 1.7;
    font-size: 12px;
}

.edge-path {
    fill: none;
    stroke-width: 2.5;
    opacity: 0.95;
}

.edge-path[data-color="next"] { stroke: rgba(91, 140, 255, 0.9); }
.edge-path[data-color="pass"] { stroke: rgba(53, 200, 122, 0.92); }
.edge-path[data-color="fail"] { stroke: rgba(255, 109, 125, 0.9); }
.edge-path[data-color="choice"] { stroke: rgba(247, 191, 83, 0.92); }

.edge-path.preview {
    stroke-dasharray: 10 8;
    stroke-width: 3;
    opacity: 0.92;
}

.edge-label {
    font-size: 12px;
    fill: #dbe8ff;
    paint-order: stroke;
    stroke: rgba(11, 18, 29, 0.96);
    stroke-width: 5px;
    stroke-linejoin: round;
}

.edge-label.preview {
    fill: #ffffff;
}

.edge-group.is-highlighted .edge-path {
    stroke-width: 3.5;
}

.edge-group.interactive:hover .edge-path {
    stroke-width: 3.6;
}

.toast {
    position: fixed;
    right: 24px;
    bottom: 24px;
    max-width: 360px;
    padding: 14px 16px;
    border-radius: 14px;
    background: rgba(11, 18, 29, 0.92);
    color: var(--text);
    border: 1px solid rgba(255, 255, 255, 0.08);
    box-shadow: var(--shadow);
    z-index: 60;
}

.toast[data-tone="error"] {
    border-color: rgba(255, 109, 125, 0.3);
    color: #ffd7dd;
}

.toast[data-tone="success"] {
    border-color: rgba(53, 200, 122, 0.3);
    color: #d7ffeb;
}

@media (max-width: 1500px) {
    .workspace {
        grid-template-columns: 208px minmax(528px, 1fr) 256px;
    }
}

@media (max-width: 1280px) {
    .workspace {
        grid-template-columns: 1fr;
    }

    .canvas-panel {
        height: 720px;
    }
}
