:root {
  --g0: #fff;
  --g1: #eee;
  --g2: #999;
  --g3: #808080;
  --g4: #282828;
  --g5: #202020;
  --g6: #1a1a1a;
  --line: #363636;
  --accent: #2b9dff;
  --key: #ab98ff;
  --hi: #e1fd00;

  --bg: var(--g6);
  --text: var(--g0);
  --muted: var(--g2);
  --hair: 0.5px solid var(--line);
  --row: 24px;
  --pane-w: 340px;
  --status-h: 24px;
  --font: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", "Inter", Roboto, sans-serif;
  --track: 0.2px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 400 11px/1.4 var(--font);
  letter-spacing: var(--track);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}
::selection { background: color-mix(in srgb, var(--hi) 25%, transparent); }
button, input, select, textarea { font: inherit; color: inherit; letter-spacing: inherit; }
button { background: none; border: 0; padding: 0; cursor: pointer; }
.tab { font-variant-numeric: tabular-nums; }
.muted-text { color: var(--muted); }
.strong { font-weight: 500; }
u { text-decoration: underline; text-decoration-color: var(--g3); text-underline-offset: 2px; text-decoration-thickness: 0.5px; }

kbd {
  display: inline-grid; place-items: center;
  min-width: 13px; height: 13px; padding: 0 2px;
  border: 0.5px solid var(--g3); border-radius: 2px;
  font: 500 8px/1 var(--font); color: var(--g1);
  margin-left: 2px; vertical-align: 1px;
}

/* ---------- layout ---------- */
.app {
  display: grid;
  grid-template-columns: var(--pane-w) 1fr;
  grid-template-rows: 1fr var(--status-h);
  height: 100dvh;
}
.pane {
  grid-row: 1; grid-column: 1;
  display: flex; flex-direction: column;
  border-right: var(--hair);
  min-height: 0; overflow: auto;
  scrollbar-width: none;
}
.canvas { grid-row: 1; grid-column: 2; position: relative; overflow: auto; }
.status {
  grid-row: 2; grid-column: 1 / -1;
  display: flex; justify-content: space-between; align-items: center;
  padding: 0 8px; border-top: var(--hair); color: var(--g1);
}
.status-left, .status-right { display: flex; gap: 14px; align-items: center; }
.dash { color: var(--g1); }
.mbar, .tabs { display: none; }

/* ---------- pane ---------- */
.section { padding: 0 8px; }
.row { display: flex; align-items: center; justify-content: space-between; min-height: var(--row); }
.head { height: 28px; }
.head-left { display: flex; gap: 12px; align-items: center; }
.label { color: var(--text); }

.toggle { display: inline-flex; align-items: center; gap: 4px; color: var(--g1); cursor: pointer; }
.toggle svg { width: 12px; height: 12px; }
.label-toggle { color: var(--muted); }
.switch {
  appearance: none; margin: 0; cursor: pointer;
  width: 22px; height: 10px; border-radius: 5px;
  background: var(--g4); position: relative;
  transition: background .15s;
}
.switch::after {
  content: ""; position: absolute; top: 2px; left: 3px;
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--g1);
  transition: transform .2s cubic-bezier(.2, 1.4, .4, 1);
}
.switch:checked { background: var(--accent); }
.switch:checked::after { transform: translateX(10px); background: #fff; }

.btn {
  display: inline-flex; align-items: center; gap: 2px;
  height: 22px; padding: 0 6px; border-radius: 3px;
  color: var(--g1);
}
.btn:hover { background: var(--g5); }
.btn.muted { color: var(--g1); }
.btn.go {
  height: 26px; padding: 0 10px;
  border: var(--hair); background: var(--g6); color: var(--g1);
}
.btn.go:hover { background: var(--g4); }
.btn.go[disabled] { opacity: .5; cursor: progress; }
.link { color: var(--g1); display: inline-flex; align-items: center; gap: 4px; }
.link:hover { color: #fff; }
.key-state { color: var(--key); }
.key-state.ok { color: var(--g1); }

.section-prompt { flex: 1 1 auto; display: flex; flex-direction: column; min-height: 240px; }
.prompt-wrap { position: relative; flex: 1; display: flex; }
#prompt {
  flex: 1; resize: none; border: 0; outline: 0; background: transparent;
  font-size: 12px; line-height: 16px; padding: 4px 0;
}
#prompt::placeholder, .field-input::placeholder, #assist::placeholder { color: var(--g1); opacity: .85; }
.prompt-key { position: absolute; right: 0; top: 4px; opacity: 0; transition: opacity .15s; }
.prompt-wrap:not(:focus-within) .prompt-key { opacity: .6; }

.refs { display: flex; align-items: flex-end; gap: 6px; padding: 8px 0; }
.ref-add {
  width: 38px; height: 38px; flex: none;
  display: grid; place-items: center; cursor: pointer;
  border: var(--hair); color: var(--g1);
}
.ref-add:hover { background: var(--g5); }
.ref-add input { display: none; }
.ref-add svg { width: 8px; height: 8px; }
.ref-list { display: flex; gap: 4px; flex: 1; overflow-x: auto; scrollbar-width: none; }
.ref-list img { width: 38px; height: 38px; object-fit: cover; border: var(--hair); cursor: pointer; }
.ref-list img:hover { opacity: .5; }
.ref-paste { margin-left: auto; }

.section-mods { padding-top: 6px; padding-bottom: 6px; }
.field-label { width: 109px; flex: none; display: inline-flex; gap: 6px; align-items: center; color: var(--g1); }
.field-label .ico { width: 10px; text-align: center; color: var(--g2); font-size: 10px; }
.field-input {
  flex: 1; min-width: 0; height: 22px; border: 0; outline: 0; background: transparent;
  font-size: 10px; color: var(--g1);
}
.field-inline { flex: 1; display: flex; align-items: center; gap: 14px; }
.stepper { display: inline-flex; align-items: center; gap: 6px; margin-left: 18px; }
.stepper-btns { display: inline-flex; flex-direction: column; line-height: 6px; font-size: 8px; color: var(--g2); }
.stepper-btns button:hover { color: #fff; }

.assist {
  margin: 0 4px; padding: 8px 10px;
  background: var(--g5); border: var(--hair); border-radius: 2px;
  display: flex; flex-direction: column; gap: 8px;
}
#assist { resize: none; height: 36px; border: 0; outline: 0; background: transparent; font-size: 10px; }
.assist-foot { display: flex; justify-content: space-between; align-items: center; }
.assist-model { color: var(--g1); }

.section-settings { border-top: var(--hair); margin-top: 6px; padding-bottom: 6px; }
.field-select {
  flex: 1; min-width: 0; height: 22px; border: 0; outline: 0; cursor: pointer;
  background: transparent; font-weight: 500; font-size: 11px;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='8' height='5' fill='none'%3E%3Cpath d='M1 1l3 3 3-3' stroke='%23eee'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 4px center;
}
.field-select option { background: var(--g5); }
.count { display: inline-flex; align-items: center; gap: 6px; }
.count .field-input { width: 26px; flex: none; font-size: 11px; color: #fff; -moz-appearance: textfield; }
.count .field-input::-webkit-inner-spin-button { -webkit-appearance: none; }
.advanced-only { display: none; }
.app.advanced .advanced-only { display: flex; }

.pane-foot {
  display: flex; justify-content: space-between; align-items: center;
  height: 34px; padding: 0 8px; border-top: var(--hair);
}

/* ---------- canvas ---------- */
.empty {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 22px;
}
.matrix {
  display: grid; grid-template-columns: repeat(4, 80px);
  border: var(--hair);
}
.matrix .cell {
  width: 80px; height: 80px; padding: 3px;
  display: grid; grid-template-columns: repeat(20, 1fr); gap: 0;
}
.matrix .cell + .cell { border-left: var(--hair); }
.matrix i {
  display: block; width: 1.5px; height: 1.5px; margin: auto; border-radius: 50%;
  background: var(--g3); opacity: .18; transition: opacity .6s;
}
.matrix i.on { opacity: .9; }
.caption { margin: 0; color: var(--g1); font-size: 11px; }
.arrow { color: var(--g2); }

.grid {
  display: grid; gap: 1px; padding: 16px;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 320px), 1fr));
  align-content: start;
}
.card {
  position: relative; background: var(--g5); border: var(--hair);
  aspect-ratio: var(--ar, 3 / 2); overflow: hidden;
}
.card img { width: 100%; height: 100%; object-fit: cover; display: block; }
.card .meta {
  position: absolute; left: 0; right: 0; bottom: 0;
  display: flex; justify-content: space-between; padding: 6px 8px;
  background: linear-gradient(to top, #000a, transparent);
  opacity: 0; transition: opacity .15s;
}
.card:hover .meta { opacity: 1; }
.card .meta a { color: #fff; text-decoration: none; }
.card.pending::before {
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(100deg, transparent 30%, #ffffff0a 50%, transparent 70%);
  background-size: 200% 100%; animation: sweep 1.4s linear infinite;
}
.card.pending .label, .card.failed .label {
  position: absolute; inset: 0; display: grid; place-items: center; padding: 16px; text-align: center;
  color: var(--muted);
}
.card.failed .label { color: var(--key); }
@keyframes sweep { from { background-position: 200% 0; } to { background-position: -200% 0; } }

.run-head {
  grid-column: 1 / -1; display: flex; justify-content: space-between; gap: 16px;
  padding: 14px 2px 6px; color: var(--g1);
}
.run-head:first-child { padding-top: 0; }
.run-head .p { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- dialog ---------- */
.dialog {
  width: min(380px, calc(100vw - 32px));
  background: var(--g5); color: var(--text);
  border: var(--hair); border-radius: 4px; padding: 16px;
  box-shadow: 0 .5px 0 #ffffff0f inset, 0 10px 30px #0008;
}
.dialog::backdrop { background: #0008; }
.dialog h2 { margin: 0 0 8px; font-size: 12px; font-weight: 500; }
.dialog p { margin: 0 0 12px; line-height: 1.5; }
.dialog input {
  width: 100%; height: 28px; padding: 0 8px; outline: 0;
  background: var(--g6); border: var(--hair); border-radius: 3px;
}
.dialog input:focus { border-color: var(--accent); }
.dialog-actions { display: flex; gap: 6px; margin-top: 14px; align-items: center; }
.spacer { flex: 1; }

/* ---------- mobile ---------- */
@media (max-width: 760px) {
  :root { --row: 36px; }
  body { font-size: 13px; }
  .app { grid-template-columns: 1fr; grid-template-rows: 52px 1fr calc(52px + var(--safe-b)); }
  .status { display: none; }
  .mbar {
    display: flex; grid-row: 1; justify-content: space-between; align-items: center;
    padding: 0 12px 0 12px; border-bottom: var(--hair);
  }
  .mbar-right { display: flex; gap: 16px; }
  .pane, .canvas { grid-row: 2; grid-column: 1; border-right: 0; }
  .app[data-tab="images"] .pane { display: none; }
  .app[data-tab="create"] .canvas { display: none; }
  .tabs {
    display: flex; grid-row: 3; justify-content: space-between; align-items: center;
    padding: 0 10px var(--safe-b); border-top: var(--hair);
  }
  .tabs-left { display: flex; gap: 4px; }
  .tab-btn { height: 38px; padding: 0 14px; color: var(--g1); border-radius: 3px; }
  .app[data-tab="create"] [data-tab-target="create"],
  .app[data-tab="images"] [data-tab-target="images"] { background: var(--g5); border: var(--hair); color: #fff; }
  .btn.go.wide { height: 38px; width: 134px; justify-content: center; }
  .pane-foot { display: none; }
  .field-input, #assist { font-size: 13px; }
  #prompt { font-size: 15px; line-height: 22px; }
  .field-select { font-size: 13px; }
  kbd { display: none; }
  .grid { padding: 8px; }
}
