:root {
  color-scheme: light;
  --bg: #f4efe3;
  --ink: #1f2720;
  --muted: #667064;
  --green: #2f6d42;
  --green-dark: #19472e;
  --gold: #c59b36;
  --cream: #fffaf0;
  --line: rgba(31, 39, 32, 0.14);
  --shadow: 0 24px 70px rgba(28, 24, 16, 0.18);
  --page-ratio: 1177 / 2504;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background:
    linear-gradient(135deg, rgba(47, 109, 66, 0.08), transparent 36%),
    linear-gradient(225deg, rgba(197, 155, 54, 0.12), transparent 32%),
    var(--bg);
}

body {
  min-height: 100%;
  margin: 0;
  color: var(--ink);
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.45;
}

button {
  font: inherit;
}

.app-shell {
  width: min(1180px, calc(100% - 32px));
  min-height: 100dvh;
  margin: 0 auto;
  padding: 22px 0 32px;
}

.topbar {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 18px;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(1.85rem, 4vw, 3.8rem);
  line-height: 1;
}

.toolbar {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}

.icon-button,
.tool-button,
.nav-button,
.thumb-button {
  border: 1px solid var(--line);
  background: rgba(255, 250, 240, 0.88);
  color: var(--ink);
  cursor: pointer;
  transition:
    transform 150ms ease,
    border-color 150ms ease,
    background 150ms ease,
    color 150ms ease,
    box-shadow 150ms ease;
}

.icon-button:hover,
.tool-button:hover,
.nav-button:hover,
.thumb-button:hover {
  transform: translateY(-1px);
  border-color: rgba(47, 109, 66, 0.42);
  box-shadow: 0 10px 24px rgba(31, 39, 32, 0.12);
}

.icon-button:focus-visible,
.tool-button:focus-visible,
.nav-button:focus-visible,
.thumb-button:focus-visible {
  outline: 3px solid rgba(197, 155, 54, 0.55);
  outline-offset: 3px;
}

.icon-button {
  display: inline-grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border-radius: 999px;
  font-size: 1.35rem;
  font-weight: 800;
}

.tool-button {
  min-height: 42px;
  padding: 0 16px;
  border-radius: 999px;
  font-weight: 800;
}

.viewer {
  position: relative;
  display: grid;
  grid-template-columns: 64px minmax(260px, 560px) 64px;
  align-items: center;
  justify-content: center;
  gap: 16px;
}

.flyer-page {
  width: min(100%, 560px);
  justify-self: center;
  transform-origin: center left;
  perspective: 1400px;
}

.flyer-page.is-turning-forward {
  animation: turnForward 260ms ease;
}

.flyer-page.is-turning-backward {
  animation: turnBackward 260ms ease;
}

.page-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 800;
}

.page-meta span {
  padding: 5px 10px;
  border-radius: 999px;
  background: rgba(255, 250, 240, 0.78);
  border: 1px solid var(--line);
}

.page-art,
.thumb-art {
  background-image: var(--page-image);
  background-repeat: no-repeat;
  background-size: var(--bg-width, 300%) var(--bg-height, 100%);
}

.page-art {
  width: 100%;
  aspect-ratio: var(--page-ratio);
  border-radius: 8px;
  border: 1px solid rgba(31, 39, 32, 0.18);
  background-color: var(--cream);
  background-position: var(--bg-x, 0) var(--bg-y, 0);
  box-shadow: var(--shadow);
  cursor: zoom-in;
  touch-action: none;
  user-select: none;
}

.page-art.is-zoomed {
  cursor: grab;
}

.page-art.is-dragging {
  cursor: grabbing;
}

.page-caption {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 18px;
  margin-top: 14px;
}

.page-caption h2 {
  margin-bottom: 0;
  font-size: clamp(1.25rem, 2.6vw, 2rem);
  line-height: 1.1;
}

.page-caption p {
  margin-bottom: 0;
  color: var(--muted);
  font-weight: 700;
  text-align: right;
}

.nav-button {
  display: grid;
  width: 58px;
  height: 58px;
  place-items: center;
  border-radius: 999px;
  background: var(--green-dark);
  color: #fffdf6;
  font-size: 1.7rem;
  font-weight: 900;
}

.nav-button:disabled {
  opacity: 0.38;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.overview {
  margin-top: 24px;
}

.overview-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 12px;
}

.overview-header h2 {
  margin-bottom: 0;
  font-size: 1rem;
  text-transform: uppercase;
}

.pager-dots {
  display: flex;
  align-items: center;
  gap: 8px;
}

.dot {
  width: 10px;
  height: 10px;
  border: 0;
  border-radius: 999px;
  background: rgba(31, 39, 32, 0.26);
  cursor: pointer;
}

.dot[aria-current="true"] {
  width: 28px;
  background: var(--green);
}

.thumbnail-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(98px, 1fr));
  gap: 10px;
}

.thumb-button {
  display: grid;
  gap: 8px;
  min-width: 0;
  padding: 8px;
  border-radius: 8px;
  text-align: left;
}

.thumb-button[aria-current="true"] {
  border-color: var(--green);
  background: #f5f8ec;
  box-shadow: inset 0 0 0 2px rgba(47, 109, 66, 0.14);
}

.thumb-art {
  width: 100%;
  aspect-ratio: var(--page-ratio);
  border-radius: 6px;
  border: 1px solid var(--line);
  background-position: var(--thumb-x, 0%) center;
}

.thumb-label {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.thumb-label strong,
.thumb-label span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.thumb-label strong {
  font-size: 0.84rem;
}

.thumb-label span {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 700;
}

@keyframes turnForward {
  0% {
    transform: rotateY(0deg) translateX(0);
    opacity: 1;
  }

  50% {
    transform: rotateY(-8deg) translateX(10px);
    opacity: 0.78;
  }

  100% {
    transform: rotateY(0deg) translateX(0);
    opacity: 1;
  }
}

@keyframes turnBackward {
  0% {
    transform: rotateY(0deg) translateX(0);
    opacity: 1;
  }

  50% {
    transform: rotateY(8deg) translateX(-10px);
    opacity: 0.78;
  }

  100% {
    transform: rotateY(0deg) translateX(0);
    opacity: 1;
  }
}

@media (max-width: 760px) {
  .app-shell {
    width: min(100% - 18px, 560px);
    padding-top: 14px;
  }

  .topbar {
    align-items: center;
    flex-direction: column;
    text-align: center;
  }

  .toolbar {
    justify-content: center;
  }

  .viewer {
    grid-template-columns: 46px minmax(0, 1fr) 46px;
    gap: 8px;
  }

  .nav-button {
    width: 44px;
    height: 54px;
    font-size: 1.35rem;
  }

  .page-caption {
    display: grid;
    gap: 5px;
  }

  .page-caption p {
    text-align: left;
  }

  .thumbnail-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

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

  .flyer-page {
    grid-column: 1 / -1;
    grid-row: 1;
  }

  .nav-button {
    grid-row: 2;
    width: 100%;
    border-radius: 8px;
  }

  .nav-button--prev {
    grid-column: 1;
  }

  .nav-button--next {
    grid-column: 2;
  }

  .thumbnail-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

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