/* Primitive (primitive-art.html). Liquid-glass UI, minimal: a blurred copy of the
   current image fills the backdrop, and the panel + both image cards are borderless
   glass over it (js/primitive-art.js adds edge refraction on Chromium).
   See reference/primitive-art-page.md. */
:root {
  color-scheme: dark;
  --bg: #0d0e12;
  --ink: #ffffff;
  --ink-2: rgba(255, 255, 255, 0.72);
  --ink-3: rgba(255, 255, 255, 0.46);
  --line: rgba(255, 255, 255, 0.14);
  --accent: #ff7a45;
  --glass-a: 0.22;                                /* glass tint */
  --radius: 26px;
  --gutter: 20px;
  --mono: ui-monospace, 'SF Mono', 'JetBrains Mono', Menlo, monospace;
  font-family: 'Manrope', ui-sans-serif, system-ui, -apple-system, 'Segoe UI', sans-serif;
  color: var(--ink);
  background: var(--bg);
}

* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; } /* no background here: it would paint over .backdrop (z-index -1); :root carries --bg */
button, input { font: inherit; color: inherit; }
[hidden] { display: none !important; }
.lg-defs { position: absolute; width: 0; height: 0; overflow: hidden; }

/* ---------------------------------------------------------------- backdrop */
.backdrop { position: fixed; inset: 0; overflow: hidden; z-index: -1; }
.backdrop img {
  position: absolute; inset: -10%; width: 120%; height: 120%; object-fit: cover;
  filter: blur(48px) saturate(1.4) brightness(0.62);
}
.backdrop .drift { position: absolute; inset: 0; width: 100%; height: 100%; filter: blur(2px); }
/* a little darkness at the edges keeps white text readable on bright images */
.backdrop::after {
  content: ''; position: absolute; inset: 0;
  background: radial-gradient(120% 90% at 60% 40%, transparent 30%, rgba(5, 6, 10, 0.55));
}

/* Glass: no border — a faint tint, a blur of what's behind, and light catching the rim. */
.glass {
  background: rgba(16, 18, 26, var(--glass-a));
  border: 0;
  border-radius: var(--radius);
  box-shadow:
    0 18px 50px rgba(0, 0, 0, 0.28),
    inset 1.5px 1.5px 1px rgba(255, 255, 255, 0.32),
    inset -1px -1px 1px rgba(255, 255, 255, 0.1),
    inset 0 0 22px rgba(255, 255, 255, 0.05);
  backdrop-filter: blur(22px) saturate(1.4);
  -webkit-backdrop-filter: blur(22px) saturate(1.4);
}

.app {
  display: grid; grid-template-columns: 300px 1fr; gap: var(--gutter);
  min-height: 100vh; padding: var(--gutter);
}

/* ---------------------------------------------------------------- panel */
.panel {
  padding: 22px 20px 20px;
  display: flex; flex-direction: column; gap: 22px;
  position: sticky; top: var(--gutter);
  height: calc(100vh - 2 * var(--gutter));
  overflow-y: auto;
}
.panel > * { flex-shrink: 0; }

.brand { display: flex; align-items: flex-start; gap: 10px; }
.brand h1 { margin: 0; font-size: 19px; font-weight: 700; letter-spacing: -0.01em; }
.brand p { margin: 3px 0 0; color: var(--ink-3); font-size: 12.5px; line-height: 1.4; }
.back {
  display: grid; place-items: center; flex-shrink: 0;
  width: 30px; height: 30px; margin-top: -2px; border-radius: 999px;
  color: var(--ink); background: rgba(255, 255, 255, 0.08);
  box-shadow: inset 1px 1px 1px rgba(255, 255, 255, 0.22);
  transition: background .15s;
}
.back:hover { background: rgba(255, 255, 255, 0.16); }
.back:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.back svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

fieldset { border: 0; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 20px; min-width: 0; }
fieldset:disabled { opacity: 0.5; }

/* drop zone: thumbnail + name on one row */
.drop {
  position: relative;
  display: flex; align-items: center; gap: 12px;
  min-height: 64px; padding: 8px;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.06);
  box-shadow: inset 0 0 0 1px var(--line);
  cursor: pointer;
  transition: background .15s, box-shadow .15s;
}
.drop:hover, .drop.is-drag { background: rgba(255, 255, 255, 0.11); box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.3); }
.drop:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: 2px; }
.drop input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.drop img { width: 48px; height: 48px; object-fit: cover; border-radius: 12px; display: block; }
.drop-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; padding-left: 4px; }
.drop-name { font-size: 13px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.drop-hint { font-size: 12px; color: var(--ink-3); }

.field { display: flex; flex-direction: column; gap: 10px; }
.field-head { display: flex; justify-content: space-between; align-items: baseline; font-size: 13px; font-weight: 600; }
.field-head output { font-family: var(--mono); font-size: 12px; color: var(--ink-2); font-weight: 400; }
.note { margin: 0; font-size: 12px; color: var(--ink-3); line-height: 1.45; }

input[type='range'] {
  -webkit-appearance: none; appearance: none;
  width: 100%; height: 4px; border-radius: 2px; background: rgba(255, 255, 255, 0.16); outline: none;
}
input[type='range']::-webkit-slider-thumb {
  -webkit-appearance: none; width: 18px; height: 18px; border-radius: 50%;
  background: #fff; border: 0; cursor: pointer;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.35);
}
input[type='range']::-moz-range-thumb {
  width: 18px; height: 18px; border-radius: 50%; background: #fff; border: 0; cursor: pointer;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.35);
}
input[type='range']:focus-visible { box-shadow: 0 0 0 3px rgba(255, 122, 69, 0.45); }

.seg {
  display: flex; padding: 3px; border-radius: 999px;
  background: rgba(255, 255, 255, 0.07); box-shadow: inset 0 0 0 1px var(--line);
}
.seg button {
  flex: 1; border: 0; background: none; padding: 6px 0; border-radius: 999px;
  font-size: 12px; font-weight: 600; cursor: pointer; color: var(--ink-2);
  transition: background .15s, color .15s;
}
.seg button:hover:not(.on) { color: var(--ink); }
.seg button.on { background: rgba(255, 255, 255, 0.9); color: #111; }
.seg button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.actions { display: flex; flex-direction: column; gap: 8px; margin-top: auto; }
.export { display: flex; gap: 8px; }
.btn {
  flex: 1; padding: 12px 14px; border-radius: 999px; border: 0;
  background: rgba(255, 255, 255, 0.1);
  box-shadow: inset 1px 1px 1px rgba(255, 255, 255, 0.24), inset 0 0 0 1px var(--line);
  font-weight: 700; font-size: 13.5px; cursor: pointer;
  transition: background .15s, transform .1s;
}
.btn:hover:not(:disabled) { background: rgba(255, 255, 255, 0.18); }
.btn:active:not(:disabled) { transform: scale(0.98); }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn.primary { background: #fff; color: #111; box-shadow: 0 6px 20px rgba(0, 0, 0, 0.25); }
.btn.primary:hover:not(:disabled) { background: rgba(255, 255, 255, 0.86); }
.btn:disabled { opacity: .4; cursor: not-allowed; }

/* ---------------------------------------------------------------- stage */
.stage { display: flex; flex-direction: column; justify-content: center; min-width: 0; }

/* Original above, generated below. The column's width is whatever lets both cards
   (+ headings above them, padding, gaps, progress bar ~ 200px) fit the viewport height at
   the image's aspect ratio (--ar, set by js). */
.result {
  display: flex; flex-direction: column; gap: 14px;
  width: min(100%, calc((100vh - 200px) / 2 * var(--ar, 1) + 20px)); margin: 0 auto;
}
/* Portrait images: original and generated side by side. Width = two cards whose
   frames are as tall as the viewport allows (minus headings, padding, bar ~ 120px). */
.result.side {
  display: grid; grid-template-columns: 1fr 1fr; gap: 14px;
  width: min(100%, calc(((100vh - 120px) * var(--ar, 1) + 20px) * 2 + 14px));
}
.result.side .bar { grid-column: 1 / -1; }
.pane { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.card { padding: 10px; }
/* heading sits on the backdrop, above its card */
.pane-head {
  margin: 0; padding: 0 6px; min-height: 26px; /* same height with or without the 3D view button, so side-by-side cards line up */
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.45);
  display: flex; align-items: center; gap: 8px;
  font-size: 13px; font-weight: 700; letter-spacing: 0.01em;
}
.frame {
  position: relative; width: 100%; aspect-ratio: var(--ar, 1);
  border-radius: calc(var(--radius) - 10px); overflow: hidden;
  background: rgba(0, 0, 0, 0.25);
}
.frame img, .frame canvas { width: 100%; height: 100%; display: block; object-fit: contain; }
.frame-empty { position: absolute; inset: 0; display: grid; place-items: center; }
.frame-go { flex: none; padding: 12px 30px; font-size: 14px; }
/* while the 3D layers sit in the frame they replace the flat canvas: orbiting
   would otherwise show the 2D result behind them (it comes back for the lightbox) */
.frame.has-layers > canvas:not(.layers-gl) { visibility: hidden; }

/* ---------------------------------------------------------------- 3D layers */
/* the WebGL view of the layers sits exactly over the 2D canvas (flat, it looks the same) */
.frame .layers-gl, .lb-stage .layers-gl {
  position: absolute; inset: 0; width: 100%; height: 100%; display: block;
  cursor: grab;
}
.layers-gl.is-dragging { cursor: grabbing; }
.orbit-hint {
  position: absolute; left: 50%; bottom: 10px; transform: translateX(-50%);
  padding: 5px 11px; border-radius: 999px; white-space: nowrap; pointer-events: none;
  font-size: 11.5px; font-weight: 600; color: #fff;
  background: rgba(10, 12, 18, 0.55); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.16);
  animation: hint-in .4s ease both;
}
@keyframes hint-in { from { opacity: 0; transform: translate(-50%, 6px); } }

/* "3D view" button, right end of the Generated heading */
.expand {
  margin-left: auto; display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px 4px 8px; border: 0; border-radius: 999px; cursor: pointer;
  font-size: 11.5px; font-weight: 700; color: #fff; text-shadow: none;
  background: rgba(255, 255, 255, 0.1);
  box-shadow: inset 1px 1px 1px rgba(255, 255, 255, 0.24), inset 0 0 0 1px var(--line);
  transition: background .15s;
}
.expand:hover { background: rgba(255, 255, 255, 0.2); }
.expand:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.expand svg { width: 14px; height: 14px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* lightbox: full-screen room to orbit */
body.lb-open { overflow: hidden; }
.lightbox {
  position: fixed; inset: 0; z-index: 50;
  display: flex; flex-direction: column; gap: 12px; padding: var(--gutter);
  background: rgba(6, 7, 10, 0.72);
  backdrop-filter: blur(16px) saturate(1.2); -webkit-backdrop-filter: blur(16px) saturate(1.2);
  animation: lb-in .25s ease both;
}
@keyframes lb-in { from { opacity: 0; } }
.lb-bar {
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  padding: 8px 8px 8px 18px; border-radius: 999px; align-self: center; max-width: 100%;
}
.lb-title { font-size: 13.5px; font-weight: 700; }
.lb-depth { display: flex; align-items: center; gap: 10px; font-size: 12.5px; font-weight: 600; color: var(--ink-2); }
.lb-depth input { width: 130px; }
.lb-reset { flex: none; padding: 8px 14px; font-size: 12.5px; }
.lb-close {
  display: grid; place-items: center; width: 36px; height: 36px; padding: 0; border: 0; border-radius: 50%;
  cursor: pointer; color: #111; background: #fff;
}
.lb-close:hover { background: rgba(255, 255, 255, 0.85); }
.lb-close:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.lb-close svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; }
.lb-stage { position: relative; flex: 1; min-height: 0; }
.lb-hint { margin: 0; text-align: center; font-size: 12px; color: var(--ink-3); }

/* the "Live" widget beside the Generated heading */
.live {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 9px 3px 8px; border-radius: 999px;
  font-size: 11px; font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase;
  color: #fff; background: rgba(255, 122, 69, 0.22);
  box-shadow: inset 0 0 0 1px rgba(255, 122, 69, 0.45);
}
.live::before {
  content: ''; width: 6px; height: 6px; border-radius: 50%;
  background: var(--accent); box-shadow: 0 0 8px var(--accent);
  animation: pulse 1s ease-in-out infinite;
}
@keyframes pulse { 50% { opacity: .25; } }

.bar { height: 4px; margin: 4px 10px 0; background: rgba(255, 255, 255, 0.14); border-radius: 2px; overflow: hidden; }
.bar > div { height: 100%; width: 0; background: #fff; border-radius: 2px; transition: width .1s linear; }

.empty { margin: auto; color: var(--ink-2); font-size: 14px; }

@media (prefers-reduced-motion: reduce) {
  .live::before { animation: none; }
}

@media (max-width: 860px) {
  :root { --gutter: 12px; --radius: 22px; }
  .app { grid-template-columns: 1fr; }
  .panel { position: static; height: auto; }
  .result, .result.side { width: 100%; }
  .lb-bar { border-radius: 22px; padding: 10px 10px 10px 16px; gap: 10px; }
  .lb-depth input { width: 100px; }
}
@media (prefers-reduced-motion: reduce) {
  .orbit-hint, .lightbox { animation: none; }
}
