:root {
  --bg: #0a0a12;
  --panel: #14141f;
  --panel-2: #1b1b2a;
  --line: #262637;
  --text: #e8e8f0;
  --muted: #8a8aa0;
  --teal: #37d1c4;
  --orange: #ff5a36;
  --yellow: #ffd23f;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--text);
  font: 13px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  overflow: hidden; user-select: none;
}

#app {
  display: grid;
  grid-template-columns: 54px 240px 1fr 300px;
  grid-template-rows: 48px 1fr;
  grid-template-areas:
    "tools top  top    top"
    "tools left center right";
  height: 100vh;
}

/* Left tool rail (Photoshop-style) */
#toolbar {
  grid-area: tools; background: #0d0d16; border-right: 1px solid var(--line);
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  padding: 10px 0; overflow: visible; z-index: 6;
}
#toolbar .tool {
  width: 38px; height: 38px; padding: 0; display: flex; align-items: center;
  justify-content: center; font-size: 17px; border-radius: 9px;
  background: transparent; border: 1px solid transparent; color: var(--muted);
  position: relative; line-height: 1;
}
#toolbar .tool:hover { background: var(--panel-2); color: var(--text); border-color: var(--line); }
#toolbar .tool.active {
  background: linear-gradient(180deg, #1d3a38, #16302e);
  color: var(--teal); border-color: var(--teal);
  box-shadow: 0 0 0 1px rgba(55,209,196,0.25) inset;
}
#toolbar .tool-sep { width: 26px; height: 1px; background: var(--line); margin: 4px 0; }
#toolbar .tool-spacer { flex: 1; }
#toolbar .tool.ghost { font-size: 15px; color: #55556a; }

/* Top bar */
#topbar {
  grid-area: top; display: flex; align-items: center; gap: 14px;
  padding: 0 14px; background: var(--panel); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 600; }
.brand .logo { color: var(--teal); font-size: 18px; }
.brand .name { letter-spacing: .3px; }
#topbar .tools { display: flex; align-items: center; gap: 8px; margin-left: 12px; }
#topbar .sep { width: 1px; height: 22px; background: var(--line); }
#topbar .status { margin-left: auto; color: var(--muted); font-size: 12px; display: flex; align-items: center; gap: 8px; }
.lang-select {
  background: var(--panel-2); color: var(--text); border: 1px solid var(--line);
  border-radius: 7px; padding: 5px 6px; font-size: 12px; cursor: pointer;
}
.lang-select:hover { border-color: #33334a; }
#topbar .status .build { color: #4a4a5e; font-size: 10px; margin-left: 6px; }
#autosave-dot { color: var(--teal); }

button {
  background: var(--panel-2); color: var(--text); border: 1px solid var(--line);
  border-radius: 7px; padding: 6px 11px; cursor: pointer; font-size: 12px;
}
button:hover { background: #24243a; border-color: #33334a; }
button.toggle.active, button.active { background: var(--orange); border-color: var(--orange); color: #fff; }

/* Panels */
aside { background: var(--panel); overflow-y: auto; display: flex; flex-direction: column; }
#left { grid-area: left; border-right: 1px solid var(--line); }
#right { grid-area: right; border-left: 1px solid var(--line); }
.panel-head {
  padding: 10px 12px 8px; font-size: 11px; text-transform: uppercase;
  letter-spacing: .8px; color: var(--muted); position: sticky; top: 0;
  background: var(--panel); border-bottom: 1px solid var(--line); z-index: 1;
}
.lib-actions { display: flex; flex-wrap: wrap; gap: 6px; padding: 10px 12px; }
.lib-actions button, .lib-actions label.btn { flex: 1 1 45%; }
label.btn {
  display: inline-flex; align-items: center; justify-content: center; text-align: center;
  background: var(--panel-2); color: var(--text); border: 1px solid var(--line);
  border-radius: 7px; padding: 6px 11px; cursor: pointer; font-size: 12px; user-select: none;
}
label.btn:hover { background: #24243a; border-color: #33334a; }
label.btn.topbtn { padding: 6px 11px; }
/* File inputs hidden visually (NOT display:none, so <label> reliably opens the
   dialog in every browser incl. Safari), still focusable/clickable. */
.sr-file {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; opacity: 0;
}
.media-row .meta .warn { color: var(--orange); font-size: 10px; }

/* Media filter + favorites */
.lib-filter { display: flex; gap: 6px; padding: 0 12px 8px; }
.lib-filter input {
  flex: 1; background: var(--bg); color: var(--text); border: 1px solid var(--line);
  border-radius: 6px; padding: 5px 8px; font-size: 12px; min-width: 0;
}
.favfilter { flex-shrink: 0; color: #6a6a80; padding: 5px 9px; }
.favfilter.active { background: var(--yellow); border-color: var(--yellow); color: #2a2405; }

/* Examples (built-in generative loops — ready to use) */
.panel-subhead {
  padding: 10px 12px 4px; font-size: 10px; text-transform: uppercase;
  letter-spacing: .8px; color: var(--muted);
}
.panel-subhead .sub-note { text-transform: none; letter-spacing: 0; color: #55556a; font-size: 10px; }
.examples { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; padding: 0 12px 8px; }
.ex-chip {
  display: flex; align-items: center; gap: 6px; padding: 6px 8px; border-radius: 8px;
  background: var(--panel-2); border: 1px solid var(--line); cursor: pointer; font-size: 11px;
  color: var(--text); text-align: left;
}
.ex-chip:hover { border-color: var(--teal); background: #172a2a; }
.ex-chip span:last-child { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ex-chip .prev {
  width: 40px; height: 24px; border-radius: 4px; flex-shrink: 0;
  background: #000; border: 1px solid var(--line); image-rendering: auto;
}
.ex-chip .dot {
  width: 16px; height: 16px; border-radius: 4px; flex-shrink: 0;
  background: linear-gradient(135deg, var(--teal), var(--orange));
}
.ex-chip .dot.play {
  display: flex; align-items: center; justify-content: center;
  color: #06201d; font-size: 9px; background: var(--teal);
}
.ex-sub {
  grid-column: 1 / -1; font-size: 10px; color: #55556a; text-transform: uppercase;
  letter-spacing: .6px; padding: 4px 0 0;
}

/* Media folders */
.folder { display: flex; flex-direction: column; }
.folder-head {
  display: flex; align-items: center; gap: 6px; padding: 5px 8px; margin: 2px 0;
  border-radius: 7px; background: #12121d; border: 1px solid var(--line);
  cursor: pointer; font-size: 11px; color: var(--muted);
}
.folder-head.dragover { border-color: var(--teal); background: #172a2a; color: var(--teal); }
.folder-head .fh-tw { width: 12px; text-align: center; color: #6a6a80; }
.folder-head .fh-name { flex: 1; letter-spacing: .3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.folder-head .fh-count { color: #55556a; font-variant-numeric: tabular-nums; }
.folder-body { display: flex; flex-direction: column; gap: 6px; padding: 4px 0 4px 6px; }
.folder-body.collapsed { display: none; }
.media-row .star { color: #4a4a5e; cursor: pointer; padding: 2px 4px; font-size: 13px; }
.media-row .star.on { color: var(--yellow); }

.media-list, .surface-list { padding: 8px; display: flex; flex-direction: column; gap: 6px; }
.empty { color: var(--muted); padding: 10px 12px; font-size: 12px; }
.hint { color: var(--muted); font-size: 11px; padding: 8px 12px; line-height: 1.5; }

.media-row {
  display: flex; align-items: center; gap: 8px; padding: 6px; border-radius: 8px;
  background: var(--panel-2); border: 1px solid var(--line); cursor: grab;
}
.media-row:hover { border-color: #33334a; }
.thumb {
  width: 42px; height: 32px; border-radius: 5px; background: #000; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center; overflow: hidden;
  color: var(--teal); font-size: 15px;
}
.thumb img { width: 100%; height: 100%; object-fit: cover; }
.thumb.vid { color: var(--orange); }
.thumb.grid { color: var(--yellow); }
.media-row .meta { flex: 1; min-width: 0; }
.media-row .meta .t { font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.media-row .meta .s { font-size: 10px; color: var(--muted); }

button.icon {
  background: transparent; border: none; padding: 3px 5px; font-size: 13px;
  color: var(--muted); border-radius: 5px;
}
button.icon:hover { background: #24243a; color: var(--text); }

.surf-row {
  display: flex; align-items: center; gap: 4px; padding: 6px 8px; border-radius: 8px;
  background: var(--panel-2); border: 1px solid var(--line); cursor: pointer;
}
.surf-row.sel { border-color: var(--teal); background: #172a2a; }
.surf-row .nm { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Center stage */
#center { grid-area: center; position: relative; display: flex; flex-direction: column; }
#stage-wrap {
  flex: 1; position: relative; background:
    repeating-conic-gradient(#0f0f18 0% 25%, #0c0c14 0% 50%) 50% / 24px 24px;
  overflow: hidden;
}
#gl, #overlay { position: absolute; }
#overlay { touch-action: none; cursor: crosshair; }
/* Per-tool cursors on the stage */
#app[data-tool="move"] #overlay { cursor: default; }
#app[data-tool="transform"] #overlay { cursor: default; }
#app[data-tool="bezier"] #overlay { cursor: crosshair; }
#app[data-tool="mesh"] #overlay { cursor: cell; }
#app[data-tool="mask"] #overlay { cursor: crosshair; }
#app[data-tool="eyedropper"] #overlay { cursor: copy; }
#app[data-tool="hand"] #overlay { cursor: grab; }
#app[data-tool="hand"].panning #overlay { cursor: grabbing; }
#app[data-tool="zoom"] #overlay { cursor: zoom-in; }
#app[data-tool="zoom"].alt #overlay { cursor: zoom-out; }

/* Zoom HUD */
.zoom-hud {
  position: absolute; right: 12px; bottom: 12px; z-index: 5; display: flex; gap: 4px;
  background: rgba(10,10,18,0.72); padding: 4px; border-radius: 10px; border: 1px solid var(--line);
  backdrop-filter: blur(4px);
}
.zoom-hud button {
  background: transparent; border: none; color: var(--muted); font-size: 12px;
  padding: 4px 8px; border-radius: 6px;
}
.zoom-hud button:hover { background: var(--panel-2); color: var(--text); }
#zoom-pct { font-variant-numeric: tabular-nums; min-width: 46px; }
#app.live-mode .zoom-hud { display: none; }
.zoom-hud .hud-sep { width: 1px; align-self: stretch; background: var(--line); margin: 2px 2px; }
#btn-snap.active { background: var(--teal); color: #06201d; }

/* Tool hint (transient helper text under the stage) */
.tool-hint {
  position: absolute; bottom: 12px; left: 50%; transform: translateX(-50%);
  background: rgba(0,0,0,0.6); color: var(--teal); padding: 5px 12px; border-radius: 20px;
  font-size: 11px; display: none; max-width: 70%; text-align: center;
}
#app.edit-mode .tool-hint.show { display: block; }
.drop-hint {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  background: rgba(55,209,196,0.12); border: 2px dashed var(--teal); color: var(--teal);
  font-size: 16px; pointer-events: none; z-index: 5;
}
.empty-stage {
  position: absolute; inset: 0; display: flex; flex-direction: column; gap: 8px;
  align-items: center; justify-content: center; text-align: center; padding: 24px;
  color: var(--muted); cursor: pointer; z-index: 4;
}
.empty-stage:hover { background: rgba(55,209,196,0.05); }
.empty-stage .es-title { font-size: 18px; color: var(--text); font-weight: 600; }
.empty-stage .es-body { font-size: 13px; line-height: 1.7; max-width: 440px; }
.empty-stage b { color: var(--teal); font-weight: 600; }
.empty-stage .es-note { display: block; margin-top: 10px; font-size: 11px; color: var(--muted); }
.empty-stage .es-note b { color: var(--yellow); }
.hidden { display: none !important; }
.live-hint {
  position: absolute; bottom: 12px; left: 50%; transform: translateX(-50%);
  background: rgba(0,0,0,0.6); color: var(--muted); padding: 5px 12px; border-radius: 20px;
  font-size: 11px; display: none;
}
#app.live-mode .live-hint { display: block; }
#app.live-mode #stage-wrap { background: #000; }

/* Scenes bar */
.scenes-bar {
  display: flex; align-items: center; gap: 8px; padding: 8px 12px;
  background: var(--panel); border-top: 1px solid var(--line); min-height: 44px;
}
.scene-add { flex-shrink: 0; }
#btn-fade, #btn-auto { flex-shrink: 0; }
#btn-fade.active { background: var(--teal); border-color: var(--teal); color: #06201d; }
.auto-sec {
  width: 46px; flex-shrink: 0; background: var(--bg); color: var(--text);
  border: 1px solid var(--line); border-radius: 6px; padding: 5px 6px; font-size: 12px;
}
.auto-unit { color: var(--muted); font-size: 11px; flex-shrink: 0; margin-left: -4px; }
.scenes-list { display: flex; align-items: center; gap: 6px; overflow-x: auto; flex: 1; }
.scenes-list .empty-inline { color: var(--muted); font-size: 11px; white-space: nowrap; }
.scene-chip {
  display: flex; align-items: center; gap: 2px; padding: 3px 4px 3px 8px;
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 16px;
  white-space: nowrap; flex-shrink: 0;
}
.scene-chip.active { border-color: var(--teal); background: #172a2a; }
.scene-chip .sc-name { cursor: pointer; font-size: 12px; padding: 2px 2px; }
.scene-chip .sc-name:hover { color: var(--teal); }

/* Inspector */
.inspector { padding: 10px 12px; display: flex; flex-direction: column; gap: 12px; }
.field { display: flex; flex-direction: column; gap: 5px; }
.field label { font-size: 11px; color: var(--muted); }
.field.mini { flex: 1; }
.field input[type=text], .field input[type=number], .inspector select {
  background: var(--bg); color: var(--text); border: 1px solid var(--line);
  border-radius: 6px; padding: 6px 8px; font-size: 12px; width: 100%;
}
.row2 { display: flex; gap: 8px; }
.slider { display: flex; align-items: center; gap: 8px; }
.slider input { flex: 1; }
.slider .val { width: 34px; text-align: right; color: var(--muted); font-variant-numeric: tabular-nums; }
.btn-row { display: flex; gap: 8px; }
button.small { flex: 1; font-size: 11px; }
button.small.mask-on { background: #ff4fd8; border-color: #ff4fd8; color: #fff; }
.crop-canvas {
  width: 100%; height: auto; display: block; border-radius: 6px;
  border: 1px solid var(--line); background: #000; cursor: crosshair;
  touch-action: none;
}

/* Video transport */
.transport { display: flex; align-items: center; gap: 6px; }
.transport + .transport { margin-top: 6px; }
button.tbtn {
  background: var(--panel-2); border: 1px solid var(--line); color: var(--text);
  border-radius: 6px; padding: 4px 9px; font-size: 13px; cursor: pointer; flex-shrink: 0;
}
button.tbtn:hover { background: #24243a; }
.tscrub { flex: 1; min-width: 0; }
.ttime { font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; flex-shrink: 0; min-width: 30px; }
.ttime:last-of-type { text-align: right; }

/* Fullscreen */
#stage-wrap:fullscreen { background: #000; }
#stage-wrap:fullscreen .live-hint { display: none; }

/* Scrollbars */
::-webkit-scrollbar { width: 10px; }
::-webkit-scrollbar-thumb { background: #2a2a3c; border-radius: 6px; }
::-webkit-scrollbar-track { background: transparent; }
