:root {
  color-scheme: dark;
  --bg: #070912;
  --panel: #111625;
  --panel-2: #171d2d;
  --line: #28324a;
  --text: #f5f7ff;
  --muted: #9ca8bd;
  --accent: #6d4cff;
  --danger: #ef4444;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  min-height: 100vh;
  background: radial-gradient(circle at 50% 0%, #10152b 0, var(--bg) 42%);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
button, input, select, textarea { font: inherit; }
button, .file-label, .upload-button { cursor: pointer; }
button:disabled { opacity: .45; cursor: not-allowed; }
textarea { resize: vertical; min-height: 96px; }

.topbar {
  min-height: 76px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 14px 22px;
  border-bottom: 1px solid var(--line);
  background: rgba(7, 9, 18, .88);
  backdrop-filter: blur(16px);
  position: sticky;
  top: 0;
  z-index: 20;
}
.topbar h1 { margin: 0; font-size: 21px; }
.topbar p { margin: 4px 0 0; color: var(--muted); font-size: 13px; }
.top-actions { display: flex; flex-wrap: wrap; gap: 8px; }

.layout {
  display: grid;
  grid-template-columns: 300px minmax(540px, 1fr) 320px;
  min-height: calc(100vh - 76px);
}
.panel {
  padding: 18px;
  background: rgba(11, 14, 25, .9);
  overflow: auto;
}
.left-panel { border-right: 1px solid var(--line); }
.right-panel { border-left: 1px solid var(--line); }
.panel section + section { margin-top: 26px; padding-top: 24px; border-top: 1px solid var(--line); }
h2 { margin: 0 0 12px; font-size: 14px; }
.hint { margin: 10px 0 0; color: var(--muted); font-size: 12px; line-height: 1.45; }

button, .file-label, .upload-button {
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 9px 12px;
  color: var(--text);
  background: var(--panel-2);
  transition: border-color .15s ease, transform .15s ease, background .15s ease;
}
button:hover, .file-label:hover, .upload-button:hover { border-color: #53617e; }
button:active, .file-label:active, .upload-button:active { transform: translateY(1px); }
.primary { border-color: #7e64ff; background: linear-gradient(135deg, #6041e7, #3659df); }
.secondary { background: #171d2d; }
.danger-button { border-color: #7f2630; background: #391a21; color: #ffc4ca; }

.row-buttons { display: grid; grid-template-columns: repeat(3, 1fr); gap: 7px; }
.row-buttons button { padding: 9px 0; }
.row-buttons button.active { border-color: #846bff; background: #2a2252; box-shadow: inset 0 0 0 1px #846bff; }

.tool-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.tool {
  min-height: 82px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-size: 12px;
  text-align: center;
}
.tool.active { border-color: #846bff; background: #29214d; box-shadow: inset 0 0 0 1px #846bff; }
.tool-icon { width: 28px; height: 28px; display: grid; place-items: center; }
.slot-demo, .highlight-demo {
  border-top: 3px solid #373737;
  border-left: 3px solid #373737;
  border-right: 3px solid #fff;
  border-bottom: 3px solid #fff;
  background: #8b8b8b;
}
.highlight-demo { background: #4a9ee0; }
.transparent-demo { border: 1px dashed #77829a; background: repeating-linear-gradient(45deg, #22283a, #22283a 4px, #161b29 4px, #161b29 8px); }
.select-demo { font-size: 24px; color: #c9bdff; }
.clear-demo { font-size: 27px; color: #ff8b96; }

.section-heading { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.section-heading h2 { margin: 0; }
.inline-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.upload-button { padding: 7px 10px; font-size: 12px; border-color: #6652df; }
.asset-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 10px; }
.asset-list { margin-top: 12px; display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.asset {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px;
  background: #0b0f1c;
  display: grid;
  gap: 8px;
  position: relative;
}
.asset.selected { border-color: #7c65ff; box-shadow: inset 0 0 0 1px #7c65ff; }
.asset-preview {
  aspect-ratio: 1;
  border-radius: 6px;
  background: linear-gradient(45deg, rgba(255,255,255,.03) 25%, transparent 25%, transparent 50%, rgba(255,255,255,.03) 50%, rgba(255,255,255,.03) 75%, transparent 75%);
  background-size: 12px 12px;
  display: grid;
  place-items: center;
}
.asset img { width: 100%; height: 100%; max-width: 100%; max-height: 100%; object-fit: contain; image-rendering: pixelated; }
.asset-name { font-size: 11px; color: var(--muted); word-break: break-word; min-height: 28px; }
.asset-actions-mini { display: grid; grid-template-columns: 1fr 1fr auto; gap: 6px; }
.asset-actions-mini button { padding: 7px 6px; font-size: 11px; }
.asset .remove-asset {
  padding: 7px 8px;
  background: #391a21;
  color: #ffc4ca;
  border-color: #7f2630;
}

.workspace {
  min-width: 0;
  display: flex;
  flex-direction: column;
  background-image: radial-gradient(#232a40 1px, transparent 1px);
  background-size: 18px 18px;
}
.workspace-toolbar {
  min-height: 54px;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 8px 16px;
  border-bottom: 1px solid var(--line);
  background: rgba(9, 12, 22, .94);
}
.workspace-toolbar label { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 13px; }
.workspace-toolbar select, select, input[type="color"], textarea, input[type="text"] {
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 7px 9px;
  background: #151b2b;
  color: var(--text);
}
.size-label { color: var(--muted); font-size: 12px; margin-right: auto; }

.snap-toggle {
  display: inline-flex !important;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
}
.snap-toggle input {
  width: 16px;
  height: 16px;
  accent-color: #7359f5;
}
.two-cols {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.canvas-scroll {
  flex: 1;
  overflow: auto;
  display: grid;
  place-items: center;
  padding: 40px;
}
.gui-frame {
  --zoom: 4;
  padding: calc(7px * var(--zoom));
  background: #c6c6c6;
  border-top: calc(2px * var(--zoom)) solid #fff;
  border-left: calc(2px * var(--zoom)) solid #fff;
  border-right: calc(2px * var(--zoom)) solid #555;
  border-bottom: calc(2px * var(--zoom)) solid #555;
  box-shadow: 0 18px 55px rgba(0,0,0,.45);
  image-rendering: pixelated;
  user-select: none;
}
.gui-stage {
  position: relative;
  width: calc(162px * var(--zoom));
  height: calc(var(--stage-height) * var(--zoom));
  background: #c6c6c6;
}
.gui-grid {
  position: absolute;
  inset: 0;
  display: grid;
  background: #c6c6c6;
  grid-template-columns: repeat(9, calc(18px * var(--zoom)));
  grid-auto-rows: calc(18px * var(--zoom));
}
.gui-slot {
  position: relative;
  width: calc(18px * var(--zoom));
  height: calc(18px * var(--zoom));
  border-top: calc(1px * var(--zoom)) solid #373737;
  border-left: calc(1px * var(--zoom)) solid #373737;
  border-right: calc(1px * var(--zoom)) solid #fff;
  border-bottom: calc(1px * var(--zoom)) solid #fff;
  background: #8b8b8b;
}
.gui-slot.highlight { background: var(--slot-color, #4a9ee0); }
.gui-slot.transparent {
  border: 0;
  background: transparent;
}
.gui-slot.selected::after {
  content: "";
  position: absolute;
  inset: calc(-1px * var(--zoom));
  border: calc(1px * var(--zoom)) solid #9b84ff;
  box-shadow: 0 0 0 calc(1px * var(--zoom)) rgba(31, 20, 81, .9);
  pointer-events: none;
  z-index: 3;
}
.gui-slot.drag-over::after {
  content: "";
  position: absolute;
  inset: 0;
  background: rgba(109, 76, 255, .32);
  outline: calc(1px * var(--zoom)) solid #b3a5ff;
  pointer-events: none;
  z-index: 4;
}
.gui-slot img {
  position: absolute;
  left: 50%;
  top: 50%;
  width: calc(16px * var(--zoom));
  height: calc(16px * var(--zoom));
  object-fit: contain;
  image-rendering: pixelated;
  pointer-events: none;
  transform-origin: center;
  z-index: 2;
}

.overlay-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
}
.overlay-element {
  position: absolute;
  pointer-events: auto;
  border: 1px dashed transparent;
}
.overlay-element.selected {
  border-color: #9b84ff;
  box-shadow: 0 0 0 1px rgba(31, 20, 81, .9), 0 0 0 3px rgba(155,132,255,.12);
}
.overlay-element .resize-handle {
  position: absolute;
  width: 12px;
  height: 12px;
  right: -6px;
  bottom: -6px;
  border-radius: 3px;
  background: #9b84ff;
  border: 1px solid #f1ecff;
  box-shadow: 0 2px 12px rgba(0,0,0,.35);
  cursor: nwse-resize;
}
.overlay-element.text-element {
  padding: 2px 4px;
  display: flex;
  align-items: center;
  overflow: hidden;
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.2;
  text-shadow: 1px 1px 0 rgba(0,0,0,.4);
  background-repeat: no-repeat;
  background-position: center;
  background-size: cover;
}
.overlay-element.image-element {
  display: grid;
  place-items: center;
  background: transparent;
}
.overlay-element.image-element img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  image-rendering: pixelated;
  pointer-events: none;
}

.quick-help {
  padding: 12px 18px;
  border-top: 1px solid var(--line);
  background: rgba(9, 12, 22, .94);
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}
.quick-help strong { color: var(--text); }

.empty-state { padding: 14px; border: 1px dashed var(--line); border-radius: 9px; color: var(--muted); font-size: 13px; }
.slot-title { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.badge { padding: 3px 7px; border-radius: 999px; background: #27203f; color: #c9bdff; font-size: 11px; }
.field { display: grid; gap: 7px; margin-top: 14px; color: var(--muted); font-size: 12px; }
.field select, .field input[type="color"], .field textarea { width: 100%; }
.field input[type="color"] { height: 38px; padding: 4px; }
.range-line { display: grid; grid-template-columns: 1fr 54px; gap: 8px; align-items: center; }
.range-line output { color: var(--text); text-align: right; font-size: 11px; }
input[type="range"] { width: 100%; accent-color: #7359f5; }
.stacked-actions { display: grid; gap: 8px; margin-top: 16px; }
.file-label { text-align: center; font-size: 13px; }
.status { min-height: 18px; color: var(--muted); font-size: 12px; line-height: 1.4; }
.metrics-box {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: #151b2b;
  color: var(--text);
  line-height: 1.45;
}
.compact-info { margin-top: 0; }

@media (max-width: 1260px) {
  .layout { grid-template-columns: 260px minmax(470px, 1fr); }
  .right-panel { grid-column: 1 / -1; border-left: 0; border-top: 1px solid var(--line); display: grid; grid-template-columns: 1fr 1fr; gap: 24px; }
  .right-panel section + section { margin: 0; padding: 0; border: 0; }
}
@media (max-width: 780px) {
  .topbar { align-items: flex-start; flex-direction: column; }
  .layout { display: block; }
  .left-panel, .right-panel { border: 0; border-bottom: 1px solid var(--line); }
  .right-panel { display: block; }
  .right-panel section + section { margin-top: 26px; padding-top: 24px; border-top: 1px solid var(--line); }
  .canvas-scroll { place-items: start; padding: 24px; }
  .asset-list { grid-template-columns: 1fr; }
  .asset-actions { grid-template-columns: 1fr; }
}
