:root {
  --bg: #0e1014;
  --panel: #171b22;
  --panel-2: #1f242e;
  --line: #2d3440;
  --text: #eef2f8;
  --muted: #8b97ab;
  --accent: #5aa7ff;
  --accent-2: #8b6cff;
  --ok: #3dcc8a;
  --warn: #f0b429;
  --danger: #ef6b63;
  --tool: #252b36;
  --tool-on: #3a76d1;
  --stage: #0a0c10;
  --shadow: 0 12px 32px rgba(0,0,0,.4);
  --xai: #d4af37;
  --chrome: 44px;
  --rail: 84px;
  --inspect: min(340px, 34vw);
  font-synthesis: none;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: "Segoe UI", Inter, system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
}
.app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  min-height: 0;
  min-width: 0;
}
.topbar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: var(--chrome);
  padding: 6px 10px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 8px; flex: 0 0 auto; }
.logo {
  width: 32px; height: 32px; border-radius: 8px;
  background: #16181d; display: grid; place-items: center; overflow: hidden;
  padding: 0;
}
.logo img { width: 32px; height: 32px; display: block; }
.brand h1 { font-size: 14px; margin: 0; letter-spacing: .2px; line-height: 1.1; }
.brand small { display: block; color: var(--muted); font-size: 10px; }
.menu { display: flex; gap: 4px; flex-wrap: wrap; align-items: center; }
.menu button, .icon-btn, .tool, .chip, .menubar button {
  background: var(--tool); color: var(--text); border: 1px solid transparent;
  border-radius: 3px; cursor: pointer; font: inherit;
}
.menu button, .menubar button {
  padding: 4px 8px; font-size: 12px; color: var(--muted);
  white-space: nowrap;
  background: transparent;
}
.menu button:hover, .icon-btn:hover, .tool:hover, .menubar button:hover { background: #384155; color: #fff; }
.icon-btn { width: 30px; height: 28px; display: grid; place-items: center; flex: 0 0 auto; }
.sep { width: 1px; height: 18px; background: var(--line); margin: 0 2px; flex: 0 0 auto; }
.grow { flex: 1 1 8px; min-width: 8px; }
.zoom-cluster { display: flex; align-items: center; gap: 4px; flex: 0 0 auto; }
.zoom-read { font-size: 12px; color: var(--muted); min-width: 42px; text-align: center; }
.menubar {
  flex: 0 0 auto;
  display: flex; align-items: center; gap: 2px;
  padding: 2px 8px;
  background: #12161c;
  border-bottom: 1px solid var(--line);
  position: relative; z-index: 20;
  flex-wrap: wrap;
}
.menubar .drop { position: relative; }
.menubar .admin-link {
  display: inline-flex; align-items: center; height: 28px;
  padding: 0 10px; border-radius: 6px; color: #e9d5ff; text-decoration: none;
}
.menubar .admin-link:hover { background: #384155; }
.menubar .drop > button { background: transparent; border-radius: 6px; }
.menubar .fly {
  display: none; position: absolute; top: calc(100% + 2px); left: 0; min-width: 220px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
  padding: 6px; box-shadow: var(--shadow); z-index: 200;
}
.menubar .drop.open .fly,
.menubar .drop:hover .fly { display: block; }
.zoom-line {
  display: flex; align-items: center; gap: 8px;
  padding: 2px 4px;
}
.zoom-line button { flex: 0 0 auto; width: auto; }
.zoom-line input[type="range"] { flex: 1 1 auto; min-width: 90px; accent-color: #6b3fd1; }
.fly-child {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 10px; margin: 2px 0;
  border-radius: 6px; color: var(--text); font-size: 13px;
}
.fly-child span { flex: 0 0 auto; color: var(--muted); }
.fly-child b { flex: 0 0 40px; font-weight: 600; font-size: 11px; color: var(--muted); text-align: right; }
.fly-child input[type="range"] { flex: 1 1 auto; min-width: 80px; accent-color: #6b3fd1; }
.menubar .fly button {
  display: flex; width: 100%; text-align: left; background: transparent;
  border-radius: 6px; padding: 7px 10px; color: var(--text);
  justify-content: space-between; gap: 12px;
}
.menubar .fly button:hover { background: #384155; }
.menubar .fly .k { color: var(--muted); font-size: 11px; float: none; }
.menubar .fly hr { border: 0; border-top: 1px solid var(--line); margin: 4px 0; }
.menubar .has-sub { position: relative; }
.menubar .fly-sub {
  display: none; position: absolute; left: calc(100% + 4px); top: 0;
  min-width: 160px; background: var(--panel); border: 1px solid var(--line);
  border-radius: 10px; padding: 6px; box-shadow: var(--shadow); z-index: 60;
}
.menubar .has-sub.open-sub .fly-sub { display: block; }
body.mode-video .mode-only-image { display: none !important; }
body.mode-image .mode-only-image,
body.mode-sprites .mode-only-image { display: block; }
.workspace {
  flex: 1 1 auto;
  min-height: 0;
  min-width: 0;
  display: grid;
  grid-template-columns: var(--rail) minmax(0, 1fr) var(--inspect);
  position: relative;
}
.tools {
  background: #3a3a3a;
  border-right: 1px solid #1c1c1c;
  display: flex; flex-direction: column;
  align-items: stretch;
  padding: 2px 2px 4px;
  overflow: hidden;
  min-width: 0;
  color: #e6e6e6;
}
.tools .g {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0;
  padding: 2px 0;
  border-bottom: 1px solid #2a2a2a;
}
.tools .g:last-child { border-bottom: 0; }
.tool {
  width: auto;
  height: 26px;
  display: grid;
  place-items: center;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 2px;
  color: #ececec;
  position: relative;
}
.tool:hover { background: #4a4a4a; border-color: #5a5a5a; }
.tool svg { width: 15px; height: 15px; fill: none; stroke: currentColor; stroke-width: 1.6; overflow: visible; }
.tool.on {
  background: #2d2d2d;
  border-color: #6a6a6a;
  color: #fff;
  box-shadow: inset 0 0 0 1px #1a1a1a;
}
body.mode-video .tab-image,
body.mode-video .tab-sprite,
body.mode-sprites .tab-image,
body.mode-sprites .tab-video,
body.mode-image .tab-sprite,
body.mode-image .tab-video { display: none !important; }
body.mode-sprites .tab-sprite,
body.mode-video .tab-video { display: inline-flex !important; }
.mode-only { display: none !important; }
body.mode-video .mode-only.mode-video { display: flex !important; }
.lock-list label { display: flex; gap: 8px; align-items: flex-start; font-size: 12px; margin: 6px 0; }
.lock-list input { margin-top: 2px; }
.stage-video {
  display: none;
  position: absolute; inset: 0; place-items: center;
  background: #0a0c10; z-index: 50; padding: 24px;
}
body.mode-video .stage-video { display: grid; }
body.mode-image .stage-video,
body.mode-sprites .stage-video { display: none !important; }
.stage-video video { max-width: 100%; max-height: 80%; background: #000; }
body.mode-video .stage-align,
body.mode-video .ruler-h,
body.mode-video .ruler-v,
body.mode-video .ruler-corner { visibility: hidden; }
body.mode-image .stage-align,
body.mode-sprites .stage-align { visibility: visible; }
.stage-wrap {
  background:
    radial-gradient(1200px 500px at 50% 0%, #151a22 0%, var(--stage) 55%),
    repeating-conic-gradient(#222831 0% 25%, #161a20 0% 50%) 0 0 / 16px 16px;
  position: relative;
  overflow: auto;
  min-width: 0;
  min-height: 0;
}
.stage-wrap::-webkit-scrollbar { width: 10px; height: 10px; }
.stage-wrap::-webkit-scrollbar-thumb { background: #3a4250; border-radius: 8px; }
.stage-align {
  position: relative;
  min-width: 100%;
  min-height: 100%;
  display: grid;
  place-items: center;
  pointer-events: none;
}
.stage-board {
  position: relative;
  display: block;
  line-height: 0;
  pointer-events: auto;
  width: fit-content;
  height: fit-content;
  overflow: hidden;
}
#view {
  position: relative;
  display: block;
  margin: 0;
  max-width: none !important;
  max-height: none !important;
  background: repeating-conic-gradient(#cfcfcf 0% 25%, #fff 0% 50%) 50% / 16px 16px;
}
#overlay {
  position: absolute;
  left: 0;
  top: 0;
  display: block;
  margin: 0;
  max-width: none !important;
  max-height: none !important;
  pointer-events: none !important;
}
.drop-hint {
  position: absolute; inset: 20px; border: 2px dashed #3a4558; border-radius: 16px;
  display: grid; place-items: center; color: var(--muted); text-align: center; pointer-events: none;
  padding: 16px;
}
.drop-hint.hide { display: none; }
.drop-hint b { color: var(--text); font-size: 17px; display: block; margin-bottom: 6px; }
.panels {
  background: var(--panel);
  border-left: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
}
.ptabs {
  display: flex; gap: 0; border-bottom: 1px solid var(--line);
  overflow-x: auto; flex: 0 0 auto;
}
.ptabs button {
  flex: 1 0 auto; background: transparent; border: 0; color: var(--muted);
  font: inherit; font-size: 11px; letter-spacing: .04em; text-transform: uppercase;
  padding: 9px 8px; cursor: pointer; white-space: nowrap;
}
.ptabs button.on { color: var(--text); box-shadow: inset 0 -2px 0 var(--accent); }
.pscroll { overflow: auto; padding: 10px; flex: 1 1 auto; min-height: 0; }
.pane { display: none; }
.pane.on { display: block; }
.card {
  background: var(--panel-2); border: 1px solid var(--line);
  border-radius: 12px; padding: 12px; margin-bottom: 10px;
}
.card h3 {
  margin: 0 0 10px; font-size: 11px; letter-spacing: .08em;
  text-transform: uppercase; color: var(--muted); font-weight: 700;
}
label.row, .row {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  font-size: 12px; margin: 8px 0;
}
input[type="range"] { width: 100%; accent-color: var(--accent); }
input[type="number"], input[type="text"], input[type="email"], input[type="tel"], input[type="password"], textarea, select {
  background: #12161c; color: var(--text); border: 1px solid var(--line);
  border-radius: 7px; padding: 6px 8px; font: inherit; width: 100%;
}
textarea { min-height: 72px; resize: vertical; }
input[type="color"] {
  width: 36px; height: 28px; border: 0; background: none; padding: 0; cursor: pointer;
}
.swatches { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.fgbg { position: relative; width: 54px; height: 36px; flex: 0 0 auto; }
.fgbg .fg, .fgbg .bg {
  position: absolute; width: 22px; height: 22px; border-radius: 4px; border: 2px solid #fff;
}
.fgbg .fg { left: 0; top: 0; z-index: 1; }
.fgbg .bg { right: 0; bottom: 0; }
.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-top: 8px; }
.actions.three { grid-template-columns: 1fr 1fr 1fr; }
.actions button, .wide {
  background: #2a303a; border: 1px solid #3a4250; color: var(--text); border-radius: 3px;
  padding: 7px 8px; font-size: 12px; cursor: pointer;
}
.actions button:hover, .wide:hover { background: #3c4558; }
.wide { width: 100%; margin-top: 6px; }
.btn-accent { background: var(--accent) !important; color: #081018 !important; font-weight: 700; }
.btn-ok { background: var(--ok) !important; color: #062014 !important; font-weight: 700; }
.btn-danger { background: #6b3030 !important; }
.btn-xai { background: var(--xai) !important; color: #1a1404 !important; font-weight: 700; }
.panels .pscroll button:not(.eye):not(.layer-check),
.panels .actions button,
.panels .wide,
.panels .btn-accent,
.panels .btn-ok,
.panels .btn-xai {
  background: #6b3fd1 !important;
  border: 1px solid #8b6cff !important;
  color: #fff !important;
  font-weight: 650;
}
.panels .pscroll button:hover,
.panels .actions button:hover,
.panels .wide:hover {
  background: #5b21b6 !important;
}
.hint { font-size: 11px; color: var(--muted); line-height: 1.4; margin-top: 6px; }
.layer-view {
  position: relative;
  background: repeating-conic-gradient(#2a2f38 0% 25%, #1c2027 0% 50%) 50% / 12px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  height: 160px;
  display: grid;
  place-items: center;
  margin-bottom: 8px;
}
.layer-view canvas {
  max-width: 100%;
  max-height: 160px;
  display: block;
}
.layer-nav { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 6px; margin-bottom: 8px; }
.layer-list { display: flex; flex-direction: column; gap: 4px; }
.layer-row {
  display: grid; grid-template-columns: 16px 18px 40px minmax(0,1fr); gap: 4px; align-items: center;
  background: #1a1f28; border: 1px solid var(--line); border-radius: 8px; padding: 3px 5px;
  cursor: pointer; font-size: 12px;
}
.layer-row.on { border-color: var(--accent); background: #243044; }
.layer-row canvas { width: 40px; height: 28px; background: #111; border-radius: 3px; }
.layer-row .lname {
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  min-width: 0; padding: 2px 0 2px 2px;
}
.layer-row .lname-edit {
  width: 100%; min-width: 0; background: #0e1218; color: #fff;
  border: 1px solid var(--accent); border-radius: 3px; padding: 2px 4px;
  font: inherit; font-size: 12px;
}
.layer-row .eye,
.panels .layer-row .eye,
.panels .pscroll .eye {
  background: transparent !important;
  border: 0 !important;
  box-shadow: none !important;
  color: var(--muted) !important;
  cursor: pointer;
  width: auto; height: auto; padding: 0;
}
.layer-row.dragging { opacity: .45; }
.layer-row.drop-target { outline: 1px dashed var(--accent); }
.layer-check { accent-color: var(--accent); }
.ctx-menu {
  display: none; position: fixed; z-index: 500; min-width: 200px;
  background: #2a2140; border: 1px solid #6b4bb8; border-radius: 8px;
  padding: 4px; box-shadow: var(--shadow);
}
.ctx-menu.show { display: block; }
.ctx-menu button {
  display: block; width: 100%; text-align: left; background: transparent;
  border: 0; color: #efe8ff; padding: 8px 10px; font: inherit; font-size: 12px;
  border-radius: 5px; cursor: pointer;
}
.ctx-menu button:hover { background: #5b3d9a; }
.tool { position: relative; }
.tool[data-tip]::after, .ibtn[data-tip]::after { content: none; }
.float-tip {
  position: fixed; display: none; z-index: 900;
  background: #1a1228; color: #f3e8ff; font-size: 11px; line-height: 1.2;
  padding: 6px 9px; border-radius: 8px; white-space: nowrap;
  pointer-events: none;
  border: 1.5px solid #9b6bff;
  box-shadow: 0 8px 18px rgba(80, 30, 140, .4);
}
.float-tip.show { display: block; }
a.lock-btn { text-decoration:none; }
.lock-btn { background: #5b35c7 !important; color: #fff; }
.lock-btn.in { background: #3dcc8a !important; color: #062014; }
.lock-btn svg { stroke: currentColor; fill: none; stroke-width: 1.7; }
.ruler-h, .ruler-v, .ruler-corner {
  position: absolute; z-index: 6; background: #1c222c; color: #8b97ab;
  pointer-events: none;
}
.ruler-corner {
  left: 0; top: 0; width: 22px; height: 22px;
  border-right: 1px solid #323846; border-bottom: 1px solid #323846;
  font-size: 8px; display: grid; place-items: center;
}
.ruler-h { left: 22px; right: 0; top: 0; height: 22px; border-bottom: 1px solid #323846; }
.ruler-v { top: 22px; bottom: 0; left: 0; width: 22px; border-right: 1px solid #323846; }
.ruler-h canvas, .ruler-v canvas { display: block; width: 100%; height: 100%; }
.ruler-hair-h {
  position: absolute; top: 0; bottom: 0; width: 1px; background: #c084fc; pointer-events: none;
}
.ruler-hair-v {
  position: absolute; left: 0; right: 0; height: 1px; background: #c084fc; pointer-events: none;
}
.grid-lines, .slices {
  position: absolute; inset: 0; pointer-events: none; z-index: 4;
}
.grid-lines {
  background-image:
    linear-gradient(to right, #3b82f6 1px, transparent 1px),
    linear-gradient(to bottom, #3b82f6 1px, transparent 1px);
  background-size: 32px 32px;
}
.slices {
  background:
    linear-gradient(to right, transparent calc(33.33% - 1px), rgba(122,196,255,.7) 33.33%, transparent calc(33.33% + 1px)),
    linear-gradient(to right, transparent calc(66.66% - 1px), rgba(122,196,255,.7) 66.66%, transparent calc(66.66% + 1px)),
    linear-gradient(to bottom, transparent calc(33.33% - 1px), rgba(122,196,255,.7) 33.33%, transparent calc(33.33% + 1px)),
    linear-gradient(to bottom, transparent calc(66.66% - 1px), rgba(122,196,255,.7) 66.66%, transparent calc(66.66% + 1px));
}
.icon-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 6px;
}
.ibtn {
  position: relative;
  height: 36px; border-radius: 3px; border: 1px solid #3a4250;
  background: #2a303a; color: var(--text); cursor: pointer; font: inherit; font-size: 11px;
}
.thumbs { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.thumbs img, .thumbs video {
  width: 100%; border-radius: 8px; border: 1px solid var(--line); cursor: pointer; background: #111;
}
.status {
  flex: 0 0 auto;
  background: #10141a; border-top: 1px solid var(--line);
  display: flex; align-items: center; gap: 12px; padding: 0 12px;
  min-height: 26px;
  font-size: 11px; color: var(--muted);
  overflow: hidden;
}
.status span { white-space: nowrap; }
.status b { color: var(--text); font-weight: 600; }
.status .build {
  margin-left: auto;
  font-size: 10px;
  letter-spacing: .02em;
  color: #7d8796;
  font-variant-numeric: tabular-nums;
}
.status .build i { color: #4d5563; font-style: normal; margin: 0 4px; }
.form-box input[type="number"], .form-box input[type="text"], .form-box select, .form-box textarea {
  width: 100%; margin: 4px 0 10px; background: #0e1218; color: var(--text);
  border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; font: inherit;
}
.form-box .actions { display: flex; gap: 8px; margin-top: 8px; }
.anchor {
  display: grid; grid-template-columns: repeat(3, 28px); gap: 4px; margin: 8px 0 12px;
}
.anchor button {
  width: 28px; height: 28px; border-radius: 4px; border: 1px solid #4a5568;
  background: #1c2430; padding: 0; cursor: pointer;
}
.anchor button.on { background: #5b35c7; border-color: #c4b5fd; }
.live-text {
  position: fixed; z-index: 500; min-width: 160px; min-height: 1.4em;
  background: transparent; color: var(--text); border: 1px dashed #5aa7ff;
  font-weight: 700; outline: none; resize: both; padding: 0 2px;
}
.gutter-guide {
  position: absolute; inset: 0; pointer-events: none; z-index: 5;
  box-shadow: inset 0 0 0 0 rgba(0,0,0,0);
}
.toast {
  position: fixed; right: 18px; bottom: 42px; background: #223049; color: #fff;
  padding: 10px 14px; border-radius: 10px; box-shadow: var(--shadow);
  font-size: 13px; opacity: 0; transform: translateY(8px); transition: .25s; z-index: 30;
  max-width: min(420px, 90vw); pointer-events: none;
}
.toast.show { opacity: 1; transform: none; }
.modal {
  position: fixed; inset: 0; background: rgba(0,0,0,.55); display: none;
  place-items: center; z-index: 60; padding: 16px;
}
.modal.show { display: grid; }
.modal .box {
  width: min(560px, 100%); background: var(--panel);
  border: 1px solid var(--line); border-radius: 14px; padding: 18px; box-shadow: var(--shadow);
  max-height: calc(100dvh - 32px); overflow: auto;
}
.modal h2 { margin: 0 0 8px; font-size: 18px; }
.modal p { color: var(--muted); font-size: 13px; line-height: 1.5; }
#login-box .login-field,
#login-box input {
  display: block;
  width: 100%;
  box-sizing: border-box;
  appearance: none;
  -webkit-appearance: none;
  background: #12161c;
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 8px 10px;
  font: inherit;
  height: 38px;
  margin: 0 0 10px;
}
#video-box video { width: 100%; border-radius: 10px; background: #000; margin: 8px 0; }
.app.hide-panels .panels { display: none; }
.app.hide-panels { --inspect: 0px; }
@media (max-width: 1100px) {
  :root { --inspect: min(300px, 38vw); --rail: 80px; }
}
@media (max-width: 860px) {
  :root { --rail: 76px; }
  .app:not(.show-panels) .panels { display: none; }
  .app.show-panels .panels {
    position: absolute; right: 0; top: 0; bottom: 0; width: min(320px, 88vw);
    z-index: 15; display: flex; --inspect: 0px;
    box-shadow: var(--shadow);
  }
  .app.show-panels { --inspect: 0px; }
  .brand small { display: none; }
}
@media (max-width: 640px) {
  .menu .sep { display: none; }
  .status span:nth-child(n+4) { display: none; }
}

.color-align {
  display: grid;
  grid-template-columns: 54px 1fr 1fr;
  gap: 10px;
  align-items: end;
  margin: 6px 0 10px;
}
.sw-lab {
  display: flex; flex-direction: column; gap: 4px;
  font-size: 11px; color: var(--muted); letter-spacing: .04em;
}
.sw-lab input[type="color"] { width: 100%; height: 32px; }
.top-admin {
  color: #ddd6fe; text-decoration: none; font-size: 12px; font-weight: 650;
  padding: 6px 10px; border: 1px solid #6b4bb8; border-radius: 8px;
}
.top-admin[hidden] { display: none !important; }
body:not(.locked) #login-box { display: none !important; }
#login-box { z-index: 500; }
#login-box.show { display: grid !important; }
.about-win {
  width: min(420px, 100%);
  background: #ece9d8;
  color: #111;
  border: 2px solid #0054e3;
  box-shadow: 4px 4px 0 #404040;
  font-family: Tahoma, "Segoe UI", sans-serif;
}
.about-win-bar {
  background: linear-gradient(90deg, #0a246a, #a6caf0);
  color: #fff; font-size: 12px; font-weight: 700; padding: 5px 8px;
}
.about-win-body { display: flex; gap: 14px; padding: 16px; align-items: flex-start; }
.about-win-body img { width: 64px; height: 64px; }
.about-win-body b { display: block; font-size: 16px; }
.about-win-body p { margin: 4px 0 0; font-size: 12px; color: #222; }
.about-win-foot { text-align: right; padding: 8px 12px 12px; background: #ece9d8; }
.about-win-foot button {
  min-width: 74px; padding: 3px 12px; font: 12px Tahoma, sans-serif;
  background: #ece9d8; border: 2px outset #fff; color: #111; cursor: pointer;
}
