:root {
  --book-ux-tap: 44px;
}

#book-ux-directory {
  position: fixed;
  z-index: 10008;
  top: max(78px, calc(env(safe-area-inset-top) + 68px));
  right: max(12px, env(safe-area-inset-right));
  width: min(326px, calc(100vw - 24px));
  color: #eff5eb;
  font-family: var(--reading-face, Georgia, "Noto Serif SC", serif);
}

/* Open navigation surfaces must sit above the roaming assistant (10012/10013).
   Their closed controls keep their existing layer, so the assistant remains draggable. */
#book-ux-directory[open],
.site-ux .ux-book-navigation[open] {
  z-index: 10020 !important;
  isolation: isolate;
}

#book-ux-directory > summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  width: max-content;
  max-width: 100%;
  min-width: var(--book-ux-tap);
  min-height: var(--book-ux-tap);
  margin-inline-start: auto;
  padding: 8px 13px;
  box-sizing: border-box;
  list-style: none;
  border: 1px solid rgba(218, 194, 133, 0.58);
  border-radius: 999px;
  background: linear-gradient(145deg, rgba(19, 51, 57, 0.96), rgba(31, 71, 70, 0.94));
  box-shadow: 0 8px 24px rgba(1, 10, 17, 0.34), inset 0 1px rgba(255, 255, 255, 0.08);
  color: #f6f1df;
  font-size: 14px;
  font-weight: 650;
  line-height: 1.35;
  letter-spacing: 0.025em;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

#book-ux-directory > summary::-webkit-details-marker {
  display: none;
}

#book-ux-directory > summary::after {
  content: "+";
  flex: 0 0 auto;
  color: #dec98f;
  font: 700 18px/1 Georgia, serif;
}

#book-ux-directory[open] > summary {
  border-radius: 14px 14px 0 0;
  border-bottom-color: transparent;
}

#book-ux-directory[open] > summary::after {
  content: "−";
}

#book-ux-directory > summary:hover {
  border-color: rgba(235, 215, 159, 0.84);
  background: linear-gradient(145deg, rgba(26, 64, 67, 0.98), rgba(42, 82, 78, 0.96));
}

#book-ux-directory > summary:focus-visible,
#book-ux-directory button:focus-visible,
.book-ux-font-controls button:focus-visible {
  outline: 3px solid #f1d995;
  outline-offset: 3px;
}

.book-ux-directory-panel {
  margin: 0;
  padding: 16px;
  box-sizing: border-box;
  max-height: min(560px, calc(100dvh - 150px));
  overflow: auto;
  overscroll-behavior: contain;
  border: 1px solid rgba(198, 176, 117, 0.72);
  border-radius: 14px 0 14px 14px;
  background:
    linear-gradient(110deg, rgba(255, 252, 239, 0.985), rgba(238, 237, 218, 0.985)),
    #f5f0df;
  box-shadow: 0 18px 48px rgba(1, 10, 17, 0.42);
  color: #29494b;
}

.book-ux-directory-heading {
  margin: 0 0 12px;
  color: #294e52;
  font: 600 19px/1.35 var(--display-face, Georgia, "Noto Serif SC", serif);
  letter-spacing: 0.025em;
}

.book-ux-directory-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 7px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.book-ux-directory-list li {
  min-width: 0;
}

#book-ux-directory button {
  width: 100%;
  min-width: 0;
  min-height: var(--book-ux-tap);
  box-sizing: border-box;
  border: 1px solid #c7c5aa;
  border-radius: 8px;
  background: rgba(255, 253, 245, 0.88);
  color: #315357;
  font: 600 13px/1.4 var(--reading-face, Georgia, "Noto Serif SC", serif);
  cursor: pointer;
  touch-action: manipulation;
}

[data-book-ux-chapter] {
  display: grid;
  grid-template-columns: 28px minmax(0, 1fr);
  align-items: center;
  gap: 7px;
  padding: 8px 9px;
  text-align: left;
}

.book-ux-chapter-number {
  color: #9a7740;
  font: 600 11px/1.1 Georgia, serif;
  letter-spacing: 0.04em;
}

.book-ux-chapter-label {
  min-width: 0;
  overflow-wrap: anywhere;
}

#book-ux-directory button[aria-current="page"] {
  border-color: #3d6868;
  background: #355f61;
  color: #fff8e7;
  box-shadow: inset 3px 0 #d4b86f;
}

#book-ux-directory button[aria-current="page"] .book-ux-chapter-number {
  color: #f2d894;
}

#book-ux-directory button:hover:not(:disabled) {
  border-color: #668485;
  background: #f2f4e8;
}

#book-ux-directory button[aria-current="page"]:hover:not(:disabled) {
  background: #3f6b6b;
}

#book-ux-directory button:disabled {
  cursor: default;
  opacity: 0.52;
}

.book-ux-directory-footer {
  display: flex;
  justify-content: flex-end;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid rgba(159, 144, 105, 0.3);
}

[data-book-ux-action="contents"] {
  max-width: 180px;
  padding: 8px 12px;
}

body.chapter-reader-open #book-ux-directory {
  display: none;
}

.book-ux-font-controls {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-self: end;
  gap: 5px;
  min-width: 0;
  padding-top: 2px;
  font-family: var(--reading-face, Georgia, "Noto Serif SC", serif);
}

.book-ux-font-controls[hidden] {
  display: none !important;
}

.book-ux-font-label {
  margin-inline-end: 3px;
  color: #68746c;
  font-size: 12px;
  line-height: 1.4;
  white-space: nowrap;
}

body.immersive .chapter-reader .book-ux-font-controls button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: auto;
  min-width: var(--book-ux-tap);
  min-height: var(--book-ux-tap) !important;
  padding: 6px 9px !important;
  border: 1px solid #bdc8ba;
  border-radius: 7px !important;
  background: #fbfaf1;
  color: #345b5e;
  font: 600 14px/1 var(--reading-face, Georgia, "Noto Serif SC", serif);
}

body.immersive .chapter-reader .book-ux-font-controls [data-book-ux-font="reset"] {
  min-width: 58px;
  font-variant-numeric: tabular-nums;
}

body.immersive .chapter-reader .book-ux-font-controls button:disabled {
  opacity: 0.42;
}

body.immersive .reader-focus .native-book-sheet-body,
body.immersive .reader-focus .book-library-leaf p {
  font-size: var(--book-ux-body-size, 16px) !important;
}

body.immersive .reader-focus .native-book-sheet h3,
body.immersive .reader-focus .book-library-record-title,
body.immersive .reader-focus .book-library-card strong {
  font-size: var(--book-ux-heading-size, 20.8px) !important;
}

body.immersive .reader-focus .book-library-card > span {
  font-size: var(--book-ux-secondary-size, 14px) !important;
}

@media (max-width: 759px) {
  #book-ux-directory {
    top: max(72px, calc(env(safe-area-inset-top) + 62px));
    right: max(8px, env(safe-area-inset-right));
    width: min(318px, calc(100vw - 16px));
  }

  #book-ux-directory > summary {
    padding-inline: 11px;
    font-size: 13px;
  }

  .book-ux-directory-panel {
    max-height: calc(100dvh - 132px - env(safe-area-inset-bottom));
    padding: 13px;
  }

  .book-ux-directory-list {
    grid-template-columns: 1fr;
  }

  body:has(#book-pages.flat-reading) .camera-tools {
    display: none !important;
  }

  body:has(#book-pages.flat-reading) #book-ux-directory {
    top: max(14px, env(safe-area-inset-top));
    right: auto;
    left: max(8px, env(safe-area-inset-left));
  }

  body:has(#book-pages.flat-reading) #book-ux-directory > summary {
    margin-inline-start: 0;
  }

  body.immersive #book-actions {
    min-height: var(--book-ux-tap);
  }

  body.immersive #book-actions :is(button, a),
  body.immersive .camera-tools button,
  body.immersive .chapter-reader :is(button, select, a),
  body.immersive .book-library-panel :is(button, input, select) {
    min-height: var(--book-ux-tap) !important;
  }

  body.immersive #book-actions .page-turn button,
  body.immersive .camera-tools :is(#zoom-out, #zoom-in) {
    width: var(--book-ux-tap) !important;
    min-width: var(--book-ux-tap) !important;
    height: var(--book-ux-tap) !important;
    min-height: var(--book-ux-tap) !important;
  }

  body.immersive #book-pages.flat-reading:not(.chapter-reader-active),
  body.immersive #book-pages.flat-reading:not(.chapter-reader-active)[data-mainline-fit="content"] {
    --book-ux-flat-top: max(70px, calc(env(safe-area-inset-top) + 60px));
    --book-ux-flat-bottom: max(88px, calc(env(safe-area-inset-bottom) + 78px));
    display: block !important;
    top: var(--book-ux-flat-top) !important;
    right: max(8px, env(safe-area-inset-right)) !important;
    bottom: auto !important;
    left: max(8px, env(safe-area-inset-left)) !important;
    width: auto !important;
    height: auto !important;
    max-width: none !important;
    max-height: calc(100dvh - var(--book-ux-flat-top) - var(--book-ux-flat-bottom)) !important;
    overflow-x: hidden !important;
    overflow-y: auto !important;
    scroll-padding-block: 12px;
    overscroll-behavior: contain;
    transform: none !important;
  }

  body.immersive #book-pages.flat-reading:not(.chapter-reader-active)[data-mainline-fit] {
    overflow-y: auto !important;
  }

  body.immersive #book-pages.flat-reading:not(.chapter-reader-active) > :is(#paper-left, #paper-right) {
    position: relative !important;
    width: 100% !important;
    height: auto !important;
    min-width: 0 !important;
    min-height: 0 !important;
    max-height: none !important;
    overflow: visible !important;
    padding: 20px clamp(17px, 5.5vw, 28px) !important;
    box-sizing: border-box;
    border: 0;
    border-radius: 0;
    background: linear-gradient(105deg, #f9f4e6, #fffaf0 46%, #f1e7d1);
  }

  body.immersive #book-pages.flat-reading:not(.chapter-reader-active) > #paper-left {
    border-bottom: 1px solid #d1c29f;
  }

  body.immersive #book-pages.flat-reading:not(.chapter-reader-active) > #paper-right {
    box-shadow: inset 0 12px 18px -20px rgba(55, 43, 24, 0.75);
  }

  .book-ux-font-controls {
    justify-self: stretch;
    justify-content: flex-end;
    width: 100%;
  }

  .book-ux-font-label {
    margin-inline-end: auto;
  }
}

@media (max-width: 380px) {
  body:has(#book-pages.flat-reading:not(.chapter-reader-active)) #book-ux-directory {
    top: max(60px, calc(env(safe-area-inset-top) + 50px));
  }

  body.immersive:has(#book-pages.flat-reading:not(.chapter-reader-active)) #book-pages.flat-reading:not(.chapter-reader-active) {
    --book-ux-flat-top: max(116px, calc(env(safe-area-inset-top) + 108px));
    --book-ux-flat-bottom: max(90px, calc(env(safe-area-inset-bottom) + 80px));
  }
}

@media (max-width: 380px) {
  .book-ux-directory-heading {
    font-size: 17px;
  }

  .book-ux-font-label {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  #book-ux-directory *,
  .book-ux-font-controls * {
    scroll-behavior: auto !important;
    transition: none !important;
    animation: none !important;
  }
}
