/* ===== Reset & dasar ===== */
* { box-sizing: border-box; margin: 0; padding: 0; }
:root {
  --bg: #0b0c18;
  --bg2: #12132a;
  --panel: #161834;
  --panel2: #1d1f40;
  --line: #2b2e58;
  --text: #e8e9f5;
  --muted: #9a9cc4;
  --accent: #7c5cff;
  --accent2: #00d4ff;
  --good: #2fd47a;
  --warn: #ffb020;
  --radius: 12px;
}
html, body { height: 100%; }
body {
  background: radial-gradient(1200px 700px at 70% -10%, #1c1d44 0%, var(--bg) 55%);
  color: var(--text);
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  overflow: hidden;
}
.hidden { display: none !important; }
button { font-family: inherit; cursor: pointer; }
select, input[type=range], input[type=color], textarea { font-family: inherit; }

/* ===== Header ===== */
#topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 18px; border-bottom: 1px solid var(--line);
  background: rgba(11,12,24,.85); backdrop-filter: blur(8px);
  height: 64px;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand .logo {
  font-size: 30px; color: var(--accent);
  text-shadow: 0 0 18px rgba(124,92,255,.8);
}
.brand h1 { font-size: 17px; letter-spacing: .3px; }
.brand p { font-size: 11px; color: var(--muted); }
.top-actions { display: flex; gap: 8px; }

/* ===== Buttons ===== */
.btn {
  background: var(--panel2); color: var(--text); border: 1px solid var(--line);
  border-radius: 9px; padding: 8px 14px; font-size: 13px; font-weight: 600;
  transition: .15s transform, .15s background, .15s border-color;
}
.btn:hover { background: #262a55; border-color: #3a3e78; transform: translateY(-1px); }
.btn:active { transform: translateY(0) scale(.98); }
.btn:focus-visible { outline: 2px solid var(--accent2); outline-offset: 2px; }
.btn:disabled { opacity: .4; cursor: not-allowed; transform: none; }
.btn-primary {
  background: linear-gradient(135deg, var(--accent), #5a3fe0);
  border-color: transparent;
}
.btn-primary:hover { background: linear-gradient(135deg, #8d6fff, #6a4ff0); }
.btn-ghost { background: transparent; }
.btn-danger {
  background: rgba(220, 50, 80, .15);
  border-color: rgba(220, 50, 80, .4);
  color: #ff8090;
}
.btn-danger:hover { background: rgba(220, 50, 80, .3); border-color: rgba(220, 50, 80, .7); }
.btn-icon { padding: 8px 12px; }
.btn-icon.active { background: var(--accent); border-color: transparent; }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-export { width: 100%; padding: 13px; font-size: 15px; margin-top: 10px; }

/* ===== Layout ===== */
#layout {
  display: grid;
  grid-template-columns: 300px 1fr 300px;
  gap: 12px; padding: 12px;
  height: calc(100vh - 64px);
}
.panel {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); overflow-y: auto; padding: 4px;
  box-shadow: 0 8px 24px rgba(0,0,0,.25);
  backdrop-filter: blur(2px);
}
.panel-section { padding: 14px; border-bottom: 1px solid var(--line); }
.panel-section:last-child { border-bottom: none; }
.panel-section h2 {
  font-size: 14px; margin-bottom: 8px; letter-spacing: .2px;
  display: flex; align-items: center; gap: 8px;
}
.panel-section h2::before {
  content: ""; width: 3px; height: 14px; border-radius: 2px;
  background: linear-gradient(180deg, var(--accent), var(--accent2));
}
.hint { font-size: 11.5px; color: var(--muted); margin-bottom: 10px; line-height: 1.5; }
.val { color: var(--accent2); font-weight: 700; font-size: 12px; }

/* ===== Form rows ===== */
.form-row { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; }
.form-row label { font-size: 12px; color: var(--muted); font-weight: 600; }
select, textarea {
  background: var(--bg2); color: var(--text); border: 1px solid var(--line);
  border-radius: 8px; padding: 8px 10px; font-size: 13px; outline: none;
}
select:focus, textarea:focus { border-color: var(--accent); }
input[type=range] { accent-color: var(--accent); width: 100%; }
input[type=color] {
  width: 100%; height: 36px; background: var(--bg2);
  border: 1px solid var(--line); border-radius: 8px; padding: 4px;
}

/* ===== Segmented buttons (export) ===== */
.seg { display: flex; gap: 6px; }
.seg-btn {
  flex: 1; background: var(--bg2); color: var(--muted); border: 1px solid var(--line);
  border-radius: 8px; padding: 8px 4px; font-size: 12.5px; font-weight: 700;
}
.seg-btn:hover { color: var(--text); }
.seg-btn.active {
  background: linear-gradient(135deg, var(--accent), #5a3fe0);
  color: #fff; border-color: transparent;
}
.estim-box {
  background: var(--bg2); border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 12px; font-size: 12.5px; color: var(--muted); line-height: 1.9;
}
.estim-box b { color: var(--text); }
.warn { color: var(--warn); font-size: 12px; margin-top: 4px; }

/* ===== Preset grid ===== */
.preset-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.preset-card {
  background: var(--bg2); border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 8px; text-align: center; transition: .15s;
  color: var(--text);
}
.preset-card:hover { border-color: var(--accent); transform: translateY(-2px); box-shadow: 0 6px 16px rgba(0,0,0,.35); }
.preset-card.active {
  border-color: var(--accent);
  background: linear-gradient(160deg, rgba(124,92,255,.25), rgba(0,212,255,.08));
  box-shadow: 0 0 0 1px var(--accent);
}
.preset-card .ic { font-size: 20px; display: block; margin-bottom: 4px; }
.preset-card .nm { font-size: 12px; font-weight: 700; color: var(--text); }
.preset-card.active .nm { color: #fff; }
.preset-card .ds { font-size: 10px; color: var(--muted); margin-top: 2px; }

/* ===== Center panel ===== */
#centerPanel { display: flex; flex-direction: column; gap: 12px; min-width: 0; min-height: 0; }
#stageWrap {
  flex: 1; min-height: 120px; background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); position: relative; overflow: hidden;
  display: flex; align-items: center; justify-content: center;
}
#stageWrap.transparent {
  background-image:
    linear-gradient(45deg, #1b1d3d 25%, transparent 25%),
    linear-gradient(-45deg, #1b1d3d 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #1b1d3d 75%),
    linear-gradient(-45deg, transparent 75%, #1b1d3d 75%);
  background-size: 24px 24px; background-position: 0 0, 0 12px, 12px -12px, -12px 0;
  background-color: #101226;
}
#emptyState { text-align: center; color: var(--muted); padding: 20px; }
.empty-icon { font-size: 52px; margin-bottom: 10px; animation: floatY 3s ease-in-out infinite; }
@keyframes floatY {
  0%, 100% { transform: translateY(0); }
  50%      { transform: translateY(-8px); }
}
#emptyState h2 { color: var(--text); margin-bottom: 6px; font-size: 20px; }
#emptyState p { font-size: 13px; margin-bottom: 14px; }
#stage {
  width: 100%; height: 100%; display: flex; align-items: center; justify-content: center;
  overflow: hidden;
}
#svgHolder {
  width: 100%; height: 100%;
  display: flex; align-items: center; justify-content: center;
  transform-origin: center; will-change: transform;
}
#svgHolder svg {
  display: block; max-width: 100%; max-height: 100%;
  width: auto; height: auto;
}
#stageInfo {
  position: absolute; bottom: 10px; left: 12px; font-size: 11.5px; color: var(--muted);
  background: rgba(11,12,24,.75); padding: 5px 10px; border-radius: 8px; border: 1px solid var(--line);
}
#stageInfo b { color: var(--accent2); }

/* ===== Zoom toolbar di stage ===== */
#stageZoom {
  position: absolute; top: 10px; right: 10px; z-index: 6;
  display: flex; align-items: center; gap: 6px;
  background: rgba(11,12,24,.78); border: 1px solid var(--line);
  border-radius: 8px; padding: 5px 8px;
  backdrop-filter: blur(4px);
}
#zoomLabel {
  font-size: 11.5px; color: var(--muted); min-width: 42px; text-align: center;
  font-variant-numeric: tabular-nums; font-weight: 700;
}
#stage.pannable { cursor: grab; }
#stage.panning { cursor: grabbing; }

/* ===== Transport bar ===== */
#transport {
  flex: none;
  display: flex; align-items: center; gap: 10px; background: var(--panel);
  border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 14px;
}
#timeDisplay {
  font-variant-numeric: tabular-nums; font-size: 13px; color: var(--muted);
  background: var(--bg2); padding: 6px 12px; border-radius: 8px; border: 1px solid var(--line);
}
.spacer { flex: 1; }
.zoom-label { display: flex; align-items: center; gap: 8px; font-size: 11.5px; color: var(--muted); font-weight: 600; }
.zoom-label input { width: 100px; }

/* ===== Timeline ===== */
#timelinePanel {
  flex: none;              /* jangan kecil: stage (flex:1) yang menyerap perubahan ukuran */
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 10px 12px; display: flex; flex-direction: column; gap: 8px;
}
.timeline-head { display: flex; align-items: baseline; gap: 12px; flex: none; }
.timeline-head h2 { font-size: 13px; }
#timelineScroll {
  flex: none; height: 240px;   /* tinggi konsisten berapapun ukuran preview */
  overflow-x: auto; overflow-y: auto;        /* track tetap terjangkau walau banyak */
}
#timelineInner { position: relative; min-width: 100%; }
#ruler { position: relative; height: 22px; margin-left: 170px; border-bottom: 1px solid var(--line); }
.tick { position: absolute; top: 0; height: 100%; border-left: 1px solid var(--line); font-size: 9.5px; color: var(--muted); padding-left: 3px; padding-top: 3px; }
#tracks { position: relative; }
.track { display: flex; align-items: stretch; height: 40px; border-bottom: 1px solid rgba(43,46,88,.5); }
.track-info { width: 170px; flex: none; display: flex; align-items: center; gap: 6px; padding: 0 8px; }
.track-info .dot { width: 9px; height: 9px; border-radius: 50%; flex: none; }
.track-info .nm { font-size: 11.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex: 1; color: var(--text); }
.track-info .tg { font-size: 9.5px; color: var(--muted); flex: none; }
.track-lane { position: relative; flex: 1; }
.track-block {
  position: absolute; top: 6px; height: 28px; border-radius: 7px; cursor: grab;
  display: flex; align-items: center; padding: 0 8px; font-size: 10.5px; font-weight: 700;
  color: #fff; border: 1px solid rgba(255,255,255,.25); user-select: none;
  box-shadow: 0 2px 8px rgba(0,0,0,.35); overflow: hidden; white-space: nowrap;
}
.track-block:hover { filter: brightness(1.12); }
.track-block.selected {
  outline: 2px solid #fff; outline-offset: 1px;
  box-shadow: 0 0 0 4px rgba(124,92,255,.35), 0 4px 14px rgba(0,0,0,.4);
}
.track-block .grip { position: absolute; right: 0; top: 0; width: 9px; height: 100%; cursor: ew-resize; }
.track-block .grip::after { content: ""; position: absolute; right: 3px; top: 8px; width: 3px; height: 12px; border-radius: 2px; background: rgba(255,255,255,.55); }
#playhead {
  position: absolute; top: 0; bottom: 0; width: 2px; background: var(--accent2);
  pointer-events: none; z-index: 5; box-shadow: 0 0 8px var(--accent2);
  transition: left .1s linear;
}
#playhead::before {
  content: ""; position: absolute; top: 0; left: -5px; border: 6px solid transparent;
  border-top: 8px solid var(--accent2);
}

/* ===== Inspector ===== */
#inspector {
  background: var(--bg2); border: 1px solid var(--accent); border-radius: 10px;
  padding: 8px 12px 10px;
  position: relative;
  box-shadow: 0 0 0 1px rgba(124,92,255,.15), 0 -6px 24px rgba(124,92,255,.08);
  animation: inspIn .18s ease-out;
}
@keyframes inspIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}
.insp-header {
  display: flex; align-items: center; justify-content: space-between;
  gap: 8px; margin-bottom: 8px;
}
.insp-header h3 {
  font-size: 12.5px; color: var(--accent2); margin: 0;
  flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
#inspClose {
  padding: 2px 8px; font-size: 11px; line-height: 1; border-radius: 6px;
  color: var(--muted);
}
#inspClose:hover { color: var(--text); background: rgba(255,255,255,.08); }
.insp-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.insp-grid label { display: flex; flex-direction: column; gap: 4px; font-size: 11px; color: var(--muted); }
.insp-actions { display: flex; gap: 6px; margin-top: 10px; flex-wrap: wrap; }

/* ===== Modal & toast ===== */
.modal {
  position: fixed; inset: 0; background: rgba(5,6,15,.7); backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center; z-index: 100;
  animation: modalFade .15s ease-out;
}
.modal-box {
  background: var(--panel); border: 1px solid var(--line); border-radius: 16px;
  padding: 22px; width: min(640px, 92vw);
  box-shadow: 0 24px 60px rgba(0,0,0,.5);
  animation: modalIn .18s ease-out;
}
@keyframes modalFade { from { opacity: 0; } to { opacity: 1; } }
@keyframes modalIn {
  from { opacity: 0; transform: scale(.96) translateY(8px); }
  to   { opacity: 1; transform: scale(1); }
}
.modal-box h2 { font-size: 17px; margin-bottom: 6px; }
.modal-box textarea { width: 100%; height: 240px; resize: vertical; font-family: Consolas, monospace; font-size: 12px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; }
#toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(12px);
  background: var(--panel2); border: 1px solid var(--accent); color: var(--text);
  padding: 12px 20px; border-radius: 12px; font-size: 13px; z-index: 200;
  box-shadow: 0 10px 30px rgba(0,0,0,.5);
  opacity: 0; transition: opacity .2s, transform .2s;
  pointer-events: none;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ===== Confirm delete modal ===== */
.confirm-box {
  max-width: 380px;
  text-align: center;
  padding: 36px 32px 28px;
  animation: confirmIn 0.25s cubic-bezier(.34,1.56,.64,1);
}

@keyframes confirmIn {
  from { opacity: 0; transform: scale(0.82) translateY(20px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}

.confirm-header {
  display: flex;
  justify-content: center;
  margin-bottom: 18px;
}

.confirm-icon-wrap {
  width: 72px; height: 72px;
  background: linear-gradient(135deg, rgba(220,50,80,.25), rgba(255,90,60,.15));
  border: 2px solid rgba(220,50,80,.4);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  animation: iconPulse 1.8s ease-in-out infinite;
  box-shadow: 0 0 24px rgba(220,50,80,.25), inset 0 0 12px rgba(220,50,80,.1);
}

@keyframes iconPulse {
  0%, 100% { transform: scale(1); box-shadow: 0 0 20px rgba(220,50,80,.2), inset 0 0 10px rgba(220,50,80,.08); }
  50%       { transform: scale(1.08); box-shadow: 0 0 36px rgba(220,50,80,.4), inset 0 0 16px rgba(220,50,80,.15); }
}

.confirm-icon { font-size: 34px; line-height: 1; }

.confirm-title {
  font-size: 22px;
  font-weight: 700;
  color: var(--text);
  margin: 0 0 14px;
  letter-spacing: -0.3px;
}

.confirm-name-wrap {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: rgba(100,80,255,.12);
  border: 1px solid rgba(100,80,255,.35);
  border-radius: 20px;
  padding: 5px 16px;
  margin-bottom: 12px;
  max-width: 100%;
}

.confirm-name {
  font-size: 14px;
  font-weight: 600;
  color: #c8bfff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 240px;
}

.confirm-sub {
  font-size: 13px;
  color: rgba(255,255,255,.35);
  margin: 0 0 24px;
}

.confirm-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
}

.confirm-btn-cancel {
  flex: 1;
  font-size: 14px;
  padding: 11px 0;
  border-radius: 10px;
  opacity: 0.75;
  transition: opacity .15s;
}
.confirm-btn-cancel:hover { opacity: 1; }

.confirm-btn-delete {
  flex: 1.2;
  font-size: 14px;
  font-weight: 600;
  padding: 11px 0;
  border-radius: 10px;
  background: linear-gradient(135deg, #dc3250, #c0274a);
  border-color: rgba(220,50,80,.5);
  color: #fff;
  box-shadow: 0 4px 14px rgba(220,50,80,.35);
  transition: all .18s;
  display: flex; align-items: center; justify-content: center; gap: 6px;
}
.confirm-btn-delete:hover {
  background: linear-gradient(135deg, #e84060, #d03055);
  box-shadow: 0 6px 20px rgba(220,50,80,.5);
  transform: translateY(-1px);
}
.confirm-btn-delete:active { transform: translateY(0) scale(.97); }
.confirm-btn-icon { font-size: 15px; }

/* icon wiggle on hover */
.confirm-box:hover .confirm-icon { animation: iconShake 0.4s ease-in-out; }

@keyframes iconShake {
  0%, 100% { transform: rotate(0deg); }
  20%       { transform: rotate(-12deg); }
  40%       { transform: rotate(10deg); }
  60%       { transform: rotate(-8deg); }
  80%       { transform: rotate(6deg); }
}

#stageWrap.dragover {
  outline: 3px dashed var(--accent2);
  outline-offset: -6px;
  background: rgba(0,212,255,.04) !important;
}

/* ===== Export progress ===== */
.progbar { width: 100%; height: 10px; background: var(--bg2); border-radius: 6px; overflow: hidden; margin-top: 10px; border: 1px solid var(--line); }
#progFill { height: 100%; width: 0%; background: linear-gradient(90deg, var(--accent), var(--accent2)); transition: width .15s; }
#progText { font-size: 12px; color: var(--muted); margin-top: 6px; text-align: center; }

/* ===== Tips ===== */
.tips { list-style: none; }
.tips li { font-size: 12px; color: var(--muted); margin-bottom: 8px; padding-left: 16px; position: relative; line-height: 1.5; }
.tips li::before { content: "▸"; position: absolute; left: 0; color: var(--accent); }

/* ===== Scrollbar ===== */
::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-thumb { background: #2c2f5c; border-radius: 6px; }
::-webkit-scrollbar-track { background: transparent; }

/* ===== Responsive (fallback) ===== */
@media (max-width: 1100px) {
  #layout { grid-template-columns: 260px 1fr 260px; }
}
@media (max-width: 860px) {
  #layout { grid-template-columns: 1fr !important; grid-template-rows: auto 1fr auto; }
  #sidebar, #inspector { max-height: 240px; overflow: auto; }
  #transport { flex-wrap: wrap; gap: 6px; }
  .zoom-label { font-size: 10px; }
  .track-info { width: 120px; }
  #ruler { margin-left: 120px; }
}
@media (max-width: 560px) {
  header { flex-direction: column; align-items: stretch; gap: 6px; }
  .toolbar { flex-wrap: wrap; justify-content: center; }
  .modal-box { padding: 14px; }
  #timeDisplay { font-size: 11px; }
}
