:root {
    color-scheme: dark;
    --bg: #08090b;
    --panel: #15181d;
    --panel-2: #1d2229;
    --line: #2a3038;
    --text: #e8edf2;
    --muted: #87919c;
    --accent: #6ee7d8;
    --danger: #ff6b6b;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    background: var(--bg);
    color: var(--text);
    font: 14px/1.45 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: 240px;
    padding: 22px 16px;
    background: #0d0f13;
    border-right: 1px solid var(--line);
}

.brand {
    color: var(--accent);
    font-weight: 800;
    letter-spacing: 2px;
    font-size: 18px;
}

.muted {
    color: var(--muted);
    margin: 6px 0 22px;
}

nav button {
    display: block;
    width: 100%;
    margin: 4px 0;
    padding: 10px 12px;
    border: 1px solid transparent;
    border-radius: 8px;
    background: transparent;
    color: var(--text);
    text-align: left;
    cursor: pointer;
}

nav button.active,
nav button:hover {
    background: var(--panel);
    border-color: var(--line);
}

.workspace {
    margin-left: 240px;
    padding: 22px;
}

.topbar {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 18px;
    margin-bottom: 18px;
}

h1, h2, p {
    margin: 0;
}

h1 {
    font-size: 28px;
}

.topbar p {
    color: var(--muted);
    margin-top: 6px;
}

.actions,
.formActions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.button {
    border: 1px solid #33736d;
    border-radius: 8px;
    background: #123d39;
    color: var(--text);
    padding: 9px 12px;
    cursor: pointer;
    text-decoration: none;
}

.button.secondary {
    background: var(--panel);
    border-color: var(--line);
}

.button.active {
    border-color: var(--accent);
    box-shadow: 0 0 0 1px rgba(110, 231, 216, 0.28);
}

.button.danger {
    background: #442024;
    border-color: var(--danger);
}

.layout {
    display: grid;
    grid-template-columns: minmax(0, 1.2fr) minmax(360px, 0.8fr);
    gap: 16px;
}

.panel {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    min-height: 240px;
}

.table-wrap {
    overflow: auto;
    max-height: calc(100vh - 132px);
}

table {
    width: 100%;
    border-collapse: collapse;
}

th,
td {
    border-bottom: 1px solid var(--line);
    padding: 9px 10px;
    text-align: left;
    vertical-align: top;
    max-width: 280px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

tr {
    cursor: pointer;
}

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

.editor {
    padding: 16px;
}

.field {
    margin: 12px 0;
}

.uploadBox {
    margin: 12px 0 18px;
    padding: 14px;
    border: 1px dashed #33736d;
    border-radius: 8px;
    background: #10201f;
}

.lockSettingsBox {
    margin: 12px 0 18px;
    padding: 14px;
    border: 1px solid #33736d;
    border-radius: 8px;
    background: #10201f;
}

.storyToolBox {
    margin: 12px 0 18px;
    padding: 14px;
    border: 1px solid #383c72;
    border-radius: 8px;
    background: #10121f;
}

.lockSettingsTitle {
    color: var(--accent);
    font-weight: 800;
    margin-bottom: 4px;
}

.lockSettingsGrid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 10px;
    margin-top: 12px;
}

.choiceEditorList {
    display: grid;
    gap: 10px;
    margin: 12px 0;
}

.choiceEditorRow {
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #0d0f13;
}

.choiceEditorRow textarea {
    min-height: 58px;
}

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

.mediaPreview {
    margin: 12px 0 18px;
    padding: 14px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #0d0f13;
}

.mediaPreviewTitle {
    margin-bottom: 10px;
    color: var(--muted);
}

.mediaPreview img,
.mediaPreview video {
    display: block;
    width: 100%;
    max-height: 320px;
    object-fit: contain;
    border-radius: 8px;
    background: #050607;
}

.mediaPreview audio {
    width: 100%;
}

.mediaPreviewEmpty {
    color: var(--muted);
}

.mediaPreviewLink {
    display: block;
    margin-top: 10px;
    color: var(--accent);
    word-break: break-all;
}

.hint {
    margin-top: 8px;
    color: var(--muted);
    font-size: 12px;
}

label {
    display: block;
    margin-bottom: 6px;
    color: var(--muted);
}

input,
textarea,
select {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #0d0f13;
    color: var(--text);
    padding: 9px 10px;
}

textarea {
    min-height: 96px;
    resize: vertical;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

#statusBox {
    min-height: 44px;
    white-space: pre-wrap;
    color: var(--muted);
}

.graphPanel {
    margin-bottom: 16px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #0d0f13;
    overflow: hidden;
}

.graphToolbar {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    padding: 12px;
    border-bottom: 1px solid var(--line);
    background: #11151a;
}

.graphTitle {
    margin-right: auto;
    color: var(--accent);
    font-weight: 800;
}

.graphFilter {
    width: 220px;
}

.graphViewport {
    height: min(70vh, 720px);
    overflow: auto;
    background:
        radial-gradient(circle at 20px 20px, rgba(110, 231, 216, 0.08) 0 1px, transparent 1px),
        linear-gradient(135deg, #0a0c0f, #12151a);
    background-size: 28px 28px, auto;
}

.graphCanvas {
    position: relative;
    min-width: 100%;
    min-height: 100%;
}

.graphEdges {
    position: absolute;
    inset: 0;
    overflow: visible;
    pointer-events: none;
}

.graphEdge {
    fill: none;
    stroke: #59616d;
    stroke-width: 2.5;
    opacity: 0.86;
}

.graphEdge-choice {
    stroke: var(--accent);
}

.graphEdgeLabel {
    fill: #aeb7c4;
    font-size: 11px;
    paint-order: stroke;
    stroke: #0a0c0f;
    stroke-width: 4px;
    stroke-linejoin: round;
}

.graphEdgeLabel-choice {
    fill: var(--accent);
}

.graphNode {
    position: absolute;
    width: 238px;
    min-height: 112px;
    padding: 11px;
    border: 1px solid #303845;
    border-radius: 8px;
    background: #171b22;
    box-shadow: 0 14px 28px rgba(0, 0, 0, 0.32);
    cursor: grab;
    user-select: none;
}

.graphNode:active {
    cursor: grabbing;
}

.graphNode-message {
    border-color: #32514f;
}

.graphNode-choice {
    border-color: #6b5b2e;
}

.graphNode-condition {
    border-color: #6b3f72;
}

.graphNode-minigame {
    border-color: #394c88;
}

.graphNode-image,
.graphNode-audio,
.graphNode-video {
    border-color: #345b79;
}

.graphNodeType {
    display: inline-block;
    margin-bottom: 7px;
    padding: 2px 7px;
    border-radius: 999px;
    background: #0c1015;
    color: var(--accent);
    font-size: 11px;
    font-weight: 800;
    text-transform: uppercase;
}

.graphNodeId {
    font-weight: 800;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.graphNodeText {
    min-height: 36px;
    margin-top: 5px;
    color: #cfd6df;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.graphNodeMeta {
    margin-top: 8px;
    color: var(--muted);
    font-size: 11px;
}

.graphPort {
    display: block;
    width: 100%;
    margin-top: 8px;
    padding: 5px 8px;
    border: 1px solid #4c5562;
    border-radius: 999px;
    background: #0c1015;
    color: #cfd6df;
    text-align: left;
    font-size: 11px;
    cursor: crosshair;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.graphPort::after {
    content: "";
    float: right;
    width: 9px;
    height: 9px;
    margin-top: 3px;
    border-radius: 50%;
    background: currentColor;
}

.graphPortNext {
    color: #aeb7c4;
}

.graphPortChoice {
    color: var(--accent);
}

.graphChoicePorts {
    margin-top: 4px;
}

.graphLinkPreview {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    overflow: visible;
    z-index: 20;
}

@media (max-width: 1000px) {
    .sidebar {
        position: static;
        width: auto;
    }

    .workspace {
        margin-left: 0;
    }

    .layout,
    .topbar,
    .lockSettingsGrid {
        display: block;
    }

    .editor {
        margin-top: 16px;
    }

    .graphFilter {
        width: 100%;
    }
}
