:root {
  --color-bg: #f5f6f8;
  --color-bg-dark: #cbcbcb;
  --color-surface: #ffffff;
  --color-text: #1f2430;
  --color-text-muted: #6b7280;
  --color-primary: #004F95;
  --color-primary-text: #ffffff;
  --color-border: #e2e5ea;
  --radius: 12px;
  --spacing-sm: 8px;
  --spacing-md: 16px;
  --spacing-lg: 24px;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  font-family: -apple-system, "Noto Sans TC", sans-serif;
  background: var(--color-bg);
  color: var(--color-text);
  overscroll-behavior-y: contain;
}

.brochure {
  height: 100dvh;
  max-height: 100dvh;
  overflow: hidden;
  max-width: 480px;
  margin: 0 auto;
  padding: var(--spacing-sm) var(--spacing-md);
  padding-bottom: max(var(--spacing-sm), env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: var(--spacing-sm);
}

.brochure__title {
  font-size: 1.25rem;
  margin: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.brochure__date {
  margin: 2px 0 0;
  color: var(--color-text-muted);
  font-size: 0.75rem;
}

.brochure__header {
  flex: none;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--spacing-md);
}

.brochure__heading {
  flex: 1;
  min-width: 0;
}

a.brochure__cta {
  flex: none;
  height: 28px;
  padding-inline: 12px;
  display: flex;
  place-items: center;
}

.viewer {
  position: relative;
  flex: 1;
  min-height: 0;
  display: flex;
  justify-content: center;
}

.viewer__stage {
  position: relative;
  background: var(--color-surface);
  border-radius: var(--radius);
  overflow: auto;
  overscroll-behavior: contain;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.08);
  display: flex;
  height: 100%;
  max-width: 100%;
  min-width: 0;
  aspect-ratio: 210 / 297;
  touch-action: pan-x pan-y;
  background: var(--color-bg-dark);
}

.viewer__canvas {
  display: block;
  margin: auto;
}

.viewer__message {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--spacing-md);
  text-align: center;
  color: var(--color-text-muted);
}

.viewer__arrow {
  border: none;
  background: var(--color-surface);
  color: var(--color-text);
  width: 40px;
  height: 40px;
  border-radius: 50%;
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: none;
}

.viewer__arrow:disabled {
  opacity: 0.3;
  cursor: default;
}

.viewer__footer {
  flex: none;
  position: relative;
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--spacing-sm);
}

/* Mobile: nav floats above the footer, over the bottom of the stage, so the
   arrows/page-count/progress don't compete with the PDF for scarce vertical
   space. Desktop keeps it docked in the footer's grid (see media query). */
.viewer__nav {
  position: absolute;
  left: var(--spacing-sm);
  right: var(--spacing-sm);
  bottom: calc(100% + var(--spacing-sm));
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  z-index: 2;
}

.viewer__nav-controls {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  background: rgba(255, 255, 255, 0.85);
  border-radius: var(--radius);
  padding: 4px;
  transition: opacity 0.25s ease;
  box-shadow: 0 4px 14px 0 rgba(0, 0, 0, 0.15);
}

.viewer__nav-controls.is-idle {
  opacity: 0;
  pointer-events: none;
}

.viewer__nav-controls .viewer__arrow {
  width: 44px;
  height: 44px;
  font-size: 1.3rem;
}

.viewer__page-count {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--color-text);
  min-width: 36px;
  padding: 0 4px;
  text-align: center;
  white-space: nowrap;
}

.viewer__progress-bar {
  width: 100%;
  height: 4px;
  background: var(--color-border);
  border-radius: 2px;
  position: relative;
  overflow: hidden;
}

.viewer__progress-bar::after {
  content: "";
  position: absolute;
  inset: 0;
  width: var(--progress, 0%);
  background: var(--color-primary);
  transition: width 0.2s ease;
}

.viewer__utility {
  display: flex;
  align-items: center;
  justify-content: space-around;
  gap: var(--spacing-sm);
}

@media (min-width: 768px) {
  .brochure {
    height: auto;
    max-height: none;
    overflow: visible;
    max-width: 640px;
    padding: var(--spacing-lg) var(--spacing-md);
    gap: var(--spacing-md);
  }

  .brochure__date {
    margin: 4px 0 0;
    font-size: 0.875rem;
  }

  a.brochure__cta {
    height: 34px;
  }

  .viewer {
    flex: none;
    min-width: 0;
    max-width: none;
    aspect-ratio: 210 / 297;
    max-height: 80vh;
  }

  .viewer__stage {
    position: absolute;
    inset: 0;
    aspect-ratio: auto;
    max-width: none;
    min-height: 320px;
  }

  .viewer__nav-controls.is-idle {
    opacity: 1;
    pointer-events: auto;
  }

  .viewer__footer {
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
  }

  .viewer__nav {
    position: static;
    grid-column: 2;
    flex-direction: row;
  }

  .viewer__progress-bar {
    display: none;
  }

  .viewer__utility {
    grid-column: 3;
    justify-self: end;
  }

  button.viewer__share {
    display: none;
  }

  .viewer__utility .action-link span {
    display: inline;
  }
}

.button {
  text-align: center;
  text-decoration: none;
  font-weight: 600;
  font-size: 14px;
}

.button--primary {
  background: var(--color-primary);
  color: var(--color-primary-text);
}

.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: none;
  background: var(--color-surface);
  color: var(--color-text);
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
  text-decoration: none;
}

.action-link {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  border: none;
  background: none;
  padding: 4px;
  color: var(--color-text-muted);
  font-size: 0.85rem;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  flex: none;
}

/* The visible icon is ~26px, under the 44px touch-target guideline. Expand
   the tappable area invisibly via an absolutely-positioned pseudo-element
   instead of growing padding, so the footer's real layout height (and the
   100dvh mobile budget) doesn't grow. */
.action-link::before {
  content: "";
  position: absolute;
  inset: -9px;
}

.action-link span {
  display: none;
}

.share-feedback {
  text-align: center;
  font-size: 0.8rem;
  color: var(--color-primary);
}

.thumbnail-panel {
  position: fixed;
  top: auto;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  margin: 0;
  width: 100%;
  max-width: 640px;
  max-height: 80vh;
  border: none;
  padding: 0;
  background: var(--color-bg);
  border-radius: var(--radius) var(--radius) 0 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.thumbnail-panel:not([open]) {
  display: none;
}

/* This file's single @media(min-width:768px) block above is declared
   before this rule in source order, so a desktop override placed there
   would lose the cascade to this later, unconditional base rule despite
   matching the same width - it has to come after this rule instead. */
@media (min-width: 768px) {
  .thumbnail-panel {
    top: 50%;
    bottom: auto;
    left: 50%;
    transform: translate(-50%, -50%);
    max-height: 85vh;
    border-radius: var(--radius);
  }
}

.thumbnail-panel::backdrop {
  background: rgba(0, 0, 0, 0.4);
}

.thumbnail-panel__header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: var(--spacing-md);
  flex: none;
}

.thumbnail-panel__grid {
  display: grid;
  grid-template-columns: repeat(var(--thumb-cols, 3), 1fr);
  gap: var(--spacing-sm);
  padding: 0 var(--spacing-md) var(--spacing-md);
  overflow-y: auto;
  grid-auto-rows: max-content;
}

.thumbnail-panel__page {
  border: none;
  padding: 0;
  background: var(--color-surface);
  border-radius: 8px;
  overflow: hidden;
  cursor: pointer;
  aspect-ratio: var(--thumb-ratio, 3 / 4);
  display: flex;
  align-items: center;
  justify-content: center;
}

.thumbnail-panel__page--pending {
  background: var(--color-border);
}

.thumbnail-panel__page img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.viewer__zoom {
  position: absolute;
  top: var(--spacing-sm);
  right: var(--spacing-sm);
  display: flex;
  align-items: center;
  gap: 2px;
  background: rgba(255, 255, 255, 0.85);
  border-radius: var(--radius);
  padding: 4px;
  box-shadow: 0 4px 14px 0 rgba(0, 0, 0, 0.15);
  z-index: 1;
}

.viewer__zoom-button {
  width: 44px;
  height: 44px;
  font-size: 1.3rem;
}

.viewer__zoom-button:disabled {
  opacity: 0.3;
  cursor: default;
}

.viewer__zoom-level {
  border: none;
  background: transparent;
  color: var(--color-text);
  font-size: 0.75rem;
  font-weight: 600;
  min-width: 32px;
  padding: 0 4px;
  cursor: pointer;
  text-align: center;
}

.viewer__stage--zoomed {
  cursor: grab;
}

.viewer__stage--panning {
  cursor: grabbing;
}
