:root {
  --bamboo: #0b4a36;
  --bamboo-deep: #073c2c;
  --ivory: #f8f2e7;
  --ivory-light: #fffdf8;
  --mustard: #d9a621;
  --terracotta: #c94735;
  --charcoal: #1f1f1f;
  --muted: #68645d;
  --line: #ded3c2;
  --shadow: 0 14px 40px rgba(21, 45, 35, 0.12);
  --app-width: 760px;
  font-family:
    -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial,
    sans-serif;
  color: var(--charcoal);
  background: #e9e2d6;
  font-synthesis: none;
  text-rendering: optimizeLegibility;
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
}

body {
  min-width: 320px;
  min-height: 100dvh;
  margin: 0;
  background:
    radial-gradient(circle at top, rgba(255, 255, 255, 0.7), transparent 44rem),
    #e9e2d6;
}

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

button {
  font: inherit;
}

button:focus-visible,
a:focus-visible {
  outline: 3px solid var(--mustard);
  outline-offset: 3px;
}

.skip-link {
  position: fixed;
  top: 0.75rem;
  left: 0.75rem;
  z-index: 100;
  padding: 0.75rem 1rem;
  border-radius: 0.75rem;
  color: white;
  background: var(--terracotta);
  font-weight: 800;
  transform: translateY(-180%);
}

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

.app-shell {
  position: relative;
  width: min(100%, var(--app-width));
  min-height: 100dvh;
  margin-inline: auto;
  overflow: clip;
  background: var(--ivory);
  box-shadow: 0 0 50px rgba(26, 35, 31, 0.12);
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  min-height: 72px;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding:
    calc(0.5rem + env(safe-area-inset-top))
    max(1rem, env(safe-area-inset-right)) 0.5rem
    max(1rem, env(safe-area-inset-left));
  border-bottom: 1px solid rgba(11, 74, 54, 0.1);
  background: rgba(255, 253, 248, 0.96);
  backdrop-filter: blur(14px);
}

.brand-lockup {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: 0.7rem;
}

.brand-logo {
  width: 54px;
  height: 54px;
  flex: 0 0 54px;
  border-radius: 0.75rem;
  object-fit: contain;
}

.brand-copy {
  min-width: 0;
}

.brand-name {
  display: block;
  margin-bottom: 0.1rem;
  color: var(--terracotta);
  font-size: 0.68rem;
  font-weight: 800;
  letter-spacing: 0.18em;
}

.brand-copy h1 {
  overflow: hidden;
  margin: 0;
  color: var(--bamboo);
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(1.25rem, 5vw, 1.8rem);
  line-height: 1.05;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.pdf-button {
  display: inline-flex;
  min-width: 52px;
  min-height: 48px;
  flex: 0 0 auto;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  padding: 0.55rem 0.7rem;
  border: 1px solid rgba(11, 74, 54, 0.24);
  border-radius: 0.9rem;
  color: var(--bamboo);
  background: var(--ivory-light);
  font-size: 0.75rem;
  font-weight: 900;
  text-decoration: none;
}

.pdf-button:hover {
  border-color: var(--bamboo);
  background: white;
}

.pdf-button svg {
  width: 23px;
  height: 23px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.8;
}

.page-control-bar {
  position: sticky;
  top: calc(72px + env(safe-area-inset-top));
  z-index: 25;
  display: grid;
  min-height: 64px;
  grid-template-columns: 48px 1fr 48px;
  align-items: center;
  gap: 0.75rem;
  padding: 0.5rem max(1rem, env(safe-area-inset-right)) 0.5rem
    max(1rem, env(safe-area-inset-left));
  color: white;
  background: var(--bamboo);
  box-shadow: 0 6px 18px rgba(7, 60, 44, 0.18);
}

.square-control {
  display: inline-grid;
  width: 48px;
  height: 48px;
  place-items: center;
  border: 1.5px solid rgba(255, 255, 255, 0.8);
  border-radius: 0.8rem;
  color: white;
  background: transparent;
  cursor: pointer;
}

.square-control:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.12);
}

.square-control:disabled {
  cursor: not-allowed;
  opacity: 0.32;
}

.square-control svg {
  width: 28px;
  height: 28px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.8;
}

.page-status {
  min-width: 0;
  text-align: center;
}

.page-status strong,
.page-status span {
  display: block;
}

.page-status strong {
  font-size: 1rem;
  line-height: 1.15;
}

.page-status span {
  overflow: hidden;
  margin-top: 0.15rem;
  color: rgba(255, 255, 255, 0.76);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-overflow: ellipsis;
  text-transform: uppercase;
  white-space: nowrap;
}

main {
  display: block;
  padding: clamp(0.75rem, 3vw, 1.25rem);
}

.document-shell {
  position: relative;
  overflow: hidden;
  border: 1px solid rgba(11, 74, 54, 0.16);
  border-radius: clamp(0.8rem, 3vw, 1.2rem);
  background: var(--ivory-light);
  box-shadow: var(--shadow);
}

.document-link {
  position: relative;
  display: block;
  color: inherit;
  background: var(--ivory);
}

.document-link::after {
  position: absolute;
  right: 0.75rem;
  bottom: 0.75rem;
  width: 2.5rem;
  height: 2.5rem;
  border: 1px solid rgba(255, 255, 255, 0.7);
  border-radius: 999px;
  color: white;
  background: rgba(7, 60, 44, 0.82);
  content: "＋";
  font-size: 1.55rem;
  font-weight: 300;
  line-height: 2.35rem;
  text-align: center;
  box-shadow: 0 4px 14px rgba(7, 60, 44, 0.25);
  backdrop-filter: blur(6px);
  pointer-events: none;
}

#guideImage {
  position: relative;
  z-index: 2;
  display: block;
  width: 100%;
  height: auto;
  background: var(--ivory);
  transition: opacity 160ms ease;
  user-select: none;
  -webkit-user-drag: none;
}

.document-shell.is-loading #guideImage {
  opacity: 0;
}

.loading-sheen {
  position: absolute;
  inset: 0;
  z-index: 1;
  min-height: 70vh;
  background:
    linear-gradient(
      110deg,
      transparent 20%,
      rgba(255, 255, 255, 0.75) 38%,
      transparent 56%
    ),
    #eee7da;
  background-size: 220% 100%;
  animation: loading 1.2s linear infinite;
}

.bottom-nav {
  position: sticky;
  bottom: 0;
  z-index: 30;
  display: grid;
  grid-template-columns: 1fr 1.18fr 1fr;
  padding-bottom: env(safe-area-inset-bottom);
  border-top: 1px solid var(--line);
  background: rgba(255, 253, 248, 0.97);
  box-shadow: 0 -8px 22px rgba(25, 45, 37, 0.11);
  backdrop-filter: blur(14px);
}

.bottom-control {
  display: flex;
  min-width: 0;
  min-height: 72px;
  align-items: center;
  justify-content: center;
  gap: 0.38rem;
  padding: 0.65rem 0.35rem;
  border: 0;
  border-right: 1px solid var(--line);
  color: var(--bamboo);
  background: transparent;
  cursor: pointer;
}

.bottom-control:last-child {
  border-right: 0;
}

.bottom-control:hover:not(:disabled) {
  background: rgba(11, 74, 54, 0.05);
}

.bottom-control:disabled {
  cursor: not-allowed;
  opacity: 0.34;
}

.bottom-control svg {
  width: 26px;
  height: 26px;
  flex: 0 0 26px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.8;
}

.bottom-control span {
  overflow: hidden;
  font-size: clamp(0.67rem, 2.8vw, 0.85rem);
  font-weight: 760;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.progress-track {
  position: sticky;
  bottom: calc(72px + env(safe-area-inset-bottom));
  z-index: 31;
  height: 4px;
  overflow: hidden;
  background: rgba(217, 166, 33, 0.15);
  pointer-events: none;
}

.progress-track span {
  display: block;
  width: 12.5%;
  height: 100%;
  border-radius: 0 99px 99px 0;
  background: var(--mustard);
  transition: width 220ms ease;
}

.page-dialog {
  width: min(92vw, 680px);
  max-height: min(84dvh, 880px);
  margin: auto;
  padding: 0;
  overflow: hidden;
  border: 0;
  border-radius: 1.35rem;
  color: var(--charcoal);
  background: var(--ivory-light);
  box-shadow: 0 28px 80px rgba(5, 34, 24, 0.35);
}

.page-dialog::backdrop {
  background: rgba(5, 34, 24, 0.62);
  backdrop-filter: blur(4px);
}

.dialog-header {
  position: sticky;
  top: 0;
  z-index: 3;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1.1rem 1.1rem 0.95rem;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 253, 248, 0.97);
  backdrop-filter: blur(12px);
}

.dialog-kicker {
  margin: 0 0 0.18rem;
  color: var(--terracotta);
  font-size: 0.7rem;
  font-weight: 900;
  letter-spacing: 0.14em;
}

.dialog-header h2 {
  margin: 0;
  color: var(--bamboo);
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1.55rem;
}

.dialog-close {
  display: inline-grid;
  width: 44px;
  height: 44px;
  flex: 0 0 44px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--bamboo);
  background: white;
  cursor: pointer;
}

.dialog-close svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-width: 1.8;
}

.thumbnail-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.85rem;
  max-height: calc(84dvh - 84px);
  margin: 0;
  padding: 1rem 1rem calc(1rem + env(safe-area-inset-bottom));
  overflow-y: auto;
  list-style: none;
}

.page-choice {
  width: 100%;
  overflow: hidden;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 0.95rem;
  color: var(--charcoal);
  background: white;
  text-align: left;
  cursor: pointer;
}

.page-choice:hover {
  border-color: var(--bamboo);
}

.page-choice[aria-current="page"] {
  border-color: var(--mustard);
  box-shadow: 0 0 0 3px rgba(217, 166, 33, 0.2);
}

.page-choice img {
  display: block;
  width: 100%;
  height: clamp(172px, 48vw, 230px);
  border-bottom: 1px solid var(--line);
  background: var(--ivory);
  object-fit: contain;
}

.page-choice span {
  display: flex;
  min-height: 48px;
  align-items: center;
  gap: 0.55rem;
  padding: 0.65rem;
  font-size: 0.78rem;
  font-weight: 720;
  line-height: 1.2;
}

.page-choice b {
  display: inline-grid;
  width: 1.65rem;
  height: 1.65rem;
  flex: 0 0 1.65rem;
  place-items: center;
  border-radius: 999px;
  color: white;
  background: var(--bamboo);
  font-size: 0.72rem;
}

.noscript-message {
  position: fixed;
  right: 1rem;
  bottom: 1rem;
  left: 1rem;
  z-index: 80;
  max-width: 680px;
  margin: auto;
  padding: 1rem;
  border-radius: 1rem;
  color: white;
  background: var(--terracotta);
  box-shadow: var(--shadow);
}

.noscript-message a {
  color: white;
  font-weight: 800;
}

.sr-only {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

@keyframes loading {
  to {
    background-position-x: -220%;
  }
}

@media (min-width: 640px) {
  .app-header {
    padding-inline: 1.4rem;
  }

  .page-control-bar {
    padding-inline: 1.4rem;
  }

  main {
    padding: 1.4rem 2.75rem 1.8rem;
  }

  .bottom-control {
    min-height: 78px;
  }

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

  .page-choice img {
    height: 220px;
  }
}

@media (max-width: 370px) {
  .brand-logo {
    width: 48px;
    height: 48px;
    flex-basis: 48px;
  }

  .brand-name {
    display: none;
  }

  .pdf-button span {
    display: none;
  }

  .bottom-control {
    flex-direction: column;
    gap: 0.12rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

@media print {
  body,
  .app-shell {
    background: white;
    box-shadow: none;
  }

  .app-header,
  .page-control-bar,
  .bottom-nav,
  .progress-track {
    display: none;
  }

  main {
    padding: 0;
  }

  .document-shell {
    border: 0;
    border-radius: 0;
    box-shadow: none;
  }

  .document-link::after {
    display: none;
  }
}
