:root {
  --bg: #15181d;
  --panel: #1d2128;
  --panel-2: #242933;
  --line: #313845;
  --text: #dfe4ec;
  --muted: #8a94a5;
  --accent: #4b8df8;
  --accent-2: #2f6fd8;
  --sel: #2b4a7e;
  --warn: #f2b84b;
  --err: #f0625d;
  --ok: #4fc58a;
  --proxied: #c38cff;
  --radius: 6px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, "Cascadia Code", Consolas, monospace;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font: 13px/1.4 var(--font); overflow: hidden; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.muted { color: var(--muted); }
.mono { font-family: var(--mono); }
kbd { font: 11px var(--mono); background: var(--panel-2); border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 4px; padding: 0 4px; }
code { font: 12px var(--mono); background: var(--panel-2); border-radius: 4px; padding: 1px 4px; }
.fatal { padding: 24px; color: var(--err); }

#app { display: grid; grid-template-columns: 340px 1fr; grid-template-rows: 36px 1fr; height: 100vh; height: 100dvh; }
#menubar { grid-column: 1 / -1; display: flex; align-items: center; gap: 12px; padding: 0 10px; background: var(--panel); border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: baseline; gap: 4px; margin-right: 8px; }
.logo { font-weight: 800; letter-spacing: .5px; color: #fff; background: var(--accent); padding: 1px 6px; border-radius: 4px; }
.menubar-items { display: flex; gap: 2px; }
.menubar-btn { background: none; border: 0; padding: 5px 10px; border-radius: var(--radius); cursor: pointer; }
.menubar-btn:hover, .menubar-btn:focus-visible { background: var(--panel-2); }

#sidebar { grid-column: 1; grid-row: 2; display: flex; flex-direction: column; background: var(--panel); border-right: 1px solid var(--line); min-height: 0; }
#tree-panel { flex: 0 0 42%; display: flex; flex-direction: column; min-height: 80px; }
.panel-title { display: flex; align-items: center; justify-content: space-between; padding: 6px 8px 6px 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; font-size: 11px; letter-spacing: .6px; }
#tree { flex: 1; overflow: auto; padding-bottom: 12px; }
#splitter { height: 5px; cursor: row-resize; background: var(--line); flex: none; }
#splitter:hover { background: var(--accent); }
#props-panel { flex: 1; overflow: auto; min-height: 0; }

.tree-row { display: flex; align-items: center; gap: 5px; height: 26px; padding-right: 6px; cursor: default; user-select: none; border: 1px solid transparent; white-space: nowrap; }
.tree-row:hover { background: var(--panel-2); }
.tree-row.selected { background: var(--sel); }
.tree-row.is-hidden .name, .tree-row.is-hidden .icon { opacity: .45; }
.tree-row.by-event .name { font-style: italic; }
.tree-row .twisty { width: 12px; flex: none; color: var(--muted); text-align: center; cursor: pointer; }
.tree-row .icon { width: 18px; flex: none; text-align: center; }
.tree-row .name { overflow: hidden; text-overflow: ellipsis; }
.tree-row .cls { color: var(--muted); font-size: 11px; }
.tree-row .state { margin-left: auto; color: var(--warn); font-size: 11px; }
.tree-row .eye { flex: none; background: none; border: 0; color: var(--muted); cursor: pointer; width: 20px; padding: 0; }
.tree-row .eye:hover { color: var(--text); }
.tree-row.drop-into { border-color: var(--accent); background: rgba(75,141,248,.15); }
.tree-row.drop-before { border-top-color: var(--accent); }
.tree-row.drop-after { border-bottom-color: var(--accent); }
.tree-row input.rename { flex: 1; min-width: 0; background: var(--bg); border: 1px solid var(--accent); border-radius: 3px; padding: 1px 4px; }
.tree-empty { padding: 16px; color: var(--muted); }

.props-empty { padding: 16px; }
.props-head { padding: 10px 12px; border-bottom: 1px solid var(--line); }
.props-title { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 15px; }
.props-title .icon-btn { margin-left: auto; }
.props-desc { margin: 4px 0 0; color: var(--muted); }
.part-status { margin-top: 6px; padding: 4px 8px; border-radius: 4px; background: rgba(242,184,75,.12); color: var(--warn); font-size: 12px; word-break: break-word; }
.part-status[hidden] { display: none; }
.group { border-bottom: 1px solid var(--line); }
.group-title { width: 100%; text-align: left; background: none; border: 0; padding: 6px 12px; color: var(--muted); text-transform: uppercase; font-size: 11px; letter-spacing: .6px; font-weight: 600; cursor: pointer; }
.group-title:hover { color: var(--text); }
.group.collapsed .group-body { display: none; }
.group-body { padding: 2px 12px 8px; display: grid; gap: 4px; }
.prop { display: grid; grid-template-columns: 118px 1fr; align-items: center; gap: 8px; min-height: 26px; }
.prop-text, .prop-expression { align-items: start; }
.prop-label { color: #b9c2d0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.prop-label.scrub, .axis.scrub { cursor: ew-resize; }
.prop-label.proxied { color: var(--proxied); }
.prop-label.proxied::after { content: " ƒ"; }
.field { width: 100%; min-width: 0; background: var(--bg); border: 1px solid var(--line); border-radius: 4px; padding: 3px 6px; }
.field:focus { border-color: var(--accent); outline: none; }
textarea.field { resize: vertical; }
select.field { padding: 2px 4px; }
.vec { display: grid; grid-template-columns: auto 1fr auto 1fr auto 1fr; gap: 3px; align-items: center; }
.axis { font-size: 10px; font-weight: 700; padding: 0 2px; user-select: none; }
.axis-0 { color: #ef6b6b; } .axis-1 { color: #6bd47a; } .axis-2 { color: #6ba3ef; }
.num { font-family: var(--mono); font-size: 12px; }
.color-row { display: flex; align-items: center; gap: 8px; }
input[type=color] { width: 44px; height: 24px; padding: 0; border: 1px solid var(--line); border-radius: 4px; background: none; cursor: pointer; }
input[type=checkbox] { width: 16px; height: 16px; accent-color: var(--accent); justify-self: start; }
.choice { display: flex; gap: 4px; min-width: 0; }
.choice .field { flex: 1; }
.stack { display: grid; gap: 4px; }
.expr-tools { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.proxy-out { color: var(--proxied); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.link-btn { background: none; border: 0; color: var(--accent); cursor: pointer; padding: 0; font-size: 12px; }
.icon-btn { background: none; border: 1px solid transparent; border-radius: 4px; cursor: pointer; padding: 1px 6px; color: var(--muted); }
.icon-btn:hover { color: var(--text); border-color: var(--line); background: var(--panel-2); }

#viewport { grid-column: 2; grid-row: 2; position: relative; min-width: 0; min-height: 0; background: #000; }
#canvas { display: block; width: 100%; height: 100%; touch-action: none; outline: none; }
#vp-toolbar { position: absolute; top: 8px; left: 8px; right: 8px; display: flex; gap: 8px; flex-wrap: wrap; pointer-events: none; }
.tb-group { display: flex; gap: 2px; padding: 3px; background: rgba(20,24,30,.82); border: 1px solid var(--line); border-radius: 8px; pointer-events: auto; backdrop-filter: blur(6px); }
.tb-group:last-child { margin-left: auto; }
.tb-btn { min-width: 30px; height: 28px; background: none; border: 0; border-radius: 6px; cursor: pointer; font-size: 15px; }
.tb-btn:hover { background: var(--panel-2); }
.tb-btn.active { background: var(--accent-2); color: #fff; }
.tb-btn.play { padding: 0 12px; font-size: 13px; font-weight: 600; background: var(--accent); color: #fff; }
.tb-btn.play:hover { background: var(--accent-2); }
.tb-select { background: var(--panel-2); border: 1px solid var(--line); border-radius: 6px; padding: 0 4px; height: 28px; }
.bone-label { position: absolute; pointer-events: none; background: rgba(0,0,0,.8); padding: 2px 6px; border-radius: 4px; font-size: 12px; }

.menu { min-width: 190px; background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 4px; box-shadow: 0 10px 30px rgba(0,0,0,.45); z-index: 1000; }
.menu.floating { position: fixed; }
.menu.submenu { position: absolute; left: 100%; top: -5px; }
.menu.submenu.left { left: auto; right: 100%; }
.menu-item { position: relative; display: grid; grid-template-columns: 22px 1fr auto; align-items: center; gap: 6px; width: 100%; padding: 5px 8px; background: none; border: 0; border-radius: 5px; text-align: left; cursor: pointer; }
.menu-item:hover, .menu-item:focus-visible { background: var(--accent-2); color: #fff; outline: none; }
.menu-item[disabled] { opacity: .4; cursor: default; background: none; }
.menu-short { color: var(--muted); font-size: 11px; }
.menu-item:hover .menu-short { color: #dce7ff; }
.menu-sep { height: 1px; background: var(--line); margin: 4px 6px; }

.overlay { position: fixed; inset: 0; background: rgba(0,0,0,.55); display: grid; place-items: center; z-index: 2000; padding: 16px; }
.modal { width: min(620px, 100%); max-height: min(80vh, 760px); display: flex; flex-direction: column; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 20px 60px rgba(0,0,0,.5); }
.modal-title { display: flex; justify-content: space-between; align-items: center; padding: 10px 14px; font-weight: 700; border-bottom: 1px solid var(--line); }
.modal-body { padding: 12px 14px; overflow: auto; }
.modal-buttons { display: flex; justify-content: flex-end; gap: 8px; padding: 10px 14px; border-top: 1px solid var(--line); }
.btn { background: var(--panel-2); border: 1px solid var(--line); border-radius: 6px; padding: 5px 12px; cursor: pointer; }
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.span2 { grid-column: 1 / -1; }
.save-list { display: grid; gap: 6px; }
.save-row { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 8px; border: 1px solid var(--line); border-radius: 6px; }
.row-btns { display: flex; gap: 6px; }
.ref h3 { margin: 14px 0 6px; font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; }
.ref details { border-bottom: 1px solid var(--line); padding: 4px 0; }
.ref summary { cursor: pointer; }
.ref dl { display: grid; grid-template-columns: 150px 1fr; gap: 2px 10px; margin: 6px 0 6px 18px; font-size: 12px; }
.ref dt { font-family: var(--mono); color: #b9c2d0; }
.ref dd { margin: 0; color: var(--muted); }
.ref a { color: var(--accent); }
.chips { display: flex; flex-wrap: wrap; gap: 4px; }
.keys td { padding: 2px 12px 2px 0; }

.toasts { position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%); display: grid; gap: 6px; z-index: 3000; width: min(560px, calc(100vw - 32px)); }
.toast { background: var(--panel-2); border: 1px solid var(--line); border-left: 4px solid var(--accent); border-radius: 6px; padding: 8px 12px; box-shadow: 0 8px 24px rgba(0,0,0,.4); transition: opacity .3s; }
.toast.ok { border-left-color: var(--ok); } .toast.warn { border-left-color: var(--warn); } .toast.error { border-left-color: var(--err); }
.toast.out { opacity: 0; }

/* play mode */
#hud { position: absolute; inset: 0; pointer-events: none; display: none; }
body.playing #hud { display: block; }
body.playing #app { grid-template-columns: 0 1fr; }
body.playing #sidebar, body.playing #vp-toolbar { display: none; }
.crosshair { position: absolute; left: 50%; top: 50%; width: 6px; height: 6px; margin: -3px; border-radius: 50%; background: rgba(255,255,255,.85); box-shadow: 0 0 0 1px rgba(0,0,0,.6); }
.play-hint { position: absolute; top: 10px; left: 50%; transform: translateX(-50%); background: rgba(0,0,0,.6); padding: 4px 12px; border-radius: 6px; font-size: 12px; white-space: nowrap; max-width: calc(100% - 20px); overflow: hidden; text-overflow: ellipsis; }
.exit-play { position: absolute; top: 8px; right: 8px; pointer-events: auto; }
.hud-health { position: absolute; left: 16px; bottom: 16px; font-size: 22px; font-weight: 800; text-shadow: 0 2px 4px rgba(0,0,0,.7); }
.event-bar { position: absolute; right: 12px; bottom: 16px; display: grid; gap: 4px; pointer-events: auto; }
.ev-btn { background: rgba(0,0,0,.6); border: 1px solid var(--line); border-radius: 6px; padding: 4px 10px; text-align: left; cursor: pointer; }
.ev-btn.on { background: var(--accent-2); border-color: var(--accent); }
.chat-log { position: absolute; left: 16px; bottom: 90px; width: min(420px, 60%); display: grid; gap: 2px; font-size: 13px; text-shadow: 0 1px 3px #000; }
.chat-input { position: absolute; left: 16px; bottom: 56px; width: min(420px, calc(100% - 32px)); pointer-events: auto; background: rgba(0,0,0,.75); border: 1px solid var(--accent); border-radius: 6px; padding: 6px 10px; }
.bubble { position: absolute; transform: translate(-50%, -100%); background: #fff; color: #111; padding: 6px 10px; border-radius: 10px; max-width: 260px; font-weight: 600; box-shadow: 0 4px 12px rgba(0,0,0,.35); }

@media (max-width: 800px) {
  #app { grid-template-columns: 1fr; grid-template-rows: 36px 55% 1fr; }
  #sidebar { grid-column: 1; grid-row: 3; border-right: 0; border-top: 1px solid var(--line); }
  #viewport { grid-row: 2; grid-column: 1; }
  #menubar { gap: 4px; padding: 0 6px; overflow-x: auto; }
  .brand .muted { display: none; }
  .menubar-btn { padding: 5px 7px; }
  .prop { grid-template-columns: 96px 1fr; }
  body.playing #app { grid-template-rows: 36px 1fr 0; }
  .tb-group:last-child { margin-left: 0; }
}
