/* How it works: one column that reads top to bottom, the same on phones and desktop. Each step is
   a heading, a short text, its live picture, and a "How exactly" expander that only adds. */
:root {
  --mark: #fff0b3;
  --mark-text: #3a2c00;
  --img-bg: #000;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) { --mark: #4a3b0c; --mark-text: #ffe7a0; }
}
:root[data-theme="dark"] { --mark: #4a3b0c; --mark-text: #ffe7a0; }

.how-top {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 8px; min-height: 52px;
  padding: calc(4px + var(--safe-t)) calc(12px + var(--safe-r)) 4px calc(8px + var(--safe-l));
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.how-top-title { font-weight: 650; }

.page-how {
  max-width: 760px; margin: 0 auto;
  padding: 24px calc(var(--gutter) + var(--safe-r)) calc(48px + var(--safe-b)) calc(var(--gutter) + var(--safe-l));
}
.page-how h1 { font-size: clamp(1.6rem, 4.5vw, 2.2rem); letter-spacing: -0.01em; margin-bottom: 8px; }
.lede { font-size: 1.0625rem; color: var(--text-2); }
.status { display: flex; align-items: center; gap: 8px; color: var(--text-3); font-size: 0.9375rem; min-height: 1.5em; }
.status.err { color: var(--danger); }
.status.ok { color: var(--ok); }
.spinner-sm { width: 16px; height: 16px; border-radius: 50%; border: 2px solid var(--border); border-top-color: var(--accent); animation: spin 0.8s linear infinite; flex: none; }
@keyframes spin { to { transform: rotate(360deg); } }

.step { padding: 32px 0 8px; border-top: 1px solid var(--border); margin-top: 28px; scroll-margin-top: 60px; }
.step h2 { font-size: 1.375rem; display: flex; align-items: baseline; gap: 10px; }
.step h2 .n {
  display: inline-flex; align-items: center; justify-content: center; flex: none;
  min-width: 30px; height: 30px; padding: 0 6px; border-radius: 15px;
  background: var(--accent-soft); color: var(--accent); font-size: 0.9375rem; font-weight: 700;
}
.step > p { color: var(--text); }
.step code, .exact code { font-family: var(--mono); font-size: 0.88em; background: var(--surface-2); padding: 1px 4px; border-radius: 4px; overflow-wrap: anywhere; }

/* The live picture under each step */
.pic { margin-top: 12px; padding: 14px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.pic:empty::before { content: "Loading…"; color: var(--text-3); font-size: 0.9375rem; }
.cap { margin: 0; color: var(--text-2); font-size: 0.9375rem; overflow-wrap: anywhere; }
.code {
  margin: 0; padding: 10px 12px; background: var(--surface-2); border-radius: var(--radius-sm);
  font: 12px/1.55 var(--mono); color: var(--text); white-space: pre; overflow-x: auto; max-width: 100%;
}
.code.wrap { white-space: pre-wrap; overflow-wrap: anywhere; }
.code mark { background: var(--mark); color: var(--mark-text); border-radius: 3px; }
.exact .code { max-height: 360px; overflow: auto; }

/* "How exactly": adds below the picture, never replaces it */
.exact { margin-top: 10px; }
.exact > summary {
  cursor: pointer; display: inline-flex; align-items: center; gap: 6px; min-height: 44px;
  color: var(--accent); font-weight: 600; list-style: none;
}
.exact > summary::-webkit-details-marker { display: none; }
.exact > summary::before { content: "▸"; font-size: 0.8em; }
.exact[open] > summary::before { content: "▾"; }
.exact-body { padding: 4px 0 4px 14px; border-left: 3px solid var(--accent); color: var(--text-2); font-size: 0.9375rem; display: flex; flex-direction: column; gap: 8px; }
.exact-body p, .exact-body ul { margin: 0; }
.exact-body ul { padding-left: 1.2em; }
.exact-body h3 { font-size: 1.0625rem; margin: 8px 0 0; color: var(--text); }

.row { display: flex; gap: 10px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.btn-danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, var(--border)); }
.btn-danger:hover { background: var(--danger-soft); }
@media (pointer: coarse) { .btn { min-height: 44px; } }
.good { color: var(--ok); }
.bad { color: var(--danger); }

/* 1: the link */
.qr-row { display: flex; flex-wrap: wrap; align-items: center; gap: 14px 20px; }
.qr svg { width: 180px; height: 180px; display: block; background: #fff; border-radius: 8px; padding: 6px; }
.small-qr svg { width: 140px; height: 140px; }
.link-actions { display: flex; flex-direction: column; gap: 8px; min-width: 0; flex: 1 1 260px; }
.link-actions .row { flex-wrap: wrap; }
.link-actions .btn { min-width: 120px; }
.link-field { font: 12px var(--mono); width: 100%; }

/* 5: the encrypted file */
.overview { position: relative; height: 10px; border-radius: 5px; background: var(--surface-2); border: 1px solid var(--border); }
.overview i { position: absolute; top: -1px; bottom: -1px; border-radius: 3px; }
.overview .win { border: 2px solid var(--accent); background: transparent; }
.overview .sl { background: var(--warn); }
.strip { display: grid; gap: 3px; touch-action: none; user-select: none; cursor: crosshair; padding-bottom: 6px; }
.rec { height: 44px; border-radius: 4px; border: 1px solid var(--border); background: var(--surface-2); display: flex; align-items: center; justify-content: center; font: 10px var(--mono); color: var(--text-3); position: relative; }
.rec.slice::after { content: ""; position: absolute; left: 0; right: 0; bottom: -6px; height: 3px; border-radius: 2px; background: var(--warn); }
.rec.sel { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); font-weight: 700; }
.rec.got { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 700; }
.thumbs { display: grid; grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); gap: 8px; }
.thumb { display: flex; flex-direction: column; gap: 4px; font-size: 0.75rem; color: var(--text-2); }
.thumb canvas { width: 100%; aspect-ratio: 1; background: var(--img-bg); border-radius: 6px; }
.thumb.this canvas { outline: 3px solid var(--warn); }
.thumb .cut { aspect-ratio: 1; border-radius: 6px; border: 1px dashed var(--border); display: flex; align-items: center; justify-content: center; text-align: center; padding: 6px; color: var(--text-3); }

/* 6: log lines */
.host-log, .reqs { display: flex; flex-direction: column; gap: 4px; max-height: 320px; overflow: auto; font: 12px/1.45 var(--mono); }
.req { display: grid; grid-template-columns: auto 1fr auto; gap: 2px 8px; padding: 6px 8px; border-radius: 6px; background: var(--surface-2); color: var(--text); }
.req .m { font-weight: 700; }
.req .p { overflow-wrap: anywhere; min-width: 0; }
.req .s.ok { color: var(--ok); font-weight: 650; }
.req .s.bad { color: var(--danger); font-weight: 650; }
.req .x { grid-column: 1 / -1; color: var(--text-3); overflow-wrap: anywhere; }

/* 7: the tag check */
.controls { gap: 12px 20px; }
.switch { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; min-height: 44px; font-weight: 550; position: relative; user-select: none; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch-track { width: 44px; height: 26px; border-radius: 13px; background: var(--border); position: relative; transition: background 0.15s; flex: none; }
.switch-thumb { position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3); transition: left 0.15s; }
.switch input:checked + .switch-track { background: var(--danger); }
.switch input:checked + .switch-track .switch-thumb { left: 21px; }
.switch input:focus-visible + .switch-track { outline: 2px solid var(--accent); outline-offset: 2px; }
.rec-tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(64px, 1fr)); gap: 8px; }
.rec-tile { display: flex; flex-direction: column; gap: 3px; font: 11px var(--mono); color: var(--text-3); }
.rec-img { position: relative; aspect-ratio: 1; border-radius: 6px; overflow: hidden; background: var(--img-bg); outline: 2px solid transparent; }
.rec-img canvas { width: 100%; height: 100%; display: block; image-rendering: pixelated; }
.rec-mark { position: absolute; right: 4px; bottom: 4px; min-width: 22px; height: 22px; padding: 0 5px; border-radius: 11px; display: none; align-items: center; justify-content: center; font: 700 12px var(--font); color: var(--bg); }
.rec-tile.ok .rec-mark { display: flex; background: var(--ok); }
.rec-tile.bad .rec-img { outline-color: var(--danger); }
.rec-tile.bad .rec-mark { display: flex; background: var(--danger); }
.slice-img { position: relative; width: 100%; max-width: 360px; aspect-ratio: 1; align-self: center; background: var(--img-bg); border-radius: 6px; overflow: hidden; }
.slice-img canvas { width: 100%; height: 100%; display: block; }
.refused { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; text-align: center; padding: 16px; background: rgba(120, 10, 10, 0.85); color: #fff; font-weight: 650; }
.verdict { margin: 0; padding: 10px 12px; border-radius: var(--radius-sm); font-weight: 600; }
.verdict:empty { display: none; }
.verdict.good { background: var(--ok-soft); color: var(--ok); }
.verdict.bad { background: var(--danger-soft); color: var(--danger); }

/* 8, 9: images */
.stage { position: relative; width: 100%; max-width: 512px; aspect-ratio: 1; align-self: center; background: var(--img-bg); border-radius: var(--radius-sm); overflow: hidden; touch-action: none; }
.stage canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.sliders { display: flex; flex-wrap: wrap; gap: 8px 20px; }
.field { flex: 1; min-width: 140px; display: flex; flex-direction: column; gap: 2px; }
.field-label { font-size: 0.875rem; color: var(--text-2); font-weight: 550; }
.sliders input[type="range"], .scrub input { accent-color: var(--accent); width: 100%; min-width: 0; min-height: 44px; }
.scrub { display: flex; align-items: center; gap: 10px; }
.scrub input { flex: 1; min-width: 0; }
.counter { margin: 0; }
.counter b { font-size: 1.25rem; }
.cbar { height: 8px; border-radius: 4px; background: var(--surface-2); border: 1px solid var(--border); overflow: hidden; }
.cbar i { display: block; height: 100%; background: var(--accent); min-width: 2px; }

/* 10: share and revoke */
.study-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; font-size: 0.9375rem; }
.study-list li { padding: 4px 8px; border-radius: 6px; color: var(--text-2); }
.study-list li.this { background: var(--mark); color: var(--mark-text); }
.share-result { display: flex; flex-direction: column; gap: 10px; }
.share-result:empty { display: none; }
.status-line { margin: 0; font-weight: 650; font-size: 1.0625rem; }
.status-line.good { color: var(--ok); }
.status-line.bad { color: var(--danger); }
.thumb-160 { width: 160px; height: 160px; border-radius: 8px; background: var(--img-bg); }

/* The end */
.facts { display: grid; grid-template-columns: max-content 1fr; gap: 4px 14px; margin: 0; font-size: 0.875rem; }
.facts dt { color: var(--text-3); }
.facts dd { margin: 0; min-width: 0; overflow-wrap: anywhere; font-family: var(--mono); font-size: 0.8125rem; }
@media (max-width: 480px) { .facts { grid-template-columns: 1fr; } }
.pbar-wrap { display: flex; flex-direction: column; gap: 4px; }
.pbar { height: 8px; border-radius: 4px; background: var(--surface-2); border: 1px solid var(--border); overflow: hidden; }
.pbar > i { display: block; height: 100%; width: 0; background: var(--accent); }
.bx { width: 100%; border-collapse: collapse; font-size: 0.875rem; }
.bx th, .bx td { padding: 6px; border-bottom: 1px solid var(--border); text-align: left; }
.bx .n { text-align: right; font-variant-numeric: tabular-nums; }

@media (prefers-reduced-motion: reduce) {
  .switch-track, .switch-thumb { transition: none !important; }
  .spinner-sm { animation-duration: 2.4s; }
}
/* Narrow screens: excerpts wrap rather than scroll sideways. */
@media (max-width: 600px) {
  .code { white-space: pre-wrap; overflow-wrap: anywhere; }
}

/* Byte views (step 8): each byte is a grid column, its hex on top, its decoding beneath. */
.bview { display: flex; flex-direction: column; gap: 12px; padding: 10px 12px; background: var(--surface-2); border-radius: var(--radius-sm); color: var(--text); }
.brow-title { font-size: 0.8125rem; color: var(--text-2); margin-bottom: 3px; }
.bflow { display: flex; flex-wrap: wrap; align-items: flex-start; gap: 6px 16px; font: 12px/1.45 var(--mono); }
.bfield { display: grid; grid-template-columns: repeat(var(--n), minmax(2ch, auto)); column-gap: 1ch; }
.bname { grid-column: 1 / -1; grid-row: 1; font: 10px/1.3 var(--font); color: var(--text-3); white-space: nowrap; }
.bx { grid-row: 2; text-align: center; white-space: pre; }
.bc { grid-row: 3; text-align: center; white-space: pre; font-weight: 600; }
.bd { grid-column: 1 / -1; grid-row: 3; text-align: center; white-space: nowrap; font-weight: 600; }
.bfield.chars .bx, .bfield.chars .bc { background: var(--mark); color: var(--mark-text); }
.bnote { margin: 0; font: 12px var(--mono); color: var(--text-3); }
