:root {
  --bg: #0f1216;
  --bg-2: #161a20;
  --panel: #1a1f26;
  --panel-2: #212731;
  --line: #2b323d;
  --line-2: #38414e;
  --text: #e6e9ee;
  --muted: #8d97a5;
  --accent: #4fb3ff;
  --accent-2: #2a8fe0;
  --accent-bg: rgba(79, 179, 255, .12);
  --ok: #3ccf91;
  --warn: #f5b84b;
  --danger: #ff6170;
  --x: #ff5d6c;
  --y: #5ddc7c;
  --z: #5aa4ff;
  --radius: 8px;
  --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, "SFMono-Regular", Menlo, monospace;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 13px/1.45 var(--font);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
h1, h2, h3, h4 { margin: 0; font-weight: 600; }
.muted { color: var(--muted); }
.mono { font-family: var(--mono); }
.hidden { display: none !important; }
.row { display: flex; align-items: center; gap: 8px; }
.row.wrap { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.stack { display: flex; flex-direction: column; gap: 8px; }

/* ---------- Kontrol ---------- */
button, .btn {
  font: inherit;
  color: var(--text);
  background: var(--panel-2);
  border: 1px solid var(--line-2);
  border-radius: 6px;
  padding: 6px 11px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
  transition: background .12s, border-color .12s;
}
button:hover, .btn:hover { background: #2a313c; border-color: #48525f; }
button:disabled { opacity: .45; cursor: not-allowed; }
button.primary, .btn.primary { background: var(--accent-2); border-color: var(--accent-2); color: #fff; }
button.primary:hover { background: #3a9df0; }
button.danger { color: var(--danger); }
button.danger:hover { background: rgba(255, 97, 112, .12); border-color: var(--danger); }
button.ghost { background: transparent; border-color: transparent; }
button.ghost:hover { background: var(--panel-2); }
button.sm { padding: 3px 8px; font-size: 12px; }
button.icon { padding: 4px 7px; }
button.active, .seg button.active { background: var(--accent-bg); border-color: var(--accent); color: var(--accent); }

input[type=text], input[type=number], input[type=search], select, textarea {
  font: inherit;
  color: var(--text);
  background: var(--bg-2);
  border: 1px solid var(--line-2);
  border-radius: 6px;
  padding: 6px 8px;
  width: 100%;
  min-width: 0;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); }
textarea { resize: vertical; min-height: 64px; }
input[type=color] { width: 34px; height: 26px; padding: 0; border: 1px solid var(--line-2); border-radius: 5px; background: none; cursor: pointer; }
input[type=checkbox] { accent-color: var(--accent); }
input[type=range] { width: 100%; accent-color: var(--accent); height: 16px; margin: 0; }
label.field { display: flex; flex-direction: column; gap: 4px; color: var(--muted); font-size: 12px; }
label.check { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; }

.seg { display: inline-flex; border: 1px solid var(--line-2); border-radius: 7px; overflow: hidden; }
.seg button { border: 0; border-radius: 0; background: transparent; padding: 5px 10px; }
.seg button + button { border-left: 1px solid var(--line-2); }

.chip {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 8px; border-radius: 99px; font-size: 11px;
  background: var(--panel-2); border: 1px solid var(--line-2); color: var(--muted);
}
.chip.ok { color: var(--ok); border-color: rgba(60, 207, 145, .4); }
.chip.warn { color: var(--warn); border-color: rgba(245, 184, 75, .4); }
.kbd { font-family: var(--mono); font-size: 11px; padding: 1px 5px; border: 1px solid var(--line-2); border-bottom-width: 2px; border-radius: 4px; color: var(--muted); }

/* ---------- Toast ---------- */
#toasts { position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 6px; z-index: 100; pointer-events: none; }
.toast { background: #262d38; border: 1px solid var(--line-2); padding: 8px 14px; border-radius: 8px; box-shadow: 0 8px 24px rgba(0,0,0,.4); animation: toastIn .18s ease-out; }
.toast.ok { border-color: rgba(60, 207, 145, .6); }
.toast.err { border-color: rgba(255, 97, 112, .7); }
@keyframes toastIn { from { opacity: 0; transform: translateY(6px); } }

/* ---------- Halaman beranda ---------- */
.home { max-width: 1100px; margin: 0 auto; padding: 32px 20px 60px; }
.home header { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 28px; flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 12px; }
.brand .logo { width: 38px; height: 38px; border-radius: 10px; display: grid; place-items: center; background: linear-gradient(135deg, var(--accent), #7a6bff); font-size: 20px; }
.brand h1 { font-size: 20px; }
.home-grid { display: grid; grid-template-columns: 1.1fr 1fr; gap: 20px; }
@media (max-width: 860px) { .home-grid { grid-template-columns: 1fr; } }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 18px; }
.card h2 { font-size: 15px; margin-bottom: 14px; display: flex; align-items: center; justify-content: space-between; }
.project-list { display: flex; flex-direction: column; gap: 8px; }
.project-item { display: flex; align-items: center; gap: 12px; padding: 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg-2); }
.project-item:hover { border-color: var(--line-2); }
.project-item h3 { font-size: 14px; }
.project-item .meta { font-size: 12px; color: var(--muted); }
.empty { padding: 28px 12px; text-align: center; color: var(--muted); border: 1px dashed var(--line-2); border-radius: 10px; }
.model-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
.model-opt { text-align: left; flex-direction: column; align-items: flex-start; padding: 10px; border-radius: 8px; background: var(--bg-2); }
.model-opt.active { border-color: var(--accent); background: var(--accent-bg); }
.model-opt small { color: var(--muted); }
.preview { position: relative; height: 260px; border-radius: 10px; overflow: hidden; background: #0b0e12; border: 1px solid var(--line); }
.preview canvas { display: block; width: 100%; height: 100%; }
.preview .overlay { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); pointer-events: none; }

/* ---------- Editor ---------- */
.app { display: grid; grid-template-columns: var(--left-w, 340px) 1fr var(--right-w, 340px); grid-template-rows: 48px 1fr; height: 100vh; overflow: hidden; }
.topbar { grid-column: 1 / -1; display: flex; align-items: center; gap: 10px; padding: 0 12px; background: var(--bg-2); border-bottom: 1px solid var(--line); }
.topbar .title { font-weight: 600; font-size: 14px; }
.topbar .sep { width: 1px; height: 22px; background: var(--line); }
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); display: inline-block; }
.status-dot.dirty { background: var(--warn); }

.side { background: var(--panel); border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.side.right { border-right: 0; border-left: 1px solid var(--line); }
.side-head { padding: 10px 12px; border-bottom: 1px solid var(--line); display: flex; flex-direction: column; gap: 8px; }
.side-head h3 { font-size: 13px; display: flex; justify-content: space-between; align-items: center; }
.side-body { flex: 1; overflow-y: auto; min-height: 0; }
.side-body::-webkit-scrollbar { width: 9px; }
.side-body::-webkit-scrollbar-thumb { background: #2f3742; border-radius: 9px; border: 2px solid var(--panel); }

.viewport { position: relative; min-width: 0; min-height: 0; background: #0b0e12; }
.viewport canvas { display: block; width: 100%; height: 100%; outline: none; }
.vp-toolbar { position: absolute; top: 10px; left: 50%; transform: translateX(-50%); display: flex; gap: 6px; align-items: center; background: rgba(22, 26, 32, .88); backdrop-filter: blur(6px); border: 1px solid var(--line); border-radius: 10px; padding: 5px; z-index: 5; flex-wrap: wrap; justify-content: center; max-width: calc(100% - 20px); }
.vp-hint { position: absolute; bottom: 10px; left: 10px; font-size: 11px; color: var(--muted); background: rgba(22, 26, 32, .8); padding: 5px 9px; border-radius: 7px; border: 1px solid var(--line); pointer-events: none; }
.vp-sel { position: absolute; top: 60px; left: 10px; background: rgba(22, 26, 32, .9); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; font-size: 12px; min-width: 190px; z-index: 4; }
.vp-sel b { color: var(--accent); }
.vp-sim { position: absolute; bottom: 14px; left: 50%; transform: translateX(-50%); font-size: 30px; font-weight: 700; letter-spacing: .5px; text-shadow: 0 2px 12px rgba(0,0,0,.7); pointer-events: none; text-align: center; }
.vp-sim small { display: block; font-size: 12px; font-weight: 500; color: var(--muted); }
.vp-loading { position: absolute; inset: 0; display: grid; place-items: center; background: rgba(11, 14, 18, .85); z-index: 10; font-size: 14px; }

/* Panel variabel */
.group { border-bottom: 1px solid var(--line); }
.group-head { display: flex; align-items: center; gap: 6px; padding: 8px 12px; cursor: pointer; user-select: none; font-weight: 600; position: sticky; top: 0; background: var(--panel); z-index: 2; }
.group-head:hover { background: var(--panel-2); }
.group-head .caret { transition: transform .15s; color: var(--muted); font-size: 10px; width: 10px; }
.group.open .group-head .caret { transform: rotate(90deg); }
.group-head .count { margin-left: auto; font-weight: 400; color: var(--muted); font-size: 11px; }
.group-body { display: none; padding: 0 0 6px; }
.group.open .group-body { display: block; }

.bone { margin: 2px 8px; border: 1px solid transparent; border-radius: 7px; }
.bone.changed .bone-name::before { content: ""; display: inline-block; width: 6px; height: 6px; border-radius: 50%; background: var(--warn); margin-right: 6px; vertical-align: 1px; }
.bone.selected { border-color: var(--accent); background: var(--accent-bg); }
.bone-head { display: flex; align-items: center; gap: 6px; padding: 5px 6px; cursor: pointer; border-radius: 6px; }
.bone-head:hover { background: var(--panel-2); }
.bone-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bone-sum { font-family: var(--mono); font-size: 10.5px; color: var(--muted); white-space: nowrap; }
.bone-sum i { font-style: normal; }
.bone-body { display: none; padding: 4px 8px 8px; }
.bone.open .bone-body { display: block; }
.axis { display: grid; grid-template-columns: 34px 1fr 64px; align-items: center; gap: 6px; margin: 3px 0; }
.axis .ax { font-family: var(--mono); font-size: 11px; font-weight: 700; }
.axis .ax.x { color: var(--x); } .axis .ax.y { color: var(--y); } .axis .ax.z { color: var(--z); }
.axis input[type=number] { padding: 2px 5px; font-family: var(--mono); font-size: 11.5px; text-align: right; }
.axis input.x[type=range] { accent-color: var(--x); }
.axis input.y[type=range] { accent-color: var(--y); }
.axis input.z[type=range] { accent-color: var(--z); }
.sub-label { font-size: 10.5px; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); margin: 6px 0 2px; display: flex; justify-content: space-between; }
body.simulating .bone-body input { pointer-events: none; opacity: .7; }

/* Tab kanan */
.tabs { display: flex; border-bottom: 1px solid var(--line); }
.tabs button { flex: 1; border: 0; border-radius: 0; background: transparent; padding: 11px 6px; color: var(--muted); border-bottom: 2px solid transparent; justify-content: center; }
.tabs button.active { color: var(--text); border-bottom-color: var(--accent); background: transparent; }
.tab { display: none; padding: 12px; flex-direction: column; gap: 14px; }
.tab.active { display: flex; }
.section { display: flex; flex-direction: column; gap: 8px; }
.section > h4 { font-size: 11px; text-transform: uppercase; letter-spacing: .7px; color: var(--muted); display: flex; justify-content: space-between; align-items: center; }
.frames { display: flex; flex-wrap: wrap; gap: 6px; }
.frame { min-width: 54px; flex-direction: column; gap: 0; padding: 5px 8px; font-size: 12px; }
.frame small { color: var(--muted); font-size: 10.5px; }
.frame.active small { color: var(--accent); }
.entry-list { display: flex; flex-direction: column; gap: 3px; max-height: 340px; overflow-y: auto; }
.entry { display: flex; align-items: center; gap: 8px; padding: 6px 8px; border-radius: 6px; cursor: pointer; border: 1px solid transparent; }
.entry:hover { background: var(--panel-2); }
.entry.active { border-color: var(--accent); background: var(--accent-bg); }
.entry .lbl { font-weight: 600; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.slider-row { display: grid; grid-template-columns: 96px 1fr 44px; align-items: center; gap: 8px; font-size: 12px; color: var(--muted); }
.slider-row output { font-family: var(--mono); font-size: 11px; text-align: right; color: var(--text); }
.tokens { display: flex; flex-wrap: wrap; gap: 4px; }
.token { padding: 3px 8px; border-radius: 6px; background: var(--bg-2); border: 1px solid var(--line-2); font-weight: 600; font-size: 12px; }
.token.word { border-color: rgba(79, 179, 255, .45); }
.token.missing { color: var(--danger); border-style: dashed; text-decoration: line-through; }
.token.space { opacity: .4; }
.token.current { background: var(--accent-2); border-color: var(--accent-2); color: #fff; }
.token.done { opacity: .55; }
.divider { height: 1px; background: var(--line); margin: 2px 0; }

@media (max-width: 1100px) {
  .app { --left-w: 290px; --right-w: 300px; }
}
@media (max-width: 820px) {
  .app { grid-template-columns: 1fr; grid-template-rows: 48px 50vh auto auto; height: auto; overflow: visible; }
  .viewport { grid-row: 2; }
  .side { max-height: 70vh; border: 0; border-top: 1px solid var(--line); }
}

/* ---------- Mode Marker: pratinjau kamera ---------- */
.cam-pip { position: absolute; right: 12px; bottom: 12px; z-index: 6; background: rgba(16, 19, 24, .94); border: 1px solid var(--line-2); border-radius: 10px; overflow: hidden; box-shadow: 0 10px 30px rgba(0,0,0,.45); width: 360px; max-width: calc(100% - 24px); }
.cam-pip[data-size="s"] { width: 240px; }
.cam-pip[data-size="l"] { width: 560px; }
.cam-head { display: flex; align-items: center; gap: 8px; padding: 4px 6px 4px 10px; font-size: 11.5px; border-bottom: 1px solid var(--line); }
.cam-view { position: relative; aspect-ratio: 16 / 9; background: #000; }
.cam-view video, .cam-view canvas { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; }
.cam-view.mirror video, .cam-view.mirror canvas { transform: scaleX(-1); }
.cam-empty { position: absolute; inset: 0; display: grid; place-items: center; text-align: center; padding: 16px; color: var(--muted); font-size: 12px; }
.rec-dot { color: var(--danger); font-weight: 700; animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity: .35; } }
.countdown { position: absolute; inset: 0; display: grid; place-items: center; font-size: 140px; font-weight: 800; color: #fff; text-shadow: 0 6px 40px rgba(0,0,0,.7); pointer-events: none; z-index: 8; }
.chip.on { color: var(--ok); border-color: rgba(60, 207, 145, .55); background: rgba(60, 207, 145, .08); }
details > summary { list-style: revert; }
