:root {
  --bg: #0f1115;
  --panel: #161920;
  --panel-2: #1c2029;
  --line: #262b35;
  --text: #e6e8ee;
  --dim: #8b93a3;
  --accent: #f59e42;
  --agent: #8ea2ff;
  --ok: #4cc38a;
  --warn: #e5b94b;
  --err: #f06a6a;
  --radius: 8px;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--text); overflow: hidden;
  font: 13px/1.45 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  display: grid; grid-template-rows: 48px 1fr;
}
button, input, select, textarea { font: inherit; color: inherit; }
.muted { color: var(--dim); font-weight: 400; }
.small { font-size: 12px; }

/* ---- top bar */
.topbar {
  display: flex; align-items: center; gap: 14px; padding: 0 12px;
  border-bottom: 1px solid var(--line); background: var(--panel);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 650; letter-spacing: .02em; }
.brand svg { width: 22px; height: 22px; }
.status { display: flex; align-items: center; gap: 6px; color: var(--dim); font-size: 12px; white-space: nowrap; }
.status i { width: 8px; height: 8px; border-radius: 50%; background: var(--warn); }
.status.live i { background: var(--ok); box-shadow: 0 0 0 3px color-mix(in srgb, var(--ok) 25%, transparent); }
.status.local i { background: var(--dim); }
.tools { display: flex; align-items: center; gap: 6px; flex: 1; min-width: 0; }
.sep { width: 1px; height: 22px; background: var(--line); margin: 0 4px; }

.btn {
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 6px;
  padding: 5px 10px; cursor: pointer; white-space: nowrap;
}
.btn:hover { border-color: #3a404d; }
.btn.icon { padding: 5px 8px; line-height: 1; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #1a1206; font-weight: 600; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--err); }
select {
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 6px; padding: 4px 6px;
}
.toggle { display: flex; align-items: center; gap: 5px; color: var(--dim); cursor: pointer; }
.btn.fx { color: var(--dim); }
.btn.fx.on { color: #111; background: var(--accent); border-color: var(--accent); }
.btn.fx[hidden] { display: none; }
input[type=checkbox], input[type=range] { accent-color: var(--accent); }

.menu { position: relative; }
.dropdown {
  position: absolute; top: calc(100% + 6px); left: 0; z-index: 20; min-width: 200px;
  background: var(--panel-2); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 4px; box-shadow: 0 12px 30px rgba(0,0,0,.45);
}
.dropdown button {
  display: flex; justify-content: space-between; gap: 16px; width: 100%; text-align: left;
  background: none; border: 0; padding: 6px 10px; border-radius: 5px; cursor: pointer;
}
.dropdown button:hover { background: var(--line); }
.dropdown button span { color: var(--dim); font-size: 12px; }
.menu-sep { border: 0; border-top: 1px solid var(--line); margin: 4px 2px; }
.gallery-list li.new span:last-child { color: var(--accent); }
.card.new .thumb { width: 100%; aspect-ratio: 16 / 10; display: grid; place-content: center; font-size: 34px; color: var(--dim); }
.card.new .thumb.t-empty { background: repeating-conic-gradient(#2a2e36 0 25%, #20232a 0 50%) 0 0 / 28px 28px; }
.card.new .thumb.t-studio { background: radial-gradient(ellipse at 50% 85%, #3a3f4a 0 28%, #1b1f27 29% 45%, #0a0b0e 75%); }

/* ---- layout */
.layout { display: grid; grid-template-columns: 230px 1fr 310px; min-height: 0; }
.panel { background: var(--panel); display: flex; flex-direction: column; min-height: 0; overflow: hidden; }
.panel.left { border-right: 1px solid var(--line); }
.panel.right { border-left: 1px solid var(--line); }
.panel section { padding: 12px; border-bottom: 1px solid var(--line); }
.panel h2 {
  margin: 0 0 8px; font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--dim);
  display: flex; align-items: center; gap: 6px;
}
.left section:first-child { flex: 1; overflow: auto; }

.outliner { list-style: none; margin: 0; padding: 0; }
.outliner li {
  display: flex; align-items: center; gap: 8px; padding: 5px 8px; border-radius: 6px; cursor: pointer;
}
.outliner li:hover { background: var(--panel-2); }
.outliner li.sel { background: color-mix(in srgb, var(--accent) 18%, transparent); }
.outliner .swatch { width: 10px; height: 10px; border-radius: 3px; flex: none; }
.outliner .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.outliner .type { color: var(--dim); font-size: 11px; }
.outliner .eye { background: none; border: 0; color: var(--dim); cursor: pointer; padding: 0 2px; }
.outliner li.off .name { color: var(--dim); text-decoration: line-through; }
.outliner .none { color: var(--dim); cursor: default; }
.gallery-side { flex: 0 0 auto; max-height: 46%; overflow: auto; }
.link { background: none; border: 0; color: var(--accent); cursor: pointer; padding: 0; margin-left: auto; font-size: 11px; text-transform: none; letter-spacing: 0; }
.gallery-list { list-style: none; margin: 0; padding: 0; }
.gallery-list li { display: flex; justify-content: space-between; gap: 8px; padding: 5px 8px; border-radius: 6px; cursor: pointer; }
.gallery-list li:hover { background: var(--panel-2); }
.gallery-list li span:last-child { color: var(--dim); font: 11px var(--mono); }
.dialog.wide { width: min(1080px, calc(100vw - 32px)); }
.gallery-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 12px; margin-top: 12px; }
.card { background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px; overflow: hidden; cursor: pointer; text-align: left; padding: 0; display: flex; flex-direction: column; }
.card:hover { border-color: var(--accent); }
.card img { width: 100%; aspect-ratio: 16 / 10; object-fit: cover; display: block; background: #000; }
.card .body { padding: 10px 12px 12px; display: grid; gap: 4px; }
.card h3 { margin: 0; font-size: 14px; }
.card p { margin: 0; color: var(--dim); font-size: 12px; line-height: 1.4; }
.card .stats { display: flex; flex-wrap: wrap; gap: 4px 10px; font: 11px var(--mono); color: var(--dim); margin-top: 4px; }
.card .stats b { color: var(--text); font-weight: 600; }

/* ---- viewport */
.viewport { position: relative; min-width: 0; min-height: 0; background: #000; }
#viewport { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; cursor: grab; }
#viewport:active { cursor: grabbing; }
.vstats, .vhint {
  position: absolute; left: 10px; font: 11px/1.4 var(--mono); color: rgba(255,255,255,.75);
  background: rgba(10,12,16,.55); padding: 3px 7px; border-radius: 5px; pointer-events: none;
}
.vstats { bottom: 10px; white-space: pre; }
.timeline {
  position: absolute; right: 10px; bottom: 10px; display: flex; align-items: center; gap: 8px; padding: 5px 10px;
  background: rgba(10, 12, 16, 0.7); border: 1px solid var(--line); border-radius: 8px; backdrop-filter: blur(6px);
}
.timeline .track { position: relative; display: flex; }
.timeline input { width: 220px; accent-color: var(--accent); }
.keymarks { position: absolute; left: 8px; right: 8px; top: -7px; height: 8px; pointer-events: none; }
.keymarks i { position: absolute; width: 7px; height: 7px; margin-left: -3.5px; transform: rotate(45deg); background: #ffc98a; pointer-events: auto; cursor: pointer; border: 1px solid rgba(0,0,0,.5); }
.keymarks i.cam { background: #8ecbff; top: 9px; }
.keymarks i.on { background: #fff; }
.timeline .btn.on { background: var(--accent); color: #111; }
.gif-form { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px 14px; margin: 12px 0; }
.gif-form label { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--dim); }
.gif-form input { width: 70px; }
.gif-form select { min-width: 80px; }
.gif-run { display: flex; align-items: center; gap: 10px; }
.gif-run progress { flex: 1; accent-color: var(--accent); }
.gif-result { display: flex; flex-direction: column; align-items: flex-start; gap: 8px; margin-top: 12px; }
.gif-result img { max-width: 100%; border-radius: 8px; border: 1px solid var(--line); }
@media (max-width: 980px) {
  .timeline { left: 10px; bottom: 8px; gap: 6px; padding: 4px 8px; }
  .timeline .track { flex: 1; }
  .timeline input { width: 100%; }
  .vstats { bottom: 50px; right: 10px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 10px; }
}
@media (max-width: 600px) { .gif-form { grid-template-columns: 1fr 1fr; } }
.timeline span { font: 11px var(--mono); color: rgba(255, 255, 255, 0.8); min-width: 52px; text-align: right; }
.timeline .btn { width: 30px; }
.vstats .size { color: #ffc98a; }
.vhint { top: 10px; color: rgba(255,255,255,.55); }
.empty {
  position: absolute; inset: 0; display: grid; place-content: center; text-align: center; gap: 6px;
  pointer-events: none;
}
.empty h3 { margin: 0; font-size: 18px; }
.empty p { margin: 0 0 8px; color: var(--dim); }
.empty .btn { pointer-events: auto; justify-self: center; }

/* ---- inspector */
.inspector { flex: 0 1 auto; overflow: auto; max-height: 62%; }
.field { display: grid; grid-template-columns: 74px 1fr; align-items: center; gap: 8px; margin-bottom: 6px; }
.field > label { color: var(--dim); font-size: 12px; }
.xyz { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; }
.field input[type=text], .field input[type=number], textarea {
  width: 100%; min-width: 0; background: var(--panel-2); border: 1px solid var(--line); border-radius: 5px; padding: 4px 6px;
}
.field input[type=number] { font: 12px var(--mono); }
.field input:focus, textarea:focus { outline: 1px solid var(--accent); border-color: var(--accent); }
.field input[type=color] { width: 44px; height: 26px; padding: 0; border: 1px solid var(--line); border-radius: 5px; background: none; }
.row { display: flex; align-items: center; gap: 10px; }
.checks { display: flex; gap: 14px; color: var(--dim); }
.checks label { display: flex; gap: 5px; align-items: center; cursor: pointer; }
textarea { font: 11.5px/1.45 var(--mono); min-height: 120px; resize: vertical; }
.subhead { margin: 12px 0 6px; font-size: 11px; color: var(--dim); text-transform: uppercase; letter-spacing: .06em; display: flex; justify-content: space-between; }
.actions { display: flex; gap: 6px; margin-top: 10px; flex-wrap: wrap; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 3px 12px; font-size: 12px; }
.kv span:nth-child(odd) { color: var(--dim); }

/* ---- activity */
.activity { flex: 1; min-height: 0; display: flex; flex-direction: column; border-bottom: 0 !important; }
.activity ol { list-style: none; margin: 0; padding: 0; overflow: auto; flex: 1; }
.activity li { padding: 6px 0; border-bottom: 1px solid var(--line); display: grid; grid-template-columns: auto 1fr; gap: 2px 8px; }
.activity li.new { animation: flash 1.2s ease-out; }
.activity .who {
  font: 600 10.5px var(--mono); padding: 1px 6px; border-radius: 4px; align-self: start; margin-top: 1px;
  background: color-mix(in srgb, var(--agent) 20%, transparent); color: var(--agent);
}
.activity .who.you { background: var(--panel-2); color: var(--dim); }
.activity .what { min-width: 0; overflow-wrap: anywhere; }
.activity .meta { grid-column: 2; color: var(--dim); font: 11px var(--mono); }
.activity li.err .what { color: var(--err); }
.activity .none { color: var(--dim); display: block; }
.working { color: var(--agent); text-transform: none; letter-spacing: 0; animation: pulse 1s ease-in-out infinite alternate; }
@keyframes flash { from { background: color-mix(in srgb, var(--agent) 14%, transparent); } to { background: transparent; } }
@keyframes pulse { from { opacity: .45; } to { opacity: 1; } }

/* ---- dialog */
.dialog {
  width: min(680px, calc(100vw - 32px)); background: var(--panel); color: var(--text);
  border: 1px solid var(--line); border-radius: 12px; padding: 18px 20px;
}
.dialog::backdrop { background: rgba(5,6,8,.6); backdrop-filter: blur(2px); }
.dialog-head { display: flex; justify-content: space-between; align-items: center; margin: 0; }
.dialog-head h2 { margin: 0; font-size: 17px; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin: 12px 0; flex-wrap: wrap; }
.tab { background: none; border: 0; padding: 7px 10px; color: var(--dim); cursor: pointer; border-bottom: 2px solid transparent; }
.tab.active { color: var(--text); border-bottom-color: var(--accent); }
.connect-body p { margin: 8px 0; }
.code { position: relative; background: #0b0d11; border: 1px solid var(--line); border-radius: 8px; margin: 8px 0 12px; }
.code pre { margin: 0; padding: 12px 70px 12px 12px; overflow: auto; font: 12px/1.5 var(--mono); white-space: pre; }
.code button { position: absolute; top: 8px; right: 8px; font-size: 11px; padding: 3px 8px; }

.toast {
  position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); z-index: 50; max-width: 80vw;
  background: var(--panel-2); border: 1px solid var(--line); border-left: 3px solid var(--err);
  padding: 8px 14px; border-radius: 8px; box-shadow: 0 10px 30px rgba(0,0,0,.4);
}
.toast.info { border-left-color: var(--ok); }

@media (max-width: 980px) {
  body { overflow: auto; grid-template-rows: auto 1fr; }
  .topbar { flex-wrap: wrap; padding: 8px 12px; gap: 8px; }
  .tools { order: 3; flex-basis: 100%; flex-wrap: wrap; }
  .layout { grid-template-columns: 1fr; grid-template-rows: 55vh auto auto; }
  .viewport { order: -1; }
  .panel.left, .panel.right { border: 0; border-top: 1px solid var(--line); }
  .inspector { max-height: none; }
  .activity ol { max-height: 260px; }
  .vhint { display: none; }
}
