/* Subject pages (History first): units that fold, lessons grouped by topic, progress, Continue card.
   Built by /js/subject-page.js from the lesson rows already in the page (the lesson editor keeps writing those rows).
   Everything is scoped under html.sp-js, which the script sets: without the script the old list shows. */
html.sp-js #main .filters,
html.sp-js #main .result-count,
html.sp-js #main [data-f="none"],
html.sp-js #main ol.lesson-list,
html.sp-js #main .page-head .lead,
html.sp-js #main .page-head .page-meta,
html.sp-js #main .page-head .syllabus-card,
html.sp-js #main .pg-notice { display: none !important; }

html.sp-js #main .page-head { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 4px 32px; align-items: end; max-width: none; padding-block: clamp(22px, 3.5vw, 40px) 20px; }
html.sp-js #main .page-head > * { grid-column: 1; margin: 0; }
html.sp-js #main .page-head h1 { font-size: clamp(2rem, 4.2vw, 2.9rem); line-height: 1.05; margin: .1em 0 .15em; }
html.sp-js #main .page-head > .sp-cont { grid-column: 2; grid-row: 1 / span 3; align-self: end; }
.sp-sub { color: var(--muted); font-size: 1.05rem; }
.sp-sub a { color: var(--sp-accent, #8a3f24); }

/* Signed-out notice of account.js: one compact line */
html.sp-js #main .account-notice-wrap { padding-top: 16px; }
html.sp-js #main .account-notice { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 18px; padding: 10px 16px; }
html.sp-js #main .account-notice > p { margin: 0; }
html.sp-js #main .account-notice-links { margin: 0 0 0 auto; }
html.sp-js #main .account-notice-links .btn { min-height: 38px; margin: 0; }

.sp-cont { display: flex; align-items: center; gap: 16px; background: var(--navy); color: #fff; border-radius: 16px; padding: 14px 18px 14px 16px; text-decoration: none; min-width: 340px; max-width: 460px; box-shadow: var(--shadow-md, 0 14px 34px -14px #102a3c47); }
.sp-cont[hidden] { display: none; }
.sp-cont:hover { background: var(--navy-deep, #102a3c); color: #fff; }
.sp-ring { --p: 0; width: 52px; height: 52px; border-radius: 50%; flex: none; display: grid; place-items: center; font-weight: 700; font-size: .82rem; background: radial-gradient(closest-side, var(--navy) 78%, transparent 80%), conic-gradient(#f0a58f calc(var(--p) * 1%), #ffffff2e 0); }
.sp-cont small { display: block; opacity: .78; font-size: .82rem; letter-spacing: .02em; }
.sp-cont strong { display: block; font-size: 1.05rem; line-height: 1.25; }
.sp-cont .sp-arrow { margin-left: auto; background: #f0a58f; color: var(--navy-deep, #102a3c); border-radius: 999px; width: 34px; height: 34px; display: grid; place-items: center; flex: none; }

.sp { padding-bottom: 72px; }
.sp-tools { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; margin-bottom: 22px; }
.sp-seg { display: inline-flex; background: var(--surface); border: 1px solid var(--line); border-radius: 999px; padding: 4px; }
.sp-seg[hidden] { display: none; }
.sp-yrow { flex-basis: 100%; }
.sp-yrow[hidden] { display: none; }
.sp-seg button { font: inherit; font-weight: 650; border: 0; background: none; color: var(--ink); padding: 8px 18px; border-radius: 999px; cursor: pointer; min-height: 38px; }
.sp-seg button[aria-pressed="true"] { background: var(--navy); color: #fff; }
.sp-seg button:focus-visible, .sp-unit summary:focus-visible { outline: 2px solid var(--accent, #b4432c); outline-offset: 2px; }
.sp-seg small { font-weight: 500; opacity: .7; margin-left: 4px; }
.sp-pick { flex: none; min-width: 200px; }
.sp-pick select { height: 46px; font: inherit; border-radius: 999px; padding: 0 16px; border: 1px solid var(--line); background: var(--surface); width: 100%; }
.sp-search { flex: 1; min-width: 220px; position: relative; }
.sp-search svg { position: absolute; left: 16px; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.sp-search input { width: 100%; height: 46px; font: inherit; color: var(--ink); background: var(--surface); border: 1px solid var(--line); border-radius: 999px; padding: 0 18px 0 44px; }
.sp-search input:focus { outline: 2px solid var(--navy); outline-offset: 1px; }
.sp-none { color: var(--muted); padding: 12px 4px; }

.sp-grid { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 28px; align-items: start; }
.sp-wait .sp-units { visibility: hidden; }
.sp-units { min-height: 320px; }
.sp-unit { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; margin-bottom: 12px; box-shadow: var(--shadow-sm, 0 1px 2px #102a3c0d); }
.sp-unit[hidden] { display: none; }
.sp-unit summary { list-style: none; cursor: pointer; display: grid; grid-template-columns: minmax(0, 1fr) auto 14px; grid-template-areas: "k count chev" "name bar chev"; gap: 2px 18px; align-items: center; padding: 16px 20px; }
.sp-unit summary::-webkit-details-marker { display: none; }
.sp-k { grid-area: k; font-size: .74rem; font-weight: 700; letter-spacing: .09em; text-transform: uppercase; color: var(--sp-accent, #8a3f24); }
.sp-name { grid-area: name; font-family: var(--serif); font-size: 1.3rem; font-weight: 600; color: var(--navy); line-height: 1.2; }
.sp-count { grid-area: count; font-size: .85rem; color: var(--muted); text-align: right; white-space: nowrap; }
.sp-bar { grid-area: bar; width: 120px; height: 6px; border-radius: 9px; background: #e6e8e2; overflow: hidden; justify-self: end; }
.sp-bar i { display: block; height: 100%; background: #3d7a2c; border-radius: 9px; }
.sp-nobar .sp-bar { visibility: hidden; }
.sp-chev { grid-area: chev; color: var(--muted); transition: transform .15s; }
.sp-unit[open] .sp-chev { transform: rotate(180deg); }
.sp-body { border-top: 1px solid var(--line); padding: 6px 12px 12px; }
.sp-topic { font-family: var(--sans); font-size: .95rem; font-weight: 700; color: var(--navy); margin: 16px 8px 4px; }
.sp-body ol { list-style: none; margin: 0; padding: 0; }
.sp-body > ol:first-child { margin-top: 6px; }
.sp-les[hidden], .sp-topic[hidden] { display: none; }
.sp-les { display: flex; align-items: center; border-radius: 10px; }
.sp-les:hover { background: #f1efe8; }
.sp-les a { text-decoration: none; filter: none; opacity: 1; }
.sp-main { flex: 1; min-width: 0; display: flex; align-items: center; gap: 12px; padding: 9px 10px; border-radius: 10px; color: var(--ink); }
.sp-acts { display: flex; gap: 6px; flex: none; padding-right: 8px; align-items: center; }
.sp-btn, .sp-more-btn { font: inherit; font-size: .82rem; font-weight: 650; border-radius: 999px; padding: 4px 13px; white-space: nowrap; cursor: pointer; line-height: 1.5; }
.sp-btn { min-width: 5.4em; text-align: center; color: var(--navy); background: var(--surface); border: 1px solid var(--navy); }
.sp-btn:hover { background: var(--navy); color: #fff; }
.sp-les.next .sp-btn { background: var(--sp-accent, #a24f31); border-color: var(--sp-accent, #a24f31); color: #fff; }
.sp-les.done .sp-btn { border-color: var(--line); color: var(--muted); }
.sp-more { position: relative; display: inline-flex; }
.sp-more-btn { display: inline-flex; align-items: center; gap: 5px; color: var(--ink); background: var(--surface); border: 1px solid var(--line); }
.sp-more-btn:hover, .sp-more-btn[aria-expanded="true"] { border-color: var(--navy); }
.sp-more-btn:focus-visible, .sp-btn:focus-visible { outline: 2px solid var(--accent, #b4432c); outline-offset: 2px; }
.sp-menu { position: absolute; top: calc(100% + 6px); right: 0; z-index: 8; min-width: 190px; display: grid; padding: 6px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow-md, 0 14px 34px -14px #102a3c47); }
.sp-menu[hidden] { display: none; }
.sp-menu a { padding: 8px 12px; border-radius: 8px; color: var(--ink); font-size: .95rem; }
.sp-menu a:hover, .sp-menu a:focus-visible { background: #f1efe8; color: var(--navy); outline: none; }
.sp-les.sp-menu-open { position: relative; z-index: 7; }
.sp-tick { width: 22px; height: 22px; border-radius: 50%; border: 1.6px solid #c6cbc5; flex: none; display: grid; place-items: center; color: #fff; }
.sp-tick svg { display: none; }
.sp-les.done .sp-tick { background: #3d7a2c; border-color: #3d7a2c; }
.sp-les.done .sp-tick svg { display: block; }
.sp-les.done .sp-lt { color: var(--muted); }
.sp-lt { flex: 1; min-width: 0; }
.sp-min { color: var(--muted); font-size: .85rem; flex: none; font-variant-numeric: tabular-nums; min-width: 3.4em; text-align: right; }
.sp-les.next, .sp-les.next:hover { background: var(--sp-tint, #f3e6df); }
.sp-les.next .sp-tick { border-color: var(--sp-accent, #a24f31); }
.sp-les.next .sp-lt { font-weight: 650; color: var(--navy); }
.sp-chip { font-size: .78rem; font-weight: 700; border-radius: 999px; padding: 3px 12px; flex: none; }
.sp-free { background: #e4efdf; color: #2c5a1f; }
.sp .pg-tick { display: none !important; }
.sp .lock-ic { flex: none; margin: 0; order: 9; }
.sp-guest .lock-ic { display: none; }

.sp-side { position: sticky; top: calc(var(--header-h, 68px) + 16px); display: grid; gap: 12px; }
.sp-game { display: block; border-radius: 16px; overflow: hidden; background: var(--navy); color: #fff; text-decoration: none; box-shadow: var(--shadow-sm, 0 1px 2px #102a3c0d); }
.sp-game[hidden] { display: none; }
.sp-game:hover { color: #fff; }
.sp-game img { display: block; width: 100%; aspect-ratio: 16 / 8; object-fit: cover; background: #234; }
.sp-game div { padding: 14px 16px 16px; }
.sp-game small { font-size: .72rem; font-weight: 700; letter-spacing: .1em; text-transform: uppercase; color: #f0a58f; }
.sp-game strong { display: block; font-family: var(--serif); font-size: 1.15rem; margin: 2px 0 4px; }
.sp-game span { font-size: .9rem; opacity: .85; line-height: 1.35; display: block; }
.sp-rev { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 6px; }
.sp-rev a { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 11px; text-decoration: none; color: var(--ink); }
.sp-rev a[hidden] { display: none; }
.sp-rev a:hover { background: #f1efe8; }
.sp-rev b { display: block; color: var(--navy); }
.sp-rev small { color: var(--muted); }
.sp-ico { width: 36px; height: 36px; border-radius: 10px; background: var(--sp-tint, #f3e6df); color: var(--sp-accent, #8a3f24); display: grid; place-items: center; flex: none; }
.sp-rev .sp-chevr { margin-left: auto; color: var(--muted); flex: none; }

@media (max-width: 900px) {
  html.sp-js #main .page-head { grid-template-columns: minmax(0, 1fr); }
  html.sp-js #main .page-head > .sp-cont { grid-column: 1; grid-row: auto; margin-top: 14px; min-width: 0; max-width: none; }
  html.sp-js #main .account-notice-links { margin-left: 0; }
  .sp-grid { grid-template-columns: minmax(0, 1fr); gap: 16px; }
  .sp-side { position: static; grid-row: 1; }
  .sp-game { display: flex; align-items: stretch; }
  .sp-game img { width: 96px; aspect-ratio: auto; flex: none; }
  .sp-game span { display: none; }
  .sp-game div { padding: 12px 14px; align-self: center; }
  .sp-rev { display: flex; }
  .sp-rev a { flex: 1; flex-direction: column; gap: 6px; text-align: center; padding: 10px 4px; }
  .sp-rev small, .sp-rev .sp-chevr { display: none; }
  .sp-unit summary { grid-template-columns: minmax(0, 1fr) 14px; grid-template-areas: "k chev" "name chev" "count chev" "bar chev"; padding: 14px 16px; }
  .sp-count { text-align: left; margin-top: 4px; }
  .sp-bar { justify-self: start; width: 100%; margin-top: 4px; }
  .sp-nobar .sp-bar { display: none; }
  .sp-name { font-size: 1.15rem; }
  .sp-les { flex-wrap: wrap; }
  .sp-main { flex-basis: 100%; align-items: flex-start; padding: 9px 6px 4px; }
  .sp-acts { padding: 0 6px 10px 40px; }
  .sp-menu { right: auto; left: 0; }
}
@media (prefers-reduced-motion: reduce) { .sp-chev { transition: none; } }
