/* IMPACT — reader-first PWA. Tuned for iPhone 12 (390 x 844 pt) in standalone mode. */
:root {
  --bg: #F6F3EC; --card: #FFFDF8; --ink: #1D1B18; --ink2: #5E594F; --ink3: #6F695D;
  --line: #E3DDD0; --accent: #0E6B62; --accent-soft: #DDEBE6;
  --hy: #9A5B0A; --hy-bg: #FAF0DA; --mn: #0E6B62; --mn-bg: #E2EFEB;
  --nt: #55606E; --nt-bg: #ECEBE6; --wr: #A3392B; --wr-bg: #F8E4DF;
  --gold: #8A6508; --gold-bg: #F3E6BF; --bar: rgba(246, 243, 236, .86);
  --m: 22px;                 /* the fixed reading margin */
  --fs: 17px; --lh: 1.56;
  --sans: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Helvetica Neue", system-ui, sans-serif;
  --serif: ui-serif, "New York", "Iowan Old Style", Georgia, serif;
  --st: env(safe-area-inset-top, 0px); --sb: env(safe-area-inset-bottom, 0px);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #101011; --card: #19191B; --ink: #E9E5DC; --ink2: #A9A498; --ink3: #948F84;
    --line: #2A2A2D; --accent: #6FCFC2; --accent-soft: #17302D;
    --hy: #E3B463; --hy-bg: #272013; --mn: #6FCFC2; --mn-bg: #14272A;
    --nt: #A3ACB8; --nt-bg: #1D1E21; --wr: #F0907F; --wr-bg: #2B1815;
    --gold: #E6C567; --gold-bg: #33290F; --bar: rgba(16, 16, 17, .84); --lh: 1.6;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #101011; --card: #19191B; --ink: #E9E5DC; --ink2: #A9A498; --ink3: #948F84;
  --line: #2A2A2D; --accent: #6FCFC2; --accent-soft: #17302D;
  --hy: #E3B463; --hy-bg: #272013; --mn: #6FCFC2; --mn-bg: #14272A;
  --nt: #A3ACB8; --nt-bg: #1D1E21; --wr: #F0907F; --wr-bg: #2B1815;
  --gold: #E6C567; --gold-bg: #33290F; --bar: rgba(16, 16, 17, .84); --lh: 1.6;
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; background: var(--bg); }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 16px/1.5 var(--sans); -webkit-font-smoothing: antialiased;
  touch-action: manipulation; overflow-x: hidden;
  min-height: 100vh; min-height: 100dvh;
}
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
a { color: inherit; text-decoration: none; }
svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }

.view { display: none; }
body[data-view="home"] #home, body[data-view="study"] #study, body[data-view="reader"] #reader { display: block; }

/* ------------------------------------------------------------ home + study */
#home, #study {
  max-width: 560px; margin: 0 auto;
  padding: calc(var(--st) + 26px) var(--m) calc(var(--sb) + 96px);
}
.brand { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.brand b { font: 600 13px/1 var(--sans); letter-spacing: .32em; color: var(--accent); }
.brand small { display: block; margin-top: 8px; font-size: 13px; line-height: 1.4; color: var(--ink3); max-width: 230px; }
.brand button { width: 40px; height: 40px; margin: -10px -8px 0 0; border-radius: 50%; color: var(--ink2); font: 500 16px var(--serif); }
.hello { margin: 30px 0 22px; }
.hello span { font-size: 13px; color: var(--ink3); letter-spacing: .02em; }
.hello h1 { margin: 6px 0 0; font: 600 32px/1.12 var(--serif); letter-spacing: -.015em; }

.card { display: block; background: var(--card); border: 1px solid var(--line); border-radius: 20px; padding: 20px; }
.card + .card, .grid + .card, .card + .grid { margin-top: 12px; }
.eyebrow { font: 600 11px/1 var(--sans); letter-spacing: .1em; text-transform: uppercase; color: var(--ink3); }
.cont { background: var(--ink); color: var(--bg); border-color: transparent; position: relative; }
.cont .eyebrow { color: color-mix(in srgb, var(--bg) 62%, transparent); }
.cont h2 { margin: 14px 0 4px; font: 600 26px/1.15 var(--serif); letter-spacing: -.01em; }
.cont p { margin: 0; font-size: 15px; line-height: 1.4; color: color-mix(in srgb, var(--bg) 74%, transparent);
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.cont .track { margin: 20px 0 10px; background: color-mix(in srgb, var(--bg) 20%, transparent); }
.cont .track i { background: var(--bg); }
.cont .meta { display: flex; justify-content: space-between; font-size: 13px; color: color-mix(in srgb, var(--bg) 66%, transparent); }
.track { height: 3px; border-radius: 3px; background: var(--line); overflow: hidden; }
.track i { display: block; height: 100%; width: 0; border-radius: 3px; background: var(--accent); }

.grid .card { margin-top: 0; }
.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.stat .num { margin: 14px 0 2px; font: 600 40px/1 var(--serif); letter-spacing: -.015em; font-variant-numeric: tabular-nums; }
.stat .cap { font-size: 13px; color: var(--ink2); }
.dots { display: flex; gap: 5px; margin-top: 14px; }
.dots i { flex: 1; height: 4px; border-radius: 4px; background: var(--line); }
.dots i.on { background: var(--accent); }
.today h3 { margin: 12px 0 0; font: 600 19px/1.3 var(--serif); }
.today p { margin: 6px 0 0; font-size: 15px; line-height: 1.5; color: var(--ink2); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 16px; }
.chips a { padding: 9px 14px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); font-size: 15px; font-weight: 600; }

.sec { display: flex; align-items: baseline; justify-content: space-between; margin: 34px 2px 14px; }
.sec h2 { margin: 0; font: 600 21px/1.2 var(--serif); }
.sec span { font-size: 13px; color: var(--ink3); font-variant-numeric: tabular-nums; }
.mini { display: block; padding: 11px 2px; }
.mini div { display: flex; justify-content: space-between; font-size: 15px; margin-bottom: 8px; }
.mini div span { color: var(--ink3); font-size: 13px; font-variant-numeric: tabular-nums; }
.foot { margin: 40px 0 0; text-align: center; font-size: 13px; line-height: 1.6; color: var(--ink3); }

#study h1 { margin: 0 0 6px; font: 600 32px/1.1 var(--serif); letter-spacing: -.015em; }
#study .lede { margin: 0 0 22px; font-size: 15px; color: var(--ink2); }
.subj { display: grid; grid-template-columns: 26px 1fr auto; align-items: center; gap: 12px;
  padding: 17px 0; border-top: 1px solid var(--line); }
.subj:last-of-type { border-bottom: 1px solid var(--line); }
.subj > i { font: 500 13px var(--serif); font-style: normal; color: var(--ink3); font-variant-numeric: tabular-nums; }
.subj h3 { margin: 0; font: 600 19px/1.25 var(--serif); }
.subj p { margin: 3px 0 9px; font-size: 13px; color: var(--ink3); }
.dl { width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center; color: var(--ink3);
  font: 600 11px var(--sans); font-variant-numeric: tabular-nums; }
.dl svg { width: 21px; height: 21px; }
.dl.done { color: var(--accent); }
.dl.busy { color: var(--accent); background: var(--accent-soft); }

/* ------------------------------------------------------------ tab bar */
#tabs { position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; display: flex; justify-content: center; gap: 56px;
  padding: 9px 0 calc(var(--sb) + 7px); background: var(--bar);
  -webkit-backdrop-filter: saturate(160%) blur(18px); backdrop-filter: saturate(160%) blur(18px);
  border-top: 1px solid var(--line); }
#tabs a { display: flex; flex-direction: column; align-items: center; gap: 3px; width: 76px; color: var(--ink3);
  font-size: 11px; font-weight: 600; letter-spacing: .02em; }
#tabs a.on { color: var(--accent); }
body[data-view="reader"] #tabs, body[data-view="boot"] #tabs { display: none; }

/* ------------------------------------------------------------ reader chrome */
#bar { position: fixed; top: 0; left: 0; right: 0; z-index: 20; display: none; align-items: center; gap: 2px;
  height: calc(var(--st) + 52px); padding: var(--st) 6px 0; background: var(--bar);
  -webkit-backdrop-filter: saturate(160%) blur(18px); backdrop-filter: saturate(160%) blur(18px);
  border-bottom: 1px solid var(--line); transition: transform .26s cubic-bezier(.3, .7, .2, 1); }
body[data-view="reader"] #bar { display: flex; }
body.immersive #bar { transform: translateY(-101%); }
.ib { width: 44px; height: 44px; display: grid; place-items: center; border-radius: 50%; color: var(--ink2); flex: none; }
.ib:active { background: var(--line); }
.aa { font: 500 17px var(--serif); }
.bt { flex: 1; min-width: 0; text-align: center; line-height: 1.2; }
.bt b { display: block; font: 600 15px var(--sans); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bt span { font-size: 13px; color: var(--ink3); font-variant-numeric: tabular-nums; }
#progress { position: fixed; top: var(--st); left: 0; right: 0; height: 2px; z-index: 21; display: none; pointer-events: none; }
body[data-view="reader"] #progress { display: block; }
#progress i { display: block; height: 100%; width: 0; background: var(--accent); }

/* ------------------------------------------------------------ the reading column */
#flow {
  max-width: 640px; margin: 0 auto;
  padding: calc(var(--st) + 52px) var(--m) calc(var(--sb) + 80px);
  font-size: var(--fs); line-height: var(--lh); overflow-wrap: break-word; hyphens: manual; text-wrap: pretty;
}
.pg { padding-top: 6px; }
.pg::before { content: "p. " attr(data-label); display: flex; align-items: center; gap: 14px; margin: 34px 0 22px;
  font: 600 11px/1 var(--sans); letter-spacing: .1em; text-transform: uppercase; color: var(--ink3); }
.pg::after { content: ""; display: block; }
.pg::before { background: linear-gradient(var(--line), var(--line)) right center / calc(100% - 62px) 1px no-repeat; }
.pg > *:first-child { margin-top: 0; }

#flow h2 { margin: 1.9em 0 .55em; font: 600 1.56em/1.18 var(--serif); letter-spacing: -.015em; }
#flow h3 { margin: 1.7em 0 .5em; font: 600 1.24em/1.25 var(--serif); letter-spacing: -.01em; }
#flow h4 { margin: 1.5em 0 .4em; font: 600 .82em/1.3 var(--sans); letter-spacing: .1em; text-transform: uppercase; color: var(--accent); }
#flow p { margin: .75em 0; }
#flow p.lead { margin: 1.35em 0 .5em; font-weight: 600; }
#flow strong { font-weight: 600; }
#flow code { font: .86em ui-monospace, Menlo, monospace; padding: .1em .35em; border-radius: 5px; background: var(--nt-bg); }
#flow mark { background: var(--gold-bg); color: inherit; padding: 0 .15em; border-radius: 3px; }
#flow ul, #flow ol { margin: .7em 0; padding-left: 1.05em; }
#flow li { margin: .42em 0; padding-left: .15em; }
#flow li::marker { color: var(--ink3); font-size: .9em; }
#flow li > ul, #flow li > ol { margin: .3em 0 .1em; }
#flow li li { font-size: .96em; color: color-mix(in srgb, var(--ink) 88%, var(--bg)); }
#flow blockquote { margin: 1em 0; padding: 12px 16px; border-radius: 12px; background: var(--nt-bg); color: var(--ink2); }

i.q, i.gold { font: 700 11px/1 var(--sans); font-style: normal; letter-spacing: .1em; text-transform: uppercase;
  display: inline-block; vertical-align: .16em; border-radius: 5px; white-space: nowrap; }
i.q { padding: .32em .42em; color: var(--wr); background: var(--wr-bg); }
i.gold { padding: .36em .6em; color: var(--gold); background: var(--gold-bg); }
h2 i.gold, h3 i.gold, h4 i.gold { vertical-align: .35em; margin-left: 4px; }
p.tag { margin: .2em 0 .6em; }

/* callouts */
.co { margin: 1.25em 0; padding: 15px 16px 14px; border-radius: 14px; background: var(--nt-bg); font-size: .94em; line-height: 1.56; }
.co .ct { font: 700 11px/1.3 var(--sans); letter-spacing: .1em; text-transform: uppercase; color: var(--nt); margin-bottom: 8px; }
.co .ct strong { font-weight: 700; }
.co > :last-child { margin-bottom: 0 !important; }
.co > .ct + * { margin-top: 0 !important; }
.co p { margin: .5em 0 !important; }
.co.hy { background: var(--hy-bg); } .co.hy .ct { color: var(--hy); }
.co.mn { background: var(--mn-bg); } .co.mn .ct { color: var(--mn); }
.co.wr { background: var(--wr-bg); } .co.wr .ct { color: var(--wr); }
.co .tw { background: transparent; }

/* tables: never break the margin, scroll sideways inside their own frame */
.tw { margin: 1.15em 0; border: 1px solid var(--line); border-radius: 12px; background: var(--card);
  overflow-x: auto; -webkit-overflow-scrolling: touch; overscroll-behavior-x: contain; }
/* a soft edge shadow shows when a table has more to the side */
.tw { background:
    linear-gradient(to right, var(--card) 30%, transparent) left / 28px 100% no-repeat local,
    linear-gradient(to left, var(--card) 30%, transparent) right / 28px 100% no-repeat local,
    linear-gradient(to right, rgba(0, 0, 0, .16), transparent) left / 12px 100% no-repeat scroll,
    linear-gradient(to left, rgba(0, 0, 0, .16), transparent) right / 12px 100% no-repeat scroll,
    var(--card); }
.tw th { position: relative; }
.tw table { width: 100%; border-collapse: collapse; font-size: .82em; line-height: 1.42; }
.tw th, .tw td { padding: 9px 11px; text-align: left; vertical-align: top; border-bottom: 1px solid var(--line); }
.tw th + th, .tw td + td { border-left: 1px solid var(--line); }
.tw tr:last-child td { border-bottom: 0; }
.tw th { font: 700 .82em/1.3 var(--sans); letter-spacing: .1em; text-transform: uppercase; color: var(--ink2); background: color-mix(in srgb, var(--line) 42%, var(--card)); }
.tw td:first-child { font-weight: 600; }
.tw table.c2 td:first-child { width: 34%; }
.tw table.c3 { min-width: 430px; } .tw table.c4 { min-width: 540px; } .tw table.c5 { min-width: 640px; } .tw table.c6 { min-width: 760px; }

/* figures: one fixed margin, full column width */
#flow figure { margin: 1.35em 0; }
#flow figure img { display: block; width: 100%; height: auto; border-radius: 12px; background: #fff; }
#flow figure.sm img { width: min(100%, var(--w)); margin: 0 auto; }
#flow figcaption { margin-top: 9px; text-align: center; font-size: .78em; line-height: 1.4; color: var(--ink3); }
:root[data-theme="dark"] #flow figure img { filter: brightness(.9); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) #flow figure img { filter: brightness(.9); } }

.end { margin: 64px 0 20px; text-align: center; }
.end span { display: block; font: 600 11px var(--sans); letter-spacing: .1em; text-transform: uppercase; color: var(--ink3); }
.end a { display: inline-block; margin-top: 18px; padding: 14px 22px; border-radius: 999px; background: var(--ink); color: var(--bg); font-weight: 600; font-size: 15px; }
.skel { height: 60vh; display: grid; place-items: center; color: var(--ink3); font-size: 13px; letter-spacing: .1em; text-transform: uppercase; }

/* ------------------------------------------------------------ sheet + lightbox */
#scrim { position: fixed; inset: 0; z-index: 30; background: rgba(0, 0, 0, .38); }
#sheet { position: fixed; left: 0; right: 0; bottom: 0; z-index: 31; max-height: 76vh; display: flex; flex-direction: column;
  background: var(--card); border-radius: 22px 22px 0 0; padding-bottom: var(--sb); box-shadow: 0 -10px 40px rgba(0, 0, 0, .18);
  animation: up .26s cubic-bezier(.3, .7, .2, 1); }
@keyframes up { from { transform: translateY(100%); } }
.grab { width: 38px; height: 4px; border-radius: 4px; background: var(--line); margin: 10px auto 4px; flex: none; }
#sheet-body { overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; padding: 8px var(--m) 18px; }
#sheet h2 { margin: 8px 0 12px; font: 600 21px var(--serif); }
.toc button { display: block; width: 100%; text-align: left; padding: 12px 0; border-top: 1px solid var(--line); font: 600 16px/1.3 var(--serif); }
.toc button.l3 { padding: 9px 0 9px 16px; border-top: 0; font: 400 15px/1.35 var(--sans); color: var(--ink2); }
.toc button.on { color: var(--accent); }
.toc button small { float: right; margin-left: 12px; font: 400 13px var(--sans); color: var(--ink3); font-variant-numeric: tabular-nums; }
.row { display: flex; align-items: center; justify-content: space-between; padding: 14px 0; border-top: 1px solid var(--line); font-size: 15px; }
.seg { display: flex; padding: 3px; border-radius: 11px; background: var(--nt-bg); }
.seg button { padding: 8px 14px; border-radius: 8px; font-size: 15px; font-weight: 600; color: var(--ink2); min-width: 48px; }
.seg button.on { background: var(--card); color: var(--ink); box-shadow: 0 1px 3px rgba(0, 0, 0, .12); }
.seg button:disabled { opacity: .35; }

#lb { position: fixed; inset: 0; z-index: 40; background: #000; }
#lb-scroll { position: absolute; inset: 0; overflow: auto; -webkit-overflow-scrolling: touch; display: grid; place-items: center; }
#lb-img { display: block; width: 100%; height: auto; background: #fff; }
#lb.zoom #lb-scroll { place-items: start; }
#lb.zoom #lb-img { width: 260%; max-width: none; }
#lb-close { position: absolute; top: calc(var(--st) + 10px); right: 12px; width: 44px; height: 44px; border-radius: 50%;
  display: grid; place-items: center; background: rgba(40, 40, 40, .72); color: #fff; }
#lb-hint { position: absolute; left: 0; right: 0; bottom: calc(var(--sb) + 18px); text-align: center; font-size: 13px;
  letter-spacing: .1em; text-transform: uppercase; color: rgba(255, 255, 255, .55); pointer-events: none; }
[hidden] { display: none !important; }

@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }

/* ------------------------------------------------------------ type details */
h1, h2, h3, #flow h4, .cont h2, .today h3 { text-wrap: balance; }
.tw td, .tw th { hyphens: auto; -webkit-hyphens: auto; font-variant-numeric: tabular-nums; }
#flow, #home, #study { font-kerning: normal; font-variant-ligatures: common-ligatures; }
::selection { background: var(--accent-soft); color: var(--ink); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; border-radius: 6px; }
.today .when, .stat .cap { font-size: 13px; color: var(--ink2); }
.today .when { margin: 0 0 4px; color: var(--ink3); }
.today h3 { margin-top: 0; }
.cont h2 { margin-top: 0; }
.stat .num { margin-top: 0; }
