:root {
  --bg: #0e0e12;
  --panel: #16161d;
  --panel2: #1d1d27;
  --line: #2a2a37;
  --txt: #ececf2;
  --muted: #7d7d92;
  --cyan: #4dd2ff;
  --violet: #a855f7;
  --accent-grad: linear-gradient(120deg, #4dd2ff 0%, #a855f7 100%);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; height: 100%;
  background: var(--bg);
  color: var(--txt);
  font-family: 'IBM Plex Mono', monospace;
  overflow: hidden;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  max-width: 560px;
  margin: 0 auto;
  background: radial-gradient(circle at 50% -10%, #1c1c2e 0%, #0e0e12 55%);
  position: relative;
}

/* Top bar */
#topbar-mount { flex: 0 0 auto; }
.topbar {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--line);
  background: rgba(20,20,28,.7);
  backdrop-filter: blur(6px);
}
.logo { font-size: 15px; font-weight: 700; white-space: nowrap; }
.logo-name {
  font-family: 'Bricolage Grotesque', sans-serif; font-weight: 900;
  background: var(--accent-grad); -webkit-background-clip: text; background-clip: text; color: transparent;
}
.proj-name {
  flex: 1; min-width: 0;
  background: transparent; border: none; color: var(--txt);
  font-family: 'IBM Plex Mono', monospace; font-size: 13px; text-align: center;
  padding: 6px; border-radius: 8px;
}
.proj-name:focus { outline: none; background: var(--panel2); }
.top-actions { display: flex; gap: 6px; }

.btn {
  border: none; border-radius: 10px; padding: 8px 12px;
  font-family: 'IBM Plex Mono', monospace; font-size: 12px; font-weight: 600;
  cursor: pointer; color: var(--txt); transition: transform .08s ease, filter .15s;
  white-space: nowrap;
}
.btn:active { transform: scale(.94); }
.btn-primary { background: var(--accent-grad); color: #0b0b12; font-weight: 700; }
.btn-accent { background: var(--violet); color: #fff; }
.btn-ghost { background: var(--panel2); border: 1px solid var(--line); }
.btn.wide { flex: 1; }

/* Preview — bounded so it never eats the controls */
.preview-wrap {
  flex: 1 1 auto;
  min-height: 120px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 10px;
  position: relative;
  overflow: hidden;
}
#canvas {
  max-width: 100%;
  max-height: 100%;
  border-radius: 14px;
  box-shadow: 0 0 0 1px var(--line), 0 12px 40px rgba(0,0,0,.6);
  background: #000;
  display: block;
}

/* Controls block — always visible, natural height */
#controls {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
}

/* Preview controls (scrubber + transport) */
.preview-controls { padding: 6px 12px 2px; position: relative; }
.scrub {
  height: 8px; border-radius: 6px; background: var(--panel2);
  border: 1px solid var(--line); cursor: pointer; position: relative; overflow: hidden;
}
.scrub-fill {
  height: 100%; width: 0%;
  background: var(--accent-grad);
  box-shadow: 0 0 10px var(--cyan);
}
.transport {
  display: flex; align-items: center; gap: 10px; justify-content: center;
  padding: 8px 0 4px;
}
.tbtn {
  background: var(--panel2); border: 1px solid var(--line); color: var(--txt);
  width: 42px; height: 42px; border-radius: 50%; font-size: 15px; cursor: pointer;
  display: grid; place-items: center; transition: transform .08s;
}
.tbtn:active { transform: scale(.9); }
.tbtn.big {
  width: 54px; height: 54px; font-size: 20px;
  background: var(--accent-grad); color: #0b0b12; border: none;
  box-shadow: 0 0 20px rgba(77,210,255,.4);
}
.time-read {
  position: absolute; right: 14px; bottom: 14px; font-size: 11px; color: var(--muted);
}

/* Timeline */
.timeline {
  display: flex; gap: 8px; overflow-x: auto; padding: 10px 12px;
  border-top: 1px solid var(--line); border-bottom: 1px solid var(--line);
  background: var(--panel);
  scrollbar-width: thin;
}
.timeline::-webkit-scrollbar { height: 5px; }
.timeline::-webkit-scrollbar-thumb { background: var(--line); border-radius: 3px; }
.tl-empty { color: var(--muted); font-size: 12px; padding: 24px 4px; white-space: nowrap; align-self: center; }
.clip {
  position: relative; flex: 0 0 auto;
  width: 66px; height: 66px; border-radius: 10px;
  background-size: cover; background-position: center; background-color: #222;
  border: 2px solid transparent; cursor: pointer;
}
.clip.sel { border-color: var(--cyan); box-shadow: 0 0 12px rgba(77,210,255,.5); }
.clip-dur {
  position: absolute; bottom: 3px; right: 3px;
  background: rgba(0,0,0,.7); font-size: 9px; padding: 1px 4px; border-radius: 4px;
}
.clip-tr { position: absolute; top: 3px; left: 3px; font-size: 10px; background: rgba(0,0,0,.6); border-radius: 4px; padding: 0 2px; }
.clip-ctrls {
  position: absolute; inset: 0; display: grid;
  grid-template-columns: 1fr 1fr; grid-template-rows: 1fr 1fr;
  background: rgba(0,0,0,.55); border-radius: 8px;
}
.clip-ctrls button {
  background: none; border: none; color: #fff; font-size: 13px; cursor: pointer;
}
.tl-add {
  flex: 0 0 auto; width: 66px; height: 66px; border-radius: 10px;
  border: 2px dashed var(--line); background: transparent; color: var(--cyan);
  font-size: 26px; cursor: pointer;
}
.tl-add:active { transform: scale(.94); }

/* Tray */
.tray {
  display: flex; gap: 4px; overflow-x: auto; padding: 8px 8px;
  background: var(--panel); border-top: 1px solid var(--line);
}
.tool {
  flex: 1 0 auto; min-width: 54px;
  background: transparent; border: none; color: var(--muted);
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  padding: 6px 4px; border-radius: 10px; cursor: pointer; transition: .12s;
}
.tool.active { background: var(--panel2); color: var(--cyan); }
.tool-ic { font-size: 19px; }
.tool-lbl { font-size: 10px; }

/* Panel */
.panel {
  background: var(--panel2); border-top: 1px solid var(--line);
  max-height: 0; overflow: hidden; transition: max-height .28s ease, padding .28s;
  padding: 0 14px;
}
.panel.open { max-height: 300px; padding: 14px; overflow-y: auto; }
.panel-title { font-family: 'Bricolage Grotesque', sans-serif; font-weight: 700; font-size: 15px; margin-bottom: 10px; }
.row { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; flex-wrap: wrap; }
.field {
  width: 100%; background: var(--bg); border: 1px solid var(--line); color: var(--txt);
  padding: 10px; border-radius: 10px; font-family: 'IBM Plex Mono', monospace; font-size: 13px;
}
.field:focus { outline: none; border-color: var(--cyan); }
.ai-box { display: flex; gap: 6px; margin: 10px 0 6px; }
.ai-box .field { flex: 1; }
.hint { color: var(--muted); font-size: 11px; }
.hint.big { font-size: 13px; text-align: center; padding: 16px 0; }
.lbl { font-size: 12px; color: var(--muted); }

.chip {
  background: var(--bg); border: 1px solid var(--line); color: var(--txt);
  padding: 8px 12px; border-radius: 20px; font-size: 12px; cursor: pointer; text-transform: capitalize;
}
.chip.on { background: var(--accent-grad); color: #0b0b12; font-weight: 700; border-color: transparent; }
.big-chip { padding: 10px 18px; font-size: 14px; }
.filter-grid { display: flex; flex-wrap: wrap; gap: 6px; }

.colors { gap: 10px; }
.swatch { width: 30px; height: 30px; border-radius: 50%; border: 2px solid var(--line); cursor: pointer; }
.swatch.on { border-color: var(--cyan); box-shadow: 0 0 8px var(--cyan); }

.range { flex: 1; accent-color: var(--cyan); }
.slider-val { font-size: 12px; color: var(--cyan); min-width: 44px; text-align: right; }

/* Footer */
.footer {
  text-align: center; font-size: 11px; color: var(--muted);
  padding: 8px; background: var(--panel);
}
.footer a { color: var(--cyan); text-decoration: none; }

/* Overlay */
.overlay {
  position: absolute; inset: 0; z-index: 40;
  background: rgba(10,10,16,.88); backdrop-filter: blur(4px);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 18px;
}
.spinner {
  width: 46px; height: 46px; border-radius: 50%;
  border: 4px solid var(--line); border-top-color: var(--cyan);
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.overlay-txt { font-family: 'Bricolage Grotesque', sans-serif; font-size: 16px; }

/* Toast */
.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: var(--panel2); border: 1px solid var(--line); color: var(--txt);
  padding: 10px 16px; border-radius: 24px; font-size: 12px; z-index: 50;
  opacity: 0; transition: .3s; pointer-events: none; box-shadow: 0 6px 24px rgba(0,0,0,.5);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* Confetti */
#confetti-layer { position: fixed; inset: 0; pointer-events: none; z-index: 60; overflow: hidden; }
.confetti {
  position: absolute; top: -20px; width: 9px; height: 14px; border-radius: 2px;
  animation: fall 2.2s ease-in forwards;
}
@keyframes fall {
  to { transform: translateY(105vh) rotate(720deg); opacity: 0; }
}

@media (min-width: 561px) {
  #app { border-left: 1px solid var(--line); border-right: 1px solid var(--line); }
}
</parameter>