/* Illustration Desk — visual language borrowed from the Xiaohei Editorial
 * template (zyncli.com/templates/xiaohei-editorial): warm white canvas, black
 * ink linework, high whitespace, and a strict functional palette — red for
 * warnings/emphasis, orange for flow/movement, blue for secondary notes. */

:root {
  --bg: #faf7f1;
  --panel: #ffffff;
  --ink: #191614;
  --ink-soft: #5c5650;
  --line: #191614;
  --line-soft: #e4ddd2;
  --red: #d63b2f;
  --orange: #e2801f;
  --blue: #2b5d8f;
  --ok: #2e7d4f;
  --shadow: 0 2px 0 rgba(25, 22, 20, 0.9);
  --radius: 10px;
  --mono: "SF Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
:root[data-theme="dark"] {
  --bg: #16130f;
  --panel: #201c17;
  --ink: #ede7dc;
  --ink-soft: #a89f92;
  --line: #ede7dc;
  --line-soft: #3a342c;
  --red: #ef6a58;
  --orange: #eda04f;
  --blue: #7aa7d4;
  --ok: #6fbf8f;
  --shadow: 0 2px 0 rgba(237, 231, 220, 0.55);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.6 "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
}
h1, h2, h3, .klabel, button, input, select, .tagline, .step-label, .shot-title,
.style-name, .meter, .how-step h3 {
  font-family: "Avenir Next", Avenir, "Helvetica Neue", Helvetica, Arial, sans-serif;
}
.mono { font-family: var(--mono); font-size: 0.82em; }
.hidden { display: none !important; }
.muted { color: var(--ink-soft); }
.small { font-size: 0.82rem; }
a { color: var(--blue); text-decoration-thickness: 1px; text-underline-offset: 2px; }

/* --- header ---------------------------------------------------------------- */
header {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  flex-wrap: wrap;
  padding: 1.1rem clamp(1rem, 4vw, 2.4rem);
  border-bottom: 2px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 0.85rem; }
.brand .mark { width: 40px; height: 40px; color: var(--ink); flex: none; }
.brand h1 { margin: 0; font-size: 1.28rem; letter-spacing: 0.01em; }
.tagline { margin: 0.1rem 0 0; font-size: 0.85rem; color: var(--ink-soft); }
.session { display: flex; align-items: center; gap: 0.55rem; flex-wrap: wrap; }
.home-link {
  display: inline-flex; align-items: center; gap: 0.3rem;
  color: var(--ink-soft); text-decoration: none; font-size: 0.85rem;
}
.home-link svg { width: 14px; height: 14px; }
.home-link:hover { color: var(--ink); }
.credits { color: var(--ok); font-weight: 600; }
.topup { font-size: 0.85rem; }

/* --- buttons & inputs -------------------------------------------------------- */
button {
  cursor: pointer; font-size: 0.92rem; color: var(--ink);
  background: var(--panel);
  border: 2px solid var(--line); border-radius: var(--radius);
  padding: 0.45rem 0.95rem;
}
button:hover { box-shadow: var(--shadow); transform: translateY(-1px); }
button:disabled { opacity: 0.45; cursor: not-allowed; box-shadow: none; transform: none; }
button.primary { background: var(--ink); color: var(--bg); border-color: var(--ink); }
:root[data-theme="dark"] button.primary { color: #16130f; }
button.ghost { border-color: transparent; background: transparent; color: var(--ink-soft); }
button.ghost:hover { color: var(--ink); box-shadow: none; transform: none; text-decoration: underline; }
button.big { padding: 0.7rem 1.5rem; font-size: 1.02rem; }
button.linkish {
  border: none; background: none; padding: 0; color: var(--blue);
  text-decoration: underline; font: inherit;
}
button.linkish:hover { box-shadow: none; transform: none; }
.small-btn { padding: 0.25rem 0.7rem; font-size: 0.82rem; }
.danger { color: var(--red); }
.theme-toggle::after { content: "Theme"; }
input[type="text"], input[type="search"], select, textarea {
  width: 100%; font: inherit; font-size: 0.95rem; color: var(--ink);
  background: var(--panel);
  border: 2px solid var(--line-soft); border-radius: var(--radius);
  padding: 0.55rem 0.7rem;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--blue); }
textarea { resize: vertical; min-height: 10rem; line-height: 1.55; }
label { font-size: 0.85rem; color: var(--ink-soft); display: block; margin-bottom: 0.25rem; }

/* --- layout ------------------------------------------------------------------ */
main { max-width: 1060px; margin: 0 auto; padding: 1.6rem clamp(1rem, 4vw, 2.4rem) 3rem; }
.klabel {
  font-size: 0.78rem; font-weight: 700; letter-spacing: 0.09em; text-transform: uppercase;
  color: var(--ink);
}
.label-row {
  display: flex; align-items: baseline; justify-content: space-between; gap: 1rem;
  margin: 1.4rem 0 0.5rem; flex-wrap: wrap;
}
.card {
  background: var(--panel); border: 2px solid var(--line); border-radius: var(--radius);
  padding: 0.8rem;
}
.card.dropping { border-color: var(--orange); border-style: dashed; }
.card textarea { border: none; padding: 0.2rem; background: transparent; }
.doc-status { min-height: 1.2rem; font-size: 0.82rem; }
.doc-status.ok { color: var(--ok); }
.doc-status.warn { color: var(--orange); }
.doc-status.err { color: var(--red); }
.prescan { color: var(--ink-soft); font-size: 0.8rem; }

/* --- style picker --------------------------------------------------------------- */
.style-field input[type="search"] { margin-bottom: 0.7rem; }
.style-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 0.7rem; max-height: 30rem; overflow-y: auto; padding: 2px;
}
.style-card {
  position: relative; text-align: left; padding: 0;
  border: 2px solid var(--line-soft); border-radius: var(--radius);
  background: var(--panel); overflow: hidden;
}
.style-card:hover { border-color: var(--ink); }
.style-card.selected { border-color: var(--ink); box-shadow: var(--shadow); }
.style-card.selected::after {
  content: "Selected"; position: absolute; top: 8px; right: 8px;
  background: var(--ink); color: var(--bg); font-size: 0.68rem; font-weight: 700;
  padding: 0.1rem 0.5rem; border-radius: 99px; letter-spacing: 0.04em;
}
:root[data-theme="dark"] .style-card.selected::after { color: #16130f; }
.style-card img { display: block; width: 100%; aspect-ratio: 16/9; object-fit: cover; }
.style-card .style-body { padding: 0.55rem 0.65rem 0.65rem; }
.style-name { font-weight: 700; font-size: 0.92rem; }
.style-meta { font-size: 0.76rem; color: var(--ink-soft); margin-top: 0.1rem; }
.swatches { display: flex; gap: 4px; margin-top: 0.45rem; }
.swatch { width: 16px; height: 16px; border-radius: 50%; border: 1px solid rgba(0,0,0,0.2); }
.style-info {
  position: absolute; top: 8px; left: 8px; padding: 0 0.45rem; font-size: 0.72rem;
  background: var(--panel); border: 1.5px solid var(--line); border-radius: 99px;
}

/* --- style detail modal ------------------------------------------------------- */
.overlay {
  position: fixed; inset: 0; z-index: 40; background: rgba(25, 22, 20, 0.45);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 4vh 1rem; overflow-y: auto;
}
.modal {
  background: var(--bg); border: 2px solid var(--line); border-radius: 14px;
  width: min(760px, 100%); max-height: 88vh; overflow-y: auto; padding: 1.1rem 1.3rem;
}
.modal-head { display: flex; align-items: baseline; justify-content: space-between; gap: 1rem; margin-bottom: 0.6rem; }
.modal-head-acts { display: flex; gap: 0.5rem; }
.modal-foot { font-size: 0.8rem; color: var(--ink-soft); margin: 0.8rem 0 0; }
.style-detail img { width: 100%; border-radius: var(--radius); border: 2px solid var(--line); }
.style-detail h3 { margin: 1rem 0 0.3rem; font-size: 0.95rem; }
.style-detail ul { margin: 0.2rem 0 0.6rem 1.1rem; padding: 0; font-size: 0.9rem; }
.style-detail .pal-row { display: flex; align-items: center; gap: 0.5rem; font-size: 0.86rem; margin: 0.2rem 0; }
.style-detail .pal-row .swatch { width: 20px; height: 20px; flex: none; }
.style-detail .use-btn { margin-top: 0.9rem; }
.pattern { margin: 0.35rem 0 0.55rem; font-size: 0.9rem; }
.pattern strong { font-weight: 700; }
.pattern .muted { display: block; }

/* --- options / actions ---------------------------------------------------------- */
.options { margin-top: 1.1rem; }
.options summary { cursor: pointer; }
.row.three { display: grid; grid-template-columns: 1fr 1fr 1.4fr; gap: 0.9rem; margin-top: 0.7rem; }
.row.one { display: grid; grid-template-columns: 1fr; gap: 0.9rem; margin-top: 0.7rem; }
@media (max-width: 720px) { .row.three { grid-template-columns: 1fr; } }
.actions { display: flex; align-items: center; gap: 0.9rem; margin-top: 1.3rem; flex-wrap: wrap; }
.meter { font-size: 0.8rem; color: var(--ink-soft); }

/* --- progress -------------------------------------------------------------------- */
.progress-panel {
  margin-top: 1.6rem; border: 2px solid var(--line); border-radius: var(--radius);
  background: var(--panel); padding: 1rem 1.2rem;
}
.pp-top { display: flex; align-items: baseline; justify-content: space-between; gap: 1rem; }
.steps { list-style: none; margin: 0.8rem 0 0; padding: 0; }
.step { display: flex; gap: 0.6rem; padding: 0.32rem 0; align-items: flex-start; }
.step-ic { width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--line-soft); margin-top: 0.32rem; flex: none; }
.step.active .step-ic { border-color: var(--orange); background: var(--orange); }
.step.done .step-ic { border-color: var(--ok); background: var(--ok); }
.step-label { font-size: 0.92rem; font-weight: 600; }
.step.pending .step-label { color: var(--ink-soft); font-weight: 400; }
.step-detail { font-size: 0.8rem; color: var(--ink-soft); }

/* --- result ------------------------------------------------------------------------ */
.result { margin-top: 1.8rem; }
.reading-card {
  border: 2px solid var(--line); border-radius: var(--radius); background: var(--panel);
  padding: 1rem 1.2rem;
}
.reading-card h2 { margin: 0.1rem 0 0.3rem; font-size: 1.25rem; }
.reading-card .core { font-size: 1rem; }
.anchor-list { margin: 0.7rem 0 0; padding: 0; list-style: none; }
.anchor-list li { display: flex; gap: 0.55rem; padding: 0.18rem 0; font-size: 0.9rem; align-items: baseline; }
.kind {
  flex: none; font-size: 0.7rem; font-weight: 700; letter-spacing: 0.05em; text-transform: uppercase;
  padding: 0.05rem 0.5rem; border-radius: 99px; border: 1.5px solid;
  font-family: "Avenir Next", Avenir, "Helvetica Neue", Helvetica, Arial, sans-serif;
}
.kind-argument { color: var(--red); border-color: var(--red); }
.kind-flow { color: var(--orange); border-color: var(--orange); }
.kind-note { color: var(--blue); border-color: var(--blue); }
.check-line { margin-top: 0.8rem; font-size: 0.86rem; }
.check-line.ok { color: var(--ok); }
.check-line.warn { color: var(--orange); }
.check-line ul { margin: 0.25rem 0 0 1.2rem; padding: 0; }

.set-tools { display: flex; gap: 0.6rem; flex-wrap: wrap; margin: 1.1rem 0; }
.shot {
  border: 2px solid var(--line); border-radius: var(--radius); background: var(--panel);
  padding: 1rem 1.2rem; margin-bottom: 1rem;
}
.shot-head { display: flex; align-items: baseline; gap: 0.7rem; flex-wrap: wrap; }
.shot-n {
  flex: none; width: 30px; height: 30px; border-radius: 50%;
  border: 2px solid var(--line); display: inline-flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 0.95rem;
  font-family: "Avenir Next", Avenir, "Helvetica Neue", Helvetica, Arial, sans-serif;
}
.shot-title { font-size: 1.05rem; font-weight: 700; }
.shot-structure { font-size: 0.78rem; color: var(--blue); border: 1.5px solid var(--blue); border-radius: 99px; padding: 0.05rem 0.55rem; }
.shot-placement { font-size: 0.82rem; color: var(--orange); margin: 0.25rem 0 0.6rem; }
.shot dl { margin: 0.5rem 0; display: grid; grid-template-columns: auto 1fr; gap: 0.15rem 0.8rem; font-size: 0.9rem; }
.shot dt { color: var(--ink-soft); font-size: 0.8rem; white-space: nowrap; }
.shot dd { margin: 0; }
.labels-warn { color: var(--red); font-size: 0.84rem; }
.prompt-box {
  position: relative; background: var(--bg); border: 1.5px dashed var(--line-soft);
  border-radius: var(--radius); padding: 0.7rem 0.85rem; margin-top: 0.6rem;
  font-family: var(--mono); font-size: 0.8rem; white-space: pre-wrap; word-break: break-word;
}
.shot-tools { display: flex; gap: 0.5rem; margin-top: 0.55rem; flex-wrap: wrap; }
.shot-media { margin: 0.6rem 0 0.2rem; }
.media-frame {
  border: 1.5px solid var(--line-soft); border-radius: var(--radius); overflow: hidden;
  background: var(--bg); display: flex; align-items: center; justify-content: center;
  min-height: 72px;
}
.media-frame img { display: block; width: 100%; max-width: 560px; height: auto; margin: 0 auto; }
.media-frame .media-note { margin: 0.8rem 1rem; font-size: 0.82rem; color: var(--ink-soft); text-align: center; }
.media-frame.failed .media-note { color: var(--red); }
.media-frame.rendering { border-style: dashed; border-color: var(--orange); }
.media-frame.rendering .media-note { color: var(--orange); }
.media-frame.rendering::after {
  content: ""; width: 16px; height: 16px; margin: 0 0.9rem 0 0; flex: none;
  border: 2.5px solid var(--orange); border-top-color: transparent; border-radius: 50%;
  animation: media-spin 0.9s linear infinite;
}
@keyframes media-spin { to { transform: rotate(360deg); } }
.media-bar { display: flex; align-items: center; gap: 0.5rem; margin-top: 0.45rem; flex-wrap: wrap; }
.media-bar select.media-model { width: auto; font-size: 0.8rem; padding: 0.22rem 0.45rem; }
.media-status { font-size: 0.76rem; color: var(--ink-soft); }
.media-model {
  font: inherit; font-size: 0.78rem; padding: 0.25rem 0.4rem;
  border: 2px solid var(--line-soft); border-radius: 6px;
  background: var(--panel); color: var(--ink);
}
.set-notes {
  border: 2px solid var(--line-soft); border-radius: var(--radius);
  padding: 0.9rem 1.1rem; font-size: 0.9rem; margin-top: 1.1rem;
}
.skipped { margin-top: 1rem; font-size: 0.88rem; }
.skipped ul { margin: 0.3rem 0 0 1.2rem; padding: 0; }
.run-meta { margin-top: 1rem; font-size: 0.78rem; color: var(--ink-soft); }
.truncated-note { margin-top: 0.8rem; color: var(--red); font-size: 0.9rem; }

.raw-result { margin-top: 1.6rem; }
.raw-output {
  background: var(--panel); border: 2px solid var(--line); border-radius: var(--radius);
  padding: 1rem 1.2rem; white-space: pre-wrap; font-family: var(--mono); font-size: 0.82rem;
}

/* --- history --------------------------------------------------------------------------- */
.hist-count { color: var(--ink-soft); margin-left: 0.5rem; }
.hist-sync { font-size: 0.76rem; color: var(--ink-soft); }
.hist-list { display: flex; flex-direction: column; gap: 0.55rem; }
.hist-item {
  border: 1.5px solid var(--line-soft); border-radius: var(--radius);
  padding: 0.6rem 0.8rem; display: flex; justify-content: space-between; gap: 0.8rem; flex-wrap: wrap;
}
.hist-main { min-width: 200px; flex: 1; }
.hist-title { font-weight: 600; font-size: 0.92rem; }
.hist-sub { font-size: 0.78rem; color: var(--ink-soft); }
.hist-acts { display: flex; gap: 0.4rem; align-items: center; flex-wrap: wrap; }

/* --- how ------------------------------------------------------------------------------ */
.how { margin-top: 2.6rem; }
.how-lead { font-size: 0.95rem; }
.how-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 1rem; margin-top: 0.9rem; }
@media (max-width: 760px) { .how-grid { grid-template-columns: 1fr; } }

/* --- questions ------------------------------------------------------------------------ */
.faq { margin-top: 2.4rem; }
.faq-list { display: grid; grid-template-columns: repeat(2, 1fr); gap: 0.9rem; margin-top: 0.8rem; }
@media (max-width: 760px) { .faq-list { grid-template-columns: 1fr; } }
.faq-item { border: 2px solid var(--line-soft); border-radius: var(--radius); padding: 0.85rem 1rem; background: var(--panel); }
.faq-item h3 { margin: 0 0 0.35rem; font-size: 0.95rem; }
.faq-item p { margin: 0; font-size: 0.88rem; color: var(--ink-soft); }

/* --- run gate: why the model run is unavailable, at the run button --------------------- */
.run-gate {
  display: flex; align-items: center; gap: 0.75rem; flex-wrap: wrap;
  margin-top: 0.9rem; padding: 0.75rem 0.95rem;
  border: 2px solid var(--ink); border-radius: var(--radius);
  background: var(--panel); font-size: 0.9rem; line-height: 1.45;
}
.run-gate span { flex: 1 1 18rem; }

/* --- held-back render --------------------------------------------------------------- */
.render-hold {
  display: flex; align-items: center; gap: 0.75rem; flex-wrap: wrap;
  margin: 0.4rem 0 1.1rem; padding: 0.7rem 0.9rem;
  border: 2px dashed var(--line); border-radius: var(--radius);
  background: var(--panel); font-size: 0.88rem;
}
.render-hold span { flex: 1 1 18rem; }
.shot-file { font-size: 0.72rem; color: var(--ink-soft); align-self: center; }
.how-step { border: 2px solid var(--line-soft); border-radius: var(--radius); padding: 0.9rem 1rem; background: var(--panel); }
.how-step h3 { margin: 0.4rem 0 0.3rem; font-size: 0.98rem; }
.how-step p { margin: 0; font-size: 0.88rem; color: var(--ink-soft); }
.step-n {
  display: inline-flex; width: 26px; height: 26px; align-items: center; justify-content: center;
  border: 2px solid var(--ink); border-radius: 50%; font-weight: 700; font-size: 0.85rem;
  font-family: "Avenir Next", Avenir, "Helvetica Neue", Helvetica, Arial, sans-serif;
}

/* --- footer / toasts --------------------------------------------------------------------- */
footer {
  border-top: 2px solid var(--line); margin-top: 2.5rem;
  padding: 1rem clamp(1rem, 4vw, 2.4rem);
  font-size: 0.84rem; color: var(--ink-soft);
  display: flex; gap: 0.6rem; flex-wrap: wrap; align-items: center;
}
.foot-sep { color: var(--line-soft); }
.toasts { position: fixed; bottom: 1.2rem; right: 1.2rem; display: flex; flex-direction: column; gap: 0.5rem; z-index: 60; max-width: min(420px, 90vw); }
.toast {
  background: var(--ink); color: var(--bg); border-radius: var(--radius);
  padding: 0.6rem 0.9rem; font-size: 0.88rem;
  font-family: "Avenir Next", Avenir, "Helvetica Neue", Helvetica, Arial, sans-serif;
}
:root[data-theme="dark"] .toast { background: var(--panel); color: var(--ink); border: 2px solid var(--line); }
.toast.err { border-left: 6px solid var(--red); }
.toast.ok { border-left: 6px solid var(--ok); }
.toast a { color: var(--orange); }
