:root { --header: 70px; }

.top {
  background: #f8f3e9;
  color: var(--ink);
}

.top .top-inner {
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  gap: 8px 16px;
  padding-inline: clamp(16px, 6vw, var(--page));
}

.top .brand { gap: 8px; }
.top .brand strong { color: var(--ink); }
.top .brand span { color: var(--muted); }
.top .top-actions { gap: 5px; }

.nav-sr-only {
  position: absolute;
  inline-size: 1px;
  block-size: 1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.chapter-dock {
  --chapter-icon-size: 42px;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 3px;
  padding: 3px;
  border: 1px solid #d9cfc3;
  border-radius: 8px;
  background: #eee5d8;
}

.chapter-dock:empty { visibility: hidden; }

.chapter-chip {
  position: relative;
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  inline-size: var(--chapter-icon-size);
  block-size: 39px;
  border-radius: 5px;
  color: #604c43;
  text-decoration: none;
}

.chapter-chip-icon {
  display: grid;
  place-items: center;
  flex: 0 0 var(--chapter-icon-size);
}

.chapter-chip-label-track {
  min-inline-size: 0;
  overflow: hidden;
  color: inherit;
  opacity: 0;
  translate: -3px 0;
  white-space: nowrap;
}

.chapter-chip-label {
  display: block;
  inline-size: max-content;
  padding-inline-end: 13px;
  font-size: .825rem;
  font-weight: 700;
  line-height: 1.25;
}

.chapter-label-short { display: none; }

.chapter-motion-ready .chapter-chip {
  transition: inline-size 410ms cubic-bezier(.24, 1.44, .42, 1), background-color 160ms ease, color 160ms ease;
}

.chapter-motion-ready .chapter-chip-label-track {
  transition: opacity 140ms ease-out, translate 235ms cubic-bezier(.22, 1, .36, 1);
}

.chapter-chip:is(:hover, :focus-visible) {
  background: #e3d6c8;
  color: var(--deep);
}

.chapter-chip[aria-current] {
  inline-size: calc(var(--chapter-icon-size) + var(--chapter-label-size, 58px));
  background: var(--wine);
  color: #fff9ef;
}

.chapter-chip[aria-current] .chapter-chip-label-track {
  opacity: 1;
  translate: 0 0;
}

.chapter-chip svg,
.chapter-rail svg,
.report-icon-tool svg,
#chapter-nav svg {
  display: block;
  inline-size: 19px;
  block-size: 19px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.top-actions .report-icon-tool {
  position: relative;
  display: inline-grid;
  place-items: center;
  inline-size: 41px;
  block-size: 41px;
  min-block-size: 41px;
  padding: 0;
  border: 1px solid transparent;
  border-radius: 5px;
  color: #604c43;
}

.top-actions .report-icon-tool:is(:hover, :focus-visible),
.top-actions .directory[open] summary,
.playing .top-actions .header-listen {
  color: var(--wine);
  background: #eee5d8;
  border-color: #d9cfc3;
}

#fullscreen .leave-fullscreen,
.presentation #fullscreen .enter-fullscreen { display: none; }
.presentation #fullscreen .leave-fullscreen { display: block; }

.nav-tool-tip,
.report-icon-tool[data-tooltip]::after {
  z-index: 2;
  position: absolute;
  inset: calc(100% + 9px) auto auto 50%;
  padding: .42rem .62rem;
  border-radius: 3px;
  background: #2c1b19;
  color: #fff9ef;
  font-size: .76rem;
  font-weight: 650;
  line-height: 1.2;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transform: translate(-50%, -3px);
  transition: opacity 130ms ease, transform 170ms ease-out;
}

.report-icon-tool[data-tooltip]::after { content: attr(data-tooltip); }
.chapter-chip:not([aria-current]):is(:hover, :focus-visible) .nav-tool-tip,
.report-icon-tool:is(:hover, :focus-visible) .nav-tool-tip,
.report-icon-tool:is(:hover, :focus-visible)[data-tooltip]::after {
  opacity: 1;
  transform: translate(-50%, 0);
}

.directory[open] .report-icon-tool[data-tooltip]::after { opacity: 0; }
#directory #chapter-nav {
  width: min(280px, calc(100vw - 30px));
  max-height: calc(100dvh - var(--header) - 20px);
  overflow-y: auto;
  padding: 6px;
  border: 1px solid #d9cfc3;
  border-radius: 7px;
  background: var(--paper);
  box-shadow: 0 12px 32px #3519121b;
}

#directory #chapter-nav a {
  display: grid;
  grid-template-columns: 20px minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  min-height: 43px;
  padding: 7px 11px;
  border: 0;
  border-radius: 4px;
  color: var(--ink);
}

#directory #chapter-nav a:is(:hover, [aria-current]) {
  background: #eee0d5;
  color: var(--wine);
  text-decoration: none;
}

#directory #chapter-nav a:focus-visible { outline-offset: -3px; }

.reading-ready .read-progress {
  background: #d9cfc3;
  overflow: hidden;
}

.reading-ready #chapter-progress { display: none; }

.read-progress .report-scroll-progress {
  inline-size: 100%;
  transform: scaleX(var(--report-scroll, 0));
  transform-origin: left center;
}

.chapter-rail { display: none; }

@media (min-width: 1200px) and (min-height: 650px) {
  #report .chapter:not(.cover) { padding-inline: max(76px, var(--page)); }
  .presentation #report .chapter:not(.cover) { padding-inline: max(76px, calc((100vw - 1480px) / 2)); }

  .chapter-rail {
    position: fixed;
    z-index: 5;
    inset: calc(var(--header) + clamp(14px, (100dvh - 660px) * .24, 78px)) clamp(12px, calc(var(--page) - 68px), 40px) auto auto;
    display: grid;
    justify-items: center;
    inline-size: 54px;
    padding: 8px 5px 6px;
    border: 1px solid #56443d;
    border-radius: 8px;
    background: #2c1b19;
    color: #eadbca;
    box-shadow: 0 6px 14px #24131024;
  }

  .chapter-rail-folio {
    margin: 0 0 6px;
    color: #edcfb7;
    font-family: Georgia, serif;
    font-size: .75rem;
    font-variant-numeric: tabular-nums;
    line-height: 1.4;
  }

  .chapter-rail-links {
    display: grid;
    justify-items: center;
    inline-size: 100%;
    gap: 2px;
    padding-block: 5px;
    border-block: 1px solid #684e43;
  }

  .chapter-rail-link,
  .chapter-rail-move {
    position: relative;
    display: grid;
    place-items: center;
    inline-size: 37px;
    block-size: 30px;
    padding: 0;
    border: 0;
    border-radius: 4px;
    background: transparent;
    color: inherit;
    text-decoration: none;
  }

  .chapter-rail-link:is(:hover, :focus-visible):not([aria-current]),
  .chapter-rail-move:is(:hover, :focus-visible):not(:disabled) { background: #49332d; }

  .chapter-rail-link[aria-current] {
    background: #edcfb7;
    color: #3d221c;
  }

  .chapter-rail-link:focus-visible,
  .chapter-rail-move:focus-visible { outline-offset: 2px; }

  .chapter-rail .nav-tool-tip,
  .chapter-rail-move::after {
    content: attr(data-tooltip);
    position: absolute;
    inset: 50% calc(100% + 13px) auto auto;
    padding: .45rem .62rem;
    border: 1px solid #684e43;
    border-radius: 3px;
    background: #2c1b19;
    color: #fff9ef;
    font-size: .76rem;
    font-weight: 650;
    line-height: 1.2;
    white-space: nowrap;
    pointer-events: none;
    opacity: 0;
    transform: translate(4px, -50%);
    transition: opacity 130ms ease, transform 170ms ease-out;
  }

  .chapter-rail-link:is(:hover, :focus-visible) .nav-tool-tip,
  .chapter-rail-move:is(:hover, :focus-visible):not(:disabled)::after {
    opacity: 1;
    transform: translate(0, -50%);
  }

  .chapter-rail-progress {
    margin-top: 7px;
    color: #edcfb7;
    font-size: .63rem;
    font-variant-numeric: tabular-nums;
  }

  .chapter-rail-controls { display: flex; justify-content: center; }
  .chapter-rail-move { inline-size: 23px; block-size: 28px; }
  .chapter-rail-move svg { inline-size: 16px; block-size: 16px; }

  .chapter-rail-meter {
    position: relative;
    inline-size: 31px;
    block-size: 2px;
    margin-block: 2px 4px;
    background: #684e43;
    overflow: hidden;
  }

  .chapter-rail-meter::before {
    content: '';
    position: absolute;
    inset: 0;
    background: #ffc7a7;
    transform: scaleX(var(--report-scroll, 0));
    transform-origin: left center;
  }
}

@media (max-width: 899px) {
  :root { --header: 101px; }

  .top .top-inner {
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-rows: 45px 44px;
    gap: 0 8px;
    padding-block: 3px 9px;
  }

  .top .top-actions { grid-column: 2; grid-row: 1; }
  .top .brand { grid-row: 1; }

  .chapter-dock {
    grid-column: 1 / -1;
    justify-self: center;
    grid-row: 2;
  }

  .top-actions .report-icon-tool { inline-size: 39px; block-size: 39px; min-block-size: 39px; }
  .chapter-chip { block-size: 36px; }
}

@media (max-width: 520px) {
  .chapter-dock { --chapter-icon-size: clamp(30px, 8.6vw, 39px); gap: 2px; }
  .chapter-chip-label { font-size: .76rem; padding-inline-end: 8px; }
  .chapter-label-full { display: none; }
  .chapter-label-short { display: inline; }

  .chapter-chip:nth-child(-n + 2) .nav-tool-tip { inset-inline-start: 0; transform: none; }
  .chapter-chip:nth-last-child(-n + 2) .nav-tool-tip { inset-inline: auto 0; transform: none; }
  .top-actions [data-tooltip='目录']::after { inset-inline: auto 0; transform: none; }
}

@media (prefers-reduced-motion: reduce) {
  .chapter-motion-ready .chapter-chip,
  .chapter-motion-ready .chapter-chip-label-track,
  .nav-tool-tip,
  .report-icon-tool[data-tooltip]::after,
  .chapter-rail-move::after { transition: none; }
}
