/* =========================================================================
   Markdwn — application styles
   A single-purpose tool: top bar with URL input always visible,
   document fills the page. Cozy paper. System blue.
   ========================================================================= */

html, body, #root { height: 100%; }
body {
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font-text);
  min-height: 100vh;
}
* { box-sizing: border-box; }

/* Paper grain overlay */
#paper-grain {
  position: fixed; inset: 0;
  pointer-events: none;
  z-index: 1;
  opacity: 0;
  transition: opacity var(--dur) var(--ease);
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='180' height='180'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.95' numOctaves='2' stitchTiles='stitch' seed='3'/><feColorMatrix values='0 0 0 0 0.4 0 0 0 0 0.36 0 0 0 0 0.28 0 0 0 0.55 0'/></filter><rect width='100%25' height='100%25' filter='url(%23n)'/></svg>");
  background-size: 180px 180px;
  mix-blend-mode: multiply;
}
[data-theme="light"][data-grain="on"] #paper-grain { opacity: 0.32; }
/* Skip grain in dark mode — it was barely visible at 0.05, and toggling
   mix-blend-mode (multiply ↔ screen) on theme change kicks iOS Safari
   into a stale-tile rendering glitch that paints horizontal bands of
   the previous theme. Hiding it side-steps the composite swap entirely. */
[data-theme="dark"][data-grain="on"]  #paper-grain { opacity: 0; }

/* During a theme swap, suppress every transition so the new colors paint
   in one frame instead of N elements each animating their bg over
   different durations. The class is removed on the next rAF, so hover
   and focus transitions resume immediately after. */
html.theming,
html.theming *,
html.theming *::before,
html.theming *::after {
  transition: none !important;
}

.app {
  position: relative;
  z-index: 2;
  min-height: 100vh;
  display: flex; flex-direction: column;
}

/* =========================================================================
   Shared atoms
   ========================================================================= */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  gap: 8px;
  height: 36px;
  padding: 0 16px;
  border-radius: var(--radius-sm);
  font: 500 14px var(--font-text);
  letter-spacing: -0.003em;
  border: 1px solid transparent;
  cursor: pointer;
  text-decoration: none;
  background: transparent;
  color: var(--fg);
  white-space: nowrap;
  transition: background var(--dur-fast) var(--ease),
              color var(--dur-fast) var(--ease),
              border-color var(--dur-fast) var(--ease),
              transform var(--dur-fast) var(--ease);
}
.btn-primary { background: var(--primary); color: var(--fg-on-accent); }
.btn-primary:hover { background: var(--primary-hover); }
.btn-primary:active { transform: scale(0.985); }
.btn-primary:disabled { opacity: 0.4; cursor: not-allowed; }

kbd {
  font-family: var(--font-mono);
  font-size: 11px;
  background: var(--bg-sunken);
  color: var(--fg-2);
  padding: 1px 6px;
  border-radius: 4px;
  border: 1px solid var(--border);
}

.hv-sep {
  display: inline-block;
  color: var(--fg-4);
  padding: 0 4px;
  user-select: none;
}

/* =========================================================================
   Top bar — wordmark · URL input · actions
   Always sticky. Always present.
   ========================================================================= */
.tb {
  position: sticky; top: 0; z-index: 30;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 20px;
  /* Respect iOS landscape's left/right safe-area insets so the wordmark
     and right-cluster aren't pinned behind the notch / camera bump. */
  padding:
    max(14px, env(safe-area-inset-top))
    max(28px, env(safe-area-inset-right))
    14px
    max(28px, env(safe-area-inset-left));
  background: var(--toolbar-bg);
  -webkit-backdrop-filter: blur(20px);
  backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border);
  transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease);
}
.tb[data-reading="0"] {
  /* On the home / converting state, the top bar is quiet — no input,
     no border. Lets the centered URL bar carry the page. */
  background: transparent;
  border-bottom-color: transparent;
  -webkit-backdrop-filter: none;
  backdrop-filter: none;
}
.tb-spacer { display: block; }
.tb-mark {
  display: inline-flex; align-items: baseline; gap: 4px;
  background: transparent;
  border: 0;
  cursor: pointer;
  color: var(--fg);
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 17px;
  letter-spacing: -0.030em;
  padding: 4px 6px 4px 2px;
  border-radius: 6px;
  transition: background var(--dur-fast) var(--ease);
}
.tb-mark:hover { background: var(--bg-sunken); }
.tb-pilcrow { color: var(--accent); font-weight: 700; font-size: 19px; line-height: 1; }
.tb-name { letter-spacing: -0.030em; }

.tb-paste {
  display: flex; align-items: center;
  gap: 6px;
  width: 100%;
  max-width: 560px;
  justify-self: center;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 4px 4px 4px 12px;
  transition: border-color var(--dur-fast) var(--ease),
              box-shadow var(--dur-fast) var(--ease),
              background var(--dur-fast) var(--ease);
}
.tb-paste:hover { border-color: var(--border-strong); }
.tb-paste.is-focused {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 4px var(--accent-soft);
  background: var(--bg-elevated);
}
.tb-paste-ico { width: 16px; height: 16px; opacity: 0.5; flex-shrink: 0; }
.tb-paste-input {
  flex: 1; min-width: 0;
  border: 0; outline: 0; background: transparent;
  /* 16px keeps iOS Safari from auto-zooming on focus. Anything below 16px
     on a focused <input> triggers the viewport scale-in on touch devices. */
  font: 400 16px var(--font-mono);
  color: var(--fg);
  padding: 7px 2px;
  letter-spacing: -0.005em;
}
.tb-paste-input::placeholder { color: var(--fg-4); }
.tb-clear {
  display: inline-flex; align-items: center; justify-content: center;
  width: 22px; height: 22px;
  background: transparent;
  border: 0;
  border-radius: 4px;
  cursor: pointer;
  color: var(--fg-3);
  flex-shrink: 0;
}
.tb-clear:hover { background: var(--bg-sunken); }
.tb-clear img { width: 12px; height: 12px; opacity: 0.7; }
.tb-paste-btn {
  height: 30px;
  padding: 0 14px;
  font-size: 13px;
  gap: 6px;
}
.tb-paste-kbd {
  font-family: var(--font-mono);
  font-size: 12px;
  opacity: 0.7;
  margin-left: 2px;
}

.tb-right {
  display: flex; align-items: center; gap: 4px;
}
.tb-sep { width: 1px; height: 20px; background: var(--border); margin: 0 4px; }
.tb-icon {
  display: inline-flex; align-items: center; justify-content: center;
  width: 32px; height: 32px;
  background: transparent;
  border: 0;
  border-radius: var(--radius-sm);
  cursor: pointer;
  color: var(--fg-2);
  transition: background var(--dur-fast) var(--ease);
}
.tb-icon:hover { background: var(--bg-sunken); }
.tb-icon img { width: 16px; height: 16px; opacity: 0.85; }

.tb-icon-btn {
  display: inline-flex; align-items: center; gap: 6px;
  height: 30px;
  padding: 0 10px;
  background: transparent;
  border: 0;
  border-radius: var(--radius-sm);
  cursor: pointer;
  color: var(--fg-2);
  font: 500 13px var(--font-text);
  white-space: nowrap;
  flex-shrink: 0;
  transition: background var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}
.tb-icon-btn:hover { background: var(--bg-sunken); color: var(--fg); }
.tb-icon-btn img { width: 14px; height: 14px; opacity: 0.75; }
.tb-icon-btn.is-flash { color: var(--accent); }
.tb-icon-btn.is-flash img { filter: var(--icon-accent-filter); opacity: 1; }
.tb-icon-label { letter-spacing: -0.003em; }

/* Segmented Rendered/Markdown toggle (in top bar when reading) */
.seg {
  display: inline-flex;
  background: var(--bg-sunken);
  padding: 2px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}
.seg-btn {
  padding: 4px 10px;
  height: 24px;
  font: 500 11px var(--font-text);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  background: transparent;
  border: 0;
  border-radius: 5px;
  cursor: pointer;
  color: var(--fg-3);
  transition: all var(--dur-fast) var(--ease);
  white-space: nowrap;
}
.seg-btn:hover { color: var(--fg); }
.seg-btn.is-active {
  background: var(--bg-elevated);
  color: var(--fg);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
}

/* =========================================================================
   Idle hero — search-engine layout. Big brand mark + big URL bar centered
   vertically on the page. Quiet chip row beneath. Tiny footer at bottom.
   ========================================================================= */
.ih {
  flex: 1;
  display: flex; flex-direction: column;
  align-items: stretch;
  padding: 0;
  position: relative;
}
.ih-inner {
  flex: 1;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 22px;
  padding: 24px 32px 80px;
  /* Nudge the cluster slightly above true vertical center — feels right. */
  padding-bottom: 18vh;
  text-align: center;
}

/* Brand mark — pilcrow + wordmark inline. */
.ih-mark {
  display: inline-flex; align-items: baseline;
  gap: 8px;
  user-select: none;
  margin-bottom: -4px;
}
.ih-mark-pilcrow {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 40px;
  line-height: 1;
  color: var(--accent);
  letter-spacing: -0.020em;
}
.ih-mark-name {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 38px;
  line-height: 1;
  letter-spacing: -0.040em;
  color: var(--fg);
}

/* Tagline — sits beneath the brand mark, smaller than it.
   Hairline ornaments + accent emphasis give it character without
   competing with the wordmark for billing. */
.ih-tagline {
  font-family: var(--font-display);
  font-style: normal;
  font-weight: 500;
  font-size: 20px;
  line-height: 1.2;
  letter-spacing: -0.015em;
  color: var(--fg-2);
  margin: 4px 0 16px;
  display: inline-flex; align-items: baseline; gap: 0.5em;
}
.ih-tagline::before,
.ih-tagline::after {
  content: "";
  display: inline-block;
  width: 32px;
  height: 1px;
  background: var(--border-strong);
  align-self: center;
  opacity: 0.5;
}

/* Instruction line beneath the bar — tells the user what to do. */
.ih-instruction {
  max-width: 52ch;
  font-family: var(--font-text);
  font-size: 14px;
  line-height: 1.5;
  letter-spacing: -0.003em;
  color: var(--fg-3);
  margin: -6px 0 4px;
}

/* Big URL bar */
.ih-paste {
  display: flex; align-items: center;
  gap: 6px;
  width: 100%;
  max-width: 580px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-pill);
  padding: 6px 6px 6px 18px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
  transition: border-color var(--dur-fast) var(--ease),
              box-shadow var(--dur) var(--ease),
              transform var(--dur-fast) var(--ease);
}
.ih-paste:hover { border-color: rgba(0, 0, 0, 0.22); box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06); }
[data-theme="dark"] .ih-paste:hover { border-color: rgba(255, 255, 255, 0.24); box-shadow: 0 2px 8px rgba(0, 0, 0, 0.30); }
.ih-paste.is-focused {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 4px var(--accent-soft);
}
.ih-paste-ico {
  width: 18px; height: 18px; align-self: center; opacity: 0.5;
  flex-shrink: 0;
}
.ih-paste-field {
  flex: 1; min-width: 0;
  position: relative;
  display: flex; align-items: center;
}
.ih-paste-input {
  width: 100%;
  border: 0; outline: 0; background: transparent;
  font: 400 17px var(--font-mono);
  color: var(--fg);
  padding: 14px 4px;
  letter-spacing: -0.005em;
  text-align: left;
}
.ih-paste-ph {
  position: absolute;
  inset: 0;
  display: flex; align-items: center;
  padding: 0 4px;
  font: 400 17px var(--font-mono);
  letter-spacing: -0.005em;
  color: var(--fg-4);
  pointer-events: none;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: clip;
}
.ih-paste-ph-proto { color: var(--fg-4); opacity: 0.7; }
.ih-paste-ph-rest  { color: var(--fg-3); }
.ih-paste-ph-caret {
  display: inline-block;
  width: 1.5px;
  height: 17px;
  background: var(--accent);
  margin-left: 2px;
  animation: ih-caret-blink 1.05s steps(2, start) infinite;
}
@keyframes ih-caret-blink {
  0%, 50%   { opacity: 1; }
  50.01%, 100% { opacity: 0; }
}

.ih-paste-clear {
  display: inline-flex; align-items: center; justify-content: center;
  width: 28px; height: 28px;
  align-self: center;
  background: transparent;
  border: 0;
  border-radius: 999px;
  cursor: pointer;
  color: var(--fg-3);
  flex-shrink: 0;
}
.ih-paste-clear:hover { background: var(--bg-sunken); }
.ih-paste-clear img { width: 14px; height: 14px; opacity: 0.7; }

.ih-paste-btn {
  height: 40px;
  padding: 0 22px;
  font-size: 14px;
  gap: 8px;
  flex-shrink: 0;
  border-radius: var(--radius-pill);
}
.ih-paste-kbd {
  font-family: var(--font-mono);
  font-size: 13px;
  opacity: 0.7;
  margin-left: 2px;
}

/* Tiny footer (left empty as a visual breathing space) */
.ih-footer {
  display: block;
  padding: 18px 24px 22px;
  min-height: 8px;
}

/* =========================================================================
   Converting
   ========================================================================= */
.cv {
  flex: 1;
  display: flex; align-items: center; justify-content: center;
  padding: 48px 32px;
}
.cv-card {
  width: 100%;
  max-width: 480px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 28px 28px 24px;
  box-shadow: var(--shadow-card);
  display: flex; flex-direction: column; gap: 20px;
}
.cv-head { display: flex; align-items: center; justify-content: space-between; }
.cv-eyebrow {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent);
}
.cv-cancel {
  background: transparent;
  border: 0;
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
  color: var(--fg-3);
}
.cv-cancel:hover { background: var(--bg-sunken); }
.cv-cancel img { width: 16px; height: 16px; }

.cv-url {
  display: flex; align-items: center; gap: 10px;
  font-family: var(--font-mono);
  font-size: 13px;
  background: var(--bg-sunken);
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  color: var(--fg);
  margin: 0;
  word-break: break-all;
}
.cv-url img { width: 14px; height: 14px; opacity: 0.5; flex-shrink: 0; }

.cv-steps { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 2px; }
.cv-step {
  display: flex; align-items: center; gap: 12px;
  padding: 8px 4px;
  font: 400 14px var(--font-text);
  color: var(--fg-4);
  transition: color var(--dur) var(--ease);
}
.cv-step.is-done { color: var(--fg-2); }
.cv-step.is-active { color: var(--fg); }
.cv-step-mark {
  display: inline-flex; align-items: center; justify-content: center;
  width: 20px; height: 20px;
  flex-shrink: 0;
}
.cv-step-mark img { width: 16px; height: 16px; }
.cv-step.is-done .cv-step-mark img { filter: var(--icon-accent-filter); }
.cv-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: currentColor;
  opacity: 0.5;
}
.cv-step.is-active .cv-dot {
  background: var(--accent);
  opacity: 1;
  animation: cv-pulse 1s infinite var(--ease);
}
@keyframes cv-pulse {
  0%, 100% { transform: scale(1); opacity: 1; }
  50%      { transform: scale(0.55); opacity: 0.4; }
}

/* =========================================================================
   Document view — e-reader page
   Structured header → drop-cap body → ornament → footer
   ========================================================================= */
.dv {
  flex: 1;
  padding:
    56px
    max(48px, env(safe-area-inset-right))
    max(96px, calc(96px + env(safe-area-inset-bottom)))
    max(48px, env(safe-area-inset-left));
  display: flex; flex-direction: column;
}
.dv-article {
  width: 100%;
  margin: 0 auto;
  font-family: var(--font-text);
  color: var(--fg);
}
.dv[data-measure="60"] .dv-article { max-width: 60ch; }
.dv[data-measure="68"] .dv-article { max-width: 68ch; }
.dv[data-measure="76"] .dv-article { max-width: 76ch; }
.dv[data-measure="88"] .dv-article { max-width: 88ch; }
.dv[data-measure="100"] .dv-article { max-width: 100ch; }
.dv[data-density="comfortable"] .dv-body { font-size: 19px; line-height: 1.78; }
.dv[data-density="compact"]     .dv-body { font-size: 17px; line-height: 1.65; }

/* — Document header (kicker · title · byline · § rule) — */
.dh {
  display: flex; flex-direction: column; gap: 16px;
  margin-bottom: 40px;
}
.dh-kicker {
  display: flex; align-items: center; flex-wrap: wrap;
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--fg-3);
}
.dh-kicker-site {
  display: inline-flex; align-items: center; gap: 6px;
  color: var(--fg-2);
}
.dh-kicker-site img { width: 12px; height: 12px; opacity: 0.6; }
.dh-kicker-site a { color: inherit; text-decoration: none; }
.dh-kicker-site a:hover { color: var(--accent); }
.dh-kicker-dot { color: var(--fg-4); padding: 0 8px; user-select: none; }

.dh-title {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: clamp(36px, 4.4vw, 52px);
  line-height: 1.06;
  letter-spacing: -0.030em;
  color: var(--fg);
  margin: 0;
  text-wrap: balance;
}
.dv[data-density="compact"] .dh-title { font-size: clamp(30px, 3.6vw, 40px); }

.dh-byline {
  display: flex; align-items: baseline; gap: 0;
  font-family: var(--font-display);
  font-style: italic;
  font-weight: 400;
  font-size: 17px;
  line-height: 1.4;
  letter-spacing: -0.005em;
  color: var(--fg-2);
  margin: 0;
}
.dh-byline-dot { color: var(--fg-4); padding: 0 8px; font-style: normal; }

.dh-rule {
  display: flex; align-items: center;
  margin: 16px 0 0;
  color: var(--fg-4);
}
.dh-rule::before,
.dh-rule::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--border);
}
.dh-rule span {
  font-family: var(--font-display);
  font-size: 16px;
  line-height: 1;
  padding: 0 14px;
  color: var(--fg-3);
}

/* — Body — */
.dv-body { color: var(--fg); }

/* Drop cap on the first qualifying paragraph (renderer decides). */
.dv-body > .md-p.is-lede::first-letter {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 4.4em;
  line-height: 0.86;
  float: left;
  padding: 6px 10px 0 0;
  margin: 4px 0 -6px 0;
  color: var(--fg);
}
.dv[data-density="compact"] .dv-body > .md-p.is-lede::first-letter {
  font-size: 3.8em;
}

/* — Foot ornament + End. — */
.dv-foot {
  margin-top: 72px;
  display: flex; flex-direction: column; align-items: center; gap: 10px;
}
.dv-foot-ornament {
  display: inline-flex; align-items: center; gap: 14px;
  color: var(--fg-4);
  font-family: var(--font-display);
  font-size: 20px;
  line-height: 1;
}
.dv-foot-ornament span { display: inline-block; transform: translateY(-2px); }
.dv-foot-end {
  font-family: var(--font-display);
  font-style: italic;
  font-weight: 400;
  font-size: 15px;
  color: var(--fg-3);
  margin: 0;
  letter-spacing: 0.04em;
}
.dv-foot-meta {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--fg-3);
  margin: 0;
}
.dv-foot-meta a {
  color: var(--accent);
  text-decoration: none;
  margin-left: 0;
}
.dv-foot-meta a:hover { text-decoration: underline; text-underline-offset: 3px; }

/* Raw markdown view — replaces .dv-body when view="raw" */
.dv-raw {
  font-family: var(--font-mono);
  font-size: 13.5px;
  line-height: 1.7;
  color: var(--fg);
  background: var(--bg-sunken);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 22px 24px;
  white-space: pre-wrap;
  word-break: break-word;
  margin: 0;
}
.dv[data-density="compact"] .dv-raw { font-size: 12.5px; line-height: 1.65; }

/* Markdown elements */
.md-h1 {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 40px;
  line-height: 1.1;
  letter-spacing: -0.030em;
  color: var(--fg);
  margin: 0 0 8px;
}
.dv[data-density="compact"] .md-h1 { font-size: 32px; }

.md-h2 {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 25px;
  line-height: 1.22;
  letter-spacing: -0.016em;
  color: var(--fg);
  margin: 40px 0 14px;
}
.md-h3 {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 19px;
  line-height: 1.3;
  letter-spacing: -0.010em;
  color: var(--fg);
  margin: 28px 0 10px;
}
.md-p {
  margin: 0 0 18px;
  letter-spacing: -0.003em;
  text-wrap: pretty;
  color: var(--fg);
}
.md-p em { font-style: italic; color: var(--fg-2); }
.md-p strong { font-weight: 600; }
.md-p code, .md-quote code, .md-ul code, .md-ol code {
  font-family: var(--font-mono);
  font-size: 0.88em;
  background: var(--bg-sunken);
  padding: 1px 6px;
  border-radius: 4px;
}
.md-quote {
  border-left: 2px solid var(--accent);
  padding: 4px 0 4px 24px;
  margin: 24px 0 24px -4px;
  color: var(--fg-2);
}
.md-quote p {
  font-family: var(--font-display);
  font-weight: 400;
  font-style: italic;
  font-size: 1.05em;
  line-height: 1.55;
  margin: 0 0 8px;
}
.md-quote p:last-child { margin-bottom: 0; }
.md-ul, .md-ol {
  margin: 0 0 22px;
  padding-left: 1.4em;
}
.md-ul li, .md-ol li {
  margin: 0 0 8px;
  line-height: 1.55;
}
.md-ul li::marker { color: var(--accent); }
.md-ol li::marker { color: var(--fg-3); font-family: var(--font-mono); font-size: 0.85em; }
.md-pre {
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.55;
  background: var(--bg-sunken);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 16px 18px;
  margin: 18px 0 22px;
  overflow-x: auto;
  color: var(--fg);
}
.md-p a, .md-quote a, .md-ul a, .md-ol a,
.md-h1 a, .md-h2 a, .md-h3 a {
  color: var(--accent);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 2px;
}
.md-p a:hover, .md-quote a:hover, .md-ul a:hover, .md-ol a:hover { text-decoration-thickness: 1.5px; }
/* Images render inline by default so tiny indicators (e.g. Wikipedia's
   change-arrow icons) sit alongside their surrounding text. When the
   image is the only thing in its paragraph it gets centered as a block. */
.md-img {
  max-width: 100%;
  max-height: 72vh;
  height: auto;
  vertical-align: middle;
  border-radius: var(--radius-sm);
}
.dv-body .md-p:has(> .md-img:only-child) {
  text-align: center;
  margin: 24px 0;
}
.dv-body .md-p:has(> .md-img:only-child) > .md-img {
  display: block;
  margin: 0 auto;
}
.md-hr {
  border: 0;
  height: 1px;
  background: var(--border);
  margin: 32px auto;
  width: 40%;
}

/* Strikethrough — quieter than body so deleted content reads as a side
   note, never as something you should still read carefully. */
.md-p del, .md-quote del, .md-ul del, .md-ol del,
.md-table del {
  color: var(--fg-3);
  text-decoration-color: var(--fg-4);
}

/* Inline code in headings keeps the editorial feel of the heading
   without ballooning to display-text size. */
.md-h1 code, .md-h2 code, .md-h3 code {
  font-family: var(--font-mono);
  font-size: 0.78em;
  font-weight: 500;
  background: var(--bg-sunken);
  padding: 1px 6px;
  border-radius: 4px;
  letter-spacing: 0;
  vertical-align: 0.04em;
}

/* Code blocks: enable tab-rendering and a touch more breathing room. */
.md-pre {
  tab-size: 2;
}

/* Long URLs and inline code should break at the measure rather than
   forcing the whole column to widen on phones. */
.md-p, .md-quote p, .md-ul li, .md-ol li {
  overflow-wrap: anywhere;
}
.md-p code, .md-quote code, .md-ul code, .md-ol code {
  word-break: break-word;
}

/* =========================================================================
   Tables — clean hairline rules, uppercase mono-style headers, horizontal
   scroll wrapper so wide tables don't break out of the article column.
   ========================================================================= */
.md-table-wrap {
  margin: 24px 0;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border-bottom: 1px solid var(--border);
}
.md-table {
  border-collapse: collapse;
  width: 100%;
  font-family: var(--font-text);
  font-size: 15px;
  line-height: 1.5;
  color: var(--fg);
}
.md-table th,
.md-table td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
}
.md-table th {
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: 11px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--fg-3);
  border-bottom: 1px solid var(--border-strong);
  white-space: nowrap;
}
.md-table tbody tr:last-child td { border-bottom: 0; }
.md-table tbody tr:hover { background: var(--bg-elevated); }

/* Error state in the converting card */
.cv-card.is-error { border-color: rgba(255, 59, 48, 0.30); }
.cv-error {
  display: flex; flex-direction: column; gap: 16px;
  padding: 4px 0 0;
}
.cv-error-msg {
  font: 400 14px var(--font-text);
  line-height: 1.5;
  color: var(--danger);
  margin: 0;
}
.cv-error-btn {
  align-self: flex-start;
  height: 32px;
  padding: 0 16px;
  font-size: 13px;
}

/* =========================================================================
   Icon tinting
   ========================================================================= */
:root {
  --icon-accent-filter: brightness(0) saturate(100%) invert(35%) sepia(96%)
                        saturate(2700%) hue-rotate(199deg) brightness(102%) contrast(101%);
}
[data-theme="dark"] {
  --icon-accent-filter: brightness(0) saturate(100%) invert(48%) sepia(96%)
                        saturate(3000%) hue-rotate(199deg) brightness(105%) contrast(101%);
}
/* Lucide icons use currentColor — invert them in dark mode so they show
   on dark surfaces. More-specific selectors below restore accent tints. */
[data-theme="dark"] img[src$=".svg"] {
  filter: invert(0.92) brightness(0.95);
}
[data-theme="dark"] .cv-step.is-done .cv-step-mark img,
[data-theme="dark"] .tb-icon-btn.is-flash img {
  filter: var(--icon-accent-filter);
}

/* =========================================================================
   Responsive — three tiers:
     ≤1024px  icon-only Copy/Download   (iPhone landscape, iPad portrait)
     ≤860px   + safe-area padding       (tablet, landscape phone with notch)
     ≤600px   + two-row top bar          (portrait phone)
   ========================================================================= */

/* Below 1024px the Copy/Download labels collapse to icons. Saves ~100px
   from the right cluster so the theme toggle stays visible on iPhone
   landscape (~932px) and iPad portrait. iPad landscape (1133+) keeps the
   labels — it has room. */
@media (max-width: 1024px) {
  .tb-icon-label { display: none; }
  .tb-icon-btn {
    padding: 0;
    width: 36px; height: 36px;
    justify-content: center;
  }
  .tb-icon-btn img { width: 16px; height: 16px; }
  .tb-sep { margin: 0 2px; }
}

/* Below 860px (covers iPad portrait, iPad mini, narrower windows) the
   top-bar/document padding shrinks and respects iOS landscape's
   left/right safe-area insets so the wordmark and theme toggle don't
   sit behind the notch. */
@media (max-width: 860px) {
  .tb {
    padding:
      max(12px, env(safe-area-inset-top))
      max(20px, env(safe-area-inset-right))
      12px
      max(20px, env(safe-area-inset-left));
    gap: 14px;
  }
  .dv {
    padding:
      40px
      max(32px, env(safe-area-inset-right))
      max(80px, calc(80px + env(safe-area-inset-bottom)))
      max(32px, env(safe-area-inset-left));
  }
  .ih-inner { padding: 24px 28px 16vh; }
}

/* Phone: top bar becomes two rows in reading state (wordmark + actions on
   row 1, URL input full-width on row 2) so the input gets real space.
   Touch targets bump up to the iOS 44px minimum, labels collapse, and
   the document view's padding + drop cap shrink. */
@media (max-width: 600px) {
  .tb {
    padding:
      max(8px, env(safe-area-inset-top))
      max(14px, env(safe-area-inset-right))
      8px
      max(14px, env(safe-area-inset-left));
    gap: 6px;
  }

  /* Idle / converting state — wordmark on the left, theme toggle on
     the right. The 1fr column in the middle absorbs the spacer. */
  .tb[data-reading="0"] {
    grid-template-columns: auto 1fr auto;
  }

  /* Reading state — two rows. */
  .tb[data-reading="1"] {
    grid-template-columns: auto 1fr;
    grid-template-areas:
      "mark right"
      "paste paste";
    row-gap: 8px;
  }
  .tb[data-reading="1"] .tb-mark   { grid-area: mark; }
  .tb[data-reading="1"] .tb-paste  { grid-area: paste; max-width: none; justify-self: stretch; }
  .tb[data-reading="1"] .tb-right  { grid-area: right; justify-self: end; }

  /* Collapse the action labels & shortcut hints, but keep the wordmark
     visible — the user navigates by tapping it, and the brand identity
     matters more than the few horizontal pixels it saves. */
  .tb-mark { font-size: 15px; padding: 4px 4px 4px 2px; }
  .tb-pilcrow { font-size: 17px; }
  .tb-icon-label { display: none; }
  .tb-icon-btn { padding: 0; width: 40px; height: 40px; justify-content: center; }
  .tb-icon-btn img { width: 18px; height: 18px; }
  .tb-icon { width: 40px; height: 40px; }
  .tb-icon img { width: 18px; height: 18px; }
  .tb-sep { display: none; }
  .tb-right { gap: 2px; }

  /* Compact segmented toggle: keep both options visible but tighter. */
  .seg-btn { padding: 0 8px; font-size: 10px; height: 28px; }

  /* URL input — fills the second row, bigger tap target inside. Font
     stays at 16px so iOS doesn't auto-zoom the page on focus. */
  .tb-paste { padding: 4px 4px 4px 10px; }
  .tb-paste-input { padding: 10px 2px; font-size: 16px; }
  .tb-paste-btn { height: 36px; padding: 0 14px; }
  .tb-paste-btn .tb-paste-kbd { display: none; }
  .tb-clear { width: 32px; height: 32px; }
  .tb-clear img { width: 14px; height: 14px; }
  .ih-paste-clear { width: 36px; height: 36px; }
  .ih-paste-clear img { width: 16px; height: 16px; }

  /* Idle hero — pull the cluster closer to vertical center, smaller mark. */
  .ih-inner { padding: 24px 18px 10vh; gap: 16px; }
  .ih-mark-pilcrow { font-size: 36px; }
  .ih-mark-name { font-size: 34px; }
  .ih-tagline { font-size: 17px; margin: 2px 0 12px; }
  .ih-tagline::before, .ih-tagline::after { width: 24px; }
  .ih-paste { padding: 5px 5px 5px 14px; }
  .ih-paste-ico { width: 16px; height: 16px; }
  .ih-paste-input, .ih-paste-ph { font-size: 16px; padding: 12px 4px; }
  .ih-paste-btn { height: 36px; padding: 0 18px; font-size: 13px; }
  .ih-paste-kbd { display: none; }
  .ih-instruction { font-size: 13px; padding: 0 8px; }

  /* Document view — tighter side padding and a smaller drop cap so it
     doesn't eat 20% of the viewport width on a 390px phone. */
  .dv {
    padding:
      24px
      max(18px, env(safe-area-inset-right))
      max(64px, calc(64px + env(safe-area-inset-bottom)))
      max(18px, env(safe-area-inset-left));
  }
  .dh { gap: 12px; margin-bottom: 32px; }
  .dh-title { font-size: clamp(28px, 8vw, 36px); }
  .dh-byline { font-size: 15px; }
  .dv-body > .md-p.is-lede::first-letter { font-size: 3em; padding: 4px 8px 0 0; }
  .dv[data-density="comfortable"] .dv-body { font-size: 18px; line-height: 1.7; }
  .dv[data-density="compact"]     .dv-body { font-size: 16px; line-height: 1.6; }
  .md-h2 { font-size: 22px; margin-top: 32px; }
  .md-h3 { font-size: 17px; margin-top: 24px; }
  .md-pre, .dv-raw { padding: 12px 14px; font-size: 12px; }
  .md-table { font-size: 14px; }
  .md-table th, .md-table td { padding: 8px 10px; }
  .dv-foot { margin-top: 48px; }

  /* Converting card — full-bleed-ish on small screens. */
  .cv { padding: 24px 18px; }
  .cv-card { padding: 22px 20px 18px; }
}
