:root {
  --deep: #08150f;
  --lime: #bcff2f;
  --ink: #101d16;
  --stage: #13261c;
  --hair: #2a4738;
  --chrome: #799686;
  --kicker: #b4dbb7;
  --paper: #f5f9f2;
  --muted: #d5e3d4;
  --font-sans: "Noto Sans SC", "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  --font-brand: "Manrope", var(--font-sans);
  --font-mono: "DM Mono", ui-monospace, monospace;
  --bar: 56px;
  --thumbs: 108px;
  --pad: 16px;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  background: var(--deep);
  color: var(--paper);
  font-family: var(--font-sans);
  font-weight: 500;
  -webkit-text-size-adjust: 100%;
}

body {
  min-height: 100dvh;
}

.skip {
  position: absolute;
  left: -999px;
  top: 0;
}

.skip:focus {
  left: 12px;
  top: 12px;
  z-index: 20;
  background: var(--deep);
  color: var(--lime);
  padding: 8px 12px;
  text-decoration: none;
}

.app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  height: 100svh;
  background: var(--deep);
}

.topbar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 16px;
  min-height: var(--bar);
  padding: 0 var(--pad);
  padding-left: max(var(--pad), env(safe-area-inset-left));
  padding-right: max(var(--pad), env(safe-area-inset-right));
  border-bottom: 1px solid var(--hair);
  background: var(--deep);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  text-decoration: none;
  color: inherit;
  flex: 0 1 auto;
}

.brand img {
  width: 22px;
  height: 22px;
  display: block;
  flex-shrink: 0;
}

.wordmark {
  font-family: var(--font-brand);
  font-weight: 800;
  font-size: 15px;
  letter-spacing: -0.04em;
  color: var(--paper);
  line-height: 1;
}

.doc-title {
  flex: 1 1 auto;
  min-width: 0;
  margin: 0;
  font-family: var(--font-sans);
  font-weight: 500;
  font-size: 14px;
  letter-spacing: -0.02em;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.controls {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-left: auto;
  flex: 0 0 auto;
}

.counter {
  font-family: var(--font-mono);
  font-weight: 500;
  font-size: 12px;
  letter-spacing: 0.04em;
  color: var(--kicker);
  padding: 0 10px;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.counter .current {
  color: var(--lime);
}

.icon-btn,
.download {
  appearance: none;
  background: none;
  border: 0;
  color: var(--kicker);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 40px;
  min-height: 40px;
  padding: 0 8px;
  cursor: pointer;
  text-decoration: none;
  font-family: var(--font-sans);
  font-weight: 500;
  font-size: 12px;
  line-height: 1;
}

.icon-btn svg,
.download svg {
  display: block;
  width: 18px;
  height: 18px;
}

.icon-btn:hover,
.download:hover,
.icon-btn:focus-visible,
.download:focus-visible {
  color: var(--lime);
  outline: none;
}

.icon-btn:focus-visible,
.download:focus-visible,
.thumb:focus-visible {
  outline: 1px solid var(--lime);
  outline-offset: 2px;
}

.icon-btn:disabled {
  color: var(--hair);
  cursor: default;
}

.download-label {
  margin-left: 6px;
}

.stage {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  padding-left: max(16px, env(safe-area-inset-left));
  padding-right: max(16px, env(safe-area-inset-right));
  background: var(--stage);
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
}

.sheet {
  margin: 0;
  max-width: 100%;
  max-height: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.sheet img {
  display: block;
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  object-fit: contain;
  background: #fff;
  outline: 1px solid rgba(181, 219, 183, 0.28);
  vertical-align: top;
  user-select: none;
  -webkit-user-drag: none;
}

.thumbs-wrap {
  flex: 0 0 auto;
  border-top: 1px solid var(--hair);
  background: var(--deep);
  padding: 10px 0 calc(10px + env(safe-area-inset-bottom));
}

.thumbs {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  overflow-y: hidden;
  padding: 0 16px;
  padding-left: max(16px, env(safe-area-inset-left));
  padding-right: max(16px, env(safe-area-inset-right));
  scroll-snap-type: x proximity;
  scrollbar-width: thin;
  scrollbar-color: var(--hair) transparent;
}

.thumb {
  appearance: none;
  background: none;
  border: 1px solid var(--hair);
  padding: 0;
  margin: 0;
  flex: 0 0 auto;
  width: 56px;
  cursor: pointer;
  scroll-snap-align: start;
  color: var(--chrome);
}

.thumb img {
  display: block;
  width: 56px;
  height: auto;
  aspect-ratio: 2479 / 3508;
  object-fit: contain;
  object-position: top center;
  background: #fff;
}

.thumb .folio {
  display: block;
  font-family: var(--font-mono);
  font-size: 9px;
  letter-spacing: 0.06em;
  text-align: center;
  padding: 4px 0 5px;
  line-height: 1;
}

.thumb[aria-current="true"] {
  border-color: var(--lime);
  color: var(--lime);
}

@media (max-width: 720px) {
  .topbar {
    gap: 8px;
    min-height: 52px;
  }

  .doc-title {
    display: none;
  }

  .download-label {
    display: none;
  }

  .wordmark {
    font-size: 14px;
  }

  .stage {
    align-items: flex-start;
    padding: 10px;
    padding-left: max(10px, env(safe-area-inset-left));
    padding-right: max(10px, env(safe-area-inset-right));
  }

  .sheet {
    height: auto;
    width: 100%;
    max-height: none;
  }

  .sheet img {
    width: 100%;
    max-height: none;
    height: auto;
  }

  .thumb {
    width: 48px;
  }

  .thumb img {
    width: 48px;
  }
}

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