:root {
  --bg: #1f2024;
  --panel: #2a2b30;
  --panel-2: #33353b;
  --line: #3e4047;
  --text: #e6e7ea;
  --muted: #9a9ca5;
  --accent: #3d8bff;
  --accent-2: #2a6fd6;
  --danger: #e5534b;
  --stage-bg: #45474e;
  --radius: 6px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--bg); color: var(--text); font: 13px/1.35 var(--font); }
button { font: inherit; color: inherit; }
input, select { font: inherit; color: var(--text); background: #1b1c20; border: 1px solid var(--line); border-radius: 4px; padding: 3px 6px; }
input:focus, select:focus { outline: 1px solid var(--accent); border-color: var(--accent); }
input[type="range"] { padding: 0; accent-color: var(--accent); background: transparent; border: 0; }
input[type="checkbox"], input[type="radio"] { accent-color: var(--accent); }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.mono { font-family: ui-monospace, Consolas, monospace; font-size: 12px; }
kbd { font-family: ui-monospace, Consolas, monospace; font-size: 11px; background: #18191c; border: 1px solid var(--line); border-radius: 3px; padding: 1px 5px; }

#app { display: grid; grid-template-rows: 30px 40px 1fr 24px; height: 100vh; }

/* ---------- menubar ---------- */
#menubar { display: flex; align-items: center; gap: 4px; padding: 0 8px; background: #18191c; border-bottom: 1px solid var(--line); user-select: none; }
.brand { font-weight: 650; letter-spacing: .2px; margin-right: 10px; color: #fff; }
#menus { display: flex; }
.menu-btn { background: none; border: 0; padding: 4px 9px; border-radius: 4px; cursor: default; }
.menu-btn:hover, .menu-btn.open { background: var(--panel-2); }
.spacer { flex: 1; }
#session-info { display: flex; gap: 8px; align-items: center; }
#session-info span { padding: 2px 8px; border-radius: 10px; background: var(--panel-2); font-size: 12px; }
#session-info .si-cond { background: #233a5c; color: #bcd6ff; }
#session-info .si-timer { font-variant-numeric: tabular-nums; }

.dropdown { position: fixed; z-index: 50; min-width: 220px; background: #26272c; border: 1px solid #4a4c55; border-radius: var(--radius); padding: 4px; box-shadow: 0 10px 30px rgba(0,0,0,.45); user-select: none; }
.dropdown .item { display: grid; grid-template-columns: 22px 1fr auto; align-items: center; gap: 6px; padding: 5px 8px; border-radius: 4px; cursor: default; }
.dropdown .item:hover, .dropdown .item.sub-open { background: var(--accent-2); color: #fff; }
.dropdown .item.disabled { color: #6b6d75; pointer-events: none; }
.dropdown .item .key { color: var(--muted); font-size: 11.5px; padding-left: 14px; }
.dropdown .item:hover .key, .dropdown .item.sub-open .key { color: #dfe9ff; }
.dropdown .ic { display: flex; justify-content: center; opacity: .85; }
.dropdown .sep { height: 1px; background: var(--line); margin: 4px 2px; }

/* ---------- options bar ---------- */
#optionsbar { display: flex; align-items: center; gap: 14px; padding: 0 12px; background: var(--panel); border-bottom: 1px solid var(--line); overflow-x: auto; white-space: nowrap; scrollbar-width: thin; }
.ob-tool { display: flex; align-items: center; gap: 6px; font-weight: 600; padding-right: 12px; border-right: 1px solid var(--line); min-width: 130px; }
.ob-ctl { display: flex; align-items: center; gap: 6px; }
.ob-lbl { color: var(--muted); }
.ob-range input[type="range"] { width: 110px; }
.ob-num { width: 52px; text-align: right; padding: 2px 5px; }
.ob-hint { color: var(--muted); font-size: 12px; padding-left: 8px; border-left: 1px solid var(--line); }
.ob-btn { background: var(--panel-2); border: 1px solid #4a4c55; border-radius: 4px; padding: 4px 11px; cursor: pointer; }
.ob-btn:hover:not(:disabled) { background: #3d3f46; }
.ob-btn:disabled { opacity: .45; cursor: default; }
.ob-btn.primary { background: var(--accent-2); border-color: var(--accent); color: #fff; }
.ob-btn.primary:hover:not(:disabled) { background: var(--accent); }
.ob-btn.danger { border-color: #7a3431; color: #ffb4ae; }
.ob-btn.sm { padding: 2px 7px; font-size: 12px; }

/* ---------- workspace ---------- */
#workspace { display: grid; grid-template-columns: 56px 1fr 260px; min-height: 0; }
#workspace:has(#panels.hidden) { grid-template-columns: 56px 1fr 0; }

#toolbar { background: var(--panel); border-right: 1px solid var(--line); display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 8px 0; overflow-y: auto; user-select: none; scrollbar-width: none; }
.cluster { position: relative; width: 42px; height: 42px; border-radius: var(--radius); display: grid; place-items: center; cursor: pointer; color: #cfd1d6; touch-action: none; }
.cluster:hover { background: var(--panel-2); }
.cluster.active { background: var(--accent-2); color: #fff; }
.cl-icon { display: grid; place-items: center; pointer-events: none; }
.cl-corner { position: absolute; right: 1px; bottom: 1px; width: 13px; height: 13px; }
.cl-corner::after { content: ""; position: absolute; right: 2px; bottom: 2px; border-left: 6px solid transparent; border-bottom: 6px solid currentColor; opacity: .7; }
.cl-corner:hover::after { opacity: 1; }
.tb-sep { width: 32px; height: 1px; background: var(--line); margin: 4px 0; }
.tb-btn { width: 36px; height: 32px; display: grid; place-items: center; background: none; border: 0; border-radius: 5px; color: #c4c6cc; cursor: pointer; }
.tb-btn:hover:not(:disabled) { background: var(--panel-2); color: #fff; }
.tb-btn:disabled { opacity: .35; cursor: default; }
.tb-btn.sm { width: 30px; height: 28px; }
.swatches { position: relative; width: 46px; height: 52px; }
.swatch-btn { position: absolute; width: 28px; height: 28px; border: 2px solid #fff; border-radius: 4px; box-shadow: 0 0 0 1px #000; cursor: pointer; padding: 0; }
.swatch-btn.fg { left: 2px; top: 2px; z-index: 2; }
.swatch-btn.bg { left: 15px; top: 15px; }
.mini { position: absolute; background: none; border: 0; color: #c4c6cc; cursor: pointer; font-size: 12px; padding: 0; width: 14px; height: 14px; line-height: 14px; }
.mini.swap { right: -2px; top: 0; }
.mini.reset { left: 0; bottom: -4px; }
.mini:hover { color: #fff; }

.flyout { position: fixed; z-index: 45; background: #26272c; border: 1px solid #4a4c55; border-radius: var(--radius); padding: 4px; box-shadow: 0 10px 30px rgba(0,0,0,.45); min-width: 190px; user-select: none; }
.fl-title { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .6px; padding: 4px 8px 6px; }
.fl-item { display: grid; grid-template-columns: 22px 1fr auto; gap: 8px; align-items: center; width: 100%; text-align: left; background: none; border: 0; padding: 6px 8px; border-radius: 4px; cursor: pointer; }
.fl-item:hover { background: var(--accent-2); color: #fff; }
.fl-item.active { box-shadow: inset 3px 0 0 var(--accent); }
.fl-item .key { color: var(--muted); font-size: 11.5px; }

#stage { position: relative; overflow: hidden; background: var(--stage-bg); min-width: 0; }
#view { display: block; touch-action: none; outline: none; }

/* ---------- suggested zone ---------- */
.suggest { position: absolute; left: 0; top: 0; z-index: 10; display: flex; align-items: center; gap: 3px; padding: 4px 5px 4px 3px; background: rgba(30, 31, 36, .92); border: 1px solid #555862; border-radius: 12px; box-shadow: 0 6px 20px rgba(0,0,0,.4); backdrop-filter: blur(6px); transition: transform .28s cubic-bezier(.2,.8,.2,1); user-select: none; touch-action: none; }
.suggest .grip { width: 8px; height: 26px; margin-right: 2px; cursor: grab; background: radial-gradient(circle, #777 1px, transparent 1.5px) 0 0 / 4px 4px; opacity: .8; }
.sg-slot { position: relative; width: 40px; height: 40px; border-radius: 9px; border: 0; background: transparent; color: #e3e4e8; display: grid; place-items: center; cursor: pointer; }
.sg-slot:hover { background: #3a3c44; }
.sg-slot.active { background: var(--accent-2); color: #fff; }
.sg-slot.empty { cursor: default; opacity: .25; border: 1px dashed #666; width: 34px; height: 34px; margin: 3px; }
.sg-slot.pinned::after { content: ""; position: absolute; top: 4px; right: 4px; width: 5px; height: 5px; border-radius: 50%; background: #ffcf5a; }

.radial { position: absolute; z-index: 12; width: 0; height: 0; }
.rd-center { position: absolute; width: 14px; height: 14px; left: -7px; top: -7px; border-radius: 50%; border: 2px solid rgba(255,255,255,.8); box-shadow: 0 0 0 1px #000; }
.rd-item { position: absolute; width: 44px; height: 44px; margin: -22px 0 0 -22px; border-radius: 50%; border: 1px solid #5a5d66; background: rgba(30,31,36,.95); color: #eee; display: grid; place-items: center; cursor: pointer; box-shadow: 0 4px 14px rgba(0,0,0,.45); animation: pop .12s ease-out; }
.rd-item:hover { background: var(--accent-2); color: #fff; }
.rd-item.active { border-color: var(--accent); }
.rd-item.pinned::after { content: ""; position: absolute; top: 5px; right: 7px; width: 5px; height: 5px; border-radius: 50%; background: #ffcf5a; }
@keyframes pop { from { transform: scale(.6); opacity: 0; } }

#toast { position: absolute; left: 50%; bottom: 18px; transform: translateX(-50%) translateY(8px); background: rgba(20,20,24,.95); border: 1px solid #555; padding: 7px 14px; border-radius: 16px; opacity: 0; pointer-events: none; transition: .2s; z-index: 20; }
#toast.show { opacity: 1; transform: translateX(-50%); }

/* ---------- panels ---------- */
#panels { background: var(--panel); border-left: 1px solid var(--line); overflow-y: auto; min-width: 0; scrollbar-width: thin; }
.panel { border-bottom: 1px solid var(--line); }
.pn-head { display: flex; align-items: center; gap: 6px; padding: 7px 10px; font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .5px; color: #c9cbd1; cursor: pointer; user-select: none; background: #2e3035; }
.pn-head .chev { transition: transform .15s; font-size: 10px; }
.panel.collapsed .pn-body { display: none; }
.panel.collapsed .chev { transform: rotate(-90deg); }
.pn-body { padding: 10px; display: flex; flex-direction: column; gap: 8px; }
.row { display: flex; gap: 6px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.sub-lbl { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .5px; }

.task-head { display: flex; justify-content: space-between; color: var(--muted); font-size: 12px; }
.task-timer { font-variant-numeric: tabular-nums; }
.pause-body { text-align: center; }
.task-est { font-size: 12px; margin-top: -4px; }
.qtext { width: 100%; margin-top: 6px; font: inherit; color: var(--text); background: #1b1c20; border: 1px solid var(--line); border-radius: 4px; padding: 6px 8px; resize: vertical; }
select.err { border-color: var(--danger); outline: 1px solid var(--danger); }
.pause-clock { font-size: 34px; font-weight: 650; font-variant-numeric: tabular-nums; margin: 6px 0; }
.task-title { font-weight: 650; font-size: 14px; }
.task-prompt { margin: 0; }
.task-steps { margin: 0; padding-left: 18px; color: #c9cbd1; font-size: 12.5px; }
.task-steps li { margin: 2px 0; }
img.ref { width: 100%; border-radius: 4px; border: 1px solid var(--line); cursor: zoom-in; background: #fff; }
img.ref-big { width: 100%; max-height: 70vh; object-fit: contain; background: #fff; border-radius: 4px; }

.big-swatch { position: static; width: 38px; height: 30px; flex: none; }
.hex { width: 96px; font-family: ui-monospace, Consolas, monospace; }
.palette { display: grid; grid-template-columns: repeat(8, 1fr); gap: 4px; }
.pal { aspect-ratio: 1; border: 1px solid rgba(0,0,0,.6); border-radius: 3px; cursor: pointer; padding: 0; box-shadow: inset 0 0 0 1px rgba(255,255,255,.08); }
.pal:hover { outline: 2px solid #fff; outline-offset: 0; }
.palette.recent { min-height: 22px; }

.layers { display: flex; flex-direction: column; gap: 2px; max-height: 260px; overflow-y: auto; }
.layer { display: grid; grid-template-columns: 22px 40px 1fr; gap: 8px; align-items: center; padding: 4px 6px; border-radius: 4px; cursor: pointer; border: 1px solid transparent; }
.layer:hover { background: var(--panel-2); }
.layer.active { background: #2f4669; border-color: #3d6cb0; }
.layer .eye { background: none; border: 0; cursor: pointer; color: #ddd; padding: 0; font-size: 14px; }
.layer .eye.off { color: #777; }
.layer .thumb { width: 40px; height: 28px; border-radius: 2px; border: 1px solid #111; }
.lname { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lrename { width: 100%; padding: 1px 4px; }
.layer-op { display: grid; grid-template-columns: auto 1fr 38px; gap: 8px; align-items: center; color: var(--muted); }
.layer-op .opv { text-align: right; color: var(--text); }
.layer-btns { display: flex; justify-content: space-between; }

.hist { max-height: 200px; overflow-y: auto; font-size: 12px; }
.hrow { padding: 3px 6px; border-radius: 3px; }
.hrow.cur { background: #2f4669; }
.hrow.undone { color: #6b6d75; font-style: italic; }
.hrow.base { color: var(--muted); }

/* ---------- popover (colour picker) ---------- */
.popover { position: fixed; z-index: 46; background: #26272c; border: 1px solid #4a4c55; border-radius: 8px; padding: 10px; box-shadow: 0 12px 34px rgba(0,0,0,.5); display: flex; flex-direction: column; gap: 8px; width: 242px; }
.popover canvas { border-radius: 4px; cursor: crosshair; touch-action: none; display: block; width: 220px; }
.popover .prev { width: 28px; height: 24px; border-radius: 4px; border: 1px solid #000; flex: none; }
.popover .hex { flex: 1; width: auto; }
.seg { display: flex; background: #1b1c20; border-radius: 5px; padding: 2px; }
.seg button { flex: 1; background: none; border: 0; padding: 4px; border-radius: 4px; cursor: pointer; color: var(--muted); }
.seg button.on { background: var(--panel-2); color: var(--text); }

/* ---------- status bar ---------- */
#statusbar { display: flex; align-items: center; gap: 14px; padding: 0 10px; background: #18191c; border-top: 1px solid var(--line); color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; font-variant-numeric: tabular-nums; }
#statusbar .sb-spacer { flex: 1; }
#statusbar .sb-log.on { color: #7ee2a8; }
#statusbar .sb-log.warn { color: #ffb86b; }

/* ---------- modals ---------- */
.modal-back { position: fixed; inset: 0; z-index: 100; background: rgba(0,0,0,.55); display: grid; place-items: center; padding: 16px; }
.modal { background: #2a2b30; border: 1px solid #4a4c55; border-radius: 10px; width: min(460px, 100%); max-height: calc(100vh - 32px); display: flex; flex-direction: column; box-shadow: 0 20px 60px rgba(0,0,0,.6); }
.modal.wide { width: min(720px, 100%); }
.modal h2 { margin: 0; padding: 14px 18px 10px; font-size: 16px; }
.modal-body { padding: 4px 18px 12px; overflow-y: auto; }
.modal-body h3 { margin: 14px 0 6px; font-size: 12px; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 18px; border-top: 1px solid var(--line); flex-wrap: wrap; }
.form { display: flex; flex-direction: column; gap: 8px; }
.frow { display: grid; grid-template-columns: 180px 1fr; gap: 4px 12px; align-items: center; }
.frow .fhint { grid-column: 2; color: var(--muted); font-size: 11.5px; }
.frow input[type="checkbox"] { justify-self: start; }
input.err { border-color: var(--danger); outline: 1px solid var(--danger); }
.model-status { background: #222327; border: 1px solid var(--line); border-radius: 6px; padding: 8px 10px; display: flex; flex-direction: column; gap: 4px; font-size: 12.5px; }
.ms-row { display: grid; grid-template-columns: 120px 1fr; gap: 10px; }
.ms-k { color: var(--muted); }
.progress { min-height: 18px; font-size: 12px; }

.tlx-item { padding: 10px 0; border-bottom: 1px solid var(--line); }
.tlx-h { display: flex; justify-content: space-between; }
.tlx-v { font-variant-numeric: tabular-nums; color: var(--accent); font-weight: 600; }
.tlx-q { color: var(--muted); font-size: 12.5px; margin: 2px 0 6px; }
.tlx input[type="range"] { width: 100%; }
.tlx input.untouched { opacity: .45; }
.tlx-anchors { display: flex; justify-content: space-between; font-size: 11.5px; color: var(--muted); }
.sus-item { padding: 8px 0; border-bottom: 1px solid var(--line); }
.sus-q { margin-bottom: 6px; }
.likert { display: flex; gap: 6px; }
.likert label { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 5px 0; border: 1px solid var(--line); border-radius: 5px; cursor: pointer; }
.likert label:has(input:checked) { border-color: var(--accent); background: #233a5c; }

.sessions { display: flex; flex-direction: column; gap: 2px; font-size: 12px; }
.srow { display: grid; grid-template-columns: 1.6fr .9fr 1fr .5fr auto; gap: 8px; align-items: center; padding: 5px 4px; border-bottom: 1px solid #34363c; }
.srow.head { color: var(--muted); font-weight: 600; }
.srow .mono { overflow: hidden; text-overflow: ellipsis; }
.sact { display: flex; gap: 4px; }
.shortcuts { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 18px; }
.sc { display: flex; justify-content: space-between; gap: 10px; align-items: center; border-bottom: 1px solid #34363c; padding: 3px 0; }

#livelog { position: fixed; right: 270px; bottom: 30px; width: 460px; height: 260px; z-index: 30; background: rgba(18,18,22,.95); border: 1px solid #4a4c55; border-radius: 8px; display: flex; flex-direction: column; font-size: 11px; box-shadow: 0 10px 30px rgba(0,0,0,.5); }
#livelog .ll-head { position: relative; padding: 6px 10px; font-weight: 600; border-bottom: 1px solid var(--line); }
#livelog .ll-head .mini { right: 10px; top: 6px; font-size: 16px; }
#livelog .ll-body { flex: 1; overflow-y: auto; padding: 4px 8px; font-family: ui-monospace, Consolas, monospace; }
.ll-row { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding: 1px 0; }
.ll-t { color: #777; display: inline-block; width: 44px; }
.ll-row b { color: #9cc3ff; font-weight: 600; }
.ll-tool_change b { color: #ffcf5a; }
.ll-wrong_tool_correction b { color: #ff8a80; }
.ll-d { color: #aaa; }

@media (max-width: 900px) {
  #workspace { grid-template-columns: 56px 1fr 0; }
  #panels { display: none; }
  #menubar { overflow-x: auto; scrollbar-width: none; }
  .brand, #session-info .si-cond { display: none; }
  .frow { grid-template-columns: 1fr; }
  .frow .fhint { grid-column: 1; }
  #livelog { right: 10px; width: calc(100vw - 20px); }
}
