:root {
  --sun: #ffd23f;
  --pink: #ff4f8b;
  --ink: #ffffff;
  --ink-soft: rgb(255 255 255 / 0.72);
  --glass: rgb(24 20 38 / 0.66);
  --glass-hover: rgb(70 60 100 / 0.8);
  --gutter: 16px;
  --ease: 180ms ease;
  color-scheme: dark;
  font-family: ui-rounded, "SF Pro Rounded", "Nunito", "Segoe UI", system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: #000;
  color: var(--ink);
  -webkit-tap-highlight-color: transparent;
}

button,
a,
label {
  touch-action: manipulation;
}

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

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

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

[hidden] {
  display: none !important;
}

/* The stage: live video, with the frozen picture stacked exactly on top */

#stage {
  position: fixed;
  inset: 0;
}

#live,
#film {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

[data-mirrored="true"] #live {
  transform: scaleX(-1);
}

#scanline {
  --glow: 0 0 10px var(--sun), 0 0 26px var(--pink);
  position: absolute;
  background: var(--sun);
  box-shadow: var(--glow);
  opacity: 0.45;
  pointer-events: none;
  transition: opacity var(--ease);
}

#scanline[data-axis="y"] {
  left: 0;
  right: 0;
  height: 3px;
  margin-top: -1.5px;
  top: calc(var(--position) * 100%);
}

#scanline[data-axis="x"] {
  top: 0;
  bottom: 0;
  width: 3px;
  margin-left: -1.5px;
  left: calc(var(--position) * 100%);
}

[data-state="scanning"] #scanline,
[data-state="paused"] #scanline {
  opacity: 1;
}

/* A paused line breathes, so it doesn't look like the app froze */
[data-state="paused"] #scanline {
  animation: breathe 1.6s ease-in-out infinite;
}

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

[data-state="starting"] #scanline,
[data-state="no-camera"] #scanline {
  opacity: 0;
}

#countdown {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: min(44vw, 44vh);
  font-weight: 800;
  color: var(--sun);
  text-shadow: 0 6px 40px rgb(0 0 0 / 0.55);
  pointer-events: none;
}

/* Messages */

#notice {
  position: fixed;
  inset: 0;
  display: none;
  place-content: center;
  justify-items: center;
  gap: 20px;
  padding: var(--gutter);
  text-align: center;
  font-size: 1.25rem;
}

#notice p {
  max-width: 28em;
  margin: 0;
}

[data-state="starting"] #notice,
[data-state="no-camera"] #notice {
  display: grid;
}

#retry {
  display: none;
}

[data-state="no-camera"] #retry {
  display: block;
}

#toast {
  position: fixed;
  top: calc(env(safe-area-inset-top) + var(--gutter));
  left: 50%;
  translate: -50%;
  width: max-content;
  max-width: calc(100vw - 2 * var(--gutter));
  margin: 0;
  padding: 10px 18px;
  border-radius: 999px;
  background: var(--glass);
  opacity: 0;
  pointer-events: none;
}

/* The controls floating over the live view */

#hud {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  display: grid;
  gap: 14px;
  padding: var(--gutter);
  padding-bottom: calc(env(safe-area-inset-bottom) + var(--gutter));
  padding-left: calc(env(safe-area-inset-left) + var(--gutter));
  padding-right: calc(env(safe-area-inset-right) + var(--gutter));
  pointer-events: none;
}

#hud > *,
#deck > * {
  pointer-events: auto;
}

[data-state="starting"] #hud,
[data-state="no-camera"] #hud {
  display: none;
}

#settings {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
  justify-self: center;
  pointer-events: none;
}

#settings > * {
  pointer-events: auto;
}

#direction {
  display: flex;
  gap: 2px;
  margin: 0;
  padding: 4px;
  border: 0;
  border-radius: 999px;
  background: var(--glass);
  backdrop-filter: blur(10px);
}

#direction label {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  cursor: pointer;
  transition: background var(--ease), color var(--ease);
}

#direction label:hover {
  background: var(--glass-hover);
}

#direction input {
  position: absolute;
  opacity: 0;
}

#direction label:has(:checked) {
  background: var(--sun);
  color: #201a33;
}

#direction label:has(:focus-visible) {
  outline: 3px solid var(--sun);
  outline-offset: 2px;
}

.arrow {
  width: 24px;
  height: 24px;
  rotate: var(--turn);
}

#speed-control {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 52px;
  padding: 0 18px;
  border-radius: 999px;
  background: var(--glass);
  backdrop-filter: blur(10px);
  font-size: 1.2rem;
}

#speed {
  width: clamp(110px, 24vw, 240px);
  accent-color: var(--sun);
  cursor: pointer;
}

#speed-value {
  min-width: 2.3em;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  text-align: right;
  color: var(--sun);
}

#deck {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  grid-template-areas: "recent shutter tools";
  align-items: center;
  gap: 14px;
  pointer-events: none;
}

#recent {
  grid-area: recent;
  display: flex;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.thumb {
  display: block;
  width: 56px;
  height: 56px;
  padding: 0;
  overflow: hidden;
  border: 2px solid var(--ink);
  border-radius: 14px;
  background: var(--glass);
  transition: scale var(--ease);
}

.thumb:hover {
  scale: 1.08;
}

.thumb img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

#tools {
  grid-area: tools;
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.tool {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  min-width: 52px;
  height: 52px;
  padding: 0 12px;
  border-radius: 999px;
  background: var(--glass);
  backdrop-filter: blur(10px);
  font-weight: 700;
  transition: background var(--ease);
}

.tool:hover:not(:disabled) {
  background: var(--glass-hover);
}

.tool:disabled {
  opacity: 0.35;
  cursor: default;
}

.tool > svg {
  width: 24px;
  height: 24px;
}

/* Wide enough for the longest label, so the row doesn't shift while cycling */
#smoothness-value {
  min-width: 3.6em;
  text-align: left;
}

#shutter {
  --progress: 0;
  grid-area: shutter;
  display: grid;
  place-items: center;
  width: 84px;
  height: 84px;
  padding: 0;
  border-radius: 50%;
  background: var(--ink);
  transition: scale var(--ease);
}

#shutter:hover {
  scale: 1.05;
}

#shutter:active {
  scale: 0.94;
}

#shutter span {
  width: 68px;
  height: 68px;
  border: 3px solid #201a33;
  border-radius: 50%;
  background: var(--pink);
  transition: width var(--ease), height var(--ease), border-radius var(--ease);
}

/* While capturing, nothing gets in the way of the picture except the shutter:
   a stop button during the countdown, then pause and resume during the scan */

[data-state="countdown"] #settings,
[data-state="scanning"] #settings,
[data-state="paused"] #settings,
[data-state="countdown"] #recent,
[data-state="scanning"] #recent,
[data-state="paused"] #recent,
[data-state="countdown"] #tools,
[data-state="scanning"] #tools,
[data-state="paused"] #tools {
  visibility: hidden;
}

[data-state="countdown"] #shutter,
[data-state="scanning"] #shutter,
[data-state="paused"] #shutter {
  width: 60px;
  height: 60px;
  margin: 12px;
  background: conic-gradient(var(--sun) calc(var(--progress) * 360deg), rgb(255 255 255 / 0.3) 0);
}

[data-state="countdown"] #shutter span,
[data-state="scanning"] #shutter span,
[data-state="paused"] #shutter span {
  width: 24px;
  height: 24px;
  border: 0;
  border-radius: 6px;
  background: var(--ink);
}

/* Pause: two bars */
[data-state="scanning"] #shutter span {
  width: 22px;
  border-radius: 3px;
  background: linear-gradient(to right, var(--ink) 36%, transparent 36% 64%, var(--ink) 64%);
}

/* Resume: a play triangle, nudged right so it looks centred */
[data-state="paused"] #shutter span {
  width: 22px;
  border-radius: 0;
  translate: 2px 0;
  clip-path: polygon(0 0, 100% 50%, 0 100%);
}

/* Stopping only appears once paused, so a stray tap can't lose a picture.
   main.js shows and hides it. */
#stop {
  grid-area: tools;
  justify-self: start;
}

/* The viewer */

#viewer {
  width: 100vw;
  height: 100dvh;
  max-width: none;
  max-height: none;
  margin: 0;
  padding: 0;
  border: 0;
  background: #0d0b16;
  color: var(--ink);
}

#viewer[open] {
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
}

#viewer-image {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

#viewer .nav {
  position: absolute;
  top: calc(50% - 60px);
}

#viewer-previous {
  left: calc(env(safe-area-inset-left) + var(--gutter));
}

#viewer-next {
  right: calc(env(safe-area-inset-right) + var(--gutter));
}

#viewer footer {
  display: grid;
  justify-items: center;
  gap: 10px;
  padding: 12px var(--gutter);
  padding-bottom: calc(env(safe-area-inset-bottom) + var(--gutter));
}

#viewer-caption {
  margin: 0;
  color: var(--ink-soft);
  font-size: 0.95rem;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
}

.pill {
  display: inline-block;
  padding: 13px 22px;
  border-radius: 999px;
  background: rgb(255 255 255 / 0.14);
  color: var(--ink);
  font-size: 1.05rem;
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
  transition: background var(--ease), scale var(--ease);
}

.pill:hover {
  background: rgb(255 255 255 / 0.24);
}

.pill:active {
  scale: 0.96;
}

.pill.primary {
  background: var(--sun);
  color: #201a33;
}

.pill.primary:hover {
  background: #ffe072;
}

.pill.quiet {
  background: none;
  color: var(--ink-soft);
}

/* Phones: five thumbnails won't fit beside the shutter, so they get a row */

@media (max-width: 720px) {
  #deck {
    grid-template-columns: 1fr auto 1fr;
    grid-template-areas:
      "recent recent recent"
      ". shutter tools";
    gap: 10px;
  }

  #recent {
    justify-content: center;
  }

}

/* Phones on their side: there's little height, so use the width instead */

@media (max-height: 500px) and (min-width: 560px) {
  #hud {
    grid-template-columns: 1fr;
    gap: 8px;
  }

  #deck {
    grid-template-areas: "recent shutter tools";
  }

  .thumb {
    width: 48px;
    height: 48px;
  }

  #recent {
    justify-content: flex-start;
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    transition: none !important;
    animation: none !important;
  }
}
