/* Apas Math — the one stylesheet of the site.
   Tokens first, then base elements, layout, components, pages.
   Playfair Display for headings, Inter for text, JetBrains Mono for labels. */

*, *::before, *::after { box-sizing: border-box; }

:root {
  --ink: #0d1117; --ink2: #24292f; --dim: #57606a; --dim2: #6e7781;
  --rule: #e3e8ee; --rule-dark: #d0d7de; --surface: #f7f9fc; --surface2: #eef2f7; --white: #ffffff;
  --blue: #2563eb; --blue-dark: #1d4ed8; --blue-dim: #eff6ff; --blue-ring: rgba(37, 99, 235, 0.28);
  --amber: #b45309; --amber-dim: #fffbeb; --green: #15803d; --green-dim: #f0fdf4; --red: #b3261e; --red-dim: #fef2f2;
  --radius-sm: 6px; --radius: 10px; --radius-lg: 16px;
  --shadow-sm: 0 1px 2px rgba(13, 17, 23, 0.05); --shadow: 0 4px 16px rgba(13, 17, 23, 0.07);
  --serif: 'Playfair Display', Georgia, 'Times New Roman', serif;
  --sans: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --mono: 'JetBrains Mono', ui-monospace, Menlo, Consolas, monospace;
  --page: 1120px; --reading: 760px; --gutter: clamp(1rem, 4vw, 2rem);
  /* the names the lesson renderer's stylesheet uses */
  --t1: var(--ink); --t2: var(--ink2); --t4: var(--dim); --accent: var(--blue); --border: var(--rule);
  --border2: var(--rule-dark); --font-display: var(--serif); --radius-md: var(--radius); --chemistry: var(--red);
}

html { font-size: 16px; -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
body { margin: 0; font-family: var(--sans); color: var(--ink); background: var(--white); line-height: 1.6;
       -webkit-font-smoothing: antialiased; min-height: 100vh; display: flex; flex-direction: column; }
main { flex: 1; }
h1, h2, h3 { font-family: var(--serif); font-weight: 700; line-height: 1.2; margin: 0 0 0.6em; color: var(--ink); }
h1 { font-size: clamp(1.9rem, 4.5vw, 2.9rem); letter-spacing: -0.01em; }
h2 { font-size: clamp(1.4rem, 3vw, 1.9rem); }
h3 { font-size: 1.15rem; }
p { margin: 0 0 1rem; }
a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }
img, svg, canvas { max-width: 100%; }
/* a lesson's graph or diagram: never taller than 480px, its shape kept */
.asc-graph canvas { max-height: 480px; width: auto; height: auto; }
:focus-visible { outline: 3px solid var(--blue-ring); outline-offset: 2px; border-radius: 4px; }
.skip { position: absolute; left: -999px; top: 0; background: var(--ink); color: var(--white); padding: 0.6rem 1rem; z-index: 100; }
.skip:focus { left: 0.5rem; top: 0.5rem; }
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } * { transition: none !important; } }

/* layout */
.wrap { width: 100%; max-width: var(--page); margin: 0 auto; padding: 0 var(--gutter); }
.wrap.reading { max-width: var(--reading); }
.section { padding: clamp(2.5rem, 6vw, 4.5rem) 0; }
.section.tint { background: var(--surface); border-top: 1px solid var(--rule); border-bottom: 1px solid var(--rule); }
.grid { display: grid; gap: 1.25rem; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }
.stack > * + * { margin-top: 1rem; }
.lead { font-size: 1.15rem; color: var(--dim); max-width: 60ch; }
.eyebrow { font-family: var(--mono); font-size: 0.78rem; letter-spacing: 0.08em; text-transform: uppercase; color: var(--blue); margin: 0 0 0.8rem; }
.muted { color: var(--dim); }
.crumbs { font-size: 0.9rem; color: var(--dim); margin: 0 0 1.2rem; }
.crumbs a { color: var(--dim); }
.crumbs span[aria-hidden] { margin: 0 0.45rem; color: var(--rule-dark); }

/* header and footer */
.site-header { position: sticky; top: 0; z-index: 20; background: rgba(255, 255, 255, 0.94); backdrop-filter: saturate(160%) blur(8px);
               border-bottom: 1px solid var(--rule); }
.site-header .wrap { display: flex; align-items: center; gap: 1.5rem; min-height: 64px; }
.brand { font-family: var(--serif); font-weight: 700; font-size: 1.3rem; color: var(--ink); white-space: nowrap; }
.brand:hover { text-decoration: none; }
.brand em { font-style: normal; color: var(--blue); }
.site-nav { display: flex; align-items: center; gap: 1.4rem; margin-left: auto; }
.site-nav a { color: var(--ink2); font-size: 0.95rem; font-weight: 500; }
.site-nav a[aria-current="page"] { color: var(--blue); }
.nav-toggle { display: none; margin-left: auto; background: none; border: 1px solid var(--rule-dark); border-radius: var(--radius-sm);
              padding: 0.45rem 0.7rem; font: inherit; color: var(--ink); cursor: pointer; }
@media (max-width: 760px) {
  .nav-toggle { display: block; }
  .site-nav { display: none; position: absolute; left: 0; right: 0; top: 64px; flex-direction: column; align-items: stretch; gap: 0;
              background: var(--white); border-bottom: 1px solid var(--rule); padding: 0.5rem var(--gutter) 1rem; margin: 0; }
  .site-nav.open { display: flex; }
  .site-nav a, .site-nav button { padding: 0.75rem 0; text-align: left; }
}
.site-footer { border-top: 1px solid var(--rule); background: var(--surface); color: var(--dim); font-size: 0.92rem; padding: 2.5rem 0 2rem; margin-top: 3rem; }
.site-footer .wrap { display: flex; flex-wrap: wrap; gap: 1.5rem 3rem; justify-content: space-between; }
.site-footer nav { display: flex; flex-wrap: wrap; gap: 0.5rem 1.4rem; }
.site-footer a { color: var(--dim); }

/* buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 0.5rem; font: inherit; font-weight: 600; font-size: 0.95rem;
       padding: 0.65rem 1.15rem; border-radius: var(--radius-sm); border: 1px solid var(--rule-dark); background: var(--white); color: var(--ink);
       cursor: pointer; text-decoration: none; transition: background 0.15s, border-color 0.15s, box-shadow 0.15s; }
.btn:hover { text-decoration: none; background: var(--surface); }
.btn.primary { background: var(--blue); border-color: var(--blue); color: var(--white); }
.btn.primary:hover { background: var(--blue-dark); border-color: var(--blue-dark); }
.btn.quiet { border-color: transparent; background: none; color: var(--blue); padding-left: 0; padding-right: 0; }
.btn[disabled] { opacity: 0.6; cursor: default; }
.btn-row { display: flex; flex-wrap: wrap; gap: 0.75rem; align-items: center; }

/* cards, badges, notices */
.card { display: flex; flex-direction: column; border: 1px solid var(--rule); border-radius: var(--radius); background: var(--white);
        padding: 1.4rem; box-shadow: var(--shadow-sm); }
a.card { color: inherit; transition: box-shadow 0.15s, border-color 0.15s, transform 0.15s; }
a.card:hover { text-decoration: none; border-color: var(--rule-dark); box-shadow: var(--shadow); transform: translateY(-1px); }
.card h3 { margin-bottom: 0.4rem; }
.card p { color: var(--dim); font-size: 0.95rem; }
.card .card-foot { margin-top: auto; padding-top: 1rem; display: flex; justify-content: space-between; align-items: baseline; gap: 1rem; }
.price { font-family: var(--serif); font-size: 1.35rem; font-weight: 700; color: var(--ink); }
.price small { font-family: var(--sans); font-size: 0.8rem; font-weight: 400; color: var(--dim); margin-left: 0.2rem; }
.badge { display: inline-block; font-family: var(--mono); font-size: 0.72rem; letter-spacing: 0.04em; text-transform: uppercase;
         padding: 0.15rem 0.5rem; border-radius: 999px; background: var(--blue-dim); color: var(--blue-dark); }
.badge.green { background: var(--green-dim); color: var(--green); }
.badge.amber { background: var(--amber-dim); color: var(--amber); }
.notice { border: 1px solid var(--rule); border-left: 4px solid var(--blue); background: var(--surface); border-radius: var(--radius-sm);
          padding: 0.9rem 1.1rem; margin: 1rem 0; }
.notice.good { border-left-color: var(--green); background: var(--green-dim); }
.notice.warn { border-left-color: var(--amber); background: var(--amber-dim); }
.notice.bad { border-left-color: var(--red); background: var(--red-dim); }
.state { text-align: center; color: var(--dim); padding: 3rem 1rem; }
.skeleton { border-radius: var(--radius); background: linear-gradient(90deg, var(--surface) 25%, var(--surface2) 37%, var(--surface) 63%);
            background-size: 400% 100%; animation: shimmer 1.4s ease infinite; min-height: 7rem; }
@keyframes shimmer { 0% { background-position: 100% 0; } 100% { background-position: 0 0; } }
@media (prefers-reduced-motion: reduce) { .skeleton { animation: none; } }

/* home */
.hero { padding: clamp(3rem, 8vw, 6rem) 0 clamp(2.5rem, 6vw, 4.5rem); }
.hero h1 em { font-style: italic; color: var(--blue); }
.steps { counter-reset: step; list-style: none; padding: 0; margin: 0; }
.steps li { counter-increment: step; }
.steps li::before { content: counter(step); display: inline-flex; align-items: center; justify-content: center; width: 2rem; height: 2rem;
                    border-radius: 50%; background: var(--blue-dim); color: var(--blue-dark); font-weight: 700; margin-bottom: 0.8rem; }

/* course */
.course-head { display: grid; gap: 2rem; grid-template-columns: minmax(0, 1fr) minmax(260px, 340px); align-items: start; }
@media (max-width: 860px) { .course-head { grid-template-columns: 1fr; } }
.buy-box { position: sticky; top: 84px; }
.plan { display: flex; justify-content: space-between; align-items: center; gap: 1rem; padding: 0.8rem 0; border-top: 1px solid var(--rule); }
.plan:first-of-type { border-top: 0; }
.chapter { border: 1px solid var(--rule); border-radius: var(--radius); margin-bottom: 0.8rem; background: var(--white); }
.chapter > summary { cursor: pointer; padding: 1rem 1.2rem; font-weight: 600; display: flex; justify-content: space-between; gap: 1rem; list-style: none; }
.chapter > summary::-webkit-details-marker { display: none; }
.chapter > summary::after { content: '+'; color: var(--dim); font-weight: 400; }
.chapter[open] > summary::after { content: '−'; }
.chapter > summary small { color: var(--dim); font-weight: 400; margin-left: auto; }
.topic-list { list-style: none; margin: 0; padding: 0 1.2rem 0.6rem; }
.topic-list li { border-top: 1px solid var(--rule); }
.topic-list a, .topic-list span.row { display: flex; justify-content: space-between; gap: 1rem; padding: 0.7rem 0; color: var(--ink2); }
.topic-list span.row { color: var(--dim2); }
.topic-list small { color: var(--dim); white-space: nowrap; }

/* topic: its lessons */
.lesson-list { list-style: none; padding: 0; margin: 1.5rem 0; counter-reset: lesson; }
.lesson-list li { counter-increment: lesson; margin-bottom: 0.7rem; }
.lesson-list a { display: flex; align-items: center; gap: 1rem; padding: 1rem 1.2rem; border: 1px solid var(--rule); border-radius: var(--radius);
                 color: var(--ink); background: var(--white); }
.lesson-list a:hover { text-decoration: none; border-color: var(--rule-dark); box-shadow: var(--shadow-sm); }
.lesson-list a::before { content: counter(lesson); display: inline-flex; align-items: center; justify-content: center; flex: none; width: 2rem; height: 2rem;
                         border-radius: 50%; background: var(--surface2); color: var(--dim); font-weight: 600; font-size: 0.9rem; }
.lesson-list .kind { font-weight: 600; text-transform: capitalize; }
.lesson-list .tags { margin-left: auto; display: flex; gap: 0.4rem; }

/* lesson: what the renderer draws, in this site's type */
.lesson-body { font-size: 1.06rem; line-height: 1.75; color: var(--ink2); overflow-wrap: anywhere; }
.lesson-body h1, .lesson-body h2, .lesson-body h3, .lesson-body h4 { margin: 1.8rem 0 0.6rem; }
.lesson-body h1 { font-size: 1.6rem; } .lesson-body h2 { font-size: 1.35rem; } .lesson-body h3 { font-size: 1.15rem; } .lesson-body h4 { font-size: 1rem; }
.lesson-body ul, .lesson-body ol, .lesson-body .apc-list { margin: 0 0 1rem 1.4rem; padding: 0; }
.lesson-body li { margin-bottom: 0.3rem; }
.lesson-body .apc-math { margin: 1.1rem 0; overflow-x: auto; overflow-y: hidden; }
.lesson-body .apc-table { border-collapse: collapse; margin: 1.1rem 0; display: block; overflow-x: auto; max-width: 100%; font-size: 0.98rem; }
.lesson-body .apc-table th, .lesson-body .apc-table td { border: 1px solid var(--rule-dark); padding: 0.5rem 0.8rem; text-align: left; vertical-align: top; }
.lesson-body .apc-table th { background: var(--surface2); font-weight: 600; }
.lesson-body .apc-callout { border: 1px solid var(--rule); border-left: 4px solid var(--blue); background: var(--surface);
                            border-radius: 0 var(--radius) var(--radius) 0; padding: 0.9rem 1.1rem; margin: 1.2rem 0; }
.lesson-body .apc-callout-label { font-family: var(--mono); font-size: 0.75rem; letter-spacing: 0.06em; text-transform: uppercase; color: var(--blue-dark); margin-bottom: 0.4rem; }
.lesson-body .apc-callout > :last-child { margin-bottom: 0; }
.lesson-body .apc-code, .lesson-body .apc-pseudocode { background: var(--surface2); border: 1px solid var(--rule); border-radius: var(--radius-sm);
                            padding: 0.8rem 1rem; overflow-x: auto; font-family: var(--mono); font-size: 0.92rem; white-space: pre; }
.lesson-body .apc-error { color: var(--red); font-family: var(--mono); white-space: pre-wrap; }
.lesson-body .apc-question { border: 1px solid var(--rule); border-radius: var(--radius); padding: 1.1rem 1.25rem; margin: 1.4rem 0; background: var(--white); box-shadow: var(--shadow-sm); }
.lesson-body .apc-question-options { list-style: none; margin: 0.6rem 0 0; padding: 0; }
.lesson-body .apc-question-options li, .lesson-body .apc-question-options label { display: flex; gap: 0.6rem; align-items: baseline; padding: 0.35rem 0; }
.lesson-body .apc-question-answer-input { font: inherit; padding: 0.5rem 0.7rem; border: 1px solid var(--rule-dark); border-radius: var(--radius-sm); max-width: 14rem; }
.apc-question-check, .lesson-again { font: inherit; font-weight: 600; font-size: 0.95rem; padding: 0.55rem 1rem; border: 1px solid var(--blue); border-radius: var(--radius-sm);
                            background: var(--white); color: var(--blue); cursor: pointer; margin-top: 0.8rem; }
.apc-question-check:hover, .lesson-again:hover { background: var(--blue-dim); }
.apc-question-feedback { margin-top: 0.6rem; font-weight: 600; }
.apc-question-feedback[data-correct="true"] { color: var(--green); }
.apc-question-feedback[data-correct="false"] { color: var(--red); }
.apc-question-key { margin-top: 0.5rem; }
.apc-question-solution { margin-top: 0.8rem; border-top: 1px solid var(--rule); padding-top: 0.8rem; }
.apc-question-solution > summary { cursor: pointer; font-weight: 600; color: var(--blue); }
.lesson-nav { display: flex; justify-content: space-between; gap: 1rem; margin-top: 2.5rem; padding-top: 1.5rem; border-top: 1px solid var(--rule); }

/* prose pages (terms, privacy, refund, contact) */
.prose { font-size: 1.02rem; line-height: 1.75; color: var(--ink2); }
.prose h2 { margin-top: 2rem; font-size: 1.35rem; }
.prose h3 { margin-top: 1.5rem; }
.prose ul, .prose ol { margin: 0 0 1rem 1.4rem; padding: 0; }
.prose li { margin-bottom: 0.35rem; }

/* forms */
label { font-size: 0.95rem; }
.field { width: 100%; font: inherit; color: var(--ink); background: var(--white); border: 1px solid var(--rule-dark); border-radius: var(--radius-sm);
         padding: 0.6rem 0.75rem; margin-top: 0.35rem; }
.field:focus { outline: 3px solid var(--blue-ring); outline-offset: 0; border-color: var(--blue); }
textarea.field { resize: vertical; }
form.card { position: relative; }

/* signing in on the page (assets/account.js) */
dialog.acct { border: 0; border-radius: var(--radius-lg); padding: 0; width: min(420px, calc(100vw - 2rem)); box-shadow: 0 24px 64px rgba(13, 17, 23, 0.28); color: var(--ink); }
dialog.acct::backdrop { background: rgba(13, 17, 23, 0.55); }
.acct-body { padding: 2rem 1.75rem 1.5rem; }
.acct-body h2 { margin-bottom: 0.3rem; }
.acct-field { margin: 1rem 0; }
.acct-field label { font-weight: 600; }
.acct-links { display: flex; flex-wrap: wrap; gap: 0.25rem 1.2rem; margin: 1rem 0 0; }
.acct-close { position: absolute; top: 0.6rem; right: 0.8rem; border: 0; background: none; font-size: 1.6rem; line-height: 1; color: var(--dim); cursor: pointer; padding: 0.2rem 0.5rem; }

/* the wallet chip of the header */
.wallet { position: relative; }
.wallet-chip { display: inline-flex; align-items: center; gap: 0.5rem; font: inherit; font-size: 0.9rem; padding: 0.4rem 0.8rem; border-radius: 999px;
               border: 1px solid var(--rule-dark); background: var(--surface); color: var(--ink); cursor: pointer; }
.wallet-chip:hover { background: var(--surface2); }
.wallet-label { color: var(--dim); }
.wallet-amount { font-weight: 700; font-variant-numeric: tabular-nums; }
.wallet-panel { position: absolute; right: 0; top: calc(100% + 0.6rem); width: min(340px, calc(100vw - 2rem)); background: var(--white); border: 1px solid var(--rule);
                border-radius: var(--radius); box-shadow: var(--shadow); padding: 1.1rem 1.2rem; z-index: 30; }
.wallet-panel h3 { font-family: var(--sans); font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--dim); margin: 1.1rem 0 0.5rem; }
.wallet-head { display: flex; justify-content: space-between; align-items: baseline; }
.wallet-head strong { font-family: var(--serif); font-size: 1.5rem; }
.tx-list { list-style: none; margin: 0; padding: 0; }
.tx-list li { display: flex; justify-content: space-between; gap: 1rem; padding: 0.5rem 0; border-top: 1px solid var(--rule); font-size: 0.92rem; }
.tx-list li:first-child { border-top: 0; }
.tx-what { display: block; }
.tx-list small { color: var(--dim); }
.tx-amount { font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.tx-amount.plus { color: var(--green); }
@media (max-width: 760px) { .wallet-panel { position: static; width: 100%; box-shadow: none; margin-top: 0.6rem; } }
.acct-or { display: flex; align-items: center; gap: 0.8rem; color: var(--dim); font-size: 0.85rem; margin: 1.1rem 0 0.8rem; }
.acct-or::before, .acct-or::after { content: ''; flex: 1; height: 1px; background: var(--rule); }
.acct-google { width: 100%; }

/* a reader's progress */
.progress { height: 8px; border-radius: 999px; background: var(--surface2); overflow: hidden; margin-top: 1rem; }
.progress span { display: block; height: 100%; background: var(--green); border-radius: 999px; }
.lesson-list.plain { counter-reset: none; }
.lesson-list.plain a::before { content: none; }
.tiles { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
.tile strong { font-family: var(--serif); font-size: 2.2rem; line-height: 1.1; }
.topic-progress .progress { margin-top: 0.8rem; }

/* the tutor, on a lesson page */
.tutor { margin-top: 3rem; padding-top: 2rem; border-top: 1px solid var(--rule); }
.tutor-turn { border: 1px solid var(--rule); border-radius: var(--radius); padding: 0.9rem 1.1rem; margin: 0.8rem 0; background: var(--white); }
.tutor-turn.mine { background: var(--surface); }
.tutor-turn > strong { font-family: var(--mono); font-size: 0.75rem; letter-spacing: 0.06em; text-transform: uppercase; color: var(--dim); }
.tutor-turn p { margin: 0.4rem 0 0; }
.tutor-turn .lesson-body { font-size: 1rem; margin-top: 0.4rem; }
.tutor-related { font-size: 0.92rem; margin-top: 0.8rem; }
.tutor-buy { margin-top: 1.2rem; padding-top: 1rem; border-top: 1px solid var(--rule); }

/* A block with voice (one-frame sequence, VIDEO-PLAN V3): only Play, no
   Previous, Next, Replay, slider or "1 / 1". The player's slider has max 0
   when there is one frame. */
.apc-sequence-controls:has(> input[type="range"][max="0"]) > :is(button:nth-of-type(1), button:nth-of-type(3), button:nth-of-type(4), input[type="range"], .apc-sequence-position) { display: none; }
.apc-sequence-controls:has(> input[type="range"][max="0"]) > button:nth-of-type(2)::before { content: "\25B6\00A0"; }
.apc-sequence-player:has(.apc-sequence-controls > input[type="range"][max="0"]) > .apc-sequence-title { font-size: 0.85rem; color: var(--dim); margin-bottom: 0.4rem; }

/* Spoken parts (sequence players): the site's look over the renderer's
   own dark style, which it adds later; the frame's audio bar is played by
   the player's buttons, not shown twice. */
main .apc-sequence-player { background: var(--white); color: var(--ink); border: 1px solid var(--rule); border-radius: var(--radius); padding: 1rem 1.1rem; }
main .apc-sequence-title { color: var(--blue-dark); font: 600 0.95rem var(--sans); }
main .apc-sequence-frame audio, main .apc-sequence-frame .apc-audio { display: none; }
main .apc-sequence-controls button { font: 600 0.9rem var(--sans); border: 1px solid var(--rule-dark); background: var(--white); color: var(--ink); border-radius: var(--radius-sm); padding: 0.4rem 0.8rem; cursor: pointer; }
main .apc-sequence-controls button:nth-of-type(2) { background: var(--blue); border-color: var(--blue); color: #fff; }
main .apc-sequence-controls button:disabled { opacity: 0.45; cursor: default; }
main .apc-sequence-controls input[type="range"] { accent-color: var(--blue); }
main .apc-sequence-position { color: var(--dim); }

/* a password box with its eye (account.js) */
.pw-wrap { position: relative; }
.pw-wrap .field { padding-right: 2.9rem; }
.pw-eye { position: absolute; right: .3rem; top: 50%; transform: translateY(-50%); display: grid; place-items: center;
  width: 2.4rem; height: 2.4rem; padding: 0; border: 0; border-radius: 8px; background: transparent; color: var(--dim); cursor: pointer; }
.pw-eye:hover { color: var(--ink); background: rgba(127, 127, 127, .14); }
.pw-eye:focus-visible { outline: 3px solid var(--blue-ring); outline-offset: 0; }
