@font-face {
  font-family: "Bricolage Grotesque";
  src: url("../vendor/fonts/bricolage-grotesque.woff2") format("woff2");
  font-weight: 200 800;
  font-display: swap;
}

:root {
  --paper: #f1f3ee;
  --raised: #fcfdfb;
  --ink: #17211f;
  --ink-soft: #56625e;
  --line: #d2d8cf;
  --coat: #5746e0; /* the violet of an anti-reflective lens coating */

  --font: "Bricolage Grotesque", "Avenir Next", "Segoe UI", system-ui, sans-serif;
  --gutter: clamp(1.25rem, 4vw, 3.5rem);
  --ease: cubic-bezier(0.2, 0.7, 0.2, 1);

  color-scheme: light;
}

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

[hidden] {
  display: none !important;
}

html {
  height: 100%;
}

body {
  display: grid;
  grid-template: minmax(0, 1fr) auto / minmax(0, 1fr); /* one column that never grows past the window */
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--paper);
  color: var(--ink);
  font: 400 1.0625rem/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
}

a {
  color: inherit;
  text-underline-offset: 0.18em;
}

:focus-visible {
  outline: 3px solid var(--coat);
  outline-offset: 3px;
}

/* --- Mirror: the camera picture with the frame on it ----------------------- */

.mirror {
  position: fixed;
  inset: 0;
  background: #000;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.5s var(--ease), visibility 0s 0.5s;
}

[data-state="live"] .mirror {
  opacity: 1;
  visibility: visible;
  transition-delay: 0s;
}

.mirror__layer {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: scaleX(-1); /* behave like a mirror */
}

/* --- Intro ----------------------------------------------------------------- */

.intro {
  position: relative;
  grid-row: 1;
  display: grid;
  grid-template-columns: minmax(0, 5fr) minmax(0, 7fr);
  align-items: center;
  gap: var(--gutter);
  padding: var(--gutter);
  padding-top: calc(var(--gutter) + env(safe-area-inset-top));
  overflow: auto;
}

[data-state="live"] .intro,
[data-state="problem"] .intro {
  display: none;
}

.intro__title {
  margin: 0 0 0.3em;
  font-size: clamp(3.25rem, 9vw, 8rem);
  font-weight: 700;
  line-height: 0.9;
  letter-spacing: -0.04em;
}

.intro__lede {
  max-width: 30ch;
  margin: 0 0 1.75em;
  color: var(--ink-soft);
  font-size: clamp(1.0625rem, 1.5vw, 1.3125rem);
  line-height: 1.4;
}

/* A pool of shade behind the frame and a shadow under it, so pale and clear frames stand out. */
.intro__preview {
  width: 100%;
  height: auto;
  background: radial-gradient(closest-side, rgb(23 33 31 / 0.1), rgb(23 33 31 / 0) 100%);
  filter: drop-shadow(0 1.25rem 1.1rem rgb(23 33 31 / 0.24));
}

@media (max-width: 760px) {
  .intro {
    grid-template-columns: minmax(0, 1fr);
    align-content: center;
    gap: 0.5rem;
  }

  .intro__preview {
    order: -1;
  }
}

/* --- Buttons --------------------------------------------------------------- */

.button {
  padding: 0.875rem 1.625rem;
  border: 0;
  border-radius: 999px;
  background: var(--ink);
  color: var(--raised);
  font: 600 1.0625rem/1.2 var(--font);
  cursor: pointer;
  transition: background-color 0.15s;
}

.button:hover {
  background: var(--coat);
}

.button:disabled {
  background: var(--ink-soft);
  cursor: progress;
}

/* --- Problem --------------------------------------------------------------- */

.problem {
  position: relative;
  grid-row: 1;
  display: none;
  align-content: center;
  justify-items: start;
  gap: 1.5rem;
  width: min(100%, 34rem);
  margin-inline: auto;
  padding: var(--gutter);
}

[data-state="problem"] .problem {
  display: grid;
}

.problem__text {
  margin: 0;
  font-size: clamp(1.375rem, 3vw, 1.875rem);
  font-weight: 600;
  line-height: 1.2;
  letter-spacing: -0.015em;
}

/* --- Hint ------------------------------------------------------------------ */

.hint {
  position: fixed;
  top: calc(1rem + env(safe-area-inset-top));
  left: 50%;
  margin: 0;
  padding: 0.5rem 1.125rem;
  border-radius: 999px;
  background: rgb(23 33 31 / 0.82);
  color: var(--raised);
  font-weight: 500;
  white-space: nowrap;
  translate: -50% 0;
}

/* --- Credits --------------------------------------------------------------- */

.credits-link {
  position: fixed;
  top: calc(0.875rem + env(safe-area-inset-top));
  right: calc(0.875rem + env(safe-area-inset-right));
  padding: 0.375rem 0.875rem;
  border: 0;
  border-radius: 999px;
  background: rgb(252 253 251 / 0.78);
  color: var(--ink);
  font: 500 0.875rem/1.3 var(--font);
  cursor: pointer;
  backdrop-filter: blur(18px) saturate(1.4);
}

.credits {
  width: min(34rem, calc(100vw - 2rem));
  padding: clamp(1.5rem, 5vw, 2.5rem);
  border: 0;
  border-radius: 1.75rem;
  background: var(--raised);
  color: var(--ink);
}

.credits::backdrop {
  background: rgb(23 33 31 / 0.5);
}

.credits__title {
  margin: 0 0 0.5em;
  font-size: 2rem;
  font-weight: 700;
  line-height: 1;
  letter-spacing: -0.03em;
}

.credits__list {
  padding-left: 1.1em;
}

.credits .button {
  margin-top: 0.5rem;
}

/* --- Tray of frames -------------------------------------------------------- */

.tray {
  position: relative;
  grid-row: 2;
  display: flex;
  justify-content: center;
  padding: 0.75rem;
  padding-bottom: calc(0.75rem + env(safe-area-inset-bottom));
}

[data-state="problem"] .tray:has(.tray__frames:empty) {
  display: none;
}

.tray__rail {
  position: relative;
  display: flex;
  min-width: 0; /* so a long catalog scrolls inside the rail and does not widen it */
  max-width: 100%;
  border: 1px solid rgb(210 216 207 / 0.7);
  border-radius: 1.875rem;
  background: rgb(252 253 251 / 0.78);
  backdrop-filter: blur(22px) saturate(1.4);
}

.tray__frames {
  --fade-before: 0rem;
  --fade-after: 0rem;
  display: flex;
  gap: 0.25rem;
  min-width: 0;
  padding: 0.375rem;
  overflow-x: auto; /* a long catalog scrolls sideways */
  overscroll-behavior-x: contain;
  scroll-snap-type: x proximity;
  scrollbar-width: none;
  border-radius: inherit;
  /* The ends fade out where more frames follow. */
  mask-image: linear-gradient(90deg, rgb(0 0 0 / 0), #000 var(--fade-before), #000 calc(100% - var(--fade-after)), rgb(0 0 0 / 0));
}

.tray__frames::-webkit-scrollbar {
  display: none;
}

.tray__rail--more-before .tray__frames {
  --fade-before: 3rem;
}

.tray__rail--more-after .tray__frames {
  --fade-after: 3rem;
}

/* Arrows for screens with a pointer; with touch, a swipe does the same. */
.tray__step {
  position: absolute;
  top: 50%;
  z-index: 1;
  display: none;
  place-items: center;
  width: 2.5rem;
  height: 2.5rem;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--raised);
  box-shadow: 0 4px 14px rgb(23 33 31 / 0.14);
  color: var(--ink);
  cursor: pointer;
  transform: translateY(-50%);
  transition: background-color 0.15s, transform 0.15s var(--ease);
}

.tray__step--back {
  left: -1rem;
}

.tray__step--onward {
  right: -1rem;
}

.tray__step:hover {
  background: #fff;
  transform: translateY(-50%) scale(1.06);
}

@media (hover: hover) and (pointer: fine) {
  .tray {
    padding-inline: 2rem;
  }

  .tray__step {
    display: grid;
  }
}

.frame {
  position: relative;
  display: grid;
  flex: none;
  justify-items: center;
  width: 6rem;
  padding: 0.375rem 0.375rem 0.5rem;
  border-radius: 1.5rem;
  cursor: pointer;
  scroll-snap-align: center;
  transition: background-color 0.15s;
}

.frame:hover {
  background: rgb(23 33 31 / 0.06);
}

.frame:has(:checked) {
  background: var(--raised);
  box-shadow: inset 0 0 0 2px var(--ink);
}

.frame:has(:focus-visible) {
  outline: 3px solid var(--coat);
  outline-offset: -3px;
}

.frame__radio {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.frame__shot {
  width: 100%;
  height: auto;
  opacity: 0;
  filter: drop-shadow(0 2px 2px rgb(23 33 31 / 0.28)); /* keeps pale frames visible on the pale tray */
  transition: opacity 0.3s;
}

.frame--ready .frame__shot {
  opacity: 1;
}

/* Until a frame's picture has arrived, its place is held by a soft shape. */
.frame:not(.frame--ready)::before {
  content: "";
  position: absolute;
  top: 0.9rem;
  left: 50%;
  width: 3.25rem;
  height: 1.5rem;
  border-radius: 999px;
  background: rgb(23 33 31 / 0.07);
  transform: translateX(-50%);
}

.frame__name {
  max-width: 100%;
  overflow: hidden;
  color: var(--ink-soft);
  font-size: 0.8125rem;
  font-weight: 500;
  line-height: 1.2;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.frame:has(:checked) .frame__name {
  color: var(--ink);
  font-weight: 650;
}

@media (max-width: 520px) {
  .frame {
    width: 5.1rem;
    padding-inline: 0.25rem;
  }

  .frame__name {
    font-size: 0.75rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition-duration: 0s !important;
  }
}

/* --- Languages with longer words ---------------------------------------------- */

:lang(de) .intro__title {
  font-size: clamp(2.25rem, 5vw, 4.5rem);
  line-height: 0.95;
}
