/* Payment Systems Engineering Handbook: article layout and hand-drawn diagrams.
   Colours come from the theme variables in ../styles.css (.t-light / .t-dark),
   so light and dark mode need no extra rules here. */

/* ---------- Frame: same 1040px bordered column as the rest of the site ---------- */
.hb-frame{border-bottom:1px solid var(--line);scroll-margin-top:64px}
.hb-wrap{position:relative;z-index:1;max-width:1040px;margin:0 auto;background:var(--bg);border-left:1px solid var(--line);border-right:1px solid var(--line)}
.hb-wrap--hero{background:linear-gradient(90deg,var(--bg) 48%,transparent 82%) top/100% 260px no-repeat,linear-gradient(var(--bg),var(--bg)) 0 260px/100% calc(100% - 260px) no-repeat}

/* ---------- Reading progress ---------- */
.hb-progress{position:fixed;top:0;left:0;right:0;height:3px;z-index:50;pointer-events:none}
.hb-progress span{display:block;height:100%;background:var(--accent);transform-origin:0 50%;transform:scaleX(0)}
@media (prefers-reduced-motion: reduce){.hb-progress span{transition:none}}

/* ---------- Hero ---------- */
.hb-hero{padding:56px 28px 40px;display:flex;flex-direction:column;gap:14px;max-width:760px}
.hb-eyebrow{font-size:12.5px;font-weight:600;letter-spacing:.14em;text-transform:uppercase;color:var(--acc)}
.hb-hero h1{margin:0;font-size:clamp(30px,4.2vw,46px);font-weight:600;line-height:1.1;letter-spacing:-.035em;text-wrap:balance}
.hb-lede{margin:0;font-size:18.5px;line-height:1.6;color:var(--muted);text-wrap:pretty;max-width:640px}
.hb-meta{display:flex;flex-wrap:wrap;gap:6px 16px;font-family:'JetBrains Mono',ui-monospace,Menlo,monospace;font-size:13px;color:var(--muted)}
.hb-meta span+span::before{content:"/";margin-right:16px;color:var(--faint)}
.hb-crumbs{font-size:14px;color:var(--muted)}
.hb-crumbs a{text-decoration:underline;text-underline-offset:3px}

/* ---------- Layout: sticky contents on the left, reading column on the right ---------- */
.hb-layout{display:grid;grid-template-columns:230px minmax(0,1fr);border-top:1px solid var(--line)}
.hb-toc{border-right:1px solid var(--line);padding:28px 20px 40px 28px}
.hb-toc details{position:sticky;top:84px;max-height:calc(100vh - 110px);overflow:auto}
.hb-toc summary{list-style:none;cursor:pointer;font-size:12px;font-weight:600;letter-spacing:.14em;text-transform:uppercase;color:var(--faint);margin-bottom:12px}
.hb-toc summary::-webkit-details-marker{display:none}
.hb-toc ol{list-style:none;margin:0;padding:0}
.hb-toc li{margin:0}
.hb-toc a{display:block;padding:5px 0 5px 10px;border-left:2px solid transparent;font-size:14px;line-height:1.4;color:var(--muted)}
.hb-toc ol ol a{padding-left:20px;font-size:13.5px}
.hb-toc a.is-active{border-left-color:var(--accent);color:var(--text);font-weight:500}

.hb-article{padding:40px 28px 64px;min-width:0}
.hb-article>*{max-width:66ch}
.hb-article>.sketch,.hb-article>.code,.hb-article>.table-wrap,.hb-article>.hb-cards{max-width:100%}

/* ---------- Typography ---------- */
.hb-article{font-size:17px;line-height:1.72}
.hb-article p,.hb-article ul,.hb-article ol{margin:0 0 1.25em}
.hb-article ul,.hb-article ol{padding-left:1.3em}
.hb-article li{margin:.3em 0}
.hb-article h2{margin:2.4em 0 .6em;padding-top:.4em;font-size:clamp(24px,2.8vw,30px);line-height:1.2;letter-spacing:-.025em;font-weight:600;scroll-margin-top:96px;text-wrap:balance}
.hb-article h2:first-child{margin-top:0}
.hb-article h3{margin:1.9em 0 .5em;font-size:20.5px;line-height:1.3;letter-spacing:-.015em;font-weight:600;scroll-margin-top:96px}
.hb-article h4{margin:1.9em 0 .45em;font-size:17.5px;font-weight:600;letter-spacing:-.01em}
.hb-article h4::before{content:"";display:inline-block;width:14px;height:2px;margin:0 10px 4px 0;background:var(--accent);vertical-align:middle}
.hb-article .chapter{margin:3em 0 0;padding-top:28px;border-top:1px solid var(--line);font-size:12.5px;font-weight:600;letter-spacing:.14em;text-transform:uppercase;color:var(--acc)}
.hb-article .chapter+h2{margin-top:.3em}
.hb-article a{color:var(--acc);text-decoration:underline;text-underline-offset:3px}
.hb-article strong{font-weight:600}
.hb-article :not(pre)>code{font-family:'JetBrains Mono',ui-monospace,Menlo,monospace;font-size:.86em;padding:.1em .35em;background:var(--chip);border:1px solid var(--line);border-radius:3px;overflow-wrap:anywhere}
.hb-article .lead{font-size:19px;color:var(--text)}
.hb-article .muted{color:var(--muted)}
.hb-article sup a{text-decoration:none;font-size:.8em}

/* ---------- Callouts ---------- */
.callout{margin:1.6em 0;padding:16px 20px;background:var(--chip);border:1px solid var(--line);border-left:3px solid var(--line2)}
.callout p:last-child{margin-bottom:0}
.callout-title{font-weight:600;margin-bottom:.4em !important}
.callout--warn{border-left-color:var(--accent)}
.callout--warn .callout-title{color:var(--acc)}
.callout--rule{border-left-color:var(--ok)}
.callout--short{background:var(--panel);border-left-color:var(--accent);padding:18px 22px}
.callout--short .callout-title{font-size:12.5px;font-weight:600;letter-spacing:.14em;text-transform:uppercase;color:var(--acc)}
.callout--short p{font-size:17.5px;line-height:1.65;color:var(--text)}

/* ---------- Tables ---------- */
.table-wrap{margin:1.6em 0;overflow-x:auto;border:1px solid var(--line);background:var(--panel)}
.table-wrap table{width:100%;border-collapse:collapse;font-size:15px;line-height:1.5}
.table-wrap caption{text-align:left;padding:12px 16px;font-size:13px;color:var(--muted);border-bottom:1px solid var(--line)}
.table-wrap th,.table-wrap td{padding:10px 16px;border-bottom:1px solid var(--line);text-align:left;vertical-align:top}
.table-wrap thead th{font-size:12.5px;font-weight:600;letter-spacing:.06em;text-transform:uppercase;color:var(--muted);background:var(--chip);vertical-align:bottom}
.table-wrap tbody th{font-weight:600;font-family:'JetBrains Mono',ui-monospace,Menlo,monospace;font-size:13.5px;white-space:nowrap}
.table-wrap tr:last-child th,.table-wrap tr:last-child td{border-bottom:0}

/* ---------- Code ---------- */
.code{margin:1.6em 0;border:1px solid var(--line);background:var(--panel)}
.code figcaption{display:flex;justify-content:space-between;gap:12px;padding:9px 16px;border-bottom:1px solid var(--line);font-family:'JetBrains Mono',ui-monospace,Menlo,monospace;font-size:12.5px;color:var(--muted)}
.code pre{margin:0;padding:16px;overflow-x:auto;font-family:'JetBrains Mono',ui-monospace,Menlo,monospace;font-size:13.5px;line-height:1.65;color:var(--text);tab-size:4}
.code .k{color:var(--cKey)}
.code .s{color:var(--cStr)}
.code .n{color:var(--cNum)}
.code .c{color:var(--cCom);font-style:italic}
.code-toggle{display:none}
.hb-js .code--long pre{max-height:calc(16 * 13.5px * 1.65 + 32px);overflow:hidden;-webkit-mask-image:linear-gradient(to bottom,#000 72%,transparent);mask-image:linear-gradient(to bottom,#000 72%,transparent)}
.hb-js .code--long.is-open pre{max-height:none;overflow-x:auto;-webkit-mask-image:none;mask-image:none}
.hb-js .code-toggle{display:block;width:100%;min-height:42px;padding:0 16px;border:0;border-top:1px solid var(--line);background:var(--chip);color:var(--acc);font:inherit;font-family:'JetBrains Mono',ui-monospace,Menlo,monospace;font-size:13px;text-align:left;cursor:pointer}
.hb-js .code-toggle:hover{background:var(--panel)}
.hb-js .code-toggle:focus-visible{outline:2px solid var(--accent);outline-offset:-2px}

/* ---------- Checklists ---------- */
.checklist{list-style:none;padding:0 !important}
.checklist li{position:relative;padding-left:30px}
.checklist li::before{content:"";position:absolute;left:2px;top:.42em;width:14px;height:14px;border:1.5px solid var(--line2);border-radius:2px}
.checklist li::after{content:"";position:absolute;left:6px;top:.62em;width:7px;height:4px;border-left:2px solid var(--ok);border-bottom:2px solid var(--ok);transform:rotate(-45deg)}

/* ---------- Cards (hub contents, part navigation) ---------- */
.hb-cards{display:grid;grid-template-columns:repeat(auto-fit,minmax(min(260px,100%),1fr));gap:12px;margin:1.6em 0}
.hb-card{position:relative;display:flex;flex-direction:column;gap:6px;padding:18px 20px;background:var(--panel);border:1px solid var(--line);color:var(--text);text-decoration:none !important}
a.hb-card:hover{opacity:1;border-color:var(--line2)}
.hb-card .tag{font-family:'JetBrains Mono',ui-monospace,Menlo,monospace;font-size:12.5px;color:var(--acc)}
.hb-card .tag--soon{color:var(--muted)}
.hb-card .title{font-size:18px;font-weight:600;line-height:1.3;letter-spacing:-.015em}
.hb-card .desc{font-size:14.5px;line-height:1.55;color:var(--muted)}
.hb-card ol{margin:4px 0 0;padding-left:1.2em;font-size:14.5px;line-height:1.55;color:var(--muted)}
.hb-card.is-soon{background:transparent;border-style:dashed}

.hb-share{margin:3.5em 0 0;padding:22px 24px 18px;background:var(--panel);border:1px solid var(--line);border-left:3px solid var(--accent)}
.hb-article .hb-share-title{margin:0 0 .4em;padding:0;border:0;font-size:20px;letter-spacing:-.01em}
.hb-share p{margin:0 0 1em;font-size:16.5px}
.hb-share-actions{display:flex;flex-wrap:wrap;gap:8px}
.hb-share-actions a,.hb-share-actions button{min-height:44px;display:inline-flex;align-items:center;padding:0 16px;border:1px solid var(--line);background:var(--bg);color:var(--text);font:inherit;font-size:14.5px;font-weight:500;text-decoration:none;cursor:pointer}
.hb-share-actions a:hover,.hb-share-actions button:hover{border-color:var(--accent)}
.hb-share-actions [hidden]{display:none}
.hb-share-actions .hb-share-native{background:var(--accent);border-color:var(--accent);color:#1a1a1a}
.hb-article .hb-share-status{min-height:1.4em;margin:.6em 0 .2em;font-size:14px;color:var(--ok)}
.hb-article .hb-share-follow{margin:0;font-size:14.5px;color:var(--muted)}
.hb-partnav{display:flex;flex-wrap:wrap;gap:12px;margin:3em 0 0;max-width:100% !important}
.hb-partnav a{flex:1 1 240px;display:flex;flex-direction:column;gap:4px;padding:16px 20px;border:1px solid var(--line);background:var(--panel);color:var(--text);text-decoration:none}
.hb-partnav a span:first-child{font-size:12.5px;letter-spacing:.1em;text-transform:uppercase;color:var(--muted)}
.hb-partnav a span:last-child{font-weight:600}

.hb-author{display:flex;gap:18px;align-items:flex-start;margin:2.4em 0;padding:20px;border:1px solid var(--line);background:var(--panel)}
.hb-author img{flex:0 0 auto;width:64px;height:72px;object-fit:cover;object-position:50% 0;border:1px solid var(--line2)}
.hb-author p{margin:0 0 .6em;font-size:15.5px;line-height:1.6;color:var(--muted)}
.hb-author p:first-child{color:var(--text);font-weight:600}
.hb-author p:last-child{margin:0}

/* ---------- FAQ ---------- */
.faq h3{font-size:18px;margin-top:1.6em}

/* ---------- Hand-drawn diagrams ---------- */
.sketch-defs{position:absolute;width:0;height:0;overflow:hidden}
.sketch{position:relative;margin:2em 0;padding:0;border:1px solid var(--line);background:var(--panel)}
.sketch-scroll{overflow-x:auto;padding:18px 14px 6px}
.sketch-scroll:focus-visible{outline:2px solid var(--accent);outline-offset:-2px}
.sketch svg{display:block;width:100%;min-width:var(--min,0px);height:auto;overflow:visible}
.sketch figcaption{padding:12px 18px 16px;border-top:1px dashed var(--line);font-size:15px;line-height:1.6;color:var(--muted)}
.sketch figcaption strong{color:var(--text)}
.sketch-hint{display:none;margin:0;padding:0 18px 8px;font-size:13px;color:var(--muted)}
.sketch-replay{position:absolute;top:8px;right:8px;min-height:32px;padding:0 12px;font:inherit;font-size:12.5px;color:var(--muted);background:var(--bg);border:1px solid var(--line);border-radius:3px;cursor:pointer}
.sketch-replay:hover{color:var(--text);border-color:var(--line2)}

.sketch path,.sketch line,.sketch ellipse{fill:none;stroke-linecap:round;stroke-linejoin:round;stroke-width:2}
.sketch .thin{stroke-width:1.1;opacity:.7}
.sketch .bold{stroke-width:2.6}
.sketch .dashed{stroke-dasharray:6 7}
.st-ink{stroke:var(--text)}
.st-acc{stroke:var(--acc)}
.st-ok{stroke:var(--ok)}
.st-muted{stroke:var(--faint)}
.fill-ink{fill:var(--text)}
.fill-acc{fill:var(--acc)}
.fill-ok{fill:var(--ok)}
.fill-muted{fill:var(--muted)}
.fill-bg{fill:var(--bg)}
.hatch--acc{fill:url(#hb-hatch-acc)}
.hatch--ok{fill:url(#hb-hatch-ok)}
.hatch--ink{fill:url(#hb-hatch-ink)}
.hatch--muted{fill:url(#hb-hatch-muted)}
.sketch .hand{font-family:Caveat,'Comic Sans MS','Segoe Print',cursive}
.sketch .mono{font-family:'JetBrains Mono',ui-monospace,Menlo,monospace}
.sketch .packet{stroke:none}

/* Animation: only once JS has marked the page (hb-js) and the figure scrolled in.
   Without JS, or with reduced motion, every drawing shows complete and still. */
.hb-js .sketch .draw{stroke-dasharray:1 1;stroke-dashoffset:1}
.hb-js .sketch .draw.dashed{stroke-dasharray:6 7;stroke-dashoffset:0;opacity:0}
.hb-js .sketch .fade,.hb-js .sketch .packet{opacity:0}
.hb-js .sketch.is-drawn .draw{stroke-dashoffset:0;transition:stroke-dashoffset .75s cubic-bezier(.5,0,.3,1) calc(var(--d,0) * .22s)}
.hb-js .sketch.is-drawn .draw.dashed{opacity:1;transition:opacity .5s ease calc(var(--d,0) * .22s)}
.hb-js .sketch.is-drawn .fade{opacity:1;transition:opacity .45s ease calc(var(--d,0) * .22s + .25s)}
.hb-js .sketch.is-drawn .thin.fade,.hb-js .sketch.is-drawn .hatch{opacity:1}
.hb-js .sketch.is-drawn .packet{opacity:1;transition:opacity .4s ease 2.2s}
.sketch-replay{display:none}
.hb-js .sketch-replay{display:block}
@media (prefers-reduced-motion: reduce){
  .hb-js .sketch .draw{stroke-dashoffset:0 !important;transition:none !important}
  .hb-js .sketch .draw.dashed{opacity:1 !important}
  .hb-js .sketch .fade{opacity:1 !important;transition:none !important}
  .sketch .packet{display:none}
  .hb-js .sketch-replay{display:none}
}

/* ---------- Tablets and phones ---------- */
@media (max-width: 900px){
  .hb-layout{grid-template-columns:minmax(0,1fr)}
  .hb-toc{border-right:0;border-bottom:1px solid var(--line);padding:14px 28px}
  .hb-toc details{position:static;max-height:none}
  .hb-toc summary{margin:0;padding:8px 0;font-size:13px}
  .hb-toc summary::after{content:" +";color:var(--acc)}
  .hb-toc details[open] summary::after{content:" \2212"}
  .hb-toc details[open] summary{margin-bottom:8px}
}
@media (max-width: 640px){
  .hb-hero{padding:36px 20px 28px}
  .hb-lede{font-size:17px}
  .hb-toc{padding:10px 20px}
  .hb-article{padding:28px 20px 48px;font-size:16.5px}
  .sketch-scroll{padding:14px 8px 4px}
  .sketch-hint{display:block;padding:0 14px 8px}
  .sketch figcaption{padding:12px 14px 14px;font-size:14.5px}
  .hb-author{flex-direction:column}
}
