/*
 * THE SHARED-COLLECTION VIEWER — one stylesheet, the app's own numbers.
 *
 * Day tokens are the app's MINERAL palette (src/theme/afterimage.ts); the
 * media viewer keeps the app's black stage and its glass discs. Radii are the
 * app's `rad` set, easings its `am` set. The page is a phone column: one
 * reading width, centred on anything wider, with the same canvas underneath.
 */

@font-face {
  font-family: 'Literata';
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url('./fonts/Literata_600SemiBold.ttf') format('truetype');
}
@font-face {
  font-family: 'Tenor Sans';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('./fonts/TenorSans_400Regular.ttf') format('truetype');
}
@font-face {
  font-family: 'Commissioner';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('./fonts/Commissioner_400Regular.ttf') format('truetype');
}
@font-face {
  font-family: 'Commissioner';
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url('./fonts/Commissioner_500Medium.ttf') format('truetype');
}
@font-face {
  font-family: 'Commissioner';
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url('./fonts/Commissioner_600SemiBold.ttf') format('truetype');
}

:root {
  /* Day · MINERAL */
  --canvas: #eeece7;
  --group: #f4f1ec;
  --surface: #f1ede7;
  --elevated: #fbf9f5;
  --tx: #161513;
  --tx2: #6e6861;
  --tx3: #9b948b;
  --border: #d7d0c6;
  --divider: #e2ddd4;
  --tonal: rgba(22, 21, 19, 0.09);
  --well: rgba(22, 21, 19, 0.05);
  --trust: #2a7650;
  --on-cta: #eeece7;
  --outside: #e6e2db;
  --tombstone: rgba(22, 21, 19, 0.9);

  /* the media viewer's own constants, both modes */
  --stage: #000000;
  --on-art: #ffffff;
  --on-art-2: rgba(255, 255, 255, 0.62);
  --disc: rgba(0, 0, 0, 0.42);
  --disc-frame: rgba(255, 255, 255, 0.14);
  --frame: rgba(255, 255, 255, 0.1);

  --r-focus: 4px;
  --r-thumb: 10px;
  --r-card: 14px;
  --r-tile: 16px;
  --r-pill: 999px;

  --ease: cubic-bezier(0.32, 0.72, 0, 1);
  --ease-soft: cubic-bezier(0.23, 1, 0.32, 1);

  --column: 430px;
  --gutter: 22px;
  --grid-gutter: 14px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);

  --sans: 'Commissioner', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --serif: 'Literata', ui-serif, Georgia, 'Times New Roman', serif;
  --brand: 'Tenor Sans', 'Commissioner', system-ui, sans-serif;

  color-scheme: light;
}

* {
  box-sizing: border-box;
}

html {
  background: var(--outside);
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100dvh;
  font: 400 15px/1.5 var(--sans);
  color: var(--tx);
  background: var(--outside);
  -webkit-font-smoothing: antialiased;
}

img {
  display: block;
}

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
}

:focus-visible {
  outline: 2px solid var(--tx);
  outline-offset: 2px;
}

.viewer :focus-visible {
  outline-color: var(--on-art);
}

/* ─────────────────────────── the column ─────────────────────────── */

.page {
  position: relative;
  max-width: var(--column);
  min-height: 100dvh;
  margin: 0 auto;
  background: var(--canvas);
}

@media (min-width: 431px) {
  .page {
    box-shadow: 0 0 0 1px var(--border);
  }
}

.page--centered {
  display: flex;
  flex-direction: column;
}

/* ─────────────────────────── the brand row ─────────────────────────── */

.brand-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 44px;
  padding: max(20px, var(--safe-top)) var(--gutter) 0;
}

.wordmark {
  margin: 0;
  font: 400 15.5px/1.2 var(--brand);
  letter-spacing: 0.3em;
  text-transform: uppercase;
  color: var(--tx);
  white-space: nowrap;
}

.brand-row__actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.icon-button {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 0;
  border-radius: 22px;
  background: var(--tonal);
  color: var(--tx);
  transition: transform 150ms var(--ease-soft);
}

.icon-button:active {
  transform: scale(0.94);
}

.icon-button[aria-busy='true'] {
  opacity: 0.5;
  pointer-events: none;
}

/* ─────────────────────────── the collection ─────────────────────────── */

.identity {
  padding: 24px var(--gutter) 0;
}

.cover {
  width: 96px;
  height: 116px;
  overflow: hidden;
  border-radius: var(--r-card);
  background: var(--surface);
}

.cover img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform-origin: 50% 50%;
}

.title {
  margin: 18px 0 0;
  font: 600 30px/1.15 var(--serif);
  letter-spacing: -0.01em;
  color: var(--tx);
  overflow-wrap: anywhere;
}

.attribution {
  margin: 6px 0 0;
  font-size: 14.5px;
  color: var(--tx2);
}

.meta {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 16px;
  margin: 10px 0 0;
  padding: 0;
  list-style: none;
  font-size: 13.5px;
  /* tx2, not the app's tx3 caption grey: 13.5px on the canvas needs 4.5:1 here */
  color: var(--tx2);
}

.meta li {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 4px;
  margin: 0;
  padding: 20px var(--grid-gutter) calc(24px + var(--safe-bottom));
  list-style: none;
}

.page--with-cta .grid {
  padding-bottom: calc(96px + var(--safe-bottom));
}

.grid li {
  min-width: 0;
}

.tile {
  position: relative;
  display: block;
  width: 100%;
  aspect-ratio: 4 / 5;
  padding: 0;
  overflow: hidden;
  border: 0;
  border-radius: var(--r-thumb);
  background: var(--surface);
  transition: transform 150ms var(--ease-soft);
}

.tile:active {
  transform: scale(0.985);
}

.tile img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform-origin: 50% 50%;
}

.tile--failed img {
  visibility: hidden;
}

.tile--gone {
  display: grid;
  place-items: center;
  color: rgba(255, 255, 255, 0.5);
  background: var(--tombstone);
}

/* ─────────────────────────── the floating action ─────────────────────────── */

.float-cta {
  position: fixed;
  left: 50%;
  bottom: calc(18px + var(--safe-bottom));
  z-index: 5;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  height: 52px;
  padding: 0 22px 0 13px;
  border: 0;
  border-radius: var(--r-pill);
  background: var(--tx);
  color: var(--on-cta);
  font: 500 15.5px/1 var(--sans);
  white-space: nowrap;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.18);
  transform: translateX(-50%);
  transition: transform 150ms var(--ease-soft);
}

.float-cta:active {
  transform: translateX(-50%) scale(0.97);
}

.float-cta[aria-busy='true'] {
  opacity: 0.6;
  pointer-events: none;
}

.mark {
  width: 26px;
  height: 26px;
  border-radius: 7px;
}

/* ─────────────────────────── centred screens ─────────────────────────── */

.stack {
  display: flex;
  flex: 1;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0;
  padding: 40px 30px calc(40px + var(--safe-bottom));
  text-align: center;
}

.stack > * + * {
  margin-top: 0;
}

.stack__title {
  margin: 24px 0 0;
  font: 500 22px/1.25 var(--sans);
  letter-spacing: -0.01em;
  color: var(--tx);
}

.stack__title--serif {
  font: 600 24px/1.2 var(--serif);
  letter-spacing: -0.01em;
}

.stack__text {
  max-width: 30ch;
  margin: 10px 0 0;
  font-size: 14.5px;
  line-height: 1.55;
  color: var(--tx2);
}

.stack__actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 100%;
  max-width: 320px;
  margin-top: 28px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  min-height: 56px;
  padding: 0 20px;
  border: 0;
  border-radius: var(--r-pill);
  font: 500 15.5px/1.2 var(--sans);
  transition: transform 150ms var(--ease-soft);
}

.btn:active {
  transform: scale(0.98);
}

.btn--primary {
  background: var(--tx);
  color: var(--on-cta);
}

.btn--secondary {
  background: transparent;
  color: var(--tx);
  box-shadow: inset 0 0 0 1px var(--border);
}

.btn--ghost-dark {
  width: auto;
  min-height: 44px;
  padding: 0 22px;
  background: transparent;
  color: var(--on-art);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.32);
}

.btn[aria-busy='true'] {
  opacity: 0.6;
  pointer-events: none;
}

.link {
  min-height: 44px;
  margin-top: 6px;
  padding: 12px;
  border: 0;
  background: none;
  font: 400 14.5px/1.2 var(--sans);
  color: var(--tx2);
  text-decoration: underline;
  text-underline-offset: 3px;
}

.ring {
  width: 36px;
  height: 36px;
  color: var(--tx2);
}

.ring circle {
  fill: none;
  stroke: currentColor;
  stroke-width: 2.4;
  stroke-linecap: round;
  stroke-dasharray: 76 30;
  transform-origin: 50% 50%;
  animation: ring-turn 1s linear infinite;
}

@keyframes ring-turn {
  to {
    transform: rotate(360deg);
  }
}

.badge {
  display: grid;
  place-items: center;
  width: 84px;
  height: 84px;
  border-radius: 42px;
  background: var(--well);
  color: var(--tx);
  position: relative;
}

.badge__check {
  position: absolute;
  top: 2px;
  right: 2px;
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border-radius: 13px;
  background: var(--trust);
  color: var(--elevated);
  box-shadow: 0 0 0 3px var(--canvas);
}

.app-icon {
  width: 72px;
  height: 72px;
  border-radius: 18px;
}

.points {
  width: 100%;
  max-width: 320px;
  margin: 24px 0 0;
  padding: 0;
  list-style: none;
  text-align: left;
}

.points li {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 0;
  font-size: 15px;
  color: var(--tx);
}

.points__check {
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  flex-shrink: 0;
  border-radius: 12px;
  background: var(--trust);
  color: var(--elevated);
}

/* ─────────────────────────── the immersive viewer ─────────────────────────── */

.viewer {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: flex;
  flex-direction: column;
  background: var(--stage);
  color: var(--on-art);
  animation: viewer-in 200ms var(--ease-soft);
}

@keyframes viewer-in {
  from {
    opacity: 0;
  }
}

.viewer__bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 44px;
  padding: calc(12px + var(--safe-top)) 12px 0;
}

.viewer__button {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 0;
  border-radius: 22px;
  background: transparent;
  color: var(--on-art);
}

.viewer__spacer {
  width: 44px;
  height: 44px;
}

.counter {
  margin: 0;
  font: 600 15px/1 var(--sans);
  letter-spacing: 0.3px;
  color: var(--on-art);
}

.stage {
  position: relative;
  flex: 1;
  min-height: 0;
  overflow: hidden;
  touch-action: pan-y;
  user-select: none;
  -webkit-user-select: none;
}

.stage__content {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  will-change: transform;
}

.stage__content--settle {
  transition: transform 240ms var(--ease);
}

.stage__content--from-right {
  animation: from-right 260ms var(--ease);
}

.stage__content--from-left {
  animation: from-left 260ms var(--ease);
}

@keyframes from-right {
  from {
    transform: translateX(28%);
    opacity: 0.4;
  }
}

@keyframes from-left {
  from {
    transform: translateX(-28%);
    opacity: 0.4;
  }
}

.stage__content img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  -webkit-user-drag: none;
}

.nav {
  position: absolute;
  top: 50%;
  z-index: 2;
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  margin-top: -22px;
  padding: 0;
  border: 1px solid var(--disc-frame);
  border-radius: var(--r-pill);
  background: var(--disc);
  color: var(--on-art);
  transition: transform 150ms var(--ease-soft);
}

.nav:active {
  transform: scale(0.9);
}

.nav--prev {
  left: 10px;
}

.nav--next {
  right: 10px;
}

.nav[aria-disabled='true'] {
  opacity: 0.35;
  cursor: default;
}

.frame {
  position: absolute;
  inset: 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 28px;
  border-radius: var(--r-tile);
  background: var(--frame);
  color: var(--on-art);
  text-align: center;
}

.frame__icon {
  color: var(--on-art-2);
}

.frame__title {
  margin: 18px 0 0;
  font: 500 16px/1.35 var(--sans);
  color: var(--on-art);
}

.frame__text {
  max-width: 28ch;
  margin: 6px 0 0;
  font-size: 13.5px;
  line-height: 1.5;
  color: var(--on-art-2);
}

.frame .btn--ghost-dark {
  margin-top: 22px;
}

.viewer__foot {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 60px;
  padding: 12px 18px calc(16px + var(--safe-bottom));
}

.avatar {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  flex-shrink: 0;
  overflow: hidden;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.12);
  font: 300 17px/1 var(--sans);
  color: rgba(255, 255, 255, 0.7);
}

.avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.foot__name {
  margin: 0;
  font: 500 15px/1.2 var(--sans);
  color: var(--on-art);
}

.foot__role {
  margin: 2px 0 0;
  font: 400 13px/1.2 var(--sans);
  color: var(--on-art-2);
}

/* ─────────────────────────── motion, reduced ─────────────────────────── */

@media (prefers-reduced-motion: reduce) {
  .ring circle {
    animation: ring-breathe 1.6s ease-in-out infinite;
  }

  @keyframes ring-breathe {
    50% {
      opacity: 0.35;
    }
  }

  .viewer,
  .stage__content--from-right,
  .stage__content--from-left {
    animation: none;
  }

  .stage__content--settle,
  .icon-button,
  .tile,
  .btn,
  .float-cta,
  .nav {
    transition: none;
  }
}

/* the page's own Reduced Motion answer — the overlay carries the class itself, being the page's sibling */
.viewer.reduced-motion,
.reduced-motion .stage__content--from-right,
.reduced-motion .stage__content--from-left {
  animation: none;
}

.reduced-motion .stage__content--settle {
  transition: none;
}
