:root {
  --bg: #16171a;
  --panel: #1c1e22;
  --panel-2: #23262b;
  --line: #2e3238;
  --text: #e6e8ea;
  --muted: #8b9199;
  --accent: #f2b33d;
  --accent-dim: #6b5320;
  --radius: 6px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 13px/1.45 "Segoe UI", system-ui, -apple-system, sans-serif;
  overflow: hidden;
}

#app {
  display: grid;
  grid-template-columns: 268px 1fr 244px;
  height: 100vh;
}

/* ---- panels ---- */
.panel {
  background: var(--panel);
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}
#left { border-right: 1px solid var(--line); }
#right { border-left: 1px solid var(--line); }

.panel h2 {
  margin: 0;
  padding: 10px 12px 8px;
  font-size: 11px;
  letter-spacing: .09em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 600;
}

.brand {
  padding: 12px 12px 8px;
  border-bottom: 1px solid var(--line);
}
.brand b { font-size: 15px; letter-spacing: .02em; }
.brand span { color: var(--muted); font-size: 11px; display: block; margin-top: 1px; }

/* ---- search + tabs ---- */
#search {
  width: calc(100% - 20px);
  margin: 10px;
  padding: 7px 9px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--text);
  font: inherit;
  outline: none;
}
#search:focus { border-color: var(--accent-dim); }

#tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  padding: 0 10px 8px;
}
#tabs button {
  flex: 1 1 auto;
  padding: 5px 8px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--muted);
  font: inherit;
  font-size: 11.5px;
  cursor: pointer;
}
#tabs button:hover { color: var(--text); }
#tabs button.on { background: var(--accent); border-color: var(--accent); color: #1a1a1a; font-weight: 600; }

#slots {
  padding: 0 10px 8px;
  display: none;
}
#slots.show { display: block; }
#slots select {
  width: 100%;
  padding: 5px 6px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--text);
  font: inherit;
}

/* ---- list ---- */
#list { flex: 1; overflow-y: auto; padding: 0 6px 10px; }
.item {
  padding: 6px 8px;
  border-radius: var(--radius);
  cursor: pointer;
  display: flex;
  align-items: baseline;
  gap: 6px;
}
.item:hover { background: var(--panel-2); }
.item.on { background: var(--accent-dim); }
.item .n { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .a { color: var(--muted); font-size: 10.5px; flex: none; }
.item.on .a { color: #d9c08a; }
#count { padding: 4px 12px 8px; color: var(--muted); font-size: 11px; }

/* ---- viewport ---- */
#center { position: relative; display: flex; flex-direction: column; min-width: 0; }
#view { flex: 1; position: relative; min-height: 0; overflow: hidden; }
/* Absolute + CSS-driven size, so changing the drawing-buffer resolution can
   never feed back into layout (that loop made the canvas grow without bound). */
#view canvas {
  position: absolute;
  inset: 0;
  display: block;
  width: 100% !important;
  height: 100% !important;
}

#hud {
  position: absolute;
  left: 12px; top: 10px;
  pointer-events: none;
  text-shadow: 0 1px 3px #000a;
}
#hud b { font-size: 16px; }
#hud span { display: block; color: var(--muted); font-size: 11px; }

#empty {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  color: var(--muted); font-size: 14px; pointer-events: none;
}

/* ---- transport ---- */
#transport {
  border-top: 1px solid var(--line);
  background: var(--panel);
  padding: 8px 12px;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
#transport select { max-width: 260px; }
#scrub { flex: 1 1 180px; min-width: 120px; }
#time { color: var(--muted); font-variant-numeric: tabular-nums; font-size: 11.5px; min-width: 84px; }

button, select, input[type=text], input[type=number] {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--text);
  font: inherit;
  padding: 5px 9px;
  cursor: pointer;
  outline: none;
}
button:hover { border-color: #3d434b; }
button.primary { background: var(--accent); border-color: var(--accent); color: #1a1a1a; font-weight: 600; }
button.primary:hover { filter: brightness(1.08); }

input[type=range] { accent-color: var(--accent); cursor: pointer; }
input[type=color] {
  width: 100%; height: 26px; padding: 1px;
  background: var(--panel-2); border: 1px solid var(--line);
  border-radius: var(--radius); cursor: pointer;
}
input[type=checkbox] { accent-color: var(--accent); cursor: pointer; }

/* ---- right panel rows ---- */
.rows { overflow-y: auto; padding: 0 12px 16px; flex: 1; }
.row { margin-bottom: 11px; }
.row label {
  display: block;
  color: var(--muted);
  font-size: 11px;
  margin-bottom: 3px;
  text-transform: uppercase;
  letter-spacing: .05em;
}
.row.inline { display: flex; align-items: center; gap: 7px; }
.row.inline label { margin: 0; text-transform: none; letter-spacing: 0; font-size: 12px; color: var(--text); }
.row input[type=range] { width: 100%; }
.row select, .row input[type=number] { width: 100%; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.grid3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 6px; }

/* ---- pose rows (one joint, three axes) ---- */
.pose-joint { margin-bottom: 9px; }
.pose-joint > b {
  display: block;
  color: var(--muted);
  font-size: 11px;
  margin-bottom: 3px;
  text-transform: uppercase;
  letter-spacing: .05em;
  font-weight: 600;
}
.pose-axis {
  display: grid;
  grid-template-columns: 14px 1fr 52px;
  align-items: center;
  gap: 6px;
  margin-bottom: 2px;
}
.pose-axis span { color: var(--muted); font-size: 11px; text-align: center; }
.pose-axis input[type=range] { width: 100%; }
.pose-axis input[type=number] {
  width: 100%;
  font-size: 11px;
  padding: 2px 4px;
}
.pose-joint.off { display: none; }
hr { border: 0; border-top: 1px solid var(--line); margin: 13px 0; }

.hint { color: var(--muted); font-size: 11px; margin-top: -4px; }

#variants { max-height: 150px; overflow-y: auto; }
#variants div {
  display: flex; align-items: center; gap: 6px;
  padding: 2px 0; font-size: 12px;
}
#variants div span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #33373d; border-radius: 5px; }
::-webkit-scrollbar-thumb:hover { background: #424851; }

/* ---- list thumbnails ---- */
.item { align-items: center; gap: 8px; }
.item .th {
  width: 34px;
  height: 34px;
  flex: none;
  object-fit: contain;
  background: #202329;
  border-radius: 4px;
}

/* ---- colour swatches ---- */
#swatches {
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  gap: 3px;
}
.sw {
  padding: 0;
  aspect-ratio: 1;
  min-height: 18px;
  border: 1px solid #00000055;
  border-radius: 3px;
  cursor: pointer;
}
.sw:hover { outline: 1px solid var(--text); }
.sw.on { outline: 2px solid var(--accent); outline-offset: 1px; }
.sw-none {
  background: var(--panel-2);
  color: var(--muted);
  font-size: 11px;
  line-height: 1;
  border-color: var(--line);
}

/* ---- layers (the way Photoshop lists them) ---- */
#proplist { margin: 0 0 10px; border: 1px solid var(--line); border-radius: 4px; }
#proplist:empty { display: none; }
.layer {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 3px 4px 3px 2px;
  border-left: 2px solid transparent;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
  font-size: 11.5px;
  user-select: none;
}
.layer:last-child { border-bottom: 0; }
.layer:hover { background: rgba(255, 255, 255, .04); }
.layer.on { border-left-color: var(--accent); background: rgba(255, 255, 255, .08); }
.layer.hidden-layer .name, .layer.hidden-layer .thumb { opacity: .45; }
.layer .thumb { flex: none; width: 24px; height: 24px; object-fit: contain; border-radius: 2px; background: rgba(0, 0, 0, .25); }
.layer .name { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.layer.on .name { color: var(--accent); }
.layer .ico {
  flex: none;
  background: transparent;
  border: 0;
  padding: 0 3px;
  color: var(--muted);
  font-size: 11px;
  line-height: 1;
  cursor: pointer;
}
.layer .ico.on { color: var(--accent); }
.layer .pct { flex: none; color: var(--muted); font-size: 10px; }
.layer .rename { flex: 1 1 auto; min-width: 0; font-size: 11px; padding: 1px 4px; }
.layer.dropto { box-shadow: inset 0 2px 0 var(--accent); }
.layer.dragging { opacity: .5; }

/* ---- mode tabs (the way Blockbench lays them out) ---- */
#modetabs {
  display: flex;
  flex: none;
  border-bottom: 1px solid var(--line);
}
#modetabs button {
  flex: 1 1 0;
  min-width: 0;
  background: transparent;
  border: 0;
  border-radius: 0;
  border-bottom: 2px solid transparent;
  color: var(--muted);
  font-size: 11px;
  padding: 10px 2px 8px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: pointer;
}
#modetabs button:hover { color: var(--text); }
#modetabs button.on { color: var(--text); border-bottom-color: var(--accent); }
#right .mode { display: none; padding-top: 12px; }
#right .mode.on { display: block; }

/* ---- section headings and folding sections ---- */
.panel h2.sech { padding: 4px 0 8px; }
#placebox { border-top: 1px solid var(--line); margin-top: 12px; padding-top: 10px; }
details.sec { border-top: 1px solid var(--line); padding-bottom: 4px; }
details.sec:first-child { border-top: 0; }
details.sec > summary {
  list-style: none;
  cursor: pointer;
  user-select: none;
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 10px 0 9px;
  font-size: 11px;
  letter-spacing: .09em;
  text-transform: uppercase;
  color: var(--muted);
}
details.sec > summary::-webkit-details-marker { display: none; }
details.sec > summary::before { content: '▸'; font-size: 10px; transition: transform .15s; }
details.sec[open] > summary::before { transform: rotate(90deg); }
details.sec > summary:hover, details.sec[open] > summary { color: var(--text); }
details.sec > summary .val { margin-left: auto; text-transform: none; letter-spacing: 0; }
#right .mode.on { padding-top: 10px; }

/* ---- view: empty state and the picture button ---- */
#empty b { display: block; font-size: 15px; color: var(--text); font-weight: 600; }
#empty span { display: block; margin-top: 4px; font-size: 12px; }
#viewtools { position: absolute; top: 12px; right: 12px; display: flex; gap: 6px; z-index: 5; }
#viewtools button { padding: 7px 12px; }
#vtcenter { font-size: 15px; line-height: 1; padding: 6px 10px; }

/* ---- guide ---- */
.brand { position: relative; padding-right: 44px; }
.helpbtn {
  position: absolute;
  top: 50%;
  right: 12px;
  transform: translateY(-50%);
  width: 26px;
  height: 26px;
  border-radius: 50%;
  padding: 0;
  font-weight: 700;
}
.overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(0, 0, 0, .6);
}
.overlay[hidden] { display: none; }
.card {
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  overflow: auto;
  padding: 20px 22px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, .5);
}
.card h3 { margin: 0 0 12px; font-size: 18px; }
.card ol.steps { margin: 0 0 12px; padding-left: 22px; }
.card ol.steps li { margin-bottom: 8px; }
.card .muted { margin: 0 0 12px; color: var(--muted); font-size: 12px; }
.card details.keys > summary { cursor: pointer; color: var(--accent); font-size: 12px; margin-bottom: 6px; }
.card table { width: 100%; border-collapse: collapse; font-size: 12px; }
.card td { padding: 3px 0; vertical-align: top; }
.card td:first-child { padding-right: 14px; white-space: nowrap; color: var(--accent); }
.card .primary { width: 100%; margin-top: 14px; padding: 9px; }

/* ---- crop frame: what the saved picture covers ---- */
#cropframe {
  position: absolute;
  z-index: 1;
  pointer-events: none;
  outline: 1px solid rgba(255, 255, 255, .5);
  box-shadow: 0 0 0 100vmax rgba(0, 0, 0, .42);
}
#hud { z-index: 4; }
#empty { z-index: 4; flex-direction: column; text-align: center; }

/* ---- saved views ---- */
.viewrow { display: flex; gap: 4px; margin-bottom: 4px; }
.viewrow button:first-child { flex: 1 1 auto; min-width: 0; text-align: left; }
