/* Demolisher · Alpha Forge
   Dark, flat, and quiet. The user is judging greyscale height data and a lit
   material preview, so the chrome stays desaturated and out of the way -- one
   accent colour, used only for the things that act. */

:root {
  --bg:        #0a0c0f;
  --panel:     #101318;
  --panel-2:   #151920;
  --line:      #212831;
  --line-soft: #1a1f27;
  --text:      #dbe2ea;
  --text-dim:  #8a95a3;
  --text-faint:#5d6875;
  --accent:    #ff5c2b;
  --accent-dim:#7a2c14;
  --cyan:      #22d3ee;
  --green:     #4ade80;
  --amber:     #fbbf24;
  --radius: 7px;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

/* The hidden attribute has to beat our own layout rules.
   The browser hides [hidden] elements with a UA rule of `display: none`, and a
   UA rule loses to ANY author rule that sets display. So `.busy { display: grid }`
   or `.field { display: flex }` silently defeats `el.hidden = true` -- which is
   how the loading overlay ended up permanently on screen, showing its own
   placeholder text, with nothing actually loading. */
[hidden] { display: none !important; }

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

/* ── Top bar ─────────────────────────────────────────────────────────────── */

.bar {
  height: 54px;
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 0 16px;
  background: linear-gradient(180deg, #12161c, #0d1015);
  border-bottom: 1px solid var(--line);
}

.brand { display: flex; align-items: center; gap: 11px; }

.mark {
  width: 22px; height: 22px;
  background: var(--accent);
  clip-path: polygon(50% 0, 100% 50%, 50% 100%, 0 50%);
  box-shadow: 0 0 18px rgba(255, 92, 43, .45);
}

.brand-text { display: flex; flex-direction: column; line-height: 1.1; }
.brand-text strong { font-size: 13px; letter-spacing: .16em; }
.brand-text span { font-size: 11px; color: var(--text-faint); letter-spacing: .1em; }

.bar-status {
  flex: 1;
  font-family: var(--mono);
  font-size: 11.5px;
  color: var(--text-faint);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.bar-status.ok   { color: var(--green); }
.bar-status.warn { color: var(--amber); }
.bar-status.err  { color: var(--accent); }

.bar-actions { display: flex; gap: 8px; }

/* ── Layout ──────────────────────────────────────────────────────────────── */

.layout {
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr) 300px;
  height: calc(100% - 54px - 116px);   /* bar + library strip */
}

/* ── Library strip ───────────────────────────────────────────────────────── */

.library {
  height: 116px;
  border-top: 1px solid var(--line);
  background: var(--panel);
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.lib-head {
  display: flex; justify-content: space-between; align-items: baseline;
  padding: 6px 14px 2px;
  font-size: 10.5px; letter-spacing: .16em; text-transform: uppercase;
  color: var(--text-faint);
}
.lib-usage { letter-spacing: 0; text-transform: none; font-family: var(--mono); font-size: 10.5px; }

.lib-add {
  margin-left: 8px; padding: 1px 7px;
  font-size: 10px; letter-spacing: .04em; text-transform: none;
  border-radius: 4px; border: 1px solid var(--line);
  background: var(--panel-2); color: var(--text-dim);
  vertical-align: 1px;
}
.lib-add:hover { border-color: var(--accent-dim); color: var(--text); }

.lib-strip {
  flex: 1;
  display: flex; gap: 8px;
  padding: 4px 14px 10px;
  overflow-x: auto; overflow-y: hidden;
  min-width: 0;
}
.lib-strip:empty::after {
  content: "Nothing saved yet — exporting an alpha keeps it here.";
  color: var(--text-faint); font-size: 12px; align-self: center;
}

.lib-item {
  position: relative; flex: 0 0 auto;
  width: 74px; padding: 0;
  background: var(--panel-2); border: 1px solid var(--line);
  border-radius: var(--radius); cursor: pointer; overflow: hidden;
  display: flex; flex-direction: column;
}
.lib-item img {
  width: 100%; height: 56px; object-fit: cover; display: block;
  background: #0d1014;
}
.lib-item .lib-name {
  font-size: 9.5px; line-height: 1.3; padding: 3px 4px;
  color: var(--text-dim);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.lib-item:hover { border-color: #39434f; }
.lib-item.on { border-color: var(--accent); }
.lib-item.on .lib-name { color: var(--text); }

/* The working session is pinned first and reads as live, not stored. */
.lib-item.current { border-style: dashed; border-color: var(--accent-dim); }
.lib-item.current.dirty::after {
  content: ""; position: absolute; top: 4px; right: 4px;
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--accent); box-shadow: 0 0 0 2px var(--panel-2);
}
.lib-del {
  position: absolute; top: 3px; right: 3px;
  width: 16px; height: 16px; padding: 0; line-height: 1;
  border-radius: 4px; border: none;
  background: rgba(10,12,15,.75); color: var(--text-faint);
  font-size: 12px; opacity: 0; transition: opacity .12s;
}
.lib-item:hover .lib-del { opacity: 1; }
.lib-del:hover { background: var(--accent); color: #120602; }

.panel {
  background: var(--panel);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.panel:last-child { border-right: none; border-left: 1px solid var(--line); }

.panel-head {
  padding: 12px 16px;
  font-size: 11px;
  letter-spacing: .16em;
  text-transform: uppercase;
  color: var(--text-faint);
  border-bottom: 1px solid var(--line-soft);
}

.panel-body {
  padding: 14px 16px 40px;
  overflow-y: auto;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* ── Stage ───────────────────────────────────────────────────────────────── */

.stage { display: flex; flex-direction: column; min-width: 0; background: #07090b; }

.viewport {
  position: relative;
  flex: 1;
  min-height: 0;
  background:
    radial-gradient(120% 90% at 50% 0%, #1b222c 0%, #0a0d11 55%, #07090b 100%);
}
.viewport canvas { display: block; width: 100%; height: 100%; }

.vp-tools { position: absolute; top: 12px; z-index: 2; display: flex; gap: 8px; }
.vp-tools.tl { left: 12px; align-items: center; }
.vp-tools.tr { right: 12px; flex-direction: column; align-items: flex-end; }

/* Floating viewport chrome: same frosted treatment as the geometry switch, so
   the controls over the render read as one layer. */
.vp-select, .vp-btn {
  background: rgba(12,15,19,.82);
  backdrop-filter: blur(8px);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--text-dim);
  font: inherit;
  font-size: 11.5px;
  padding: 5px 9px;
  cursor: pointer;
}
.vp-select { padding-right: 24px; width: auto; }
.vp-btn:hover, .vp-select:hover { border-color: #2c3540; color: var(--text); }

.vp-hint {
  position: absolute; left: 12px; bottom: 12px; z-index: 2;
  font-size: 11px; color: var(--text-faint);
  background: rgba(12,15,19,.72);
  backdrop-filter: blur(6px);
  border-radius: var(--radius);
  padding: 4px 9px;
  pointer-events: none;
  transition: opacity .25s;
}

.vp-empty {
  position: absolute; inset: 0;
  display: grid; place-items: center;
  text-align: center; color: var(--text-faint);
  pointer-events: none;
}
.vp-empty h2 { margin: 0 0 6px; font-size: 15px; font-weight: 600; color: var(--text-dim); }
.vp-empty p  { margin: 0; font-size: 13px; }

.channels {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 1px;
  background: var(--line);
  border-top: 1px solid var(--line);
  padding: 1px 0 0;
}
.channels figure { margin: 0; background: var(--panel); position: relative; }
.channels canvas {
  display: block;
  width: 100%;
  aspect-ratio: 1;
  object-fit: contain;
  background: #0d1014;
  image-rendering: auto;
}
.channels figcaption {
  position: absolute; left: 0; right: 0; bottom: 0;
  padding: 5px 8px;
  font-size: 10.5px;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--text-dim);
  background: linear-gradient(180deg, transparent, rgba(10,12,15,.92));
  display: flex; justify-content: space-between;
}
.channels figcaption em { font-family: var(--mono); font-style: normal; color: var(--text-faint); }

/* ── Controls ────────────────────────────────────────────────────────────── */

.field { display: flex; flex-direction: column; gap: 5px; }
.field > span {
  font-size: 11.5px;
  color: var(--text-dim);
  display: flex; justify-content: space-between; align-items: baseline;
}
.field > span b {
  font-family: var(--mono); font-weight: 500; font-size: 11px; color: var(--text);
}
.field > span em { font-style: normal; color: var(--text-faint); }

select, input[type=text], input[type=password] {
  width: 100%;
  padding: 7px 9px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--text);
  font: inherit;
  font-size: 13px;
}
select:focus, input:focus { outline: none; border-color: #33404e; }
select { appearance: none; background-image:
  linear-gradient(45deg, transparent 50%, var(--text-faint) 50%),
  linear-gradient(135deg, var(--text-faint) 50%, transparent 50%);
  background-position: calc(100% - 15px) 14px, calc(100% - 10px) 14px;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  padding-right: 26px;
}

.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

/* Generate and Upload are equal-weight routes into the tool -- one costs an API
   call, one costs nothing, and neither is a footnote to the other. */
.btn-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

/* Colour input: a swatch, not the chunky default control. */
.field.colour { flex-direction: row; align-items: center; justify-content: space-between; }
.field.colour > span { flex: 1; }
input[type=color] {
  appearance: none;
  width: 46px; height: 24px; padding: 0;
  background: none;
  border: 1px solid var(--line);
  border-radius: 5px;
  cursor: pointer;
}
input[type=color]::-webkit-color-swatch-wrapper { padding: 2px; }
input[type=color]::-webkit-color-swatch { border: none; border-radius: 3px; }
input[type=color]::-moz-color-swatch { border: none; border-radius: 3px; }
input[type=color]:hover { border-color: #3a4552; }

/* The channel strip labels pick up each mask's colour, so the thumbnail, the
   3D overlay and the panel heading all agree at a glance. */
figure[data-mask=a] figcaption em { color: var(--mask-a, var(--text-faint)); }
figure[data-mask=b] figcaption em { color: var(--mask-b, var(--text-faint)); }

input[type=range] {
  appearance: none;
  width: 100%;
  height: 18px;
  background: transparent;
  cursor: ew-resize;
}
input[type=range]::-webkit-slider-runnable-track {
  height: 3px; border-radius: 2px; background: #262e38;
}
input[type=range]::-webkit-slider-thumb {
  appearance: none;
  width: 13px; height: 13px; margin-top: -5px;
  border-radius: 50%;
  background: var(--text);
  border: 2px solid var(--panel);
  box-shadow: 0 0 0 1px #39434f;
}
input[type=range]:active::-webkit-slider-thumb { background: var(--accent); }
input[type=range]::-moz-range-track { height: 3px; border-radius: 2px; background: #262e38; }
input[type=range]::-moz-range-thumb {
  width: 11px; height: 11px; border-radius: 50%;
  background: var(--text); border: 2px solid var(--panel);
}

button {
  font: inherit;
  font-size: 13px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
  padding: 7px 13px;
  cursor: pointer;
  transition: background .12s, border-color .12s;
}
button:hover:not(:disabled) { background: #1b212a; border-color: #2c3540; }
button:disabled { opacity: .4; cursor: not-allowed; }

button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #120602;
  font-weight: 600;
}
button.primary:hover:not(:disabled) { background: #ff734a; border-color: #ff734a; }
button.big { padding: 11px; font-size: 14px; margin-top: 4px; }
button.ghost { background: transparent; }

button.link {
  background: none; border: none; padding: 0;
  color: var(--text-faint); font-size: 11.5px;
  text-decoration: underline; text-underline-offset: 2px;
}
button.link:hover { color: var(--text-dim); background: none; }

.seg { display: flex; background: var(--panel-2); border: 1px solid var(--line); border-radius: var(--radius); padding: 2px; }
.seg button {
  flex: 1; border: none; background: transparent; padding: 6px 8px;
  font-size: 12.5px; color: var(--text-dim); border-radius: 5px;
}
.seg button.on { background: #262e38; color: var(--text); }
.seg.small { background: rgba(12,15,19,.82); backdrop-filter: blur(8px); }
.seg.small button { padding: 4px 10px; font-size: 11.5px; }

.chk { display: flex; align-items: center; gap: 8px; font-size: 12.5px; color: var(--text-dim); cursor: pointer; }
.chk input { accent-color: var(--accent); width: 14px; height: 14px; }
.vp-tools .chk {
  background: rgba(12,15,19,.82); backdrop-filter: blur(8px);
  border: 1px solid var(--line); border-radius: var(--radius);
  padding: 6px 10px;
}

.note { margin: 0; font-size: 11.5px; color: var(--text-faint); line-height: 1.45; }
.note.warn { color: var(--amber); opacity: .85; }

.row-between { display: flex; justify-content: space-between; align-items: center; gap: 8px; }

hr { border: none; border-top: 1px solid var(--line-soft); margin: 4px 0; }

.group { display: flex; flex-direction: column; gap: 12px; }

details { border-top: 1px solid var(--line-soft); padding-top: 10px; }
details:first-of-type { border-top: none; padding-top: 0; }
details summary {
  cursor: pointer; list-style: none;
  font-size: 11px; letter-spacing: .14em; text-transform: uppercase;
  color: var(--text-dim); padding: 3px 0 9px;
  display: flex; align-items: center; gap: 8px;
}
details summary::-webkit-details-marker { display: none; }
details summary::before {
  content: "›"; font-size: 14px; color: var(--text-faint);
  transition: transform .15s; display: inline-block;
}
details[open] summary::before { transform: rotate(90deg); }
details > *:not(summary) { margin-bottom: 11px; }
details .ch {
  font-family: var(--mono); font-style: normal; font-size: 10px;
  padding: 1px 5px; border-radius: 3px; letter-spacing: 0;
}
.ch.g { background: rgba(74,222,128,.14); color: var(--green); }
.ch.b { background: rgba(34,211,238,.14); color: var(--cyan); }
.ch.a { background: rgba(251,191,36,.14); color: var(--amber); }

.readout {
  font-family: var(--mono); font-size: 11.5px;
  background: var(--panel-2); border: 1px solid var(--line-soft);
  border-radius: var(--radius); padding: 8px 10px; color: var(--text-dim);
  white-space: pre-line;
}
.readout.small { font-size: 11px; padding: 6px 9px; }
.readout .bad { color: var(--accent); }
.readout .good { color: var(--green); }

/* ── Reference drop ──────────────────────────────────────────────────────── */

.drop {
  position: relative;
  height: 120px;
  border: 1px dashed #2b333e;
  border-radius: var(--radius);
  background: var(--panel-2);
  display: grid; place-items: center;
  cursor: pointer;
  overflow: hidden;
  transition: border-color .12s, background .12s;
}
.drop:hover, .drop.over { border-color: var(--accent); background: #171b21; }
.drop img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; display: none; background: #0b0e12; }
.drop img.on { display: block; }
.drop img.on + .drop-text { display: none; }
.drop-text { text-align: center; color: var(--text-faint); }
.drop-text strong { display: block; font-size: 12.5px; font-weight: 500; color: var(--text-dim); }
.drop-text em { font-style: normal; font-size: 11.5px; }

/* Three ORM-standard slots: base colour, normal, ORM. */
.slots { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
/* The slot NAME stays put and the loaded file goes on a second line beneath.
   Overwriting the name with the filename left three identical-looking boxes
   with no way to tell which channel each one fed. */
.slot {
  padding: 8px 6px; text-align: center;
  background: var(--panel-2); border: 1px solid var(--line);
  border-radius: var(--radius); color: var(--text-dim); cursor: pointer;
  display: flex; flex-direction: column; gap: 1px; min-width: 0;
}
.slot > span,
.slot > em {
  display: block; min-width: 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.slot > span { font-size: 11.5px; }
.slot > em {
  font-style: normal; font-size: 9.5px; line-height: 1.35;
  color: var(--text-faint); min-height: 13px;
}
.slot:hover { border-color: #2c3540; }
.slot.on { border-color: var(--accent-dim); color: var(--text); }
.slot.on > em { color: var(--accent); opacity: .85; }

/* ── Dialog, busy, toast ─────────────────────────────────────────────────── */

dialog {
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 11px;
  padding: 0;
  width: min(440px, 92vw);
  box-shadow: 0 24px 70px rgba(0,0,0,.6);
}
dialog::backdrop { background: rgba(4,6,8,.72); backdrop-filter: blur(3px); }
dialog form { padding: 20px; display: flex; flex-direction: column; gap: 13px; }
dialog h2 { margin: 0; font-size: 15px; font-weight: 600; }
dialog menu { display: flex; justify-content: flex-end; gap: 8px; margin: 4px 0 0; padding: 0; }

#busy {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(6,8,11,.74);
  backdrop-filter: blur(3px);
  display: grid; place-items: center;
}
.busy-card {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 11px; padding: 26px 34px;
  display: flex; flex-direction: column; align-items: center; gap: 14px;
  box-shadow: 0 24px 70px rgba(0,0,0,.6);
}
.busy-card p { margin: 0; font-size: 13px; color: var(--text-dim); }
.spin {
  width: 26px; height: 26px; border-radius: 50%;
  border: 2px solid #2a323d; border-top-color: var(--accent);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

#toast {
  position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%);
  z-index: 60; max-width: min(560px, 90vw);
  background: var(--panel-2); border: 1px solid var(--line);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius); padding: 11px 15px;
  font-size: 13px; color: var(--text);
  box-shadow: 0 14px 40px rgba(0,0,0,.5);
  cursor: pointer;
  line-height: 1.45;
}
#toast:hover { border-color: #2c3540; }
#toast.ok { border-left-color: var(--green); cursor: default; }

@media (max-width: 1180px) {
  .layout { grid-template-columns: 260px minmax(0,1fr) 260px; }
  .channels { grid-template-columns: repeat(5, 1fr); }
}
