:root {
  --ink: #2b2724;
  --muted: #7e7269;
  --paper: #f4efe8;
  --paper-deep: #e9dfd5;
  --line: rgba(63, 46, 37, 0.16);
  --accent: #b76645;
  --accent-soft: #d9a489;
  --topbar-height: 72px;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
  background: var(--paper);
  overflow-x: hidden;
}

body {
  margin: 0;
  min-width: 0;
  overflow-x: hidden;
  color: var(--ink);
  background:
    linear-gradient(rgba(98, 71, 53, 0.035) 1px, transparent 1px),
    var(--paper);
  background-size: 100% 32px;
  font-family: Inter, "Noto Sans SC", "Microsoft YaHei", sans-serif;
}

button,
a {
  font: inherit;
}

button,
a.tool-button {
  -webkit-tap-highlight-color: transparent;
}

.progress {
  position: fixed;
  inset: 0 0 auto;
  z-index: 20;
  height: 3px;
  background: transparent;
}

.progress span {
  display: block;
  width: 0;
  height: 100%;
  background: var(--accent);
  transition: width 120ms ease-out;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  min-height: var(--topbar-height);
  padding: 12px 28px;
  border-bottom: 1px solid var(--line);
  background: rgba(244, 239, 232, 0.92);
  backdrop-filter: blur(16px);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
  color: var(--ink);
  text-decoration: none;
}

.brand-mark {
  display: grid;
  flex: 0 0 auto;
  place-items: center;
  width: 42px;
  height: 42px;
  border: 1px solid var(--ink);
  border-radius: 50%;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.08em;
}

.brand-text {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.03em;
}

.toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
}

.tool-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 36px;
  padding: 0 13px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--ink);
  background: rgba(255, 252, 248, 0.72);
  text-decoration: none;
  cursor: pointer;
  transition: color 160ms ease, border-color 160ms ease, background 160ms ease;
}

.tool-button:hover,
.tool-button:focus-visible {
  border-color: var(--accent);
  color: var(--accent);
  outline: none;
}

.tool-button[aria-pressed="true"] {
  border-color: var(--accent);
  background: rgba(183, 102, 69, 0.1);
}

.shell {
  display: grid;
  grid-template-columns: 188px minmax(0, 1fr);
  gap: 32px;
  width: min(1480px, 100%);
  margin: 0 auto;
  padding: 28px 28px 72px;
}

.thumb-rail {
  position: sticky;
  top: calc(var(--topbar-height) + 24px);
  align-self: start;
  display: grid;
  gap: 12px;
  max-height: calc(100vh - var(--topbar-height) - 48px);
  padding-right: 10px;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--accent-soft) transparent;
}

.thumb-button {
  display: grid;
  gap: 6px;
  width: 100%;
  padding: 0;
  border: 0;
  color: var(--muted);
  background: transparent;
  text-align: left;
  cursor: pointer;
}

.thumb-image {
  display: block;
  width: 100%;
  height: auto;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--paper-deep);
  opacity: 0.62;
  transition: opacity 160ms ease, border-color 160ms ease, transform 160ms ease;
}

.thumb-button:hover .thumb-image,
.thumb-button:focus-visible .thumb-image,
.thumb-button[aria-current="true"] .thumb-image {
  border-color: var(--accent);
  opacity: 1;
  transform: translateY(-2px);
}

.thumb-label {
  padding-left: 2px;
  font-size: 11px;
  letter-spacing: 0.08em;
}

.thumb-button[aria-current="true"] .thumb-label {
  color: var(--accent);
  font-weight: 700;
}

.viewer {
  min-width: 0;
  max-width: 100%;
}

.viewer-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 20px;
  min-height: 28px;
  margin: 0 0 16px;
}

.kicker,
.page-status {
  margin: 0;
  color: var(--muted);
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.page-status {
  letter-spacing: 0.05em;
  text-transform: none;
}

.pages {
  display: grid;
  gap: 40px;
}

.page {
  scroll-margin-top: calc(var(--topbar-height) + 24px);
  margin: 0;
}

.page img {
  display: block;
  max-width: 100%;
  width: 100%;
  height: auto;
  border: 1px solid rgba(63, 46, 37, 0.12);
  border-radius: 6px;
  background: #e7ddd3;
  box-shadow: 0 14px 34px rgba(53, 35, 26, 0.12);
}

.page-number {
  display: block;
  margin-top: 8px;
  color: var(--muted);
  font-size: 10px;
  letter-spacing: 0.1em;
  text-align: right;
}

.back-top {
  position: fixed;
  right: 24px;
  bottom: 24px;
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 50%;
  color: var(--ink);
  background: rgba(244, 239, 232, 0.9);
  box-shadow: 0 8px 24px rgba(53, 35, 26, 0.1);
  cursor: pointer;
  opacity: 0;
  pointer-events: none;
  transform: translateY(8px);
  transition: opacity 160ms ease, transform 160ms ease, border-color 160ms ease;
}

.back-top.is-visible {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
}

.back-top:hover,
.back-top:focus-visible {
  border-color: var(--accent);
  outline: none;
}

body.thumbs-hidden .shell {
  grid-template-columns: minmax(0, 1060px);
  justify-content: center;
}

body.wide .shell {
  width: min(1760px, 100%);
}

body.wide .pages {
  gap: 28px;
}

@media (max-width: 800px) {
  :root {
    --topbar-height: 62px;
  }

  .topbar {
    width: 100%;
    overflow: hidden;
    min-height: var(--topbar-height);
    padding: 10px 14px;
  }

  .brand {
    gap: 8px;
  }

  .brand-mark {
    width: 34px;
    height: 34px;
    font-size: 8px;
  }

  .brand-text {
    max-width: 165px;
    font-size: 12px;
  }

  .toolbar {
    gap: 5px;
  }

  .tool-button {
    min-height: 34px;
    padding: 0 8px;
    font-size: 12px;
  }

  .tool-button:first-child {
    display: none;
  }

  .shell,
  body.thumbs-hidden .shell,
  body.wide .shell {
    display: block;
    width: 100%;
    padding: 14px 10px 52px;
  }

  .thumb-rail {
    position: sticky;
    top: var(--topbar-height);
    z-index: 5;
    display: flex;
    gap: 8px;
    max-height: none;
    margin: -14px -10px 16px;
    padding: 10px;
    overflow-x: auto;
    overflow-y: hidden;
    overscroll-behavior-x: contain;
    -webkit-overflow-scrolling: touch;
    touch-action: pan-x;
    background: rgba(244, 239, 232, 0.94);
    border-bottom: 1px solid var(--line);
  }

  .thumb-button {
    flex: 0 0 66px;
  }

  .thumb-label {
    font-size: 9px;
  }

  body.thumbs-hidden .thumb-rail {
    display: none;
  }

  .viewer-head {
    margin-bottom: 10px;
  }

  .pages {
    gap: 22px;
  }

  .page img {
    max-width: 100%;
    border-radius: 3px;
    box-shadow: 0 8px 22px rgba(53, 35, 26, 0.1);
  }

  .back-top {
    right: 14px;
    bottom: 14px;
  }
}

@media (min-width: 801px) and (max-width: 1120px) {
  .shell {
    grid-template-columns: 148px minmax(0, 1fr);
    gap: 20px;
    padding-inline: 20px;
  }

  .topbar {
    padding-inline: 20px;
  }
}

@media (max-width: 480px) {
  .topbar {
    gap: 8px;
    padding-inline: 10px;
  }

  .brand-text {
    max-width: min(42vw, 170px);
    font-size: 11px;
  }

  .tool-button {
    padding-inline: 7px;
    font-size: 11px;
    white-space: nowrap;
  }

  .shell,
  body.thumbs-hidden .shell,
  body.wide .shell {
    padding-inline: 8px;
  }

  .thumb-rail {
    margin-inline: -8px;
    padding-inline: 8px;
  }

  .thumb-button {
    flex-basis: 60px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
  }
}
