/* ==========================================================================
   MakeItMarkdown — design system + landing screen
   Art direction: quiet, precise developer tool. Near-neutral palette,
   one indigo accent, generous whitespace, one focal point (the input).
   Themes: CSS light-dark() + [data-theme] override (JS toggle).
   ========================================================================== */

/* --- Fonts (self-hosted, latin subset, variable weight) ------------------ */

@font-face {
  font-family: "Inter";
  font-style: normal;
  font-weight: 400 700;
  font-display: swap;
  src: url("../fonts/inter-var-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: "JetBrains Mono";
  font-style: normal;
  font-weight: 400 500;
  font-display: swap;
  src: url("../fonts/jetbrains-mono-var-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;
}

/* --- Tokens --------------------------------------------------------------- */

:root {
  color-scheme: light dark;

  /* surfaces */
  --bg:        light-dark(#fafafa, #0a0a0c);
  --bg-raised: light-dark(#ffffff, #131317);

  /* text */
  --fg:       light-dark(#18181b, #ededf0);
  --fg-muted: light-dark(#52525b, #a2a2ab);
  --fg-faint: light-dark(#71717a, #7a7a84);

  /* lines */
  --border:        light-dark(#e4e4e7, #26262c);
  --border-strong: light-dark(#d0d0d5, #37373f);

  /* accent — indigo, the only non-neutral in the system */
  --accent:      light-dark(#4f46e5, #818cf8);
  --accent-soft: light-dark(rgb(79 70 229 / 0.06), rgb(129 140 248 / 0.08));

  /* semantic status (fidelity report, warnings) */
  --ok:   light-dark(#15803d, #4ade80);
  --warn: light-dark(#b45309, #fbbf24);

  /* elevation (light mode only; dark relies on borders) */
  --shadow-color: light-dark(rgb(24 24 27 / 0.05), transparent);

  /* type */
  --font-sans: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI",
    sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, Consolas,
    monospace;

  /* shape */
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;

  /* motion */
  --ease: 150ms ease;
}

[data-theme="light"] { color-scheme: light; }
[data-theme="dark"]  { color-scheme: dark; }

/* --- Base ------------------------------------------------------------------ */

* { box-sizing: border-box; }

/* author display rules must not defeat the hidden attribute */
[hidden] { display: none !important; }

@media (prefers-reduced-motion: no-preference) {
  html { scroll-behavior: smooth; }
}

html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--font-sans);
  font-size: 1rem;
  line-height: 1.5;
  background: var(--bg);
  color: var(--fg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  display: grid;
  grid-template-rows: auto 1fr;
}

/* body is a grid: without this, a child's min-content (one long <pre>
   line) widens the whole page on small screens instead of scrolling. */
body > * { min-width: 0; }

::selection {
  background: color-mix(in srgb, var(--accent) 22%, transparent);
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

button {
  font: inherit;
  color: inherit;
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
}

.mono { font-family: var(--font-mono); }

kbd {
  font-family: var(--font-mono);
  font-size: 0.6875rem;
  font-weight: 500;
  color: var(--fg-muted);
  background: var(--bg);
  border: 1px solid var(--border);
  border-bottom-width: 2px;
  border-radius: 5px;
  padding: 0.125rem 0.375rem;
}

/* --- Header ----------------------------------------------------------------- */

.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.25rem 1.5rem;
}

.wordmark {
  font-size: 1.0625rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--fg);
  text-decoration: none;
}

.site-header .bar-spacer { flex: 1; }

.header-link {
  margin-right: 1rem;
  font-size: 0.9375rem;
  font-weight: 500;
  color: var(--fg-muted);
  text-decoration: none;
}

.header-link:hover { color: var(--fg); }

.theme-toggle {
  display: grid;
  place-items: center;
  width: 2.5rem;
  height: 2.5rem;
  border-radius: var(--radius-sm);
  color: var(--fg-muted);
  transition: color var(--ease), background-color var(--ease);
}

.theme-toggle svg { width: 19px; height: 19px; }

.theme-toggle:hover {
  color: var(--fg);
  background: color-mix(in srgb, var(--fg) 6%, transparent);
}

/* --- Landing ------------------------------------------------------------------ */

.landing { padding: 0; }

.hero {
  min-height: min(44rem, calc(100svh - 4.5rem));
  justify-content: center;
  margin: 0 auto;
  padding: 2rem 1.5rem 3rem;
}

.scroll-cue {
  margin-top: 2.5rem;
  font-size: 0.75rem;
  color: var(--fg-faint);
  text-decoration: none;
  transition: color var(--ease);
}

.scroll-cue:hover { color: var(--fg); }

/* --- landing strips (below the fold) ---------------------------------------- */

/* first-view reveal — class added by main.js only when motion is allowed */
.strip.reveal { opacity: 0; transform: translateY(18px); }
.strip.reveal.is-revealed {
  opacity: 1;
  transform: none;
  transition: opacity 0.55s ease, transform 0.55s ease;
}

.strip { border-top: 1px solid var(--border); }

.strip-inner {
  max-width: 64rem;
  margin: 0 auto;
  padding: 4rem 1.5rem;
}

.strip-title {
  margin: 0 0 0.5rem;
  font-size: clamp(1.375rem, 1.6vw + 0.75rem, 1.75rem);
  font-weight: 650;
  letter-spacing: -0.02em;
}

.strip-sub {
  margin: 0 0 1.75rem;
  font-size: 0.9375rem;
  color: var(--fg-muted);
  max-width: 44rem;
}

.stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 2.5rem;
  padding-top: 3rem;
  padding-bottom: 3rem;
}

.stat-num {
  display: block;
  font-family: var(--font-mono);
  font-size: clamp(2rem, 2.4vw + 1rem, 2.75rem);
  font-weight: 600;
  line-height: 1;
  color: var(--accent);
  letter-spacing: -0.02em;
}

.stat-label {
  display: block;
  margin-top: 0.625rem;
  font-size: 0.8125rem;
  line-height: 1.55;
  color: var(--fg-muted);
}

.steps, .teasers {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(14rem, 1fr));
  gap: 1rem;
}

.step, .teaser {
  padding: 1.375rem 1.5rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--bg-raised);
}

.step svg { display: block; margin-bottom: 0.875rem; }
.step h3, .teaser h3 { margin: 0 0 0.375rem; font-size: 0.9375rem; font-weight: 600; letter-spacing: -0.01em; line-height: 1.35; }
.step p, .teaser p { margin: 0; font-size: 0.8125rem; line-height: 1.6; color: var(--fg-muted); }

.teaser {
  display: flex;
  flex-direction: column;
  gap: 0.375rem;
  color: inherit;
  text-decoration: none;
  transition: border-color var(--ease), box-shadow var(--ease);
}

.teaser:hover {
  border-color: color-mix(in srgb, var(--accent) 45%, var(--border));
  box-shadow: 0 4px 18px -8px color-mix(in srgb, var(--accent) 22%, transparent);
}

.teaser p { flex: 1; }
.teaser-meta { font-family: var(--font-mono); font-size: 0.6875rem; color: var(--fg-faint); }

.strip-more { margin: 1.75rem 0 0; font-size: 0.875rem; }
.strip-more a { color: var(--accent); text-decoration: none; }
.strip-more a:hover { text-decoration: underline; }

.format-chips { display: flex; flex-wrap: wrap; gap: 0.5rem; margin: 0; }
.format-chips a {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  padding: 0.3125rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--bg-raised);
  color: var(--fg-muted);
  text-decoration: none;
  transition: border-color var(--ease), color var(--ease);
}
.format-chips a:hover { color: var(--fg); border-color: color-mix(in srgb, var(--accent) 45%, var(--border)); }

.site-footer {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.375rem 1.5rem;
  padding: 2.5rem 1.5rem 3rem;
  border-top: 1px solid var(--border);
  font-size: 0.75rem;
}

.site-footer a.footer-version { font-family: var(--font-mono); }

.site-footer a {
  color: var(--fg-faint);
  text-decoration: none;
  transition: color var(--ease);
}

.site-footer a:hover { color: var(--fg); }

.hero {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
  max-width: 40rem;
  text-align: center;
}

.hero h1 {
  margin: 0;
  font-size: clamp(2.125rem, 3.4vw + 1rem, 3rem);
  font-weight: 650;
  letter-spacing: -0.032em;
  line-height: 1.08;
  text-wrap: balance;
}

.subhead {
  margin: 0.875rem 0 0;
  max-width: 44rem;
  font-size: 1.0625rem;
  line-height: 1.6;
  color: var(--fg-muted);
  text-wrap: balance;
}

/* --- Input target (treatment A: dashed card) ---------------------------------- */

.drop-target {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.875rem;
  width: 100%;
  margin-top: 3rem;
  padding: 4rem 2rem 3.5rem;
  background: var(--bg-raised);
  border: 1.5px dashed var(--border-strong);
  border-radius: var(--radius-lg);
  box-shadow: 0 1px 2px var(--shadow-color);
  transition: border-color var(--ease), background-color var(--ease);
}

.drop-target:hover {
  border-color: color-mix(in srgb, var(--accent) 55%, var(--border-strong));
  background: color-mix(in srgb, var(--accent) 2.5%, var(--bg-raised));
}

.drop-target:hover .drop-icon { color: var(--accent); }

.drop-icon {
  color: var(--fg-faint);
  transition: color var(--ease);
}

.drop-cta {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  font-size: 1.0625rem;
  font-weight: 500;
}

.drop-formats {
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  color: var(--fg-muted); /* AA contrast, incl. on the tinted article CTA */
  letter-spacing: 0.01em;
}

/* --- Below the target ------------------------------------------------------------ */

.privacy {
  display: flex;
  align-items: center;
  gap: 0.4375rem;
  margin: 1.125rem 0 0;
  font-size: 0.8125rem;
  color: var(--fg-muted);
}

.privacy svg { color: var(--fg-faint); }

.privacy-link {
  color: var(--fg-muted);
  text-decoration: underline;
  text-decoration-color: var(--fg-faint);
  text-underline-offset: 2px;
  transition: color var(--ease);
}

.privacy-link:hover { color: var(--accent); }

.sample {
  margin-top: 2.25rem;
  font-size: 0.875rem;
  color: var(--fg-faint);
  transition: color var(--ease);
}

.sample .sample-action {
  color: var(--fg-muted);
  font-weight: 500;
  transition: color var(--ease);
}

.sample:hover .sample-action { color: var(--accent); }

/* --- Utilities -------------------------------------------------------------------- */

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

/* --- Landing extras ------------------------------------------------------------ */

.drop-target.is-dragover {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 4%, var(--bg-raised));
}

/* Converting state: icon swaps for a spinner, formats line for the filename.
   Applied only when conversion takes >150ms (no flash on the fast paths). */
.drop-spinner {
  display: none;
  width: 26px;
  height: 26px;
  border: 2px solid var(--border-strong);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 700ms linear infinite;
}

.drop-busy-label {
  display: none;
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  color: var(--fg-muted);
}

.drop-target.is-busy { pointer-events: none; }
.drop-target.is-busy .drop-icon,
.drop-target.is-busy .drop-formats { display: none; }
.drop-target.is-busy .drop-cta { visibility: hidden; height: 0; }
.drop-target.is-busy .drop-spinner { display: block; }
.drop-target.is-busy .drop-busy-label { display: block; }

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Rejected file: a brief head-shake "no" on the target itself. */
@keyframes drop-shake {
  10%, 90% { transform: translateX(-1px); }
  20%, 80% { transform: translateX(3px); }
  30%, 50%, 70% { transform: translateX(-5px); }
  40%, 60% { transform: translateX(5px); }
}

.drop-target.is-rejected {
  animation: drop-shake 480ms cubic-bezier(0.36, 0.07, 0.19, 0.97) both;
  border-color: color-mix(in srgb, var(--warn) 55%, transparent);
}

@media (prefers-reduced-motion: reduce) {
  .drop-target.is-rejected { animation: none; }
}

.drop-error {
  margin: 1rem 0 0;
  max-width: 40rem;
  padding: 0.625rem 1rem;
  font-size: 0.875rem;
  color: var(--warn);
  background: color-mix(in srgb, var(--warn) 7%, var(--bg-raised));
  border: 1px solid color-mix(in srgb, var(--warn) 35%, transparent);
  border-radius: var(--radius-md);
}

.drop-error code {
  font-family: var(--font-mono);
  font-size: 0.8125rem;
}

.drop-error a {
  color: inherit;
  font-weight: 550;
  text-decoration: underline;
  text-underline-offset: 2px;
}

/* --- Recent conversions ----------------------------------------------------------- */

.history {
  width: 100%;
  max-width: 40rem;
  margin-top: 2.5rem;
  text-align: left;
}

.history-title {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  margin: 0 0 0.5rem;
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--fg-muted);
}

.history-note {
  font-weight: 400;
  letter-spacing: 0.02em;
  text-transform: none;
  color: var(--fg-faint);
}

.history-clear {
  margin-left: auto;
  font-size: 0.71875rem;
  font-weight: 500;
  letter-spacing: 0.02em;
  text-transform: none;
  color: var(--fg-faint);
}

.history-clear:hover { color: var(--warn); }

.history-list {
  margin: 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.375rem;
}

.history-item {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  width: 100%;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg-raised);
  text-align: left;
  transition: border-color var(--ease);
}

.history-item:hover { border-color: color-mix(in srgb, var(--accent) 45%, var(--border)); }

.history-name {
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-meta {
  flex: none;
  font-size: 0.71875rem;
  color: var(--fg-faint);
}

/* --- Result view: 3-panel trust view --------------------------------------------- */

.result {
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: 0 1rem 1rem;
  gap: 0.75rem;
}

/* container receives programmatic focus on reveal — never draw a ring on it */
.result:focus {
  outline: none;
}

/* One orchestrated reveal: bar first, panes rise in a quiet stagger. */
.result:not([hidden]) .result-bar,
.result:not([hidden]) .pane,
.result:not([hidden]) .result-privacy {
  animation: rise 300ms cubic-bezier(0.22, 1, 0.36, 1) backwards;
}

.result:not([hidden]) .pane:nth-child(1) { animation-delay: 40ms; }
.result:not([hidden]) .pane:nth-child(2) { animation-delay: 90ms; }
.result:not([hidden]) .pane:nth-child(3) { animation-delay: 140ms; }
.result:not([hidden]) .result-privacy { animation-delay: 200ms; }

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
}

.result-privacy {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.4375rem;
  margin: 0;
  font-size: 0.75rem;
  color: var(--fg-faint);
}

.result-bar {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  flex-wrap: wrap;
}

.result-meta {
  font-size: 0.8125rem;
  color: var(--fg-muted);
}

.bar-spacer { flex: 1; }

/* download/copy cluster wraps as one unit on narrow windows */
.bar-actions {
  display: flex;
  align-items: center;
  gap: 0.625rem;
}

/* square icon-only button (Copy) */
.btn-icon {
  padding: 0.4375rem 0.5625rem;
}

.btn-icon.is-done {
  color: var(--ok);
  border-color: color-mix(in srgb, var(--ok) 45%, transparent);
  background: color-mix(in srgb, var(--ok) 8%, transparent);
}

/* download split button + menu */
.dl-menu { position: relative; }

.dl-chevron { margin-left: 0.125rem; opacity: 0.8; }

.dl-pop {
  position: absolute;
  right: 0;
  top: calc(100% + 0.375rem);
  z-index: 30;
  min-width: 16.5rem;
  padding: 0.375rem;
  display: flex;
  flex-direction: column;
  gap: 0.125rem;
  background: var(--bg-raised);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  box-shadow: 0 12px 32px -12px rgb(0 0 0 / 0.35);
}

.dl-item {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  width: 100%;
  padding: 0.5rem 0.625rem;
  border-radius: var(--radius-sm);
  text-align: left;
  color: var(--fg);
  transition: background-color var(--ease);
}

.dl-item:hover { background: color-mix(in srgb, var(--accent) 9%, transparent); }
.dl-item > svg { flex: none; color: var(--accent); }

.dl-item-text { display: flex; flex-direction: column; gap: 0.0625rem; min-width: 0; flex: 1; }
.dl-item-text strong { font-size: 0.8125rem; font-weight: 600; font-family: var(--font-mono); }
.dl-item-text small { font-size: 0.71875rem; color: var(--fg-muted); }

.info-dot {
  position: relative;
  flex: none;
  font-size: 0.8125rem;
  line-height: 1;
  color: var(--fg-faint);
  cursor: help;
}
.info-dot:hover, .info-dot:focus-visible { color: var(--fg-muted); }

/* custom tooltip — native title is unreliable inside menu buttons */
.info-dot::after {
  content: attr(data-tip);
  position: absolute;
  right: -0.25rem;
  bottom: calc(100% + 0.5rem);
  z-index: 40;
  width: 15rem;
  padding: 0.5rem 0.625rem;
  font-size: 0.71875rem;
  font-weight: 400;
  line-height: 1.5;
  text-align: left;
  color: var(--fg);
  background: var(--bg-raised);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  box-shadow: 0 8px 24px -10px rgb(0 0 0 / 0.4);
  opacity: 0;
  visibility: hidden;
  transition: opacity var(--ease);
  pointer-events: none;
}
.info-dot:hover::after, .info-dot:focus-visible::after {
  opacity: 1;
  visibility: visible;
}

/* "Copied" bubble above the copy button */
.btn-icon { position: relative; }

.copy-toast {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(100% + 0.5rem);
  z-index: 40;
  padding: 0.3125rem 0.625rem;
  font-size: 0.71875rem;
  font-weight: 500;
  white-space: nowrap;
  color: var(--ok);
  background: var(--bg-raised);
  border: 1px solid color-mix(in srgb, var(--ok) 45%, transparent);
  border-radius: var(--radius-sm);
  box-shadow: 0 8px 24px -10px rgb(0 0 0 / 0.35);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}
.copy-toast.is-shown {
  opacity: 1;
  visibility: visible;
}
@media (prefers-reduced-motion: no-preference) {
  .copy-toast.is-shown { animation: toast-rise 200ms cubic-bezier(0.22, 1, 0.36, 1); }
}
@keyframes toast-rise {
  from { opacity: 0; transform: translate(-50%, 4px); }
  to { transform: translate(-50%, 0); }
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.4375rem 0.875rem;
  font-size: 0.8125rem;
  font-weight: 500;
  border-radius: var(--radius-sm);
  transition: background-color var(--ease), color var(--ease), border-color var(--ease);
}

.btn-ghost {
  color: var(--fg-muted);
  border: 1px solid var(--border);
  background: var(--bg-raised);
}

.btn-ghost:hover { color: var(--fg); border-color: var(--border-strong); }

.btn-ghost.is-done { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 40%, transparent); }

.btn-solid {
  color: #ffffff;
  background: var(--accent);
  border: 1px solid transparent;
}

.btn-solid:hover { background: color-mix(in srgb, var(--accent) 88%, #000); }

.seg {
  display: inline-flex;
  padding: 2px;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

.seg-item {
  padding: 0.3125rem 0.75rem;
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--fg-muted);
  border-radius: 4px;
}

.seg-item.is-active {
  color: var(--fg);
  background: color-mix(in srgb, var(--fg) 7%, transparent);
}

.seg-item:disabled { cursor: not-allowed; color: var(--fg-faint); }

/* panes */

.panes {
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(0, 1.25fr) minmax(0, 0.9fr);
  gap: 0.75rem;
  flex: 1;
  min-height: 0;
}

/* Original pane folds from its own header: a slim rail on wide screens,
   an accordion header on small ones. The chevron is the affordance. */
.pane-fold {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  width: 100%;
  font: inherit;
  letter-spacing: inherit;
  text-transform: inherit;
  color: inherit;
  transition: color var(--ease);
}
.pane-fold:hover { color: var(--fg); }
.fold-chevron { flex: none; transition: transform var(--ease); }
.orig-collapsed .fold-chevron { transform: rotate(180deg); }

.panes.orig-collapsed { grid-template-columns: 2.75rem minmax(0, 1.4fr) minmax(0, 1fr); }
.panes.orig-collapsed .pane-original .pane-body { display: none; }

@media (min-width: 768px) {
  .panes.orig-collapsed .pane-original .pane-title {
    height: 100%;
    padding: 0.75rem 0;
    border-bottom: 0;
  }
  .panes.orig-collapsed .pane-original .pane-fold {
    flex-direction: column;
    justify-content: flex-start;
    height: 100%;
    gap: 0.625rem;
  }
  .panes.orig-collapsed .pane-original .fold-text {
    writing-mode: vertical-rl;
  }
}

/* Token savings strip — arithmetic on measured sizes, shown before the QC score */
.tok-save {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr);
  gap: 0.5rem 1rem;
  align-items: center;
  padding: 0.875rem 1rem;
  margin-bottom: 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: color-mix(in srgb, var(--accent) 4%, var(--bg-raised));
}

.tok-pct { display: flex; flex-direction: column; gap: 0.25rem; min-width: 0; }

.tok-pct-num {
  font-family: var(--font-mono);
  font-size: 1.625rem;
  font-weight: 600;
  line-height: 1;
  letter-spacing: -0.02em;
  color: var(--accent);
}

.tok-pct-label {
  font-size: 0.6875rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--fg-faint);
}

.tok-bar {
  margin-top: 0.25rem;
  height: 4px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--accent) 14%, transparent);
  overflow: hidden;
}
.tok-bar > span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
}

.tok-nums {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  font-family: var(--font-mono);
  font-size: 0.71875rem;
  color: var(--fg);
  min-width: 0;
}
.tok-k { color: var(--fg-faint); margin-right: 0.375rem; }
.tok-time { margin-top: 0.125rem; color: var(--fg-muted); font-family: var(--font-sans); font-size: 0.71875rem; }

/* while the exact o200k pass runs, the ≈ numbers breathe — opacity animates on
   the compositor, so it keeps moving even while tokenizing blocks the thread */
.tok-save.is-counting .tok-nums,
.tok-save.is-counting .tok-pct-num { opacity: 0.75; }
@media (prefers-reduced-motion: no-preference) {
  .tok-save.is-counting .tok-nums,
  .tok-save.is-counting .tok-pct-num { animation: tok-pulse 1.1s ease-in-out infinite; }
}
@keyframes tok-pulse {
  50% { opacity: 0.4; }
}

/* preview-only: frontmatter properties box + figure placeholder chips */
.fm-props {
  margin: 0 0 1rem;
  padding: 0.75rem 0.875rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: color-mix(in srgb, var(--fg) 2.5%, transparent);
}

.fm-kicker {
  margin: 0 0 0.5rem;
  font-family: var(--font-mono);
  font-size: 0.65625rem;
  font-weight: 650;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--fg-muted);
}
.fm-note { font-weight: 400; letter-spacing: 0; text-transform: none; color: var(--fg-faint); margin-left: 0.375rem; }

.fm-row {
  display: grid;
  grid-template-columns: 7rem minmax(0, 1fr);
  gap: 0.75rem;
  padding: 0.2rem 0;
  font-size: 0.75rem;
  line-height: 1.5;
}
.fm-key { font-family: var(--font-mono); color: var(--fg-faint); }
.fm-val { color: var(--fg); word-break: break-word; }

.fig-ph {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.1875rem 0.5rem;
  font-family: var(--font-mono);
  font-size: 0.71875rem;
  color: var(--fg-muted);
  background: color-mix(in srgb, var(--accent) 7%, transparent);
  border: 1px dashed color-mix(in srgb, var(--accent) 35%, transparent);
  border-radius: var(--radius-sm);
  vertical-align: baseline;
}
.fig-ph svg { color: var(--accent); flex: none; }

/* resolved figure images in the preview — the real extracted pixels */
.md-preview .md-fig {
  display: block;
  max-width: 100%;
  height: auto;
  margin: 0.75rem 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: #fff; /* transparent PNGs from notebooks assume a light canvas */
}

/* OCR offer under the fidelity report */
.ocr-offer {
  margin-top: 1rem;
  padding: 0.875rem 1rem;
  font-size: 0.8125rem;
  line-height: 1.6;
  border: 1px dashed color-mix(in srgb, var(--warn) 40%, transparent);
  border-radius: var(--radius-md);
  background: color-mix(in srgb, var(--warn) 6%, transparent);
}
.ocr-offer p { margin: 0 0 0.75rem; color: var(--fg-muted); }
.ocr-btn { font-size: 0.8125rem; }
.ocr-btn:disabled { opacity: 0.7; cursor: progress; }

/* slide-card preview for decks */
.slide-preview { display: flex; flex-direction: column; gap: 0.75rem; }
.slide-card {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 0.75rem 0.875rem;
  background: color-mix(in srgb, var(--fg) 2.5%, transparent);
}
.slide-card h3 { margin: 0 0 0.375rem; font-size: 0.8125rem; font-weight: 600; }
.slide-card pre {
  margin: 0;
  font-family: var(--font-mono);
  font-size: 0.71875rem;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--fg-muted);
}

/* real slide rendering (result-view renderPptxSlides) — slides keep a
   white canvas in both themes, like the deck itself */
.pptx-slides { display: flex; flex-direction: column; gap: 1rem; }
.pptx-slide-item { margin: 0; }
.pptx-slide {
  position: relative;
  overflow: hidden;
  width: 100%;
  container-type: inline-size;
  background: #ffffff;
  color: #1a1a1e;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  box-shadow: 0 1px 3px var(--shadow-color);
}
.pptx-shape { position: absolute; overflow: hidden; }
.pptx-pic { position: absolute; object-fit: contain; }
/* shapes whose box can't be resolved stack top-down instead of vanishing */
.pptx-flow { position: absolute; inset: 6% 5%; display: flex; flex-direction: column; gap: 4cqw; }
.pptx-shape-flow { position: static; overflow: visible; }
.pptx-pic-flow { position: static; max-width: 60%; max-height: 45%; object-fit: contain; align-self: flex-start; }
.pptx-par { margin: 0; line-height: 1.25; overflow-wrap: break-word; }
.pptx-slide-num {
  margin: 0.375rem 0 0;
  font-family: var(--font-mono);
  font-size: 0.6875rem;
  letter-spacing: 0.04em;
  color: var(--fg-muted);
}

.pane {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.pane-title {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.375rem 0.625rem;
  margin: 0;
  padding: 0.75rem 1rem 0.625rem;
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--fg-muted);
  border-bottom: 1px solid var(--border);
}

.pane-title-note {
  font-family: var(--font-mono);
  font-weight: 400;
  letter-spacing: 0;
  text-transform: none;
  color: var(--fg-faint);
}

.md-exact {
  font-family: var(--font-mono);
  font-size: 0.65625rem;
  font-weight: 400;
  letter-spacing: 0;
  text-transform: none;
  color: var(--accent);
  border-radius: var(--radius-sm);
  padding: 0.0625rem 0.25rem;
}

.md-exact:hover { background: color-mix(in srgb, var(--accent) 10%, transparent); }
.md-exact:disabled { color: var(--fg-faint); cursor: default; }

.pane-seg {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.pane-seg-btn {
  padding: 0.125rem 0.5rem;
  font-family: var(--font-mono);
  font-size: 0.625rem;
  font-weight: 500;
  letter-spacing: 0.02em;
  text-transform: none;
  color: var(--fg-faint);
  transition: color var(--ease), background-color var(--ease);
}

.pane-seg-btn + .pane-seg-btn { border-left: 1px solid var(--border); }
.pane-seg-btn:hover { color: var(--fg); }

.pane-seg-btn.is-active {
  color: var(--fg);
  background: color-mix(in srgb, var(--accent) 14%, transparent);
}

.pane-body {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: 1rem;
}

/* ② raw markdown */

.md-raw {
  margin: 0;
  font-family: var(--font-mono);
  font-size: 0.78125rem;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
}

/* ② rendered preview — the Markdown as a chat UI would show it */

.md-preview { font-size: 0.8125rem; line-height: 1.65; }
.md-preview > :first-child { margin-top: 0; }
.md-preview h1, .md-preview h2, .md-preview h3, .md-preview h4 {
  margin: 1.25rem 0 0.5rem;
  line-height: 1.25;
  letter-spacing: -0.01em;
}
.md-preview h1 { font-size: 1.25rem; }
.md-preview h2 { font-size: 1.0625rem; }
.md-preview h3 { font-size: 0.9375rem; }
.md-preview h4 { font-size: 0.875rem; }
.md-preview p, .md-preview ul, .md-preview ol { margin: 0 0 0.75rem; }
.md-preview ul, .md-preview ol { padding-left: 1.25rem; }
.md-preview code {
  font-family: var(--font-mono);
  font-size: 0.9em;
  background: color-mix(in srgb, var(--fg) 6%, transparent);
  padding: 0.05em 0.3em;
  border-radius: 4px;
}
.md-preview pre {
  padding: 0.625rem 0.75rem;
  background: color-mix(in srgb, var(--fg) 4%, transparent);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow-x: auto;
  margin: 0 0 0.75rem;
}
.md-preview pre code { background: none; padding: 0; }
.md-preview table { border-collapse: collapse; margin: 0 0 0.75rem; font-size: 0.78125rem; }
.md-preview th, .md-preview td { border: 1px solid var(--border); padding: 0.25rem 0.5rem; text-align: left; }
.md-preview th { background: color-mix(in srgb, var(--fg) 4%, transparent); }
.md-preview img { max-width: 100%; }
.md-preview blockquote {
  margin: 0 0 0.75rem;
  padding: 0.125rem 0.75rem;
  border-left: 2px solid var(--accent);
  color: var(--fg-muted);
}
.md-preview hr { border: none; border-top: 1px solid var(--border); margin: 1rem 0; }
.md-preview a { color: var(--accent); }

/* ① notebook preview */

.nb-cell { margin-bottom: 1.25rem; }

.nb-prompt {
  display: block;
  margin-bottom: 0.25rem;
  font-family: var(--font-mono);
  font-size: 0.6875rem;
  color: var(--accent);
}

.nb-src {
  margin: 0;
  padding: 0.625rem 0.75rem;
  font-family: var(--font-mono);
  font-size: 0.78125rem;
  line-height: 1.55;
  background: color-mix(in srgb, var(--fg) 4%, transparent);
  border-radius: var(--radius-sm);
  overflow-x: auto;
}

.nb-out {
  margin: 0.375rem 0 0;
  padding: 0.375rem 0.75rem;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  line-height: 1.5;
  color: var(--fg-muted);
  border-left: 2px solid var(--border-strong);
  overflow-x: auto;
  max-height: 16rem;
}

.nb-err { color: var(--warn); border-left-color: var(--warn); }

.nb-img {
  display: block;
  margin-top: 0.5rem;
  max-width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

.pdf-embed {
  width: 100%;
  height: 100%;
  min-height: 24rem;
  border: 0;
  border-radius: var(--radius-sm);
}

.original-note {
  margin: 0;
  font-size: 0.8125rem;
  line-height: 1.5;
  color: var(--fg-faint);
}

.nb-md { font-size: 0.875rem; line-height: 1.6; }
.nb-md h1 { font-size: 1.25rem; margin: 0.5rem 0; }
.nb-md h2 { font-size: 1.0625rem; margin: 0.5rem 0; }
.nb-md h3 { font-size: 0.9375rem; margin: 0.5rem 0; }
.nb-md p { margin: 0.375rem 0; }
.nb-md table { border-collapse: collapse; font-size: 0.8125rem; }
.nb-md th, .nb-md td { border: 1px solid var(--border); padding: 0.25rem 0.5rem; }

/* ③ fidelity report */

.qc {
  display: flex;
  align-items: baseline;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

/* the QC block is a disclosure button — click for the five checks */
.qc-toggle {
  width: 100%;
  text-align: left;
  cursor: pointer;
  border-radius: var(--radius-md);
  padding: 0.375rem 0.5rem;
  margin: -0.375rem -0.5rem 0.625rem;
  transition: background-color var(--ease);
}

.qc-toggle:hover { background: color-mix(in srgb, var(--fg) 5%, transparent); }

.qc-chevron {
  align-self: center;
  margin-left: auto;
  color: var(--fg-faint);
  transition: transform var(--ease);
}

.qc-toggle.is-open .qc-chevron { transform: rotate(180deg); }

.qc-checks {
  list-style: none;
  margin: 0 0 1rem;
  padding: 0.625rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: color-mix(in srgb, var(--fg) 3%, transparent);
  display: flex;
  flex-direction: column;
  gap: 0.4375rem;
  font-size: 0.75rem;
  line-height: 1.5;
}

.qc-checks li { display: flex; gap: 0.5rem; color: var(--fg-muted); }
.qc-checks strong { color: var(--fg); font-weight: 550; }
.qc-checks .qc-mark { flex: none; font-family: var(--font-mono); }
.qc-pass .qc-mark { color: var(--ok); }
.qc-part .qc-mark { color: var(--warn); }
.qc-fail .qc-mark { color: var(--warn); }

.qc-weight {
  margin-left: 0.3em;
  font-family: var(--font-mono);
  font-size: 0.6875rem;
  color: var(--fg-faint);
}

.qc-score {
  font-family: var(--font-mono);
  font-size: 2.25rem;
  font-weight: 500;
  color: var(--ok);
  line-height: 1;
}

.qc-score .count-num {
  display: inline;
  font-size: inherit;
  font-weight: inherit;
}

.qc-pct { font-size: 1.125rem; color: var(--fg-faint); }

.qc-label {
  font-size: 0.8125rem;
  font-weight: 500;
}

.qc-label span {
  display: block;
  font-size: 0.71875rem;
  font-weight: 400;
  color: var(--fg-faint);
}

.counts {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
}

.count {
  padding: 0.625rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
}

.count-num {
  display: block;
  font-family: var(--font-mono);
  font-size: 1.25rem;
  font-weight: 500;
}

.count-label {
  font-size: 0.71875rem;
  color: var(--fg-muted);
}

.fidelity-note {
  margin: 0.875rem 0 0;
  font-size: 0.75rem;
  line-height: 1.5;
  color: var(--fg-faint);
}

.fidelity-sub {
  margin: 1.25rem 0 0.5rem;
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--fg-muted);
}

.warn-list {
  margin: 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.375rem;
}

.warn-list li {
  display: flex;
  gap: 0.5rem;
  font-size: 0.78125rem;
  line-height: 1.5;
  color: var(--fg-muted);
}

.warn-mark { color: var(--warn); flex: none; }

.warn-none { margin: 0; font-size: 0.8125rem; color: var(--ok); }

.dag-wrap { overflow-x: auto; }
.dag-wrap svg { display: block; margin-inline: auto; max-width: 100%; height: auto; }

/* --- Motion & small screens --------------------------------------------------------- */

@media (prefers-reduced-motion: reduce) {
  * {
    transition: none !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }
}

/* Result view adapts to the window: 3 panes ≥1240, 2 panes + full-width
   fidelity 768–1239, a single content-first column below 768. */
@media (max-width: 1239px) {
  .panes { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .panes > .pane:last-child { grid-column: 1 / -1; }
  .panes.orig-collapsed { grid-template-columns: 2.75rem minmax(0, 1fr); }
  .pane-body { max-height: 70vh; }

  /* bar: actions on one row, meta on its own line beneath */
  .result-meta { order: 10; flex-basis: 100%; }
  .seg {
    overflow-x: auto;
    max-width: 100%;
    scrollbar-width: none;
  }
  .seg::-webkit-scrollbar { display: none; }
  .seg-item { white-space: nowrap; }
}

@media (max-width: 767px) {
  .panes { grid-template-columns: 1fr; flex: none; }
  .panes.orig-collapsed { grid-template-columns: 1fr; } /* accordion: header row stays */
  .result { padding: 0 0.75rem 0.75rem; }

  /* Content first: the app-shell height cap is released, the Markdown and
     fidelity panes grow with their content and the page scrolls; only the
     original stays a compact scrollable reference. */
  .pane-body { max-height: none; overflow: visible; }
  .pane-original .pane-body { max-height: 45vh; overflow: auto; }

  /* The deliverable leads on a phone: Markdown, then the fidelity report;
     the original drops to the bottom as reference (visual order only —
     DOM and reading order are unchanged). */
  .pane-original { order: 3; }
}

/* Touch devices: interactive controls reach the 44px comfort size */
@media (pointer: coarse) {
  .btn, .seg-item { min-height: 2.75rem; }
  .pane-seg-btn { min-height: 2.25rem; padding: 0.375rem 0.75rem; }
  .theme-toggle { width: 2.75rem; height: 2.75rem; }
  .history-item { min-height: 2.75rem; }
  /* header links: grow the hit area without moving the layout */
  .site-header a { padding: 0.6875rem 0.375rem; margin: -0.6875rem -0.375rem; }
}

@media (max-width: 960px) {
  .stats { grid-template-columns: repeat(2, 1fr); gap: 2rem; }
  .strip-inner { padding: 2.75rem 1.5rem; }
}

@media (max-width: 480px) {
  .drop-target { padding: 3rem 1.25rem 2.75rem; }
  .drop-cta kbd { display: none; } /* no ⌘V on touch-first screens */
}

/* reserved ad container (landing) — same contract as article.css */
.ad-slot {
  min-height: 280px;
  display: grid;
  place-items: center;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-md);
  background: color-mix(in srgb, var(--fg) 2.5%, transparent);
}
.ad-slot::before {
  content: "Advertisement";
  font-family: var(--font-mono);
  font-size: 0.6875rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--fg-faint);
}
.ad-slot.ad-demo::after {
  content: "reserved · " attr(data-unit);
  margin-top: 0.5rem;
  font-family: var(--font-mono);
  font-size: 0.6875rem;
  letter-spacing: 0.04em;
  color: var(--fg-faint);
  max-width: 24rem;
  text-align: center;
}

/* media-slot — visible placeholders for owner-produced screen recordings.
   Swapped for a <video> with the same footprint when the file exists. */
.media-slot {
  display: grid;
  place-content: center;
  gap: 0.5rem;
  aspect-ratio: 16 / 9;
  padding: 1.5rem;
  border: 1.5px dashed var(--border-strong);
  border-radius: var(--radius-lg);
  background: color-mix(in srgb, var(--accent) 3%, var(--bg-raised));
  text-align: center;
}

.media-slot .media-kicker {
  font-family: var(--font-mono);
  font-size: 0.6875rem;
  font-weight: 650;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--fg-faint);
}

.media-slot .media-note {
  margin: 0;
  max-width: 34rem;
  font-size: 0.875rem;
  line-height: 1.6;
  color: var(--fg-muted);
}

.media-slot code {
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  color: var(--accent);
}

.media-slot-sub { margin-top: 2rem; aspect-ratio: 21 / 9; }

/* When the recording lands, a <video> drops into the slot with the same
   footprint — no layout shift, no new styles needed. */
.media-slot > video {
  grid-area: 1 / 1 / -1 / -1;
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: calc(var(--radius-lg) - 2px);
}

/* Hero rails: two 160×600 display units flanking the drop target on wide
   screens only. Hiding a responsive unit's container via media query is
   AdSense-supported. Generous gap keeps them clear of the drop target
   (accidental-click policy). */
.hero-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
}

.ad-rail-side { display: none; }

@media (min-width: 1280px) {
  .hero-row {
    grid-template-columns: 180px minmax(0, 1fr) 180px;
    gap: 2.5rem;
    align-items: center;
    padding: 0 2rem;
  }
  .ad-rail-side { display: grid; min-height: 600px; }
}

/* --- Pre-approval ad kill-switch ------------------------------------------
   Every reserved unit stays in the markup as the ready-to-fill AdSense
   backup, but the deployed site shows none of them until approval.
   To go live after "adsense approved": delete this block — the inject
   script styles the real units (they don't carry .ad-demo). */
.ad-slot.ad-demo,
.ad-card,
.ad-rail-fixed { display: none !important; }

/* with the side rails display:none, the hero grid must not keep its
   180px rail tracks — the content child would auto-place into the
   first, narrow one. Collapse the row to a single full-width track. */
.hero-row {
  grid-template-columns: minmax(0, 1fr) !important;
  padding: 0 !important;
}
