:root {
  --bg-page: #F3ECDC;
  --bg-paper: #F7F1E3;
  --bg-surface: #FAF6EC;
  --bg-subtle: #EAE1CE;
  --border-soft: #DCD1BA;
  --ink-primary: #152238;
  --ink-muted: #4A5B75;
  --accent: #1D6FE2;
  --accent-hover: #1558BA;
  --accent-soft: #E5F0FF;
  --active-coral: #EA5B38;
  --active-coral-hover: #CF4624;
  --shadow-card: 0 8px 24px rgba(21, 34, 56, 0.08);
  --shadow-hover: 0 14px 32px rgba(21, 34, 56, 0.14);
  --radius-md: 14px;
  --radius-lg: 20px;
  --font-sans: "Nunito", "Segoe UI", "PingFang TC", "Microsoft JhengHei", sans-serif;

  /* 3-size body scale discipline */
  --text-heading: clamp(1.25rem, 1.08rem + 0.65vw, 1.625rem);
  --text-body: 1.0625rem;
  --text-sm: 0.9375rem;
}

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

html,
body {
  width: 100%;
  margin: 0;
  padding: 0;
  overflow-x: clip;
  background-color: var(--bg-page);
  color: var(--ink-primary);
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

[hidden] {
  display: none !important;
}

.visually-hidden:where(:not(:focus-within, :active)) {
  position: absolute !important;
  clip-path: inset(50%) !important;
  overflow: hidden !important;
  width: 1px !important;
  height: 1px !important;
  margin: -1px !important;
  padding: 0 !important;
  border: 0 !important;
  white-space: nowrap !important;
}

.skip-link:focus {
  position: fixed;
  top: 12px;
  left: 12px;
  z-index: 100;
  padding: 10px 16px;
  border-radius: 10px;
  background: var(--ink-primary);
  color: #FFFFFF;
  font-weight: 700;
  text-decoration: none;
}

:where(a, button, input, select, [tabindex]):focus-visible {
  outline: 3px solid var(--ink-primary);
  outline-offset: 3px;
}

/* Desktop 70% centered container */
.container {
  width: 70%;
  max-width: 1180px;
  margin-inline: auto;
}

/* ---------- Bookshelf View ---------- */
.site-header {
  position: sticky;
  top: 0;
  z-index: 20;
  background-color: var(--bg-page);
  border-bottom: 1px solid var(--border-soft);
  padding-top: env(safe-area-inset-top, 0px);
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding-block: 16px;
}

.brand-group {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-icon {
  width: 38px;
  height: 38px;
  flex-shrink: 0;
}

.site-title {
  margin: 0;
  font-size: clamp(1.375rem, 1.15rem + 1vw, 1.875rem);
  font-weight: 800;
  letter-spacing: -0.02em;
  line-height: 1.2;
}

.shelf-summary {
  margin: 0;
  font-size: var(--text-body);
  color: var(--ink-muted);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.shelf-main {
  padding-block: 24px 56px;
}

/* Home Reading Guide (<details> disclosure) */
.guide-card {
  margin-bottom: 22px;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-soft);
  background: var(--bg-surface);
  box-shadow: var(--shadow-card);
  overflow: hidden;
}

.guide-summary {
  list-style: none;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 14px 18px;
  cursor: pointer;
  user-select: none;
  color: var(--ink-primary);
  font-size: var(--text-body);
  font-weight: 800;
  transition: background-color 150ms ease-out;
}

.guide-summary::-webkit-details-marker {
  display: none;
}

.guide-summary::before {
  content: "";
  inline-size: 1em;
  block-size: 1em;
  flex-shrink: 0;
  background-color: var(--accent);
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.6' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E") no-repeat center / contain;
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.6' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E") no-repeat center / contain;
  rotate: -90deg;
}

.guide-card[open] > .guide-summary::before {
  rotate: 0deg;
}

.guide-summary:hover {
  background: rgba(234, 225, 206, 0.45);
}

.guide-summary-hint {
  margin-inline-start: auto;
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--ink-muted);
}

.guide-card:not([open]) .guide-summary-hint {
  visibility: hidden;
}

.guide-card::details-content {
  interpolate-size: allow-keywords;
  overflow: clip;
  contain: layout;
}

.guide-card:not([open])::details-content {
  block-size: 0;
}

@media (prefers-reduced-motion: no-preference) {
  .guide-summary::before {
    transition: rotate 200ms ease-out;
  }

  .guide-card::details-content {
    transition: block-size, content-visibility, display;
    transition-duration: 240ms;
    transition-timing-function: ease-in-out;
    transition-behavior: allow-discrete;
  }
}

.guide-body {
  padding: 0 18px 18px;
  border-top: 1px solid var(--border-soft);
}

.guide-steps {
  list-style: none;
  margin: 14px 0 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}

.guide-step {
  padding: 12px 14px;
  border-radius: var(--radius-md);
  background: var(--bg-page);
  border: 1px solid var(--border-soft);
}

.guide-step-title {
  margin: 0 0 6px;
  font-size: var(--text-body);
  font-weight: 800;
  color: var(--ink-primary);
}

.guide-step-desc {
  margin: 0;
  font-size: var(--text-sm);
  color: var(--ink-muted);
  line-height: 1.55;
}

.shelf-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 24px;
}

.search-field {
  flex: 1 1 260px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}

.search-label {
  font-size: var(--text-body);
  font-weight: 700;
  color: var(--ink-primary);
}

.search-input {
  flex: 1 1 200px;
  max-width: 340px;
  min-block-size: 48px;
  padding: 10px 16px;
  border: 2px solid var(--border-soft);
  border-radius: var(--radius-md);
  background: var(--bg-surface);
  color: var(--ink-primary);
  font-family: inherit;
  font-size: var(--text-body);
  transition: border-color 160ms ease-out, box-shadow 160ms ease-out;
}

.search-input:focus {
  border-color: var(--accent);
}

.shelf-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
}

.shelf-filter {
  margin: 0;
  padding: 0;
  border: 0;
}

.shelf-segmented {
  display: inline-grid;
  grid-template-columns: auto auto;
}

.shelf-segmented label {
  padding: 7px 14px;
  min-block-size: 40px;
  white-space: nowrap;
}

.btn-playlist {
  white-space: nowrap;
}

.book-grid {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 24px;
}

.book-card {
  position: relative;
}

.book-card-btn {
  width: 100%;
  display: flex;
  flex-direction: column;
  padding: 0;
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-lg);
  background: var(--bg-surface);
  color: inherit;
  text-align: left;
  cursor: pointer;
  overflow: hidden;
  box-shadow: var(--shadow-card);
  transition: transform 180ms cubic-bezier(0.22, 1, 0.36, 1), box-shadow 180ms ease-out, border-color 180ms ease-out;
}

.book-card-btn:hover {
  transform: translateY(-4px);
  box-shadow: var(--shadow-hover);
  border-color: var(--accent);
}

.book-card-btn:active {
  transform: translateY(-1px) scale(0.98);
}

.book-cover-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 2 / 3;
  padding: 6px;
  background: var(--bg-paper);
  overflow: hidden;
}

.book-cover-img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  object-position: center;
  mix-blend-mode: multiply;
  display: block;
}

/* Subtle read-count stars on bottom-left corner of cover */
.read-stars {
  position: absolute;
  left: 10px;
  bottom: 10px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 9px;
  border-radius: 999px;
  background: rgba(21, 34, 56, 0.84);
  color: #FFD43B;
  font-size: var(--text-sm);
  font-weight: 800;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  pointer-events: none;
}

.read-stars svg {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
}

/* Favorite toggle button positioned cleanly as sibling of book-card-btn */
.fav-btn {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 2;
  min-inline-size: 40px;
  min-block-size: 40px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  border: 1px solid rgba(21, 34, 56, 0.14);
  background: var(--bg-surface);
  color: var(--ink-muted);
  cursor: pointer;
  box-shadow: 0 3px 10px rgba(21, 34, 56, 0.14);
  -webkit-tap-highlight-color: transparent;
  transition: transform 150ms ease-out, background-color 150ms ease-out, color 150ms ease-out, border-color 150ms ease-out;
}

.fav-btn svg {
  width: 20px;
  height: 20px;
}

.fav-btn:hover {
  transform: scale(1.08);
  background: var(--bg-surface);
  color: var(--active-coral);
  border-color: rgba(234, 91, 56, 0.45);
}

.fav-btn:active {
  transform: scale(0.94);
}

.fav-btn[aria-pressed="true"] {
  background: var(--active-coral);
  border-color: var(--active-coral);
  color: #FFFFFF;
}

.fav-btn[aria-pressed="true"]:hover {
  background: var(--active-coral-hover);
  color: #FFFFFF;
}

.book-card-meta {
  padding: 14px 16px 16px;
}

.book-card-title {
  margin: 0 0 4px;
  font-size: var(--text-heading);
  font-weight: 800;
  color: var(--ink-primary);
  line-height: 1.25;
}

.book-card-stats {
  margin: 0;
  font-size: var(--text-sm);
  color: var(--ink-muted);
  font-variant-numeric: tabular-nums;
}

.shelf-empty {
  margin: 40px 0;
  font-size: var(--text-body);
  color: var(--ink-muted);
}

.shelf-footer {
  margin-top: 40px;
  padding-top: 20px;
  border-top: 1px solid var(--border-soft);
}

.footer-note {
  margin: 0;
  font-size: var(--text-sm);
  color: var(--ink-muted);
  max-width: 65ch;
}

.footer-note code {
  padding: 2px 6px;
  border-radius: 6px;
  background: var(--bg-subtle);
  color: var(--ink-primary);
  font-size: 0.9em;
}

/* ---------- Reader View (Image-First Focus Stage) ---------- */
.reader-view {
  position: relative;
  width: 100%;
  min-height: 100dvh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg-page);
  transition: opacity 260ms ease-out;
}

.reader-view.is-fading-out {
  opacity: 0;
  pointer-events: none;
}

.view.is-fading-in {
  animation: shelfFadeIn 260ms ease-out both;
}

@keyframes shelfFadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

/* Floating top-right controls locked inside reader-view (never drifts off-screen on iPad) */
.reader-top-actions {
  position: absolute;
  top: calc(14px + env(safe-area-inset-top, 0px));
  right: calc(14px + env(safe-area-inset-right, 0px));
  z-index: 30;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.drawer-trigger {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-block-size: 48px;
  padding: 8px 14px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-soft);
  background: var(--bg-surface);
  color: var(--ink-primary);
  font-family: inherit;
  font-size: var(--text-sm);
  font-weight: 700;
  cursor: pointer;
  box-shadow: var(--shadow-card);
  opacity: 0.92;
  -webkit-tap-highlight-color: transparent;
  transition: opacity 160ms ease-out, background-color 160ms ease-out, border-color 160ms ease-out, box-shadow 160ms ease-out, scale 150ms ease-out;
}

.home-trigger {
  min-inline-size: 48px;
  padding: 8px;
}

.drawer-trigger svg {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
}

.drawer-trigger:hover,
.drawer-trigger:focus-visible {
  opacity: 1;
  background: var(--bg-surface);
  border-color: var(--accent);
  box-shadow: var(--shadow-hover);
}

.drawer-trigger:active {
  scale: 0.96;
}

.reader-view.is-auto-reading .drawer-trigger {
  opacity: 0.42;
  border-color: rgba(234, 91, 56, 0.5);
  color: var(--active-coral);
}

.reader-view.is-auto-reading .drawer-trigger:hover,
.reader-view.is-auto-reading .drawer-trigger:focus-visible {
  opacity: 1;
  border-color: var(--active-coral);
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-block-size: 48px;
  min-inline-size: 48px;
  padding: 10px 16px;
  border-radius: var(--radius-md);
  border: 2px solid transparent;
  font-family: inherit;
  font-size: var(--text-body);
  font-weight: 700;
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  transition: background-color 160ms ease-out, border-color 160ms ease-out, box-shadow 160ms ease-out, scale 150ms ease-out;
}

.btn svg {
  width: 22px;
  height: 22px;
  flex-shrink: 0;
}

.btn:active:not(:disabled) {
  scale: 0.97;
}

.btn:disabled {
  opacity: 0.42;
  cursor: not-allowed;
}

.btn-full {
  width: 100%;
}

.btn-icon-close {
  padding: 8px;
  min-inline-size: 44px;
  min-block-size: 44px;
}

.btn-primary {
  background: var(--accent);
  color: #FFFFFF;
}

.btn-primary:hover:not(:disabled) {
  background: var(--accent-hover);
  box-shadow: 0 4px 14px rgba(29, 111, 226, 0.3);
}

.btn-primary.is-speaking {
  background: var(--active-coral);
}

.btn-primary.is-speaking:hover:not(:disabled) {
  background: var(--active-coral-hover);
}

.btn-auto {
  background: var(--accent-soft);
  color: var(--accent);
  border-color: #BBD4FA;
}

.btn-auto:hover:not(:disabled) {
  background: #D6E7FF;
  box-shadow: 0 3px 10px rgba(29, 111, 226, 0.16);
}

.btn-auto[aria-pressed="true"] {
  background: var(--active-coral);
  color: #FFFFFF;
  border-color: var(--active-coral);
}

.btn-auto[aria-pressed="true"]:hover:not(:disabled) {
  background: var(--active-coral-hover);
}

.btn-secondary {
  background: var(--bg-surface);
  color: var(--ink-primary);
  border-color: var(--border-soft);
}

.btn-secondary:hover:not(:disabled) {
  background: var(--bg-subtle);
  box-shadow: 0 2px 8px rgba(21, 34, 56, 0.1);
}

/* ---------- Book Stage ---------- */
.reader-main {
  flex: 1;
  min-height: 0;
  width: 100%;
  display: flex;
  align-items: stretch;
  justify-content: center;
  padding:
    calc(14px + env(safe-area-inset-top, 0px))
    calc(16px + env(safe-area-inset-right, 0px))
    calc(14px + env(safe-area-inset-bottom, 0px))
    calc(16px + env(safe-area-inset-left, 0px));
}

.reader-stage-shell {
  width: 100%;
  max-width: 1360px;
  height: 100%;
  min-height: 0;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 16px;
}

.reader-view.is-auto-reading .reader-stage-shell {
  grid-template-columns: 1fr;
  gap: 0;
}

.reader-view.is-auto-reading .stage-arrow {
  display: none;
}

.stage-arrow {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-inline-size: 52px;
  min-block-size: 76px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-soft);
  background: var(--bg-surface);
  color: var(--ink-primary);
  cursor: pointer;
  box-shadow: var(--shadow-card);
  transition: background-color 160ms ease-out, box-shadow 160ms ease-out, scale 150ms ease-out;
}

.stage-arrow svg {
  width: 28px;
  height: 28px;
}

.stage-arrow:hover:not(:disabled) {
  background: var(--accent-soft);
  color: var(--accent);
  box-shadow: var(--shadow-hover);
}

.stage-arrow:active:not(:disabled) {
  scale: 0.95;
}

.stage-arrow:disabled {
  opacity: 0.26;
  cursor: not-allowed;
}

.stage-viewport {
  width: 100%;
  height: 100%;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.page-frame {
  position: relative;
  border-radius: 12px;
  background: var(--bg-paper);
  box-shadow:
    0 14px 36px rgba(21, 34, 56, 0.14),
    3px 0 0 #EDE4CE,
    4px 0 0 rgba(21, 34, 56, 0.08),
    6px 2px 0 #E4D8BD,
    7px 2px 0 rgba(21, 34, 56, 0.06);
  overflow: visible;
}

.page-surface {
  position: relative;
  width: 100%;
  height: 100%;
  border-radius: 12px;
  background: var(--bg-paper);
  isolation: isolate;
  overflow: hidden;
}

/* Subtle left book-spine binding crease */
.page-surface::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 18px;
  background: linear-gradient(90deg, rgba(45, 32, 16, 0.1) 0%, rgba(45, 32, 16, 0.03) 45%, transparent 100%);
  pointer-events: none;
  z-index: 2;
}

.page-image {
  display: block;
  width: 100%;
  height: 100%;
  user-select: none;
  mix-blend-mode: multiply;
}

/* Real-time curved paper-curl Canvas overlay */
.page-flip-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 6;
}

.page-curl-canvas {
  position: absolute;
  display: block;
  pointer-events: none;
}

/* On-page clickable word overlays */
.word-layer {
  position: absolute;
  inset: 0;
}

.word-hotspot {
  position: absolute;
  padding: 0;
  border: 2.5px solid transparent;
  border-radius: 10px;
  background: transparent;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background-color 140ms ease-out, border-color 140ms ease-out, box-shadow 140ms ease-out, transform 150ms cubic-bezier(0.22, 1, 0.36, 1);
}

.word-hotspot:hover {
  background: rgba(255, 212, 59, 0.36);
  mix-blend-mode: multiply;
  border-color: rgba(245, 159, 0, 0.72);
}

.word-hotspot:active {
  background: rgba(255, 212, 59, 0.56);
  mix-blend-mode: multiply;
}

/* Vivid warm-yellow highlighter box that draws eyes to the English text without obscuring black ink */
.word-hotspot.is-active {
  background: rgba(255, 212, 59, 0.68);
  mix-blend-mode: multiply;
  border-color: #F59F00;
  box-shadow: 0 0 0 4px rgba(255, 212, 59, 0.46), 0 4px 14px rgba(245, 159, 0, 0.28);
  transform: scale(1.04);
}

/* ---------- Right Slide-Out Settings Drawer (Modal Dialog + Scroll Snap) ---------- */
.drawer {
  --drawer-width: min(22.5rem, 86dvw, 100dvw - 24px);
  --drawer-backdrop: 0;

  inset: 0;
  width: 100%;
  height: 100%;
  max-width: none;
  max-height: none;
  margin: 0;
  padding: 0;
  background: transparent;
  border: 0;
  overflow: hidden;
}

.drawer::backdrop {
  background: #152238;
  opacity: calc(var(--drawer-backdrop) * 0.42);
}

.drawer-scroller {
  position: relative;
  display: grid;
  grid-template-columns: 100% var(--drawer-width);
  height: 100svh;
  overflow-x: scroll;
  overflow-y: hidden;
  overscroll-behavior: none;
  scrollbar-width: none;
  scroll-snap-type: x mandatory;
}

.drawer-scroller::-webkit-scrollbar {
  display: none;
}

@media (prefers-reduced-motion: no-preference) {
  .drawer-scroller {
    scroll-behavior: smooth;
  }
}

/* Left empty spacer creates the closed snap stop at scrollLeft = 0 */
.drawer-scroller::before {
  content: "";
  scroll-snap-align: start;
  scroll-initial-target: nearest;
}

.drawer-sheet {
  display: grid;
  grid-template-rows: auto 1fr auto;
  height: 100svh;
  background: var(--bg-surface);
  color: var(--ink-primary);
  border-left: 1px solid var(--border-soft);
  box-shadow: -12px 0 36px rgba(21, 34, 56, 0.16);
  overflow-y: auto;
  overscroll-behavior-y: contain;
  scroll-snap-align: end;
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

@supports (animation-timeline: scroll()) {
  @property --drawer-backdrop {
    syntax: "<number>";
    inherits: true;
    initial-value: 0;
  }

  .drawer {
    timeline-scope: --drawer-fade;
    animation: fade-drawer-backdrop linear both;
    animation-timeline: --drawer-fade;
  }

  .drawer-scroller {
    scroll-timeline: --drawer-fade x;
  }

  @keyframes fade-drawer-backdrop {
    0% {
      --drawer-backdrop: 0;
    }
    100% {
      --drawer-backdrop: 1;
    }
  }
}

.drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--border-soft);
}

.drawer-title-group {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.reader-title {
  margin: 0;
  font-size: var(--text-heading);
  font-weight: 800;
  letter-spacing: -0.02em;
  line-height: 1.2;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.page-counter {
  font-size: var(--text-sm);
  font-weight: 700;
  color: var(--ink-muted);
  font-variant-numeric: tabular-nums;
}

.drawer-body {
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.drawer-section {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--bg-subtle);
}

.drawer-section:last-child {
  padding-bottom: 0;
  border-bottom: 0;
}

.drawer-section-title {
  margin: 0;
  font-size: var(--text-sm);
  font-weight: 800;
  color: var(--ink-muted);
}

.drawer-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.status-line {
  margin: 0;
  font-size: var(--text-sm);
  color: var(--ink-muted);
  font-weight: 600;
  line-height: 1.45;
  font-variant-numeric: tabular-nums;
}

.speed-control {
  margin: 0;
  padding: 0;
  border: 0;
}

.segmented-group {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  padding: 3px;
  border-radius: 12px;
  background: var(--bg-subtle);
  border: 1px solid var(--border-soft);
}

.segmented-group input[type="radio"] {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.segmented-group label {
  min-block-size: 38px;
  padding: 6px 4px;
  border-radius: 9px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: var(--text-sm);
  font-weight: 700;
  color: var(--ink-muted);
  cursor: pointer;
  user-select: none;
  font-variant-numeric: tabular-nums;
  transition: background-color 150ms ease-out, color 150ms ease-out, box-shadow 150ms ease-out;
}

.segmented-group input[type="radio"]:checked + label {
  background: var(--bg-surface);
  color: var(--accent);
  box-shadow: 0 2px 6px rgba(21, 34, 56, 0.12);
}

.segmented-group input[type="radio"]:focus-visible + label {
  outline: 3px solid var(--ink-primary);
  outline-offset: 2px;
}

.delay-control {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 4px;
}

.setting-caption,
.setting-unit {
  font-size: var(--text-sm);
  font-weight: 700;
  color: var(--ink-muted);
}

.delay-input-row {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.delay-input {
  width: 78px;
  min-block-size: 42px;
  padding: 6px 10px;
  border-radius: 10px;
  border: 2px solid var(--border-soft);
  background: var(--bg-page);
  color: var(--ink-primary);
  font-family: inherit;
  font-size: var(--text-body);
  font-weight: 700;
  text-align: center;
  font-variant-numeric: tabular-nums;
  transition: border-color 150ms ease-out, background-color 150ms ease-out;
}

.delay-input:focus {
  border-color: var(--accent);
  background: var(--bg-surface);
}

.word-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.word-btn {
  min-block-size: 40px;
  padding: 6px 12px;
  border-radius: 10px;
  border: 1px solid var(--border-soft);
  background: var(--bg-page);
  color: var(--ink-primary);
  font-family: inherit;
  font-size: var(--text-body);
  font-weight: 700;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background-color 140ms ease-out, border-color 140ms ease-out, color 140ms ease-out, scale 140ms ease-out;
}

.word-btn:hover {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
}

.word-btn:active {
  scale: 0.96;
}

.word-btn.is-active {
  background: #FFD43B;
  border-color: #F59F00;
  color: var(--ink-primary);
}

.page-dots {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}

.page-dot {
  min-inline-size: 38px;
  min-block-size: 38px;
  padding: 0 8px;
  border-radius: 10px;
  border: 1px solid var(--border-soft);
  background: var(--bg-page);
  color: var(--ink-muted);
  font-family: inherit;
  font-size: var(--text-sm);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
  transition: background-color 150ms ease-out, color 150ms ease-out, border-color 150ms ease-out;
}

.page-dot:hover {
  background: var(--bg-subtle);
  color: var(--ink-primary);
}

.page-dot.is-current {
  background: var(--accent);
  border-color: var(--accent);
  color: #FFFFFF;
}

/* ---------- Collapsible Parent Insights (<details>) ---------- */
.parent-insights {
  border-radius: 12px;
  background: var(--bg-page);
  border: 1px solid var(--border-soft);
  padding: 10px 12px;
}

.insights-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-block-size: 36px;
  font-size: var(--text-sm);
  font-weight: 800;
  color: var(--ink-primary);
  cursor: pointer;
  list-style: none;
  user-select: none;
}

.insights-summary::-webkit-details-marker {
  display: none;
}

.summary-chevron {
  width: 18px;
  height: 18px;
  color: var(--ink-muted);
  flex-shrink: 0;
  transition: transform 180ms ease-out;
}

.parent-insights[open] .summary-chevron {
  transform: rotate(180deg);
}

.insights-body {
  padding-top: 10px;
  margin-top: 8px;
  border-top: 1px solid var(--border-soft);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.insights-note,
.insights-empty {
  margin: 0;
  font-size: var(--text-sm);
  color: var(--ink-muted);
  line-height: 1.45;
}

.help-words-list {
  margin: 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.help-word-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 6px 10px;
  border-radius: 9px;
  background: var(--bg-surface);
  border: 1px solid var(--border-soft);
}

.help-word-main {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.help-word-rank {
  font-size: var(--text-sm);
  font-weight: 800;
  color: var(--ink-muted);
  font-variant-numeric: tabular-nums;
  min-width: 18px;
}

.help-word-text {
  font-size: var(--text-body);
  font-weight: 800;
  color: var(--ink-primary);
}

.help-word-count {
  font-size: var(--text-sm);
  font-weight: 700;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.insights-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.copy-wrap {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.btn-compact {
  min-block-size: 40px;
  padding: 6px 12px;
  font-size: var(--text-sm);
}

.btn-compact svg {
  width: 17px;
  height: 17px;
}

.copy-button .icon-check {
  display: none;
}

.copy-button[data-copied] .icon-copy {
  display: none;
}

.copy-button[data-copied] .icon-check {
  display: block;
  color: #1B7F4B;
}

.copy-button[data-copied] {
  border-color: #1B7F4B;
  color: #1B7F4B;
}

.copy-button[data-failed] {
  border-color: var(--active-coral);
  color: var(--active-coral);
}

.copy-tip {
  font-size: var(--text-sm);
  font-weight: 700;
  color: #1B7F4B;
  opacity: 0;
  transition: opacity 160ms ease-out;
}

.copy-button[data-copied] + .copy-tip {
  opacity: 1;
}

.copy-button[data-failed] + .copy-tip {
  opacity: 1;
  color: var(--active-coral);
}

.btn-text-subtle {
  min-block-size: 36px;
  padding: 4px 8px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--ink-muted);
  font-family: inherit;
  font-size: var(--text-sm);
  font-weight: 700;
  cursor: pointer;
  transition: color 150ms ease-out, background-color 150ms ease-out;
}

.btn-text-subtle:hover {
  color: var(--active-coral);
  background: rgba(234, 91, 56, 0.08);
}

.btn-text-subtle.is-confirming {
  color: var(--active-coral);
  background: rgba(234, 91, 56, 0.14);
}

.drawer-footer {
  padding: 14px 18px 18px;
  border-top: 1px solid var(--border-soft);
}

/* ---------- Touch / Mobile / Tablet Adaptation ---------- */
@media (pointer: coarse) {
  .btn {
    min-block-size: 52px;
    min-inline-size: 52px;
  }

  .word-btn {
    min-block-size: 44px;
    padding: 6px 14px;
  }

  .delay-input {
    min-block-size: 44px;
  }

  .page-dot {
    min-inline-size: 42px;
    min-block-size: 42px;
  }
}

@media (max-width: 768px) {
  .container {
    width: 94%;
  }

  .guide-steps {
    grid-template-columns: 1fr;
    gap: 10px;
  }

  .header-inner {
    flex-direction: column;
    align-items: flex-start;
    gap: 6px;
  }

  .book-grid {
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 14px;
  }

  .reader-main {
    padding:
      calc(10px + env(safe-area-inset-top, 0px))
      calc(8px + env(safe-area-inset-right, 0px))
      calc(10px + env(safe-area-inset-bottom, 0px))
      calc(8px + env(safe-area-inset-left, 0px));
  }

  .reader-stage-shell {
    position: relative;
    grid-template-columns: 1fr;
    gap: 0;
  }

  .stage-arrow {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    z-index: 10;
    min-inline-size: 44px;
    min-block-size: 58px;
    background: var(--bg-surface);
  }

  .stage-arrow-left {
    left: 6px;
  }

  .stage-arrow-right {
    right: 6px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
