:root {
  --bg: #09090b;
  --card-bg: rgba(20, 20, 25, 0.6);
  --border: rgba(255, 255, 255, 0.08);
  --primary: hsl(250, 100%, 65%);
  --primary-hover: hsl(250, 100%, 75%);
  --accent: hsl(320, 100%, 60%);
  --text: #f4f4f5;
  --text-muted: #a1a1aa;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
body {
  background-color: var(--bg); color: var(--text); font-family: 'Outfit', sans-serif;
  height: 100vh; overflow: hidden; display: flex; flex-direction: column;
}
.glow, .glow-right { position: absolute; z-index: 0; pointer-events: none; }
.glow { width: 500px; height: 500px; background: radial-gradient(circle, rgba(99,102,241,0.15) 0%, transparent 70%); top: -10%; left: -10%; }
.glow-right { width: 600px; height: 600px; background: radial-gradient(circle, rgba(236,72,153,0.1) 0%, transparent 70%); bottom: -20%; right: -10%; }

header {
  padding: 1.1rem 2rem; border-bottom: 1px solid var(--border); display: flex; align-items: center;
  justify-content: space-between; z-index: 10; background: rgba(9,9,11,0.5); backdrop-filter: blur(8px);
}
header h1 {
  font-size: 1.4rem; font-weight: 800; letter-spacing: 0.5px;
  background: linear-gradient(135deg, #fff 30%, var(--primary) 120%);
  -webkit-background-clip: text; -webkit-text-fill-color: transparent;
}
header .meta { display: flex; gap: 0.6rem; align-items: center; }
.badge {
  padding: 0.25rem 0.6rem; border-radius: 9999px; font-size: 0.72rem; font-weight: 600;
  background: rgba(255,255,255,0.05); border: 1px solid var(--border);
}
.badge.active { background: rgba(99,102,241,0.2); border-color: var(--primary); color: #a5b4fc; }
.badge.type { background: rgba(236,72,153,0.15); border-color: var(--accent); color: #f9a8d4; }

.workspace {
  flex: 1; display: grid; grid-template-columns: 340px 1fr 420px; grid-template-rows: 1fr; gap: 1px;
  background: var(--border); z-index: 5; overflow: hidden; min-height: 0;
}
.sidebar, .editor-container { background: rgba(12,12,16,0.95); padding: 1.4rem; display: flex; flex-direction: column; gap: 1.3rem; overflow-y: auto; min-height: 0; }
.sidebar-title { font-size: 0.82rem; text-transform: uppercase; letter-spacing: 1px; color: var(--text-muted); font-weight: 600; }
.card { background: var(--card-bg); border: 1px solid var(--border); border-radius: 12px; padding: 1rem; display: flex; flex-direction: column; gap: 0.8rem; }

.dropzone {
  border: 2px dashed rgba(255,255,255,0.15); border-radius: 12px; padding: 1.6rem 1rem; text-align: center;
  cursor: pointer; transition: all 0.2s ease; background: rgba(255,255,255,0.02);
}
.dropzone:hover, .dropzone.dragover { border-color: var(--primary); background: rgba(99,102,241,0.05); }
.dropzone p { font-size: 0.82rem; color: var(--text-muted); margin-top: 0.4rem; }
.muted-note { font-size: 0.78rem; color: var(--text-muted); line-height: 1.5; }
.muted-note code { color: #a7f3d0; font-family: 'JetBrains Mono', monospace; font-size: 0.74rem; }

/* T-Pose panel */
.poses-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 0.6rem; }
.pose-card {
  position: relative; border: 1px solid var(--border); border-radius: 10px; padding: 0.5rem;
  background: rgba(255,255,255,0.02); cursor: pointer; transition: all 0.15s ease; display: flex; flex-direction: column; gap: 0.4rem;
}
.pose-card:hover { border-color: rgba(255,255,255,0.25); }
.pose-card.pose-focus { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.pose-card.pose-off { opacity: 0.4; }
.pose-thumb {
  aspect-ratio: 1; border-radius: 6px; background: radial-gradient(circle at center, #1c1c22, #0d0d10);
  display: flex; align-items: center; justify-content: center; font-weight: 800; color: var(--text-muted); overflow: hidden;
}
.pose-thumb img { width: 100%; height: 100%; object-fit: contain; image-rendering: pixelated; }
.pose-meta { display: flex; flex-direction: column; }
.pose-name { font-size: 0.78rem; font-weight: 600; }
.pose-sub { font-size: 0.66rem; color: var(--text-muted); }
.pose-toggle { position: absolute; top: 0.4rem; right: 0.4rem; }
.pose-toggle input { accent-color: var(--accent); cursor: pointer; }

.btn {
  background: rgba(255,255,255,0.05); border: 1px solid var(--border); color: var(--text);
  padding: 0.55rem 0.9rem; border-radius: 8px; font-size: 0.82rem; font-weight: 600; cursor: pointer;
  transition: all 0.15s ease; display: flex; align-items: center; justify-content: center; gap: 0.5rem;
}
.btn:hover { background: rgba(255,255,255,0.1); border-color: rgba(255,255,255,0.25); }
.btn.primary { background: var(--primary); border-color: var(--primary); }
.btn.primary:hover { background: var(--primary-hover); }
.btn.busy { opacity: 0.6; pointer-events: none; }
.unit-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 0.4rem; }
.unit-btn { font-size: 0.68rem; padding: 0.35rem 0.5rem; }
.unit-btn.active { background: rgba(99,102,241,0.25); border-color: var(--primary); color: #c7d2fe; }
.unit-btn.dimmed { opacity: 0.3; }

.control-group { display: flex; flex-direction: column; gap: 0.45rem; }
.control-group label { font-size: 0.72rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.5px; }
.seg { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0.3rem; }
.seg .btn { padding: 0.4rem 0.3rem; font-size: 0.72rem; }
.seg .btn.active { background: var(--primary); border-color: var(--primary); }
select, .editor-textarea { font-family: 'JetBrains Mono', monospace; }
select {
  width: 100%; background: rgba(0,0,0,0.3); border: 1px solid var(--border); color: var(--text);
  padding: 0.4rem 0.5rem; border-radius: 8px; font-size: 0.76rem;
}
.slider { -webkit-appearance: none; width: 100%; height: 6px; background: rgba(255,255,255,0.1); border-radius: 3px; outline: none; }
.slider::-webkit-slider-thumb { -webkit-appearance: none; width: 16px; height: 16px; border-radius: 50%; background: var(--primary); cursor: pointer; }

kbd {
  text-align: center; padding: 6px; border: 1px solid var(--border); border-radius: 4px;
  font-family: 'JetBrains Mono'; font-size: 0.75rem; background: rgba(255,255,255,0.03); transition: all 0.12s;
}
kbd.key-active { background: rgba(99,102,241,0.4); border-color: var(--primary); }

.viewport-container { background: radial-gradient(circle at center, #18181b 0%, #09090b 100%); display: flex; align-items: center; justify-content: center; position: relative; overflow: hidden; }
.viewport-grid { position: absolute; width: 100%; height: 100%; background-image: radial-gradient(var(--border) 1px, transparent 1px); background-size: 24px 24px; pointer-events: none; }
.fsm-status { position: absolute; top: 1.5rem; left: 1.5rem; display: flex; align-items: center; gap: 0.5rem; background: rgba(9,9,11,0.8); border: 1px solid var(--border); padding: 0.5rem 1rem; border-radius: 8px; backdrop-filter: blur(8px); }
.status-dot { width: 8px; height: 8px; background: #10b981; border-radius: 50%; box-shadow: 0 0 8px #10b981; animation: pulse 1.5s infinite; }
@keyframes pulse { 0%,100% { opacity: 0.5; } 50% { opacity: 1; } }
#canvas-container { position: relative; width: 100%; height: 100%; }
#crosshair { position: absolute; top: 50%; left: 50%; width: 20px; height: 20px; pointer-events: none; transform: translate(-50%, -50%); display: none !important; }
#crosshair::before, #crosshair::after { content: ''; position: absolute; background: var(--accent); opacity: 0.7; }
#crosshair::before { top: 9px; left: 0; width: 20px; height: 2px; }
#crosshair::after { top: 0; left: 9px; width: 2px; height: 20px; }

/* Frame inspector bar */
.frame-bar {
  position: absolute; bottom: 1rem; left: 50%; transform: translateX(-50%);
  display: flex; flex-direction: column; gap: 0.8rem; width: 85%; max-width: 900px;
  background: rgba(9,9,11,0.9); border: 1px solid var(--border);
  padding: 0.8rem; border-radius: 12px; backdrop-filter: blur(16px);
  z-index: 20; user-select: none; box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
}
.frame-bar-controls {
  display: flex; align-items: center; justify-content: center; gap: 0.6rem; width: 100%;
}
.frame-bar button {
  background: rgba(255,255,255,0.06); border: 1px solid var(--border);
  color: var(--text); border-radius: 6px; width: 32px; height: 32px;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; font-size: 1rem; transition: all 0.12s;
}
.frame-bar button:hover { background: rgba(99,102,241,0.25); border-color: var(--primary); }
.frame-bar button.active { background: rgba(99,102,241,0.35); border-color: var(--primary); color: #c7d2fe; }
.frame-bar .frame-label {
  font-size: 0.75rem; font-family: 'Outfit', sans-serif;
  color: var(--text-muted); min-width: 5rem; text-align: center;
}
.frame-bar .frame-label strong { color: #fff; }
#frame-regen { width: auto !important; padding: 0 0.7rem; font-size: 0.72rem !important; font-weight: 600; gap: 0.3rem; }
#frame-regen.copied { background: rgba(16,185,129,0.3) !important; border-color: #10b981 !important; color: #6ee7b7; }

/* Timeline styles */
.timeline-container {
  width: 100%; display: flex; overflow-x: auto; gap: 0.5rem; padding: 0.2rem 0;
  scrollbar-width: thin; scrollbar-color: var(--primary) transparent;
  border-top: 1px solid rgba(255, 255, 255, 0.08); padding-top: 0.8rem;
}
.timeline-frame {
  flex: 0 0 auto; display: flex; flex-direction: column; align-items: center; gap: 0.3rem;
  padding: 0.4rem 0.6rem; border: 1px solid var(--border); border-radius: 8px; background: rgba(255,255,255,0.02);
  cursor: pointer; transition: all 0.15s ease; min-width: 75px;
}
.timeline-frame:hover {
  background: rgba(255, 255, 255, 0.06); border-color: rgba(255, 255, 255, 0.2);
}
.timeline-frame.active {
  background: rgba(99, 102, 241, 0.15); border-color: var(--primary);
  box-shadow: 0 0 12px rgba(99, 102, 241, 0.4);
}
.timeline-frame-num {
  font-size: 0.68rem; font-family: 'JetBrains Mono', monospace; font-weight: 600; color: var(--text-muted);
}
.timeline-frame.active .timeline-frame-num {
  color: #fff;
}
.timeline-frame-dur {
  width: 58px; font-size: 0.68rem; font-family: 'JetBrains Mono', monospace;
  background: rgba(0,0,0,0.4); border: 1px solid var(--border); border-radius: 4px;
  color: #a7f3d0; text-align: center; padding: 2px 4px; outline: none; transition: border-color 0.15s;
}
.timeline-frame-dur:focus {
  border-color: var(--primary);
}

.editor-textarea {
  flex: 1; width: 100%; min-height: 320px; background: rgba(0,0,0,0.3); border: 1px solid var(--border);
  border-radius: 8px; padding: 1rem; color: #a7f3d0; font-size: 0.78rem; line-height: 1.4; resize: none; outline: none; transition: all 0.2s ease;
}
.editor-textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 1px var(--primary); }
.editor-textarea.json-invalid { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.anchor-input { width: 100%; background: rgba(0,0,0,0.3); border: 1px solid var(--border); color: var(--text); padding: 0.35rem 0.5rem; border-radius: 6px; font-size: 0.76rem; font-family: 'JetBrains Mono', monospace; }
.anchor-input:focus { border-color: var(--primary); outline: none; }
.toolbar { display: flex; gap: 0.5rem; }
.toolbar .btn { flex: 1; }


/* Lucide Icons */
.icon-sm { width: 14px; height: 14px; margin-right: 4px; vertical-align: -2px; }
.icon-md { width: 18px; height: 18px; vertical-align: middle; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 4px; }
.btn .icon-sm, .btn .icon-md { margin-right: 0; vertical-align: baseline; }
