:root {
  --bg: #0e0f13;
  --panel: #171922;
  --panel-2: #1f2230;
  --line: #2b2f3f;
  --text: #eef0f6;
  --muted: #9aa1b5;
  --accent: #6ea8ff;
  --accent-ink: #06111f;
  --warn: #ffb454;
  --radius: 12px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior: none;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* ---------- top bar ---------- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: max(10px, env(safe-area-inset-top, 0px)) 14px 10px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}

.topbar h1 {
  margin: 0;
  font-size: 17px;
  font-weight: 650;
  letter-spacing: 0.2px;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.badge {
  padding: 3px 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.badge.warn {
  border-color: color-mix(in srgb, var(--warn) 50%, transparent);
  color: var(--warn);
}

/* ---------- layout ---------- */

.editor {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

/* ---------- stage ---------- */

.stage {
  position: relative;
  flex: 1;
  min-height: 30vh;
  overflow: hidden;
  background:
    repeating-conic-gradient(#15171f 0% 25%, #1b1e28 0% 50%) 50% / 22px 22px;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  cursor: grab;
}

.stage.dragging { cursor: grabbing; }
.stage.empty-state { cursor: default; }
.stage.dropping { outline: 2px dashed var(--accent); outline-offset: -8px; }

.layer-host {
  position: absolute;
  inset: 0;
  overflow: hidden;
}

.layer {
  position: absolute;
  top: 0;
  left: 0;
  transform-origin: 0 0;
  image-orientation: from-image;
  will-change: transform;
}

.frame {
  position: absolute;
  top: 0;
  left: 0;
  pointer-events: none;
  border: 1px solid rgba(255, 255, 255, 0.85);
  box-shadow: 0 0 0 100vmax rgba(6, 7, 11, 0.62);
}

/* rule-of-thirds guides, only while the user is moving the photo */
.frame::before,
.frame::after {
  content: "";
  position: absolute;
  inset: 0;
  opacity: 0;
  transition: opacity 120ms ease;
}

.frame::before {
  background:
    linear-gradient(to right, transparent calc(33.333% - 0.5px), rgba(255,255,255,.5) calc(33.333% - 0.5px) calc(33.333% + 0.5px), transparent calc(33.333% + 0.5px)),
    linear-gradient(to right, transparent calc(66.666% - 0.5px), rgba(255,255,255,.5) calc(66.666% - 0.5px) calc(66.666% + 0.5px), transparent calc(66.666% + 0.5px));
}

.frame::after {
  background:
    linear-gradient(to bottom, transparent calc(33.333% - 0.5px), rgba(255,255,255,.5) calc(33.333% - 0.5px) calc(33.333% + 0.5px), transparent calc(33.333% + 0.5px)),
    linear-gradient(to bottom, transparent calc(66.666% - 0.5px), rgba(255,255,255,.5) calc(66.666% - 0.5px) calc(66.666% + 0.5px), transparent calc(66.666% + 0.5px));
}

.stage.dragging .frame::before,
.stage.dragging .frame::after { opacity: 1; }

.stage.empty-state .frame { display: none; }

/* Effect output, drawn over the frame at exactly the frame's position. */
.preview {
  position: absolute;
  top: 0;
  left: 0;
  transform-origin: 0 0;
  pointer-events: none;
}

.preview[hidden] { display: none; }

.empty {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  text-align: center;
}

.empty[hidden] { display: none; }

.empty-inner {
  max-width: 320px;
  padding: 22px;
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  background: rgba(23, 25, 34, 0.72);
}

.empty-title { margin: 0 0 6px; font-size: 16px; font-weight: 600; }
.empty-sub { margin: 0; color: var(--muted); font-size: 13px; }

/* ---------- controls ---------- */

/*
 * Three bands: tabs and the footer stay put while the panes scroll between
 * them. A randomised chain plus the JSON panel is far taller than a phone, and
 * the export button has to stay reachable without hunting for it.
 */
.controls {
  flex: 0 1 auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 10px 14px calc(10px + var(--safe-b));
  border-top: 1px solid var(--line);
  background: var(--panel);
  overflow: hidden;
}

.panes {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.footer {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.row { display: flex; flex-direction: column; gap: 6px; }

/* ---------- steps ---------- */

.steps {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel-2);
}

.step {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 7px 10px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 13px;
  font-weight: 550;
  cursor: pointer;
}

.step[aria-selected="true"] {
  background: color-mix(in srgb, var(--accent) 22%, var(--panel));
  color: var(--text);
}

.step-num {
  display: grid;
  place-items: center;
  width: 18px;
  height: 18px;
  border: 1px solid currentColor;
  border-radius: 999px;
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  opacity: 0.75;
}

.step[aria-selected="true"] .step-num {
  border-color: transparent;
  background: var(--accent);
  color: var(--accent-ink);
  opacity: 1;
}

.step-arrow { flex: 0 0 auto; color: var(--muted); font-size: 12px; }

.step-note {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
}

/*
 * Step navigation sits between the scrolling panes and the footer rather than
 * inside a pane. On a short phone the crop controls alone overflow, and the way
 * forward must not be something you scroll to find — nor a sticky button
 * overlapping the control it covers.
 */
.stepnav {
  flex: 0 0 auto;
  display: flex;
  gap: 8px;
}

.stepnav .btn { flex: 1; padding: 8px 12px; font-size: 13px; }
.stepnav .btn[hidden] { display: none; }

.count {
  min-width: 18px;
  padding: 1px 5px;
  border-radius: 999px;
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}

.count[hidden] { display: none; }

/* Never shrink: the pane scrolls inside .panes rather than squashing its
   content out over the footer. */
.pane {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding-bottom: 2px;
}

.pane[hidden] { display: none; }

/* ---------- effect chain ---------- */

.chain {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.chain:empty { display: none; }
.hint-empty[hidden] { display: none; }

.effect {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel-2);
}

.effect.off { opacity: 0.5; }

/* The summary is a child of the inner <details>, not of .effect itself. */
.effect summary {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px 6px 4px;
  cursor: pointer;
  list-style: none;
  font-size: 14px;
}

.effect summary::-webkit-details-marker { display: none; }

.effect summary::before {
  content: "›";
  flex: 0 0 auto;
  width: 16px;
  color: var(--muted);
  font-size: 15px;
  text-align: center;
  transition: transform 120ms ease;
}

.effect details[open] > summary::before { transform: rotate(90deg); }

.effect-index {
  flex: 0 0 auto;
  width: 18px;
  color: var(--muted);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}

.effect-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.effect-tools { display: flex; gap: 2px; flex: 0 0 auto; }

.tool {
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
}

.tool:hover:not(:disabled) { background: var(--line); color: var(--text); }
.tool:disabled { opacity: 0.3; cursor: default; }
.tool[aria-pressed="false"] { color: var(--warn); }

.params {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 4px 10px 10px;
  border-top: 1px solid var(--line);
}

.param { display: flex; flex-direction: column; gap: 4px; }

.param-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  color: var(--muted);
  font-size: 12px;
}

.param-value { font-variant-numeric: tabular-nums; color: var(--text); }

.param-toggle {
  flex-direction: row;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 12px;
  cursor: pointer;
}

.param-toggle input { width: 18px; height: 18px; accent-color: var(--accent); }

/* ---------- JSON panel ---------- */

.json { border: 1px solid var(--line); border-radius: 10px; background: var(--panel-2); }

.json > summary {
  padding: 8px 10px;
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  cursor: pointer;
}

.json[open] > summary { border-bottom: 1px solid var(--line); }

.json-text {
  display: block;
  width: 100%;
  padding: 8px 10px;
  border: 0;
  background: transparent;
  color: var(--text);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  line-height: 1.45;
  resize: vertical;
}

.json-actions { padding: 0 10px 10px; }
.json-actions .btn { flex: 1; padding: 8px 10px; font-size: 13px; }

.row-inline {
  display: flex;
  flex-direction: row;
  align-items: flex-end;
  gap: 8px;
}

.row-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.presets {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 2px;
  scrollbar-width: thin;
  -webkit-overflow-scrolling: touch;
}

.chip {
  flex: 0 0 auto;
  padding: 6px 11px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel-2);
  color: var(--text);
  font: inherit;
  font-size: 13px;
  line-height: 1.25;
  white-space: nowrap;
  cursor: pointer;
}

.chip[aria-pressed="true"] {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 20%, var(--panel-2));
  color: #fff;
}

.chip small { display: block; color: var(--muted); font-size: 11px; }
.chip[aria-pressed="true"] small { color: rgba(255,255,255,.8); }

.field { display: flex; flex-direction: column; gap: 6px; flex: 1; min-width: 0; }

.field label {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.field-unit { flex: 0 0 auto; }
.field-unit span { padding-bottom: 11px; color: var(--muted); font-size: 13px; }

.field-format { flex: 0 0 auto; width: 104px; }

.row-seed { align-items: center; }
.row-seed .btn-icon { align-self: auto; font-size: 15px; line-height: 1; }

.inline-label {
  flex: 0 0 auto;
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

input[type="number"],
input[type="text"],
select {
  width: 100%;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel-2);
  color: var(--text);
  font: inherit;
  font-size: 16px; /* keeps iOS Safari from zooming on focus */
}

select { appearance: none; padding-right: 28px; }

/* `input.` to match the specificity of `input[type="text"]` above, and placed
   after it so this wins the tie — that rule's `font` shorthand resets family. */
input.seed-input {
  flex: 1;
  min-width: 0;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  letter-spacing: 0.06em;
}

.slider {
  flex: 1;
  min-width: 0;
  height: 34px;
  accent-color: var(--accent);
  background: transparent;
}

.mono { font-variant-numeric: tabular-nums; letter-spacing: 0; text-transform: none; }

.row-zoom { align-items: center; }
.row-zoom .btn { padding: 8px 10px; font-size: 13px; }
.zoom-val { flex: 0 0 auto; color: var(--muted); font-size: 12px; }

.btn {
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel-2);
  color: var(--text);
  font: inherit;
  font-weight: 550;
  cursor: pointer;
  white-space: nowrap;
}

.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.45; cursor: default; transform: none; }

.btn-primary {
  flex: 1;
  border-color: transparent;
  background: var(--accent);
  color: var(--accent-ink);
}

.btn-icon { padding: 10px 12px; align-self: flex-end; }
.row-actions { align-items: flex-end; }
.row-actions .btn-primary { padding: 12px 14px; }

.hint {
  margin: 0;
  color: var(--muted);
  font-size: 11px;
  text-align: center;
}

/* ---------- toast ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(18px + var(--safe-b));
  transform: translateX(-50%);
  max-width: min(92vw, 420px);
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(20, 22, 30, 0.96);
  color: var(--text);
  font-size: 13px;
  text-align: center;
  z-index: 10;
}

.toast[hidden] { display: none; }

/* ---------- wider screens ---------- */

/* Side-by-side when there is width to spare, and on a phone held sideways
   where a stacked layout would leave the preview a letterbox slit. */
@media (min-width: 820px), (orientation: landscape) and (max-height: 560px) {
  .editor { flex-direction: row; }
  .stage { min-height: 0; }
  .controls {
    flex: 0 0 min(340px, 46vw);
    border-top: 0;
    border-left: 1px solid var(--line);
  }
}

@media (min-width: 820px) {
  .presets { flex-wrap: wrap; overflow-x: visible; }
}
