/* Editor & live control UI (dark + gold). The overlay canvas keeps its own styles. */
:root {
  --ui-bg: #0e0f13;
  --ui-bg2: #15171d;
  --ui-bg3: #1d2027;
  --ui-border: #2a2e38;
  --ui-text: #e8e9ee;
  --ui-muted: #8b90a0;
  --ui-gold: #f5a800;
  --ui-gold2: #ffd84f;
  --ui-danger: #ff4d6d;
  --ui-ok: #35d07f;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--ui-bg); color: var(--ui-text); font: 13px/1.4 system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif; }
body.dragging { user-select: none; cursor: grabbing; }
.hidden { display: none !important; }
a { color: var(--ui-gold2); }
button, input, select, textarea { font: inherit; color: inherit; }
input[type="text"], input[type="number"], input[type="password"], select, textarea {
  background: var(--ui-bg); border: 1px solid var(--ui-border); border-radius: 6px; padding: 6px 8px; width: 100%; min-width: 0; outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--ui-gold); }
input[type="color"] { width: 34px; height: 30px; padding: 0; border: 1px solid var(--ui-border); border-radius: 6px; background: none; }
input[type="range"] { width: 100%; accent-color: var(--ui-gold); }
input[type="checkbox"] { accent-color: var(--ui-gold); }
textarea { resize: vertical; }
.mono { font-family: ui-monospace, Consolas, monospace; }
.muted { color: var(--ui-muted); }
.small { font-size: 12px; }
.row { display: flex; gap: 6px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 10px; }
.grid4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }

.btn {
  background: var(--ui-bg3); border: 1px solid var(--ui-border); border-radius: 6px; padding: 7px 12px; cursor: pointer; white-space: nowrap; text-decoration: none; display: inline-flex; align-items: center; gap: 6px; line-height: 1.1;
}
.btn:hover { border-color: var(--ui-gold); color: #fff; }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn.primary { background: linear-gradient(180deg, var(--ui-gold2), var(--ui-gold)); color: #1a1200; border-color: transparent; font-weight: 700; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.small { padding: 5px 9px; font-size: 12px; }
.btn.tiny { padding: 2px 6px; font-size: 11px; }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--ui-danger); }
.btn.danger:hover { border-color: var(--ui-danger); }
.btn.on { border-color: var(--ui-gold); color: var(--ui-gold2); }
.btn.active { border-color: var(--ui-gold); background: rgba(245, 168, 0, 0.12); }

/* ---- login ---------------------------------------------------------- */
.login { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; background: radial-gradient(ellipse at top, #1c1a10, var(--ui-bg) 70%); z-index: 50; }
.login form { width: 340px; background: var(--ui-bg2); border: 1px solid var(--ui-border); border-radius: 12px; padding: 28px; display: flex; flex-direction: column; gap: 12px; }
.login h1 { margin: 0 0 4px; font-size: 20px; letter-spacing: 0.04em; }
.login h1 span { color: var(--ui-gold); }
.login .err { color: var(--ui-danger); min-height: 1.2em; font-size: 12px; }

/* ---- layout --------------------------------------------------------- */
.app { display: grid; grid-template-columns: 270px 1fr 340px; grid-template-rows: 48px 1fr; height: 100vh; }
.topbar { grid-column: 1 / -1; display: flex; align-items: center; gap: 8px; padding: 0 12px; background: var(--ui-bg2); border-bottom: 1px solid var(--ui-border); position: relative; z-index: 20; }
.brand { font-weight: 800; letter-spacing: 0.06em; margin-right: 8px; }
.brand span { color: var(--ui-gold); font-weight: 600; letter-spacing: 0.02em; }
.topbar select { width: 220px; }
.spacer { flex: 1; }
.save-status { color: var(--ui-muted); font-size: 12px; min-width: 90px; text-align: right; }
.save-status.error { color: var(--ui-danger); }
.left, .right { background: var(--ui-bg2); overflow: auto; display: flex; flex-direction: column; }
.left { border-right: 1px solid var(--ui-border); }
.right { border-left: 1px solid var(--ui-border); }
.tabs { display: flex; border-bottom: 1px solid var(--ui-border); position: sticky; top: 0; background: var(--ui-bg2); z-index: 2; flex-wrap: wrap; }
.tabs button { flex: 1; background: none; border: 0; border-bottom: 2px solid transparent; padding: 10px 6px; cursor: pointer; color: var(--ui-muted); font-weight: 600; font-size: 12px; }
.tabs button.active { color: var(--ui-gold2); border-bottom-color: var(--ui-gold); }
.tabs button:hover { color: #fff; }
.center { display: flex; flex-direction: column; min-width: 0; }
.toolbar { display: flex; align-items: center; gap: 10px; padding: 6px 12px; background: var(--ui-bg2); border-bottom: 1px solid var(--ui-border); flex-wrap: wrap; }
.toolbar select { width: auto; }
.toolbar label { display: inline-flex; align-items: center; gap: 4px; color: var(--ui-muted); font-size: 12px; }
#activeInfo { display: inline-flex; align-items: center; gap: 6px; margin-left: auto; font-size: 12px; }
.viewport { flex: 1; overflow: auto; position: relative; background: #0a0b0e; }
.viewport::before { content: ''; position: absolute; inset: 0; pointer-events: none; }
.canvas-wrap { position: relative; margin: 24px; overflow: visible; outline: 1px solid var(--ui-border); background-color: #2a2a30; background-image: linear-gradient(45deg, #222228 25%, transparent 25%, transparent 75%, #222228 75%), linear-gradient(45deg, #222228 25%, transparent 25%, transparent 75%, #222228 75%); background-position: 0 0, 50% 50%; }
.canvas-wrap[data-bg="dark"] { background: #101014; }
.canvas-wrap[data-bg="black"] { background: #000; }
.canvas-wrap[data-bg="green"] { background: #00a651; }
.canvas-wrap .canvas { position: absolute; left: 0; top: 0; transform-origin: 0 0; }
.statusbar { padding: 4px 12px; font-size: 12px; color: var(--ui-muted); border-top: 1px solid var(--ui-border); background: var(--ui-bg2); }

/* widgets on the editor canvas */
.canvas .wg { cursor: grab; outline: 1px dashed transparent; outline-offset: 2px; }
.canvas .wg:hover { outline-color: rgba(255, 216, 79, 0.45); }
.canvas .wg.selected { outline: calc(2px * var(--inv, 1)) solid #19d3ff; outline-offset: calc(2px * var(--inv, 1)); cursor: move; }
.canvas .wg .wg-in { pointer-events: none; }
.canvas .wg .handles { display: none; }
.canvas .wg.selected .handles { display: block; }
.canvas .handle { position: absolute; width: calc(10px * var(--inv, 1)); height: calc(10px * var(--inv, 1)); background: #19d3ff; border: calc(1px * var(--inv, 1)) solid #04303a; z-index: 5; }
.canvas .handle.n { top: calc(-5px * var(--inv, 1)); left: 50%; transform: translateX(-50%); cursor: ns-resize; }
.canvas .handle.s { bottom: calc(-5px * var(--inv, 1)); left: 50%; transform: translateX(-50%); cursor: ns-resize; }
.canvas .handle.e { right: calc(-5px * var(--inv, 1)); top: 50%; transform: translateY(-50%); cursor: ew-resize; }
.canvas .handle.w { left: calc(-5px * var(--inv, 1)); top: 50%; transform: translateY(-50%); cursor: ew-resize; }
.canvas .handle.ne { right: calc(-5px * var(--inv, 1)); top: calc(-5px * var(--inv, 1)); cursor: nesw-resize; }
.canvas .handle.sw { left: calc(-5px * var(--inv, 1)); bottom: calc(-5px * var(--inv, 1)); cursor: nesw-resize; }
.canvas .handle.nw { left: calc(-5px * var(--inv, 1)); top: calc(-5px * var(--inv, 1)); cursor: nwse-resize; }
.canvas .handle.se { right: calc(-5px * var(--inv, 1)); bottom: calc(-5px * var(--inv, 1)); cursor: nwse-resize; }

/* ---- left panel ----------------------------------------------------- */
.scene-list, .widget-list { display: flex; flex-direction: column; }
.scene-row, .widget-row { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border-bottom: 1px solid var(--ui-border); cursor: pointer; }
.scene-row:hover, .widget-row:hover { background: var(--ui-bg3); }
.scene-row.selected, .widget-row.selected { background: rgba(245, 168, 0, 0.12); box-shadow: inset 3px 0 0 var(--ui-gold); }
.widget-row.hidden-w { opacity: 0.5; }
.scene-name, .w-type { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.w-name { color: var(--ui-muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 80px; }
.orient { font-size: 10px; font-weight: 700; padding: 2px 5px; border-radius: 4px; background: var(--ui-bg3); color: var(--ui-muted); }
.orient.p { color: #19d3ff; }
.row-actions { display: none; gap: 3px; }
.scene-row:hover .row-actions, .widget-row:hover .row-actions, .scene-row.selected .row-actions, .widget-row.selected .row-actions { display: inline-flex; }
.live-dot { width: 9px; height: 9px; border-radius: 50%; background: #ff2a2a; box-shadow: 0 0 6px #ff2a2a; display: inline-block; animation: liveBlink 1.4s ease-in-out infinite; }
@keyframes liveBlink { 50% { opacity: 0.35; } }
.add-scene { padding: 10px; display: flex; flex-direction: column; gap: 6px; border-bottom: 1px solid var(--ui-border); }
.add-widgets { padding: 10px; }
.add-widgets .cat { font-size: 11px; color: var(--ui-muted); text-transform: uppercase; letter-spacing: 0.08em; margin: 10px 0 4px; }
.type-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; }
.type-btn { background: var(--ui-bg3); border: 1px solid var(--ui-border); border-radius: 6px; padding: 6px; cursor: pointer; text-align: left; font-size: 12px; }
.type-btn:hover { border-color: var(--ui-gold); color: #fff; }

/* ---- right panel ---------------------------------------------------- */
.panel-body { padding: 10px 12px 30px; display: flex; flex-direction: column; gap: 8px; }
.panel-head { font-size: 14px; padding: 4px 0 2px; }
.section { border: 1px solid var(--ui-border); border-radius: 8px; padding: 8px 10px 10px; display: flex; flex-direction: column; gap: 7px; background: rgba(255, 255, 255, 0.015); }
.section-title { font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--ui-gold); font-weight: 700; }
.field { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.field.inline { flex-direction: row; align-items: center; }
.field.compact { flex: 1; }
.field-label { font-size: 11px; color: var(--ui-muted); }
.field-help { font-size: 11px; color: var(--ui-muted); opacity: 0.8; }
.toggle { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; }
.toggle b { font-weight: 500; }
.color-row { display: flex; gap: 6px; align-items: center; }
.range-row { display: flex; gap: 8px; align-items: center; }
.range-val { min-width: 34px; text-align: right; font-size: 12px; color: var(--ui-muted); }
.checks { display: flex; flex-wrap: wrap; gap: 8px; }
.check { display: inline-flex; align-items: center; gap: 4px; }
.list-field { display: flex; flex-direction: column; gap: 6px; }
.list-row { display: flex; gap: 6px; align-items: flex-end; border-bottom: 1px dashed var(--ui-border); padding-bottom: 6px; }
.list-actions { display: flex; gap: 2px; }
.image-field { display: flex; flex-direction: column; gap: 6px; position: relative; }
.img-preview img { max-width: 100%; max-height: 90px; border: 1px solid var(--ui-border); border-radius: 6px; background: #000; }
.menu { position: absolute; top: 100%; left: 0; right: 0; background: var(--ui-bg3); border: 1px solid var(--ui-border); border-radius: 8px; padding: 6px; z-index: 30; max-height: 260px; overflow: auto; display: flex; flex-direction: column; gap: 2px; box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5); }
.menu-item { display: flex; gap: 8px; align-items: center; background: none; border: 0; padding: 6px; cursor: pointer; text-align: left; border-radius: 4px; }
.menu-item:hover { background: var(--ui-bg); }
.menu-item img { width: 36px; height: 24px; object-fit: cover; border-radius: 3px; }
.swatches { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.swatch { display: flex; align-items: center; gap: 8px; background: var(--ui-bg); border: 1px solid var(--ui-border); border-radius: 6px; padding: 5px 8px; cursor: pointer; font-size: 12px; }
.swatch i { width: 26px; height: 18px; border-radius: 4px; display: block; }
.swatch.active { border-color: var(--ui-gold); }

/* ---- dropdown menus ------------------------------------------------- */
.dropdown { position: absolute; top: 44px; background: var(--ui-bg3); border: 1px solid var(--ui-border); border-radius: 8px; padding: 6px; display: flex; flex-direction: column; gap: 2px; min-width: 220px; box-shadow: 0 12px 30px rgba(0, 0, 0, 0.5); z-index: 40; }
.dropdown button { background: none; border: 0; text-align: left; padding: 7px 10px; border-radius: 5px; cursor: pointer; }
.dropdown button:hover { background: var(--ui-bg); color: #fff; }
.dropdown button.danger { color: var(--ui-danger); }
.dropdown hr { border: 0; border-top: 1px solid var(--ui-border); margin: 4px 0; }
#profileMenu { left: 250px; }
#linksPop { right: 150px; width: 560px; max-width: calc(100vw - 40px); padding: 12px; gap: 8px; max-height: calc(100vh - 70px); overflow: auto; }
.link-row { display: flex; flex-direction: column; gap: 3px; }
.link-label { font-size: 12px; }
.link-row input { font-family: ui-monospace, Consolas, monospace; font-size: 11px; }

/* ---- toasts --------------------------------------------------------- */
.toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 6px; z-index: 100; }
.toast { background: var(--ui-bg3); border: 1px solid var(--ui-border); border-left: 3px solid var(--ui-gold); padding: 8px 12px; border-radius: 6px; box-shadow: 0 8px 20px rgba(0, 0, 0, 0.5); animation: toastIn 0.25s ease-out; }
.toast.error { border-left-color: var(--ui-danger); }
.toast.out { opacity: 0; transition: opacity 0.3s; }
@keyframes toastIn { from { transform: translateY(10px); opacity: 0; } }

/* ---- live controls -------------------------------------------------- */
.live-controls { display: flex; flex-direction: column; gap: 10px; }
.scene-buttons { display: flex; flex-direction: column; gap: 6px; }
.scene-group { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.group-name { font-size: 11px; color: var(--ui-muted); text-transform: uppercase; letter-spacing: 0.06em; min-width: 60px; }
.scene-btn .orient { margin-right: 2px; }
.goals-live { display: flex; flex-direction: column; gap: 6px; }
.goal-row { display: flex; gap: 6px; align-items: center; }
.goal-row b { min-width: 90px; font-size: 12px; }
.goal-row input { width: 80px; }
/* full-canvas layers (particles, media alerts) must not swallow clicks meant for other widgets */
.canvas .wg[data-type="mediaAlert"]:not(.selected), .canvas .wg[data-type="particles"]:not(.selected) { pointer-events: none; }
.img-preview video { max-width: 100%; max-height: 110px; border: 1px solid var(--ui-border); border-radius: 6px; background: #000; display: block; }
.img-preview audio { width: 100%; height: 32px; }
.section.warn { border-color: rgba(255, 196, 0, 0.55); background: rgba(255, 196, 0, 0.06); flex-direction: row; align-items: center; justify-content: space-between; gap: 10px; }
.rules { display: flex; flex-direction: column; gap: 10px; }
.rule-card { border: 1px solid var(--ui-border); border-left: 3px solid var(--ui-gold); border-radius: 8px; padding: 8px 10px 10px; display: flex; flex-direction: column; gap: 7px; background: rgba(255, 255, 255, 0.02); }
.rule-card.off { opacity: 0.55; border-left-color: var(--ui-border); }
.rule-head { display: flex; align-items: center; gap: 6px; }
.rule-head input[type="text"] { flex: 1; font-weight: 600; }
.rule-gift { width: 28px; height: 28px; object-fit: contain; }
.gift-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(86px, 1fr)); gap: 6px; }
.gift-chip { display: flex; flex-direction: column; align-items: center; gap: 2px; background: var(--ui-bg); border: 1px solid var(--ui-border); border-radius: 8px; padding: 6px 4px; cursor: pointer; font-size: 11px; }
.gift-chip:hover { border-color: var(--ui-gold); color: #fff; }
.gift-chip img { width: 36px; height: 36px; object-fit: contain; }
.gift-chip small { color: var(--ui-muted); }
.gift-dot { font-size: 26px; line-height: 36px; }
.tk-status { padding: 6px 8px; border-radius: 6px; background: var(--ui-bg); border-left: 3px solid var(--ui-border); }
.tk-status.ok { border-left-color: var(--ui-ok); color: var(--ui-text); }
.tk-status.bad { border-left-color: var(--ui-danger); }

/* ---- standalone live page ------------------------------------------ */
.live-page { max-width: 720px; margin: 0 auto; padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.live-page header { display: flex; align-items: center; gap: 10px; }
.live-page header .spacer { flex: 1; }
.live-page .scene-btn { padding: 12px 14px; font-size: 15px; }
@media (max-width: 600px) {
  .grid4 { grid-template-columns: 1fr 1fr; }
  .grid2 { grid-template-columns: 1fr; }
}
