/* Lain Rupa Satu studio — warm, cozy, no sci-fi. Reuses the site's tokens:
   cream paper, espresso ink, sienna accent, Source Serif 4 display + Inter body. */

:root {
  --paper: rgb(251 247 240);
  --paper-deep: rgb(244 235 221);
  --paper-warm: rgb(247 240 229);
  --ink: rgb(48 38 26);
  --ink-soft: rgb(92 78 60);
  --muted: rgb(148 132 110);
  --sienna: rgb(186 84 38);
  --sienna-deep: rgb(143 58 22);
  --line: rgba(48, 38, 26, 0.14);
  --line-soft: rgba(48, 38, 26, 0.08);
  --font-display: "Source Serif 4", "Iowan Old Style", Georgia, serif;
  --font-body: "Inter", "Helvetica Neue", Arial, sans-serif;
  --radius: 18px;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

.studio {
  max-width: 760px;
  margin: 0 auto;
  padding: clamp(18px, 3vw, 32px);
}

.card {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: clamp(22px, 4vw, 40px);
}

.title {
  font-family: var(--font-display);
  font-weight: 500;
  font-size: clamp(1.7rem, 4.6vw, 2.6rem);
  line-height: 1.08;
  letter-spacing: -0.03em;
  text-wrap: balance;
}
.title em { color: var(--sienna); font-weight: 400; }

.lede {
  margin-top: 16px;
  max-width: 52ch;
  color: var(--ink-soft);
  font-family: var(--font-display);
  font-size: clamp(1rem, 2.2vw, 1.15rem);
  line-height: 1.7;
  text-wrap: pretty;
}
.lede em { color: var(--sienna); font-style: italic; }

.hint { margin-top: 12px; color: var(--muted); font-size: 0.9rem; }
.muted { color: var(--muted); font-weight: 400; }

/* ---- buttons ---- */
.btn {
  font-family: var(--font-body);
  font-weight: 500;
  font-size: 1rem;
  border: 1px solid transparent;
  border-radius: 12px;
  padding: 12px 22px;
  cursor: pointer;
  transition: background-color 0.25s var(--ease), color 0.25s var(--ease),
              border-color 0.25s var(--ease), transform 0.1s var(--ease);
}
.btn:active { transform: translateY(1px); }
.btn-primary {
  margin-top: 24px;
  background: var(--sienna);
  color: var(--paper);
}
.btn-primary:hover { background: var(--sienna-deep); }
.btn-primary:disabled { background: var(--muted); cursor: not-allowed; opacity: 0.7; }
.btn-wide { width: 100%; margin-top: 20px; }
.btn-ghost {
  margin-top: 0;
  background: var(--paper-deep);
  color: var(--ink-soft);
  padding: 8px 12px;
}
.btn-ghost:hover { color: var(--sienna); }

/* ---- loading ---- */
.load { margin-top: 26px; }
.load-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}
.load-phase {
  font-family: var(--font-display);
  font-size: 1.05rem;
  color: var(--ink);
}
.load-pct {
  font-variant-numeric: tabular-nums;
  font-size: 0.95rem;
  font-weight: 500;
  color: var(--sienna);
}
.load-bar {
  position: relative;
  height: 8px;
  background: var(--paper-deep);
  border-radius: 999px;
  overflow: hidden;
}
.load-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--sienna), rgb(214 132 74));
  border-radius: 999px;
  /* The width is now written every frame from live byte counts, so this only
     has to smooth between frames — a long ease would visibly lag the number. */
  transition: width 0.1s linear;
}
/* Work with no measurable total yet: sweep instead of lying about a number. */
.load-fill.is-waiting {
  width: 34%;
  animation: sweep 1.5s var(--ease) infinite;
}
.load-fill.is-done { width: 100%; }
.load-fill.is-error { background: linear-gradient(90deg, rgb(150 60 40), rgb(186 84 38)); }
@keyframes sweep {
  0%   { transform: translateX(-110%); }
  100% { transform: translateX(320%); }
}
/* A second, softer bar that keeps moving even when bytes stall (decoding,
   shader compilation) so the panel never looks frozen. */
.load-bar::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.55), transparent);
  transform: translateX(-100%);
  animation: shimmer 1.9s linear infinite;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.3s var(--ease);
}
.load-bar.is-active::after { opacity: 1; }
@keyframes shimmer {
  0%   { transform: translateX(-100%); }
  100% { transform: translateX(100%); }
}

.load-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 26px;
  margin-top: 16px;
}
.load-stats dt {
  font-size: 0.72rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}
.load-stats dd {
  font-size: 0.95rem;
  font-variant-numeric: tabular-nums;
  color: var(--ink-soft);
}

.checklist { list-style: none; margin-top: 18px; }
.checklist li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 5px 0;
  font-size: 0.9rem;
  color: var(--muted);
  transition: color 0.25s var(--ease);
}
.checklist .dot {
  flex: none;
  width: 9px;
  height: 9px;
  border-radius: 999px;
  border: 1.5px solid var(--line);
  background: transparent;
  transition: background-color 0.25s var(--ease), border-color 0.25s var(--ease);
}
.checklist .what { flex: 1; }
.checklist .state { font-size: 0.8rem; font-variant-numeric: tabular-nums; }
.checklist li.is-active { color: var(--ink); }
.checklist li.is-active .dot {
  border-color: var(--sienna);
  background: var(--sienna);
  animation: pulse 1.2s var(--ease) infinite;
}
.checklist li.is-done { color: var(--ink-soft); }
.checklist li.is-done .dot { border-color: var(--sienna); background: var(--sienna); }
.checklist li.is-cached .dot { border-color: var(--sienna); background: var(--paper); }
.checklist li.is-error { color: var(--sienna-deep); }
.checklist li.is-error .dot { border-color: var(--sienna-deep); background: var(--sienna-deep); }
@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(186, 84, 38, 0.35); }
  50%      { box-shadow: 0 0 0 5px rgba(186, 84, 38, 0); }
}

.load-actions { display: flex; gap: 10px; margin-top: 18px; }

@media (prefers-reduced-motion: reduce) {
  .load-fill.is-waiting,
  .load-bar::after,
  .checklist li.is-active .dot { animation: none; }
}

/* ---- tabs ---- */
.tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 22px;
  border-bottom: 1px solid var(--line-soft);
}
.tab {
  background: none;
  border: none;
  font-family: var(--font-body);
  font-size: 0.98rem;
  font-weight: 500;
  color: var(--muted);
  padding: 10px 6px;
  margin-bottom: -1px;
  border-bottom: 2px solid transparent;
  cursor: pointer;
  transition: color 0.2s var(--ease), border-color 0.2s var(--ease);
}
.tab:hover { color: var(--ink-soft); }
.tab.is-active { color: var(--sienna); border-bottom-color: var(--sienna); }

/* Small pill in the tab strip: asks the host page to grow the frame. */
.chip {
  margin-left: auto;
  align-self: center;
  background: var(--paper-deep);
  border: 1px solid var(--line-soft);
  border-radius: 999px;
  font-family: var(--font-body);
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--ink-soft);
  padding: 5px 12px;
  margin-bottom: 6px;
  cursor: pointer;
  transition: color 0.2s var(--ease), border-color 0.2s var(--ease);
}
.chip:hover { color: var(--sienna); border-color: var(--sienna); }

/* ---- stage / canvas ---- */
.stage { display: flex; flex-direction: column; align-items: center; gap: 16px; }
.canvas-frame {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--paper-deep);
  padding: 10px;
  width: fit-content;
  max-width: 100%;
}
#canvas {
  display: block;
  width: min(360px, 74vw);
  height: min(360px, 74vw);
  image-rendering: auto;
  border-radius: 10px;
  background:
    repeating-conic-gradient(var(--paper-warm) 0% 25%, var(--paper-deep) 0% 50%) 50% / 22px 22px;
}
/* Busy state is the live step previews + gen bar; no fake sheen. */
.canvas-frame { position: relative; }

.gen-bar {
  height: 4px;
  margin: 10px 2px 0;
  background: var(--paper-warm);
  border-radius: 999px;
  overflow: hidden;
}
.gen-fill {
  height: 100%;
  width: 0%;
  background: var(--sienna);
  border-radius: 999px;
  transition: width 0.2s linear;
}

.status {
  margin-top: 10px;
  text-align: center;
  color: var(--ink-soft);
  font-family: var(--font-display);
  font-style: italic;
  font-size: 0.95rem;
}

.gallery {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  max-width: 100%;
}
.gallery figure {
  position: relative;
  border: 1px solid var(--line-soft);
  border-radius: 10px;
  overflow: hidden;
  line-height: 0;
}
.gallery img { width: 72px; height: 72px; display: block; cursor: pointer; }
.gallery a.dl {
  position: absolute;
  right: 4px; bottom: 4px;
  background: rgba(251, 247, 240, 0.85);
  color: var(--ink);
  font-size: 11px;
  padding: 1px 6px;
  border-radius: 6px;
  line-height: 1.4;
  opacity: 0;
  transition: opacity 0.2s var(--ease);
}
.gallery figure:hover a.dl { opacity: 1; }

/* ---- controls ---- */
.panel { margin-top: 26px; }
.field { display: flex; flex-direction: column; gap: 8px; margin-top: 16px; }
.field-label { font-size: 0.85rem; font-weight: 500; color: var(--ink-soft); }
.row { display: flex; gap: 18px; flex-wrap: wrap; }
.grow { flex: 1 1 180px; }

.input, .range {
  font-family: var(--font-body);
  font-size: 0.98rem;
  color: var(--ink);
}
.input {
  background: var(--paper-warm);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 11px 13px;
  transition: border-color 0.2s var(--ease), background-color 0.2s var(--ease);
}
.input:focus {
  outline: none;
  border-color: var(--sienna);
  background: var(--paper);
}
.input.narrow { width: 88px; }
.input::placeholder { color: var(--muted); }

.range { width: 100%; accent-color: var(--sienna); }

.seed { display: flex; align-items: center; gap: 8px; }
.seed .input { flex: 1; }
.lock { display: flex; align-items: center; gap: 5px; font-size: 0.85rem; color: var(--muted); white-space: nowrap; }
.lock input { accent-color: var(--sienna); }

/* ---- drop zone ---- */
.drop {
  margin-top: 4px;
  border: 1.5px dashed var(--line);
  border-radius: var(--radius);
  background: var(--paper-warm);
  min-height: 120px;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  color: var(--muted);
  padding: 18px;
  cursor: pointer;
  transition: border-color 0.2s var(--ease), background-color 0.2s var(--ease);
}
.drop:hover, .drop.hover { border-color: var(--sienna); background: var(--paper); }
.thumb { max-width: 160px; max-height: 160px; border-radius: 10px; }

.footnote {
  margin-top: 24px;
  padding-top: 16px;
  border-top: 1px solid var(--line-soft);
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.6;
}

/* ---- expanded mode ----
   The host page grows the iframe to the whole viewport and tells us about it.
   We stop pretending to be a short embed: fill the height, scroll internally,
   and — when there is room — put the easel and the controls side by side. */
body.is-expanded { min-height: 100%; overflow: auto; }
body.is-expanded .studio {
  max-width: 1200px;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: clamp(20px, 3vw, 40px) clamp(18px, 4vw, 48px) clamp(28px, 5vw, 56px);
}
body.is-expanded .card { border: none; background: transparent; padding: 0; }
/* Leave room for the host page's floating ✕ on narrow screens. */
@media (max-width: 700px) {
  body.is-expanded .studio { padding-top: 56px; }
}

@media (min-width: 900px) {
  /* :not([hidden]) matters — a bare `display: grid` would out-rank the hidden
     attribute and show the studio before it is warm. */
  body.is-expanded #app:not([hidden]) {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(320px, 400px);
    grid-template-areas:
      "tabs  tabs"
      "stage panel"
      "foot  foot";
    column-gap: clamp(28px, 4vw, 56px);
    align-items: start;
  }
  body.is-expanded #app .tabs { grid-area: tabs; }
  body.is-expanded #app .stage { grid-area: stage; position: sticky; top: 0; }
  body.is-expanded #app .panel { grid-area: panel; margin-top: 0; }
  body.is-expanded #app .footnote { grid-area: foot; }
  body.is-expanded #canvas {
    width: min(520px, 46vw);
    height: min(520px, 46vw);
  }
  body.is-expanded .gallery { justify-content: flex-start; }
  body.is-expanded .gallery img { width: 84px; height: 84px; }
  /* The gate reads better as one centred column on a big screen. */
  body.is-expanded #gate,
  body.is-expanded #unsupported { max-width: 640px; margin: 0 auto; }
}
