:root {
  color: #2e241f;
  background: #f4efe5;
  font-family: "Hiragino Kaku Gothic ProN", "Yu Gothic", "YuGothic", sans-serif;
  font-synthesis: none;
  --burgundy-dark: #53080b;
  --burgundy: #7c1015;
  --paper: #f4efe5;
  --ink: #2e241f;
  --muted: #756960;
  --line: rgba(83, 8, 11, 0.25);
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background-color: var(--paper);
  background-image: url("../assets/paper-topography.png");
  background-position: center top;
  background-size: cover;
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
}

button,
a {
  font: inherit;
}

button:focus-visible,
a:focus-visible {
  outline: 3px solid #c77d57;
  outline-offset: 4px;
}

.skip-link {
  position: fixed;
  top: 12px;
  left: 12px;
  z-index: 20000;
  padding: 10px 14px;
  color: var(--burgundy-dark);
  background: #fff;
  transform: translateY(-160%);
}

.skip-link:focus {
  transform: translateY(0);
}

.site-header {
  position: relative;
  min-height: 76px;
  padding: 12px clamp(20px, 3vw, 48px);
  color: #fffaf1;
  background: var(--burgundy-dark);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
}

.header-copy {
  position: absolute;
  top: 50%;
  left: 50%;
  margin: 0;
  font-family: "Yu Mincho", "Hiragino Mincho ProN", serif;
  font-size: clamp(14px, 1.35vw, 18px);
  font-weight: 400;
  letter-spacing: 0.1em;
  line-height: 1.4;
  text-align: center;
  white-space: nowrap;
  transform: translate(-50%, -50%);
  pointer-events: none;
}

.wordmark {
  color: inherit;
  display: inline-block;
  line-height: 1.2;
  letter-spacing: 0.1em;
  text-decoration: none;
  white-space: nowrap;
}

.wordmark span {
  font-family: "Yu Mincho", "Hiragino Mincho ProN", serif;
  font-size: 16px;
  font-weight: 500;
}

.header-actions {
  display: flex;
  gap: 12px;
}

.action {
  min-height: 44px;
  padding: 10px 20px;
  color: #fffaf1;
  border: 1px solid rgba(255, 250, 241, 0.72);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  letter-spacing: 0.08em;
  text-decoration: none;
  transition: color 180ms ease, background-color 180ms ease;
}

.action-primary {
  background: var(--burgundy);
}

.action:hover {
  color: var(--burgundy-dark);
  background: #fffaf1;
}

.stage {
  width: min(100%, 1540px);
  margin: 0 auto;
  padding: clamp(32px, 5vh, 58px) clamp(18px, 4vw, 64px) 30px;
  display: grid;
  grid-template-columns: minmax(270px, 0.6fr) minmax(650px, 1.7fr);
  gap: clamp(24px, 3vw, 54px);
  align-items: center;
}

.reader {
  min-width: 0;
  position: relative;
}

.reader-actions {
  position: absolute;
  top: -8px;
  right: 0;
  z-index: 10000;
  display: flex;
  gap: 8px;
}

.reader-actions button,
.turn-button {
  color: var(--burgundy-dark);
  background: rgba(255, 253, 247, 0.92);
  border: 1px solid var(--line);
  cursor: pointer;
  transition: color 180ms ease, background-color 180ms ease, transform 180ms ease;
}

.reader-actions button {
  min-height: 42px;
  padding: 8px 13px;
}

.reader-actions button:hover,
.turn-button:hover:not(:disabled) {
  color: #fffaf1;
  background: var(--burgundy);
}

.book-area {
  min-height: 650px;
  padding-top: 38px;
  display: block;
}

.book-shell {
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

#book {
  width: 100%;
  height: 580px;
  filter: drop-shadow(0 20px 24px rgba(56, 36, 24, 0.18));
}

.page {
  background: #fff;
  overflow: hidden;
}

.page img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  user-select: none;
  pointer-events: none;
}

.turn-button {
  min-width: 156px;
  min-height: 56px;
  padding: 12px 34px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  letter-spacing: 0.12em;
}

.turn-controls {
  margin-top: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 18px;
}

.turn-button:disabled {
  opacity: 0.28;
  cursor: not-allowed;
}

.page-count {
  margin: 14px 0 0;
  color: var(--burgundy-dark);
  font-family: "Yu Mincho", "Hiragino Mincho ProN", serif;
  font-size: 18px;
  letter-spacing: 0.12em;
}

.gesture-note {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 11px;
  letter-spacing: 0.04em;
  text-align: center;
}

.thumbnail-list {
  display: flex;
  align-items: end;
  gap: 10px;
  padding: 10px 4px 14px;
  overflow-x: auto;
  scrollbar-color: rgba(83, 8, 11, 0.4) transparent;
}

.thumbnail {
  width: 70px;
  flex: 0 0 70px;
  padding: 4px 4px 6px;
  color: var(--muted);
  background: transparent;
  border: 1px solid transparent;
  cursor: pointer;
  transition: transform 180ms ease, border-color 180ms ease, background-color 180ms ease;
}

.thumbnail:hover {
  transform: translateY(-3px);
}

.thumbnail.is-active {
  color: var(--burgundy-dark);
  background: rgba(255, 253, 247, 0.7);
  border-color: var(--burgundy);
}

.thumbnail img {
  display: block;
  width: 100%;
  aspect-ratio: 2480 / 3508;
  object-fit: cover;
  box-shadow: 0 5px 12px rgba(56, 36, 24, 0.12);
}

.thumbnail span {
  display: block;
  margin-top: 5px;
  font-size: 11px;
}

.reader:fullscreen {
  width: 100%;
  max-width: none;
  height: 100%;
  margin: 0;
  padding: 18px 24px 16px;
  color: var(--ink);
  background-color: var(--paper);
  background-image: url("../assets/paper-topography.png");
  background-position: center;
  background-size: cover;
  overflow: hidden;
}

.reader:fullscreen .reader-actions {
  top: 18px;
  right: 24px;
}

.reader:fullscreen .book-area {
  height: 100%;
  min-height: 0;
  padding: 52px 0 78px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.reader:fullscreen .book-shell {
  width: 100%;
  flex: 1 1 100%;
}

.reader:fullscreen #book {
  width: 100%;
  max-width: min(1360px, calc(100vw - 48px));
  height: min(calc(100vh - 220px), 792px);
  margin-inline: auto;
}

.reader:fullscreen .turn-controls {
  position: absolute;
  left: 50%;
  bottom: 18px;
  z-index: 20000;
  margin: 0;
  transform: translateX(-50%);
  pointer-events: auto;
  gap: 24px;
}

.reader:fullscreen .turn-button {
  min-width: 176px;
  min-height: 60px;
  padding-inline: 42px;
  background: #fffdf7;
  box-shadow: 0 8px 24px rgba(56, 36, 24, 0.2);
  pointer-events: auto;
}

.reader:fullscreen .thumbnail-list {
  display: none;
}

.loading {
  position: fixed;
  inset: 0;
  z-index: 30000;
  color: var(--burgundy-dark);
  background: var(--paper);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  transition: opacity 300ms ease, visibility 300ms ease;
}

.loading.is-hidden {
  opacity: 0;
  visibility: hidden;
}

.loading p {
  margin: 0;
  font-family: "Yu Mincho", "Hiragino Mincho ProN", serif;
  letter-spacing: 0.12em;
}

.loading-mark {
  width: 54px;
  height: 54px;
  border: 3px solid rgba(83, 8, 11, 0.16);
  border-top-color: var(--burgundy);
  border-radius: 50%;
  animation: rotate 800ms linear infinite;
}

.error-message {
  position: fixed;
  inset: 0;
  z-index: 31000;
  padding: 28px;
  color: var(--burgundy-dark);
  background: var(--paper);
  text-align: center;
}

@keyframes rotate {
  to {
    transform: rotate(360deg);
  }
}

@media (min-width: 1051px) {
  .stage {
    padding-top: clamp(22px, 3vh, 34px);
    grid-template-columns: 1fr;
    gap: 0;
    align-items: start;
  }

  .reader {
    width: min(100%, 1280px);
    margin: 0 auto;
    padding-left: 0;
  }

  .book-area {
    min-height: 790px;
    padding-top: 42px;
  }

  #book {
    max-width: 1180px;
    height: clamp(650px, 76vh, 820px);
    margin-inline: auto;
  }

  .thumbnail-list {
    width: min(100%, 1180px);
    margin-inline: auto;
  }
}

@media (max-width: 1050px) {
  .stage {
    grid-template-columns: 1fr;
  }

  .reader {
    width: min(100%, 900px);
    margin: 0 auto;
  }
}

@media (max-width: 760px) {
  .site-header {
    min-height: 84px;
    padding: 9px 13px;
    align-items: flex-start;
  }

  .header-copy {
    top: 58px;
    width: calc(100% - 24px);
    font-size: 11px;
    letter-spacing: 0.06em;
  }

  .wordmark span {
    font-size: 11px;
    letter-spacing: 0.04em;
  }

  .action {
    min-height: 42px;
    padding-inline: 12px;
    font-size: 12px;
  }

  .action-secondary {
    display: none;
  }

  .stage {
    padding: 28px 8px 24px;
  }

  .book-area {
    min-height: 510px;
  }

  #book {
    height: min(68vh, 560px);
  }

  .turn-button {
    min-width: 120px;
    min-height: 48px;
    padding-inline: 22px;
    font-size: 11px;
  }

  .turn-controls {
    margin-top: 12px;
    gap: 10px;
  }

  .reader-actions {
    top: 0;
    right: 7px;
  }

  .reader-actions button {
    min-height: 38px;
    padding: 7px 10px;
    font-size: 11px;
  }

  .thumbnail {
    width: 62px;
    flex-basis: 62px;
  }

  .gesture-note {
    padding-inline: 16px;
  }
}

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