/* Book atelier — ported from the original encyclopedia frame */
/* —— Solarpunk reading grove —— */
.book-atelier {
  position: relative;
  width: 100%;
  min-height: 100dvh;
  padding: 0;
  background-color: var(--atelier);
  background-image:
    radial-gradient(ellipse 70% 45% at 15% 10%, color-mix(in srgb, var(--sun-lit) 22%, transparent), transparent 55%),
    radial-gradient(ellipse 55% 40% at 85% 20%, color-mix(in srgb, var(--atelier-mist) 16%, transparent), transparent 50%),
    radial-gradient(ellipse 80% 50% at 50% 100%, color-mix(in srgb, var(--atelier-floor) 55%, transparent), transparent 60%),
    linear-gradient(165deg, var(--atelier-mid) 0%, var(--atelier) 42%, var(--atelier-deep) 100%);
}

.book-atelier::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 0.35;
  background-image:
    radial-gradient(1.5px 1.5px at 10% 20%, color-mix(in srgb, var(--leaf) 35%, transparent), transparent),
    radial-gradient(1px 1px at 30% 70%, color-mix(in srgb, var(--gold-dust) 30%, transparent), transparent),
    radial-gradient(1.5px 1.5px at 70% 40%, color-mix(in srgb, var(--leaf) 28%, transparent), transparent),
    radial-gradient(1px 1px at 90% 80%, color-mix(in srgb, var(--gold-dust) 25%, transparent), transparent);
  animation: leaf-twinkle 10s ease-in-out infinite alternate;
}

/* —— Open encyclopedia volume —— */
.book {
  --facing-collapsed: clamp(2.25rem, 5.5vw, 4rem);
  --facing-expanded: min(18.75rem, calc(100vw - 4.5rem));
  --facing-w: var(--facing-collapsed);
  --stack-w: clamp(0.55rem, 1.4vw, 0.95rem);
  --page-inset: clamp(0.35rem, 0.9vw, 0.65rem);
  --page-inset-top: 0px;
  /* Snap the reading page. Animating this margin restomps the whole leaf. */
  --gutter-left: var(--facing-collapsed);
  --hump-x: 4.5rem;
  --hump-y: 2.4rem;
  --facing-motion: 0.55s cubic-bezier(0.22, 1, 0.36, 1);
  position: relative;
  width: 100%;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  border-radius: 0.55rem;
  box-shadow:
    0 0 0 1px rgba(var(--binding-rgb), 0.28),
    0 22px 48px rgba(var(--shade-cool-rgb), 0.48),
    0 4px 12px rgba(var(--shade-cool-rgb), 0.25);
}

.book--help-open {
  --facing-w: var(--facing-expanded);
  --gutter-left: var(--facing-expanded);
}

/* Staff utilities: keep the help spine, give the leaf the rest of the viewport. */
.book--utility {
  --facing-collapsed: clamp(1.7rem, 3.2vw, 2.4rem);
  --page-inset: 0.12rem;
  --stack-w: 0.28rem;
  --hump-x: 1.6rem;
  --hump-y: 0.85rem;
  border-radius: 0;
  box-shadow: none;
}

.book--utility .book__page {
  border-radius: 0.12rem 0 0 0;
}

/* Left-hand page — mirrors the right page hump into the crease */
.book__facing {
  position: absolute;
  z-index: 1;
  top: var(--page-inset-top);
  bottom: calc(var(--page-inset) * 0.55);
  left: 0;
  width: var(--facing-w);
  pointer-events: auto;
  overflow: visible;
  cursor: pointer;
  /* Mirror of right page: elliptical hump at top-right (toward the crease) */
  border-radius: 0.15rem var(--hump-x) 0.1rem 0.15rem / 0.15rem var(--hump-y) 0.1rem 0.15rem;
  background-color: var(--paper-deep);
  background-image:
    linear-gradient(
      270deg,
      rgba(var(--ink-deep-rgb), 0.16) 0%,
      rgba(var(--ink-rgb), 0.07) 40%,
      transparent 100%
    ),
    linear-gradient(
      180deg,
      color-mix(in srgb, var(--sun-wash) 35%, transparent) 0%,
      transparent 22%
    ),
    radial-gradient(
      ellipse 90% 70% at 100% 0%,
      color-mix(in srgb, var(--paper) 55%, transparent),
      transparent 58%
    ),
    linear-gradient(195deg, var(--paper) 0%, var(--paper-mid) 50%, var(--paper-shade) 100%);
  box-shadow:
    0 0 0 1px rgba(var(--page-line-rgb), 0.28),
    inset 14px 0 22px rgba(var(--shade-rgb), 0.08),
    inset -14px 0 22px rgba(var(--shade-rgb), 0.28),
    inset -4px 0 8px rgba(var(--shade-rgb), 0.18),
    inset 0 18px 28px -18px rgba(var(--shade-rgb), 0.14);
  transition: box-shadow 0.55s ease;
}

.book--help-open .book__facing {
  /* Stay under the crease/well valley so the top gap stays dark */
  z-index: 1;
  cursor: default;
  overflow: visible;
  background-color: var(--paper-open);
  background-image:
    linear-gradient(
      270deg,
      rgba(var(--ink-deep-rgb), 0.14) 0%,
      rgba(var(--ink-rgb), 0.05) 36%,
      transparent 100%
    ),
    linear-gradient(
      180deg,
      color-mix(in srgb, var(--cream-warm) 42%, transparent) 0%,
      transparent 20%
    ),
    radial-gradient(
      ellipse 90% 70% at 100% 0%,
      color-mix(in srgb, var(--cream-lit) 75%, transparent),
      transparent 58%
    ),
    linear-gradient(165deg, var(--paper-open-lit) 0%, var(--paper-open) 52%, var(--paper-open-deep) 100%);
  box-shadow:
    0 0 0 1px rgba(var(--page-line-rgb), 0.28),
    0 18px 40px rgba(var(--shade-cool-rgb), 0.22),
    inset 14px 0 22px rgba(var(--shade-rgb), 0.03),
    inset -10px 0 18px rgba(var(--shade-rgb), 0.14),
    inset 0 18px 28px -18px rgba(var(--shade-rgb), 0.08);
}

.book__facing-hit {
  position: absolute;
  inset: 0;
  z-index: 6;
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
  cursor: pointer;
}

.book__facing::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 3;
  pointer-events: none;
  opacity: 0;
  border-radius: inherit;
  background:
    radial-gradient(
      ellipse 140% 70% at 40% 50%,
      color-mix(in srgb, var(--gold-hot) 90%, transparent) 0%,
      color-mix(in srgb, var(--gold-mid) 50%, transparent) 42%,
      color-mix(in srgb, var(--gold-deep) 15%, transparent) 68%,
      transparent 82%
    );
  transition: opacity 0.55s ease;
}

.book:not(.book--help-open) .book__facing:hover {
  z-index: 5;
  box-shadow:
    0 0 0 1px color-mix(in srgb, var(--sun-lit) 55%, transparent),
    0 0 18px color-mix(in srgb, var(--sun-lit) 70%, transparent),
    0 0 42px color-mix(in srgb, var(--gold-mid) 50%, transparent),
    0 0 72px color-mix(in srgb, var(--gold-deep) 28%, transparent),
    inset 0 0 28px color-mix(in srgb, var(--gold-dust) 55%, transparent),
    inset 0 0 48px color-mix(in srgb, var(--sun-lit) 28%, transparent),
    inset 14px 0 22px rgba(var(--shade-rgb), 0.02),
    inset -10px 0 18px rgba(var(--shade-rgb), 0.12);
}

.book:not(.book--help-open) .book__facing:hover::after {
  opacity: 1;
}

/* Sibling of facing so it paints above the crease */
.book__facing-mark-slot {
  position: absolute;
  z-index: 6;
  top: var(--page-inset-top);
  bottom: calc(var(--page-inset) * 0.55);
  left: 0;
  width: var(--facing-w);
  pointer-events: none;
  transition:
    width var(--facing-motion),
    opacity 0.35s ease;
}

.book--help-open .book__facing-mark-slot {
  opacity: 0;
}

.book__facing-mark {
  position: sticky;
  top: calc(50dvh - 2.5rem);
  display: grid;
  place-items: center;
  width: 100%;
  margin-inline: auto;
  padding-block: 0.35rem;
  font-family: var(--font-fraunces), serif;
  font-size: clamp(0.8125rem, 1.7vw, 1rem);
  font-weight: 600;
  font-style: normal;
  line-height: 1;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  writing-mode: vertical-rl;
  text-orientation: mixed;
  color: rgba(var(--mark-rgb), 0.88);
  text-shadow:
    0 1px 0 color-mix(in srgb, var(--cream) 55%, transparent),
    0 0 12px color-mix(in srgb, var(--sun-lit) 22%, transparent);
  user-select: none;
  animation: facing-mark-float 3.6s ease-in-out infinite;
  transition:
    color 0.55s ease,
    text-shadow 0.55s ease;
}

.book__facing-hit--desktop {
  display: none;
}

@media (min-width: 641px) {
  .book__facing-hit--desktop {
    display: block;
  }
}

.book__help-fab {
  display: none;
}

.book:not(.book--help-open) .book__facing:hover ~ .book__facing-mark-slot .book__facing-mark,
.facing-tip-visible .book__facing-mark {
  color: var(--glow-ink);
  text-shadow:
    0 0 4px var(--cream),
    0 0 12px var(--gold-dust),
    0 0 28px color-mix(in srgb, var(--gold-mid) 95%, transparent),
    0 0 48px color-mix(in srgb, var(--gold-deep) 75%, transparent),
    0 0 72px color-mix(in srgb, var(--gold-deep) 45%, transparent);
}

.facing-tip-visible .book__facing {
  z-index: 5;
  box-shadow:
    0 0 0 1px color-mix(in srgb, var(--sun-lit) 45%, transparent),
    0 0 18px color-mix(in srgb, var(--sun-lit) 55%, transparent),
    0 0 42px color-mix(in srgb, var(--gold-mid) 35%, transparent),
    inset 0 0 28px color-mix(in srgb, var(--gold-dust) 40%, transparent),
    inset 14px 0 22px rgba(var(--shade-rgb), 0.02),
    inset -10px 0 18px rgba(var(--shade-rgb), 0.12);
}

.facing-tip-visible .book__facing::after {
  opacity: 0.85;
}

@keyframes facing-mark-float {
  0%,
  100% {
    translate: 0 0.2rem;
  }
  50% {
    translate: 0 -0.35rem;
  }
}

/* Onboarding tip — bottom-left, caret points left at the facing ? */
.facing-tip {
  --facing-tip-edge: rgba(var(--help-ink-rgb), 0.22);
  position: fixed;
  z-index: 40;
  left: calc(var(--facing-w) + 0.85rem);
  bottom: clamp(4.75rem, 13vh, 7rem);
  display: flex;
  align-items: flex-start;
  gap: 0.45rem;
  width: min(15.75rem, calc(100vw - var(--facing-w) - 2rem));
  padding: 0.75rem 0.7rem 0.75rem 0.9rem;
  border: 1px solid var(--facing-tip-edge);
  border-radius: 0.2rem 0.55rem 0.55rem 0.2rem;
  background:
    linear-gradient(165deg, color-mix(in srgb, var(--cream) 55%, transparent) 0%, transparent 42%),
    var(--facing-tip-paper);
  color: var(--facing-tip-ink);
  box-shadow:
    0 10px 28px rgba(var(--shade-cool-rgb), 0.28),
    0 2px 6px rgba(var(--shade-cool-rgb), 0.12);
  animation: facing-tip-in 0.55s ease-out both;
}

.facing-tip__arrow {
  position: absolute;
  left: -0.42rem;
  top: 1.05rem;
  width: 0.72rem;
  height: 0.72rem;
  border-left: 1px solid var(--facing-tip-edge);
  border-bottom: 1px solid var(--facing-tip-edge);
  background: var(--facing-tip-paper);
  rotate: 45deg;
  box-shadow: -2px 2px 5px rgba(var(--shade-cool-rgb), 0.06);
}

.facing-tip__action {
  flex: 1;
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
  color: inherit;
  font-family: var(--font-fraunces), serif;
  font-size: 1.0625rem;
  font-weight: 500;
  line-height: 1.35;
  letter-spacing: 0.01em;
  text-align: left;
  cursor: pointer;
}

.facing-tip__action:hover {
  color: var(--accent-strong);
}

.facing-tip__action:focus-visible {
  outline: 2px solid rgba(var(--help-focus-rgb), 0.55);
  outline-offset: 2px;
}

.book__help-panel {
  /* Fill the tall facing page; inner copy sticks to the viewport */
  position: absolute;
  inset: 0;
  /* Below shade/hump so the radiused paper corner still reads */
  z-index: 1;
  display: flex;
  flex-direction: column;
  width: 100%;
  opacity: 0;
  pointer-events: none;
  overflow: visible;
  background: transparent;
  transition: opacity 0.35s ease;
}

.book--help-open .book__help-panel {
  opacity: 1;
  pointer-events: auto;
  transition-delay: 0.12s;
}

.book__help {
  /* Always the open measure so copy does not rewrap as the spine grows.
     Ride the crease — the block slides in from the left with the page. */
  position: sticky;
  top: 0;
  align-self: flex-end;
  flex: none;
  display: flex;
  flex-direction: column;
  width: var(--facing-expanded);
  max-width: var(--facing-expanded);
  height: 100dvh;
  max-height: 100dvh;
  min-height: 0;
  padding: 1rem 1rem 1.15rem 1.05rem;
  color: var(--ink);
  background: transparent;
  overflow: clip;
}

.book__help-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.85rem;
  padding-bottom: 0.7rem;
  border-bottom: 1px solid rgba(var(--help-ink-rgb), 0.14);
}

.book__help-eyebrow {
  margin: 0;
  font-size: 0.8125rem;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}

.book__help-title {
  margin: 0.2rem 0 0;
  font-family: var(--font-fraunces), serif;
  font-size: 1.375rem;
  font-weight: 600;
  line-height: 1.2;
  letter-spacing: -0.02em;
}

.book__help-blurb {
  margin: 0;
  font-size: 1rem;
  line-height: 1.45;
  color: var(--ink-soft);
}

.book__help-actions {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.book__help-action {
  display: block;
  padding: 0.55rem 0.7rem;
  border: 1px solid rgba(var(--help-ink-rgb), 0.16);
  border-radius: 0.35rem;
  background: color-mix(in srgb, var(--cream-lit) 72%, transparent);
  color: var(--accent-strong);
  font-family: var(--font-fraunces), serif;
  font-size: 1rem;
  font-weight: 600;
  line-height: 1.25;
  transition:
    border-color 0.2s ease,
    background-color 0.2s ease,
    color 0.2s ease;
}

.book__help-action:hover {
  border-color: rgba(var(--grove), 0.45);
  background: rgba(var(--grove), 0.08);
  color: var(--ink);
}

.book__help-top-actions {
  display: flex;
  flex: none;
  align-items: center;
  gap: 0.35rem;
}

.book__help-back {
  margin: 0;
  padding: 0.25rem 0.45rem;
  border: 0;
  border-radius: 0.3rem;
  background: transparent;
  color: var(--accent-strong);
  font-family: var(--font-fraunces), serif;
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
}

.book__help-back:hover {
  background: rgba(var(--help-ink-rgb), 0.08);
  color: var(--ink);
}

.book__help-back:focus-visible {
  outline: 2px solid rgba(var(--help-focus-rgb), 0.55);
  outline-offset: 2px;
}

.book__help-close {
  flex: none;
  display: grid;
  place-items: center;
  width: 2.4rem;
  height: 2.4rem;
  margin: -0.25rem -0.25rem 0 0;
  border: 0;
  border-radius: 0.35rem;
  background: transparent;
  color: rgba(var(--help-ink-rgb), 0.55);
  font-size: 2rem;
  line-height: 1;
  cursor: pointer;
  transition:
    color 0.2s ease,
    background-color 0.2s ease;
}

.book__help-close:hover {
  color: var(--ink);
  background: rgba(var(--help-ink-rgb), 0.08);
}

.book__help-close:focus-visible {
  outline: 2px solid rgba(var(--help-focus-rgb), 0.55);
  outline-offset: 2px;
}

.book__help-body {
  display: flex;
  flex: 1 1 auto;
  flex-direction: column;
  gap: 0.95rem;
  min-height: 0;
  overflow: auto;
  padding-right: 0.2rem;
}

.book__help-ask {
  position: relative;
  z-index: 1;
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  min-height: 0;
  margin-top: auto;
  padding-top: 0.75rem;
  border-top: 1px solid rgba(var(--help-ink-rgb), 0.14);
  background: transparent;
}

.book__help--asking .book__help-ask {
  flex: 1 1 auto;
  margin-top: 0;
  padding-top: 0;
  border-top: 0;
}

.book__help--asking .book__help-ask-thread {
  flex: 1 1 auto;
  max-height: none;
  min-height: 0;
}

.book__help-ask-head {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.book__help-ask-title {
  margin: 0;
  font-family: var(--font-fraunces), serif;
  font-size: 1.0625rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  color: var(--accent-strong);
}

.book__help-ask-hint {
  margin: 0;
  font-size: 0.875rem;
  line-height: 1.35;
  color: var(--muted);
}

.book__help-ask-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.book__help-ask-chip {
  margin: 0;
  padding: 0.3rem 0.55rem;
  border: 1px solid rgba(var(--help-ink-rgb), 0.16);
  border-radius: 999px;
  background: color-mix(in srgb, var(--cream-lit) 85%, transparent);
  color: var(--ink-soft);
  font-size: 0.875rem;
  line-height: 1.2;
  cursor: pointer;
  transition:
    border-color 0.2s ease,
    background-color 0.2s ease,
    color 0.2s ease;
}

.book__help-ask-chip:hover:not(:disabled) {
  border-color: rgba(var(--grove), 0.4);
  color: var(--accent-strong);
}

.book__help-ask-chip:disabled {
  opacity: 0.55;
  cursor: default;
}

.book__help-ask-chip:focus-visible {
  outline: 2px solid rgba(var(--help-focus-rgb), 0.55);
  outline-offset: 2px;
}

.book__help-ask-thread {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  max-height: 9.5rem;
  overflow: auto;
  padding-right: 0.15rem;
}

.book__help-ask-bubble {
  margin: 0;
  padding: 0.45rem 0.55rem;
  border-radius: 0.35rem;
  font-size: 0.9375rem;
  line-height: 1.4;
}

.book__help-ask-bubble--user {
  align-self: flex-end;
  max-width: 92%;
  background: rgba(var(--grove), 0.14);
  color: var(--ink);
}

.book__help-ask-bubble--assistant {
  align-self: stretch;
  background: color-mix(in srgb, var(--cream) 55%, transparent);
  color: var(--ink-soft);
  border: 1px solid rgba(var(--help-ink-rgb), 0.1);
}

.book__help-ask-bubble--pending {
  font-style: italic;
  color: var(--muted);
}

.book__help-ask-error {
  margin: 0;
  font-size: 0.875rem;
  color: var(--danger);
}

.book__help-ask-form {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.book__help-ask-input {
  flex: 1;
  min-width: 0;
  height: 2.15rem;
  padding: 0 0.65rem;
  border: 1px solid rgba(var(--help-ink-rgb), 0.2);
  border-radius: 0.3rem;
  background: color-mix(in srgb, var(--cream-lit) 90%, transparent);
  color: var(--ink);
  font: inherit;
  font-size: 1rem;
}

.book__help-ask-input::placeholder {
  color: var(--muted);
}

.book__help-ask-input:focus {
  outline: 2px solid rgba(var(--grove), 0.35);
  outline-offset: 1px;
  border-color: rgba(var(--grove), 0.45);
}

.book__help-ask-input:disabled {
  opacity: 0.7;
}

.book__help-ask-launch {
  width: 100%;
  height: 2.35rem;
  margin-top: 0.15rem;
  padding: 0 0.85rem;
  border: 0;
  border-radius: 0.3rem;
  background: var(--accent-strong);
  color: var(--on-accent);
  font-family: var(--font-fraunces), serif;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: background-color 0.2s ease;
}

.book__help-ask-launch:hover {
  background: var(--accent);
}

.book__help-ask-launch:focus-visible {
  outline: 2px solid rgba(var(--help-focus-rgb), 0.55);
  outline-offset: 2px;
}

.book__help-ask-send {
  flex: none;
  height: 2.15rem;
  padding: 0 0.75rem;
  border: 0;
  border-radius: 0.3rem;
  background: var(--accent-strong);
  color: var(--on-accent);
  font-family: var(--font-fraunces), serif;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: background-color 0.2s ease;
}

.book__help-ask-send:hover:not(:disabled) {
  background: var(--accent);
}

.book__help-ask-send:disabled {
  opacity: 0.45;
  cursor: default;
}

.book__help-ask-send:focus-visible {
  outline: 2px solid rgba(var(--help-focus-rgb), 0.55);
  outline-offset: 2px;
}

.book__help-section h3 {
  margin: 0 0 0.28rem;
  font-family: var(--font-fraunces), serif;
  font-size: 1.0625rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  color: var(--accent-strong);
}

.book__help-section p {
  margin: 0;
  font-size: 1rem;
  line-height: 1.45;
  color: var(--ink-soft);
}

.book__help-section a {
  color: var(--accent-strong);
  text-decoration: underline;
  text-underline-offset: 0.12em;
}

.book__help-section a:hover {
  color: var(--ink);
}

.book__help-body,
.book__help-ask-thread,
.book__help-look-menu,
.book__help-scroll {
  scrollbar-width: thin;
  scrollbar-color:
    color-mix(in srgb, var(--accent) 62%, var(--atelier))
    color-mix(in srgb, var(--paper-deep) 70%, transparent);
}

.book__help-body::-webkit-scrollbar,
.book__help-ask-thread::-webkit-scrollbar,
.book__help-look-menu::-webkit-scrollbar,
.book__help-scroll::-webkit-scrollbar {
  width: 0.5rem;
}

.book__help-body::-webkit-scrollbar-track,
.book__help-ask-thread::-webkit-scrollbar-track,
.book__help-look-menu::-webkit-scrollbar-track,
.book__help-scroll::-webkit-scrollbar-track {
  margin: 0.2rem 0;
  background: color-mix(in srgb, var(--paper-shade) 58%, transparent);
  border-radius: 999px;
}

.book__help-body::-webkit-scrollbar-thumb,
.book__help-ask-thread::-webkit-scrollbar-thumb,
.book__help-look-menu::-webkit-scrollbar-thumb,
.book__help-scroll::-webkit-scrollbar-thumb {
  background:
    linear-gradient(
      180deg,
      color-mix(in srgb, var(--accent) 50%, var(--atelier-mid)),
      var(--atelier)
    );
  border: 2px solid transparent;
  border-radius: 999px;
  background-clip: padding-box;
}

.book__help-body::-webkit-scrollbar-thumb:hover,
.book__help-ask-thread::-webkit-scrollbar-thumb:hover,
.book__help-look-menu::-webkit-scrollbar-thumb:hover,
.book__help-scroll::-webkit-scrollbar-thumb:hover {
  background: var(--accent-strong);
  background-clip: padding-box;
}

.book__help-body::-webkit-scrollbar-corner,
.book__help-ask-thread::-webkit-scrollbar-corner,
.book__help-look-menu::-webkit-scrollbar-corner,
.book__help-scroll::-webkit-scrollbar-corner {
  background: transparent;
}

.book__help-look {
  position: relative;
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  padding-top: 0.7rem;
  border-top: 1px solid rgba(var(--help-ink-rgb), 0.14);
}

.book__help-look-title {
  margin: 0;
  font-family: var(--font-fraunces), serif;
  font-size: 0.9375rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  color: var(--accent-strong);
}

.book__help-look-card,
.book__help-look-trigger {
  display: flex;
  align-items: flex-start;
  gap: 0.45rem;
  width: 100%;
  padding: 0.32rem 0.42rem;
  border: 1px solid rgba(var(--help-ink-rgb), 0.16);
  border-radius: 0.32rem;
  background: color-mix(in srgb, var(--cream-lit) 72%, transparent);
  color: var(--ink);
  text-align: left;
  cursor: pointer;
  transition:
    border-color 0.2s ease,
    background-color 0.2s ease;
}

.book__help-look-card:hover,
.book__help-look-trigger:hover {
  border-color: rgba(var(--grove), 0.45);
  background: rgba(var(--grove), 0.08);
}

.book__help-look-card.is-selected,
.book__help-look-trigger[aria-expanded="true"] {
  border-color: rgba(var(--grove), 0.55);
  background: rgba(var(--grove), 0.12);
}

.book__help-look-card:focus-visible,
.book__help-look-trigger:focus-visible {
  outline: 2px solid rgba(var(--help-focus-rgb), 0.55);
  outline-offset: 2px;
}

.book__help-look-swatch {
  display: flex;
  flex: none;
  width: 1.15rem;
  height: 1.15rem;
  margin-top: 0.08rem;
  overflow: hidden;
  border: 1px solid rgba(var(--help-ink-rgb), 0.18);
  border-radius: 0.24rem;
}

.book__help-look-swatch-bind {
  width: 38%;
}

.book__help-look-swatch-mark {
  width: 0.22rem;
  margin-left: auto;
}

.book__help-look-copy,
.book__help-look-trigger-copy {
  min-width: 0;
  flex: 1;
}

.book__help-look-label {
  display: block;
  font-family: var(--font-fraunces), serif;
  font-size: 0.8125rem;
  font-weight: 600;
  line-height: 1.2;
}

.book__help-look-desc {
  display: block;
  margin-top: 0.08rem;
  font-size: 0.6875rem;
  line-height: 1.3;
  color: var(--muted);
}

.book__help-look-caret {
  flex: none;
  margin-top: 0.15rem;
  color: var(--muted);
  font-size: 0.7rem;
}

.book__help-look-menu {
  position: fixed;
  z-index: 50;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  overflow: auto;
  padding: 0.35rem;
  border: 1px solid rgba(var(--help-ink-rgb), 0.16);
  border-radius: 0.4rem;
  background: var(--paper);
  box-shadow: var(--shadow);
}

.facing-tip__dismiss {
  flex: none;
  display: grid;
  place-items: center;
  width: 1.35rem;
  height: 1.35rem;
  margin: -0.15rem -0.1rem 0 0;
  border: 0;
  border-radius: 0.25rem;
  background: transparent;
  color: rgba(var(--help-ink-rgb), 0.55);
  font-size: 1.15rem;
  line-height: 1;
  cursor: pointer;
  transition:
    color 0.2s ease,
    background-color 0.2s ease;
}

.facing-tip__dismiss:hover {
  color: var(--facing-tip-ink);
  background: rgba(var(--help-ink-rgb), 0.08);
}

.facing-tip__dismiss:focus-visible {
  outline: 2px solid rgba(var(--help-focus-rgb), 0.55);
  outline-offset: 2px;
}

@keyframes facing-tip-in {
  from {
    opacity: 0;
    translate: -0.6rem 0.35rem;
  }
  to {
    opacity: 1;
    translate: 0 0;
  }
}

.book__facing-hump {
  position: absolute;
  z-index: 4;
  top: 0;
  right: 0;
  width: clamp(2.4rem, 70%, 3.5rem);
  height: clamp(1.5rem, 4.8vw, 2.75rem);
  pointer-events: none;
  background:
    radial-gradient(
      ellipse 95% 110% at 88% -10%,
      color-mix(in srgb, var(--paper) 55%, transparent) 0%,
      color-mix(in srgb, var(--paper-deep) 22%, transparent) 38%,
      transparent 70%
    ),
    linear-gradient(
      210deg,
      color-mix(in srgb, var(--paper) 28%, transparent) 0%,
      transparent 60%
    );
  border-bottom-left-radius: 90% 120%;
  box-shadow:
    -6px 8px 16px -8px rgba(var(--shade-rgb), 0.14),
    inset 8px -4px 12px -6px rgba(var(--shade-rgb), 0.08);
  mask-image: linear-gradient(
    220deg,
    #000 0%,
    #000 48%,
    transparent 80%
  );
}

.book__facing-shade {
  position: absolute;
  z-index: 3;
  inset: 0;
  pointer-events: none;
  border-radius: inherit;
  background:
    linear-gradient(
      270deg,
      rgba(var(--shade-deep-rgb), 0.22) 0%,
      rgba(var(--shade-rgb), 0.06) 40%,
      transparent 80%
    ),
    linear-gradient(
      180deg,
      transparent 0%,
      transparent 88%,
      rgba(var(--ink-rgb), 0.1) 100%
    );
}

/* Deep valley where left and right pages meet */
.book__crease {
  position: absolute;
  z-index: 4;
  top: var(--page-inset-top);
  bottom: calc(var(--page-inset) * 0.35);
  left: calc(var(--facing-w) - 0.55rem);
  width: 1.1rem;
  pointer-events: none;
  background: linear-gradient(
    90deg,
    rgba(var(--hero-shade-rgb), 0.05) 0%,
    rgba(var(--hero-shade-rgb), 0.45) 35%,
    rgba(var(--shade-deep-rgb), 0.7) 50%,
    rgba(var(--hero-shade-rgb), 0.4) 65%,
    rgba(var(--hero-shade-rgb), 0.04) 100%
  );
  filter: blur(0.6px);
  box-shadow:
    0 0 14px rgba(var(--shade-deep-rgb), 0.35),
    0 0 4px rgba(var(--shade-deep-rgb), 0.25);
}

/* Soft fill behind both page humps at the crease */
.book__well {
  position: absolute;
  z-index: 0;
  top: 0;
  left: 0;
  width: calc(var(--facing-w) + clamp(3.5rem, 12vw, 6rem));
  height: clamp(2.6rem, 7vw, 4rem);
  pointer-events: none;
  background-color: var(--atelier);
  background-image:
    linear-gradient(
      180deg,
      var(--atelier) 0%,
      var(--atelier) 40%,
      transparent 100%
    ),
    linear-gradient(
      180deg,
      var(--atelier) 0%,
      var(--atelier-well) 55%,
      transparent 100%
    );
}

.book__edge {
  position: absolute;
  z-index: 3;
  left: var(--gutter-left);
  right: var(--stack-w);
  height: var(--page-inset);
  pointer-events: none;
  background: linear-gradient(
    90deg,
    rgba(var(--ink-rgb), 0.2),
    var(--page-edge) 40%,
    var(--page-edge-deep) 100%
  );
}

.book__edge--top {
  display: none;
}

.book__edge--bottom {
  bottom: 0;
  border-radius: 0 0 0.2rem 0;
  background:
    linear-gradient(
      90deg,
      rgba(var(--ink-rgb), 0.16),
      transparent 22%,
      color-mix(in srgb, var(--sun-wash) 20%, transparent) 70%,
      rgba(var(--leather), 0.08)
    ),
    linear-gradient(0deg, var(--paper-deep), var(--paper));
}

.book__stack {
  position: absolute;
  z-index: 3;
  top: var(--page-inset-top);
  bottom: var(--page-inset);
  right: 0;
  width: var(--stack-w);
  pointer-events: none;
  display: flex;
  border-radius: 0 0.45rem 0.45rem 0;
  overflow: hidden;
  background: linear-gradient(90deg, var(--paper-deep), var(--page-stack));
  box-shadow: inset 1px 0 0 rgba(var(--sheen-rgb), 0.35);
}

.book__stack span {
  flex: 1;
  border-left: 1px solid rgba(var(--grove), 0.12);
  background: linear-gradient(
    90deg,
    rgba(var(--sheen-rgb), 0.2),
    transparent 60%,
    rgba(var(--leather), 0.06)
  );
}

.book__page {
  position: relative;
  z-index: 1;
  display: flex;
  flex: 1;
  flex-direction: column;
  min-height: inherit;
  margin:
    var(--page-inset-top)
    var(--stack-w)
    var(--page-inset)
    var(--gutter-left);
  overflow: visible;
  /* Elliptical top-left: paper hump of an open right-hand page */
  border-radius: var(--hump-x) 0.25rem 0.25rem 0.1rem / var(--hump-y) 0.25rem 0.25rem 0.1rem;
  background-color: var(--paper);
  background-image:
    linear-gradient(
      90deg,
      rgba(var(--ink-deep-rgb), 0.16) 0%,
      rgba(var(--ink-rgb), 0.07) 2.8rem,
      transparent 6.5rem,
      transparent 100%
    ),
    linear-gradient(
      180deg,
      color-mix(in srgb, var(--sun-wash) 40%, transparent) 0%,
      transparent 18%,
      rgba(var(--grove), 0.04) 100%
    ),
    radial-gradient(
      ellipse 90% 70% at 0% 0%,
      color-mix(in srgb, var(--paper) 55%, transparent),
      transparent 58%
    ),
    radial-gradient(
      ellipse 90% 50% at 50% -10%,
      color-mix(in srgb, var(--sun-glow) 16%, transparent),
      transparent 55%
    ),
    linear-gradient(165deg, var(--paper-lit) 0%, var(--paper) 45%, var(--paper-deep) 100%);
  box-shadow:
    0 0 0 1px rgba(var(--page-line-rgb), 0.35),
    inset 28px 0 36px -12px rgba(var(--shade-rgb), 0.28),
    inset 10px 0 16px -6px rgba(var(--shade-rgb), 0.18),
    inset 0 18px 28px -18px rgba(var(--shade-rgb), 0.16),
    -3px 0 10px rgba(var(--shade-deep-rgb), 0.12);
}

/* Raised paper hump at the top-left of the open page */
.book__hump {
  position: absolute;
  z-index: 3;
  top: 0;
  left: 0;
  width: clamp(5.5rem, 18vw, 10rem);
  height: clamp(1.75rem, 4.8vw, 3rem);
  pointer-events: none;
  background:
    radial-gradient(
      ellipse 95% 110% at 12% -10%,
      color-mix(in srgb, var(--paper) 55%, transparent) 0%,
      color-mix(in srgb, var(--paper-deep) 22%, transparent) 38%,
      transparent 70%
    ),
    linear-gradient(
      150deg,
      color-mix(in srgb, var(--paper) 28%, transparent) 0%,
      transparent 60%
    );
  border-bottom-right-radius: 90% 120%;
  box-shadow:
    6px 8px 16px -8px rgba(var(--shade-rgb), 0.14),
    inset -8px -4px 12px -6px rgba(var(--shade-rgb), 0.08);
  mask-image: linear-gradient(
    140deg,
    #000 0%,
    #000 48%,
    transparent 80%
  );
}

.book__hump::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  width: 70%;
  height: 70%;
  border-radius: 0 0 100% 0;
  background: linear-gradient(
    155deg,
    color-mix(in srgb, var(--paper) 50%, transparent),
    transparent 65%
  );
  filter: blur(1.5px);
}

.book__hump::after {
  content: "";
  position: absolute;
  top: 0.45rem;
  left: 0.15rem;
  width: 72%;
  height: 1px;
  background: linear-gradient(
    90deg,
    rgba(var(--shade-rgb), 0.18),
    rgba(var(--shade-rgb), 0.05) 55%,
    transparent
  );
  transform: rotate(-8deg);
  transform-origin: left center;
}

/* Soft cylindrical falloff from the binding onto the page */
.book__gutter {
  position: absolute;
  z-index: 2;
  top: 0;
  bottom: 0;
  left: 0;
  width: clamp(4rem, 12vw, 7rem);
  pointer-events: none;
  background: linear-gradient(
    90deg,
    rgba(var(--shade-deep-rgb), 0.28) 0%,
    rgba(var(--shade-rgb), 0.14) 20%,
    rgba(var(--ink-deep-rgb), 0.05) 48%,
    transparent 88%
  );
  mask-image: linear-gradient(
    180deg,
    rgba(0, 0, 0, 0.35) 0%,
    #000 14%,
    #000 90%,
    rgba(0, 0, 0, 0.55) 100%
  );
}

.book__leaf {
  position: relative;
  z-index: 1;
  display: flex;
  flex: 1;
  flex-direction: column;
  min-height: 100%;
}

@keyframes leaf-twinkle {
  from {
    opacity: 0.22;
  }
  to {
    opacity: 0.42;
  }
}

@media (prefers-reduced-motion: reduce) {
  .book-atelier::before,
  .book__facing-mark,
  .facing-tip,
  .book__facing-mark-slot,
  .book__crease,
  .book__well,
  .book__edge,
  .book__page,
  .book__help-fab {
    animation: none;
    transition: none !important;
  }
}

@media (max-width: 640px) {
  .book {
    --facing-collapsed: 0px;
    --facing-expanded: 100%;
    --hump-x: 0.25rem;
    --hump-y: 0.25rem;
  }

  .book--help-open {
    --gutter-left: 0px;
    --facing-w: 100%;
    --hump-x: 0.25rem;
    --hump-y: 0.25rem;
  }

  html:has(.book--help-open) {
    overflow: hidden;
  }

  .book__hump,
  .book__facing-hump {
    height: 1.45rem;
  }

  .book:not(.book--help-open) .book__facing,
  .book__facing-mark-slot,
  .book__crease,
  .book__well {
    visibility: hidden;
    pointer-events: none;
  }

  .book__facing {
    pointer-events: none;
  }

  .book--help-open .book__facing {
    position: fixed;
    inset: 0;
    z-index: 40;
    width: 100%;
    border-radius: 0;
    pointer-events: auto;
  }

  .book--help-open .book__help {
    align-self: stretch;
    width: 100%;
    max-width: none;
    padding: 1rem 1.1rem max(1.15rem, env(safe-area-inset-bottom)) 1.1rem;
  }

  .book__facing-mark-slot {
    opacity: 0;
  }

  .book__help-fab {
    position: fixed;
    z-index: 45;
    left: 0.85rem;
    bottom: max(0.85rem, env(safe-area-inset-bottom));
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 3.5rem;
    height: 2.5rem;
    padding: 0 0.9rem;
    border: 1px solid rgba(var(--help-ink-rgb), 0.2);
    border-radius: 999px;
    background:
      linear-gradient(165deg, color-mix(in srgb, var(--cream) 55%, transparent) 0%, transparent 42%),
      var(--facing-tip-paper);
    color: var(--facing-tip-ink);
    font-family: var(--font-fraunces), serif;
    font-size: 1rem;
    font-weight: 600;
    box-shadow:
      0 10px 24px rgba(var(--shade-cool-rgb), 0.22),
      0 2px 6px rgba(var(--shade-cool-rgb), 0.1);
    cursor: pointer;
  }

  .book--help-open .book__help-fab {
    left: auto;
    right: 0.85rem;
  }

  .facing-tip {
    left: 0.85rem;
    right: 0.85rem;
    bottom: calc(3.5rem + env(safe-area-inset-bottom));
    width: auto;
    max-width: none;
  }

  .facing-tip__arrow {
    left: 1.1rem;
    top: auto;
    bottom: -0.36rem;
    border-left: 1px solid var(--facing-tip-edge);
    border-bottom: 1px solid var(--facing-tip-edge);
    border-right: 0;
    border-top: 0;
    rotate: -45deg;
  }
}

