/* Surreal Image Generator — one stylesheet, two themes.
 *
 * theme.js picks the theme before first paint and writes it to <html data-theme>, so every
 * colour here resolves once at the root. Nothing below depends on JavaScript having run: the
 * page is fully styled and readable with scripts blocked.
 *
 * Two variable vocabularies are declared deliberately. The app uses --ink / --surface /
 * --line; the docs stylesheet that ships alongside it uses --ink2 / --panel / --panel2. Both
 * are defined here so /api.html and /tokens.html inherit real colours instead of falling back
 * to their own defaults and drifting a shade away from the app they document.
 */

:root {
  --ink: #1d2030;
  --ink-soft: #4b5068;
  --ink-faint: #757a94;
  --bg: #f7f6f2;
  --surface: #ffffff;
  --surface-2: #efeee9;
  --line: #dedcd4;
  --line-strong: #c6c3b8;
  --accent: #2f4a6d;
  --accent-ink: #ffffff;
  --accent-soft: #e4eaf2;
  --ochre: #97622a;
  --ochre-soft: #f6ecdf;
  --warn: #8a5a12;
  --warn-soft: #fbf0dc;
  --ok: #1f6647;
  --ok-soft: #e2f1e9;
  --danger: #97303a;
  --danger-soft: #fbe8ea;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(29, 32, 48, .06), 0 8px 24px rgba(29, 32, 48, .07);
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;

  /* the docs vocabulary */
  --ink2: var(--ink-soft);
  --ink3: var(--ink-faint);
  --panel: var(--surface);
  --panel2: var(--surface-2);
}

:root[data-theme="dark"] {
  --ink: #e8e8ef;
  --ink-soft: #adb0c2;
  --ink-faint: #83869a;
  --bg: #101320;
  --surface: #181c2c;
  --surface-2: #202536;
  --line: #2b3145;
  --line-strong: #3b4258;
  --accent: #8fb2dd;
  --accent-ink: #121626;
  --accent-soft: #1f2a3c;
  --ochre: #d9a469;
  --ochre-soft: #2e2519;
  --warn: #e0b276;
  --warn-soft: #322715;
  --ok: #79c9a4;
  --ok-soft: #142a20;
  --danger: #ec96a0;
  --danger-soft: #331a1e;
  --shadow: 0 1px 2px rgba(0, 0, 0, .32), 0 10px 28px rgba(0, 0, 0, .34);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  padding: 0 20px 72px;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.6 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, sans-serif;
  -webkit-font-smoothing: antialiased;
}

main, .topbar, .foot { max-width: 1080px; margin: 0 auto; }

a { color: var(--accent); }
a:hover { color: var(--ochre); }

.skip {
  position: absolute; left: -9999px; top: 0;
  background: var(--surface); padding: 10px 16px; border-radius: var(--radius-sm);
}
.skip:focus { left: 12px; top: 12px; z-index: 40; }

.hidden { display: none !important; }
.mono { font-family: var(--mono); font-size: .92em; }
.muted { color: var(--ink-faint); }
.small { font-size: .88rem; }

/* --- header --------------------------------------------------------------------------- */

.topbar {
  display: flex; flex-wrap: wrap; gap: 16px;
  align-items: center; justify-content: space-between;
  padding: 22px 0 18px;
  border-bottom: 1px solid var(--line);
}

.brand { display: flex; align-items: center; gap: 14px; }
.brand h1 { margin: 0; font-size: 1.35rem; letter-spacing: -.01em; }
.tagline { margin: 2px 0 0; color: var(--ink-faint); font-size: .9rem; }

.mark {
  display: inline-flex; align-items: center; justify-content: center;
  width: 40px; height: 40px;
  border: 1px solid var(--line-strong); border-radius: var(--radius-sm);
  background: var(--surface-2); color: var(--accent);
  font-size: 1.3rem; line-height: 1;
}

.session { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.home-link { font-size: .88rem; color: var(--ink-faint); text-decoration: none; }
.home-link:hover { color: var(--accent); }
.credits {
  font-family: var(--mono); font-size: .85rem;
  padding: 5px 10px; border-radius: 999px;
  background: var(--accent-soft); color: var(--ink);
}

/* --- buttons -------------------------------------------------------------------------- */

button, .ghost, .primary {
  font: inherit;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background .12s ease, border-color .12s ease, color .12s ease;
}

.primary {
  background: var(--accent); color: var(--accent-ink);
  border: 1px solid var(--accent);
  padding: 11px 20px; font-weight: 600;
}
.primary:hover:not(:disabled) { filter: brightness(1.08); }
.primary:disabled { opacity: .45; cursor: not-allowed; }

.ghost {
  background: var(--surface); color: var(--ink);
  border: 1px solid var(--line-strong);
  padding: 9px 14px; text-decoration: none; display: inline-block;
}
.ghost:hover { background: var(--surface-2); border-color: var(--accent); color: var(--ink); }
.small-btn { padding: 6px 11px; font-size: .85rem; }
.danger { color: var(--danger); border-color: var(--danger); }
.danger:hover { background: var(--danger-soft); border-color: var(--danger); }

input[type="text"], input[type="search"], textarea, select {
  font: inherit; color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  padding: 9px 11px;
  width: 100%;
}
textarea { resize: vertical; line-height: 1.55; }
input:focus, textarea:focus, select:focus {
  outline: 2px solid var(--accent); outline-offset: 1px; border-color: var(--accent);
}

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

.intro { max-width: 74ch; margin: 30px auto 8px; }
.intro p { margin: 0 0 12px; }

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 22px;
  margin: 22px 0;
}
.panel-head {
  display: flex; flex-wrap: wrap; gap: 12px;
  align-items: center; justify-content: space-between;
  margin-bottom: 10px;
}
.panel-head h2 { margin: 0; font-size: 1.1rem; letter-spacing: -.01em; }
.head-actions { display: flex; flex-wrap: wrap; gap: 8px; }

.klabel {
  display: inline-block;
  font-size: .78rem; text-transform: uppercase; letter-spacing: .08em;
  color: var(--ink-faint); margin-bottom: 4px;
}

/* --- the seed row --------------------------------------------------------------------- */

.seed-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.seed-row .klabel { margin: 0; }
.seed-input { width: auto; min-width: 210px; flex: 0 1 260px; }

/* --- the axis grid -------------------------------------------------------------------- */

.axis-grid {
  display: grid; gap: 14px;
  grid-template-columns: repeat(auto-fit, minmax(258px, 1fr));
  margin: 18px 0 6px;
}

.axis-card {
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  padding: 13px 14px;
}
/* The two axes named in the interface copy as the steering controls get a visible edge, so
 * the thing the app claims is steerable looks steerable. */
.axis-card.axis-primary { border-left: 3px solid var(--ochre); }
.axis-card.is-locked { background: var(--accent-soft); border-color: var(--accent); }

.axis-head {
  display: flex; align-items: baseline; justify-content: space-between; gap: 10px;
}
.axis-label { font-weight: 600; font-size: .95rem; }
.axis-question { margin: 4px 0 8px; }
.axis-blurb {
  margin: 8px 0 0; font-size: .86rem; color: var(--ink-soft);
  min-height: 2.6em;
}
.lock {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: .78rem; color: var(--ink-faint); white-space: nowrap; cursor: pointer;
}
.lock input { width: auto; }

.divergence { margin-top: 14px; padding-top: 14px; border-top: 1px dashed var(--line); }
.divergence p { margin: 0 0 4px; }
#divergence { color: var(--ochre); font-weight: 600; }

.tensions { margin: 10px 0 0; padding-left: 18px; }
.tension-head { list-style: none; margin-left: -18px; color: var(--warn); font-size: .88rem; }
.tension { font-size: .88rem; color: var(--ink-soft); }

/* --- the note field ------------------------------------------------------------------- */

.note-card {
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  padding: 12px;
  background: var(--surface-2);
}
.note-card.is-blocked { border-color: var(--danger); background: var(--danger-soft); }
.note-foot { display: flex; justify-content: space-between; margin-top: 6px; }

.guard-panel {
  margin-top: 14px; padding: 14px;
  border: 1px solid var(--danger); border-radius: var(--radius-sm);
  background: var(--danger-soft);
}
.guard-message { margin: 0 0 8px; font-weight: 600; color: var(--danger); }
.guard-list { margin: 0 0 8px; padding-left: 18px; font-size: .88rem; }
.guard-item { margin-bottom: 4px; }
.guard-phrase { color: var(--danger); }
.guard-target { color: var(--danger); }

.lint-panel {
  margin-top: 14px; padding: 14px;
  border: 1px solid var(--warn); border-radius: var(--radius-sm);
  background: var(--warn-soft);
}
.lint-head { margin: 0 0 8px; font-weight: 600; color: var(--warn); }
.lint-list { margin: 0 0 8px; padding-left: 18px; font-size: .9rem; }
.lint-item { margin-bottom: 8px; }
.lint-phrase { color: var(--warn); }
.lint-instead { margin: 2px 0 0; }

/* --- the brief ------------------------------------------------------------------------ */

.brief {
  margin: 12px 0 8px;
  padding: 16px 18px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius-sm);
  font-family: var(--mono);
  font-size: .87rem; line-height: 1.7;
  white-space: pre-wrap; word-break: break-word;
  max-height: 460px; overflow-y: auto;
}

/* --- the render panel ------------------------------------------------------------------ */

.render-controls {
  display: flex; flex-wrap: wrap; gap: 16px; align-items: flex-start;
  margin-bottom: 10px;
}
.field { flex: 0 0 auto; }
.field select { width: auto; min-width: 84px; }
.field-note { flex: 1 1 260px; margin: 0; align-self: center; }

.meter {
  margin: 8px 0; padding: 10px 12px;
  background: var(--accent-soft); border-radius: var(--radius-sm);
  font-size: .87rem; color: var(--ink);
  min-height: 1.2em;
}

.gate {
  margin: 10px 0; padding: 13px 14px;
  border: 1px solid var(--line-strong); border-left: 3px solid var(--ochre);
  border-radius: var(--radius-sm); background: var(--ochre-soft);
  display: flex; flex-wrap: wrap; gap: 12px; align-items: center;
  justify-content: space-between;
}
.gate p { margin: 0; flex: 1 1 320px; font-size: .9rem; }

.run-row { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 12px; }

/* --- progress --------------------------------------------------------------------------- */

.progress {
  margin-top: 18px; padding: 14px;
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: var(--surface-2);
}
.progress-head { display: flex; justify-content: space-between; margin-bottom: 8px; }
.steps { margin: 0; padding-left: 20px; font-size: .89rem; }
.step { color: var(--ink-faint); margin-bottom: 3px; }
.step-doing { color: var(--accent); font-weight: 600; }
.step-done { color: var(--ok); }
.step-failed { color: var(--danger); font-weight: 600; }

/* --- the gallery ------------------------------------------------------------------------ */

.result { margin-top: 20px; }
.result-head {
  display: flex; flex-wrap: wrap; gap: 12px;
  align-items: flex-start; justify-content: space-between;
  margin-bottom: 12px;
}
.result-head h3 { margin: 0; font-size: 1.02rem; }
.result-head p { margin: 3px 0 0; }

.gallery {
  display: grid; gap: 16px;
  grid-template-columns: repeat(auto-fit, minmax(268px, 1fr));
}
.shot { margin: 0; }
.shot-frame {
  position: relative;
  aspect-ratio: 1 / 1;
  display: flex; align-items: center; justify-content: center;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  overflow: hidden;
}
.shot-frame img { width: 100%; height: 100%; object-fit: cover; display: block; }
.shot-empty { color: var(--ink-faint); }
.shot-working { border-color: var(--accent); }
.shot-failed { border-color: var(--danger); background: var(--danger-soft); }
.shot-idx { font-size: 1.6rem; color: var(--ink-faint); }
.shot-note { margin: 0; padding: 14px; font-size: .85rem; text-align: center; color: var(--danger); }
.shot-cap {
  display: flex; flex-wrap: wrap; gap: 8px;
  align-items: center; justify-content: space-between;
  margin-top: 8px;
}
.shot-status { font-size: .78rem; color: var(--ink-faint); }
.shot-acts { display: flex; flex-wrap: wrap; gap: 6px; }

/* --- history ----------------------------------------------------------------------------- */

.modal {
  position: fixed; inset: 0; z-index: 30;
  background: rgba(16, 19, 32, .55);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 40px 16px; overflow-y: auto;
}
.modal-card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
  width: 100%; max-width: 700px; padding: 20px;
}
.modal-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  margin-bottom: 12px;
}
.modal-head h2 { margin: 0; font-size: 1.05rem; }
.modal-foot { margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--line); }
.history-tools { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 8px; }
.history-tools input { flex: 1 1 200px; width: auto; }
.history-list { list-style: none; margin: 10px 0 0; padding: 0; }
.history-row {
  display: flex; flex-wrap: wrap; gap: 10px;
  align-items: flex-start; justify-content: space-between;
  padding: 11px 0; border-bottom: 1px solid var(--line);
}
.history-main { flex: 1 1 300px; }
.history-title { margin: 0; font-weight: 600; font-size: .95rem; }
.history-meta { margin: 2px 0 0; }
.history-note { margin: 4px 0 0; }
.history-acts { display: flex; gap: 6px; }
.history-empty { padding: 18px 0; }

/* --- toast and footer --------------------------------------------------------------------- */

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  z-index: 50; max-width: 560px;
  padding: 12px 18px; border-radius: var(--radius-sm);
  box-shadow: var(--shadow); font-size: .9rem;
}
.toast-ok { background: var(--ok-soft); color: var(--ok); border: 1px solid var(--ok); }
.toast-err { background: var(--danger-soft); color: var(--danger); border: 1px solid var(--danger); }

.foot {
  margin-top: 40px; padding-top: 20px;
  border-top: 1px solid var(--line);
  color: var(--ink-faint); font-size: .88rem;
}
.foot p { margin: 0 0 8px; max-width: 74ch; }
.foot-links { display: flex; flex-wrap: wrap; gap: 8px; }

/* --- the docs pages ------------------------------------------------------------------------
 * api.html and tokens.html carry their own stylesheet for their own furniture, but they share
 * this file's header, footer and buttons. These two rules are all they need from here. */
main.doc { max-width: 900px; margin: 0 auto; }
.token-box {
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: var(--surface-2); padding: 14px; margin: 12px 0;
}
.token-val { word-break: break-all; }
.theme-toggle { margin-left: 4px; }

@media (max-width: 640px) {
  body { padding: 0 14px 56px; }
  .panel { padding: 16px; }
  .topbar { padding: 16px 0 14px; }
  .axis-grid { grid-template-columns: 1fr; }
  .gallery { grid-template-columns: 1fr; }
  .brief { font-size: .82rem; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; scroll-behavior: auto !important; }
}
