/* ===========================================================================
   First Aid to the SMLE — the screen layer.

   The print stylesheet that builds the PDF is loaded first and untouched; this
   file sits on top of it and changes only what a screen needs: a type scale in
   rem instead of points, two-column blocks that fold to one on a phone, wide
   tables that scroll instead of overflowing, and a dark palette. Every colour,
   component and icon still comes from the print sheet, so the page on screen is
   the same book as the page in the PDF.
   =========================================================================== */

:root{
  --ui:"Archivo","Segoe UI",system-ui,-apple-system,sans-serif;
  --page-bg:#F1F4F7; --surface:#FFFFFF; --chrome:#FFFFFFEE;
  --rule:#D3DCE4; --rule-soft:#E6ECF1; --faint-ink:#788DA0;
  --step:1rem;
  color-scheme:light;
}
:root[data-mode="dark"]{
  --page-bg:#0C141A; --surface:#131E26; --chrome:#131E26EE;
  --rule:#243542; --rule-soft:#1C2A34; --faint-ink:#71879A;

  /* the print sheet's own tokens, restated for a dark page */
  --ink:#DDE7EE; --ink-bold:#F2F7FA; --muted:#A7B9C6; --muted-2:#93A7B6;
  --faint:#71879A; --line:#243542; --dots:#2A3C49; --panel:#172530;
  --zebra:#16222C; --hl:#3A3410;
  --navy:#CFE0EA; --teal:#4FA6C2; --teal-dark:#9FD2E3; --teal-soft:#102A33;
  --teal-line:#1E4250;
  --gold:#C9962B; --gold-dark:#E7C071; --gold-soft:#2B2110;
  --red:#C0574B; --red-dark:#F0A89D; --red-soft:#2E1715;
  --blue:#5B81B8; --blue-dark:#A9C4E8; --blue-soft:#15202E;
  --case-soft:#141F29; --case-dash:#2A3C49;
  color-scheme:dark;
}

html{background:var(--page-bg)}
body{
  background:var(--page-bg); color:var(--ink);
  font-size:var(--step); line-height:1.58;
  margin:0; padding:0;
  -webkit-text-size-adjust:100%;
}

/* ---------- the page frame ---------- */
.rd-wrap{max-width:900px;margin:0 auto;
  padding-left:max(18px,env(safe-area-inset-left,0px));
  padding-right:max(18px,env(safe-area-inset-right,0px));
  padding-bottom:calc(60px + env(safe-area-inset-bottom,0px))}
.rd-body{background:var(--surface);border:1px solid var(--rule);border-radius:16px;
  padding:26px 26px 30px;margin:16px 0 22px;
  box-shadow:0 1px 2px rgba(15,31,42,.05), 0 14px 36px -24px rgba(15,31,42,.5)}

/* ---------- top bar ---------- */
.rd-bar{position:sticky;top:0;z-index:20;display:flex;align-items:center;gap:12px;
  background:var(--chrome);backdrop-filter:saturate(1.4) blur(10px);
  border-bottom:1px solid var(--rule);
  padding:10px max(18px,env(safe-area-inset-left,0px)) 10px max(18px,env(safe-area-inset-right,0px));
  font-family:var(--ui)}
.rd-bar .home{display:inline-flex;align-items:center;gap:7px;text-decoration:none;color:var(--ink)}
.rd-bar .home svg{width:26px;height:26px;flex:none;border-radius:7px}
.rd-bar .home b{font-size:.95rem;font-weight:700;letter-spacing:-.02em}
.rd-bar .home b i{font-style:normal;font-weight:800;color:var(--teal)}
.rd-bar .where{margin-left:auto;font-size:.76rem;font-weight:600;letter-spacing:.07em;
  text-transform:uppercase;color:var(--faint-ink);text-align:right;line-height:1.35}
.rd-bar .iconbtn{flex:none;width:34px;height:34px;border:1px solid var(--rule);border-radius:50%;
  background:var(--surface);display:flex;align-items:center;justify-content:center;color:var(--muted)}
.rd-bar .iconbtn:hover{border-color:var(--teal);color:var(--teal)}
.rd-bar .iconbtn svg{width:16px;height:16px;fill:none;stroke:currentColor;stroke-width:1.9;
  stroke-linecap:round;stroke-linejoin:round}

/* ---------- a type scale a phone can read ---------- */
.doc-head{border-left-width:5px;padding-left:14px;margin-bottom:18px}
.doc-head .eyebrow{font-size:.7rem}
.doc-head .author{position:static;display:block;font-size:.8rem;margin-bottom:2px}
.doc-head h1{font-size:2.1rem;margin-top:2px}
.doc-head .subtitle{font-size:.95rem}
.doc-head .desc{font-size:.92rem;line-height:1.6}
h2.sec{font-size:1.32rem;margin:30px 0 11px;scroll-margin-top:72px}
h2.sec .num{min-width:38px;height:28px;font-size:.95rem;margin-right:11px}
h3{font-size:1.05rem;margin:19px 0 7px}
h4{font-size:.95rem}
p, li, td, th, .def, .flow, .summary{font-size:1rem}
.def{font-size:1.04rem;margin-bottom:11px}
.label{font-size:.72rem}
.small-note{font-size:.9rem}
table{font-size:.95rem;line-height:1.48}
th,td{padding:7px 9px}
.box{padding:10px 14px 12px;margin:13px 0;border-radius:8px}
ul{padding-left:20px}
ul li::before{top:.66em}
figure.fig figcaption{font-size:.87rem}
.ico{width:13px !important}

/* the chapter's own contents list */
ol.toc{font-size:.97rem;margin-bottom:18px}
ol.toc li{padding:5px 0}
ol.toc .n{width:20px;margin-right:9px}
ol.toc .pg{display:none}            /* page numbers mean nothing here */
ol.toc a{color:inherit;text-decoration:none}
ol.toc a:hover .t{color:var(--teal-dark);text-decoration:underline}

/* ---------- what changes on a narrow screen ---------- */
@media (max-width:820px){
  .rd-body{padding:20px 18px 24px;border-radius:14px;margin:12px 0 18px}
  .doc-head h1{font-size:1.75rem}
  ol.toc{columns:1}
}
@media (max-width:760px){
  /* two columns side by side need 760px to be worth reading; below that the
     block simply runs on as one column, in the order it was written */
  .grid2{column-count:1}
  .grid2 > div + div{margin-top:4px}
}
@media (max-width:560px){
  :root{--step:1.02rem}
  .rd-wrap{padding-left:max(12px,env(safe-area-inset-left,0px));
           padding-right:max(12px,env(safe-area-inset-right,0px))}
  .rd-body{padding:17px 14px 20px;border-radius:12px}
  .doc-head h1{font-size:1.55rem}
  h2.sec{font-size:1.18rem}
  table.kv td:first-child{width:38%}
  th,td{padding:6px 7px}
  .box{padding:9px 11px 11px}
}

/* ---- tables ------------------------------------------------------------
   A table is laid out to be read across, so on a phone it has to scroll —
   but it must SAY so, or the reader thinks the page is stuck. The hint is
   a bar in the normal flow under the table. It is NOT an absolutely
   positioned overlay: .grid2 is a CSS multi-column container, and a
   positioned box inside a multi-column flow is painted in the wrong
   fragment by WebKit, which is what made tables escape the page and print
   over the footer on an iPad.

   From 768px up nothing scrolls at all: a block holding a table drops to
   one column so the table gets the full width of the page, the minimum
   width is released, and if it still will not fit the type steps down. */
.tablewrap{overflow-x:auto;-webkit-overflow-scrolling:touch;margin:4px 0 12px}
.tablewrap > table{margin:0;min-width:clamp(0px, 100%, 520px)}
.tablewrap table{min-width:420px}

.tw-hint{display:none;align-items:center;justify-content:center;gap:8px;
  margin:-8px 0 12px;padding:5px 10px;border-radius:999px;
  background:var(--accent-soft);color:var(--accent);
  font:600 .72rem/1 var(--ui);letter-spacing:.04em;text-transform:uppercase}
.tw-hint.on{display:flex}
.tw-hint svg{width:13px;height:13px;fill:none;stroke:currentColor;stroke-width:2.4;
  stroke-linecap:round;stroke-linejoin:round;animation:twnudge 1.6s ease-in-out infinite}
@keyframes twnudge{0%,100%{transform:translateX(-2px)}50%{transform:translateX(2px)}}
@media (prefers-reduced-motion:reduce){.tw-hint svg{animation:none}}

@media (min-width:768px){
  /* a tablet and up: everything fits, nothing slides */
  .grid2.has-table{column-count:1}
  .tablewrap{overflow-x:visible}
  .tablewrap table,.tablewrap > table{min-width:0}
  .tw-hint{display:none!important}
  .tablewrap.fit1 table{font-size:.93em}
  .tablewrap.fit2 table{font-size:.86em}
  .tablewrap.fit3 table{font-size:.8em}
  .tablewrap.fit3 th,.tablewrap.fit3 td{padding-left:6px;padding-right:6px}
}
@media print{.tw-hint{display:none!important}}

/* ---------- foot of the chapter ---------- */
.rd-next{display:grid;gap:10px;margin:0 0 10px;font-family:var(--ui)}
@media (min-width:560px){.rd-next{grid-template-columns:1fr 1fr}}
.rd-next a{display:block;background:var(--surface);border:1px solid var(--rule);
  border-radius:13px;padding:13px 15px;text-decoration:none;color:inherit;
  transition:border-color .14s,transform .14s}
.rd-next a:hover{border-color:var(--teal);transform:translateY(-1px)}
.rd-next .dir{display:block;font-size:.68rem;font-weight:700;letter-spacing:.11em;
  text-transform:uppercase;color:var(--faint-ink);margin-bottom:3px}
.rd-next .nm{display:block;font-size:.97rem;font-weight:700;color:var(--teal-dark);
  letter-spacing:-.01em;line-height:1.3}
.rd-next a.to-prev{text-align:left}
.rd-next a.to-next{text-align:right}
.rd-foot{font-family:var(--ui);font-size:.82rem;color:var(--faint-ink);
  text-align:center;line-height:1.7;margin:0 0 6px}
.rd-foot a{color:var(--teal-dark)}

/* ---------- print from the browser: hand it back to the print sheet ---------- */
@media print{
  .rd-bar,.rd-next,.rd-foot{display:none !important}
  .rd-body{border:none;box-shadow:none;padding:0;margin:0;background:#fff}
  .rd-wrap{max-width:none;padding:0}
  .tablewrap{overflow:visible}
}

/* hidden must actually hide: the rules above set a display, which beats the
   browser's own [hidden] rule, so the chapter's next-chapter link and the
   pager arrows stayed on screen when the script had switched them off. */
.label[hidden],.doc-head[hidden],ol.toc[hidden],section.pg[hidden]{display:none}
.rd-next[hidden],.rd-pager[hidden],.rd-next a[hidden],.rd-pager a[hidden],
.rd-pager .to-prev[hidden],.rd-pager .to-next[hidden]{display:none}

@media (max-width:480px){
  /* smaller type means fewer tables need scrolling at all */
  .tablewrap table{font-size:.82rem;line-height:1.4}
  .tablewrap th,.tablewrap td{padding-left:7px;padding-right:7px}
  .tablewrap table.kv{min-width:0}
}

