/* selfhelp.gg Dedicated Phone-Exact SH Artistic E-Reader (Book 1: Living Story Theater)
 * Scroll-first continuous literary e-reader with smooth Auto-Scroll + Speed Adjuster,
 * high-contrast legible Chapter Selection header & sheet, 100dvw x 100dvh viewport containment,
 * zero horizontal overflow, 8 California-Wudang & IDE palettes, cedar-gold corner brackets,
 * cinnabar [SH] seal, coiled acupuncture-needle rule, Five-Organ crest, illuminated drop-cap,
 * and >= 44px touch targets.
 */

.sh-reader-root,
.sh-reader-root *,
.sh-reader-root *::before,
.sh-reader-root *::after {
  box-sizing: border-box;
}

.sh-reader-root {
  /* Default Palette: Shasta Washi (#F6EFE2) */
  --sh-r-bg: #F6EFE2;
  --sh-r-surface: #EFE4D0;
  --sh-r-surface-2: #E5D5B8;
  --sh-r-ink: #1A1511;
  --sh-r-muted: #5C4D3C;
  --sh-r-gold: #8A622E;
  --sh-r-cedar: #6D4226;
  --sh-r-cinnabar: #A62C2B;
  --sh-r-dialogue: #844306;
  --sh-r-system: #0D4B7E;
  --sh-r-somatic: #0B654A;
  --sh-r-btn-bg: rgba(138, 98, 46, 0.12);
  --sh-r-btn-active: rgba(138, 98, 46, 0.25);
  --sh-r-border: rgba(138, 98, 46, 0.48);
  --sh-r-track: rgba(109, 66, 38, 0.34);
  --sh-r-shadow: rgba(54, 34, 16, 0.22);

  /* Typography */
  --sh-font-serif: 'Iowan Old Style', 'Palatino Linotype', Georgia, 'Times New Roman', serif;
  --sh-font-sans: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --sh-font-mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --sh-r-font-family: var(--sh-font-serif);
  --sh-r-font-size: 1.25rem;
  --sh-r-line-height: 1.72;

  position: fixed;
  inset: 0;
  z-index: 30;
  width: 100dvw;
  height: 100dvh;
  max-width: 100vw;
  max-height: 100dvh;
  overflow: hidden;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
  padding: env(safe-area-inset-top, 0px) env(safe-area-inset-right, 0px) env(safe-area-inset-bottom, 0px) env(safe-area-inset-left, 0px);
  background: var(--sh-r-bg);
  color: var(--sh-r-ink);
  font-family: var(--sh-r-font-family);
  touch-action: pan-y;
  -webkit-font-smoothing: antialiased;
  color-scheme: light;
}

.sh-reader-root[hidden] {
  display: none !important;
}

/* 8 California-Wudang & Studio Palettes */
.sh-reader-root[data-reader-theme="shasta-washi"] {
  color-scheme: light;
  --sh-r-bg: #F6EFE2;
  --sh-r-surface: #EFE4D0;
  --sh-r-surface-2: #E5D5B8;
  --sh-r-ink: #1A1511;
  --sh-r-muted: #5C4D3C;
  --sh-r-gold: #8A622E;
  --sh-r-cedar: #6D4226;
  --sh-r-cinnabar: #A62C2B;
  --sh-r-dialogue: #844306;
  --sh-r-system: #0D4B7E;
  --sh-r-somatic: #0B654A;
  --sh-r-btn-bg: rgba(138, 98, 46, 0.12);
  --sh-r-btn-active: rgba(138, 98, 46, 0.25);
  --sh-r-border: rgba(138, 98, 46, 0.48);
  --sh-r-track: rgba(109, 66, 38, 0.34);
  --sh-r-shadow: rgba(54, 34, 16, 0.22);
}

.sh-reader-root[data-reader-theme="cedar-night"] {
  color-scheme: dark;
  --sh-r-bg: #14110F;
  --sh-r-surface: #1F1A16;
  --sh-r-surface-2: #2B231D;
  --sh-r-ink: #F2EAE0;
  --sh-r-muted: #BCAEA0;
  --sh-r-gold: #DFB974;
  --sh-r-cedar: #8C5A37;
  --sh-r-cinnabar: #E05A4F;
  --sh-r-dialogue: #F5CE82;
  --sh-r-system: #84D4FF;
  --sh-r-somatic: #66E6BE;
  --sh-r-btn-bg: rgba(223, 185, 116, 0.14);
  --sh-r-btn-active: rgba(223, 185, 116, 0.28);
  --sh-r-border: rgba(223, 185, 116, 0.46);
  --sh-r-track: rgba(223, 185, 116, 0.34);
  --sh-r-shadow: rgba(0, 0, 0, 0.58);
}

.sh-reader-root[data-reader-theme="pure-oled"] {
  color-scheme: dark;
  --sh-r-bg: #000000;
  --sh-r-surface: #0D0F15;
  --sh-r-surface-2: #171B26;
  --sh-r-ink: #E6ECF5;
  --sh-r-muted: #9FAAC0;
  --sh-r-gold: #DFB974;
  --sh-r-cedar: #7D5836;
  --sh-r-cinnabar: #E05A4F;
  --sh-r-dialogue: #F0D294;
  --sh-r-system: #8ECAE0;
  --sh-r-somatic: #6EE7B7;
  --sh-r-btn-bg: rgba(223, 185, 116, 0.15);
  --sh-r-btn-active: rgba(223, 185, 116, 0.30);
  --sh-r-border: rgba(223, 185, 116, 0.46);
  --sh-r-track: rgba(159, 170, 192, 0.38);
  --sh-r-shadow: rgba(0, 0, 0, 0.76);
}

.sh-reader-root[data-reader-theme="tokyo-night"] {
  color-scheme: dark;
  --sh-r-bg: #1A1B26;
  --sh-r-surface: #232638;
  --sh-r-surface-2: #2E324B;
  --sh-r-ink: #D5DCF8;
  --sh-r-muted: #9AA3CE;
  --sh-r-gold: #84AAFF;
  --sh-r-cedar: #565F89;
  --sh-r-cinnabar: #F7768E;
  --sh-r-dialogue: #E6B976;
  --sh-r-system: #7DCFFF;
  --sh-r-somatic: #73DACA;
  --sh-r-btn-bg: rgba(132, 170, 255, 0.15);
  --sh-r-btn-active: rgba(132, 170, 255, 0.28);
  --sh-r-border: rgba(132, 170, 255, 0.44);
  --sh-r-track: rgba(154, 163, 206, 0.36);
  --sh-r-shadow: rgba(8, 10, 20, 0.64);
}

.sh-reader-root[data-reader-theme="gruvbox-ember"] {
  color-scheme: dark;
  --sh-r-bg: #282828;
  --sh-r-surface: #33302F;
  --sh-r-surface-2: #3E3A37;
  --sh-r-ink: #F2E5BC;
  --sh-r-muted: #BDAE93;
  --sh-r-gold: #E3A72F;
  --sh-r-cedar: #9D5C2B;
  --sh-r-cinnabar: #FB4934;
  --sh-r-dialogue: #FABD2F;
  --sh-r-system: #83A598;
  --sh-r-somatic: #8EC07C;
  --sh-r-btn-bg: rgba(227, 167, 47, 0.15);
  --sh-r-btn-active: rgba(227, 167, 47, 0.28);
  --sh-r-border: rgba(227, 167, 47, 0.45);
  --sh-r-track: rgba(189, 174, 147, 0.36);
  --sh-r-shadow: rgba(0, 0, 0, 0.58);
}

.sh-reader-root[data-reader-theme="solarized-sepia"] {
  color-scheme: light;
  --sh-r-bg: #EDE0C8;
  --sh-r-surface: #E2D1B3;
  --sh-r-surface-2: #D6C19D;
  --sh-r-ink: #22170E;
  --sh-r-muted: #5A412C;
  --sh-r-gold: #8D5424;
  --sh-r-cedar: #784824;
  --sh-r-cinnabar: #B8332A;
  --sh-r-dialogue: #7D460B;
  --sh-r-system: #12567F;
  --sh-r-somatic: #0E614F;
  --sh-r-btn-bg: rgba(141, 84, 36, 0.12);
  --sh-r-btn-active: rgba(141, 84, 36, 0.25);
  --sh-r-border: rgba(141, 84, 36, 0.48);
  --sh-r-track: rgba(120, 72, 36, 0.34);
  --sh-r-shadow: rgba(54, 34, 16, 0.24);
}

.sh-reader-root[data-reader-theme="nord-pine"] {
  color-scheme: dark;
  --sh-r-bg: #1C2933;
  --sh-r-surface: #243542;
  --sh-r-surface-2: #2F4454;
  --sh-r-ink: #F0FAF7;
  --sh-r-muted: #B0D2CA;
  --sh-r-gold: #7FD1B5;
  --sh-r-cedar: #4B746A;
  --sh-r-cinnabar: #E07575;
  --sh-r-dialogue: #EBCB8B;
  --sh-r-system: #88C0D0;
  --sh-r-somatic: #66D9B8;
  --sh-r-btn-bg: rgba(127, 209, 181, 0.14);
  --sh-r-btn-active: rgba(127, 209, 181, 0.28);
  --sh-r-border: rgba(127, 209, 181, 0.44);
  --sh-r-track: rgba(176, 210, 202, 0.36);
  --sh-r-shadow: rgba(8, 16, 22, 0.60);
}

.sh-reader-root[data-reader-theme="starlight"] {
  color-scheme: dark;
  --sh-r-bg: #141724;
  --sh-r-surface: #1C2135;
  --sh-r-surface-2: #262C46;
  --sh-r-ink: #F2F4FC;
  --sh-r-muted: #BCC4E2;
  --sh-r-gold: #DAB568;
  --sh-r-cedar: #6D563A;
  --sh-r-cinnabar: #E0645E;
  --sh-r-dialogue: #F2C97D;
  --sh-r-system: #7DCFFF;
  --sh-r-somatic: #5CE0B8;
  --sh-r-btn-bg: rgba(218, 181, 104, 0.15);
  --sh-r-btn-active: rgba(218, 181, 104, 0.28);
  --sh-r-border: rgba(218, 181, 104, 0.45);
  --sh-r-track: rgba(188, 196, 226, 0.36);
  --sh-r-shadow: rgba(4, 6, 16, 0.64);
}

@media (forced-colors: active) {
  .sh-reader-root {
    --sh-r-bg: Canvas;
    --sh-r-surface: Canvas;
    --sh-r-ink: CanvasText;
    --sh-r-muted: GrayText;
    --sh-r-gold: Highlight;
    --sh-r-border: ButtonText;
    --sh-r-track: GrayText;
  }
}

/* Font Stacks */
.sh-reader-root[data-reader-font="serif"] {
  --sh-r-font-family: var(--sh-font-serif);
}

.sh-reader-root[data-reader-font="sans"] {
  --sh-r-font-family: var(--sh-font-sans);
}

.sh-reader-root[data-reader-font="mono"] {
  --sh-r-font-family: var(--sh-font-mono);
}

/* Strict Width Containment on All Structural Regions */
.sh-r-header,
.sh-r-main,
.sh-r-folio,
.sh-r-stage,
.sh-r-audio-bar,
.sh-r-footer,
.sh-r-sheet,
.sh-tut-pill {
  min-width: 0;
  max-width: 100%;
  overflow-x: hidden;
}

/* Prominent 3-Item Header Bar (z-index 50 > dropdown sheets z-index 49) */
.sh-r-header {
  position: relative;
  z-index: 50;
  flex: 0 0 auto;
  width: 100%;
  min-block-size: 56px;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 8px;
  background: var(--sh-r-surface);
  border-bottom: 1.5px solid var(--sh-r-border);
  font-family: var(--sh-font-sans);
}

.sh-r-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  min-height: 44px;
  min-block-size: 46px;
  min-width: 44px;
  min-inline-size: 44px;
  padding: 6px 10px;
  border-radius: 11px;
  border: 1.5px solid var(--sh-r-border);
  background: var(--sh-r-btn-bg);
  color: var(--sh-r-ink);
  font-family: var(--sh-font-sans);
  font-size: 0.9rem;
  font-weight: 650;
  line-height: 1.2;
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
  transition: background 140ms ease, border-color 140ms ease, transform 110ms ease;
}

.sh-r-btn:hover {
  border-color: var(--sh-r-gold);
  background: var(--sh-r-btn-active);
}

.sh-r-btn:active {
  transform: scale(0.98);
}

.sh-r-btn[aria-expanded="true"],
.sh-r-btn.is-active {
  border-color: var(--sh-r-gold);
  background: var(--sh-r-btn-active);
  box-shadow: 0 0 0 1.5px var(--sh-r-gold);
}

.sh-r-btn:focus-visible,
.sh-r-chip:focus-visible,
.sh-r-input:focus-visible,
.sh-r-select:focus-visible,
.sh-r-ch-item:focus-visible,
.sh-r-book-item:focus-visible {
  outline: 2.5px solid var(--sh-r-gold);
  outline-offset: 2px;
}

.sh-r-courtyard-btn {
  flex: 0 0 auto;
  padding: 6px 8px;
  font-size: 0.85rem;
}

/* High-Contrast Unmistakable Chapter Selector Pill */
.sh-r-ch-btn {
  flex: 1 1 auto;
  min-width: 0;
  min-block-size: 50px;
  justify-content: space-between;
  overflow: hidden;
  padding: 5px 11px;
  background: var(--sh-r-bg);
  border: 2px solid var(--sh-r-gold);
  color: var(--sh-r-ink);
  font-size: 1rem;
  font-weight: 750;
  box-shadow: 0 2px 8px var(--sh-r-shadow);
}

.sh-r-ch-label {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
  gap: 2px;
  overflow: hidden;
  min-width: 0;
  flex: 1 1 auto;
  text-align: start;
}

.sh-r-ch-kicker-mini {
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--sh-r-gold);
  line-height: 1.1;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sh-r-ch-name {
  font-size: 1rem;
  font-weight: 750;
  color: var(--sh-r-ink);
  line-height: 1.2;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sh-r-ch-caret {
  flex-shrink: 0;
  font-size: 1.08rem;
  color: var(--sh-r-gold);
  font-weight: 800;
  margin-inline-start: 5px;
}

.sh-r-studio-btn {
  flex: 0 0 auto;
  padding: 6px 9px;
  font-size: 0.94rem;
  font-weight: 750;
}

@media (max-width: 420px) {
  .sh-r-header {
    gap: 5px;
    padding: 5px 6px;
  }
  .sh-r-courtyard-btn .sh-r-courtyard-word,
  .sh-r-studio-btn .sh-r-studio-word {
    display: none;
  }
  .sh-r-courtyard-btn::after {
    content: "Stage";
  }
}

/* Main Reading Stage & California-Wudang Folio */
.sh-r-main {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 6px 8px 4px;
  overflow: hidden;
}

.sh-r-folio {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
  max-width: 760px;
  display: flex;
  flex-direction: column;
  padding: 12px 16px 10px;
  border-radius: 14px;
  border: 1.5px solid var(--sh-r-border);
  background: var(--sh-r-bg);
  box-shadow: 0 10px 28px var(--sh-r-shadow);
  overflow: hidden;
}

.sh-reader-root[data-reader-theme="shasta-washi"] .sh-r-folio,
.sh-reader-root[data-reader-theme="solarized-sepia"] .sh-r-folio {
  background-image:
    radial-gradient(circle at 18% 22%, rgba(143, 107, 61, 0.06) 0%, transparent 48%),
    radial-gradient(circle at 82% 78%, rgba(109, 66, 38, 0.05) 0%, transparent 52%);
}

/* Diegetic Cedar-and-Gold Corner Brackets */
.sh-corner-bracket {
  position: absolute;
  width: 14px;
  height: 14px;
  pointer-events: none;
  z-index: 2;
  border-color: var(--sh-r-gold);
  border-style: solid;
  opacity: 0.78;
}

.sh-corner-bracket.tl {
  top: 5px;
  left: 5px;
  border-width: 2px 0 0 2px;
  border-top-left-radius: 3px;
}

.sh-corner-bracket.tr {
  top: 5px;
  right: 5px;
  border-width: 2px 2px 0 0;
  border-top-right-radius: 3px;
}

.sh-corner-bracket.bl {
  bottom: 5px;
  left: 5px;
  border-width: 0 0 2px 2px;
  border-bottom-left-radius: 3px;
}

.sh-corner-bracket.br {
  bottom: 5px;
  right: 5px;
  border-width: 0 2px 2px 0;
  border-bottom-right-radius: 3px;
}

/* Folio Top Meta Strip (Organ Crest + Cinnabar [SH] Seal) */
.sh-r-folio-meta {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 6px;
  padding: 0 4px 6px;
  border-bottom: 1px dashed color-mix(in oklab, var(--sh-r-gold) 38%, transparent);
  font-family: var(--sh-font-sans);
  font-size: 0.8125rem;
  letter-spacing: 0.03em;
  color: var(--sh-r-muted);
}

.sh-organ-crest {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-weight: 700;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sh-organ-crest svg {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  color: var(--sh-r-gold);
}

.sh-cinnabar-seal {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  border: 1.5px solid var(--sh-r-cinnabar);
  color: var(--sh-r-cinnabar);
  font-family: var(--sh-font-serif);
  font-weight: 800;
  font-size: 0.78rem;
  line-height: 1;
  letter-spacing: 0.05em;
  padding: 3px 6px;
  border-radius: 4px;
  transform: rotate(-2.5deg);
  background: color-mix(in oklab, var(--sh-r-cinnabar) 8%, transparent);
}

/* Reading Stage (Continuous Smooth Scroll Default + Scrollability Affordance Shadows) */
.sh-r-stage {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
  overflow: hidden;
  overflow-x: hidden;
  font-family: var(--sh-r-font-family);
  font-size: var(--sh-r-font-size);
  line-height: var(--sh-r-line-height);
  color: var(--sh-r-ink);
  overflow-wrap: break-word;
  scroll-padding-block: 1.25rem;
}

.sh-reader-root[data-view-mode="scroll"] .sh-r-stage,
.sh-reader-root[data-view-mode="zen"] .sh-r-stage {
  overflow-y: auto;
  padding-inline: 2px 6px;
  padding-block-end: 1.5rem;
  -webkit-overflow-scrolling: touch;
  container-type: scroll-state;
  transition: padding-inline-end 160ms ease;
}

/* Reserve gutter for thumb-reachable Right-Side Auto-Scroll Speed Rail so prose is never covered */
@media (max-width: 820px) {
  .sh-reader-root.is-autoscrolling[data-view-mode="scroll"] .sh-r-stage,
  .sh-reader-root.is-autoscrolling[data-view-mode="zen"] .sh-r-stage {
    padding-inline-end: 54px;
  }
}

/* Floating Right-Side Auto-Scroll Speed Rail (0.5× – 2.0×) */
.sh-r-speed-rail {
  position: absolute;
  inset-inline-end: 6px;
  inset-block-start: 50%;
  transform: translateY(-50%);
  z-index: 38;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  padding: 6px 4px;
  border-radius: 14px;
  border: 1.5px solid var(--sh-r-gold);
  background: color-mix(in oklab, var(--sh-r-surface) 92%, transparent);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  box-shadow: 0 8px 24px var(--sh-r-shadow);
  font-family: var(--sh-font-sans);
}

.sh-r-speed-rail[hidden] {
  display: none !important;
}

.sh-r-rail-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  min-height: 44px;
  width: 44px;
  height: 44px;
  padding: 0;
  border-radius: 11px;
  border: 1.5px solid var(--sh-r-border);
  background: var(--sh-r-bg);
  color: var(--sh-r-ink);
  font-family: var(--sh-font-sans);
  font-size: 1.18rem;
  font-weight: 800;
  line-height: 1;
  cursor: pointer;
  touch-action: manipulation;
  transition: background 120ms ease, border-color 120ms ease, transform 90ms ease;
}

.sh-r-rail-btn:hover:not(:disabled) {
  border-color: var(--sh-r-gold);
  background: var(--sh-r-btn-active);
}

.sh-r-rail-btn:active:not(:disabled) {
  transform: scale(0.95);
}

.sh-r-rail-btn:disabled {
  opacity: 0.42;
  cursor: default;
}

.sh-r-rail-btn.is-pause {
  font-size: 0.96rem;
  border-color: var(--sh-r-gold);
  background: var(--sh-r-btn-active);
}

.sh-r-rail-readout {
  font-size: 0.78rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  color: var(--sh-r-gold);
  padding: 2px 3px;
  line-height: 1.15;
  text-align: center;
  user-select: none;
}

.sh-reader-root[data-view-mode="scroll"] .sh-r-stage::before,
.sh-reader-root[data-view-mode="scroll"] .sh-r-stage::after {
  content: "";
  display: block;
  position: sticky;
  block-size: 0.85rem;
  z-index: 2;
  pointer-events: none;
  opacity: 0;
  transition: opacity 180ms ease;
}

.sh-reader-root[data-view-mode="scroll"] .sh-r-stage::before {
  inset-block-start: 0;
  margin-block-end: -0.85rem;
  background: radial-gradient(farthest-side at 50% 0, rgba(0, 0, 0, 0.18), transparent);
}

.sh-reader-root[data-view-mode="scroll"] .sh-r-stage::after {
  inset-block-end: 0;
  margin-block-start: -0.85rem;
  background: radial-gradient(farthest-side at 50% 100%, rgba(0, 0, 0, 0.18), transparent);
}

@container scroll-state(scrollable: block-start) {
  .sh-reader-root[data-view-mode="scroll"] .sh-r-stage::before {
    opacity: 1;
  }
}

@container scroll-state(scrollable: block-end) {
  .sh-reader-root[data-view-mode="scroll"] .sh-r-stage::after {
    opacity: 1;
  }
}

@supports not (container-type: scroll-state) {
  @supports (animation-timeline: scroll()) {
    .sh-reader-root[data-view-mode="scroll"] .sh-r-stage::before,
    .sh-reader-root[data-view-mode="scroll"] .sh-r-stage::after {
      animation: sh-scroll-shadow-fade linear both;
      animation-timeline: scroll(nearest block);
    }

    .sh-reader-root[data-view-mode="scroll"] .sh-r-stage::before {
      animation-range: 0px 2rem;
    }

    .sh-reader-root[data-view-mode="scroll"] .sh-r-stage::after {
      animation-direction: reverse;
      animation-range: calc(100% - 2rem) 100%;
    }
  }
}

@keyframes sh-scroll-shadow-fade {
  from { opacity: 0; }
  to { opacity: 1; }
}

.sh-reader-root[data-view-mode="scroll"] .sh-r-stage.more-start::before,
.sh-reader-root[data-view-mode="scroll"] .sh-r-stage.more-end::after {
  opacity: 1;
}

/* Offscreen Measurer (strictly inside overflow:hidden root so scrollWidth never grows) */
.sh-r-measurer {
  position: absolute;
  top: 0;
  left: 0;
  visibility: hidden;
  pointer-events: none;
  z-index: -1;
  font-family: var(--sh-r-font-family);
  font-size: var(--sh-r-font-size);
  line-height: var(--sh-r-line-height);
  overflow-wrap: break-word;
}

/* Chapter Opening Banner + Coiled Acupuncture-Needle Rule */
.sh-r-chapter-head {
  max-inline-size: 62ch;
  margin: 0 auto 1rem;
  text-align: center;
  padding: 6px 4px 10px;
}

.sh-r-ch-kicker {
  font-family: var(--sh-font-sans);
  font-size: 0.78rem;
  font-weight: 750;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--sh-r-gold);
  margin-bottom: 4px;
}

.sh-r-ch-title {
  margin: 0 0 8px;
  font-family: var(--sh-font-serif);
  font-size: clamp(1.3rem, 1rem + 2.2vw, 1.75rem);
  line-height: 1.26;
  font-weight: 750;
  color: var(--sh-r-ink);
  text-wrap: balance;
}

.sh-needle-rule {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  margin: 4px auto 2px;
  color: var(--sh-r-gold);
}

.sh-needle-rule svg {
  width: min(220px, 74%);
  height: 16px;
  display: block;
}

/* Prose Paragraphs, Calm Cognitive-Load Measure & Semantic Highlighting */
.sh-r-para {
  max-inline-size: 62ch;
  margin: 0 auto 0.95em;
  text-align: start;
  text-wrap: pretty;
  transition: background 180ms ease, border-color 180ms ease;
  border-radius: 6px;
}

.sh-r-para:last-child {
  margin-bottom: 0;
}

.sh-r-para.is-cont {
  text-indent: 0;
}

.sh-r-para.is-break {
  text-align: center;
  color: var(--sh-r-gold);
  font-weight: 700;
  letter-spacing: 0.25em;
  margin: 0.85em auto;
}

.sh-r-para.is-audio-active {
  background: color-mix(in oklab, var(--sh-r-gold) 16%, transparent);
  padding: 4px 8px;
  border-left: 3px solid var(--sh-r-cinnabar);
}

.sh-drop-cap::first-letter,
.sh-para-opening::first-letter {
  float: left;
  font-family: var(--sh-font-serif);
  font-size: 3.05em;
  line-height: 0.86;
  font-weight: 700;
  padding: 4px 8px 2px 6px;
  margin: 2px 9px 0 0;
  border: 1px solid var(--sh-r-gold);
  border-radius: 4px;
  color: var(--sh-r-cinnabar);
  background: color-mix(in oklab, var(--sh-r-gold) 12%, transparent);
}

.sh-syn-dialogue {
  color: var(--sh-r-dialogue);
}

.sh-syn-system {
  color: var(--sh-r-system);
  font-family: var(--sh-font-mono);
  font-size: 0.9em;
}

.sh-syn-somatic {
  color: var(--sh-r-somatic);
  font-weight: 700;
}

.sh-bionic-lead {
  font-weight: 700;
}

/* End-of-Chapter Continuous Scroll Card */
.sh-r-end-chapter-card {
  max-inline-size: 62ch;
  margin: 1.6rem auto 0.5rem;
  padding: 14px;
  border-radius: 12px;
  border: 1.5px dashed var(--sh-r-border);
  background: var(--sh-r-surface);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-family: var(--sh-font-sans);
  font-size: 0.95rem;
}

/* Audio Mini-Bar */
.sh-r-audio-bar {
  flex: 0 0 auto;
  width: 100%;
  max-width: 760px;
  margin: 0 auto 4px;
  padding: 5px 8px;
  border-radius: 10px;
  border: 1px solid var(--sh-r-border);
  background: var(--sh-r-surface);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  font-family: var(--sh-font-sans);
  font-size: 0.85rem;
}

.sh-r-audio-bar[hidden] {
  display: none !important;
}

.sh-r-audio-time {
  font-variant-numeric: tabular-nums;
  color: var(--sh-r-muted);
  font-size: 0.82rem;
  font-weight: 600;
  white-space: nowrap;
}

/* Footer Scroll / Auto-Scroll + Speed Adjuster Bar */
.sh-r-footer {
  flex: 0 0 auto;
  width: 100%;
  min-block-size: 54px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  padding: 5px 8px;
  background: var(--sh-r-surface);
  border-top: 1.5px solid var(--sh-r-border);
  font-family: var(--sh-font-sans);
}

.sh-r-nav-edge {
  padding: 6px 8px;
  font-size: 0.86rem;
}

.sh-r-autoscroll-group {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  flex: 1 1 auto;
  min-width: 0;
}

.sh-r-autoscroll-group[hidden],
.sh-r-footer-mid[hidden] {
  display: none !important;
}

.sh-r-auto-btn {
  padding: 6px 10px;
  font-size: 0.88rem;
  font-weight: 750;
}

.sh-r-speed-wrap {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: 1 1 auto;
  min-width: 0;
  max-width: 210px;
}

.sh-r-speed-val {
  font-size: 0.84rem;
  font-weight: 750;
  font-variant-numeric: tabular-nums;
  color: var(--sh-r-ink);
  min-inline-size: 3.1ch;
  text-align: end;
  flex-shrink: 0;
}

/* Brand-Consistent Native Range Slider (WebKit + Firefox separate blocks + progress() fallback) */
input[type="range"].sh-r-speed-slider {
  --slider-track-size: 0.45rem;
  --slider-thumb-size: 1.25rem;
  --slider-track-radius: 999px;
  --slider-thumb-radius: 50%;
  --slider-track-color: var(--sh-r-track);
  --slider-fill-color: var(--sh-r-gold);
  --slider-thumb-color: var(--sh-r-cinnabar);
  --slider-direction: to right;
  --attr-min: 0.5;
  --attr-max: 2;
  --control-value: 1;
  --slider-progress: calc(progress(var(--control-value), var(--attr-min), var(--attr-max)) * 100%);

  appearance: none;
  flex: 1 1 56px;
  min-inline-size: 52px;
  inline-size: 100%;
  block-size: 2.75rem;
  min-height: 44px;
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
  cursor: pointer;
}

input[type="range"].sh-r-speed-slider:dir(rtl) {
  --slider-direction: to left;
}

@supports not (opacity: progress(1, 0, 100)) {
  input[type="range"].sh-r-speed-slider {
    --slider-progress: calc(
      (var(--control-value) - var(--attr-min)) /
      (var(--attr-max) - var(--attr-min)) * 100%
    );
  }
}

input[type="range"].sh-r-speed-slider::-webkit-slider-runnable-track {
  block-size: var(--slider-track-size);
  border: 1px solid var(--sh-r-border);
  border-radius: var(--slider-track-radius);
  background: linear-gradient(
    var(--slider-direction),
    var(--slider-fill-color) var(--slider-progress),
    var(--slider-track-color) var(--slider-progress)
  );
}

input[type="range"].sh-r-speed-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  inline-size: var(--slider-thumb-size);
  block-size: var(--slider-thumb-size);
  margin-block-start: calc((var(--slider-track-size) - var(--slider-thumb-size)) / 2 - 1px);
  border: 2px solid var(--sh-r-bg);
  border-radius: var(--slider-thumb-radius);
  background: var(--slider-thumb-color);
  box-shadow: 0 1px 4px var(--sh-r-shadow);
}

input[type="range"].sh-r-speed-slider::-moz-range-track {
  block-size: var(--slider-track-size);
  border: 1px solid var(--sh-r-border);
  border-radius: var(--slider-track-radius);
  background: var(--slider-track-color);
}

input[type="range"].sh-r-speed-slider::-moz-range-progress {
  block-size: var(--slider-track-size);
  border-radius: var(--slider-track-radius);
  background: var(--slider-fill-color);
}

input[type="range"].sh-r-speed-slider::-moz-range-thumb {
  inline-size: var(--slider-thumb-size);
  block-size: var(--slider-thumb-size);
  border: 2px solid var(--sh-r-bg);
  border-radius: var(--slider-thumb-radius);
  background: var(--slider-thumb-color);
}

input[type="range"].sh-r-speed-slider:focus-visible {
  outline: 2.5px solid var(--sh-r-gold);
  outline-offset: 3px;
  border-radius: 6px;
}

.sh-r-page-ind {
  font-size: 0.88rem;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
  color: var(--sh-r-muted);
  white-space: nowrap;
  text-align: center;
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sh-r-footer-mid {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  flex: 1 1 auto;
  min-width: 0;
}

.sh-r-progress-track {
  flex: 0 0 auto;
  width: 100%;
  height: 4px;
  background: color-mix(in oklab, var(--sh-r-gold) 20%, transparent);
}

.sh-r-progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--sh-r-cinnabar), var(--sh-r-gold));
  transition: width 120ms linear;
}

/* Zen Mode */
.sh-reader-root.is-zen .sh-r-header,
.sh-reader-root.is-zen .sh-r-audio-bar,
.sh-reader-root.is-zen .sh-r-footer {
  display: none !important;
}

.sh-r-zen-exit {
  position: fixed;
  top: calc(10px + env(safe-area-inset-top, 0px));
  right: calc(10px + env(safe-area-inset-right, 0px));
  z-index: 46;
  min-height: 44px;
  min-block-size: 46px;
  padding: 6px 14px;
  border-radius: 999px;
  border: 1.5px solid var(--sh-r-gold);
  background: var(--sh-r-surface);
  color: var(--sh-r-ink);
  font-family: var(--sh-font-sans);
  font-size: 0.88rem;
  font-weight: 750;
  cursor: pointer;
  box-shadow: 0 6px 18px var(--sh-r-shadow);
}

.sh-r-zen-exit[hidden] {
  display: none !important;
}

/* Dropdown Sheets (z-index 49 sits BELOW header z-index 50 so header buttons remain 1-tap clickable) */
.sh-r-sheet {
  position: absolute;
  top: calc(60px + env(safe-area-inset-top, 0px));
  left: 8px;
  right: 8px;
  width: auto;
  max-width: calc(100vw - 16px);
  max-height: calc(100dvh - 122px - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px));
  margin: 0 auto;
  overflow-y: auto;
  overflow-x: hidden;
  z-index: 49;
  padding: 14px 14px 20px;
  border-radius: 14px;
  border: 2px solid var(--sh-r-gold);
  background: var(--sh-r-surface);
  color: var(--sh-r-ink);
  box-shadow: 0 18px 48px var(--sh-r-shadow);
  font-family: var(--sh-font-sans);
}

.sh-r-sheet[hidden] {
  display: none !important;
}

@media (min-width: 768px) {
  .sh-r-sheet {
    max-width: 580px;
  }
}

.sh-r-sheet-head {
  position: sticky;
  top: -14px;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding-top: 2px;
  padding-bottom: 8px;
  margin-bottom: 10px;
  background: var(--sh-r-surface);
}

.sh-r-tabs {
  display: flex;
  gap: 6px;
  flex: 1 1 auto;
  min-width: 0;
}

.sh-r-tab {
  flex: 1 1 0;
  min-height: 44px;
  min-block-size: 46px;
  padding: 6px 10px;
  border-radius: 10px;
  border: 1.5px solid var(--sh-r-border);
  background: var(--sh-r-bg);
  color: var(--sh-r-ink);
  font-size: 0.94rem;
  font-weight: 750;
  cursor: pointer;
}

.sh-r-tab.is-active {
  border-color: var(--sh-r-gold);
  background: var(--sh-r-btn-active);
}

.sh-r-section {
  margin-bottom: 14px;
}

.sh-r-section:last-child {
  margin-bottom: 0;
}

.sh-r-label {
  display: block;
  font-size: 0.8rem;
  font-weight: 750;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--sh-r-muted);
  margin-bottom: 7px;
}

.sh-r-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 7px;
}

.sh-r-grid-3 {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 7px;
}

.sh-r-grid-4 {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 6px;
}

.sh-r-chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 44px;
  min-block-size: 46px;
  padding: 6px 8px;
  border-radius: 10px;
  border: 1.5px solid var(--sh-r-border);
  background: var(--sh-r-bg);
  color: var(--sh-r-ink);
  font-size: 0.88rem;
  font-weight: 650;
  line-height: 1.2;
  cursor: pointer;
  text-align: center;
  min-width: 0;
  overflow-wrap: break-word;
}

.sh-r-chip.is-active {
  border-color: var(--sh-r-gold);
  background: var(--sh-r-btn-active);
  box-shadow: inset 0 0 0 1px var(--sh-r-gold);
}

.sh-r-swatch {
  width: 15px;
  height: 15px;
  border-radius: 50%;
  border: 1px solid var(--sh-r-gold);
  flex-shrink: 0;
}

.sh-r-ch-list,
.sh-r-book-list {
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.sh-r-ch-item,
.sh-r-book-item {
  width: 100%;
  min-height: 44px;
  min-block-size: 50px;
  padding: 9px 12px;
  border-radius: 11px;
  border: 1.5px solid var(--sh-r-border);
  background: var(--sh-r-bg);
  color: var(--sh-r-ink);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-size: 0.98rem;
  font-weight: 650;
  line-height: 1.32;
  text-align: start;
  cursor: pointer;
}

.sh-r-ch-item.is-active,
.sh-r-book-item.is-active {
  border-color: var(--sh-r-gold);
  background: var(--sh-r-btn-active);
  box-shadow: inset 0 0 0 1px var(--sh-r-gold);
}

.sh-r-badge {
  font-size: 0.78rem;
  font-weight: 750;
  padding: 3px 8px;
  border-radius: 999px;
  border: 1px solid var(--sh-r-border);
  color: var(--sh-r-muted);
  flex-shrink: 0;
}

.sh-r-badge.is-open {
  border-color: var(--sh-r-somatic);
  color: var(--sh-r-somatic);
}

.sh-r-unlock-box {
  margin-top: 10px;
  padding: 12px;
  border-radius: 12px;
  border: 1.5px solid var(--sh-r-border);
  background: var(--sh-r-bg);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.sh-r-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.sh-r-input,
.sh-r-select {
  min-height: 44px;
  min-block-size: 46px;
  flex: 1 1 140px;
  min-width: 0;
  padding: 8px 11px;
  border-radius: 10px;
  border: 1.5px solid var(--sh-r-border);
  background: var(--sh-r-surface);
  color: var(--sh-r-ink);
  font-family: var(--sh-font-sans);
  font-size: 0.94rem;
}

.sh-r-status-msg {
  font-size: 0.88rem;
  line-height: 1.42;
  color: var(--sh-r-muted);
}

.sh-r-status-msg.is-ok {
  color: var(--sh-r-somatic);
  font-weight: 650;
}

.sh-r-status-msg.is-err {
  color: var(--sh-r-cinnabar);
  font-weight: 650;
}

/* Gate 1 SH Silent-First Tutorial Pill (non-overlapping flex slot above footer) */
.sh-tut-pill {
  position: relative;
  flex: 0 0 auto;
  width: calc(100% - 16px);
  max-width: 760px;
  margin: 0 auto 4px;
  z-index: 47;
  padding: 8px 11px;
  border-radius: 13px;
  border: 2px solid var(--sh-r-gold);
  background: var(--sh-r-surface);
  color: var(--sh-r-ink);
  box-shadow: 0 8px 22px var(--sh-r-shadow);
  font-family: var(--sh-font-sans);
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.sh-reader-root.is-zen .sh-tut-pill,
.sh-reader-root.is-zen .sh-r-progress-track {
  display: none !important;
}

.sh-tut-pill[hidden] {
  display: none !important;
}

.sh-tut-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
}

.sh-tut-think {
  font-size: 1.1rem;
  line-height: 1.2;
  flex-shrink: 0;
}

.sh-tut-lines {
  flex: 1 1 auto;
  min-width: 0;
  font-size: 0.92rem;
  line-height: 1.38;
}

.sh-tut-line1 {
  font-weight: 750;
}

.sh-tut-line2 {
  color: var(--sh-r-muted);
}

.sh-tut-line2[hidden] {
  display: none !important;
}

.sh-tut-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}

.sh-tut-beat-tag {
  font-size: 0.78rem;
  font-weight: 750;
  color: var(--sh-r-gold);
  letter-spacing: 0.04em;
}

.sh-tut-btns {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
