:root {
  color-scheme: dark;
  --bg: #0d1017; --panel: #151a24; --panel2: #1b2230; --border: #262f42;
  --text: #e8ecf4; --muted: #8b96ab; --accent: #6d8dff; --accent2: #8f6dff;
  --ok: #4ade80; --err: #f87171; --warn: #fbbf24;
  --hover: #1a2233; --hover-border: #3a4763;
  --glass: #000a; --glass-strong: #000c;          /* buttons/readouts floating on the viewer */
  --popover: #0e1320ee; --popover-solid: #0e1320f2; --toast-bg: #111827f5;
  --divider: #1c2436; --scrim: #000a; --shadow: #000c;
  --badge-bg: #3a2f10; --err-text: #fecaca;
}
/* light theme: chosen explicitly, or following the OS until the user picks one */
:root[data-theme="light"] {
  color-scheme: light;
  --bg: #eef1f6; --panel: #ffffff; --panel2: #f3f5f9; --border: #d6dce7;
  --text: #1a2130; --muted: #5f6b80; --accent: #4a6cf7; --accent2: #7a55f0;
  --ok: #16a34a; --err: #dc2626; --warn: #b45309;
  --hover: #eef2fe; --hover-border: #b7c3dc;
  --glass: #ffffffcc; --glass-strong: #ffffffeb;
  --popover: #ffffffee; --popover-solid: #fffffff7; --toast-bg: #fffffffa;
  --divider: #e6eaf1; --scrim: #0f172a59; --shadow: #0f172a33;
  --badge-bg: #fef3c7; --err-text: #b91c1c;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: "Inter", -apple-system, "Segoe UI", sans-serif;
  background: var(--bg); color: var(--text); height: 100vh; height: 100dvh; overflow: hidden;
  /* minmax(0, …) lets the middle track shrink below its content, so the page
     always fits the window (a plain 1fr can be held open by the canvas) */
  display: grid; grid-template-columns: 340px minmax(0, 1fr) 300px; grid-template-rows: 56px minmax(0, 1fr);
}
header {
  grid-column: 1 / -1; display: flex; align-items: center; gap: 12px;
  padding: 0 20px; border-bottom: 1px solid var(--border); background: var(--panel);
}
header .logo {
  font-weight: 700; font-size: 17px; letter-spacing: .3px;
  background: linear-gradient(90deg, var(--accent), var(--accent2));
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
header .tag { font-size: 12px; color: var(--muted); }
#mockBadge {
  font-size: 11px; font-weight: 600; padding: 4px 10px;
  border-radius: 20px; background: var(--badge-bg); color: var(--warn); display: none;
}
#headRight { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.hbtn {
  background: var(--panel2); border: 1px solid var(--border); color: var(--text);
  border-radius: 20px; padding: 5px 12px; font-size: 12px; cursor: pointer; white-space: nowrap;
  font-variant-numeric: tabular-nums; display: flex; align-items: center; gap: 6px;
}
.hbtn:hover { border-color: var(--accent); }
#balanceBtn[hidden] { display: none; }
#balanceBtn .bal { font-weight: 700; }
#balanceBtn.low .bal { color: var(--warn); }
#balanceBtn.empty .bal { color: var(--err); }
#balanceBtn.setup { color: var(--muted); }
#themeBtn { padding: 5px 9px; font-size: 14px; line-height: 1; }
/* left panel */
#left { border-right: 1px solid var(--border); background: var(--panel); padding: 18px; overflow-y: auto; min-height: 0; }
h3 { font-size: 11px; text-transform: uppercase; letter-spacing: 1.2px; color: var(--muted); margin: 18px 0 8px; }
h3:first-child { margin-top: 0; }
#drop {
  border: 2px dashed var(--border); border-radius: 12px; padding: 20px; text-align: center;
  cursor: pointer; transition: all .15s; color: var(--muted); font-size: 13px;
}
#drop:hover, #drop.drag { border-color: var(--accent); color: var(--text); background: var(--hover); }
#preview { display: none; }
/* once an image is picked the drop zone collapses to a compact file row */
#drop.has { display: flex; align-items: center; gap: 12px; padding: 10px; text-align: left; border-style: solid; }
#drop.has #dropText { display: none; }
#drop.has #preview { display: block; width: 64px; height: 64px; object-fit: contain; border-radius: 8px; background: var(--panel2); flex-shrink: 0; }
#imgInfo { display: none; flex: 1; min-width: 0; }
#drop.has #imgInfo { display: block; }
#imgName { color: var(--text); font-weight: 600; font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#imgMeta { font-size: 11px; margin-top: 2px; }
#imgClear { display: none; background: none; border: none; color: var(--muted); cursor: pointer; font-size: 14px; padding: 4px 6px; align-self: flex-start; }
#drop.has #imgClear { display: block; }
#imgClear:hover { color: var(--err); }
.hint { font-size: 11px; color: var(--muted); font-weight: 400; }
/* step 1 header with the Image / Text switch */
.stepHead { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.stepHead h3 { margin: 0; }
.seg { display: flex; background: var(--panel2); border: 1px solid var(--border); border-radius: 8px; padding: 2px; }
.seg button {
  background: none; border: none; color: var(--muted); font-size: 11.5px; padding: 3px 10px;
  border-radius: 6px; cursor: pointer;
}
.seg button.on { background: var(--panel); color: var(--text); box-shadow: 0 1px 2px var(--shadow); }
/* batch: several images, one model each */
#batchStrip { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
#batchStrip[hidden] { display: none; }
.bthumb { position: relative; width: 46px; height: 46px; border-radius: 7px; overflow: hidden; border: 1px solid var(--border); background: var(--panel2); }
.bthumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.bthumb button {
  position: absolute; top: 1px; right: 1px; width: 16px; height: 16px; border-radius: 50%; border: none;
  background: #000a; color: #fff; font-size: 9px; line-height: 16px; padding: 0; cursor: pointer; display: none;
}
.bthumb:hover button, .bthumb:focus-within button { display: block; }
/* extra reference views */
#viewsBox { margin-top: 10px; }
#viewsBox[hidden] { display: none; }
.viewsHead { font-size: 12px; font-weight: 600; margin-bottom: 6px; }
.viewSlots { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.viewSlot {
  position: relative; aspect-ratio: 1; border: 1.5px dashed var(--border); border-radius: 8px;
  display: flex; align-items: center; justify-content: center; font-size: 11.5px; color: var(--muted);
  cursor: pointer; overflow: hidden; background: var(--panel);
}
.viewSlot:hover, .viewSlot.drag { border-color: var(--accent); color: var(--text); }
.viewSlot.has { border-style: solid; }
.viewSlot.off { opacity: .45; }
.viewSlot img { width: 100%; height: 100%; object-fit: contain; background: var(--panel2); }
.viewSlot .vlabel {
  position: absolute; left: 4px; bottom: 4px; font-size: 10px; background: var(--glass-strong);
  color: var(--text); padding: 1px 5px; border-radius: 4px;
}
.viewSlot .vclear {
  position: absolute; top: 3px; right: 3px; width: 17px; height: 17px; border-radius: 50%; border: none;
  background: #000a; color: #fff; font-size: 9px; padding: 0; cursor: pointer;
}
#viewsNote { margin-top: 5px; line-height: 1.4; }
/* text → concept images */
#textPane[hidden] { display: none; }
#conceptPrompt {
  width: 100%; background: var(--panel2); color: var(--text); border: 1px solid var(--border);
  border-radius: 8px; padding: 8px; font: inherit; font-size: 13px; resize: vertical;
}
.conceptRow { display: flex; gap: 6px; margin: 6px 0 0; }
.conceptRow select:first-child { flex: 1; }
.conceptRow select:last-child { width: auto; }
.btn2 {
  width: 100%; margin-top: 4px; padding: 8px; border-radius: 8px; border: 1px solid var(--accent);
  background: var(--hover); color: var(--text); font-size: 13px; font-weight: 600; cursor: pointer;
}
.btn2:disabled { opacity: .5; cursor: progress; }
#conceptGrid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-top: 10px; }
#conceptGrid:empty { display: none; }
.concept {
  position: relative; aspect-ratio: 1; border-radius: 8px; overflow: hidden; border: 2px solid transparent;
  cursor: pointer; background: var(--panel2); padding: 0;
}
.concept img { width: 100%; height: 100%; object-fit: cover; display: block; }
.concept:hover { border-color: var(--hover-border); }
.concept.picked { border-color: var(--accent); }
.concept .use {
  position: absolute; left: 0; right: 0; bottom: 0; padding: 4px; font-size: 11px; text-align: center;
  background: var(--glass-strong); color: var(--text); opacity: 0; transition: opacity .15s;
}
.concept:hover .use, .concept:focus-visible .use, .concept.picked .use { opacity: 1; }
.conceptSec { grid-column: 1 / -1; font-size: 10.5px; color: var(--muted); text-transform: uppercase; letter-spacing: 1px; margin-top: 4px; }
#conceptHint { margin-top: 8px; line-height: 1.4; }
/* model picker: compact rows grouped by price tier; the selected one expands with its options */
.tierHead { font-size: 10.5px; color: var(--muted); margin: 12px 2px 5px; display: flex; justify-content: space-between; }
.tierHead:first-child { margin-top: 0; }
.modelCard {
  border: 1px solid var(--border); border-radius: 9px; padding: 8px 11px; margin-bottom: 5px;
  cursor: pointer; transition: border-color .15s, background .15s;
}
.modelCard:hover { border-color: var(--hover-border); }
.modelCard.sel { border-color: var(--accent); background: var(--hover); cursor: default; padding: 10px 11px; }
.modelCard .mhead { display: flex; align-items: baseline; gap: 8px; }
.modelCard .name { font-size: 12.5px; font-weight: 600; flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.modelCard .price { font-size: 11.5px; color: var(--muted); font-variant-numeric: tabular-nums; flex-shrink: 0; }
.modelCard.sel .price { color: var(--accent); font-weight: 600; }
.modelCard .mbody { display: none; }
.modelCard.sel .mbody { display: block; }
.modelCard .desc { font-size: 11.5px; color: var(--muted); margin-top: 4px; line-height: 1.4; }
.modelCard .cost { font-size: 11px; color: var(--accent); margin-top: 4px; line-height: 1.4; }
.modelCard .optSlot:not(:empty) { margin-top: 8px; padding-top: 4px; border-top: 1px solid var(--border); }
.modelCard .optSlot label.opt { font-size: 12.5px; margin: 6px 0; }
.modelCard .optSlot select { width: auto; margin-left: auto; }
#optStore { display: none; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
label.opt { display: flex; align-items: center; gap: 8px; font-size: 13px; margin: 8px 0; color: var(--text); cursor: pointer; white-space: nowrap; }
select, input[type=number] {
  background: var(--panel2); color: var(--text); border: 1px solid var(--border);
  border-radius: 6px; padding: 5px 8px; font-size: 13px; width: 100%;
}
#generateBtn {
  width: 100%; margin-top: 16px; padding: 12px; border: none; border-radius: 10px;
  background: linear-gradient(90deg, var(--accent), var(--accent2)); color: white;
  font-size: 14px; font-weight: 700; cursor: pointer; transition: opacity .15s;
}
/* pinned to the bottom of the left panel so it's reachable without scrolling past the model list */
#genDock { position: sticky; bottom: -18px; margin: 16px -18px -18px; padding: 12px 18px 18px; background: var(--panel); box-shadow: 0 -10px 14px var(--panel); }
#genDock #generateBtn { margin-top: 0; }
#generateBtn:disabled { opacity: .35; cursor: not-allowed; }
/* viewer */
#viewerWrap { position: relative; min-width: 0; min-height: 0; overflow: hidden; container-type: inline-size; background: radial-gradient(1200px 700px at 50% 30%, #141a28, #0a0d13); }
/* absolutely positioned so the canvas never sizes the layout: it follows the
   viewer area, never the other way round (otherwise the page ratchets to the
   largest size the window has had and cuts off the bottom bars / library) */
#viewer { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
#viewerEmpty {
  position: absolute; inset: 0; display: flex; flex-direction: column; gap: 8px;
  align-items: center; justify-content: center; color: var(--muted); font-size: 14px; pointer-events: none;
  padding: 0 24px; text-align: center;
}
#viewerEmpty .big { font-size: 40px; opacity: .5; }
/* status sits in its own row above the bottom bars, clear of the top toolbar and stats panel */
#statusRow { flex-basis: 100%; order: -1; display: flex; justify-content: center; pointer-events: none; }
#viewerStatus {
  pointer-events: auto; background: var(--glass-strong); backdrop-filter: blur(6px); border: 1px solid var(--border);
  padding: 8px 16px; border-radius: 20px; font-size: 13px; display: none; align-items: center; gap: 8px;
  max-width: min(560px, 100%);
}
#viewerStatus.err { border-color: var(--err); border-radius: 12px; }
#viewerStatus.err #statusText { color: var(--err-text); line-height: 1.4; }
.spinner {
  width: 14px; height: 14px; border: 2px solid var(--border); border-top-color: var(--accent);
  border-radius: 50%; animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
#bottomBar {
  position: absolute; bottom: 14px; left: 14px; right: 14px;
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  flex-wrap: wrap; pointer-events: none;
}
#bottomBar > * { pointer-events: auto; }
#dlBar { display: none; gap: 8px; margin-left: auto; flex-wrap: wrap; justify-content: flex-end; }
#dlMenuWrap { position: relative; }
#dlMenu {
  position: absolute; bottom: 44px; left: 0; min-width: 230px; max-height: 340px; overflow-y: auto;
  background: var(--popover-solid); backdrop-filter: blur(8px); border: 1px solid var(--border);
  border-radius: 10px; padding: 6px; display: flex; flex-direction: column; gap: 1px; z-index: 10;
}
#dlMenu[hidden] { display: none; }
#dlMenu a {
  display: block; padding: 7px 10px; border-radius: 6px; color: var(--text);
  text-decoration: none; font-size: 12.5px; border: none; background: none; white-space: nowrap;
}
#dlMenu a:hover { background: var(--hover); border: none; }
#dlMenu .dlgroup { font-size: 10.5px; text-transform: uppercase; letter-spacing: 1px; color: var(--muted); padding: 6px 10px 2px; }
#dlBar a, #dlBar button {
  background: var(--glass); backdrop-filter: blur(6px); border: 1px solid var(--border); color: var(--text);
  padding: 8px 14px; border-radius: 8px; font-size: 12.5px; text-decoration: none; cursor: pointer;
}
#dlBar a:hover { border-color: var(--accent); }
/* right panel: library */
#right { border-left: 1px solid var(--border); background: var(--panel); overflow-y: auto; padding: 14px; min-height: 0; }
.job {
  border: 1px solid var(--border); border-radius: 10px; padding: 10px; margin-bottom: 8px;
  cursor: pointer; display: flex; gap: 10px; align-items: center; transition: border-color .15s;
}
.job:hover, .job.sel { border-color: var(--accent); }
.job img.thumb { width: 44px; height: 44px; object-fit: cover; border-radius: 6px; background: var(--panel2); }
.job .meta { flex: 1; min-width: 0; }
.job .name { font-size: 12.5px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.job .sub { font-size: 11px; color: var(--muted); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.dot.done { background: var(--ok); } .dot.failed { background: var(--err); }
.dot.generating, .dot.queued { background: var(--warn); animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { opacity: .35; } }
.job .del { background: none; border: none; color: var(--muted); cursor: pointer; font-size: 14px; padding: 2px 6px; }
.job .del:hover { color: var(--err); }
/* rename: pencil appears on hover / focus / selection; the name becomes an inline input */
.job .ren { background: none; border: none; color: var(--muted); cursor: pointer; font-size: 13px; padding: 2px 4px; display: none; }
.job:hover .ren, .job:focus-within .ren, .job.sel .ren { display: block; }
.job .ren:hover { color: var(--accent); }
.job .nameInput {
  width: 100%; font: inherit; font-size: 12.5px; font-weight: 600; color: var(--text);
  background: var(--panel2); border: 1px solid var(--accent); border-radius: 5px; padding: 2px 6px;
}
.job .retry { background: none; border: none; color: var(--accent); cursor: pointer; font-size: 15px; padding: 2px 4px; }
.job .retry:hover { color: var(--text); }
#spend { font-size: 11px; color: var(--muted); margin: -4px 0 10px; cursor: help; }
#spend[hidden] { display: none; }
#emptyLib { color: var(--muted); font-size: 12.5px; text-align: center; padding: 30px 10px; }
#libSearch {
  width: 100%; background: var(--panel2); color: var(--text); border: 1px solid var(--border);
  border-radius: 8px; padding: 6px 10px; font-size: 12.5px; margin-bottom: 10px;
}
#libSearch[hidden] { display: none; }
/* toasts (replace blocking toast()s) */
#toasts {
  position: fixed; top: 8px; left: 50%; transform: translateX(-50%); z-index: 80;
  display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none;
  width: min(460px, calc(100vw - 32px));
}
.toast {
  pointer-events: auto; cursor: pointer; background: var(--toast-bg); backdrop-filter: blur(8px);
  border: 1px solid var(--border); border-left: 3px solid var(--accent); border-radius: 10px;
  padding: 10px 14px; font-size: 13px; line-height: 1.45; white-space: pre-line;
  box-shadow: 0 8px 30px var(--shadow); animation: toastIn .18s ease-out; max-width: 100%;
}
.toast.error { border-left-color: var(--err); }
.toast.ok { border-left-color: var(--ok); }
.toast.out { opacity: 0; transform: translateY(-6px); transition: all .2s; }
@keyframes toastIn { from { opacity: 0; transform: translateY(-6px); } }
/* confirm dialog (replaces confirm()) */
#confirmDlg { position: fixed; inset: 0; background: var(--scrim); display: flex; align-items: center; justify-content: center; z-index: 75; }
#confirmDlg[hidden] { display: none; }
#confirmBox { width: 380px; max-width: 92vw; background: var(--panel); border: 1px solid var(--border); border-radius: 14px; padding: 18px; box-shadow: 0 12px 50px var(--shadow); }
#confirmTitle { font-size: 15px; font-weight: 700; margin-bottom: 6px; }
#confirmMsg { font-size: 12.5px; color: var(--muted); line-height: 1.5; white-space: pre-line; }
#confirmBox .modalBtns { margin-top: 16px; }
#confirmNo { background: var(--panel2); border: 1px solid var(--border); color: var(--muted); }
#confirmYes { background: linear-gradient(90deg, var(--accent), var(--accent2)); border: none; color: white; }
#confirmYes.danger { background: #b91c1c; }
/* viewer toolbar + lighting panel */
#vtools { position: absolute; top: 14px; right: 14px; display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; max-width: calc(100% - 28px); z-index: 7; }
.vbtn {
  background: var(--glass); backdrop-filter: blur(6px); border: 1px solid var(--border); color: var(--text);
  padding: 8px 14px; border-radius: 8px; font-size: 12.5px; cursor: pointer;
}
.vbtn:hover, .vbtn.on { border-color: var(--accent); }
select.vbtn { width: auto; padding: 8px 10px; }
#lightPanel {
  position: absolute; top: 52px; right: 14px; width: 250px; background: var(--popover);
  backdrop-filter: blur(8px); border: 1px solid var(--border); border-radius: 12px; padding: 12px;
  display: flex; flex-direction: column; gap: 8px; font-size: 12px; z-index: 5;
}
#lightPanel[hidden] { display: none; }
#lightPanel .lrow { display: grid; grid-template-columns: 84px 1fr; align-items: center; gap: 8px; color: var(--muted); }
#lightPanel input[type=range] { width: 100%; accent-color: var(--accent); }
#lightPanel input[type=color] {
  width: 100%; height: 24px; border: 1px solid var(--border); border-radius: 6px;
  background: var(--panel2); padding: 1px; cursor: pointer;
}
#lightPanel select { padding: 4px 6px; font-size: 12px; }
#lightPanel .checks { display: flex; gap: 12px; color: var(--text); }
#lightPanel .checks label { display: flex; gap: 5px; align-items: center; cursor: pointer; }
#lp_reset {
  background: var(--panel2); border: 1px solid var(--border); color: var(--muted);
  border-radius: 8px; padding: 6px; cursor: pointer; font-size: 12px;
}
#lp_reset:hover { color: var(--text); border-color: var(--accent); }
/* library header + import */
#libHead { display: flex; align-items: center; justify-content: space-between; margin: 4px 0 8px; }
#libHead h3 { margin: 0; }
#importBtn {
  background: var(--panel2); border: 1px solid var(--border); color: var(--text);
  border-radius: 8px; padding: 5px 10px; font-size: 11.5px; cursor: pointer; white-space: nowrap;
}
#importBtn:hover { border-color: var(--accent); }
/* animation playback bar */
#animBar { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
#animBar[hidden] { display: none; }
#animBar select {
  width: auto; background: var(--glass); backdrop-filter: blur(6px); border: 1px solid var(--border);
  color: var(--text); border-radius: 8px; padding: 8px 10px; font-size: 12.5px;
}
#animBar input[type=range] { width: 120px; accent-color: var(--accent); }
#animTime {
  font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums;
  background: var(--glass); padding: 8px 10px; border-radius: 8px; border: 1px solid var(--border);
}
/* modal (rig / retexture) */
#modal { position: fixed; inset: 0; background: var(--scrim); display: flex; align-items: center; justify-content: center; z-index: 50; }
#modal[hidden] { display: none; }
/* side mode (rig dialog): keep the viewer visible & interactive behind it */
#modal.side { background: transparent; pointer-events: none; justify-content: flex-end; }
#modal.side #modalBox { pointer-events: auto; margin-right: 316px; box-shadow: 0 8px 40px var(--shadow); }
#modalBox {
  width: 410px; max-width: 92vw; max-height: 86vh; overflow-y: auto;
  background: var(--panel); border: 1px solid var(--border); border-radius: 14px; padding: 18px;
}
#modalTitle { font-size: 15px; font-weight: 700; margin-bottom: 4px; }
#modalDesc { font-size: 12px; color: var(--muted); margin-bottom: 12px; line-height: 1.5; }
.animGrid { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 10px; margin: 8px 0; }
.animGrid label { display: flex; gap: 6px; align-items: center; font-size: 12.5px; cursor: pointer; padding: 3px 0; }
/* clip browser */
.clipTools { display: flex; gap: 6px; margin: 6px 0; }
.clipTools input[type=text] {
  flex: 1; background: var(--panel2); border: 1px solid var(--border); color: var(--text);
  border-radius: 6px; padding: 5px 8px; font-size: 12.5px;
}
.clipTools select { width: auto; max-width: 140px; font-size: 12px; }
/* floats beside the dialog (actions.js places it), so showing it never moves the list */
#clipPreview { position: fixed; z-index: 60; pointer-events: none; padding: 6px; border-radius: 12px;
  background: var(--panel); border: 1px solid var(--border); box-shadow: 0 8px 30px var(--shadow); }
#clipPreview img { display: block; width: 140px; height: 140px; object-fit: contain; border-radius: 8px; background: #fff; }
#clipPreview[hidden] { display: none; }
#clipList { height: 185px; overflow-y: auto; border: 1px solid var(--border); border-radius: 8px; padding: 4px; }
.clipRow { display: flex; gap: 6px; align-items: center; padding: 3px 6px; border-radius: 5px; font-size: 12.5px; cursor: pointer; }
.clipRow:hover { background: var(--hover); }
.clipRow .cl { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.clipRow .cc { color: var(--muted); font-size: 10.5px; flex-shrink: 0; }
.clipMore { color: var(--muted); font-size: 11.5px; padding: 6px; text-align: center; }
#modalBox textarea {
  width: 100%; min-height: 64px; background: var(--panel2); color: var(--text);
  border: 1px solid var(--border); border-radius: 8px; padding: 8px; font-size: 13px;
  font-family: inherit; resize: vertical;
}
#modalCost { font-size: 12.5px; color: var(--accent); margin: 10px 0 4px; font-weight: 600; }
.modalBtns { display: flex; gap: 8px; margin-top: 10px; }
.modalBtns button { flex: 1; padding: 10px; border-radius: 9px; font-size: 13px; font-weight: 600; cursor: pointer; }
#modalCancel { background: var(--panel2); border: 1px solid var(--border); color: var(--muted); }
#modalGo { background: linear-gradient(90deg, var(--accent), var(--accent2)); border: none; color: white; }
#modalGo:disabled { opacity: .35; cursor: not-allowed; }
.mrow { display: flex; align-items: center; gap: 8px; font-size: 12.5px; margin: 8px 0; color: var(--text); }
.mrow input[type=number] { width: 90px; }
.mrow select { width: auto; }
/* model stats */
#statsPanel {
  position: absolute; top: 14px; left: 14px; background: var(--glass); backdrop-filter: blur(6px);
  border: 1px solid var(--border); border-radius: 10px; padding: 10px 14px;
  font-size: 12px; display: grid; grid-template-columns: auto auto; gap: 3px 14px;
  font-variant-numeric: tabular-nums;
}
#statsPanel[hidden] { display: none; }
#statsPanel .k { color: var(--muted); }
/* texture map inspector */
#mapsPanel {
  position: absolute; top: 52px; right: 14px; width: 258px; background: var(--popover);
  backdrop-filter: blur(8px); border: 1px solid var(--border); border-radius: 12px;
  padding: 10px 12px; font-size: 12.5px; z-index: 5;
}
#mapsPanel[hidden] { display: none; }
#mapsPanel .mprow { display: flex; gap: 10px; align-items: center; padding: 5px 0; border-bottom: 1px solid var(--divider); }
#mapsPanel .mprow:last-of-type { border-bottom: none; }
#mapsPanel .mpleft { flex: 1; min-width: 0; }
#mapsPanel .mphead { display: flex; align-items: center; justify-content: space-between; gap: 6px; }
#mapsPanel .mphead label { display: flex; gap: 6px; align-items: center; cursor: pointer; }
#mapsPanel .mpval { color: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
#mapsPanel input[type=range] { width: 100%; accent-color: var(--accent); margin-top: 3px; }
#mapsPanel .mpright { display: flex; flex-direction: column; align-items: center; gap: 2px; }
#mapsPanel .dims { color: var(--muted); font-size: 10px; font-variant-numeric: tabular-nums; }
#mapsPanel canvas.mthumb {
  width: 44px; height: 44px; border-radius: 6px; border: 1px solid var(--border);
  cursor: zoom-in; background: var(--panel2);
}
#mapsPanel .mapsEmpty { color: var(--muted); padding: 6px 0; }
#mapsReset {
  width: 100%; margin-top: 8px; background: var(--panel2); border: 1px solid var(--border);
  color: var(--muted); border-radius: 8px; padding: 6px; cursor: pointer; font-size: 12px;
}
#mapsReset:hover { color: var(--text); border-color: var(--accent); }
/* animation editor */
#editPanel {
  position: absolute; top: 14px; left: 14px; width: 252px; max-height: calc(100% - 90px);
  overflow-y: auto; background: var(--popover); backdrop-filter: blur(8px);
  border: 1px solid var(--border); border-radius: 12px; padding: 12px;
  display: flex; flex-direction: column; gap: 7px; font-size: 12px; z-index: 6;
}
#editPanel[hidden] { display: none; }
.epTitle { font-size: 13px; font-weight: 700; display: flex; justify-content: space-between; align-items: center; }
#epClose { background: none; border: none; color: var(--muted); cursor: pointer; font-size: 14px; }
#epClose:hover { color: var(--err); }
.epSec { font-size: 10.5px; text-transform: uppercase; letter-spacing: 1px; color: var(--muted); margin-top: 6px; }
.epHint { text-transform: none; letter-spacing: 0; }
#editPanel .lrow { display: grid; grid-template-columns: 92px 1fr; align-items: center; gap: 8px; color: var(--muted); }
#editPanel input[type=number] { width: 100%; padding: 4px 6px; font-size: 12px; }
#editPanel input[type=range] { width: 100%; accent-color: var(--accent); }
#editPanel select { font-size: 12px; padding: 4px 6px; }
.epBtn {
  background: var(--panel2); border: 1px solid var(--border); color: var(--text);
  border-radius: 8px; padding: 6px; cursor: pointer; font-size: 12px;
}
.epBtn:hover { border-color: var(--accent); }
.epBtn.on { border-color: var(--accent); color: var(--accent); }
#epMorphs .lrow span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#epMorphs, #epItems { display: flex; flex-direction: column; gap: 4px; }
.epRow { display: flex; gap: 4px; }
.epRow .epBtn { flex: 1; padding: 5px 2px; font-size: 11.5px; }
.epHint2 { font-size: 11px; color: var(--muted); line-height: 1.4; }
#epTimeline {
  position: relative; height: 22px; background: var(--panel2);
  border: 1px solid var(--border); border-radius: 6px;
}
#epTimeline .epDot {
  position: absolute; top: 50%; transform: translate(-50%, -50%);
  width: 10px; height: 10px; border-radius: 50%; background: var(--accent);
  cursor: pointer; border: 1px solid #fff3;
}
#epTimeline .epDot:hover { background: var(--warn); }
#epLib { display: flex; flex-direction: column; gap: 2px; max-height: 130px; overflow-y: auto; }
#epLib .libRow {
  display: flex; gap: 6px; align-items: center; padding: 3px 8px;
  background: var(--panel2); border-radius: 6px; font-size: 11.5px;
}
#epLib .libRow .ln { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#epLib .libRow button { background: none; border: none; color: var(--accent); cursor: pointer; font-size: 11px; }
#epLib .libRow button.del { color: var(--muted); }
#epLib .libRow button.del:hover { color: var(--err); }
#epKeys { display: flex; flex-direction: column; gap: 2px; }
#epKeys .kf { display: flex; justify-content: space-between; align-items: center; padding: 3px 8px; background: var(--panel2); border-radius: 6px; font-size: 11.5px; }
#epKeys .kf button { background: none; border: none; color: var(--muted); cursor: pointer; }
#epKeys .kf button:hover { color: var(--err); }
/* map lightbox */
#lightbox {
  position: fixed; inset: 0; background: #000d; z-index: 60; cursor: zoom-out;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px;
}
#lightbox[hidden] { display: none; }
#lbTitle { font-size: 13px; color: var(--text); }
#lbCanvas { max-width: 90vw; max-height: 82vh; border: 1px solid var(--border); border-radius: 8px; background: #222; }
/* smaller laptop screens: give the viewer more room */
@media (max-width: 1280px) {
  body { grid-template-columns: 300px minmax(0, 1fr) 260px; }
  header .tag { display: none; }
  #modal.side #modalBox { margin-right: 276px; }
}

/* narrow viewer: the toolbar and the top-left panels would overlap —
   drop the panels below the toolbar row */
@container (max-width: 820px) {
  #statsPanel, #editPanel { top: 62px; }
  #editPanel { max-height: calc(100% - 140px); }
}
@container (max-width: 520px) {
  #statsPanel, #editPanel { top: 108px; }  /* toolbar wraps to two rows */
}

/* ---------- sprite sheet dialog ---------- */
#spriteDlg { position: fixed; inset: 0; background: var(--scrim); display: flex; align-items: center; justify-content: center; z-index: 55; }
#spriteDlg[hidden] { display: none; }
#spriteBox {
  width: min(960px, 96vw); max-height: 92vh; display: flex; flex-direction: column;
  background: var(--panel); border: 1px solid var(--border); border-radius: 14px; box-shadow: 0 12px 50px var(--shadow);
}
.spHead { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; padding: 16px 18px 10px; border-bottom: 1px solid var(--border); }
#spTitle { font-size: 15px; font-weight: 700; margin-bottom: 2px; }
.spX { background: none; border: none; color: var(--muted); font-size: 15px; cursor: pointer; padding: 2px 6px; }
.spX:hover { color: var(--err); }
.spBody { display: grid; grid-template-columns: 330px minmax(0, 1fr); min-height: 0; flex: 1; overflow: hidden; }
.spForm { padding: 6px 18px 14px; overflow-y: auto; border-right: 1px solid var(--border); }
.spPreviewCol { padding: 6px 18px 14px; overflow-y: auto; display: flex; flex-direction: column; gap: 10px; }
.spSec { font-size: 10.5px; text-transform: uppercase; letter-spacing: 1px; color: var(--muted); margin: 12px 0 6px; }
.spSec .hint { text-transform: none; letter-spacing: 0; }
.spSeg { display: grid; grid-template-columns: repeat(3, 1fr); margin-bottom: 8px; row-gap: 2px; }
.spSeg button { padding: 6px 4px; font-size: 12px; }
.spRow { display: flex; align-items: center; gap: 8px; font-size: 12.5px; margin: 7px 0; }
.spRow > span:first-child { width: 88px; flex-shrink: 0; color: var(--muted); }
.spRow select, .spRow input[type=text] { flex: 1; width: auto; min-width: 0; }
.spRow input[type=text] {
  background: var(--panel2); color: var(--text); border: 1px solid var(--border); border-radius: 6px;
  padding: 5px 8px; font-size: 12px; font-family: ui-monospace, Consolas, monospace;
}
.spRow input[type=range] { flex: 1; accent-color: var(--accent); }
.spRow output { width: 44px; text-align: right; font-variant-numeric: tabular-nums; font-size: 12px; }
.spInline { display: flex; gap: 5px; align-items: center; white-space: nowrap; cursor: pointer; }
.spSizes { display: flex; gap: 10px; flex-wrap: wrap; }
.spSizes label { display: flex; gap: 4px; align-items: center; cursor: pointer; font-variant-numeric: tabular-nums; }
#spAnims { display: flex; flex-direction: column; gap: 3px; max-height: 280px; overflow-y: auto; font-size: 12.5px; }
#spAnims label { display: flex; gap: 6px; align-items: center; cursor: pointer; }
#spAnims label span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#spAnims .hint { line-height: 1.4; }
#spPreview { display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 8px; }
.spTile {
  border: 1px solid var(--border); border-radius: 8px; padding: 4px; cursor: pointer; background: var(--panel2);
  display: flex; flex-direction: column; align-items: center; gap: 3px; font-size: 11px; color: var(--muted);
}
.spTile.on { border-color: var(--accent); color: var(--text); }
.spTile canvas, #spPlayCanvas {
  width: 96px; height: 96px; border-radius: 4px;
  background: repeating-conic-gradient(var(--panel) 0 25%, var(--hover) 0 50%) 0 0 / 12px 12px;
}
.pixelated canvas, #spPlayCanvas.pixelated { image-rendering: pixelated; }
#spPlayer { display: flex; align-items: center; gap: 12px; }
#spPlayCanvas { width: 160px; height: 160px; }
#spSummary { font-size: 12px; line-height: 1.55; color: var(--muted); }
#spSummary b { color: var(--text); font-weight: 600; }
#spSummary .warn { color: var(--warn); }
.spFoot { display: flex; align-items: center; gap: 10px; padding: 12px 18px; border-top: 1px solid var(--border); }
.spFoot button { padding: 9px 16px; border-radius: 9px; font-size: 13px; font-weight: 600; cursor: pointer; }
#spCancel { margin-left: auto; background: var(--panel2); border: 1px solid var(--border); color: var(--muted); }
#spGo { background: linear-gradient(90deg, var(--accent), var(--accent2)); border: none; color: white; }
#spGo:disabled { opacity: .45; cursor: not-allowed; }
#spProgress { display: flex; align-items: center; gap: 10px; flex: 1; font-size: 12px; color: var(--muted); }
#spProgress[hidden] { display: none; }
.spBar { flex: 1; max-width: 260px; height: 6px; border-radius: 3px; background: var(--panel2); overflow: hidden; }
#spBarFill { height: 100%; width: 0; background: linear-gradient(90deg, var(--accent), var(--accent2)); transition: width .1s; }
@media (max-width: 760px) {
  .spBody { grid-template-columns: 1fr; overflow-y: auto; }
  .spForm { border-right: none; overflow: visible; }
}
.spPreset { background: var(--panel2); border: 1px solid var(--border); color: var(--text); border-radius: 5px; padding: 1px 6px; font-size: 11px; cursor: pointer; }
.spPreset:hover { border-color: var(--accent); }
#spPitchHint { margin: -2px 0 6px 96px; line-height: 1.5; }
/* split-out objects (static props) */
.spSeg2 { display: grid; grid-template-columns: 1fr 1fr; margin-bottom: 8px; }
.spSeg2 button { padding: 6px 4px; font-size: 12px; }
.spTile.off canvas { opacity: .3; }
.spObjRow { display: flex; gap: 4px; align-items: center; width: 100%; }
.spObjRow input[type=text] {
  flex: 1; min-width: 0; background: var(--panel); color: var(--text); border: 1px solid var(--border);
  border-radius: 5px; padding: 2px 5px; font-size: 11px; font-family: ui-monospace, Consolas, monospace;
}
#spPackHint { margin: -2px 0 8px 96px; line-height: 1.45; }
#spriteBox.busy .spForm, #spriteBox.busy #spPreview { pointer-events: none; opacity: .55; }
/* models & sheets list */
.spModel { border: 1px solid var(--border); border-radius: 8px; padding: 6px 8px; margin-bottom: 6px; }
#spAnims > .spModel:only-of-type { border: none; padding: 0; }
.spModelHead { display: flex; align-items: center; gap: 6px; margin-bottom: 4px; }
.spMName { flex: 1; min-width: 0; font-size: 12px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.spMScale { display: flex; align-items: center; gap: 3px; font-size: 11px; color: var(--muted); }
.spMScale input { width: 52px; background: var(--panel2); color: var(--text); border: 1px solid var(--border); border-radius: 5px; padding: 2px 4px; font-size: 11px; }
.spMDel { background: none; border: none; color: var(--muted); cursor: pointer; padding: 0 4px; }
.spMDel:hover { color: var(--err); }
.spItems { display: flex; flex-direction: column; gap: 3px; max-height: 150px; overflow-y: auto; }
.spItem { display: flex; align-items: center; gap: 6px; font-size: 12px; cursor: pointer; }
.spIName {
  flex: 1; min-width: 0; background: var(--panel2); color: var(--text); border: 1px solid var(--border);
  border-radius: 5px; padding: 2px 6px; font-size: 11.5px; font-family: ui-monospace, Consolas, monospace;
}
.spMini {
  background: var(--panel2); border: 1px dashed var(--border); color: var(--text); border-radius: 7px;
  padding: 5px 10px; font-size: 12px; cursor: pointer; margin: 2px 0 6px;
}
.spMini:hover { border-color: var(--accent); }
/* colour variants */
.spVar { border: 1px solid var(--border); border-radius: 8px; padding: 6px 8px; margin-bottom: 6px; font-size: 12px; }
.spVarTop { display: flex; gap: 6px; margin-bottom: 4px; }
.spVarTop .vName { flex: 1; background: var(--panel2); color: var(--text); border: 1px solid var(--border); border-radius: 5px; padding: 2px 6px; font-size: 12px; font-family: ui-monospace, Consolas, monospace; }
.vDel { background: none; border: none; color: var(--muted); cursor: pointer; }
.vDel:hover { color: var(--err); }
.spVarRow { display: grid; grid-template-columns: 70px 1fr 42px; align-items: center; gap: 6px; color: var(--muted); }
.spVarRow input { accent-color: var(--accent); }
.spVarRow output { text-align: right; font-variant-numeric: tabular-nums; color: var(--text); }
.spVarOnly { display: flex; align-items: center; gap: 5px; margin-top: 4px; color: var(--muted); cursor: pointer; }
.spVarOnly input[type=color] { width: 28px; height: 20px; padding: 0; border: 1px solid var(--border); border-radius: 4px; background: none; }
.spVarOnly input[type=number] { width: 48px; background: var(--panel2); color: var(--text); border: 1px solid var(--border); border-radius: 5px; padding: 1px 4px; }
#spVarStrip { display: flex; flex-wrap: wrap; gap: 8px; }
#spVarStrip:empty { display: none; }
.spVarTile { display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 11px; color: var(--muted); }
.spVarTile canvas { width: 72px; height: 72px; border-radius: 6px; background: repeating-conic-gradient(var(--panel) 0 25%, var(--hover) 0 50%) 0 0 / 10px 10px; }
#spVarStrip.pixelated canvas { image-rendering: pixelated; }
/* library picker */
#spriteBox { position: relative; }
#spPicker, #spAnimPicker {
  position: absolute; inset: 56px 12px 12px; z-index: 5; background: var(--panel); border: 1px solid var(--border);
  border-radius: 12px; box-shadow: 0 10px 40px var(--shadow); display: flex; flex-direction: column; padding: 12px;
}
#spPicker[hidden], #spAnimPicker[hidden] { display: none; }
#spAnimList { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 2px; font-size: 12.5px; }
.spAnimGroup { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 10px 0 3px; }
.spAnimGroup:first-child { margin-top: 0; }
.spAnimRow { display: flex; align-items: center; gap: 8px; padding: 5px 8px; border-radius: 7px; cursor: pointer; }
.spAnimRow:hover { background: var(--hover); }
.spAnimRow input { accent-color: var(--accent); }
.spAnimRow .hint { margin-left: auto; white-space: nowrap; }
.spFileBtn { padding: 8px 14px; border-radius: 8px; font-size: 12.5px; font-weight: 600; cursor: pointer; border: 1px dashed var(--border); background: var(--panel2); color: var(--text); }
.spFileBtn:hover { border-color: var(--accent); }
.spGrow { flex: 1; }
.spPickHead { font-size: 13px; margin-bottom: 8px; }
#spPickGrid { flex: 1; overflow-y: auto; display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 8px; align-content: start; }
.spPick {
  display: flex; flex-direction: column; gap: 2px; align-items: stretch; text-align: left; padding: 6px;
  border: 2px solid var(--border); border-radius: 9px; background: var(--panel2); color: var(--text); cursor: pointer; font-size: 11.5px;
}
.spPick img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 6px; background: var(--panel); }
.spPick span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.spPick.sel { border-color: var(--accent); background: var(--hover); }
.spPickFoot { display: flex; justify-content: flex-end; gap: 8px; margin-top: 10px; }
.spPickFoot button { padding: 8px 14px; border-radius: 8px; font-size: 12.5px; font-weight: 600; cursor: pointer; border: 1px solid var(--border); background: var(--panel2); color: var(--text); }
#spPickAdd, #spAnimAdd { background: linear-gradient(90deg, var(--accent), var(--accent2)); color: white; border: none; }
#spPickAdd:disabled, #spAnimAdd:disabled { opacity: .45; cursor: not-allowed; }
#spBgColor { width: 34px; height: 26px; padding: 0; border: 1px solid var(--border); border-radius: 5px; background: none; flex: none; }
.spPrevErr { grid-column: 1 / -1; color: var(--err); font-size: 12.5px; padding: 12px; border: 1px dashed var(--err); border-radius: 8px; }
