/* =========================================================
   scrrr — unified app stylesheet
   ========================================================= */

:root {
  --page-width: 1080px;
  --header-h: 48px;
  --footer-h: 28px;
  --dynamic-h: 40vh;

  --bg: #050505;
  --fg: #cccac0;
  --mg: #a3a3a3;
  --muted: #666;
  --dim: #888;

  --item-gap: 12px;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html {
  scrollbar-width: none;
}

html::-webkit-scrollbar {
  display: none;
}

html,
body {
  width: 100%;
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--fg);
}

body {
  min-height: 100dvh;
  font-family: ui-monospace, Consolas, monospace;
  font-size: 14px;
  touch-action: pan-y;
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
}

a {
  color: inherit;
  text-decoration: none;
}

button,
select {
  font: inherit;
}

img {
  pointer-events: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* =========================================================
   Top bar
   ========================================================= */

.top-bar {
  position: fixed;
  z-index: 100;
  top: 0;
  left: 50%;

  transform: translateX(-50%);
  will-change: transform;
  transition: transform 200ms ease;

  width: min(var(--page-width), 100%);
  height: var(--header-h);

  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;

  padding-inline: 12px;
  background: var(--bg);
}

.top-bar.is-hidden {
  transform: translate(-50%, -100%);
}

.top-bar__menu {
  appearance: none;
  border: 0;
  outline: 0;
  padding: 12px;
  margin: -12px;

  background: transparent;
  color: var(--dim);
  cursor: pointer;

  display: inline-flex;
  align-items: center;
  justify-content: center;
  justify-self: start;

  transition: color 120ms ease;
}

.top-bar__menu:hover,
.top-bar__menu[aria-expanded="true"] {
  color: var(--fg);
}

.top-bar__brand {
  justify-self: center;
  display: inline-flex;
  align-items: center;
  gap: 12px;
  max-width: 100%;
  min-width: 0;
}

.top-bar__logo {
  display: block;
  width: 138px;
  height: 32px;
  flex: 0 0 auto;
}

.top-bar__chapter {
  color: var(--fg);
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}

.top-bar__chapter[hidden] {
  display: none;
}

/* =========================================================
   add PWA
   ========================================================= */

.top-bar__install {
  appearance: none;
  border: 0;
  outline: 0;
  padding: 8px 12px;
  margin: -8px 0 -8px -12px;

  background: transparent;
  color: var(--dim);
  cursor: pointer;

  font: inherit;
  font-size: 16px;
  line-height: 1;

  transition: color 120ms ease;
}

.top-bar__install:hover,
.top-bar__install:focus-visible {
  color: var(--fg);
  outline: none;
  text-decoration: underline;
  text-underline-offset: 3px;
}

/* =========================================================
   Info dropdown
   ========================================================= */

.top-bar__info {
  position: relative;
  justify-self: end;
  align-self: center;
}

.top-bar__info-trigger {
  appearance: none;
  border: 0;
  outline: 0;
  padding: 8px 12px;
  margin: -8px -12px;

  background: transparent;
  color: var(--dim);
  cursor: pointer;

  font: inherit;
  font-size: 16px;
  line-height: 1;

  transition: color 120ms ease;
}

.top-bar__info-trigger:hover {
  color: var(--mg);
}

.top-bar__info-trigger[aria-expanded="true"] {
  color: var(--fg);
}

.top-bar__info-menu {
  position: absolute;
  top: calc(100% + 10px);
  right: 0;
  z-index: 120;

  display: grid;
  grid-template-columns: repeat(2, minmax(160px, max-content));
  gap: 24px 32px;

  padding: 20px 24px;

  background: var(--bg);
  color: var(--fg);

  border: 1px solid color-mix(in srgb, var(--muted) 30%, transparent);
  border-radius: 10px;

  max-width: calc(100vw - 24px);
}

.top-bar__info-menu[hidden] {
  display: none;
}

.info-section {
  min-width: 0;
}

.info-section__title {
  margin: 0 0 12px;

  color: var(--muted);
  font-size: 12px;
  font-weight: 400;
  line-height: 1.2;
  text-transform: capitalize;
  letter-spacing: 0.08em;
}

.info-section__list {
  margin: 0;
  padding: 0;
  list-style: none;

  display: flex;
  flex-direction: column;
  gap: 6px;
}

.info-section__list a {
  display: block;
  padding: 4px 0;

  color: var(--dim);
  transition: color 120ms ease;
}

.info-section__list a:hover {
  color: var(--fg);
}

.info-section__list a[aria-current="true"] {
  color: var(--fg);
}

/* =========================================================
   Viewer
   ========================================================= */

.viewer {
  position: relative;
  cursor: grab;
}

/* Clip stops #overlay's scaled layout box (height =
   pageHeight / scale) from extending document.scrollHeight.
   Without this, scrollHeight reports the un-scaled 1080-ref
   height (~22400px) instead of the rendered page height
   (~8300px on mobile). Every consumer of scrollHeight —
   maxPageScroll, the ScrollTarget's max getter, chrome
   visibility, scrollbar drag — then works with numbers
   that can't be reached, and wheel tweens loop forever. */
#viewport {
  width: 100%;
  max-width: var(--page-width);
  margin: 0 auto;
  overflow: clip;
  contain: layout style;
}

#page {
  position: relative;
  margin: 0 auto;
  max-width: var(--page-width);
  transform-origin: 0 0;
}

.bg-slice {
  display: block;
  width: 100%;
  height: auto;
  margin: 0 auto;
  transform-origin: top center;
}

#overlay {
  position: absolute;
  left: 0;
  top: 0;
  width: var(--page-width);
  min-height: 100%;
  pointer-events: none;
  user-select: none;
}

.gfx {
  position: relative;
  z-index: 10;
  display: block;
}

.gfx-wrapper {
  position: absolute;
  pointer-events: none;
}

.txt {
  position: absolute;
  z-index: 20;
  display: block;
}

/* =========================================================
   Viewer scrollbar
   ========================================================= */

.viewer__scrollbar {
  position: fixed;
  z-index: 85;

  top: calc(var(--header-h) + 12px);
  bottom: calc(var(--footer-h) + 12px);
  right: max(-6px, calc((100vw - var(--page-width)) / 2 - 6px));

  width: 34px;

  pointer-events: auto;
  cursor: pointer;
  touch-action: none;

  opacity: 0;
  transition: opacity 420ms ease;
}

.viewer__scrollbar.is-visible {
  opacity: 0.5;
}

.viewer__scrollbar.is-dragging {
  opacity: 1;
  transition: opacity 120ms ease;
}

.viewer__scrollbar::before {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  right: 8px;
  width: 2px;

  background: color-mix(in srgb, var(--muted) 20%, transparent);
  border-radius: 2px;
  pointer-events: none;

  transition: width 200ms ease;
}

.viewer__scrollbar-thumb {
  position: absolute;
  top: 0;
  right: 8px;
  width: 2px;
  height: 0;

  background: var(--mg);
  border-radius: 2px;

  transform: translateY(0);
  transition:
    background-color 120ms ease,
    width 200ms ease;
  will-change: transform;

  pointer-events: none;
}

.viewer__scrollbar.is-dragging::before,
.viewer__scrollbar.is-dragging .viewer__scrollbar-thumb {
  width: 5px;
}

.viewer__scrollbar.is-dragging .viewer__scrollbar-thumb {
  background: var(--fg);
}

@media (hover: hover) {
  .viewer__scrollbar:hover {
    opacity: 1;
    transition: opacity 120ms ease;
  }

  .viewer__scrollbar:hover::before,
  .viewer__scrollbar:hover .viewer__scrollbar-thumb {
    width: 5px;
  }
}

.contents[data-open="true"] ~ .viewer__scrollbar {
  opacity: 0 !important;
  pointer-events: none;
}

body.is-dragging .viewer__scrollbar {
  pointer-events: none;
}

/* =========================================================
   Contents overlay
   ========================================================= */

.contents {
  position: fixed;
  inset: 0;
  z-index: 90;

  display: none;
  grid-template-rows: 1fr;
  place-items: stretch;

  touch-action: none;
}

.contents[data-open="true"] {
  display: grid;
}

.contents__scrim {
  position: absolute;
  inset: 0;
  background: rgba(5, 5, 5, 0.92);
  cursor: pointer;
}

.contents__panel {
  position: relative;

  display: grid;
  grid-template-rows: var(--dynamic-h) 1fr;

  width: min(var(--page-width), 100%);
  margin-inline: auto;

  padding-top: var(--header-h);
  padding-bottom: var(--footer-h);

  min-height: 0;

  contain: layout style;
  overscroll-behavior: contain;
}

/* -------- dynamic block -------- */

.contents__dynamic {
  position: relative;
  overflow: hidden;
  isolation: isolate;
  background: #111;
}

.dynamic-media {
  position: absolute;
  inset: 0;
  z-index: -2;

  background-position: center top;
  background-repeat: no-repeat;
  background-size: cover;

  opacity: 0;
  transition: opacity 320ms ease;
}

.dynamic-media.is-active {
  opacity: 1;
}

.dynamic-media.is-panning {
  animation: pan-image 11s linear infinite alternate;
}

@keyframes pan-image {
  from {
    background-position: center top;
  }
  to {
    background-position: center bottom;
  }
}

.contents__dynamic::before,
.contents__dynamic::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  pointer-events: none;
}

.contents__dynamic::before {
  background: linear-gradient(
    to bottom,
    color-mix(in srgb, var(--bg) 20%, transparent),
    transparent 8%
  );
}

.contents__dynamic::after {
  background: linear-gradient(
    to top,
    color-mix(in srgb, var(--bg) 30%, transparent),
    transparent 12%
  );
}

.contents__dynamic-content {
  position: absolute;
  inset-inline: 24px;
  bottom: 24px;

  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: end;
  gap: 24px;
}

.dynamic-text {
  min-width: 0;
}

.contents__dynamic h1 {
  margin: 0 0 8px;
  font-size: clamp(24px, 4vw, 48px);
  line-height: 1;
  text-transform: capitalize;
}

.contents__dynamic p {
  max-width: 680px;
  margin: 0;
  line-height: 1.5;
}

.contents__dynamic h1,
.contents__dynamic p {
  color: var(--fg);
  display: table;
  width: fit-content;
  max-width: 100%;
  background: var(--bg);
  padding: 0 14px;
  border-radius: 10px;
  white-space: pre-line;
}

.dynamic-read {
  align-self: end;
  display: inline-block;
  padding: 0 14px;

  font-family: inherit;
  font-size: clamp(24px, 4vw, 48px);
  font-weight: 700;
  line-height: 1;
  letter-spacing: normal;
  text-transform: capitalize;

  color: var(--fg);
  background: var(--bg);
  border-radius: 10px;
  cursor: pointer;

  transition:
    color 120ms ease,
    background-color 120ms ease;
}

.dynamic-read span {
  display: block;
}

.dynamic-read:hover {
  color: var(--bg);
  background: var(--fg);
}

.dynamic-read:active {
  color: var(--bg);
  background: var(--mg);
}

.dynamic-read[aria-disabled="true"] {
  pointer-events: none;
  opacity: 0.4;
}

/* -------- menu scroll region -------- */

.contents__menu {
  position: relative;
  min-height: 0;

  overflow-x: hidden;
  overflow-y: auto;

  padding-left: 20px;

  touch-action: pan-y;
  overscroll-behavior: contain;

  scrollbar-width: none;

  user-select: none;
  -webkit-user-select: none;
}

.contents__menu::-webkit-scrollbar {
  display: none;
}

.menu-list {
  padding-inline: 20px;
}

.snap-spacer {
  height: 0;
  min-height: 0;
  pointer-events: none;
  position: relative;
}

.scroll-hint {
  pointer-events: none;
  user-select: none;
  position: absolute;
  left: 50%;
  top: 65%;
  translate: -50% -50%;
  color: var(--muted);
  font-size: 12px;
  letter-spacing: 0.08em;
  max-width: 100%;
  text-align: center;
}

/* -------- contents scrollbar -------- */

.contents__scrollbar {
  position: absolute;
  top: calc(var(--header-h) + var(--dynamic-h) + 12px);
  bottom: var(--footer-h);
  right: -6px;

  width: 32px;

  pointer-events: auto;
  cursor: pointer;
  touch-action: none;

  opacity: 0.5;
  transition: opacity 200ms ease;
  z-index: 20;
}

.contents__scrollbar.is-dragging {
  opacity: 1;
  transition: opacity 120ms ease;
}

.contents__scrollbar::before {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  right: 8px;
  width: 2px;
  background: color-mix(in srgb, var(--muted) 20%, transparent);
  border-radius: 2px;
  pointer-events: none;
  transition: width 200ms ease;
}

.contents__scrollbar-thumb {
  position: absolute;
  top: 0;
  right: 8px;
  width: 2px;
  height: 0;
  background: var(--mg);
  border-radius: 2px;
  transform: translateY(0);
  transition:
    background-color 120ms ease,
    width 200ms ease;
  will-change: transform;
  pointer-events: none;
}

.contents__scrollbar.is-dragging::before,
.contents__scrollbar.is-dragging .contents__scrollbar-thumb {
  width: 5px;
}

.contents__scrollbar.is-dragging .contents__scrollbar-thumb {
  background: var(--fg);
}

@media (hover: hover) {
  .contents__scrollbar:hover {
    opacity: 1;
    transition: opacity 120ms ease;
  }

  .contents__scrollbar:hover::before,
  .contents__scrollbar:hover .contents__scrollbar-thumb {
    width: 5px;
  }
}

/* -------- menu headings -------- */

.menu-heading {
  margin: 28px 0 12px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 400;
  line-height: 1.2;
  text-transform: capitalize;
  letter-spacing: 0.08em;
}

.menu-heading:first-child {
  margin-top: 0;
}

/* -------- menu item -------- */

.menu-item {
  position: relative;
  display: flex;
  align-items: baseline;
  flex-wrap: nowrap;
  gap: 20px;
  min-height: 72px;
  padding: 20px 10px;
  color: var(--dim);
  cursor: pointer;
  transition: color 120ms ease;
  overflow: visible;
}

.menu-item + .menu-item {
  margin-top: var(--item-gap);
}

.menu-item-number {
  display: inline-block;
  flex: 0 0 auto;
  min-width: 1.5ch;
  font-size: 0.8em;
  color: var(--muted);
  font-family: inherit;
  font-variant-numeric: tabular-nums;
  line-height: inherit;
  text-decoration: none;
  transition: color 120ms ease;
}

.menu-item.is-selected .menu-item-number {
  color: var(--muted);
}

.menu-item-title {
  transition: transform 160ms ease;
}

.show-more {
  color: var(--mg);
  opacity: 0;
  transition:
    opacity 160ms ease,
    color 120ms ease;
}

.menu-item.is-selected {
  color: var(--fg);
}

.menu-item.is-selected .menu-item-title {
  transform: translateX(8px);
}

.menu-item.is-selected .show-more {
  opacity: 1;
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 2px;
  text-decoration-skip-ink: auto;
}

.menu-item:hover {
  color: var(--mg);
}

.menu-item.is-selected:hover {
  color: var(--fg);
}

/* -------- sponsors -------- */

.sponsors-item {
  display: block;
  min-height: 0;
  padding: 0;
  color: var(--dim);
}

.sponsors-inner {
  padding-bottom: 32px;
}

.sponsors-item .menu-heading {
  margin-top: 48px;
}

.sponsors-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 24px 32px;
  margin-top: 20px;
}

.sponsors-grid a {
  min-height: 72px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.sponsors-grid img {
  display: block;
  max-width: 100%;
  max-height: 48px;
  object-fit: contain;
}

.sponsors-grid a:hover {
  opacity: 0.65;
}

/* =========================================================
   Footer
   ========================================================= */

.footer {
  position: fixed;
  z-index: 100;
  left: 50%;
  bottom: 0;

  transform: translateX(-50%);
  will-change: transform;
  transition: transform 200ms ease;

  width: min(var(--page-width), 100%);
  height: var(--footer-h);

  display: flex;
  align-items: center;
  justify-content: center;

  background: var(--bg);
  color: var(--muted);
  font-size: 11px;
}

body.is-chrome-hidden .footer {
  transform: translate(-50%, 100%);
}

/* =========================================================
   Shakers
   ========================================================= */

@keyframes shake {
  0%,
  100% {
    transform: translate(0, 0) rotate(0deg);
  }
  10% {
    transform: translate(-2px, -1px) rotate(-1deg);
  }
  20% {
    transform: translate(3px, 1px) rotate(1deg);
  }
  30% {
    transform: translate(-3px, 0px) rotate(-0.5deg);
  }
  40% {
    transform: translate(2px, -1px) rotate(0.5deg);
  }
  50% {
    transform: translate(-1px, 2px) rotate(-0.5deg);
  }
  60% {
    transform: translate(3px, 1px) rotate(0.5deg);
  }
  70% {
    transform: translate(-2px, -1px) rotate(-1deg);
  }
  80% {
    transform: translate(-1px, 2px) rotate(1deg);
  }
  90% {
    transform: translate(2px, -2px) rotate(-0.5deg);
  }
}

.shake {
  animation: shake 0.5s ease-in-out infinite;
}

@keyframes shake-hard {
  0%,
  100% {
    transform: translate(0, 0) rotate(0deg);
  }
  25% {
    transform: translate(-5px, -3px) rotate(-3deg);
  }
  50% {
    transform: translate(5px, 3px) rotate(3deg);
  }
  75% {
    transform: translate(-3px, 5px) rotate(-2deg);
  }
}

.shake-hard {
  animation: shake-hard 0.3s ease-in-out infinite;
}

@keyframes tremor {
  0%,
  100% {
    transform: translate(0, 0);
  }
  10% {
    transform: translate(-1px, -1px);
  }
  20% {
    transform: translate(1px, 1px);
  }
  30% {
    transform: translate(-1px, 0);
  }
  40% {
    transform: translate(1px, -1px);
  }
  50% {
    transform: translate(0, 1px);
  }
  60% {
    transform: translate(-1px, 1px);
  }
  70% {
    transform: translate(1px, 0);
  }
  80% {
    transform: translate(-1px, -1px);
  }
  90% {
    transform: translate(1px, 1px);
  }
}

.tremor {
  animation: tremor 0.1s ease-in-out infinite;
}

@keyframes shake-vertical {
  0%,
  100% {
    transform: translateY(0);
  }
  25% {
    transform: translateY(-5px);
  }
  50% {
    transform: translateY(0);
  }
  75% {
    transform: translateY(5px);
  }
}

.shake-vertical {
  animation: shake-vertical 0.5s ease-in-out infinite;
}

@keyframes shake-horizontal {
  0%,
  100% {
    transform: translateX(0);
  }
  25% {
    transform: translateX(-5px);
  }
  50% {
    transform: translateX(0);
  }
  75% {
    transform: translateX(5px);
  }
}

.shake-horizontal {
  animation: shake-horizontal 0.5s ease-in-out infinite;
}

@keyframes shake-rotate {
  0%,
  100% {
    transform: rotate(0deg);
  }
  25% {
    transform: rotate(-5deg);
  }
  50% {
    transform: rotate(0deg);
  }
  75% {
    transform: rotate(5deg);
  }
}

.shake-rotate {
  animation: shake-rotate 0.5s ease-in-out infinite;
}

@keyframes pulse-shake {
  0%,
  100% {
    transform: scale(1) rotate(0deg);
  }
  25% {
    transform: scale(1.05) rotate(-2deg);
  }
  75% {
    transform: scale(0.95) rotate(2deg);
  }
}

.pulse-shake {
  animation: pulse-shake 0.8s ease-in-out infinite;
}

/* =========================================================
   Focus
   ========================================================= */

a:focus,
a:focus-visible,
.menu-item:focus,
.menu-item:focus-visible {
  outline: none;
}

.top-bar__info-trigger:focus-visible,
.top-bar__menu:focus-visible {
  color: var(--fg);
  outline: none;
  text-decoration: underline;
  text-underline-offset: 3px;
}

/* =========================================================
   Reduced motion
   ========================================================= */

@media (prefers-reduced-motion: reduce) {
  .dynamic-media,
  .menu-item-title,
  .show-more,
  .menu-item-number,
  .viewer__scrollbar,
  .viewer__scrollbar-thumb,
  .viewer__scrollbar::before,
  .dynamic-media.is-panning {
    transition: none;
    animation: none;
  }
}

/* =========================================================
   Drag & selection
   ========================================================= */

.contents__menu a,
.contents__menu img,
.contents__menu .menu-item {
  -webkit-user-drag: none;
}

body.is-dragging,
body.is-dragging .viewer,
body.is-dragging .contents__panel,
body.is-dragging .contents__panel * {
  cursor: grabbing !important;
  user-select: none !important;
  -webkit-user-select: none !important;
}

/* =========================================================
   Mobile
   ========================================================= */

@media (max-width: 700px) {
  :root {
    --header-h: 52px;
    --dynamic-h: 30vh;
  }

  html {
    text-size-adjust: 80%;
  }

  .top-bar {
    padding: 5px 12px;
  }

  .top-bar__chapter {
    font-size: 12px;
  }

  .contents__dynamic-content {
    inset-inline: 18px;
    bottom: 18px;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 12px;
  }

  .contents__dynamic h1 {
    font-size: clamp(24px, 8vw, 40px);
    font-weight: 700;
  }

  .contents__dynamic p {
    max-width: none;
    font-size: 12px;
  }

  .dynamic-read {
    justify-self: end;
    font-size: clamp(24px, 8vw, 40px);
    font-weight: 700;
  }

  .menu-list {
    padding-inline: 18px;
  }

  .menu-item {
    min-height: 64px;
    padding: 20px 10px;
    align-items: baseline;
    flex-wrap: nowrap;
    overflow: visible;
  }

  .sponsors-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 16px;
  }

  .scroll-hint {
    font-size: 11px;
    letter-spacing: 0.04em;
    padding-inline: 12px;
  }

  .viewer__scrollbar {
    top: calc(var(--header-h) + 8px);
    bottom: calc(var(--footer-h) + 8px);
  }
}

/* =========================================================
   PWA safe area (standalone / fullscreen only)
   ========================================================= */

@supports (padding: env(safe-area-inset-bottom)) {
  .footer {
    padding-bottom: env(safe-area-inset-bottom);
    height: calc(var(--footer-h) + env(safe-area-inset-bottom));
  }

  .viewer__scrollbar {
    bottom: calc(var(--footer-h) + env(safe-area-inset-bottom) + 12px);
  }
}
