:root {
  --paper: #ffffff;
  --ink: #0b0b0b;
  --red: #e3120b;
  --yellow: #f0a804;
  --line: 4px solid var(--ink);
  --font: "Jost", Futura, "Century Gothic", "Avenir Next", system-ui, sans-serif;
  --mono: ui-monospace, "Roboto Mono", "SFMono-Regular", Menlo, monospace;
}
* { box-sizing: border-box; border-radius: 0; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--paper); color: var(--ink); font: 500 17px/1.4 var(--font); }
a { color: inherit; }
[hidden] { display: none !important; }

.top { display: flex; align-items: stretch; justify-content: space-between; border-bottom: var(--line);
  padding-top: env(safe-area-inset-top); position: sticky; top: 0; background: var(--paper); z-index: 5; }
.brand { background: var(--red); color: var(--paper); font-weight: 800; font-style: italic; font-size: 28px;
  letter-spacing: -0.02em; padding: 8px 16px; text-decoration: none; }
nav { display: flex; }
nav a { display: flex; align-items: center; padding: 0 12px; font-weight: 800; font-size: 14px;
  letter-spacing: 0.04em; text-decoration: none; border-left: var(--line); }
nav a.on { background: var(--ink); color: var(--paper); }

main { padding: 16px; max-width: 1200px; margin: 0 auto; }
footer { padding: 24px 16px calc(24px + env(safe-area-inset-bottom)); font: 12px var(--mono); text-align: center; }
/* minmax(0, 1fr), not the default auto column: a long unbroken prompt in the
   queue would otherwise widen the column past a phone's screen. */
.columns { display: grid; gap: 16px; grid-template-columns: minmax(0, 1fr); }
@media (max-width: 480px) {
  .brand { font-size: 22px; padding: 8px 10px; display: flex; align-items: center; }
  nav a { padding: 0 8px; font-size: 12px; }
  main { padding: 10px; }
}
@media (min-width: 900px) { .columns { grid-template-columns: minmax(0, 5fr) minmax(0, 4fr); align-items: start; } }

.panel { border: var(--line); margin: 0 0 16px; padding: 0 12px 12px; }
.panel.narrow { max-width: 560px; margin-left: auto; margin-right: auto; }
.bar { background: var(--ink); color: var(--paper); font-weight: 800; font-size: 15px; letter-spacing: 0.06em;
  padding: 6px 12px; margin: 12px -12px 12px; display: flex; justify-content: space-between; align-items: center; }
.panel > .bar:first-child, form.panel > input[type=hidden] + .bar { margin-top: 0; }
.bar.red { background: var(--red); }
.bar.yellow { background: var(--yellow); color: var(--ink); }
.count, .badge { font: 700 12px var(--mono); }
.badge { padding: 2px 8px; background: var(--paper); color: var(--ink); }
.badge.on { background: var(--yellow); }
.badge.off { background: var(--red); color: var(--paper); }

textarea, input:not([type=radio]):not([type=file]) { width: 100%; border: var(--line); background: var(--paper);
  color: var(--ink); font: 500 17px/1.4 var(--font); padding: 10px; appearance: none; }
textarea { resize: vertical; min-height: 140px; }
textarea:focus, input:focus, button:focus-visible, a:focus-visible, summary:focus-visible { outline: 4px solid var(--yellow); outline-offset: 0; }
.hint { font: 13px/1.4 var(--mono); margin: 8px 0; }
.empty { font: 13px var(--mono); margin: 12px 0; }
.alert { background: var(--red); color: var(--paper); font-weight: 700; padding: 8px 12px; margin: 0 0 12px; }

.btn { display: inline-flex; align-items: center; justify-content: center; border: var(--line); background: var(--paper);
  color: var(--ink); font: 800 16px var(--font); letter-spacing: 0.05em; padding: 12px 18px; cursor: pointer;
  text-decoration: none; min-height: 48px; }
.btn.primary { background: var(--red); color: var(--paper); border-color: var(--red); }
.btn.yellow { background: var(--yellow); border-color: var(--yellow); }
.btn.danger { color: var(--red); border-color: var(--red); }
.btn:disabled { opacity: 0.45; cursor: default; }
form .btn.primary { width: 100%; font-size: 22px; margin-top: 12px; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0; }

.choices { display: flex; border: var(--line); }
.choices label, .choices a { flex: 1; text-align: center; border-left: var(--line); cursor: pointer; text-decoration: none; }
.choices label:first-child, .choices a:first-child { border-left: 0; }
.choices input { position: absolute; opacity: 0; pointer-events: none; }
.choices span, .choices a { display: block; padding: 12px 4px; font-weight: 800; font-size: 14px; letter-spacing: 0.04em; }
.choices small { font: 11px var(--mono); }
.choices input:checked + span, .choices a.on { background: var(--ink); color: var(--paper); }
.choices input:focus-visible + span { outline: 4px solid var(--yellow); }

.advanced { border: var(--line); margin-top: 12px; }
.advanced summary { font-weight: 800; letter-spacing: 0.06em; padding: 10px 12px; cursor: pointer; }
.advanced[open] summary { background: var(--yellow); }
.advanced .fields { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; padding: 12px; }
.advanced label { font-weight: 800; font-size: 13px; letter-spacing: 0.05em; }
.advanced .hint { padding: 0 12px; }

.refs { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; margin-bottom: 8px; }
.ref { margin: 0; border: var(--line); }
.ref img { display: block; width: 100%; aspect-ratio: 1; object-fit: cover; }
.ref figcaption { font: 700 10px var(--mono); padding: 3px 4px; border-top: var(--line); overflow: hidden;
  white-space: nowrap; text-overflow: ellipsis; }
.ref-tools { display: flex; border-top: var(--line); }
.ref-tools button { flex: 1; border: 0; border-left: var(--line); background: var(--paper); color: var(--ink);
  font: 800 16px var(--font); padding: 6px 0; cursor: pointer; min-height: 36px; }
.ref-tools button:first-child { border-left: 0; }
.ref-tools button:disabled { opacity: 0.3; }

.job { border: var(--line); margin: 0 0 8px; }
.job-head { display: flex; align-items: stretch; }
.tag { background: var(--ink); color: var(--paper); font: 800 12px var(--font); letter-spacing: 0.06em;
  padding: 8px; display: flex; align-items: center; white-space: nowrap; }
.job.generating .tag { background: var(--yellow); color: var(--ink); }
.job.failed .tag { background: var(--red); }
.job-prompt { flex: 1; min-width: 0; padding: 8px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  text-decoration: none; }
.job .btn { border: 0; border-left: var(--line); min-height: 0; padding: 8px 12px; font-size: 13px; }
.meter { height: 14px; border-top: var(--line); background: var(--paper); }
.meter .fill { height: 100%; background: var(--yellow); transition: width 0.4s linear; }
.steps { font: 700 12px var(--mono); padding: 4px 8px; border-top: var(--line); }
.error { font: 12px/1.4 var(--mono); white-space: pre-wrap; overflow-wrap: anywhere; margin: 0; padding: 8px;
  border-top: var(--line); max-height: 220px; overflow: auto; color: var(--red); }
.panel > .error { border: 4px solid var(--red); }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; margin-top: 12px; }
.grid.small { grid-template-columns: repeat(3, 1fr); margin-top: 0; }
.tile { border: var(--line); text-decoration: none; display: block; }
.tile img, .tile .blank { display: block; width: 100%; aspect-ratio: 1; object-fit: cover; }
.tile .blank { display: flex; align-items: center; justify-content: center; font-weight: 800; background: var(--ink); color: var(--paper); }
.tile.failed .blank { background: var(--red); }
.tile .caption { display: block; font: 11px var(--mono); padding: 4px 6px; border-top: var(--line);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pager { display: flex; align-items: center; justify-content: center; gap: 12px; margin-top: 16px; font: 700 13px var(--mono); }

.result { display: block; max-width: 100%; max-height: 80vh; margin: 12px auto; border: var(--line); }
.prompt { white-space: pre-wrap; overflow-wrap: anywhere; margin: 0; }
.meta { display: grid; grid-template-columns: auto 1fr; margin: 0; border: var(--line); }
.meta dt, .meta dd { margin: 0; padding: 6px 10px; border-bottom: 2px solid var(--ink); }
.meta dt { font-weight: 800; font-size: 12px; letter-spacing: 0.06em; background: var(--ink); color: var(--paper); }
.meta dd { font: 14px var(--mono); overflow-wrap: anywhere; }
.devices { list-style: none; padding: 0; margin: 0; }
.devices li { display: flex; justify-content: space-between; align-items: center; gap: 8px; border: var(--line);
  padding: 0 0 0 10px; margin-bottom: 8px; font: 13px var(--mono); }
.devices .btn { border: 0; border-left: var(--line); min-height: 40px; padding: 6px 12px; font-size: 13px; }

.flash { position: sticky; top: 52px; z-index: 6; margin: 0; padding: 10px 16px; font-weight: 800;
  background: var(--red); color: var(--paper); border-bottom: var(--line); }
.flash.ok { background: var(--yellow); color: var(--ink); }
