/* Meme Generator — app chrome only. The meme itself is drawn on a canvas with its own fixed
 * palette, deliberately outside this file: an exported picture has to look the same for the
 * person you send it to, whatever theme they happen to be using. */

:root {
  --bg: #f6f5f2;
  --panel: #ffffff;
  --panel-2: #fbfaf7;
  --ink: #16150f;
  --ink-soft: #5b584c;
  --ink-faint: #8b8778;
  --line: #e0ddd2;
  --line-strong: #cbc7b8;
  --accent: #7a3ea8;
  --accent-ink: #ffffff;
  --accent-soft: #f2e9fa;
  --warn: #a84b12;
  --warn-soft: #fdf0e4;
  --ok: #2c6b3f;
  --ok-soft: #e9f4ec;
  --danger: #a52020;
  --shadow: 0 1px 2px rgba(20, 18, 10, .06), 0 8px 24px rgba(20, 18, 10, .06);
  --radius: 12px;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

:root[data-theme="dark"] {
  --bg: #14140f;
  --panel: #1e1e18;
  --panel-2: #24241d;
  --ink: #f0eee5;
  --ink-soft: #b3afa1;
  --ink-faint: #857f70;
  --line: #33322a;
  --line-strong: #45443a;
  --accent: #c79cf0;
  --accent-ink: #1a1024;
  --accent-soft: #2b2138;
  --warn: #f0a86a;
  --warn-soft: #2e2113;
  --ok: #8ed3a4;
  --ok-soft: #14251a;
  --danger: #f08a8a;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 10px 30px rgba(0, 0, 0, .3);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.55 "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  -webkit-text-size-adjust: 100%;
}

.mono { font-family: var(--mono); font-size: .82em; }
.hidden { display: none !important; }

/* `hidden` is the platform-neutral way to hide a node, but the UA rule behind it
 * lives in the weakest cascade origin at specificity 0,1,0 - so any author class
 * rule that sets `display` silently beats it and the node paints anyway. Make the
 * attribute authoritative. Keep this in step with .hidden below/above: an element
 * is shown by clearing BOTH, never by dropping the class alone. */
[hidden] { display: none !important; }

.muted { color: var(--ink-soft); }
.small { font-size: .88rem; }

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

header {
  display: flex;
  flex-wrap: wrap;
  gap: 14px 20px;
  align-items: flex-start;
  justify-content: space-between;
  padding: 20px clamp(16px, 4vw, 40px);
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}

.brand { display: flex; gap: 14px; align-items: center; }
.brand .mark { width: 38px; height: 38px; color: var(--accent); flex: none; }
.brand h1 { margin: 0; font-size: 1.35rem; letter-spacing: -.01em; }
.tagline { margin: 2px 0 0; color: var(--ink-soft); font-size: .92rem; }

.session { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.home-link {
  display: inline-flex; gap: 5px; align-items: center;
  color: var(--ink-soft); text-decoration: none; font-size: .88rem;
}
.home-link svg { width: 14px; height: 14px; }
.home-link:hover { color: var(--ink); }
.credits { color: var(--ink-soft); }
.topup { color: var(--accent); font-size: .88rem; }

/* --- controls ---------------------------------------------------------------------------- */

button {
  font: inherit;
  cursor: pointer;
  border-radius: 9px;
  border: 1px solid var(--line-strong);
  background: var(--panel-2);
  color: var(--ink);
  padding: 9px 15px;
  transition: background .12s ease, border-color .12s ease, opacity .12s ease;
}
button:hover:not(:disabled) { border-color: var(--ink-faint); }
button:disabled { opacity: .45; cursor: not-allowed; }
button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
button.ghost { background: transparent; }
button.small-btn { padding: 6px 11px; font-size: .86rem; }
button.danger { color: var(--danger); }

input[type="text"], input[type="search"], textarea, select {
  font: inherit;
  width: 100%;
  color: var(--ink);
  background: var(--panel);
  border: 1px solid var(--line-strong);
  border-radius: 9px;
  padding: 9px 11px;
}
textarea { resize: vertical; font-size: .96rem; }
select { cursor: pointer; }
label { display: block; font-size: .88rem; color: var(--ink-soft); margin-bottom: 5px; }

.klabel {
  font-family: var(--mono);
  font-size: .74rem;
  letter-spacing: .09em;
  text-transform: uppercase;
  color: var(--ink-faint);
}
.klabel.small { font-size: .7rem; }
.label-row { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; margin-bottom: 7px; }
.prescan { color: var(--ink-faint); }
.prescan.at-limit { color: var(--warn); }
.hint { margin: 6px 0 0; font-size: .85rem; color: var(--ink-soft); }

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

main {
  max-width: 940px;
  margin: 0 auto;
  padding: 26px clamp(14px, 4vw, 30px) 60px;
}

.step {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 18px;
  box-shadow: var(--shadow);
}

.card { border: 1px solid var(--line-strong); border-radius: 10px; background: var(--panel); }
.card textarea { border: 0; background: transparent; }
.card.drop-on { border-color: var(--accent); background: var(--accent-soft); }
.doc-status { padding: 0 11px 8px; font-size: .82rem; color: var(--ink-soft); }

.row { display: grid; gap: 14px; margin-top: 14px; }
.row.three { grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); }
.check-cell { align-self: start; }
.check { display: flex; gap: 8px; align-items: center; color: var(--ink); font-size: .92rem; }
.check input { width: auto; }

/* --- format picker ------------------------------------------------------------------------ */

.format-choices { display: grid; gap: 10px; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); }
.format-btn { text-align: left; display: flex; flex-direction: column; gap: 5px; padding: 12px 13px; }
.format-btn.is-on { border-color: var(--accent); background: var(--accent-soft); }
.format-name { font-weight: 600; }
.format-blurb { font-size: .82rem; color: var(--ink-soft); line-height: 1.45; }

/* --- captions ------------------------------------------------------------------------------ */

.caption-fields { display: grid; gap: 13px; }
.caption-line { display: flex; gap: 8px; }
.anchor-select { width: auto; min-width: 128px; flex: none; }

.alts { margin-top: 14px; }
.alts-row { display: grid; gap: 8px; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); margin-top: 7px; }
.alt-btn { text-align: left; display: flex; flex-direction: column; gap: 3px; padding: 9px 11px; }
.alt-label { font-family: var(--mono); font-size: .72rem; text-transform: uppercase; letter-spacing: .08em; color: var(--accent); }
.alt-preview { font-size: .85rem; color: var(--ink-soft); }
.alt-restore { border-style: dashed; }

.why { margin: 12px 0 0; font-size: .9rem; color: var(--ink-soft); font-style: italic; }

.lint { list-style: none; margin: 13px 0 0; padding: 0; display: grid; gap: 6px; }
.lint li { font-size: .87rem; padding: 7px 10px; border-radius: 8px; border: 1px solid var(--line); color: var(--ink-soft); }
.lint .lint-ok { border-color: var(--ok); background: var(--ok-soft); color: var(--ok); }
.lint .lint-warn { border-color: var(--warn); background: var(--warn-soft); color: var(--warn); }
.lint .lint-head { border: 0; padding: 2px 0 0; font-family: var(--mono); font-size: .72rem; letter-spacing: .08em; text-transform: uppercase; color: var(--ink-faint); }

/* --- guard --------------------------------------------------------------------------------- */

.guard {
  margin-top: 14px;
  border: 1px solid var(--danger);
  border-radius: 10px;
  padding: 13px 15px;
  background: var(--warn-soft);
}
.guard.guard-redirect { border-color: var(--accent); background: var(--accent-soft); }
.guard h3 { margin: 0 0 6px; font-size: 1rem; }
.guard p { margin: 0 0 8px; font-size: .9rem; }
.guard-list { margin: 0 0 10px; padding-left: 18px; font-size: .86rem; }
.guard-list li { margin-bottom: 4px; }
.guard-acts { margin-bottom: 8px; }
.guard-foot { margin: 0; font-size: .8rem; color: var(--ink-soft); }

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

.brief-box { margin-top: 14px; border: 1px solid var(--line); border-radius: 10px; padding: 11px 13px; background: var(--panel-2); }
.brief-box summary { cursor: pointer; display: flex; gap: 10px; align-items: baseline; }
.brief {
  white-space: pre-wrap;
  font-family: var(--mono);
  font-size: .78rem;
  line-height: 1.65;
  margin: 11px 0;
  color: var(--ink-soft);
  max-height: 340px;
  overflow: auto;
}
.brief-acts { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

/* --- run row -------------------------------------------------------------------------------- */

.run-gate {
  border: 1px solid var(--accent);
  background: var(--accent-soft);
  border-radius: 10px;
  padding: 12px 14px;
  margin-bottom: 14px;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  justify-content: space-between;
}
.run-gate p { margin: 0; font-size: .89rem; flex: 1 1 320px; }
.run-row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.meter { font-size: .86rem; color: var(--ink-soft); flex: 1 1 260px; }
.run-note { margin: 10px 0 22px; }

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

.progress { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; margin-bottom: 18px; }
.progress-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 10px; }
.steps { list-style: none; margin: 0; padding: 0; display: grid; gap: 7px; }
/* Scoped to the progress list on purpose. A bare `.step` here also matches the wizard's
 * <section class="step"> cards, which are declared further up as ordinary blocks — the two
 * rules collide at equal specificity, the later one wins, and every card silently becomes a
 * nowrap flex row. That squashed the card contents side by side at every width and pushed the
 * page 194px wider than a 500px viewport. Keep this selector scoped. */
.steps .step { display: flex; gap: 10px; align-items: center; font-size: .89rem; color: var(--ink-faint); }
.step-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--line-strong); flex: none; }
.step-note { margin-left: auto; color: var(--ink-faint); }
.step-on { color: var(--ink); }
.step-on .step-dot { background: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); }
.step-done { color: var(--ink-soft); }
.step-done .step-dot { background: var(--ok); }
.step-failed { color: var(--danger); }
.step-failed .step-dot { background: var(--danger); }

/* --- the stage ---------------------------------------------------------------------------------- */

.result { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); }
.result-head { display: flex; flex-wrap: wrap; gap: 12px; justify-content: space-between; align-items: flex-start; margin-bottom: 14px; }
.result-head h2 { margin: 0; font-size: 1.15rem; }
.result-acts { display: flex; flex-wrap: wrap; gap: 7px; }
.stage {
  background: repeating-conic-gradient(var(--panel-2) 0% 25%, var(--panel) 0% 50%) 50% / 22px 22px;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  padding: 14px;
  display: flex;
  justify-content: center;
}
.stage canvas { max-width: 100%; height: auto; border-radius: 4px; box-shadow: 0 2px 14px rgba(0,0,0,.16); }

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

.overlay { position: fixed; inset: 0; background: rgba(12, 11, 8, .55); display: flex; align-items: flex-start; justify-content: center; padding: 5vh 14px; z-index: 40; }
.modal { background: var(--panel); border: 1px solid var(--line-strong); border-radius: var(--radius); width: min(720px, 100%); max-height: 88vh; overflow: auto; padding: 18px; box-shadow: var(--shadow); }
.modal-head { display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; margin-bottom: 12px; }
.modal-head-acts { display: flex; gap: 7px; }
.hist-count { margin-left: 8px; color: var(--ink-faint); }
.hist-sync { font-size: .82rem; color: var(--ink-soft); margin-top: 4px; }
.hist-search { display: flex; gap: 8px; margin-bottom: 13px; }
.hist-list { display: grid; gap: 10px; }
.hist-card { border: 1px solid var(--line); border-radius: 10px; padding: 11px 13px; background: var(--panel-2); }
.hist-head { display: flex; justify-content: space-between; gap: 10px; align-items: baseline; }
.hist-when { color: var(--ink-faint); }
.hist-line { margin: 5px 0; font-size: .9rem; }
.hist-meta { margin: 0 0 8px; color: var(--ink-faint); }
.hist-acts { display: flex; flex-wrap: wrap; gap: 7px; }
.modal-foot { font-size: .82rem; color: var(--ink-soft); margin: 14px 0 0; }
kbd { font-family: var(--mono); font-size: .78em; border: 1px solid var(--line-strong); border-radius: 4px; padding: 1px 4px; }

/* --- toast --------------------------------------------------------------------------------------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: 22px;
  transform: translateX(-50%);
  padding: 11px 17px;
  border-radius: 10px;
  font-size: .89rem;
  max-width: min(560px, 92vw);
  z-index: 60;
  box-shadow: var(--shadow);
}
.toast-ok { background: var(--ok-soft); color: var(--ok); border: 1px solid var(--ok); }
.toast-err { background: var(--warn-soft); color: var(--warn); border: 1px solid var(--warn); }

/* --- footer -------------------------------------------------------------------------------------- */

footer {
  border-top: 1px solid var(--line);
  padding: 26px clamp(16px, 4vw, 40px) 44px;
  color: var(--ink-soft);
  font-size: .87rem;
  background: var(--panel);
}
footer p { max-width: 78ch; margin: 0 0 9px; }
footer a { color: var(--accent); }
.foot-links { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 14px; }

/* --- docs pages ------------------------------------------------------------------------------------ */

.doc { max-width: 900px; margin: 0 auto; padding: 26px clamp(14px, 4vw, 30px) 60px; }
.doc h2 { margin-top: 34px; font-size: 1.2rem; }
.doc h3 { margin-top: 24px; font-size: 1rem; }
.doc p, .doc li { max-width: 78ch; }
.doc table { border-collapse: collapse; width: 100%; font-size: .88rem; margin: 14px 0; display: block; overflow-x: auto; }
.doc th, .doc td { border: 1px solid var(--line); padding: 7px 9px; text-align: left; vertical-align: top; }
.doc th { background: var(--panel-2); }
.tabs { display: flex; flex-wrap: wrap; gap: 6px; margin: 14px 0 0; }
.tab.is-on { border-color: var(--accent); background: var(--accent-soft); }
pre {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 13px 15px;
  overflow-x: auto;
  font-family: var(--mono);
  font-size: .8rem;
  line-height: 1.6;
}
code { font-family: var(--mono); font-size: .86em; }
.token-box { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 17px; margin-bottom: 16px; }
.token-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 10px; }
.token-val { font-family: var(--mono); font-size: .8rem; word-break: break-all; background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 9px 11px; }

@media (max-width: 620px) {
  .caption-line { flex-direction: column; }
  .anchor-select { width: 100%; }
  header { padding: 16px; }
}

/* --- questions, as collapsed disclosures ---
 *
 * These back the page's FAQPage schema. A closed <details> still renders its content into the
 * DOM, so the answers are visible content that costs nothing above the first field. Never put a
 * refusal, a gate or an input in here — only prose a reader can choose to open.
 */

.faq { margin-top: 26px; padding-top: 18px; border-top: 1px solid var(--line); }
.faq > .hint { margin-bottom: 10px; }
.faq-item {
  border: 1px solid var(--line); border-radius: 10px;
  background: var(--panel-2); padding: 10px 13px; margin-bottom: 8px;
}
.faq-item > summary { cursor: pointer; font-size: .92rem; font-weight: 620; color: var(--ink); }
.faq-item > summary:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.faq-item[open] > summary { margin-bottom: 8px; }
.faq-item p { margin: 0 0 8px; font-size: .88rem; line-height: 1.6; color: var(--ink-soft); max-width: 78ch; }
.faq-item p:last-child { margin-bottom: 0; }
