/* The practice drawer on chapter pages (js/drawer.js). Choice and solution styles come from engine/book.css
   (.practice, .choices, .why, .eq). */
.sheet .practice { display: none; }            /* the open repo's in-page questions: practice lives in the drawer */
:root { --pd-w: 440px; }

.pd-open {
  position: fixed; right: 22px; bottom: calc(22px + env(safe-area-inset-bottom)); z-index: 6;
  border: 0; border-radius: 999px; padding: 13px 20px; background: var(--hi); color: #fff; cursor: pointer;
  font: 500 12px var(--mono); letter-spacing: .08em; text-transform: uppercase; box-shadow: 0 6px 20px #0000002e;
}
.pd-open:hover { background: var(--lit); }
html.pd-on .pd-open { display: none; }
/* the figure's readout sits above the button, not under it (phones place both themselves, below) */
@media (min-width: 901px) and (min-height: 521px) { .corner.br { bottom: 62px; } }

.pd {
  position: fixed; z-index: 20; top: 56px; right: 0; bottom: 0; width: min(var(--pd-w), 100vw); border-top-left-radius: 14px;
  display: flex; flex-direction: column; background: var(--card);
  box-shadow: -1px 0 0 #0000000f, -24px 0 48px -24px #00000033;
  transform: translateX(100%); visibility: hidden; transition: transform .35s cubic-bezier(.16,1,.3,1), visibility 0s .35s;
}
.pd.open { transform: none; visibility: visible; transition: transform .35s cubic-bezier(.16,1,.3,1); }
/* wide screens: the book moves over and narrows so the whole figure stays in view beside the drawer */
@media (min-width: 901px) and (min-height: 521px) {
  .book { transition: left .35s cubic-bezier(.16,1,.3,1), width .35s cubic-bezier(.16,1,.3,1); }
  html.pd-on .book { left: calc((100vw - var(--pd-w)) / 2); width: calc(100vw - var(--pd-w) - 40px); }
}
.pd-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; padding: 20px 24px 14px; border-bottom: 1px solid var(--faint); }
.pd-title { font: 400 24px/1.15 var(--serif); color: var(--strong); margin-top: 8px; }
.pd-x { width: 40px; height: 40px; flex: none; border: 0; border-radius: 50%; background: none; font: 300 28px/1 var(--sans); color: var(--hi); cursor: pointer; }
.pd-x:hover { background: #f0f0ec; }
.pd-body { --pd-pb: calc(28px + env(safe-area-inset-bottom)); flex: 1; overflow-y: auto; overscroll-behavior: contain; padding: 4px 24px var(--pd-pb); }
.pd .note { color: var(--muted); font-size: 14px; }
.pd .err { color: var(--red); font-size: 14px; min-height: 0; margin: 6px 0 0; }
.pd-pad { margin: 16px 0; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

.pd-btn { display: inline-flex; align-items: center; justify-content: center; border: 1px solid var(--hi); background: var(--hi); color: #fff;
  font: 500 12px var(--mono); letter-spacing: .04em; padding: 10px 16px; border-radius: 999px; cursor: pointer; text-decoration: none; }
.pd-btn:hover:not(:disabled) { background: var(--lit); }
.pd-btn.ghost { background: var(--card); color: var(--hi); border-color: var(--faint); }
.pd-btn.ghost:hover:not(:disabled) { border-color: var(--mid); background: var(--card); }
.pd-btn:disabled { opacity: .45; cursor: default; }
.pd-link { border: 0; background: none; padding: 0; font: 500 12px var(--mono); letter-spacing: .04em; color: var(--hi); cursor: pointer; text-decoration: underline; text-underline-offset: 3px; }

.pd-cta { margin: 18px 0; padding: 16px 18px; border-radius: 12px; background: var(--page); }
.pd-cta p { margin: 0 0 12px; color: var(--strong); }

.pd-sets { list-style: none; padding: 0; margin: 16px 0; display: grid; gap: 6px; }
.pd-sets button { width: 100%; display: grid; grid-template-columns: 64px 1fr auto; gap: 10px; align-items: baseline; padding: 11px 12px; text-align: left; cursor: pointer;
  border: 1px solid var(--faint); border-radius: 8px; background: var(--card); color: var(--text); font: 14px/1.35 var(--sans); }
.pd-sets button:hover { border-color: var(--mid); color: var(--strong); }
.pd-sets button.here { border-color: var(--hi); color: var(--strong); }
.pd-sets .pg { font: 12px var(--mono); color: var(--muted); }
.pd .tag { font: 500 10px var(--mono); letter-spacing: .06em; text-transform: uppercase; color: var(--muted); white-space: nowrap; }
.pd .tag.free { color: #2f8f5b; } .pd .tag.lock { color: var(--lo); } .pd .tag.done { color: var(--hi); }

/* a question */
.pd .practice { display: block; margin: 0; padding: 0; border: 0; max-width: none; }
.pd-q .qtext { margin: 18px 0 6px; color: var(--strong); font-size: 16px; }
.pd-hint { margin: 0 0 12px; font-size: 13px !important; }
.pd-num { margin: 12px 0 4px; }
.pd-num .row { margin-top: 8px; flex-wrap: nowrap; }
.pd-num input { flex: 1; min-width: 0; font: 17px var(--sans); padding: 10px 12px; border: 1px solid var(--faint); border-radius: 10px; background: var(--card); color: var(--strong); }
.pd-num input:focus { outline: 2px solid var(--hi); outline-offset: 1px; }
.pd-num .unit { font: 16px var(--serif); color: var(--hi); min-width: 2ch; }
.pd-ok, .pd-no { margin: 14px 0 6px; font-weight: 500; }
.pd-ok { color: #2f8f5b; } .pd-no { color: var(--red); }
.pd-slip { margin: 0 0 8px; padding: 8px 12px; border-left: 2px solid var(--red); background: #fcefef; border-radius: 0 8px 8px 0; color: var(--strong); }
.pd-step { margin: 14px 0; padding: 14px 16px; border-radius: 12px; background: var(--page); }
.pd-step p { margin: 8px 0; color: var(--strong); }
.pd-step .eq { font-size: 19px; margin: 8px 0 12px; }
.pd-step .row { margin-top: 10px; }
.pd .mark { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-top: 10px; }
/* a question: a column, so its way on sits at the foot of the drawer even when the question is short */
.pd-body:has(> .pd-nav) { display: flex; flex-direction: column; }
.pd-body:has(> .pd-nav) > * { flex-shrink: 0; }
.pd-body > .pd-nav { margin-top: auto; }
.pd-q { margin-bottom: 22px; }
/* a question's way on stays at the foot of the drawer; it covers the body's bottom padding so nothing shows beneath it */
.pd-nav { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; margin: 22px 0 0;
  position: sticky; bottom: calc(-1 * var(--pd-pb)); z-index: 1; padding: 12px 0 var(--pd-pb); margin-bottom: calc(-1 * var(--pd-pb)); background: var(--card); border-top: 1px solid var(--faint); }
.pd-paused { margin: 14px 0 0; padding: 10px 12px; border-radius: 8px; background: var(--page); font-size: 14px; color: var(--strong); }
.pd-paused .pd-link { display: block; margin-top: 6px; }

/* phones and tablets: a bottom sheet over the text half, so the figure above stays in view */
@media (max-width: 900px), (max-height: 520px) {
  :root { --pd-w: 100vw; }
  .pd-open { right: 14px; bottom: calc(14px + env(safe-area-inset-bottom)); }
  .pd { top: auto; left: 0; width: auto; height: min(50vh, 50dvh); border-radius: 16px 16px 0 0; transform: translateY(100%); box-shadow: 0 -12px 40px #00000026; }
  .pd-head { padding: 12px 16px 8px; }
  .pd-title { font-size: 19px; margin-top: 4px; }
  .pd-body { --pd-pb: calc(20px + env(safe-area-inset-bottom)); padding: 0 16px var(--pd-pb); }
  html.pd-on { overflow: hidden; }   /* answering doesn't turn the page */
  .pd-sets button { grid-template-columns: 1fr auto; } .pd-sets .pg { grid-column: 1 / -1; }
}
@media (prefers-reduced-motion: reduce) { .pd, .pd.open, .book { transition: none; } }

/* a question's marks on the figure (chapters/*/world.js setMarks) */
.lbl.qmark { font: 15px/1.1 var(--serif); color: var(--hi); transform: translate(0, -125%); background: #fbfbfacc; padding: 1px 4px; border-radius: 3px; }
.lbl.qmark.red { color: var(--red); }

/* the book's top bar carries the site's links: all on wide screens, fewer as it narrows */
.sitelinks { display: flex; gap: 18px; align-items: center; }
@media (max-width: 1240px) { .sitelinks .wide { display: none; } }
@media (max-width: 900px) { .sitelinks .mid { display: none; } }

/* math (KaTeX, chapters/engine/tex.js): displayed equations sit left in the book's .eq rule, sized to the text */
.eq .katex-display { margin: 0; text-align: left; }
.eq .katex-display > .katex { text-align: left; }
.eq .katex { font-size: 1em; }
.katex { font-size: 1em; color: var(--strong); }
.eq .katex-display > .katex { font-size: 1.12em; }   /* displayed equations a touch larger than in-text math */
.eq { overflow-x: auto; overflow-y: hidden; scrollbar-width: thin; }

/* follow-up questions to the tutor (Premium), under the question */
.pd-ask { margin: 18px 0 0; }
.pd-ask summary { display: inline-block; cursor: pointer; list-style: none; font: 500 12px var(--mono); letter-spacing: .04em; color: var(--hi); text-decoration: underline; text-underline-offset: 3px; }
.pd-ask summary::-webkit-details-marker { display: none; }
.pd-ask summary::before { content: '+ '; text-decoration: none; display: inline-block; width: 1.4ch; }
.pd-ask[open] summary::before { content: '− '; }
.pd-thread { display: grid; gap: 8px; margin: 10px 0; }
.pd-msg { padding: 10px 12px; border-radius: 12px; font-size: 15px; line-height: 1.45; color: var(--strong); overflow-wrap: anywhere; }
.pd-msg.me { justify-self: end; max-width: 85%; background: var(--hi); color: #fff; white-space: pre-wrap; border-bottom-right-radius: 4px; }
.pd-msg.ai { background: var(--page); border-bottom-left-radius: 4px; }
.pd-msg.ai p { margin: 0 0 8px; } .pd-msg.ai p:last-child { margin: 0; }
.pd-msg .katex-display { margin: 6px 0; overflow-x: auto; overflow-y: hidden; }
.pd-askf { display: flex; gap: 8px; align-items: flex-end; }
.pd-askf textarea { flex: 1; min-width: 0; resize: vertical; font: 15px/1.4 var(--sans); padding: 9px 12px; border: 1px solid var(--faint); border-radius: 10px; background: var(--card); color: var(--strong); }
.pd-askf textarea:focus { outline: 2px solid var(--hi); outline-offset: 1px; }
.pd-ask-note { margin: 6px 0 0; font-size: 12px !important; }
.pd .sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

/* phones and tablets upright: the pager and Practice in one bar at the foot of the screen, in thumb reach, with the book
   above it; the figure's hint a pill and its readout a strip on its bottom edge, clear of each other; the practice sheet
   starts where the figure ends, so the whole figure stays in view while answering */
@media (max-width: 900px) and (min-height: 521px) {
  :root { --dock: calc(68px + env(safe-area-inset-bottom)); --bookh: calc(100dvh - 68px - var(--dock)); --fig: .55; }
  .book { height: var(--bookh); top: calc(60px + var(--bookh) / 2); }
  .book-body::after { content: ''; position: fixed; inset: auto 0 0; height: var(--dock); z-index: 4; border-top: 1px solid var(--faint);
    background: color-mix(in srgb, var(--card) 92%, transparent); -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px); }
  .pager { position: fixed; z-index: 6; left: 14px; bottom: calc(10px + env(safe-area-inset-bottom)); width: 156px; height: 48px; margin: 0; padding: 2px;
    justify-content: space-between; gap: 0; border-radius: 999px; background: var(--page); }
  .pager button { width: 44px; height: 44px; }
  #pagenum { flex: 1; text-align: center; }
  .pd-open { left: calc(14px + 156px + 8px); right: 14px; bottom: calc(10px + env(safe-area-inset-bottom)); height: 48px; padding: 0; box-shadow: none; }
  .sitelinks { margin-left: auto; }
  .sitelinks a { padding: 7px 12px; border: 1px solid var(--faint); border-radius: 999px; background: var(--card); color: var(--hi); text-decoration: none; }

  .corner.bl { top: auto; bottom: 54px; left: 50%; transform: translateX(-50%); width: max-content; max-width: calc(100% - 28px); text-align: center;
    padding: 5px 10px; border-radius: 999px; background: #fbfbfae6; box-shadow: var(--lift); color: var(--hi); font-size: 10.5px; line-height: 1.35; }
  .corner.br { left: 0; right: 0; bottom: 0; padding: 6px 12px; text-align: center; font-size: 11px; line-height: 1.5;
    background: #fbfbfaee; border-top: 1px solid var(--faint); }
  .corner.bl:empty, .corner.br:empty { display: none; }

  .pd { top: calc(60px + var(--fig) * var(--bookh) + 6px); height: auto; }
}
@media (max-width: 599px) and (min-height: 521px) { :root { --fig: .42; } }

/* phones: the drawer's header on one line when it fits, a short call to action beside its button, and the sets as
   one list, each a title over its pages */
@media (max-width: 900px), (max-height: 520px) {
  .pd-head { align-items: center; padding: 8px 8px 8px 16px; }
  .pd-head > div { display: flex; flex-wrap: wrap; align-items: baseline; column-gap: 8px; min-width: 0; }
  .pd-title { margin-top: 0; font-size: 20px; }
  .pd-x { width: 44px; height: 44px; }
  .pd-cta:has(> p:only-of-type):has(> .pd-btn) { display: flex; align-items: center; gap: 12px; padding: 12px 12px 12px 14px; margin: 14px 0 10px; }
  .pd-cta:has(> p:only-of-type):has(> .pd-btn) p { flex: 1; margin: 0; font-size: 14px; line-height: 1.4; }
  .pd-cta:has(> p:only-of-type) .pd-btn { flex: none; white-space: nowrap; }
  .pd-sets { gap: 0; border: 1px solid var(--faint); border-radius: 12px; overflow: hidden; }
  .pd-sets li + li { border-top: 1px solid var(--faint); }
  .pd-sets button { grid-template-columns: 1fr auto; gap: 2px 12px; align-items: center; padding: 10px 14px; border: 0; border-radius: 0; }
  .pd-sets button.here { border: 0; box-shadow: inset 3px 0 0 var(--hi); }
  .pd-sets .t { grid-area: 1 / 1; }
  .pd-sets .tag { grid-area: 1 / 2; }
  .pd-sets .pg { grid-area: 2 / 1; font-size: 11px; }
}
