/* ===========================================================================
   undoai, ink on cool slate
   Near-monochrome, cool-neutral dark. One restrained blue marks where the
   machine is alive (loader, focus, selection, active model). Crisp, plain,
   precise, the writing is the interface. No decoration.
   =========================================================================== */

/* ---------------------------------------------------------------------------
   Self-hosted type. Geist + Geist Mono (SIL OFL 1.1), vendored in /fonts/ so the
   page makes no third-party font request and leaks no visitor IP to a CDN.
   latin + latin-ext subsets; system stack is the fallback.
   --------------------------------------------------------------------------- */
@font-face {
  font-family: "Geist";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("/fonts/geist-400-latin-ext.woff2") format("woff2");
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: "Geist";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("/fonts/geist-400-latin.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "Geist";
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url("/fonts/geist-500-latin-ext.woff2") format("woff2");
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: "Geist";
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url("/fonts/geist-500-latin.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "Geist";
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url("/fonts/geist-600-latin-ext.woff2") format("woff2");
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: "Geist";
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url("/fonts/geist-600-latin.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "Geist Mono";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("/fonts/geist-mono-400-latin-ext.woff2") format("woff2");
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: "Geist Mono";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("/fonts/geist-mono-400-latin.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "Geist Mono";
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url("/fonts/geist-mono-500-latin-ext.woff2") format("woff2");
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: "Geist Mono";
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url("/fonts/geist-mono-500-latin.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

:root {
  /* surfaces, cool near-black, layered */
  --bg: #0a0b0d;
  --bg-2: #0d0e11;
  --surface: #121419;
  --surface-2: #171a20;
  --surface-3: #1d2027;

  /* ink, cool off-white, never pure white */
  --ink: #e7e9ee;
  --muted: #a3aab6;
  --faint: #7b828f;

  /* hairlines */
  --line: #20242c;
  --line-strong: #2b3039;

  /* accent, one flat, desaturated blue; "alive" only */
  --accent: #4d8dff;
  --accent-hover: #6ba1ff;
  --accent-soft: rgba(77, 141, 255, 0.14);
  --accent-line: rgba(77, 141, 255, 0.45);

  /* degraded / rules-only, one muted amber, used only on the model dot + notice */
  --warn: #cf9b51;

  /* diff */
  --ins-bg: rgba(77, 141, 255, 0.16);
  --ins-ink: #c6dbff;
  --del-ink: #6b727e;

  /* type */
  --sans: "Geist", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --mono: "Geist Mono", ui-monospace, "Cascadia Mono", "SF Mono", Menlo, Consolas, monospace;

  /* shape + depth, minimal; lean on borders, not shadows */
  --radius: 10px;
  --radius-sm: 8px;
  --shadow-pop: 0 24px 60px -24px rgba(0, 0, 0, 0.72), 0 2px 8px -4px rgba(0, 0, 0, 0.6);

  /* motion */
  --ease: cubic-bezier(0.4, 0, 0.2, 1);
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
/* Reserve the scrollbar gutter so opening the modal (which toggles page
   scrollability) never shifts the layout. */
html { scrollbar-gutter: stable; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.55;
  font-feature-settings: "cv01", "ss03";
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

::selection { background: var(--accent-soft); color: var(--ink); }

/* thin, quiet scrollbars */
* {
  scrollbar-width: thin;
  scrollbar-color: var(--line-strong) transparent;
}
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-thumb {
  background: var(--line-strong);
  border-radius: 10px;
  border: 3px solid transparent;
  background-clip: content-box;
}
*::-webkit-scrollbar-thumb:hover { background: #3a404b; background-clip: content-box; }

/* ---------- app shell: one calm full-height viewport ---------- */
.app {
  height: 100dvh;
  max-width: 1180px;
  margin: 0 auto;
  padding: 0 32px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ---------- top bar ---------- */
.topbar {
  flex: 0 0 auto;
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--line);
}
.brand {
  display: inline-flex;
  align-items: baseline;
  gap: 11px;
  text-decoration: none;
  color: var(--ink);
}
.brand-mark {
  font-size: 16px;
  font-weight: 600;
  letter-spacing: -0.012em;
}
.brand em { font-style: normal; color: var(--faint); font-weight: 500; }
.brand-tag {
  position: relative;
  padding-left: 12px;
  font-size: 13px;
  font-weight: 400;
  color: var(--muted);
  letter-spacing: -0.005em;
  white-space: nowrap;
}
.brand-tag::before {
  content: "";
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  height: 13px;
  width: 1px;
  background: var(--line-strong);
}

/* model indicator */
.model {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: 0.01em;
  color: var(--muted);
  user-select: none;
}
.model-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--faint);
  position: relative;
  flex: 0 0 auto;
  transition: background 0.25s var(--ease);
}
.model.is-busy .model-dot { background: var(--accent); }
.model.is-busy .model-dot::after {
  content: "";
  position: absolute;
  inset: -3px;
  border-radius: 50%;
  border: 1px solid var(--accent);
  animation: dot-ping 1.2s var(--ease-out) infinite;
}
.model.is-degraded .model-dot { background: var(--warn); }
@keyframes dot-ping {
  0% { opacity: 0.7; transform: scale(0.6); }
  100% { opacity: 0; transform: scale(1.6); }
}
.model-name {
  white-space: nowrap;
  color: inherit;
  text-decoration: none;
  transition: color 0.15s var(--ease);
}
a.model-name:hover { color: var(--ink); }

/* ---------- stage + editor ---------- */
.stage {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding: 24px 0;
}
.editor {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}

/* ---------- panels ---------- */
.panel {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
  transition: border-color 0.2s var(--ease);
}
#inputPanel:focus-within { border-color: var(--line-strong); }

.panel-head {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  height: 46px;
  padding: 0 16px;
  border-bottom: 1px solid var(--line);
}
.panel-label {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.13em;
  text-transform: uppercase;
  color: var(--faint);
}
.head-right { display: flex; align-items: center; gap: 16px; }
.counter {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--faint);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.panel-tools { display: flex; gap: 8px; }

.linklike {
  appearance: none;
  border: 0;
  background: transparent;
  text-decoration: none;
  font-family: var(--sans);
  font-size: 13px;
  color: var(--muted);
  cursor: pointer;
  padding: 0;
  transition: color 0.15s var(--ease);
}
.linklike:hover { color: var(--ink); }

/* ---------- textarea ---------- */
textarea#input {
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
  border: 0;
  resize: none;
  padding: 18px 16px;
  font-family: var(--sans);
  font-size: 15.5px;
  line-height: 1.7;
  color: var(--ink);
  background: transparent;
  outline: none;
}
textarea#input::placeholder { color: var(--faint); }

/* ---------- panel foot ---------- */
.panel-foot {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 14px;
  padding: 12px 16px;
  border-top: 1px solid var(--line);
}

/* ---------- buttons ---------- */
.btn-primary {
  appearance: none;
  border: 0;
  background: var(--ink);
  color: var(--bg);
  font-family: var(--sans);
  font-size: 13.5px;
  font-weight: 600;
  letter-spacing: 0.005em;
  padding: 9px 16px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 9px;
  white-space: nowrap;
  transition: background 0.15s var(--ease), opacity 0.15s var(--ease), transform 0.06s var(--ease);
}
.btn-primary:hover:not(:disabled) { background: #ffffff; }
.btn-primary:active:not(:disabled) { transform: translateY(1px); }
.btn-primary:disabled { background: var(--surface-3); color: var(--faint); cursor: not-allowed; }
.btn-primary kbd {
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 500;
  background: rgba(10, 11, 13, 0.16);
  color: inherit;
  padding: 2px 5px;
  border-radius: 5px;
  line-height: 1;
}

.btn-ghost {
  appearance: none;
  background: transparent;
  border: 1px solid var(--line-strong);
  color: var(--muted);
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.04em;
  padding: 6px 11px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: color 0.15s var(--ease), border-color 0.15s var(--ease), background 0.15s var(--ease);
}
.btn-ghost:hover { color: var(--ink); border-color: var(--faint); background: var(--surface-2); }
.btn-ghost.done { color: var(--accent); border-color: var(--accent-line); }

/* focus visibility (a11y) */
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
.btn-primary:focus-visible, .btn-ghost:focus-visible { outline-offset: 3px; }

/* ---------- output ---------- */
.output {
  flex: 1 1 auto;
  min-height: 0;
  padding: 18px 16px;
  overflow-y: auto;
}
.placeholder { color: var(--faint); font-size: 15px; }

.result {
  font-size: 15.5px;
  line-height: 1.7;
  white-space: pre-wrap;
  color: var(--ink);
}
.result.reveal { animation: rise 0.45s var(--ease-out) both; }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.result ins { background: var(--ins-bg); color: var(--ins-ink); text-decoration: none; border-radius: 3px; padding: 0 1px; }
.result del { color: var(--del-ink); text-decoration-line: line-through; text-decoration-thickness: 1px; }

/* ---------- moving loader ---------- */
/* top-edge indeterminate progress bar */
.progress {
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 2px;
  overflow: hidden;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s var(--ease);
  z-index: 2;
}
#outputPanel.busy .progress { opacity: 1; }
.progress::before {
  content: "";
  position: absolute;
  inset: 0;
  background: var(--accent-soft);
}
.progress::after {
  content: "";
  position: absolute;
  top: 0; bottom: 0;
  left: 0;
  width: 33%;
  background: linear-gradient(90deg, transparent 0%, var(--accent) 50%, transparent 100%);
  animation: sweep 1.15s var(--ease) infinite;
}
@keyframes sweep {
  0% { transform: translateX(-110%); }
  100% { transform: translateX(410%); }
}

/* shimmer skeleton where the result will land */
.skeleton { display: flex; flex-direction: column; gap: 12px; }
.skeleton-line {
  height: 13px;
  border-radius: 6px;
  background: linear-gradient(90deg, var(--surface-2) 0%, var(--surface-3) 42%, var(--surface-2) 84%);
  background-size: 220% 100%;
  animation: shimmer 1.5s linear infinite;
}
.skeleton-line:nth-child(1) { width: 100%; }
.skeleton-line:nth-child(2) { width: 96%; }
.skeleton-line:nth-child(3) { width: 88%; }
.skeleton-line:nth-child(4) { width: 62%; }
@keyframes shimmer {
  0% { background-position: 120% 0; }
  100% { background-position: -120% 0; }
}

.loader-caption {
  margin-top: 18px;
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: 0.02em;
  color: var(--faint);
}
.loader-caption::after { content: "\2026"; animation: ellipsis 1.4s steps(4) infinite; }
@keyframes ellipsis { 0% { opacity: 0.2; } 50% { opacity: 1; } 100% { opacity: 0.2; } }

/* ---------- rhythm readout (subtle, result-only) ---------- */
.panel-foot.meta { justify-content: flex-start; }
.rhythm {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--faint);
}
.rhythm-label { letter-spacing: 0.13em; text-transform: uppercase; }
.rhythm-num { color: var(--muted); font-variant-numeric: tabular-nums; }

/* ---------- footer ---------- */
.botbar {
  flex: 0 0 auto;
  height: 46px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-top: 1px solid var(--line);
  font-size: 12.5px;
  color: var(--faint);
}
.botbar .linklike { font-family: var(--mono); font-size: 12px; letter-spacing: 0.02em; }
.foot-right { display: inline-flex; align-items: center; gap: 16px; }
.foot-copy { font-family: var(--mono); font-size: 12px; color: var(--faint); white-space: nowrap; }
.foot-note { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
@media (max-width: 560px) {
  .botbar {
    height: auto;
    flex-direction: column-reverse;
    align-items: center;
    gap: 8px;
    padding: 14px 0 16px;
    text-align: center;
  }
  .foot-note { white-space: normal; line-height: 1.5; }
  .foot-right { gap: 18px; }
}

/* ---------- turnstile (managed widget, lives in the draft panel footer) ---------- */
.run-foot { justify-content: space-between; flex-wrap: wrap; gap: 12px; }
.turnstile-host { min-height: 0; }
.turnstile-host:empty { display: none; }

/* ---------- notice toast ---------- */
.notice {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  max-width: min(520px, calc(100vw - 40px));
  margin: 0;
  padding: 12px 16px;
  border: 1px solid var(--line-strong);
  border-left: 2px solid var(--warn);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  box-shadow: var(--shadow-pop);
  font-size: 13.5px;
  color: var(--ink);
  z-index: 50;
  animation: toast 0.3s var(--ease-out) both;
}
@keyframes toast { from { opacity: 0; transform: translateX(-50%) translateY(10px); } to { opacity: 1; transform: translateX(-50%) translateY(0); } }

/* ---------- modal ---------- */
.modal {
  border: 0;
  padding: 0;
  background: transparent;
  max-width: 480px;
  width: calc(100vw - 40px);
  color: var(--ink);
}
.modal::backdrop { background: rgba(5, 6, 8, 0.66); backdrop-filter: blur(2px); }
.modal[open] .modal-card { animation: pop 0.24s var(--ease-out) both; }
@keyframes pop { from { opacity: 0; transform: scale(0.97); } to { opacity: 1; transform: none; } }
.modal-card {
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: 12px;
  box-shadow: var(--shadow-pop);
  padding: 24px 26px 26px;
  max-height: calc(100dvh - 40px);
  overflow-y: auto;
}
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.modal-head h2 { font-size: 16px; font-weight: 600; margin: 0; letter-spacing: -0.01em; }
.modal-x {
  appearance: none; border: 0; background: transparent; cursor: pointer;
  font-size: 14px; color: var(--faint); padding: 6px 8px; border-radius: var(--radius-sm);
  transition: color 0.15s var(--ease), background 0.15s var(--ease);
}
.modal-x:hover { color: var(--ink); background: var(--surface-2); }
.modal-card h3 {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.13em;
  text-transform: uppercase;
  color: var(--faint);
  margin: 18px 0 7px;
}
.modal-card p { color: var(--muted); margin: 0 0 12px; font-size: 14px; line-height: 1.62; }
.modal-card p:last-child { margin-bottom: 0; }
.modal-lede { color: var(--muted); margin: 0 0 16px; font-size: 14px; }

/* numbered steps */
.steps { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 14px; }
.steps li { display: flex; align-items: flex-start; gap: 13px; }
.step-n {
  flex: 0 0 auto;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 500;
  color: var(--accent);
  background: var(--accent-soft);
  border: 1px solid var(--accent-line);
  margin-top: 1px;
}
.step-body { color: var(--muted); font-size: 14px; line-height: 1.55; }
.step-body b { color: var(--ink); font-weight: 600; }
.modal-note {
  margin: 18px 0 0;
  padding-top: 14px;
  border-top: 1px solid var(--line);
  color: var(--faint);
  font-size: 12.5px;
  line-height: 1.55;
}
.modal-note a { color: var(--muted); text-decoration: underline; text-underline-offset: 2px; }
.modal-note a:hover { color: var(--ink); }

/* ---------- custom tooltip (replaces native title=) ---------- */
.tooltip { position: relative; }
.tooltip::after {
  content: attr(data-tooltip);
  position: absolute;
  left: var(--tip-left, 50%);
  z-index: 80;
  width: max-content;
  max-width: 260px;
  padding: 9px 11px;
  border-radius: var(--radius-sm);
  background: var(--surface-3);
  border: 1px solid var(--line-strong);
  box-shadow: var(--shadow-pop);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 12.5px;
  font-weight: 400;
  line-height: 1.45;
  letter-spacing: 0;
  text-align: left;
  white-space: normal;
  opacity: 0;
  transform: translateX(var(--tip-x, -50%)) translateY(var(--tip-shift, 4px));
  pointer-events: none;
  transition: opacity 0.16s var(--ease), transform 0.16s var(--ease-out);
}
.tooltip::before {
  content: "";
  position: absolute;
  left: var(--arrow-left, 50%);
  z-index: 81;
  width: 8px;
  height: 8px;
  background: var(--surface-3);
  border: 1px solid var(--line-strong);
  transform: translateX(-50%) rotate(45deg);
  opacity: 0;
  transition: opacity 0.16s var(--ease);
}
.tooltip:hover::after,
.tooltip:focus-visible::after { opacity: 1; transform: translateX(var(--tip-x, -50%)) translateY(0); }
.tooltip:hover::before,
.tooltip:focus-visible::before { opacity: 1; }

/* vertical placement */
.tip-above::after { bottom: calc(100% + 9px); --tip-shift: 4px; }
.tip-above::before { bottom: calc(100% + 5px); border-top: 0; border-left: 0; }
.tip-below::after { top: calc(100% + 9px); --tip-shift: -4px; }
.tip-below::before { top: calc(100% + 5px); border-bottom: 0; border-right: 0; }

/* horizontal alignment: anchor the tooltip's right edge to the trigger so
   tooltips near the right edge of the screen don't clip off-canvas. */
.tip-end::after { --tip-left: auto; --tip-x: 0; right: 0; }
.tip-end::before { --arrow-left: auto; right: 14px; }

/* keep edge tooltips from clipping off-screen */
@media (max-width: 560px) {
  .tooltip::after { max-width: min(260px, calc(100vw - 32px)); }
}

/* ---------- entrance motion ---------- */
.reveal-on-load { animation: enter 0.5s var(--ease-out) both; animation-delay: var(--d, 0ms); }
@keyframes enter { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ---------- responsive ---------- */
@media (max-width: 900px) {
  .app { height: auto; min-height: 100dvh; overflow: visible; padding: 0 20px; }
  .editor { grid-template-columns: 1fr; gap: 16px; }
  .panel { min-height: 300px; }
  .stage { padding: 18px 0; }
}
@media (max-width: 560px) {
  .app { padding: 0 16px; }
  .topbar { height: auto; min-height: 54px; padding: 9px 0; gap: 12px; }
  .model-name { font-size: 11px; }
  /* Stack the tagline under the wordmark so the longer header still fits. */
  .brand { flex-direction: column; align-items: flex-start; gap: 2px; }
  .brand-tag { padding-left: 0; white-space: normal; font-size: 11.5px; line-height: 1.3; }
  .brand-tag::before { display: none; }
  /* Turnstile widget shouldn't crowd the button on small screens. */
  .run-foot { justify-content: center; }
  #inputPanel .panel-foot .btn-primary { width: 100%; justify-content: center; }
}

/* ---------- reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
  /* keep the loader legible without motion: a static partial bar + steady caption */
  .progress::after { animation: none; width: 36%; transform: none; left: 0; }
  .skeleton-line { animation: none; background: var(--surface-2); }
  .loader-caption::after { animation: none; }
  .model.is-busy .model-dot::after { animation: none; opacity: 0; }
}
