/* ==========================================================================
   Editor chrome — a quiet ink-blue workbench with a brass accent, so the game
   UI on the canvas is the loudest thing on screen.
   ========================================================================== */
:root {
  --ink: #141925;
  --ink-2: #1b2130;
  --ink-3: #242c3e;
  --ink-4: #2e374d;
  --line: #333c53;
  --text: #dfe3ee;
  --muted: #8b94ab;
  --brass: #d7a94f;
  --brass-deep: #a77d2c;
  --sel: #6fb6ff;
  --warn: #e46a5b;
  --radius: 6px;
  --font: 'Barlow Semi Condensed', system-ui, sans-serif;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--ink); color: var(--text); font: 15px/1.35 var(--font); overflow: hidden; display: flex; flex-direction: column; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--brass); outline-offset: 1px; }

/* ───────── Top bar ───────── */
.topbar { display: flex; align-items: center; gap: 14px; height: 50px; padding: 0 12px; background: var(--ink-2); border-bottom: 1px solid var(--line); flex: none; }
.brand { display: flex; align-items: center; gap: 9px; font-weight: 600; font-size: 17px; white-space: nowrap; }
.brand-mark { width: 22px; height: 22px; border: 2px solid var(--brass); border-radius: 4px; position: relative; }
.brand-mark::before { content: ''; position: absolute; left: 3px; right: 3px; top: 3px; height: 5px; background: var(--brass); border-radius: 1px; }
.brand-mark::after { content: ''; position: absolute; left: 3px; width: 8px; bottom: 3px; height: 5px; border: 1.5px solid var(--brass); border-radius: 1px; }

.screens { display: flex; align-items: center; gap: 2px; flex: 1; min-width: 0; overflow-x: auto; scrollbar-width: none; }
.scr-tab {
  display: flex; align-items: center; gap: 6px; height: 32px; padding: 0 12px; border-radius: var(--radius); border: 1px solid transparent;
  background: none; color: var(--muted); cursor: pointer; white-space: nowrap;
}
.scr-tab:hover { color: var(--text); background: var(--ink-3); }
.scr-tab.is-on { color: var(--text); background: var(--ink-3); border-color: var(--line); }
.scr-tab .start-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--brass); }
.scr-add { width: 32px; padding: 0; justify-content: center; font-size: 18px; }

.tb { display: flex; align-items: center; gap: 6px; flex: none; }
.tb-sep { width: 1px; height: 22px; background: var(--line); margin: 0 4px; }
.tb-btn { height: 32px; min-width: 32px; padding: 0 8px; border-radius: var(--radius); border: 1px solid var(--line); background: var(--ink-3); cursor: pointer; font-size: 16px; }
.tb-btn:hover:not(:disabled) { background: var(--ink-4); }
.tb-btn:disabled { opacity: .4; cursor: default; }
.tb-wide { font-size: 15px; padding: 0 12px; }
.tb-check { display: flex; align-items: center; gap: 5px; color: var(--muted); cursor: pointer; padding: 0 4px; }
.tb-check input { accent-color: var(--brass); }
.tb-select { height: 32px; border-radius: var(--radius); border: 1px solid var(--line); background: var(--ink-3); padding: 0 6px; }

.play-btn {
  display: flex; align-items: center; gap: 8px; height: 34px; padding: 0 16px 0 12px; margin-left: 4px; cursor: pointer;
  background: var(--brass); color: #20180a; border: 0; border-radius: var(--radius); font-weight: 600; font-size: 16px;
}
.play-btn:hover { background: #e4b961; }
.play-ico { width: 0; height: 0; border-left: 11px solid currentColor; border-top: 7px solid transparent; border-bottom: 7px solid transparent; }
.is-playing .play-btn { background: var(--warn); color: #fff; }
.is-playing .play-ico { width: 11px; height: 11px; border: 0; background: currentColor; border-radius: 2px; }

.menu { position: relative; }
.menu-pop { position: absolute; right: 0; top: calc(100% + 6px); z-index: 50; min-width: 210px; padding: 6px; background: var(--ink-3); border: 1px solid var(--line); border-radius: 8px; box-shadow: 0 14px 40px rgba(0,0,0,.5); }
.menu-pop button { display: block; width: 100%; text-align: left; padding: 7px 10px; border: 0; background: none; border-radius: 4px; cursor: pointer; }
.menu-pop button:hover { background: var(--ink-4); }
.menu-pop hr { border: 0; border-top: 1px solid var(--line); margin: 5px 2px; }

/* ───────── Workspace ───────── */
.workspace { flex: 1; min-height: 0; display: grid; grid-template-columns: 252px minmax(0, 1fr) 312px; }
.side { background: var(--ink-2); display: flex; flex-direction: column; min-height: 0; }
.side.left { border-right: 1px solid var(--line); }
.side.right { border-left: 1px solid var(--line); }
.side-tabs { display: flex; gap: 2px; padding: 8px 8px 0; border-bottom: 1px solid var(--line); flex: none; }
.side-tab { flex: 1; padding: 7px 4px 8px; border: 0; background: none; color: var(--muted); cursor: pointer; border-bottom: 2px solid transparent; }
.side-tab:hover { color: var(--text); }
.side-tab.is-on { color: var(--text); border-bottom-color: var(--brass); }
.side-body { flex: 1; overflow-y: auto; padding: 12px; scrollbar-width: thin; scrollbar-color: var(--ink-4) transparent; }
.is-playing .side.left .side-body { opacity: .35; pointer-events: none; }

/* Palette */
.pal-group + .pal-group { margin-top: 14px; }
.pal-head { color: var(--muted); font-size: 13px; margin: 0 0 6px 2px; }
.pal-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 5px; }
.pal-item {
  display: flex; align-items: center; gap: 7px; padding: 7px 8px; min-width: 0; text-align: left;
  background: var(--ink-3); border: 1px solid transparent; border-radius: var(--radius); cursor: grab; font-size: 14px;
}
.pal-item:hover { border-color: var(--line); background: var(--ink-4); }
.pal-item:active { cursor: grabbing; }
.pal-glyph { width: 20px; flex: none; text-align: center; color: var(--brass); font-size: 15px; }
.pal-item span:last-child { line-height: 1.15; overflow-wrap: anywhere; }
.pal-note { color: var(--muted); font-size: 13px; margin: 0 2px 12px; }

/* Layers */
.layer { display: flex; align-items: center; gap: 6px; height: 30px; padding-right: 4px; border-radius: 4px; cursor: pointer; color: var(--text); }
.layer:hover { background: var(--ink-3); }
.layer.is-sel { background: color-mix(in srgb, var(--sel) 22%, var(--ink-3)); }
.layer-glyph { width: 18px; text-align: center; color: var(--brass); flex: none; font-size: 13px; }
.layer-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.layer-flag { color: var(--muted); font-size: 12px; }
.layer-eye { width: 26px; height: 24px; border: 0; background: none; color: var(--muted); cursor: pointer; border-radius: 4px; font-size: 13px; }
.layer-eye:hover { background: var(--ink-4); color: var(--text); }
.layer.is-off .layer-name { opacity: .45; text-decoration: line-through; }
.empty { color: var(--muted); padding: 10px 4px; }

/* ───────── Stage ───────── */
.stage { position: relative; min-width: 0; min-height: 0; display: flex; flex-direction: column; background: #10141e; }
.stage-scroll {
  flex: 1; min-height: 0; overflow: auto; display: grid; place-items: center; padding: 28px;
  background-color: #10141e;
  background-image:
    linear-gradient(rgba(111,182,255,.05) 1px, transparent 1px), linear-gradient(90deg, rgba(111,182,255,.05) 1px, transparent 1px),
    linear-gradient(rgba(111,182,255,.025) 1px, transparent 1px), linear-gradient(90deg, rgba(111,182,255,.025) 1px, transparent 1px);
  background-size: 120px 120px, 120px 120px, 24px 24px, 24px 24px;
}
.canvas-wrap { position: relative; flex: none; box-shadow: 0 0 0 1px #000, 0 20px 60px rgba(0,0,0,.6); }
.canvas-wrap.is-drop { box-shadow: 0 0 0 2px var(--brass), 0 20px 60px rgba(0,0,0,.6); }
#canvas:focus { outline: none; }
.overlay { position: absolute; inset: 0; pointer-events: none; z-index: 10; }
.is-playing .overlay { display: none; }

.sel-box { position: absolute; border: 1.5px solid var(--sel); pointer-events: none; }
.sel-tag { position: absolute; left: -1.5px; bottom: 100%; margin-bottom: 3px; padding: 1px 6px; font-size: 12px; background: var(--sel); color: #06121f; border-radius: 3px; white-space: nowrap; }
.sel-box.is-below .sel-tag { bottom: auto; top: 100%; margin: 3px 0 0; }
.hdl { position: absolute; width: 10px; height: 10px; margin: -5px; background: #fff; border: 1.5px solid var(--sel); border-radius: 2px; pointer-events: auto; }
.hdl[data-h="nw"] { left: 0; top: 0; cursor: nwse-resize; } .hdl[data-h="ne"] { left: 100%; top: 0; cursor: nesw-resize; }
.hdl[data-h="sw"] { left: 0; top: 100%; cursor: nesw-resize; } .hdl[data-h="se"] { left: 100%; top: 100%; cursor: nwse-resize; }
.hdl[data-h="n"] { left: 50%; top: 0; cursor: ns-resize; } .hdl[data-h="s"] { left: 50%; top: 100%; cursor: ns-resize; }
.hdl[data-h="w"] { left: 0; top: 50%; cursor: ew-resize; } .hdl[data-h="e"] { left: 100%; top: 50%; cursor: ew-resize; }
.hover-box { position: absolute; border: 1px dashed color-mix(in srgb, var(--sel) 70%, transparent); pointer-events: none; }
.drop-box { position: absolute; border: 2px solid var(--brass); background: color-mix(in srgb, var(--brass) 10%, transparent); pointer-events: none; }
.guide { position: absolute; background: #ff5fa8; pointer-events: none; }
.guide.v { width: 1px; top: 0; bottom: 0; } .guide.h { height: 1px; left: 0; right: 0; }

/* Editing affordances on the canvas */
.mode-edit .gx { cursor: move; }
.mode-edit .gx *, .mode-edit .gx *::before { pointer-events: none; }
.mode-edit .gx .gx, .mode-edit .gx .ui-tab { pointer-events: auto; }
.mode-edit .gx .ui-tab { cursor: pointer; }
.mode-edit .gx.is-cond-off > .gx-inner { opacity: .35; }
.mode-edit .gx.is-start-hidden { outline: 1px dashed rgba(255,255,255,.35); outline-offset: 2px; }
.mode-edit .gx.is-start-hidden::after, .mode-edit .gx.is-conditional::after {
  position: absolute; right: 0; top: 0; transform: translateY(-100%); padding: 1px 6px; font: 500 13px var(--font); color: #fff;
  background: rgba(20,25,37,.85); border-radius: 3px 3px 0 0; pointer-events: none; white-space: nowrap; z-index: 2;
}
.mode-edit .gx.is-start-hidden::after { content: 'Hidden at start'; }
.mode-edit .gx.is-conditional::after { content: 'Conditional'; }
.mode-edit .gx.is-start-hidden.is-conditional::after { content: 'Hidden at start, conditional'; }

.statusbar { flex: none; display: flex; gap: 18px; align-items: center; height: 28px; padding: 0 12px; color: var(--muted); font-size: 13px; border-top: 1px solid var(--line); background: var(--ink-2); white-space: nowrap; overflow: hidden; }
.statusbar b { color: var(--text); font-weight: 500; }
.is-playing .statusbar { color: var(--brass); }

/* ───────── Inspector ───────── */
.insp-head { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }
.insp-glyph { width: 30px; height: 30px; display: grid; place-items: center; border-radius: var(--radius); background: var(--ink-3); color: var(--brass); flex: none; }
.insp-name { flex: 1; min-width: 0; font-size: 17px; font-weight: 600; background: transparent; border: 1px solid transparent; border-radius: 4px; padding: 3px 6px; }
.insp-name:hover { border-color: var(--line); }
.insp-name:focus { border-color: var(--brass); outline: none; background: var(--ink-3); }
.insp-type { color: var(--muted); font-size: 13px; }

.sec { border-top: 1px solid var(--line); padding: 12px 0 4px; }
.sec:first-of-type { border-top: 0; padding-top: 2px; }
.sec-title { display: flex; align-items: center; justify-content: space-between; margin: 0 0 10px; font-size: 14px; font-weight: 600; color: var(--muted); }
.sec-title button { font-weight: 400; }

.fld { display: flex; flex-direction: column; gap: 4px; margin-bottom: 10px; }
.fld > span { color: var(--muted); font-size: 13px; }
.fld-hint { color: var(--muted); font-size: 12px; opacity: .8; }
.fld-row { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; margin-bottom: 10px; }
.fld-row .fld { margin: 0; }
.fld-pair { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.inp {
  width: 100%; min-width: 0; height: 30px; padding: 0 8px; border-radius: 4px; border: 1px solid var(--line); background: var(--ink-3);
}
textarea.inp { height: auto; min-height: 76px; padding: 6px 8px; resize: vertical; line-height: 1.4; }
.inp:focus { border-color: var(--brass); outline: none; }
.inp[type=color] { padding: 2px; cursor: pointer; }
.inp[type=number] { padding-right: 2px; }
select.inp { padding: 0 4px; }
.chk { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; cursor: pointer; }
.chk input { accent-color: var(--brass); width: 16px; height: 16px; }
.color-row { display: flex; gap: 6px; align-items: center; }
.color-row .inp[type=color] { width: 44px; flex: none; }
.color-row .inp[type=text] { flex: 1; font-variant-numeric: tabular-nums; }

.btn { height: 30px; padding: 0 10px; border-radius: 4px; border: 1px solid var(--line); background: var(--ink-3); cursor: pointer; white-space: nowrap; }
.btn:hover { background: var(--ink-4); }
.btn-sm { height: 24px; padding: 0 8px; font-size: 13px; }
.btn-danger { color: #ffb3a8; }
.btn-danger:hover { background: color-mix(in srgb, var(--warn) 30%, var(--ink-3)); color: #fff; }
.btn-brass { height: 32px; padding: 0 16px; border-radius: 4px; border: 0; background: var(--brass); color: #20180a; font-weight: 600; cursor: pointer; }
.btn-row { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.icon-btn { width: 26px; height: 26px; border: 0; border-radius: 4px; background: none; color: var(--muted); cursor: pointer; flex: none; }
.icon-btn:hover { background: var(--ink-4); color: var(--text); }

.action { padding: 8px; margin-bottom: 8px; background: var(--ink-3); border: 1px solid var(--line); border-radius: var(--radius); }
.action-top { display: flex; gap: 6px; align-items: center; margin-bottom: 6px; }
.action-top select { flex: 1; }
.action .fld { margin-bottom: 6px; }
.action .inp { background: var(--ink-2); }
.action-opt { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 13px; }
.action-opt .inp { width: 62px; height: 26px; }

.cond { display: grid; grid-template-columns: minmax(0, 1.3fr) 54px minmax(0, 1fr); gap: 6px; }

.var-row { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr) minmax(0, .8fr) minmax(0, 1fr) 22px; gap: 4px; align-items: center; margin-bottom: 5px; }
.var-row .inp { height: 28px; padding: 0 5px; }
.var-head { color: var(--muted); font-size: 12px; margin-bottom: 4px; }
.var-live { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.4fr) 60px; gap: 8px; align-items: center; margin-bottom: 8px; }
.var-live input[type=range] { accent-color: var(--brass); width: 100%; }
.var-live .inp { height: 28px; }
.var-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.theme-colors { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 10px; }
.tc { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); min-width: 0; }
.tc input { width: 30px; height: 24px; padding: 1px; border-radius: 4px; border: 1px solid var(--line); background: var(--ink-3); flex: none; cursor: pointer; }
.tc span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tc.is-custom span { color: var(--brass); }

.play-info { padding: 10px 12px; margin-bottom: 14px; border-radius: var(--radius); background: color-mix(in srgb, var(--brass) 12%, var(--ink-3)); border: 1px solid color-mix(in srgb, var(--brass) 40%, transparent); }
.play-info p { margin: 0 0 8px; }

/* Dialog */
.dlg { max-width: 760px; width: calc(100% - 32px); background: var(--ink-2); color: var(--text); border: 1px solid var(--line); border-radius: 10px; padding: 22px 26px; }
.dlg::backdrop { background: rgba(5,7,12,.65); }
.dlg h2 { margin: 0 0 14px; font-size: 22px; }
.dlg h3 { margin: 0 0 8px; font-size: 16px; color: var(--brass); }
.help-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 26px; margin-bottom: 18px; }
.help-grid dl { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; margin: 0; }
.help-grid dt { color: var(--text); font-weight: 600; white-space: nowrap; }
.help-grid dd { margin: 0; color: var(--muted); }
.help-grid p { margin: 0 0 9px; color: var(--muted); }
.help-grid b { color: var(--text); font-weight: 600; }
.help-grid code { background: var(--ink-3); padding: 1px 5px; border-radius: 3px; color: var(--text); }

/* Narrow screens: stack the side panels under the stage */
@media (max-width: 1000px) {
  body { overflow: auto; }
  .topbar { flex-wrap: wrap; height: auto; padding: 8px 12px; }
  .screens { order: 3; flex-basis: 100%; }
  .workspace { flex: none; grid-template-columns: 1fr; grid-template-rows: 56vh auto auto; }
  .stage { order: -1; }
  .side { border: 0; border-top: 1px solid var(--line); max-height: 60vh; }
  .help-grid { grid-template-columns: 1fr; }
}
@media (max-width: 560px) { .brand-name, .tb-check { display: none; } }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
