/* ReadGen UI ------------------------------------------------------------- */

:root {
  --bg: #0f1419;
  --panel: #161c23;
  --panel2: #1d252e;
  --line: #2a3541;
  --ink: #e6edf3;
  --dim: #8b98a5;
  --accent: #4c9aff;
  --accent-dim: #2b6cb0;
  --ok: #3fb950;
  --warn: #d29922;
  --danger: #f85149;
  --radius: 8px;
  --ui: -apple-system, system-ui, "Segoe UI", "Liberation Sans", sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--ui);
  font-size: 14px;
}

/* --- top bar ------------------------------------------------------------ */
.topbar {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 20px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}
.brand { display: flex; align-items: baseline; gap: 12px; }
.logo { font-size: 18px; font-weight: 700; letter-spacing: -0.3px; }
.tagline { color: var(--dim); font-size: 12.5px; }
.status { color: var(--dim); font-size: 12.5px; }
.status.ok { color: var(--ok); }
.status.err { color: var(--danger); }

/* --- layout ------------------------------------------------------------- */
.layout {
  display: grid;
  grid-template-columns: 400px 1fr;
  gap: 0;
  height: calc(100% - 49px);
}
@media (max-width: 980px) {
  .layout { grid-template-columns: 1fr; height: auto; }
}

.panel { overflow: auto; padding: 14px; }
#controls { border-right: 1px solid var(--line); background: var(--panel); }

/* --- steps -------------------------------------------------------------- */
.step {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel2);
  margin-bottom: 10px;
}
.step > summary {
  cursor: pointer;
  padding: 10px 12px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
  list-style: none;
  user-select: none;
}
.step > summary::-webkit-details-marker { display: none; }
.step > summary::after {
  content: "▾";
  margin-left: auto;
  color: var(--dim);
  transition: transform .15s;
}
.step:not([open]) > summary::after { transform: rotate(-90deg); }
.num {
  width: 20px; height: 20px;
  border-radius: 50%;
  background: var(--accent-dim);
  color: #fff;
  font-size: 11px;
  display: grid;
  place-items: center;
  flex: none;
}
.pill {
  background: var(--line);
  color: var(--dim);
  border-radius: 20px;
  padding: 1px 9px;
  font-size: 11.5px;
  font-weight: 600;
}
.pill.on { background: var(--accent-dim); color: #fff; }
.body { padding: 0 12px 12px; }

.hint { color: var(--dim); font-size: 12px; margin: 4px 0 8px; line-height: 1.45; }

/* --- inputs ------------------------------------------------------------- */
label { display: block; font-size: 12px; color: var(--dim); margin-bottom: 8px; }
input, select {
  width: 100%;
  margin-top: 3px;
  padding: 6px 8px;
  background: #0f151b;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--ink);
  font: inherit;
  font-size: 13px;
}
input[type="color"] { padding: 2px; height: 30px; cursor: pointer; }
input[type="checkbox"] { width: auto; margin: 0 6px 0 0; }
input:focus, select:focus { outline: none; border-color: var(--accent); }

.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 10px; }
.filters { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 0 8px; }
.search { margin-bottom: 8px; }

.check {
  display: block;
  color: var(--ink);
  font-size: 12.5px;
  border-top: 1px solid var(--line);
  padding-top: 9px;
  margin-top: 4px;
}
.check .hint { margin: 3px 0 0 22px; }
.seed { width: 62px !important; display: inline-block; margin-left: 6px; padding: 2px 6px; }

/* --- buttons ------------------------------------------------------------ */
.rowbtns { display: flex; flex-wrap: wrap; gap: 6px; margin: 6px 0 8px; }
.mini {
  background: #0f151b;
  border: 1px solid var(--line);
  color: var(--dim);
  border-radius: 5px;
  padding: 4px 9px;
  font: inherit;
  font-size: 11.5px;
  cursor: pointer;
}
.mini:hover { border-color: var(--accent); color: var(--ink); }
.mini.danger:hover { border-color: var(--danger); color: var(--danger); }

.go {
  width: 100%;
  padding: 11px;
  background: var(--accent);
  border: none;
  border-radius: 6px;
  color: #06121f;
  font: inherit;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
}
.go:disabled { background: var(--line); color: var(--dim); cursor: not-allowed; }
.go:not(:disabled):hover { filter: brightness(1.1); }

/* --- chips -------------------------------------------------------------- */
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  border: 1px solid var(--line);
  background: #0f151b;
  color: var(--dim);
  border-radius: 6px;
  padding: 5px 10px;
  font-size: 12.5px;
  cursor: pointer;
  user-select: none;
}
.chip:hover { border-color: var(--accent); }
.chip.on { background: var(--accent-dim); border-color: var(--accent); color: #fff; }
.chip .code { opacity: .6; font-size: 10.5px; margin-left: 5px; }

/* --- passage list ------------------------------------------------------- */
.list {
  max-height: 300px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #0f151b;
}
.item {
  display: flex;
  gap: 8px;
  padding: 7px 9px;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
  align-items: flex-start;
}
.item:last-child { border-bottom: none; }
.item:hover { background: #141d26; }
.item input { margin-top: 2px; flex: none; }
.item .t { font-size: 12.5px; line-height: 1.35; }
.item .m { color: var(--dim); font-size: 11px; margin-top: 2px; }
.empty { padding: 14px; color: var(--dim); font-size: 12.5px; text-align: center; }

/* --- progress / log ----------------------------------------------------- */
.estimate {
  background: #0f151b;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 9px 10px;
  font-size: 12.5px;
  color: var(--dim);
  margin-bottom: 10px;
  line-height: 1.5;
}
.estimate b { color: var(--ink); }
.estimate .warn { color: var(--warn); }

.progress { margin-top: 10px; }
.bar { height: 6px; background: var(--line); border-radius: 4px; overflow: hidden; }
.fill { height: 100%; width: 0; background: var(--accent); transition: width .15s; }
.ptext { font-size: 11.5px; color: var(--dim); margin: 6px 0; }

.log {
  margin-top: 8px;
  font-family: "Roboto Mono", ui-monospace, monospace;
  font-size: 11px;
  color: var(--dim);
  max-height: 120px;
  overflow: auto;
  white-space: pre-wrap;
}
.log .err { color: var(--danger); }
.log .ok { color: var(--ok); }

/* --- preview ------------------------------------------------------------ */
.preview { display: flex; flex-direction: column; gap: 10px; }
.previewbar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.previewbar select { width: auto; min-width: 90px; margin-top: 0; }
.previewbar .grow { flex: 1; min-width: 180px; }
.previewbar .meta { color: var(--dim); font-size: 11.5px; margin-left: auto; }

.stagewrap {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #0a0e12;
  padding: 14px;
  display: grid;
  place-items: center;
  overflow: hidden;
  min-height: 260px;
}
#previewStage { transform-origin: top left; }
.pvhint { max-width: 70ch; }

/* --- offscreen render surface ------------------------------------------- */
#renderRoot {
  position: absolute;
  left: -9999px;
  top: 0;
  width: 0;
  height: 0;
  pointer-events: none;
}

/* --- the stimulus itself (this is what ends up in the PNG) -------------- */
.stimulus {
  position: relative;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.stimulus.va-center { justify-content: center; }
.stimulus.va-top { justify-content: flex-start; }

/* Applied to BOTH the real stimulus body and the hidden measuring element,
   so pagination measures exactly what gets rendered. */
.rg-text {
  width: 100%;
  flex: none;
  white-space: pre-wrap;
  word-wrap: break-word;
  overflow-wrap: break-word;
  text-align: left;
  box-sizing: border-box;
  padding: 0;
  border: 0;
  letter-spacing: normal;
}
.rg-text p { margin: 0; }
.rg-text .qprompt { margin: 0 0 1em 0; }
