@font-face { font-family: "Studio Mono"; src: url("assets/fonts/MEK-Mono.woff2") format("woff2"); font-display: block; }
@font-face { font-family: "Studio Dings"; src: url("assets/fonts/MEK-Dings.woff2") format("woff2"); font-display: block; }
@font-face { font-family: "Studio Sans"; src: url("assets/fonts/MEKSans-Regular.woff2") format("woff2"); font-display: block; }

:root {
  color-scheme: dark;
  --black: #050505;
  --black-soft: #0d0d0b;
  --bone: #e8e2c6;
  --bone-dim: #999581;
  --line: #57554a;
  --blood: #b51520;
  --green: #8daa78;
  --blue: #8398b3;
  --node-width: 188px;
  font: 15px/1.25 "Studio Sans", monospace;
  font-synthesis: none;
}

* { box-sizing: border-box; font-synthesis: none; }
.fonts-loading body { visibility: hidden; }
html, body { width: 100%; height: 100%; }
body { margin: 0; overflow: hidden; color: var(--bone); background: var(--black); }
button, input, select, textarea, output { font: inherit; }
button, input, select, textarea {
  min-width: 0;
  color: var(--bone);
  background: var(--black);
  border: 1px solid var(--bone-dim);
  border-radius: 0;
}
button { min-height: 30px; padding: 4px 8px; cursor: pointer; font-family: "Studio Mono"; }
button:hover, button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, a:focus-visible { outline: 1px solid var(--bone); outline-offset: 1px; }
button:active, button.active { color: var(--black); background: var(--bone); }
button:disabled { opacity: .35; cursor: default; }
input, select { height: 30px; padding: 3px 6px; }
input[type="checkbox"] { width: 16px; height: 16px; padding: 0; accent-color: var(--bone); }
textarea { min-height: 58px; padding: 6px; resize: vertical; }

.menu-bar {
  position: relative;
  z-index: 20;
  height: 42px;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 12px;
  color: var(--black);
  background: var(--bone);
  border-bottom: 2px solid var(--black);
  user-select: none;
}
.menu-gem { width: 12px; height: 12px; flex: 0 0 12px; border: 2px solid currentColor; transform: rotate(45deg); }
.menu-bar > strong { white-space: nowrap; font: 18px "Studio Sans"; }
.menu-bar nav { display: flex; align-self: stretch; }
.menu-bar nav button { min-height: 0; padding: 0 10px; color: var(--black); background: transparent; border: 0; }
.menu-bar nav button:hover { color: var(--bone); background: var(--black); outline: none; }
.painter-link { padding: 5px 7px; color: var(--black); border: 1px solid var(--black); text-decoration: none; white-space: nowrap; font: 12px "Studio Mono"; }
.hardware-budget { min-width: 210px; margin-left: auto; display: grid; grid-template-columns: auto minmax(54px,1fr) auto; align-items: center; gap: 7px; font: 11px "Studio Mono"; }
.budget-track { height: 8px; overflow: hidden; border: 1px solid var(--black); background: transparent; }
#budgetBar { display: block; width: 0; height: 100%; background: var(--black); transition: width .2s; }
.hardware-budget.warning #budgetBar { background: #8a4e15; }
.hardware-budget.danger #budgetBar, .hardware-budget.invalid #budgetBar { background: var(--blood); }

.studio-shell {
  height: calc(100vh - 42px);
  display: grid;
  grid-template-columns: 220px minmax(440px,1fr) 334px;
  gap: 8px;
  padding: 8px;
  overflow: hidden;
}
.library-column, .workbench-column { min-width: 0; min-height: 0; padding-right: 4px; scrollbar-color: var(--bone-dim) var(--black); }
.library-column { overflow-y: auto; }
.workbench-column { display: grid; grid-template-rows: minmax(260px,1fr) auto; gap: 8px; overflow: hidden; }
.graph-column { min-width: 0; min-height: 0; }
.mac-window { border: 1px solid var(--bone); background: var(--black-soft); box-shadow: 4px 4px 0 #000; }
.library-column .mac-window { margin-bottom: 9px; }
.title-bar {
  height: 29px;
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 3px 6px;
  color: var(--black);
  background: var(--bone);
  border-bottom: 1px solid var(--black);
  font: 12px "Studio Mono";
  letter-spacing: .06em;
  white-space: nowrap;
  user-select: none;
}
.title-bar output { color: inherit; }
.close-box, .zoom-box { width: 15px; height: 15px; flex: 0 0 15px; border: 1px solid var(--black); }
.close-box::after { content: ""; display: block; width: 9px; height: 1px; margin: 6px 2px; background: var(--black); transform: rotate(45deg); }
.zoom-box::after { content: ""; display: block; width: 8px; height: 8px; margin: 2px; border: 1px solid var(--black); }
.stripes { flex: 1; height: 11px; border-top: 1px solid var(--black); border-bottom: 1px solid var(--black); box-shadow: inset 0 2px 0 var(--bone), inset 0 3px 0 var(--black), inset 0 -2px 0 var(--bone), inset 0 -3px 0 var(--black); opacity: .75; }

.library-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; padding: 6px; border-bottom: 1px solid var(--line); }
.library-actions button { font-size: 11px; }
.scene-list, .entity-list { padding: 4px; }
.scene-list { min-height: 120px; max-height: 36vh; overflow-y: auto; }
.scene-item, .entity-item { width: 100%; min-height: 39px; display: grid; grid-template-columns: 20px minmax(0,1fr) auto; align-items: center; gap: 6px; padding: 5px 6px; border: 0; border-bottom: 1px solid #282822; text-align: left; }
.scene-item strong, .entity-item strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font: 11px "Studio Mono"; }
.scene-item small, .entity-item small { display: block; color: var(--bone-dim); font: 11px "Studio Sans"; }
.scene-item.selected, .entity-item.selected { color: var(--black); background: var(--bone); }
.scene-item.selected small, .entity-item.selected small { color: #49473e; }
.scene-symbol { display: grid; place-items: center; width: 18px; height: 18px; border: 1px solid currentColor; font: 9px "Studio Mono"; }
.entry-badge { font: 9px "Studio Mono"; }
.entity-group-title { margin: 6px 4px 2px; color: var(--bone-dim); font: 9px "Studio Mono"; letter-spacing: .12em; }
.empty-list { padding: 10px 7px; color: var(--bone-dim); font-size: 12px; }
.hardware-facts { margin: 0; padding: 4px 7px; }
.hardware-facts div { display: grid; grid-template-columns: 64px 1fr; gap: 5px; padding: 4px 0; border-bottom: 1px dotted #34332c; }
.hardware-facts dt, .hardware-facts dd { margin: 0; font: 10px "Studio Mono"; }
.hardware-facts dt { color: var(--bone-dim); }
.micro-note { margin: 7px; color: #777568; font-size: 11px; line-height: 1.35; }

.graph-window { height: 100%; display: grid; grid-template-rows: 29px 38px minmax(0,1fr) 27px; }
.graph-toolbar { display: flex; align-items: center; gap: 8px; padding: 4px 6px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.graph-toolbar button { min-height: 27px; font-size: 10px; }
.graph-toolbar label { display: flex; align-items: center; gap: 4px; color: var(--bone-dim); font: 10px "Studio Mono"; }
.graph-toolbar select { width: 70px; height: 27px; font-size: 10px; }
.toolbar-rule { width: 1px; height: 22px; background: var(--line); }
#linkHint { overflow: hidden; color: var(--bone-dim); text-overflow: ellipsis; font: 10px "Studio Mono"; }
.graph-mode { margin-left: auto; display: flex; align-items: center; gap: 5px; font: 9px "Studio Mono"; }
.status-lamp { width: 7px; height: 7px; border: 1px solid currentColor; background: var(--blood); }
.status-lamp.ready { background: var(--green); }
.graph-viewport {
  position: relative;
  min-height: 0;
  overflow: auto;
  background-color: #0a0a09;
  background-image: linear-gradient(#1a1a17 1px, transparent 1px), linear-gradient(90deg,#1a1a17 1px,transparent 1px), linear-gradient(#11110f 1px,transparent 1px), linear-gradient(90deg,#11110f 1px,transparent 1px);
  background-size: 80px 80px,80px 80px,16px 16px,16px 16px;
  scrollbar-color: var(--bone-dim) var(--black);
}
.graph-viewport.link-pending { cursor: crosshair; }
.graph-world { position: relative; width: 1800px; height: 1100px; transform-origin: 0 0; }
.graph-connections, .graph-nodes { position: absolute; inset: 0; width: 1800px; height: 1100px; }
.graph-connections { overflow: visible; }
.connection-line { fill: none; stroke: #797666; stroke-width: 2; }
.connection-hit { fill: none; stroke: transparent; stroke-width: 14; cursor: pointer; pointer-events: stroke; }
.connection-line.selected { stroke: var(--bone); stroke-width: 3; }
.connection-line.menu-link { stroke-dasharray: 5 4; }
.connection-label { fill: var(--bone-dim); font: 10px "Studio Mono"; pointer-events: none; }

.scene-node { position: absolute; width: var(--node-width); color: var(--bone); background: #10100e; border: 1px solid var(--bone-dim); box-shadow: 4px 4px 0 rgba(0,0,0,.65); user-select: none; }
.scene-node.selected { border-color: var(--bone); box-shadow: 0 0 0 1px var(--bone),4px 4px 0 rgba(0,0,0,.8); }
.scene-node.start-node::after { content: "START"; position: absolute; right: 5px; top: -17px; color: var(--bone); font: 9px "Studio Mono"; }
.node-header { height: 25px; display: flex; align-items: center; gap: 5px; padding: 3px 6px; color: var(--black); background: var(--bone); cursor: grab; font: 10px "Studio Mono"; }
.node-header:active { cursor: grabbing; }
.scene-node[data-kind="menu"] .node-header { background: #bfc6af; }
.scene-node[data-kind="finale"] .node-header { color: var(--bone); background: var(--blood); }
.node-header strong { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.node-header small { margin-left: auto; font-size: 8px; }
.node-body { display: grid; grid-template-columns: 64px 1fr; min-height: 57px; }
.node-thumb { width: 64px; height: 59px; object-fit: fill; image-rendering: pixelated; border-right: 1px solid var(--line); background: #050505; }
.node-meta { min-width: 0; display: grid; align-content: center; gap: 4px; padding: 5px; }
.node-meta span { overflow: hidden; color: var(--bone-dim); text-overflow: ellipsis; white-space: nowrap; font: 9px "Studio Mono"; }
.node-meta strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font: 10px "Studio Sans"; }
.node-port { position: absolute; top: 46px; z-index: 3; width: 18px; height: 18px; min-height: 0; display: grid; place-items: center; padding: 0; border: 1px solid var(--bone); border-radius: 50%; background: var(--black); font-size: 9px; }
.node-port.input { left: -10px; }
.node-port.output { right: -10px; color: var(--black); background: var(--bone); }
.node-port.pending { outline: 2px solid var(--blood); outline-offset: 2px; }
.node-event { padding: 4px 6px; border-top: 1px solid var(--line); color: var(--bone-dim); font: 8px "Studio Mono"; }
.graph-footer { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 0 7px; color: var(--bone-dim); border-top: 1px solid var(--line); font: 9px "Studio Mono"; }

.inspector-window { min-height: 0; display: grid; grid-template-rows: 29px minmax(0,1fr); overflow: hidden; }
.inspector { min-height: 0; display: grid; align-content: start; gap: 7px; padding: 8px; overflow-y: auto; scrollbar-color: var(--bone-dim) var(--black); }
.inspector fieldset { min-width: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin: 0; padding: 7px; border: 1px solid var(--line); }
.inspector legend { padding: 0 4px; color: var(--bone-dim); font: 9px "Studio Mono"; }
.field { min-width: 0; display: grid; gap: 3px; }
.field.full { grid-column: 1/-1; }
.field > span { color: var(--bone-dim); font: 9px "Studio Mono"; }
.field.checkbox-field { display: flex; align-items: center; gap: 5px; }
.field.checkbox-field > span { order: 2; }
.inspector input, .inspector select, .inspector textarea { width: 100%; font-size: 12px; }
.inspector-actions { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 5px; }
.inspector-actions button { font-size: 9px; }
.scene-actions [data-action="open-background-painter"] { grid-column: 1 / -1; }
.danger-button { color: #ef9097; }
.menu-item-editor { display: grid; grid-template-columns: 1fr 1fr 26px; gap: 3px; }
.menu-item-editor input, .menu-item-editor select { height: 26px; font-size: 10px; }
.menu-item-editor button { min-height: 26px; padding: 2px; }
.inspector-empty { min-height: 150px; display: grid; place-items: center; color: var(--bone-dim); text-align: center; font: 11px "Studio Mono"; }

.preview-window { overflow: hidden; }
.preview-stage { display: grid; place-items: center; padding: 8px; background: #151512; border-bottom: 1px solid var(--line); }
.preview-bezel { position: relative; width: min(240px,100%); aspect-ratio: 240/220; overflow: hidden; border: 2px solid var(--bone-dim); background: #000; box-shadow: 0 0 15px rgba(232,226,198,.08); }
#storyPreview, .preview-mask { position: absolute; inset: 0; width: 100%; height: 100%; }
#storyPreview { image-rendering: pixelated; image-rendering: crisp-edges; }
.preview-mask { pointer-events: none; }
.preview-mask::before, .preview-mask::after { content: ""; position: absolute; inset: 0; background-position: 0 0; background-repeat: repeat; background-size: 6px 4px; image-rendering: pixelated; }
.preview-mask::before { opacity: var(--slot-colour-opacity,.018); background-image: var(--slot-colour-image,none); mix-blend-mode: color; }
.preview-mask::after { opacity: var(--slot-junction-opacity,.025); background-image: var(--slot-junction-image,none); mix-blend-mode: multiply; }
.transport { display: grid; grid-template-columns: 2fr 1fr; gap: 5px; padding: 6px 7px; }
.transport button { font-size: 10px; }
.controller { width: 116px; margin: 0 auto; display: grid; grid-template-columns: repeat(3,36px); grid-template-rows: repeat(3,28px); gap: 4px; }
.controller button { min-height: 28px; padding: 0; font-size: 16px; touch-action: manipulation; }
.controller .action-button { color: var(--bone); border-radius: 50%; border-color: var(--blood); }
.controller button.pressed { color: var(--black); background: var(--bone); }
.play-hint { margin: 6px 8px 8px; color: var(--bone-dim); text-align: center; font: 8px/1.4 "Studio Mono"; }

.toast { position: fixed; z-index: 50; left: 50%; bottom: 15px; max-width: min(520px,calc(100vw - 30px)); padding: 8px 12px; color: var(--black); background: var(--bone); border: 2px solid var(--black); box-shadow: 4px 4px 0 #000; opacity: 0; transform: translate(-50%,12px); pointer-events: none; transition: .16s; font: 11px "Studio Mono"; }
.toast.visible { opacity: 1; transform: translate(-50%,0); }
.toast.error { color: var(--bone); background: var(--blood); }

@media (max-width: 1120px) {
  .studio-shell { grid-template-columns: 190px minmax(390px,1fr) 300px; }
  .hardware-budget { min-width: 135px; grid-template-columns: 1fr auto; }
  .hardware-budget #budgetLabel { display: none; }
  .budget-track { grid-column: 1; }
  .menu-bar { gap: 8px; }
  .menu-bar nav button { padding-inline: 7px; }
}
@media (max-height: 760px) {
  .hardware-window { display: none; }
  .scene-list { max-height: 28vh; }
  .controller { width: 104px; grid-template-columns: repeat(3,32px); grid-template-rows: repeat(3,25px); }
  .controller button { min-height: 25px; font-size: 14px; }
  .preview-stage { padding: 5px; }
  .preview-bezel { width: min(220px,100%); }
  .inspector fieldset { padding: 5px; }
}
@media (max-width: 860px) {
  body { overflow: auto; }
  .menu-bar { position: sticky; top: 0; }
  .hardware-budget { display: none; }
  .studio-shell { height: auto; min-height: calc(100vh - 42px); grid-template-columns: 180px minmax(500px,1fr); overflow: visible; }
  .workbench-column { grid-column: 1/-1; display: grid; grid-template-columns: 1fr 320px; grid-template-rows: auto; gap: 8px; overflow: visible; }
  .graph-column { height: 680px; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
