/* Upside Down Garry — whitepaper docs (/docs/)
   Layout: a navy sidebar (search, collapsible groups, play button), the reading column on cream
   case-file paper, and an "On this page" index on wide screens. Loaded after garry.css. */
body.docs { background: var(--cream); color: var(--ink); font-size: 17px; }
body.docs::before { content: ''; position: fixed; inset: 0; z-index: -1; pointer-events: none;
  background: radial-gradient(circle at 1px 1px, rgba(26,20,16,.06) 1.2px, transparent 1.6px) 0 0 / 10px 10px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.ic { width: 18px; height: 18px; flex: none; }

.dlayout { display: grid; grid-template-columns: 290px minmax(0, 1fr); min-height: 100vh; }

/* ---------- sidebar ---------- */
.side { position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: 14px; padding: 20px 16px 16px;
  background: linear-gradient(170deg, #17246a 0%, #2a3a9a 45%, #5a3aa6 100%); color: var(--cream); border-right: 4px solid var(--ink); overflow: hidden; }
.side-brand { display: inline-flex; align-items: center; gap: 10px; text-decoration: none; color: var(--cream); }
.side-brand .trio img:nth-child(1), .side-brand .trio img:nth-child(3) { width: 24px; height: 24px; }
.side-brand .trio img:nth-child(2) { width: 32px; height: 32px; }
.side-brand .trio img.mark { width: 38px; height: 38px; margin: 0; }
.side-name { font-family: var(--display); font-size: 22px; text-transform: uppercase; text-shadow: 2px 2px 0 var(--ink); line-height: 1; }
.side-name small { font-family: var(--type); font-size: 13px; letter-spacing: .14em; color: var(--gold); text-shadow: none; margin-left: 4px; vertical-align: 2px; }

.search { position: relative; display: flex; align-items: center; gap: 8px; padding: 0 10px; height: 42px; background: rgba(11,20,40,.55); border: 2px solid rgba(245,234,210,.25); border-radius: 12px; }
.search:focus-within { border-color: var(--gold); }
.search input { flex: 1; min-width: 0; background: none; border: 0; outline: none; color: var(--cream); font: 600 15px var(--body); }
.search input::placeholder { color: rgba(245,234,210,.6); }
.search input::-webkit-search-cancel-button { filter: invert(1); }
.search kbd { font-family: var(--type); font-size: 12px; color: rgba(245,234,210,.7); border: 1px solid rgba(245,234,210,.35); border-radius: 5px; padding: 0 6px; }
.results { position: absolute; z-index: 20; left: 0; right: 0; top: calc(100% + 6px); max-height: 60vh; overflow-y: auto; background: var(--cream); color: var(--ink); border: 3px solid var(--ink); border-radius: 12px; box-shadow: 0 8px 0 rgba(11,20,40,.6); padding: 6px; }
.results a { display: grid; gap: 2px; padding: 8px 10px; border-radius: 8px; text-decoration: none; color: var(--ink); }
.results a:hover, .results a.on { background: #fff3b8; }
.results b { font-family: var(--display); font-weight: 400; font-size: 14px; text-transform: uppercase; color: var(--navy); }
.results span { font-size: 13px; color: var(--ink-2); line-height: 1.4; }
.results mark { background: var(--gold); color: var(--ink); border-radius: 3px; padding: 0 2px; }
.results p { padding: 10px; font-size: 14px; color: var(--ink-3); }

.groups { flex: 1; overflow-y: auto; margin: 0 -6px; padding: 0 6px; }
.grp { border-radius: 10px; }
.grp summary { list-style: none; display: flex; align-items: center; gap: 10px; padding: 10px 8px; cursor: pointer; font-weight: 700; font-size: 15px; color: var(--cream); border-radius: 10px; }
.grp summary::-webkit-details-marker { display: none; }
.grp summary:hover { background: rgba(255,255,255,.08); }
.grp summary .ic { color: var(--gold); }
.chev { width: 16px; height: 16px; margin-left: auto; transition: transform .2s; opacity: .7; }
.grp[open] .chev { transform: rotate(90deg); }
.grp-links { display: grid; gap: 2px; margin: 0 0 8px 17px; padding-left: 14px; border-left: 2px solid rgba(245,234,210,.22); }
.grp-links a { display: block; padding: 7px 10px; border-radius: 8px; color: rgba(245,234,210,.85); text-decoration: none; font-size: 15px; }
.grp-links a:hover { color: var(--cream); background: rgba(255,255,255,.08); }
.grp-links a[aria-current="page"] { color: var(--ink); background: var(--gold); font-weight: 700; box-shadow: 0 3px 0 var(--ink); }
.side-foot { display: grid; gap: 10px; padding-top: 12px; border-top: 2px solid rgba(245,234,210,.18); }
.side-play { width: 100%; }
.side-back { display: inline-flex; align-items: center; gap: 8px; justify-content: center; color: var(--cream-2); text-decoration: none; font-weight: 700; font-size: 14px; }
.side-back:hover { color: var(--gold); }
.side-back .ic { width: 16px; height: 16px; }

/* ---------- reading column ---------- */
.dmain { display: grid; grid-template-columns: minmax(0, 760px) 220px; gap: 56px; justify-content: center; padding: 48px max(28px, env(safe-area-inset-right, 0px)) 80px max(28px, env(safe-area-inset-left, 0px)); }
.doc { min-width: 0; }
.crumbs { font-family: var(--type); font-size: 14px; color: var(--ink-3); margin-bottom: 10px; }
.crumbs a { color: var(--siren); text-decoration: none; }
.doc h1 { font-family: var(--display); font-size: clamp(34px, 4.6vw, 54px); line-height: 1.02; text-transform: uppercase; color: var(--navy); text-shadow: 3px 3px 0 var(--gold), 6px 6px 0 var(--ink); margin-bottom: 18px; }
.lead { font-size: 19.5px; color: var(--ink-2); margin-bottom: 30px; max-width: 62ch; }
.doc h2 { position: relative; font-family: var(--display); font-size: clamp(22px, 2.4vw, 28px); text-transform: uppercase; color: var(--navy); margin: 44px 0 16px; padding-bottom: 10px; scroll-margin-top: 24px; }
.doc h2::after { content: ''; position: absolute; left: 0; bottom: 0; width: 64px; height: 5px; border-radius: 3px; background: var(--gold); box-shadow: 2px 2px 0 var(--ink); }
.anchor { position: absolute; left: -28px; top: 0; color: var(--cream-3); text-decoration: none; opacity: 0; transition: opacity .2s; font-family: var(--body); }
.doc h2:hover .anchor, .anchor:focus { opacity: 1; }
.doc p { margin: 0 0 14px; max-width: 68ch; }
.doc p.aside-note { font-family: var(--type); color: var(--ink-3); }
.doc a { color: #2a5591; font-weight: 700; text-decoration-thickness: 2px; text-underline-offset: 3px; }
.doc a:hover { color: var(--siren); }
.doc strong { color: var(--ink); }
.doc code { font-family: var(--type); background: #fff3b8; border: 1px solid var(--cream-3); border-radius: 5px; padding: 0 5px; }
.doc hr { border: 0; border-top: 2px dashed var(--cream-3); margin: 30px 0; }
.doc .leaf { margin: 6px 0 18px; }
.doc .leaf li { max-width: 66ch; }
.doc ol.steps { list-style: none; counter-reset: s; padding: 0; margin: 8px 0 20px; display: grid; gap: 12px; }
.doc ol.steps li { counter-increment: s; position: relative; padding-left: 46px; max-width: 66ch; }
.doc ol.steps li::before { content: counter(s); position: absolute; left: 0; top: -2px; width: 32px; height: 32px; display: grid; place-items: center; border-radius: 50%; background: var(--gold); border: 3px solid var(--ink); font-family: var(--display); font-size: 15px; box-shadow: 0 3px 0 var(--ink); }

.table-wrap { overflow-x: auto; margin: 10px 0 24px; background: #fbf4e3; border: 3px solid var(--ink); border-radius: 14px; box-shadow: 6px 7px 0 var(--ink); }
.doc table { width: 100%; border-collapse: collapse; font-size: 15px; min-width: 440px; font-variant-numeric: tabular-nums; }
.doc thead th { text-align: left; padding: 11px 14px; background: var(--cream-2); border-bottom: 3px solid var(--ink); font-family: var(--type); font-weight: 400; font-size: 13.5px; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-2); white-space: nowrap; }
.doc tbody th, .doc tbody td { padding: 10px 14px; border-top: 2px dashed var(--cream-3); text-align: left; vertical-align: top; }
.doc tbody th { font-weight: 700; color: var(--navy); }
.doc tbody tr:first-child th, .doc tbody tr:first-child td { border-top: 0; }
.doc tbody tr:hover { background: #fff7e0; }

.callout { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 12px; margin: 18px 0 24px; padding: 16px 18px; background: #fff3b8; border: 3px solid var(--ink); border-left-width: 8px; border-radius: 12px; box-shadow: 5px 6px 0 var(--ink); }
.callout .ic { width: 22px; height: 22px; color: var(--ink); margin-top: 2px; }
.callout b { display: block; font-family: var(--display); font-weight: 400; text-transform: uppercase; font-size: 15px; color: var(--navy); margin-bottom: 4px; }
.callout p { margin: 0; }
.callout.tip { background: #e5f6d4; }
.callout.tip .ic { color: var(--catnip-deep); }
.soon { display: inline-block; font-family: var(--type); font-size: 13.5px; padding: 1px 10px; border: 2px dashed var(--ink-3); border-radius: 6px; color: var(--ink-2); }

/* welcome page */
.parts { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; margin: 6px 0 24px; }
.part { display: grid; gap: 6px; padding: 16px; background: #fbf4e3; border: 3px solid var(--ink); border-top: 8px solid var(--pc); border-radius: 12px; box-shadow: 5px 6px 0 var(--ink); text-decoration: none; color: var(--ink) !important; font-weight: 400 !important; transition: transform .25s cubic-bezier(.2,1.4,.4,1); }
.part:hover { transform: translateY(-5px); }
.part b { font-family: var(--display); font-weight: 400; font-size: 19px; text-transform: uppercase; color: var(--navy); }
.part span { font-size: 15px; color: var(--ink-2); }
.qgrid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.qcard { position: relative; display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 4px 12px; padding: 16px 40px 16px 16px; background: #fbf4e3; border: 3px solid var(--ink); border-radius: 12px; box-shadow: 4px 5px 0 var(--ink); text-decoration: none; color: var(--ink) !important; font-weight: 400 !important; transition: transform .25s cubic-bezier(.2,1.4,.4,1), box-shadow .25s; }
.qcard:hover { transform: translateY(-4px); box-shadow: 6px 9px 0 var(--ink); }
.qi { grid-row: 1 / 3; display: grid; place-items: center; width: 40px; height: 40px; border-radius: 10px; background: var(--navy); color: var(--gold); border: 2px solid var(--ink); }
.qcard b { font-family: var(--display); font-weight: 400; font-size: 16px; text-transform: uppercase; color: var(--navy); }
.qcard > span:not(.qi) { font-size: 14px; color: var(--ink-2); line-height: 1.4; }
.qa { position: absolute; right: 14px; top: 50%; width: 18px; height: 18px; margin-top: -9px; color: var(--ink-3); transition: transform .2s, color .2s; }
.qcard:hover .qa { transform: translateX(4px); color: var(--siren); }

/* foot + pager */
.doc-foot { margin-top: 48px; padding-top: 18px; border-top: 2px dashed var(--cream-3); font-size: 14.5px; color: var(--ink-3); }
.doc-foot p { margin: 0 0 6px; }
.ver { display: inline-block; margin-right: 8px; font-family: var(--type); font-size: 12.5px; padding: 1px 8px; border-radius: 6px; background: var(--navy); color: var(--gold); }
.pager { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-top: 26px; }
.pg { display: grid; gap: 2px; padding: 14px 18px; background: #fbf4e3; border: 3px solid var(--ink); border-radius: 12px; box-shadow: 4px 5px 0 var(--ink); text-decoration: none; color: var(--ink) !important; transition: transform .2s; }
.pg:hover { transform: translateY(-3px); }
.pg small { font-family: var(--type); font-size: 13px; color: var(--ink-3); font-weight: 400; }
.pg b { font-family: var(--display); font-weight: 400; font-size: 17px; text-transform: uppercase; color: var(--navy); }
.pg.next { text-align: right; grid-column: 2; }

/* on this page */
.toc { position: sticky; top: 40px; align-self: start; padding-top: 70px; }
.toc p { font-family: var(--type); font-size: 13px; letter-spacing: .12em; text-transform: uppercase; color: var(--siren); margin-bottom: 10px; }
.toc ul { list-style: none; margin: 0; padding: 0; border-left: 2px solid var(--cream-3); }
.toc a { display: block; padding: 5px 0 5px 14px; margin-left: -2px; border-left: 3px solid transparent; color: var(--ink-2); text-decoration: none; font-size: 14px; line-height: 1.35; }
.toc a:hover { color: var(--ink); }
.toc a.on { color: var(--navy); font-weight: 700; border-left-color: var(--gold); }

/* reveal on scroll (only with JS) */
.dfx .doc > h2, .dfx .doc > .table-wrap, .dfx .doc > .callout, .dfx .doc > .parts, .dfx .doc > .qgrid { opacity: 0; transform: translateY(18px); transition: opacity .6s ease, transform .7s cubic-bezier(.2,1.2,.4,1); }
.dfx .doc > .in { opacity: 1; transform: none; }

/* mobile top bar + drawer */
.dtop { display: none; }
.scrim { position: fixed; inset: 0; z-index: 55; background: rgba(11,20,40,.55); }
@media (max-width: 1180px) {
  .dmain { grid-template-columns: minmax(0, 760px); }
  .toc { display: none; }
}
@media (max-width: 900px) {
  .dlayout { grid-template-columns: minmax(0, 1fr); }
  .dtop { position: sticky; top: 0; z-index: 50; display: flex; align-items: center; gap: 12px; padding: calc(8px + env(safe-area-inset-top, 0px)) max(16px, env(safe-area-inset-right, 0px)) 8px max(16px, env(safe-area-inset-left, 0px));
    background: #17246a; border-bottom: 4px solid var(--ink); }
  .dtop .side-name { font-size: 19px; }
  .dtop-menu { width: 42px; height: 40px; display: grid; place-items: center; border: 3px solid var(--ink); border-radius: 10px; background: var(--cream); color: var(--ink); box-shadow: 0 3px 0 var(--ink); cursor: pointer; }
  .dtop-play { margin-left: auto; min-height: 40px; padding: 0 16px; font-size: 13px; }
  .side { position: fixed; z-index: 60; left: 0; top: 0; bottom: 0; width: min(310px, 86vw); height: auto; transform: translateX(-104%); transition: transform .3s cubic-bezier(.2,1,.3,1); padding-top: calc(20px + env(safe-area-inset-top, 0px)); }
  .side.open { transform: none; box-shadow: 10px 0 0 rgba(11,20,40,.35); }
  .dmain { padding: 28px max(18px, env(safe-area-inset-right, 0px)) 64px max(18px, env(safe-area-inset-left, 0px)); }
  .anchor { display: none; }
}
@media (max-width: 640px) {
  body.docs { font-size: 16px; }
  .lead { font-size: 17.5px; }
  .parts, .qgrid { grid-template-columns: minmax(0, 1fr); }
  .pager { grid-template-columns: minmax(0, 1fr); }
  .pg.next { grid-column: auto; }
}
@media (prefers-reduced-motion: reduce) {
  .dfx .doc > * { opacity: 1 !important; transform: none !important; }
}
