/* Imagehide demo — self-contained, side-by-side encode | decode workbench.
   Lives inside the site's <article class="page"> wrapper which itself is
   inside <main class="shell">. The site clamps `.prose` to 60ch, so we
   neutralize that locally so the two-column layout has room. */

.prose:has(.ih) { max-width: none !important; }
.shell:has(.ih) { max-width: 1180px; }
.page:has(.ih)  { padding-top: 0.6rem; }

/* === tokens === */
/* Aligned with the dashboard palette (index.html, docs/html/*.html) so the
   demo sits on the same visual stack: stone-neutral surfaces + #2563eb
   accent + matching dark-mode set. Variable names kept from the earlier
   warm-paper draft so the ~500 downstream usages don't need rewriting. */
.ih {
  --ink: #1c1917;            /* dashboard --text */
  --ink-soft: #1c1917;
  --muted: #78716c;          /* dashboard --muted */
  --faint: #a8a29e;          /* lighter than muted */
  --paper: #ffffff;          /* dashboard --surface */
  --paper-soft: #f5f5f4;     /* dashboard --surface-2 */
  --paper-warm: #eff6ff;     /* dashboard --accent-bg — the "highlighted" tint */
  --rule: #e7e5e4;           /* dashboard --border */
  --rule-strong: #d6d3d1;
  --accent: #2563eb;         /* dashboard --accent — same blue as the dashboard */
  --accent-deep: #1d4ed8;
  --link: #2563eb;
  --ok: #15803d;             /* dashboard --ok */
  --bad: #b91c1c;            /* dashboard --bad */

  font-family: ui-sans-serif, system-ui, -apple-system, "SF Pro Text",
               "Segoe UI", "Helvetica Neue", sans-serif;
  font-size: 15px;
  line-height: 1.5;
  color: var(--ink);
  margin: 0.8rem 0 0;
}

.ih *, .ih *::before, .ih *::after { box-sizing: border-box; }
.ih a { color: var(--link); }
.ih code, .ih pre { font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace; }
.is-hidden { display: none !important; }

/* === global status bar at the very top === */
.ih-globalbar {
  font: 0.78rem/1.4 ui-monospace, monospace;
  color: var(--muted);
  letter-spacing: 0.02em;
  margin: 0 0 0.8rem;
  padding: 0.35rem 0;
  border-bottom: 1px solid var(--rule);
  display: flex;
  align-items: baseline;
}
.ih-globalbar__version {
  margin-left: auto;
  padding-left: 1rem;
  opacity: 0.55;
  font-size: 0.72rem;
  letter-spacing: 0.04em;
  white-space: nowrap;
}
.ih-globalbar::before {
  content: "";
  display: inline-block;
  width: 0.55rem; height: 0.55rem;
  background: var(--faint);
  margin-right: 0.5rem;
  vertical-align: 0.05em;
  border-radius: 50%;
}
.ih-globalbar.is-ready::before { background: var(--ok); }
.ih-globalbar.is-error::before { background: var(--bad); }

/* === two-column grid === */
.ih-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem;
  align-items: stretch;
}
/* Stretch each card to a column flex so the bits dump (always the last
   element in the card) sits at the bottom of the card. With both cards at
   the same height (align-items: stretch), the bit codeblocks end up at the
   same Y position — easy side-by-side comparison. */
.ih-col { display: flex; flex-direction: column; }
.ih-col > .ih-results { display: flex; flex-direction: column; flex: 1 1 auto; min-height: 0; }
.ih-col > .ih-results > .ih-details { margin-top: auto; }
@media (max-width: 880px) {
  .ih-grid { grid-template-columns: 1fr; gap: 1.8rem; }
}

.ih-col {
  background: var(--paper);
  border: 1px solid var(--rule);
  padding: 1.4rem 1.4rem 1.5rem;
  position: relative;
  min-width: 0;
}
.ih-col[data-col="decode"] { background: var(--paper-soft); }

.ih-col__head { margin: 0 0 1.2rem; }
.ih-col__title {
  margin: 0 0 0.2rem;
  font-size: 1.6rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--ink);
}
.ih-col__sub {
  margin: 0;
  color: var(--muted);
  font-size: 0.92rem;
}

/* === section block: label + content === */
.ih-section { margin: 0 0 1.2rem; }
.ih-section__label {
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 0 0 0.45rem;
}
.ih-hint {
  font-style: italic;
  color: var(--faint);
  font-size: 0.95em;
  font-weight: 400;
  letter-spacing: 0;
  text-transform: none;
  margin-left: 0.3em;
}

/* === drop zone === */
.ih-drop {
  position: relative;
  border: 1.5px dashed var(--rule-strong);
  background: var(--paper);
  padding: 1.1rem 1rem;
  text-align: center;
  transition: border-color 0.15s, background 0.15s;
  cursor: pointer;
}
.ih-drop:hover { border-color: var(--accent); background: var(--paper-soft); }
.ih-drop.is-dragover { border-color: var(--accent); background: var(--paper-warm); }
.ih-drop--small { padding: 0.7rem 0.9rem; text-align: left; margin-top: 0.5rem; }
.ih-drop__input {
  position: absolute; inset: 0; opacity: 0; cursor: pointer;
}
.ih-drop__cta { pointer-events: none; }
/* Re-enable clicks on the "use the sample" link — otherwise the click
   passes through the link down to the overlaid file input below. */
.ih-drop__cta a { pointer-events: auto; }
.ih-drop__big {
  font-size: 0.95rem;
  color: var(--ink);
}
.ih-drop__big .ih-link {
  color: var(--link);
  text-decoration: underline;
  font-weight: 500;
}
.ih-drop__small {
  font-size: 0.85rem;
  color: var(--muted);
  margin-top: 0.25rem;
}
.ih-drop__small a { color: var(--link); }

/* === preview (after image picked) — same 14rem height as result previews === */
.ih-preview {
  display: block;
  background: var(--paper);
  border: 1px solid var(--rule);
  padding: 0.5rem;
}
.ih-preview canvas {
  display: block;
  width: 100%;
  height: 14rem;
  object-fit: contain;
  background: var(--paper-soft);
}
.ih-preview__meta {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 0.6rem;
  padding: 0.4rem 0.2rem 0;
  font-size: 0.78rem;
  color: var(--muted);
  font-style: italic;
}
.ih-preview__meta span { color: var(--ink-soft); font-style: normal; word-break: break-all; }

/* === radio rows === */
.ih-radios { display: flex; flex-direction: column; gap: 0.3rem; }
.ih-radio {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  padding: 0.45rem 0.6rem;
  border: 1px solid transparent;
  background: var(--paper);
  cursor: pointer;
  font-size: 0.92rem;
  line-height: 1.4;
  transition: background 0.12s, border-color 0.12s;
}
.ih-radio:hover { background: var(--paper-soft); }
.ih-radio input { margin-top: 0.18rem; accent-color: var(--accent); flex-shrink: 0; }
.ih-radio:has(input:checked) {
  background: var(--paper-warm);
  border-color: var(--rule-strong);
}
.ih-radio:has(input:disabled) { opacity: 0.5; cursor: not-allowed; }
.ih-radio strong { font-weight: 600; color: var(--ink); }
.ih-radio em { font-style: italic; color: var(--muted); }

/* === textarea === */
.ih-textarea {
  display: block;
  width: 100%;
  margin-top: 0.5rem;
  padding: 0.55rem 0.7rem;
  font-family: ui-monospace, Menlo, Consolas, monospace;
  font-size: 0.78rem;
  border: 1px solid var(--rule-strong);
  background: var(--paper);
  line-height: 1.5;
  resize: vertical;
  color: var(--ink);
}
.ih-textarea:focus {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}
.ih-customwrap { margin-top: 0.5rem; }
.ih-customwrap .ih-textarea { margin-top: 0; }
.ih-charcount {
  font-size: 0.72rem;
  font-family: ui-monospace, Menlo, Consolas, monospace;
  color: var(--ink-soft, #666);
  text-align: right;
  margin-top: 0.25rem;
  letter-spacing: 0.02em;
}
.ih-charcount.is-over { color: #c1372b; }

/* === select === */
.ih-select {
  font: inherit;
  font-size: 0.92rem;
  padding: 0.45rem 0.55rem;
  width: 100%;
  background: var(--paper);
  border: 1px solid var(--rule-strong);
  color: var(--ink);
  cursor: pointer;
}
.ih-select:focus { outline: 2px solid var(--accent); outline-offset: -2px; }

/* === run line: button + status === */
.ih-runline {
  display: flex;
  align-items: center;
  gap: 0.9rem;
  margin: 1rem 0 0.4rem;
  flex-wrap: wrap;
}
.ih-runline__status {
  font-size: 0.85rem;
  color: var(--muted);
  font-style: italic;
}
.ih-runline__status.is-warn { color: var(--bad); font-style: normal; }

/* === buttons === */
.ih-btn {
  appearance: none;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font: inherit;
  font-size: 0.95rem;
  font-weight: 500;
  padding: 0.55rem 1.1rem;
  border: 1px solid var(--ink-soft);
  background: var(--paper);
  color: var(--ink);
  cursor: pointer;
  letter-spacing: 0.01em;
  transition: background 0.12s, color 0.12s, border-color 0.12s, transform 0.05s;
}
.ih-btn:hover:not(:disabled) { background: var(--paper-warm); }
.ih-btn:active:not(:disabled) { transform: translateY(1px); }
.ih-btn:disabled { opacity: 0.45; cursor: not-allowed; }
.ih-btn--primary {
  background: var(--ink);
  border-color: var(--ink);
  color: #fff;
  font-weight: 600;
  padding: 0.6rem 1.4rem;
  font-size: 1rem;
}
.ih-btn--primary:hover:not(:disabled) {
  background: var(--accent-deep);
  border-color: var(--accent-deep);
  color: #fff;
}
.ih-btn--accent {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 600;
}
.ih-btn--accent:hover:not(:disabled) {
  background: var(--accent-deep);
  border-color: var(--accent-deep);
}
.ih-btn--ghost {
  background: transparent;
  border-color: var(--rule-strong);
  color: var(--ink-soft);
  font-weight: 500;
}
.ih-btn--ghost:hover:not(:disabled) {
  color: var(--ink);
  border-color: var(--ink-soft);
  background: var(--paper);
}

.ih-textbtn {
  appearance: none;
  background: none;
  border: 0;
  padding: 0;
  font: inherit;
  font-size: 0.85rem;
  color: var(--link);
  text-decoration: underline;
  cursor: pointer;
}
.ih-textbtn:hover { color: var(--accent-deep); }

.ih-link { color: var(--link); cursor: pointer; }

/* === results === */
.ih-results {
  margin-top: 1.3rem;
  padding-top: 1rem;
  border-top: 1px solid var(--rule);
}

/* big stat row */
.ih-stats {
  display: flex;
  flex-wrap: wrap;
  border: 1px solid var(--rule);
  background: var(--paper);
  margin-bottom: 0.9rem;
}
.ih-stats > .ih-stat {
  flex: 1 1 0;
  min-width: 6.5rem;
  border-top: 1px solid var(--rule);
  margin-top: -1px;
}
.ih-stat {
  padding: 0.7rem 0.85rem 0.65rem;
  border-right: 1px solid var(--rule);
  min-width: 0;
}
.ih-stat:last-child { border-right: 0; }
.ih-stat__val {
  font-size: 1.45rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
  line-height: 1.05;
  letter-spacing: -0.01em;
}
.ih-stat__val.is-ok  { color: var(--ok); }
.ih-stat__val.is-bad { color: var(--bad); }
.ih-stat__lbl {
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
  margin-top: 0.25rem;
}
.ih-stat__unit { font-weight: 400; color: var(--faint); font-size: 0.85em; }
.ih-stat__note {
  font-size: 0.62rem;
  font-style: italic;
  color: var(--faint);
  letter-spacing: 0;
  text-transform: none;
  font-weight: 400;
  cursor: help;
  border-bottom: 1px dotted var(--faint);
  margin-left: 0.2em;
  white-space: nowrap;
}

/* image preview grid */
.ih-canvases {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.6rem;
  margin-bottom: 0.8rem;
}
.ih-canvases--single { grid-template-columns: 1fr; max-width: 22rem; }
.ih-canvases figure { margin: 0; }
.ih-canvases canvas {
  display: block;
  width: 100%;
  height: 14rem;            /* fixed height for all result previews */
  object-fit: contain;       /* preserve aspect; letterbox if needed */
  border: 1px solid var(--rule);
  background: var(--paper);
  image-rendering: pixelated;
}
.ih-canvases figcaption {
  font-size: 0.78rem;
  color: var(--muted);
  text-align: center;
  margin-top: 0.3rem;
  font-style: italic;
}

.ih-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 0.6rem;
}

/* === details / collapsible bit dump === */
.ih-message {
  margin-top: 0.8rem;
  padding: 0.85rem 1rem;
  border: 1px solid var(--rule-strong);
  background: var(--paper-soft, #fafaf7);
  font-family: ui-monospace, Menlo, Consolas, monospace;
  font-size: 0.92rem;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
}
.ih-message__label {
  display: block;
  font-size: 0.68rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-soft, #888);
  margin-bottom: 0.35rem;
  font-family: inherit;
}
.ih-message__text { color: var(--ink); }

.ih-details {
  margin-top: 0.6rem;
  font-size: 0.88rem;
}
.ih-details > summary {
  cursor: pointer;
  list-style: none;
  color: var(--link);
  display: inline-flex;
  align-items: center;
  gap: 0.3em;
  padding: 0.25rem 0;
}
.ih-details > summary::-webkit-details-marker { display: none; }
.ih-details > summary::before {
  content: "▸";
  font-size: 0.85em;
  transition: transform 0.15s;
  display: inline-block;
}
.ih-details[open] > summary::before { transform: rotate(90deg); }

.ih-codeblock {
  font-size: 0.73rem;
  background: var(--paper-soft);
  padding: 0.7rem 0.9rem;
  border-left: 2px solid var(--accent);
  margin: 0.4rem 0 0;
  white-space: pre;          /* preserve exact column layout for bit alignment */
  overflow-x: auto;          /* horizontal scroll if a line is wider than card */
  max-height: 22rem;
  overflow-y: auto;
  line-height: 1.55;
  color: var(--ink-soft);
}
/* A single mismatched bit in the decode block: red-on-tinted background so it
   pops at a glance, no need to compare character-by-character. */
.ih-codeblock .b-bad {
  color: var(--bad);
  background: rgba(168, 32, 26, 0.16);
  font-weight: 700;
}

/* === handoff highlight when "Send to decode" is clicked === */
.ih-col[data-col="decode"].is-flash {
  animation: ih-flash 0.9s ease-out;
}
@keyframes ih-flash {
  0%   { background: var(--paper-warm); }
  100% { background: var(--paper-soft); }
}

/* === about / perf table === */
.ih-about {
  margin-top: 2.4rem;
  border-top: 1px solid var(--rule);
  padding-top: 1rem;
  font-size: 0.92rem;
  color: var(--ink-soft);
  max-width: 70ch;
}
.ih-about > summary {
  cursor: pointer;
  list-style: none;
  color: var(--muted);
  font-style: italic;
  display: inline-flex;
  align-items: center;
  gap: 0.3em;
  font-size: 0.92rem;
}
.ih-about > summary::-webkit-details-marker { display: none; }
.ih-about > summary::before {
  content: "▸";
  font-size: 0.85em;
  transition: transform 0.15s;
}
.ih-about[open] > summary::before { transform: rotate(90deg); }
.ih-about > summary:hover { color: var(--ink); }
.ih-about__body { padding: 0.5rem 0; line-height: 1.6; }
.ih-about__body p { margin: 0.4rem 0; }
.ih-about__body code { background: var(--paper-warm); padding: 0 0.25em; font-size: 0.92em; }
.ih-perf {
  border-collapse: collapse;
  font-size: 0.83rem;
  margin: 0.4rem 0;
  width: 100%;
}
.ih-perf th, .ih-perf td {
  border-bottom: 1px solid var(--rule);
  padding: 0.3rem 0.6rem 0.3rem 0;
  text-align: left;
  font-variant-numeric: tabular-nums;
}
.ih-perf th {
  font-weight: 600;
  color: var(--muted);
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  border-bottom-color: var(--rule-strong);
}
.ih-perf td:nth-child(n+3), .ih-perf th:nth-child(n+3) {
  text-align: right;
  font-family: ui-monospace, Menlo, monospace;
  font-size: 0.92em;
}

/* === small-screen tweaks === */
@media (max-width: 540px) {
  .ih-col { padding: 1.1rem 1rem 1.2rem; }
  .ih-col__title { font-size: 1.35rem; }
  .ih-stats { grid-template-columns: 1fr 1fr; }
  .ih-stat:nth-child(2) { border-right: 0; }
  .ih-stat:nth-child(odd) { border-right: 1px solid var(--rule); }
  .ih-stat:last-child { grid-column: 1 / -1; border-top: 1px solid var(--rule); }
  .ih-canvases { grid-template-columns: 1fr; }
}

/* === dark mode — mirror the dashboard's `@media (prefers-color-scheme: dark)`
   overrides on the dashboard pages (index.html, docs/html/*.html). Only the
   token values change; everything else cascades. === */
@media (prefers-color-scheme: dark) {
  .ih {
    --ink:          #fafaf9;   /* dashboard dark --text */
    --ink-soft:     #fafaf9;
    --muted:        #a8a29e;   /* dashboard dark --muted */
    --faint:        #78716c;
    --paper:        #1c1917;   /* dashboard dark --surface */
    --paper-soft:   #292524;   /* dashboard dark --surface-2 */
    --paper-warm:   #1e3a5f;   /* dashboard dark --accent-bg */
    --rule:         #44403c;   /* dashboard dark --border */
    --rule-strong:  #57534e;
    --accent:       #60a5fa;   /* dashboard dark --accent */
    --accent-deep:  #93c5fd;
    --link:         #60a5fa;
    --ok:           #15803d;
    --bad:          #b91c1c;
  }
}
