/*
 * 408 Study Reader · Apple Books / Developer Documentation inspired shell
 * -------------------------------------------------------------------------
 * This file is intentionally scoped to html[data-study-ui]. It can be loaded
 * by every subject deck without changing presenter previews or standalone
 * slides. JavaScript owns only state and controls; all layout modes live here.
 */

html[data-study-ui] {
  color-scheme: light;

  /* Study-reader palette */
  --study-canvas: #f5f5f7;
  --study-canvas-warm: #faf9f6;
  --study-paper: rgba(255, 255, 255, .94);
  --study-paper-solid: #ffffff;
  --study-raised: #ffffff;
  --study-tint: #f0f1f3;
  --study-tint-strong: #e8e9ed;
  --study-label: #1d1d1f;
  --study-secondary: #5f6065;
  --study-tertiary: #86868b;
  --study-separator: rgba(28, 28, 30, .10);
  --study-separator-strong: rgba(28, 28, 30, .18);
  --study-blue: #0071e3;
  --study-blue-hover: #0077ed;
  --study-blue-soft: rgba(0, 113, 227, .10);
  --study-green: #248a3d;
  --study-green-soft: rgba(36, 138, 61, .11);
  --study-orange: #c65d00;
  --study-red: #d70015;
  --study-focus: rgba(0, 113, 227, .42);
  --study-bar: rgba(250, 250, 252, .78);
  --study-scrim: rgba(20, 20, 22, .28);
  --study-shadow-sm: 0 1px 2px rgba(0, 0, 0, .04), 0 5px 18px rgba(0, 0, 0, .045);
  --study-shadow: 0 2px 8px rgba(0, 0, 0, .035), 0 22px 70px rgba(0, 0, 0, .075);
  --study-shadow-float: 0 14px 44px rgba(0, 0, 0, .16), 0 2px 8px rgba(0, 0, 0, .08);
  --study-radius-xs: 8px;
  --study-radius-sm: 12px;
  --study-radius: 18px;
  --study-radius-lg: 28px;
  --study-appbar-height: 72px;
  --study-content-width: 1120px;
  --study-reading-width: 1060px;
  --study-ease: cubic-bezier(.22, .61, .36, 1);

  /* Override the old deck themes with one calm, content-first system. */
  --bg: var(--study-canvas);
  --bg-soft: var(--study-canvas-warm);
  --surface: var(--study-paper-solid);
  --surface-2: var(--study-tint);
  --border: var(--study-separator);
  --border-strong: var(--study-separator-strong);
  --text-1: var(--study-label);
  --text-2: var(--study-secondary);
  --text-3: var(--study-tertiary);
  --accent: var(--study-blue);
  --accent-2: #5e5ce6;
  --accent-3: #bf5af2;
  --good: var(--study-green);
  --warn: var(--study-orange);
  --bad: var(--study-red);
  --grad: linear-gradient(135deg, #0066cc 0%, #5e5ce6 52%, #af52de 100%);
  --grad-soft: linear-gradient(135deg, rgba(0, 102, 204, .08), rgba(94, 92, 230, .08) 52%, rgba(175, 82, 222, .07));
  --radius: var(--study-radius);
  --radius-sm: var(--study-radius-sm);
  --radius-lg: var(--study-radius-lg);
  --shadow: var(--study-shadow-sm);
  --shadow-lg: var(--study-shadow);
  --font-sans: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro SC", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  --font-display: -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro SC", "PingFang SC", sans-serif;
  --font-serif: "New York", "Songti SC", "STSong", "Noto Serif CJK SC", serif;
  --font-mono: "SFMono-Regular", "SF Mono", ui-monospace, Menlo, Monaco, Consolas, "Liberation Mono", monospace;

  background: var(--study-canvas);
  scroll-padding-top: calc(var(--study-appbar-height) + 24px);
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

html[data-study-ui][data-study-theme="dark"] {
  color-scheme: dark;
  --study-canvas: #101012;
  --study-canvas-warm: #141416;
  --study-paper: rgba(29, 29, 31, .94);
  --study-paper-solid: #1c1c1e;
  --study-raised: #242426;
  --study-tint: #2c2c2e;
  --study-tint-strong: #38383a;
  --study-label: #f5f5f7;
  --study-secondary: #b5b5bb;
  --study-tertiary: #8e8e93;
  --study-separator: rgba(255, 255, 255, .10);
  --study-separator-strong: rgba(255, 255, 255, .18);
  --study-blue: #2997ff;
  --study-blue-hover: #45a5ff;
  --study-blue-soft: rgba(41, 151, 255, .14);
  --study-green: #30d158;
  --study-green-soft: rgba(48, 209, 88, .14);
  --study-orange: #ff9f0a;
  --study-red: #ff453a;
  --study-focus: rgba(41, 151, 255, .55);
  --study-bar: rgba(24, 24, 26, .76);
  --study-scrim: rgba(0, 0, 0, .56);
  --study-shadow-sm: 0 1px 1px rgba(0, 0, 0, .28), 0 8px 24px rgba(0, 0, 0, .22);
  --study-shadow: 0 2px 9px rgba(0, 0, 0, .28), 0 24px 72px rgba(0, 0, 0, .34);
  --study-shadow-float: 0 18px 58px rgba(0, 0, 0, .54), 0 2px 10px rgba(0, 0, 0, .28);
  --grad: linear-gradient(135deg, #64d2ff 0%, #7d7aff 52%, #da8fff 100%);
  --grad-soft: linear-gradient(135deg, rgba(100, 210, 255, .10), rgba(125, 122, 255, .10) 52%, rgba(218, 143, 255, .09));
}

html[data-study-ui],
html[data-study-ui] body {
  min-height: 100%;
  background: var(--study-canvas) !important;
  color: var(--study-label);
  font-family: var(--font-sans);
  letter-spacing: -.008em;
  accent-color: var(--study-blue);
}

html[data-study-ui] body {
  background-image:
    radial-gradient(900px 440px at 15% -5%, rgba(0, 113, 227, .055), transparent 70%),
    radial-gradient(760px 440px at 90% 10%, rgba(94, 92, 230, .04), transparent 72%) !important;
  background-attachment: fixed !important;
}

html[data-study-ui][data-study-theme="dark"] body {
  background-image:
    radial-gradient(900px 440px at 15% -5%, rgba(41, 151, 255, .09), transparent 70%),
    radial-gradient(760px 440px at 90% 10%, rgba(94, 92, 230, .075), transparent 72%) !important;
}

html[data-study-ui] ::selection {
  color: var(--study-label);
  background: rgba(0, 113, 227, .19);
}

html[data-study-ui][data-study-theme="dark"] ::selection {
  background: rgba(41, 151, 255, .32);
}

html[data-study-ui] button,
html[data-study-ui] a {
  -webkit-tap-highlight-color: transparent;
}

html[data-study-ui] button {
  font: inherit;
}

html[data-study-ui] :where(a, button, [tabindex]):focus-visible {
  outline: 3px solid var(--study-focus);
  outline-offset: 3px;
}

.study-visually-hidden {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

/* ---------------------------------------------------------------------- */
/* App bar                                                                 */
/* ---------------------------------------------------------------------- */

.study-appbar {
  position: fixed;
  z-index: 120;
  top: 0;
  left: 0;
  right: 0;
  height: var(--study-appbar-height);
  color: var(--study-label);
  background: var(--study-bar);
  border-bottom: 1px solid var(--study-separator);
  -webkit-backdrop-filter: saturate(180%) blur(22px);
  backdrop-filter: saturate(180%) blur(22px);
}

.study-appbar__inner {
  width: min(100%, 1440px);
  height: 100%;
  margin: 0 auto;
  padding: 0 24px;
  display: grid;
  grid-template-columns: minmax(190px, .75fr) minmax(300px, 1.25fr) minmax(430px, auto);
  align-items: center;
  gap: 18px;
}

.study-brand {
  min-width: 0;
  display: inline-flex;
  align-items: center;
  gap: 11px;
  color: inherit;
  text-decoration: none !important;
  border-radius: 10px;
}

.study-brand__mark {
  width: 32px;
  height: 32px;
  flex: 0 0 32px;
  display: grid;
  place-items: center;
  color: #fff;
  background: linear-gradient(145deg, #2389f5, #0066cc);
  border-radius: 9px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .26), 0 4px 12px rgba(0, 102, 204, .22);
}

.study-brand__mark svg {
  width: 18px;
  height: 18px;
}

.study-brand__copy {
  min-width: 0;
  display: flex;
  flex-direction: column;
  line-height: 1.15;
}

.study-brand__copy strong {
  overflow: hidden;
  font-size: 13px;
  font-weight: 650;
  letter-spacing: -.01em;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.study-brand__copy span {
  overflow: hidden;
  margin-top: 4px;
  color: var(--study-tertiary);
  font-size: 11px;
  font-weight: 500;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.study-section-nav {
  min-width: 0;
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr) 34px;
  align-items: center;
  gap: 8px;
}

.study-current {
  min-width: 0;
  text-align: center;
  line-height: 1.2;
}

.study-current__eyebrow {
  display: block;
  margin-bottom: 3px;
  color: var(--study-tertiary);
  font-size: 10px;
  font-weight: 620;
  letter-spacing: .075em;
  text-transform: uppercase;
}

.study-current__title {
  display: block;
  overflow: hidden;
  color: var(--study-label);
  font-size: 13px;
  font-weight: 620;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.study-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 7px;
}

.study-icon-button,
.study-action-button,
.study-mode-button,
.study-pager__button,
.study-toc__close {
  appearance: none;
  border: 0;
  color: var(--study-secondary);
  background: transparent;
  cursor: pointer;
  user-select: none;
  transition: color .18s ease, background-color .18s ease, transform .18s var(--study-ease), box-shadow .18s ease;
}

.study-icon-button {
  width: 34px;
  height: 34px;
  padding: 0;
  display: inline-grid;
  flex: 0 0 34px;
  place-items: center;
  border-radius: 50%;
}

.study-icon-button svg,
.study-action-button svg,
.study-mode-button svg,
.study-pager__button svg,
.study-toc__close svg {
  width: 17px;
  height: 17px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.8;
}

.study-icon-button:hover,
.study-action-button:hover,
.study-mode-button:hover,
.study-toc__close:hover {
  color: var(--study-label);
  background: var(--study-tint);
}

.study-icon-button:active,
.study-action-button:active,
.study-mode-button:active,
.study-pager__button:active,
.study-toc__close:active {
  transform: scale(.94);
}

.study-icon-button:disabled,
.study-pager__button:disabled {
  opacity: .28;
  cursor: default;
  transform: none;
}

.study-action-button {
  min-height: 36px;
  padding: 0 11px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px solid transparent;
  border-radius: 10px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}

.study-action-button[aria-pressed="true"] {
  color: var(--study-green);
  background: var(--study-green-soft);
}

.study-action-button[aria-expanded="true"] {
  color: var(--study-blue);
  background: var(--study-blue-soft);
}

.study-mode-switch {
  height: 36px;
  padding: 3px;
  display: inline-flex;
  align-items: center;
  gap: 2px;
  border: 1px solid var(--study-separator);
  border-radius: 11px;
  background: var(--study-tint);
}

.study-mode-button {
  min-width: 33px;
  height: 28px;
  padding: 0 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  border-radius: 8px;
  font-size: 11px;
  font-weight: 620;
}

.study-mode-button[aria-pressed="true"] {
  color: var(--study-label);
  background: var(--study-paper-solid);
  box-shadow: 0 1px 4px rgba(0, 0, 0, .10), 0 0 0 1px rgba(0, 0, 0, .025);
}

html[data-study-ui][data-study-theme="dark"] .study-mode-button[aria-pressed="true"] {
  background: var(--study-raised);
  box-shadow: 0 1px 5px rgba(0, 0, 0, .32), 0 0 0 1px rgba(255, 255, 255, .035);
}

.study-read-progress {
  position: absolute;
  left: 0;
  right: 0;
  bottom: -1px;
  height: 2px;
  overflow: hidden;
  background: transparent;
}

.study-read-progress__value {
  display: block;
  width: 0;
  height: 100%;
  border-radius: 0 99px 99px 0;
  background: var(--study-blue);
  transition: width .24s var(--study-ease);
}

/* Replace old deck chrome with the reader shell. */
html[data-study-ui] .deck-back,
html[data-study-ui] body > .progress-bar {
  display: none !important;
}

/* ---------------------------------------------------------------------- */
/* Continuous reading mode                                                 */
/* ---------------------------------------------------------------------- */

html[data-study-ui][data-study-mode="reader"],
html[data-study-ui][data-study-mode="reader"] body {
  width: 100%;
  height: auto;
  overflow-x: hidden;
  overflow-y: auto;
}

html[data-study-ui][data-study-mode="reader"] {
  /* Long TOC/deep-link jumps must be immediate; adjacent navigation opts
     into smooth motion explicitly in study-ui.js. */
  scroll-behavior: auto;
}

html[data-study-ui][data-study-mode="reader"] .deck {
  position: relative !important;
  width: min(100%, var(--study-reading-width)) !important;
  height: auto !important;
  min-height: 100vh;
  margin: 0 auto !important;
  padding: calc(var(--study-appbar-height) + 42px) 24px 150px !important;
  overflow: visible !important;
  background: transparent !important;
}

html[data-study-ui][data-study-mode="reader"] .slide {
  position: relative !important;
  inset: auto !important;
  z-index: 1 !important;
  width: 100% !important;
  height: auto !important;
  min-height: 0 !important;
  margin: 0 0 28px !important;
  padding: clamp(34px, 5.1vw, 62px) clamp(28px, 5.5vw, 68px) !important;
  display: block !important;
  overflow: visible !important;
  opacity: 1 !important;
  pointer-events: auto !important;
  transform: none !important;
  /* The root already owns the sticky-header scroll offset. Keeping the same
     value here would double it and make a deep link select the previous card. */
  scroll-margin-top: 0;
  color: var(--study-label);
  background: var(--study-paper) !important;
  border: 1px solid var(--study-separator) !important;
  border-radius: var(--study-radius-lg) !important;
  box-shadow: var(--study-shadow-sm) !important;
  transition: border-color .25s ease, box-shadow .25s ease, background-color .25s ease !important;
}

html[data-study-ui][data-study-mode="reader"] .slide.is-active {
  z-index: 2 !important;
  border-color: rgba(0, 113, 227, .20) !important;
  box-shadow: var(--study-shadow) !important;
}

html[data-study-ui][data-study-mode="reader"][data-study-theme="dark"] .slide.is-active {
  border-color: rgba(41, 151, 255, .28) !important;
}

html[data-study-ui][data-study-mode="reader"] .slide:first-child {
  padding-top: clamp(48px, 7vw, 86px) !important;
  padding-bottom: clamp(48px, 7vw, 86px) !important;
  background:
    radial-gradient(620px 330px at 88% 6%, rgba(0, 113, 227, .09), transparent 70%),
    radial-gradient(540px 300px at 8% 94%, rgba(94, 92, 230, .065), transparent 70%),
    var(--study-paper-solid) !important;
}

html[data-study-ui][data-study-mode="reader"][data-study-theme="dark"] .slide:first-child {
  background:
    radial-gradient(620px 330px at 88% 6%, rgba(41, 151, 255, .14), transparent 70%),
    radial-gradient(540px 300px at 8% 94%, rgba(125, 122, 255, .10), transparent 70%),
    var(--study-paper-solid) !important;
}

/* Comfortable reading type, including dense inline styles in old slides. */
html[data-study-ui][data-study-mode="reader"] .slide :where(p, li):not(.kicker):not(.eyebrow) {
  font-size: clamp(15px, 1.5vw, 16.5px) !important;
  line-height: 1.78 !important;
}

html[data-study-ui][data-study-mode="reader"] .slide :where(.h1, h1.title) {
  max-width: 15ch;
  font-size: clamp(50px, 8vw, 82px) !important;
  line-height: 1.03 !important;
  letter-spacing: -.045em !important;
}

html[data-study-ui][data-study-mode="reader"] .slide :where(.h2, h2.title) {
  font-size: clamp(32px, 5vw, 48px) !important;
  line-height: 1.13 !important;
  letter-spacing: -.035em !important;
}

html[data-study-ui][data-study-mode="reader"] .slide :where(h3, .h3) {
  font-size: clamp(24px, 3.2vw, 31px) !important;
  line-height: 1.22 !important;
}

html[data-study-ui][data-study-mode="reader"] .slide :where(h4, .h4) {
  color: var(--study-label);
  font-size: clamp(18px, 2vw, 21px) !important;
  line-height: 1.35 !important;
}

html[data-study-ui][data-study-mode="reader"] .slide .lede {
  max-width: 66ch;
  color: var(--study-secondary);
  font-size: clamp(18px, 2vw, 21px) !important;
  line-height: 1.68 !important;
  font-weight: 400;
}

html[data-study-ui] .slide .kicker {
  color: var(--study-blue);
  font-family: var(--font-mono);
  font-weight: 650;
  letter-spacing: .075em;
}

html[data-study-ui] .dim {
  color: var(--study-secondary) !important;
}

html[data-study-ui] .dim2 {
  color: var(--study-tertiary) !important;
}

html[data-study-ui][data-study-mode="reader"] .slide :where(.grid, .cmp) {
  align-items: start;
}

html[data-study-ui][data-study-mode="reader"] .slide :where(.card, .qcard, .steps li, .state, .layer) {
  background: var(--study-raised) !important;
  border-color: var(--study-separator) !important;
  box-shadow: none !important;
}

html[data-study-ui][data-study-mode="reader"] .slide :where(.card, .qcard) {
  border-radius: var(--study-radius-sm) !important;
}

html[data-study-ui][data-study-mode="reader"] .slide .steps li::before {
  color: #fff !important;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .2);
}

html[data-study-ui][data-study-mode="reader"] .slide :where(.viz, pre, .code-block) {
  max-width: 100%;
  max-height: none !important;
  overflow: auto;
  border-color: var(--study-separator) !important;
  border-radius: var(--study-radius-sm) !important;
  font-size: clamp(12px, 1.3vw, 14px) !important;
  line-height: 1.7 !important;
  -webkit-overflow-scrolling: touch;
}

html[data-study-ui][data-study-mode="reader"] .slide .viz {
  color: var(--study-label) !important;
  background: var(--study-tint) !important;
}

html[data-study-ui][data-study-mode="reader"] .slide .code-block {
  color: #e8e8ed !important;
  background: #1d1d1f !important;
}

html[data-study-ui][data-study-mode="reader"][data-study-theme="dark"] .slide .code-block {
  color: #f2f2f7 !important;
  background: #0b0b0c !important;
}

html[data-study-ui][data-study-mode="reader"] .slide table.cmp-table {
  display: table;
  width: 100%;
  overflow: hidden;
  color: var(--study-label);
  background: var(--study-raised);
  border: 1px solid var(--study-separator);
  border-radius: var(--study-radius-sm);
  border-collapse: separate;
  border-spacing: 0;
  font-size: 14px !important;
}

html[data-study-ui][data-study-mode="reader"] .slide table.cmp-table th {
  color: var(--study-secondary) !important;
  background: var(--study-tint) !important;
}

html[data-study-ui][data-study-mode="reader"] .slide table.cmp-table :where(th, td) {
  padding: 11px 13px;
  border-color: var(--study-separator) !important;
}

html[data-study-ui][data-study-mode="reader"] .slide table.cmp-table tr:last-child td {
  border-bottom: 0;
}

html[data-study-ui][data-study-mode="reader"] .deck-footer {
  position: relative;
  left: auto;
  right: auto;
  bottom: auto;
  width: 100%;
  margin-top: clamp(28px, 4vw, 48px);
  padding-top: 16px;
  color: var(--study-tertiary);
  border-top: 1px solid var(--study-separator);
  pointer-events: none;
}

html[data-study-ui][data-study-mode="reader"] .slide[data-study-mastered="true"]::after {
  content: "✓  已掌握";
  position: absolute;
  top: 22px;
  right: 24px;
  padding: 5px 10px;
  color: var(--study-green);
  background: var(--study-green-soft);
  border: 1px solid rgba(36, 138, 61, .15);
  border-radius: 999px;
  font-size: 11px;
  font-weight: 680;
  letter-spacing: .01em;
}

html[data-study-ui][data-study-mode="reader"][data-study-theme="dark"] .slide[data-study-mastered="true"]::after {
  border-color: rgba(48, 209, 88, .18);
}

/* ---------------------------------------------------------------------- */
/* Presentation/card mode                                                  */
/* ---------------------------------------------------------------------- */

html[data-study-ui][data-study-mode="deck"],
html[data-study-ui][data-study-mode="deck"] body {
  width: 100%;
  height: 100%;
  overflow: hidden;
}

html[data-study-ui][data-study-mode="deck"] .deck {
  width: 100vw;
  height: 100vh;
  overflow: hidden;
  background: transparent !important;
}

html[data-study-ui][data-study-mode="deck"] .slide {
  padding: calc(var(--study-appbar-height) + 34px) clamp(48px, 5vw, 96px) 68px !important;
  background: transparent !important;
}

html[data-study-ui][data-study-mode="deck"] .slide :where(.card, .qcard) {
  background: var(--study-paper) !important;
  border-color: var(--study-separator) !important;
  box-shadow: var(--study-shadow-sm) !important;
}

html[data-study-ui][data-study-mode="deck"] .slide :where(.viz, .state, .layer, .steps li) {
  background: var(--study-tint) !important;
  border-color: var(--study-separator) !important;
}

html[data-study-ui][data-study-mode="deck"] .slide .code-block {
  color: #f2f2f7 !important;
  background: #1d1d1f !important;
  border-color: var(--study-separator) !important;
}

html[data-study-ui][data-study-mode="deck"] .deck-footer {
  bottom: 22px;
  color: var(--study-tertiary);
}

/* ---------------------------------------------------------------------- */
/* Contents drawer                                                         */
/* ---------------------------------------------------------------------- */

.study-toc-layer {
  position: fixed;
  z-index: 220;
  inset: 0;
  visibility: hidden;
  pointer-events: none;
}

.study-toc-layer.is-open {
  visibility: visible;
  pointer-events: auto;
}

.study-toc__scrim {
  position: absolute;
  inset: 0;
  opacity: 0;
  background: var(--study-scrim);
  -webkit-backdrop-filter: blur(2px);
  backdrop-filter: blur(2px);
  transition: opacity .25s ease;
}

.study-toc-layer.is-open .study-toc__scrim {
  opacity: 1;
}

.study-toc {
  position: absolute;
  top: 10px;
  bottom: 10px;
  left: 10px;
  width: min(410px, calc(100vw - 20px));
  display: flex;
  flex-direction: column;
  overflow: hidden;
  color: var(--study-label);
  background: var(--study-paper-solid);
  border: 1px solid var(--study-separator);
  border-radius: 22px;
  box-shadow: var(--study-shadow-float);
  transform: translateX(calc(-100% - 20px));
  transition: transform .34s var(--study-ease);
}

.study-toc-layer.is-open .study-toc {
  transform: translateX(0);
}

.study-toc__header {
  padding: 22px 20px 18px;
  border-bottom: 1px solid var(--study-separator);
}

.study-toc__topline {
  display: flex;
  align-items: flex-start;
  gap: 14px;
}

.study-toc__heading {
  min-width: 0;
  flex: 1;
}

.study-toc__heading h2 {
  margin: 0;
  color: var(--study-label);
  font-size: 24px;
  line-height: 1.18;
  font-weight: 720;
  letter-spacing: -.035em;
}

.study-toc__heading p {
  margin: 6px 0 0;
  color: var(--study-tertiary);
  font-size: 12px;
  line-height: 1.45;
}

.study-toc__close {
  width: 32px;
  height: 32px;
  padding: 0;
  display: grid;
  flex: 0 0 32px;
  place-items: center;
  border-radius: 50%;
  color: var(--study-secondary);
  background: var(--study-tint);
}

.study-mastery-summary {
  margin-top: 18px;
}

.study-mastery-summary__copy {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 8px;
  color: var(--study-secondary);
  font-size: 11px;
  font-weight: 600;
}

.study-mastery-summary__track {
  height: 5px;
  overflow: hidden;
  background: var(--study-tint-strong);
  border-radius: 99px;
}

.study-mastery-summary__value {
  display: block;
  width: 0;
  height: 100%;
  background: var(--study-green);
  border-radius: inherit;
  transition: width .25s var(--study-ease);
}

.study-toc__list {
  flex: 1;
  margin: 0;
  padding: 10px 10px 20px;
  overflow-x: hidden;
  overflow-y: auto;
  list-style: none;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

.study-toc__list li + li {
  margin-top: 2px;
}

.study-toc__item {
  width: 100%;
  min-height: 48px;
  padding: 7px 10px;
  display: grid;
  grid-template-columns: 32px minmax(0, 1fr) 22px;
  align-items: center;
  gap: 8px;
  border: 0;
  border-radius: 11px;
  color: var(--study-secondary);
  background: transparent;
  text-align: left;
  cursor: pointer;
  transition: color .16s ease, background-color .16s ease;
}

.study-toc__item:hover {
  color: var(--study-label);
  background: var(--study-tint);
}

.study-toc__item[aria-current="true"] {
  color: var(--study-blue);
  background: var(--study-blue-soft);
}

.study-toc__number {
  color: var(--study-tertiary);
  font-family: var(--font-mono);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  text-align: center;
}

.study-toc__item[aria-current="true"] .study-toc__number {
  color: var(--study-blue);
}

.study-toc__title {
  overflow: hidden;
  font-size: 13px;
  font-weight: 580;
  line-height: 1.35;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.study-toc__check {
  width: 19px;
  height: 19px;
  display: grid;
  place-items: center;
  color: transparent;
  border: 1px solid var(--study-separator-strong);
  border-radius: 50%;
}

.study-toc__check svg {
  width: 12px;
  height: 12px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2.4;
}

.study-toc__item.is-mastered .study-toc__check {
  color: #fff;
  background: var(--study-green);
  border-color: var(--study-green);
}

html[data-study-ui][data-study-toc-open="true"],
html[data-study-ui][data-study-toc-open="true"] body {
  overflow: hidden !important;
}

/* ---------------------------------------------------------------------- */
/* Mobile pager + status toast                                             */
/* ---------------------------------------------------------------------- */

.study-mobile-pager {
  position: fixed;
  z-index: 115;
  left: 50%;
  bottom: max(14px, env(safe-area-inset-bottom));
  min-width: 232px;
  height: 48px;
  padding: 5px;
  display: none;
  grid-template-columns: 42px minmax(120px, 1fr) 42px;
  align-items: center;
  gap: 4px;
  color: var(--study-label);
  background: var(--study-bar);
  border: 1px solid var(--study-separator);
  border-radius: 16px;
  box-shadow: var(--study-shadow-float);
  transform: translateX(-50%);
  -webkit-backdrop-filter: saturate(180%) blur(22px);
  backdrop-filter: saturate(180%) blur(22px);
}

.study-pager__button {
  width: 38px;
  height: 38px;
  padding: 0;
  display: grid;
  place-items: center;
  border-radius: 11px;
}

.study-pager__button:not(:disabled):hover {
  color: var(--study-blue);
  background: var(--study-blue-soft);
}

.study-pager__status {
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  line-height: 1.15;
}

.study-pager__status strong {
  max-width: 100%;
  overflow: hidden;
  color: var(--study-label);
  font-size: 11px;
  font-weight: 650;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.study-pager__status span {
  margin-top: 3px;
  color: var(--study-tertiary);
  font-family: var(--font-mono);
  font-size: 9px;
  font-variant-numeric: tabular-nums;
}

.study-toast {
  position: fixed;
  z-index: 300;
  left: 50%;
  bottom: 28px;
  max-width: min(420px, calc(100vw - 32px));
  padding: 10px 15px;
  color: var(--study-label);
  background: var(--study-paper-solid);
  border: 1px solid var(--study-separator);
  border-radius: 12px;
  box-shadow: var(--study-shadow-float);
  font-size: 12px;
  font-weight: 580;
  line-height: 1.4;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 12px) scale(.98);
  transition: opacity .2s ease, transform .24s var(--study-ease);
}

.study-toast.is-visible {
  opacity: 1;
  transform: translate(-50%, 0) scale(1);
}

/* ---------------------------------------------------------------------- */
/* Responsive                                                              */
/* ---------------------------------------------------------------------- */

@media (max-width: 1120px) {
  .study-appbar__inner {
    grid-template-columns: minmax(155px, .6fr) minmax(240px, 1fr) auto;
    gap: 12px;
  }

  .study-action-button {
    width: 36px;
    padding: 0;
  }

  .study-action-button__label,
  .study-mode-button__label {
    display: none;
  }

  .study-mode-button {
    padding: 0 7px;
  }
}

@media (max-width: 760px) {
  html[data-study-ui] {
    --study-appbar-height: 60px;
  }

  .study-appbar {
    padding-top: env(safe-area-inset-top);
    height: calc(var(--study-appbar-height) + env(safe-area-inset-top));
  }

  .study-appbar__inner {
    padding: 0 12px;
    display: flex;
    gap: 8px;
  }

  .study-brand {
    flex: 1;
  }

  .study-brand__mark {
    width: 30px;
    height: 30px;
    flex-basis: 30px;
    border-radius: 8px;
  }

  .study-brand__copy strong {
    font-size: 12px;
  }

  .study-brand__copy span {
    display: none;
  }

  .study-section-nav {
    display: none;
  }

  .study-actions {
    gap: 4px;
  }

  .study-action-button,
  .study-mode-switch {
    height: 34px;
  }

  .study-action-button {
    width: 34px;
    min-height: 34px;
  }

  .study-mode-switch {
    padding: 2px;
  }

  .study-mode-button {
    min-width: 29px;
    width: 29px;
    height: 28px;
    padding: 0;
  }

  .study-mode-button svg {
    width: 15px;
    height: 15px;
  }

  .study-mobile-pager {
    display: grid;
  }

  .study-toast {
    bottom: calc(76px + env(safe-area-inset-bottom));
  }

  html[data-study-ui][data-study-mode="reader"] .deck {
    width: 100% !important;
    padding: calc(var(--study-appbar-height) + env(safe-area-inset-top) + 20px) 12px 118px !important;
  }

  html[data-study-ui][data-study-mode="reader"] .slide {
    margin-bottom: 14px !important;
    padding: 30px 22px !important;
    border-radius: 20px !important;
  }

  html[data-study-ui][data-study-mode="reader"] .slide:first-child {
    padding-top: 48px !important;
    padding-bottom: 44px !important;
  }

  html[data-study-ui][data-study-mode="reader"] .slide :where(.g2, .g3, .g4, .cmp) {
    grid-template-columns: minmax(0, 1fr) !important;
    gap: 20px !important;
  }

  html[data-study-ui][data-study-mode="reader"] .slide .row {
    flex-wrap: wrap;
  }

  html[data-study-ui][data-study-mode="reader"] .slide :where(.pipe, .gantt, .packet, table.cmp-table) {
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  html[data-study-ui][data-study-mode="reader"] .slide table.cmp-table {
    display: block;
    white-space: normal;
  }

  html[data-study-ui][data-study-mode="reader"] .slide table.cmp-table :where(th, td) {
    min-width: 112px;
  }

  html[data-study-ui][data-study-mode="reader"] .slide[data-study-mastered="true"]::after {
    top: 15px;
    right: 16px;
  }

  html[data-study-ui][data-study-mode="deck"] .slide {
    padding: calc(var(--study-appbar-height) + env(safe-area-inset-top) + 24px) 28px 80px !important;
  }

  .study-toc {
    top: max(8px, env(safe-area-inset-top));
    bottom: max(8px, env(safe-area-inset-bottom));
    left: 8px;
    width: calc(100vw - 16px);
    border-radius: 20px;
  }

  .study-toc__header {
    padding: 20px 18px 16px;
  }

  .study-toc__heading h2 {
    font-size: 22px;
  }
}

@media (max-width: 430px) {
  .study-brand__copy {
    display: none;
  }

  .study-actions {
    gap: 2px;
  }

  html[data-study-ui][data-study-mode="reader"] .slide {
    padding-right: 18px !important;
    padding-left: 18px !important;
  }
}

/* ---------------------------------------------------------------------- */
/* Reduced motion + print                                                  */
/* ---------------------------------------------------------------------- */

@media (prefers-reduced-motion: reduce) {
  html[data-study-ui][data-study-mode="reader"] {
    scroll-behavior: auto;
  }

  html[data-study-ui] *,
  html[data-study-ui] *::before,
  html[data-study-ui] *::after {
    scroll-behavior: auto !important;
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
}

@media print {
  html[data-study-ui],
  html[data-study-ui] body {
    overflow: visible !important;
    background: #fff !important;
  }

  .study-appbar,
  .study-toc-layer,
  .study-mobile-pager,
  .study-toast,
  html[data-study-ui] .deck-back,
  html[data-study-ui] body > .progress-bar {
    display: none !important;
  }

  html[data-study-ui] .deck {
    width: 100% !important;
    height: auto !important;
    padding: 0 !important;
    overflow: visible !important;
  }

  html[data-study-ui] .slide {
    position: relative !important;
    inset: auto !important;
    display: block !important;
    height: auto !important;
    min-height: 0 !important;
    margin: 0 !important;
    padding: 24px !important;
    overflow: visible !important;
    opacity: 1 !important;
    pointer-events: auto !important;
    transform: none !important;
    break-after: page;
    color: #111 !important;
    background: #fff !important;
    border: 0 !important;
    border-radius: 0 !important;
    box-shadow: none !important;
  }
}
