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

:root {
  --bg: #0a0a0f;
  --surface: #13131a;
  --surface2: #1c1c27;
  --accent: #6c63ff;
  --accent2: #a78bfa;
  --orange: #f97316;
  --orange2: #fb923c;
  --success: #34d399;
  --error: #f87171;
  --text: #e2e8f0;
  --muted: #64748b;
  --border: #2a2a3d;
  --radius: 12px;
}

html { scroll-behavior: smooth; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.6;
}

/* Header */
header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 1.2rem 2rem;
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 200;
  background: rgba(10,10,15,0.92);
  backdrop-filter: blur(12px);
}
.logo { font-size: 1.3rem; font-weight: 700; color: var(--accent2); letter-spacing: -0.02em; }
nav { display: flex; gap: 1.5rem; }
nav a { color: var(--muted); text-decoration: none; font-size: 0.9rem; transition: color .2s; }
nav a:hover { color: var(--text); }

/* Steps */
main { width: 100%; }
.step { display: none; }
.step.active { display: block; }

/* Step 1: Upload */
#step-upload { max-width: 800px; margin: 0 auto; padding: 2rem 1.5rem 4rem; }
.hero { text-align: center; padding: 3.5rem 0 2.5rem; }
.hero h1 { font-size: clamp(1.8rem, 4vw, 3rem); font-weight: 800; line-height: 1.15; letter-spacing: -0.03em; margin-bottom: 1rem; }
.hero h1 span { background: linear-gradient(135deg, var(--accent), var(--accent2)); -webkit-background-clip: text; -webkit-text-fill-color: transparent; }
.subtitle { color: var(--muted); font-size: 1rem; max-width: 500px; margin: 0 auto; }

.drop-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 3.5rem 2rem;
  text-align: center;
  cursor: pointer;
  transition: border-color .2s, background .2s;
  background: var(--surface);
  margin-top: 1.5rem;
}
.drop-zone:hover, .drop-zone.over { border-color: var(--accent); background: rgba(108,99,255,.06); }
.drop-icon { font-size: 2.8rem; margin-bottom: 1rem; }
.drop-title { font-size: 1.1rem; font-weight: 600; margin-bottom: .4rem; }
.drop-sub { color: var(--muted); font-size: .9rem; margin-bottom: .8rem; }
.browse-link { color: var(--accent2); cursor: pointer; text-decoration: underline; }
.drop-formats { font-size: .78rem; color: var(--muted); letter-spacing: .04em; }

/* Demo / Preview animations button */
.demo-buttons {
  display: flex;
  gap: .75rem;
  justify-content: center;
  margin-top: 1.5rem;
  flex-wrap: wrap;
}
.btn-demo {
  display: block;
  padding: .75rem 2rem;
  background: linear-gradient(135deg, var(--orange), var(--orange2));
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: .95rem;
  font-weight: 600;
  cursor: pointer;
  transition: opacity .2s, transform .15s;
  letter-spacing: .01em;
}
.btn-demo:hover { opacity: .9; transform: translateY(-1px); }
.btn-demo-alt {
  background: linear-gradient(135deg, #6c5ce7, #a855f7);
}
.demo-hint {
  text-align: center;
  font-size: .78rem;
  color: var(--muted);
  margin-top: .5rem;
}

/* Status card (step 2) */
#step-converting {
  display: none;
  min-height: 60vh;
  align-items: center;
  justify-content: center;
}
#step-converting.active { display: flex; }

/* Rigging progress with 3D preview (step 4) */
#step-rigging { display: none; height: calc(100vh - 60px); }
#step-rigging.active { display: flex; flex-direction: column; }

.rig-progress-layout {
  flex: 1;
  display: flex;
  align-items: stretch;
  justify-content: center;
  padding: 1rem;
}
.rig-viewer-wrap {
  position: relative;
  flex: 1;
  max-width: 1200px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.rig-viewer-wrap canvas {
  width: 100%;
  height: 100%;
  display: block;
}
.rig-overlay {
  position: absolute;
  bottom: 0; left: 0; right: 0;
  display: flex;
  justify-content: center;
  padding: 1.5rem;
  pointer-events: none;
  background: linear-gradient(to top, rgba(10,10,15,0.85) 0%, transparent 100%);
}
.rig-overlay-card {
  text-align: center;
  width: 100%;
  max-width: 420px;
}
.rig-overlay-card .spinner {
  width: 32px; height: 32px;
  border-width: 2px;
  margin: 0 auto 0.8rem;
}
.rig-overlay-card .status-title { font-size: 1rem; }
.rig-overlay-card .status-sub { font-size: .82rem; margin-bottom: 1rem; }
.rig-overlay-card .progress-bar { height: 3px; }
.rig-viewer-badge {
  position: absolute;
  top: 1rem; left: 1rem;
  background: rgba(108,99,255,0.2);
  border: 1px solid rgba(108,99,255,0.4);
  color: var(--accent2);
  font-size: .78rem;
  padding: 0.3rem 0.7rem;
  border-radius: 6px;
  pointer-events: none;
}
/* Display mode buttons (shared across all 3D viewers) */
.display-modes {
  position: absolute;
  top: 0.7rem; right: 0.7rem;
  display: flex;
  gap: 3px;
  background: rgba(19,19,26,0.85);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 3px;
  z-index: 10;
}
.rig-vis-modes {
  top: 2.6rem;
}
.dm-btn {
  background: transparent;
  border: 1px solid transparent;
  color: var(--muted);
  font-size: .72rem;
  padding: 0.25rem 0.55rem;
  border-radius: 5px;
  cursor: pointer;
  transition: all .2s;
  font-family: inherit;
  white-space: nowrap;
}
.dm-btn:hover { color: var(--text); background: rgba(255,255,255,0.06); }
.dm-btn.active {
  color: var(--accent2);
  background: rgba(108,99,255,0.15);
  border-color: rgba(108,99,255,0.3);
}

.status-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 3rem 2.5rem;
  text-align: center;
  width: 100%;
  max-width: 480px;
  margin: 2rem auto;
}
.spinner {
  width: 52px; height: 52px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .8s linear infinite;
  margin: 0 auto 1.4rem;
}
@keyframes spin { to { transform: rotate(360deg); } }
.status-title { font-size: 1.1rem; font-weight: 600; margin-bottom: .5rem; }
.status-sub { font-size: .88rem; color: var(--muted); margin-bottom: 1.4rem; }
.progress-bar { height: 4px; background: var(--surface2); border-radius: 99px; overflow: hidden; }
.progress-fill { height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent2)); border-radius: 99px; transition: width .5s ease; }

/* Step 3: Joints */
#step-joints { display: none; height: calc(100vh - 60px); }
#step-joints.active { display: flex; flex-direction: column; }
.joints-layout {
  display: grid;
  grid-template-columns: 1fr 380px;
  flex: 1;
  overflow: hidden;
}
.viewer-wrap { position: relative; background: #080810; overflow: hidden; }
#previewCanvas, #resultCanvas { width: 100% !important; height: 100% !important; display: block; }
.viewer-hint {
  position: absolute; bottom: 12px; left: 50%; transform: translateX(-50%);
  background: rgba(0,0,0,.6); color: var(--muted);
  padding: .4rem 1rem; border-radius: 99px; font-size: .75rem;
  white-space: nowrap; pointer-events: none;
}

.joints-panel {
  background: var(--surface);
  border-left: 1px solid var(--border);
  padding: 1.2rem;
  display: flex; flex-direction: column; gap: .7rem;
  overflow-y: auto;
}
.joints-panel h3 { font-size: .9rem; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.joints-desc { font-size: .8rem; color: var(--muted); line-height: 1.5; }

/* Mode selector */
.mode-group { display: flex; gap: .4rem; }
.mode-btn {
  flex: 1; padding: .45rem .3rem;
  background: var(--surface2); border: 1px solid var(--border);
  color: var(--muted); border-radius: 7px; font-size: .78rem;
  cursor: pointer; transition: all .15s; text-align: center;
}
.mode-btn:hover { border-color: var(--accent2); color: var(--text); }
.mode-btn.active { background: rgba(108,99,255,.18); border-color: var(--accent); color: var(--accent2); font-weight: 600; }

/* Mirror toggle */
.option-row { display: flex; align-items: center; }
.toggle-label {
  display: flex; align-items: center; gap: .6rem;
  font-size: .82rem; color: var(--text); cursor: pointer; user-select: none;
}
.toggle-label input { display: none; }
.toggle-track {
  width: 34px; height: 18px; background: var(--surface2);
  border: 1px solid var(--border); border-radius: 99px;
  position: relative; transition: background .2s;
}
.toggle-label input:checked ~ .toggle-track { background: var(--accent); border-color: var(--accent); }
.toggle-thumb {
  position: absolute; top: 2px; left: 2px;
  width: 12px; height: 12px; border-radius: 50%;
  background: var(--muted); transition: transform .2s, background .2s;
}
.toggle-label input:checked ~ .toggle-track .toggle-thumb {
  transform: translateX(16px); background: #fff;
}
.joints-list { display: flex; flex-direction: column; gap: .3rem; flex: 1; }
.joint-item {
  display: flex; align-items: center; gap: .6rem;
  padding: .45rem .7rem;
  border-radius: 6px;
  font-size: .82rem;
  cursor: pointer;
  border: 1px solid transparent;
  transition: background .15s, border-color .15s;
}
.joint-item:hover { background: var(--surface2); }
.joint-item.selected { background: rgba(249,115,22,.1); border-color: var(--orange); }
.joint-dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--orange); flex-shrink: 0;
}
.joint-item.selected .joint-dot { background: var(--orange2); box-shadow: 0 0 6px var(--orange); }

/* Step 5: Result */
#step-result { display: none; height: calc(100vh - 60px); }
#step-result.active { display: flex; flex-direction: column; }
.result-layout {
  display: grid;
  grid-template-columns: 1fr 380px;
  height: 100vh;
  overflow: hidden;
}
.anim-controls {
  position: absolute; bottom: 16px; left: 50%; transform: translateX(-50%);
  display: flex; gap: .5rem;
}
.anim-btn {
  background: rgba(0,0,0,.7); color: var(--muted);
  border: 1px solid var(--border); padding: .4rem 1rem;
  border-radius: 6px; font-size: .82rem; cursor: pointer;
  transition: all .2s;
}
.anim-btn:hover { border-color: var(--accent); color: var(--text); }
.anim-btn.active { background: var(--accent); border-color: var(--accent); color: #fff; }

.result-panel {
  background: var(--surface);
  border-left: 1px solid var(--border);
  padding: 1.2rem 1.2rem;
  display: flex; flex-direction: column; gap: .8rem;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.result-badge {
  display: inline-flex; align-items: center; gap: .4rem;
  background: rgba(52,211,153,.1); color: var(--success);
  border: 1px solid rgba(52,211,153,.3);
  padding: .35rem .9rem; border-radius: 99px; font-size: .82rem; font-weight: 600;
  width: fit-content; flex-shrink: 0;
}
.result-panel h3 { font-size: 1.05rem; font-weight: 700; }
.result-panel p { font-size: .85rem; color: var(--muted); line-height: 1.5; }
.result-stats { font-size: .78rem; color: var(--muted); margin-top: auto; padding-top: 1rem; border-top: 1px solid var(--border); }

/* Buttons */
.btn-primary {
  width: 100%; padding: .85rem 1.5rem; flex-shrink: 0;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  color: #fff; border: none; border-radius: 8px;
  font-size: .95rem; font-weight: 600; cursor: pointer;
  transition: opacity .2s, transform .15s;
}
.btn-primary:hover { opacity: .9; transform: translateY(-1px); }
.btn-secondary {
  width: 100%; padding: .7rem 1.5rem; flex-shrink: 0;
  background: none; color: var(--muted);
  border: 1px solid var(--border); border-radius: 8px;
  font-size: .88rem; cursor: pointer;
  transition: border-color .2s, color .2s;
}
.btn-secondary:hover { border-color: var(--text); color: var(--text); }

.btn-cancel {
  margin-top: .8rem; padding: .4rem 1.5rem;
  background: none; color: var(--error);
  border: 1px solid var(--error); border-radius: 6px;
  font-size: .82rem; cursor: pointer;
  transition: background .2s, color .2s;
}
.btn-cancel:hover { background: var(--error); color: #fff; }

/* Info sections */
.info-section { border-top: 1px solid var(--border); padding: 3.5rem 1.5rem; }
.info-inner { max-width: 860px; margin: 0 auto; }
h2 { font-size: 1.5rem; font-weight: 700; margin-bottom: 2rem; letter-spacing: -0.02em; }
.steps-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 1.2rem; }
.step-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.4rem; }
.step-num { width: 32px; height: 32px; background: linear-gradient(135deg, var(--accent), var(--accent2)); border-radius: 7px; display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: .85rem; margin-bottom: .8rem; }
.step-card h4 { font-size: .95rem; margin-bottom: .3rem; }
.step-card p { font-size: .82rem; color: var(--muted); }
.format-grid { display: flex; flex-wrap: wrap; gap: .5rem; }
.fmt { background: var(--surface2); border: 1px solid var(--border); border-radius: 6px; padding: .35rem .8rem; font-size: .8rem; font-family: monospace; color: var(--accent2); }

/* Quality preset buttons */
.quality-group { display: flex; gap: .4rem; }
.quality-btn {
  flex: 1; padding: .45rem .3rem;
  background: var(--surface2); border: 1px solid var(--border);
  color: var(--muted); border-radius: 7px; font-size: .78rem;
  cursor: pointer; transition: all .15s; text-align: center;
}
.quality-btn:hover { border-color: var(--accent2); color: var(--text); }
.quality-btn.active { background: rgba(108,99,255,.18); border-color: var(--accent); color: var(--accent2); font-weight: 600; }

/* Advanced section */
.adv-section { border: 1px solid var(--border); border-radius: 7px; overflow: hidden; flex-shrink: 0; }
.adv-toggle {
  padding: .5rem .8rem; font-size: .78rem; color: var(--muted);
  cursor: pointer; list-style: none; user-select: none;
  background: var(--surface2);
}
.adv-toggle:hover { color: var(--text); }
.adv-body { padding: .7rem .8rem; display: flex; flex-direction: column; gap: .55rem; background: var(--surface); }
.adv-row { display: flex; flex-direction: column; gap: .2rem; }
.adv-row label { font-size: .78rem; color: var(--muted); display: flex; justify-content: space-between; }
.adv-row label span { color: var(--accent2); font-weight: 600; }
.adv-row input[type=range] {
  -webkit-appearance: none; width: 100%; height: 4px;
  background: var(--surface2); border-radius: 99px; outline: none;
}
.adv-row input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 14px; height: 14px;
  border-radius: 50%; background: var(--accent); cursor: pointer;
}

/* Animation category tabs */
.anim-cat-tabs { display: flex; gap: .25rem; flex-wrap: wrap; flex-shrink: 0; }
.anim-cat {
  padding: .3rem .55rem; font-size: 12px; font-weight: 500;
  background: var(--surface2); border: 1px solid var(--border);
  color: #fff; border-radius: 5px; cursor: pointer; transition: all .15s;
}
.anim-cat:hover { border-color: var(--accent2); color: var(--text); }
.anim-cat.active { background: rgba(108,99,255,.18); border-color: var(--accent); color: var(--accent2); font-weight: 600; }

/* Animation search box */
.anim-search {
  width: 100%; padding: .5rem .8rem; font-size: 13px; box-sizing: border-box;
  background: var(--surface2); border: 1px solid var(--border); border-radius: 7px;
  color: var(--text); outline: none; margin-bottom: .3rem;
}
.anim-search:focus { border-color: var(--accent); }
.anim-search::placeholder { color: var(--text2); opacity: .6; }

/* Scrollable animation list */
.anim-scroll-list {
  flex: 1 1 0;
  overflow-y: auto;
  min-height: 120px;
  border: 1px solid var(--border); border-radius: 7px; padding: .5rem;
  background: var(--surface2);
}
.anim-scroll-list::-webkit-scrollbar { width: 6px; }
.anim-scroll-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 99px; }
.anim-item {
  display: block;
  padding: .35rem .7rem;
  border-radius: 5px;
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  color: #fff;
  transition: background .1s;
  white-space: nowrap;
  text-overflow: ellipsis;
  overflow: hidden;
}
.anim-item:hover { background: var(--surface); }
.anim-item.active { background: rgba(249,115,22,.18); color: var(--orange2); font-weight: 700; }
.anim-item.loading { opacity: 0.5; pointer-events: none; }
.anim-item.loading::after { content: " ⏳"; font-size: 12px; }
.anim-item.loaded { color: #ccc; }

/* Source badge (Meshy.AI vs Mixamo) inside each anim list item */
.anim-item { display: flex; align-items: center; gap: .4rem; }
.anim-item-label { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.anim-src-badge {
  flex-shrink: 0;
  font-size: 11px;
  line-height: 1;
  padding: 2px 5px;
  border-radius: 4px;
  font-weight: 700;
  opacity: .85;
}
.anim-src-badge.meshy  { background: rgba(168,85,247,.22); color: #c084fc; }   /* purple */
.anim-src-badge.mixamo { background: rgba(108,99,255,.14); color: #8b86d6; }   /* muted indigo */
/* Source filter tabs get a distinct tint so they read as a different axis */
.anim-cat.anim-cat-src { border-style: dashed; }
.anim-cat.anim-cat-src.active { background: rgba(168,85,247,.18); border-color: #a855f7; color: #c084fc; }

/* Now-playing transport bar */
.anim-transport-bar {
  display: flex; align-items: center; justify-content: space-between;
  padding: .45rem .6rem; background: var(--surface2);
  border: 1px solid var(--border); border-radius: 7px; gap: .5rem;
  flex-shrink: 0;
}
.now-playing { font-size: .9rem; color: var(--accent2); font-weight: 600; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.transport-btns { display: flex; gap: .4rem; flex-shrink: 0; }
.transport-btn {
  width: 28px; height: 28px; border-radius: 6px; font-size: .82rem;
  background: var(--surface); border: 1px solid var(--border);
  color: var(--muted); cursor: pointer; transition: all .15s;
  display: flex; align-items: center; justify-content: center;
}
.transport-btn:hover { border-color: var(--accent2); color: var(--text); }
.transport-btn.active { background: rgba(108,99,255,.25); border-color: var(--accent); color: var(--accent2); }

/* View preset buttons */
.view-btns {
  position: absolute; bottom: 48px; left: 12px;
  display: flex; gap: 4px; z-index: 12;
}
.view-btn {
  background: rgba(0,0,0,.65); color: var(--muted);
  border: 1px solid var(--border); padding: .3rem .65rem;
  border-radius: 6px; font-size: .78rem; cursor: pointer;
  transition: border-color .15s, color .15s, background .15s;
  backdrop-filter: blur(6px);
}
.view-btn:hover { border-color: var(--accent2); color: var(--text); background: rgba(108,99,255,.18); }

/* Background color picker (shared across all 3D viewers) */
.bg-colors {
  position: absolute;
  bottom: 0.7rem; right: 0.7rem;
  display: flex; gap: 4px;
  background: rgba(19,19,26,0.85);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 4px 6px;
  z-index: 10;
}
.bg-dot {
  width: 16px; height: 16px; border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  transition: border-color .2s, transform .15s;
  flex-shrink: 0;
}
.bg-dot:hover { transform: scale(1.2); }
.bg-dot.active { border-color: var(--accent2); box-shadow: 0 0 6px rgba(167,139,250,0.4); }

/* Small button (reset, etc.) */
.btn-sm {
  padding: .4rem .8rem;
  background: var(--surface2); border: 1px solid var(--border);
  color: var(--muted); border-radius: 6px; font-size: .78rem;
  cursor: pointer; transition: all .15s; width: fit-content;
}
.btn-sm:hover { border-color: var(--accent2); color: var(--text); }

/* Animation editor (inside result panel) */
.anim-editor { flex-shrink: 0; }
.anim-editor .adv-body { gap: .4rem; }

/* Timeline editor */
.timeline-editor {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: .6rem .8rem;
  display: flex;
  flex-direction: column;
  gap: .5rem;
  flex-shrink: 0;
}
.timeline-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .5rem;
}
.timeline-header h4 {
  font-size: .78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--muted);
  margin: 0;
}
.timeline-time {
  font-size: .78rem;
  color: var(--accent2);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.timeline-transport {
  display: flex;
  align-items: center;
  gap: .3rem;
}
.tl-btn {
  width: 28px; height: 28px;
  border-radius: 6px;
  font-size: .82rem;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--muted);
  cursor: pointer;
  transition: all .15s;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.tl-btn:hover { border-color: var(--accent2); color: var(--text); }
.tl-btn.active { background: rgba(108,99,255,.25); border-color: var(--accent); color: var(--accent2); }
.timeline-scrub-wrap {
  position: relative;
  height: 32px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
  cursor: pointer;
}
.timeline-ticks {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  pointer-events: none;
}
.timeline-tick {
  position: absolute;
  top: 0; bottom: 0;
  width: 1px;
  background: var(--border);
}
.timeline-tick-label {
  position: absolute;
  top: 1px;
  font-size: 9px;
  color: var(--muted);
  transform: translateX(-50%);
  pointer-events: none;
  user-select: none;
}
.timeline-playhead {
  position: absolute;
  top: 0; bottom: 0;
  width: 2px;
  background: var(--orange);
  box-shadow: 0 0 6px var(--orange);
  z-index: 5;
  pointer-events: none;
  transition: left 0.05s linear;
}
.timeline-progress {
  position: absolute;
  top: 0; left: 0; bottom: 0;
  background: rgba(249,115,22,0.08);
  pointer-events: none;
  z-index: 1;
}
.timeline-keyframes {
  display: flex;
  align-items: center;
  gap: .3rem;
  flex-wrap: wrap;
}
.kf-chip {
  padding: .15rem .5rem;
  font-size: .7rem;
  border-radius: 4px;
  background: rgba(249,115,22,0.15);
  border: 1px solid rgba(249,115,22,0.3);
  color: var(--orange2);
  cursor: pointer;
  transition: all .15s;
  white-space: nowrap;
}
.kf-chip:hover { background: rgba(249,115,22,0.25); }
.kf-chip.active { background: rgba(249,115,22,0.35); border-color: var(--orange); }
.kf-chip .kf-del {
  margin-left: .3rem;
  color: var(--muted);
  cursor: pointer;
}
.kf-chip.has-pose { background: rgba(249,115,22,0.25); border-color: rgba(249,115,22,0.5); }
.kf-chip .kf-del:hover { color: var(--error); }

/* ── Sequence Timeline Editor ────────────────────────────── */
.sequence-editor {
  margin-top: .3rem;
}
.seq-header {
  display: flex;
  align-items: center;
  gap: .5rem;
  flex-wrap: wrap;
}
.seq-mode-btn {
  padding: .25rem .6rem;
  font-size: .75rem;
  font-weight: 600;
  border-radius: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--muted);
  cursor: pointer;
  transition: all .15s;
}
.seq-mode-btn:hover { border-color: var(--accent2); color: var(--text); }
.seq-mode-btn.active {
  background: rgba(108,99,255,.2);
  border-color: var(--accent);
  color: var(--accent2);
}
.seq-duration {
  font-size: .75rem;
  color: var(--accent2);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.seq-transport {
  display: flex;
  align-items: center;
  gap: .3rem;
  margin-left: auto;
}
.seq-export-btn {
  background: rgba(249,115,22,.15);
  border-color: rgba(249,115,22,.3);
  color: var(--orange2);
}
.seq-export-btn:hover { background: rgba(249,115,22,.3); }
.seq-clear-btn {
  background: rgba(239,68,68,.1);
  border-color: rgba(239,68,68,.2);
  color: #f87171;
}
.seq-clear-btn:hover { background: rgba(239,68,68,.2); }
#seqLoop.active { background: rgba(99,102,241,.25); border-color: rgba(99,102,241,.5); color: #a5b4fc; }
.seq-body {
  margin-top: .4rem;
}
.seq-track-wrap {
  position: relative;
  min-height: 44px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
  cursor: pointer;
}
.seq-track {
  display: flex;
  height: 44px;
  align-items: stretch;
}
.seq-clip-block {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 30px;
  padding: 0 6px;
  border-right: 1px solid rgba(255,255,255,.08);
  cursor: grab;
  transition: opacity .15s;
  overflow: hidden;
  user-select: none;
}
.seq-clip-block:active { cursor: grabbing; }
.seq-clip-block:hover { filter: brightness(1.15); }
.seq-clip-block.dragging { opacity: .4; }
.seq-clip-label {
  font-size: .65rem;
  font-weight: 600;
  color: rgba(255,255,255,.9);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-shadow: 0 1px 3px rgba(0,0,0,.5);
  pointer-events: none;
}
.seq-clip-dur {
  position: absolute;
  bottom: 2px;
  right: 4px;
  font-size: .55rem;
  color: rgba(255,255,255,.5);
  pointer-events: none;
}
.seq-clip-remove {
  position: absolute;
  top: 2px;
  right: 3px;
  font-size: .6rem;
  color: rgba(255,255,255,.3);
  cursor: pointer;
  opacity: 0;
  transition: opacity .15s;
}
.seq-clip-block:hover .seq-clip-remove { opacity: 1; }
.seq-clip-remove:hover { color: #f87171; }
.seq-crossfade {
  position: absolute;
  top: 0;
  right: -6px;
  width: 12px;
  height: 100%;
  cursor: ew-resize;
  z-index: 3;
  display: flex;
  align-items: center;
  justify-content: center;
}
.seq-crossfade-diamond {
  width: 8px;
  height: 8px;
  background: var(--orange);
  transform: rotate(45deg);
  border-radius: 1px;
  box-shadow: 0 0 4px rgba(249,115,22,.4);
}
.seq-playhead {
  position: absolute;
  top: 0; bottom: 0;
  width: 2px;
  background: var(--orange);
  box-shadow: 0 0 6px var(--orange);
  z-index: 5;
  pointer-events: none;
  left: 0;
  transition: left 0.05s linear;
}
.seq-drop-hint {
  font-size: .7rem;
  color: var(--muted);
  text-align: center;
  padding: .5rem 0 .2rem;
}
.seq-track-wrap.drag-over {
  border-color: var(--accent);
  background: rgba(108,99,255,.05);
}

/* Bone Adjustment Panel */
.bone-adjust-panel {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  overflow: hidden;
}
.bone-panel-header {
  display: flex;
  align-items: center;
  gap: .5rem;
  padding: .5rem .7rem;
  background: var(--surface2);
  font-size: .82rem;
  font-weight: 600;
  color: var(--accent2);
  cursor: pointer;
  user-select: none;
}
.bone-panel-header:hover { color: var(--text); }
.bone-panel-hint {
  font-size: .68rem;
  font-weight: 400;
  color: var(--muted);
  flex: 1;
}
.bone-search {
  width: calc(100% - .6rem);
  margin: .3rem;
  padding: .4rem .6rem;
  font-size: .75rem;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 5px;
  color: var(--text);
  outline: none;
}
.bone-search:focus { border-color: var(--accent); }
.bone-search::placeholder { color: var(--muted); }
.bone-list {
  max-height: 180px;
  overflow-y: auto;
  padding: .3rem;
}
.bone-list::-webkit-scrollbar { width: 5px; }
.bone-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 99px; }
.bone-item {
  display: flex;
  align-items: center;
  gap: .4rem;
  padding: .3rem .5rem;
  border-radius: 4px;
  font-size: .75rem;
  color: var(--text);
  cursor: pointer;
  transition: background .1s;
}
.bone-item:hover { background: var(--surface2); }
.bone-item.active { background: rgba(108,99,255,.2); color: var(--accent2); font-weight: 600; }
.bone-item .bone-dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--muted); flex-shrink: 0;
}
.bone-item.active .bone-dot { background: var(--accent2); box-shadow: 0 0 4px var(--accent); }
.bone-item.has-offset .bone-dot { background: var(--orange); }
.bone-item.has-offset { color: var(--orange2); }
.bone-selected-label {
  padding: .35rem .7rem;
  font-size: .72rem;
  color: var(--muted);
  background: var(--surface2);
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
}
.bone-section-label {
  font-size: .68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--muted);
  padding-top: .25rem;
}
.bone-transform {
  padding: .5rem .7rem;
  display: flex;
  flex-direction: column;
  gap: .35rem;
}
.bone-transform .adv-row label { font-size: .72rem; }
.bone-transform .adv-row input[type=range] { height: 3px; }
.bone-btn-row {
  display: flex;
  gap: .4rem;
  padding-top: .3rem;
}
.bone-btn-row .btn-sm { flex: 1; text-align: center; }
.btn-bone-reset { color: var(--orange) !important; border-color: rgba(249,115,22,.3) !important; }
.btn-bone-reset:hover { background: rgba(249,115,22,.15) !important; }
.btn-bone-reset-all { color: var(--error) !important; border-color: rgba(248,113,113,.3) !important; }
.btn-bone-reset-all:hover { background: rgba(248,113,113,.15) !important; }

/* Re-Rig Editor */
.rerig-section { margin: .8rem 0; }
.btn-rerig {
  width: 100%; padding: .7rem; border: 2px dashed var(--accent);
  background: rgba(108,99,255,.08); color: var(--accent2);
  border-radius: var(--radius); font-size: .85rem; cursor: pointer;
  transition: all .2s;
}
.btn-rerig:hover { background: rgba(108,99,255,.18); border-color: var(--accent2); }

.rerig-panel {
  background: var(--surface2); border: 1px solid var(--accent);
  border-radius: var(--radius); padding: .8rem; margin-top: .5rem;
}
.rerig-badge {
  display: inline-block; padding: .25rem .6rem;
  background: rgba(108,99,255,.2); color: var(--accent2);
  border-radius: 6px; font-size: .75rem; font-weight: 600;
}
.rerig-hint {
  font-size: .75rem; color: var(--muted); margin: .4rem 0 .6rem;
}
.bone-edit-list {
  max-height: 180px; overflow-y: auto; border: 1px solid var(--border);
  border-radius: 8px; padding: 2px; margin-bottom: .5rem;
}
.bone-edit-list .bone-item {
  padding: .3rem .5rem; font-size: .72rem;
  cursor: pointer; border-radius: 4px; display: flex;
  align-items: center; gap: .3rem;
  transition: background .15s;
}
.bone-edit-list .bone-item:hover { background: rgba(255,255,255,.05); }
.bone-edit-list .bone-item.active { background: rgba(108,99,255,.2); color: #fff; }
.bone-edit-list .bone-item.edited .bone-dot {
  background: var(--success) !important;
  box-shadow: 0 0 6px rgba(52,211,153,.5);
}
.rerig-selected-label {
  font-size: .8rem; color: var(--muted); padding: .3rem 0;
}
.rerig-transform .adv-row { margin-bottom: .3rem; }
.rerig-actions {
  display: flex; flex-direction: column; gap: .4rem; margin-top: .6rem;
}
.btn-rerig-apply {
  background: linear-gradient(135deg, var(--accent), #8b5cf6) !important;
  font-weight: 600;
}
.btn-rerig-apply:hover { filter: brightness(1.15); }

footer { text-align: center; padding: 2rem; border-top: 1px solid var(--border); font-size: .8rem; color: var(--muted); }
footer a { color: var(--accent2); text-decoration: none; }

@media (max-width: 700px) {
  .joints-layout, .result-layout { grid-template-columns: 1fr; grid-template-rows: 60vh auto; }
  .joints-panel, .result-panel { height: auto; overflow-y: visible; }
}

/* ── V2 Feature 4: AI Chat ─────────────────────────────────────────── */
.ai-chat-btn {
  position: fixed; right: 18px; bottom: 18px; z-index: 250;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  color: #fff; border: none; border-radius: 999px;
  padding: 12px 18px; font-size: .9rem; font-weight: 600;
  cursor: pointer; box-shadow: 0 6px 20px rgba(108,99,255,.35);
  transition: transform .15s, filter .15s;
}
.ai-chat-btn:hover { filter: brightness(1.15); transform: translateY(-1px); }

.ai-chat-panel {
  position: fixed; top: 0; right: 0; bottom: 0;
  width: 360px; max-width: 90vw;
  background: var(--surface); border-left: 1px solid var(--border);
  display: none; flex-direction: column; z-index: 260;
  box-shadow: -8px 0 30px rgba(0,0,0,0.4);
}
.ai-chat-panel.open { display: flex; }

.ai-chat-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 14px; border-bottom: 1px solid var(--border);
  background: var(--surface2);
}
.ai-chat-title { font-weight: 700; color: var(--accent2); font-size: .95rem; }
.ai-chat-close {
  background: transparent; color: var(--muted); border: none;
  cursor: pointer; font-size: 1.1rem; padding: 4px 8px; border-radius: 6px;
}
.ai-chat-close:hover { color: var(--text); background: var(--border); }

.ai-chat-selectors {
  display: grid; grid-template-columns: 1fr 1fr; gap: 8px;
  padding: 10px 14px; border-bottom: 1px solid var(--border);
}
.ai-chat-sel {
  background: var(--bg); color: var(--text); border: 1px solid var(--border);
  border-radius: 6px; padding: 6px 8px; font-size: .8rem;
}

.ai-chat-status {
  padding: 6px 14px; font-size: .72rem; color: var(--muted);
  border-bottom: 1px solid var(--border);
}
.ai-chat-status.ok { color: var(--success); }
.ai-chat-status.err { color: var(--error); }

.ai-chat-messages {
  flex: 1; overflow-y: auto; padding: 12px 14px;
  display: flex; flex-direction: column; gap: 10px;
}
.ai-msg { max-width: 90%; padding: 8px 11px; border-radius: 10px;
  font-size: .85rem; line-height: 1.45; white-space: pre-wrap; word-wrap: break-word; }
.ai-msg.user { align-self: flex-end; background: var(--accent); color: #fff; }
.ai-msg.assistant { align-self: flex-start; background: var(--surface2); color: var(--text); border: 1px solid var(--border); }
.ai-msg.error { align-self: stretch; background: rgba(248,113,113,.12); color: var(--error); border: 1px solid rgba(248,113,113,.3); }
.ai-msg.typing { color: var(--muted); font-style: italic; }
.ai-action-btn {
  display: inline-block; margin-top: 6px;
  background: linear-gradient(135deg, var(--orange), var(--orange2));
  color: #fff; border: none; border-radius: 6px;
  padding: 6px 10px; font-size: .78rem; font-weight: 600; cursor: pointer;
}
.ai-action-btn:hover { filter: brightness(1.1); }

.ai-chat-form {
  display: flex; gap: 6px; padding: 10px 12px;
  border-top: 1px solid var(--border); background: var(--surface2);
}
.ai-chat-input {
  flex: 1; resize: none; background: var(--bg); color: var(--text);
  border: 1px solid var(--border); border-radius: 8px;
  padding: 8px 10px; font-family: inherit; font-size: .85rem;
}
.ai-chat-input:focus { outline: none; border-color: var(--accent); }
.ai-chat-send {
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  color: #fff; border: none; border-radius: 8px;
  padding: 0 14px; cursor: pointer; font-size: 1rem; font-weight: 700;
}
.ai-chat-send:hover { filter: brightness(1.15); }
.ai-chat-send:disabled { opacity: .5; cursor: not-allowed; }

@media (max-width: 700px) {
  .ai-chat-panel { width: 100vw; max-width: 100vw; }
}
