:root {
  --bg:      #f5f0e6;
  --bg2:     #fcfaf5;
  --bg3:     #ffffff;
  --border:  #e6dcce;
  --border2: #c8a840;
  --accent:  #c8a840;
  --accent2: #b59430;
  --text:    #4a3f35;
  --text2:   #6b5e52;
  --text3:   #a19181;
  --gold:    #c8a840;
  --gold2:   #8a6d1c;
  --danger:  #b84040;
  --success: #409860;
  --font-mono: 'Courier New', Courier, monospace;
  --font-ui:   system-ui, 'Segoe UI', sans-serif;
  --r: 4px;
  --resize-handle-size: 5px;
}

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: 'Segoe UI', Arial, sans-serif;
  background: #f5f0e8;
  color: #3a2e1e;
  min-height: 100vh;
  padding: 24px;
}

/* HEADER */
#header {
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  padding: 12px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
}
#header h1 {
  font-size: 1.3rem;
  font-weight: 800;
  color: #8b4513;
  letter-spacing: 2px;
  margin-bottom: 6px;
}
#header .sp {
  flex: 1;
}

/* TOOLBAR */
#toolbar {
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  padding: 8px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.tb-row {
  display: flex;
  gap: 6px;
  align-items: center;
  flex-wrap: wrap;
}
.lbl {
  font-family: var(--font-ui);
  font-size: 11px;
  color: var(--text2);
  font-weight: bold;
  letter-spacing: 0.03em;
  white-space: nowrap;
}
.sep {
  width: 1px;
  height: 18px;
  background: var(--border);
  margin: 0 2px;
  flex-shrink: 0;
}
.sep-h {
  width: 100%;
  height: 1px;
  background: var(--border);
}

select, input[type=text], input[type=number] {
  background: var(--bg3);
  border: 1px solid var(--border);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 12px;
  padding: 4px 6px;
  border-radius: var(--r);
  outline: none;
}
select:focus, input:focus {
  border-color: var(--accent);
}
input[type=color] {
  width: 32px;
  height: 24px;
  padding: 1px 2px;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--r);
  cursor: pointer;
}
input[type=range] {
  accent-color: var(--accent);
  cursor: pointer;
}
input[type=file] {
  display: none;
}

button {
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 600;
  padding: 5px 12px;
  border: 1px solid var(--border);
  border-radius: var(--r);
  background: var(--bg3);
  color: var(--text2);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  transition: all 0.15s;
  white-space: nowrap;
}
button:hover:not(:disabled) {
  border-color: var(--accent);
  color: var(--gold2);
  background: #fdfcf9;
}
button:disabled {
  opacity: 0.35;
  cursor: default;
}
.btn-primary {
  border-color: var(--accent);
  color: var(--gold2);
  background: #fbf9f3;
}
.btn-primary:hover:not(:disabled) {
  background: #eedcb3;
}
.btn-danger {
  border-color: #dbc5c5;
  color: var(--danger);
}
.btn-danger:hover:not(:disabled) {
  background: #fdf3f3;
  border-color: var(--danger);
}
.btn-gold {
  border-color: var(--gold);
  color: var(--gold2);
  background: #fbf9f3;
}
.btn-gold:hover:not(:disabled) {
  background: #f5eedc;
}

/* CANVAS (1920x1080 16:9 aspect-ratio) */
#canvas-container {
  padding: 16px;
  display: flex;
  justify-content: center;
  background: #e2dacb;
}
#canvas-wrap {
  position: relative;
  background: var(--bg3);
  border: 1px solid var(--border);
  overflow: hidden;
  cursor: crosshair;
  user-select: none;
  width: 100%;
  max-width: 1200px;
  aspect-ratio: 16 / 9;
  box-shadow: 0 4px 12px rgba(0,0,0,0.06);
}
#canvas-bg-img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0.65;
  pointer-events: none;
}
#grid-svg, #snap-svg {
  position: absolute;
  inset: 0;
  pointer-events: none;
  width: 100%;
  height: 100%;
}
#grid-svg {
  z-index: 1;
}
#snap-svg {
  z-index: 3;
}

/* PANEL ELEMENT */
.panel-el {
  position: absolute;
  z-index: 2;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: flex-start;
  cursor: move;
  user-select: none;
  border: 1px solid rgba(0,0,0,0.15);
  box-shadow: 0 2px 4px rgba(0,0,0,0.05);
}
.panel-el.selected {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
  z-index: 10;
}
.panel-el .pen-dot {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 5px;
  height: 5px;
  background: var(--accent);
  border-radius: 50%;
  pointer-events: none;
}
.panel-el .p-l1 {
  font-size: 18px;
  font-weight: 600;
  color: #fff;
  pointer-events: none;
  width: 100%;
  padding: 0 6px;
  text-shadow: 0 1px 2px rgba(0,0,0,0.6);
}
.panel-el .p-l2 {
  font-size: 10px;
  opacity: 0.75;
  color: #eee;
  pointer-events: none;
  padding: 0 6px;
}

/* 4-SIDE RESIZE HANDLES */
.panel-el .edge-h {
  position: absolute;
  background: transparent;
  z-index: 4;
}
.panel-el .edge-h:hover {
  background: rgba(200, 168, 64, 0.25);
}
.panel-el .edge-t {
  top: 0;
  left: 4px;
  right: 4px;
  height: var(--resize-handle-size);
  cursor: n-resize;
}
.panel-el .edge-b {
  bottom: 0;
  left: 4px;
  right: 4px;
  height: var(--resize-handle-size);
  cursor: s-resize;
}
.panel-el .edge-l {
  left: 0;
  top: 4px;
  bottom: 4px;
  width: var(--resize-handle-size);
  cursor: w-resize;
}
.panel-el .edge-r {
  right: 0;
  top: 4px;
  bottom: 4px;
  width: var(--resize-handle-size);
  cursor: e-resize;
}

.panel-el.sel-type {
  border-color: var(--gold);
}
.panel-el.sel-nb {
  border: 1px dashed var(--text3);
}

/* PROPS */
#props-bar {
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  padding: 6px 14px;
  min-height: 38px;
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  align-items: center;
}

/* OUTPUT */
#output-section {
  background: var(--bg2);
  border-top: 1px solid var(--border);
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.out-hdr {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.out-title {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text2);
  font-weight: bold;
  letter-spacing: 0.05em;
}
#scene-output {
  width: 100%;
  height: 120px;
  background: var(--bg3);
  border: 1px solid var(--border);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 12px;
  padding: 8px 12px;
  border-radius: var(--r);
  resize: vertical;
  outline: none;
  box-shadow: inset 0 1px 3px rgba(0,0,0,0.02);
}

/* FOOTER */
#footer {
  background: var(--bg2);
  border-top: 1px solid var(--border);
  padding: 6px 14px;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text3);
  display: flex;
  justify-content: space-between;
}
#footer a {
  color: var(--gold2);
  text-decoration: none;
  font-weight: bold;
}
#footer a:hover {
  text-decoration: underline;
}

/* TOAST */
#toast {
  position: fixed;
  bottom: 18px;
  left: 18px;
  background: var(--bg3);
  border: 1px solid var(--accent);
  color: var(--gold2);
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: bold;
  padding: 6px 16px;
  border-radius: var(--r);
  box-shadow: 0 4px 10px rgba(0,0,0,0.08);
  opacity: 0;
  transition: opacity 0.18s;
  pointer-events: none;
  z-index: 9999;
}
#toast.on {
  opacity: 1;
}