/* Recording page: one frame, centred on white. Nothing else. */

/* The page is exactly one screen tall and the picture takes whatever is left
   over after the words and the controls. Picking a fraction of the viewport
   instead cannot satisfy both "as big as possible" and "never scrolls", because
   the heading and the buttons cost the same on a short phone as a tall one. */
.record-body {
  /* Georgia is on every machine, so nothing to download and nothing to wait
     for. Serif for the words, plain system sans for the controls. */
  --serif: Georgia, 'Times New Roman', Times, serif;
  --ui: -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif;
  --accent: #e3a2b0;

  background: #fff;
  min-height: 100svh;
  height: 100svh;
  display: grid;
  justify-items: center;
  /* Stretched, not centred: flex-grow inside needs a container with a real
     height or the picture collapses to nothing. */
  align-items: stretch;
  padding: clamp(1.875rem, 4vw, 2.5rem);
}

.record-body .backdrop,
.record-body .grain {
  display: none;
}

/* iOS Safari gives buttons and inputs a native appearance that overrides
   background, border and radius. Without opting out, every control here renders
   as a stock iOS button on a phone while looking correct everywhere else.
   Deliberately only appearance: an element+class selector outranks the plain
   class selectors the components use, so anything else set here would clobber
   them. */
.record-body button,
.record-body input,
.record-body textarea {
  -webkit-appearance: none;
  appearance: none;
  -webkit-tap-highlight-color: transparent;
}

.stage-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: clamp(0.8rem, 2vh, 1.4rem);
  /* A bounded content column, so the layout is the same shape on a small
     phone and a large one. */
  width: min(100%, 30rem);
  height: 100%;
  min-height: 0;
  justify-content: center;
}

/* ------------------------------------------------------------------ intro */

.intro {
  text-align: center;
  max-width: min(48rem, 100%);
}

.intro h1 {
  font-family: var(--serif);
  font-weight: 400;
  font-size: clamp(1.65rem, 5.5vw, 2.4rem);
  line-height: 1.15;
  letter-spacing: -0.01em;
  margin: 0 0 0.4rem;
  color: #16130f;
}

.intro h1 em {
  font-style: italic;
  color: var(--accent);
}

.intro p {
  margin: 0;
  font-family: var(--serif);
  font-size: clamp(0.82rem, 1.5vw, 0.98rem);
  line-height: 1.5;
  color: #8a8279;
  text-wrap: balance;
}

/* Once the take is done the instructions have served their purpose, and the
   space they were using is needed. */
.intro.is-done p {
  display: none;
}

/* --------------------------------------------------------------- the frame */

/* Portrait on a phone, landscape on a desktop, sized so the picture is roughly
   half the screen either way. */
.stage-wrap {
  --stage-h: min(66svh, 132vw);
  --stage-w: calc(var(--stage-h) * 3 / 4);
}

/* The review fields add a block under the picture, so the picture gives up
   height and the spacing tightens, keeping the whole step on one screen. */
.stage-wrap.is-review {
  --stage-h: min(52svh, 104vw);
  --stage-w: calc(var(--stage-h) * 3 / 4);
  gap: clamp(0.7rem, 1.8vh, 1rem);
}

/* The heading has done its job by this point and the room is needed. */
.stage-wrap.is-review .intro {
  display: none;
}

/* A drawing pad is taller than a two-line field, so the picture gives up more.
   Only after recording: before that there is no note yet and the picture should
   be its full size. */
.stage-wrap.is-review.is-drawn {
  --stage-h: min(32svh, 64vw);
  --stage-w: calc(var(--stage-h) * 3 / 4);
  --sketch-h: min(12rem, 27svh);
}

.stage {
  position: relative;
  /* Takes the leftover height; the aspect ratio then sets the width. */
  flex: 1 1 0;
  min-height: 0;
  height: auto;
  width: auto;
  max-height: var(--stage-h);
  max-width: 100%;
  align-self: center;
  aspect-ratio: 3 / 4;
  overflow: hidden;
  border-radius: 10px;
  background: #f1efec;
}

@media (min-width: 48rem) {
  .stage-wrap {
    --stage-h: min(64svh, 48vw);
    --stage-w: calc(var(--stage-h) * 3 / 2);
  }

  .stage-wrap.is-review {
    --stage-h: min(44svh, 32vw);
    --stage-w: calc(var(--stage-h) * 3 / 2);
  }

  .stage-wrap.is-review.is-drawn {
    --stage-h: min(30svh, 24vw);
    --stage-w: calc(var(--stage-h) * 3 / 2);
    --sketch-h: min(15rem, 26svh);
  }

  /* A short laptop has less room than a phone once the fields are in. */
  @media (max-height: 820px) {
    .stage-wrap.is-review {
      --stage-h: min(36svh, 30vw);
      --stage-w: calc(var(--stage-h) * 3 / 2);
    }

    .stage-wrap.is-review.is-drawn {
      --stage-h: min(25svh, 22vw);
      --stage-w: calc(var(--stage-h) * 3 / 2);
      --sketch-h: min(15rem, 25svh);
    }
  }

  /* The column cap is a phone concern; on a desktop it would squeeze the
     picture down to the width of a phone. */
  .stage-wrap {
    width: auto;
    max-width: 100%;
  }

  /* A desktop has the height to spare, so the picture goes back to being sized
     directly rather than taking what is left. */
  .stage {
    flex: 0 0 auto;
    height: var(--stage-h);
    max-height: none;
    aspect-ratio: 3 / 2;
  }
}

/* A laptop is wide but short, so the picture has to be sized by the height
   that is actually left over rather than by the width. */
@media (min-width: 48rem) and (max-height: 800px) {
  .stage-wrap {
    --stage-h: min(48svh, 42vw);
    --stage-w: calc(var(--stage-h) * 3 / 2);
  }
}

@media (min-width: 48rem) and (min-height: 801px) and (max-height: 960px) {
  .stage-wrap {
    --stage-h: min(57svh, 44vw);
    --stage-w: calc(var(--stage-h) * 3 / 2);
  }
}

.stage video,
.stage canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  background: #12100e;
}

/* Mirrored so it behaves like a mirror while you record. The file itself is the
   camera stream untouched. */
#preview.is-mirrored,
#playback.is-mirrored {
  transform: scaleX(-1);
}

.stage video[hidden],
.stage canvas[hidden] {
  display: none;
}

.stage-idle {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 1.5rem;
  background: #f1efec;
}

.stage-idle p {
  margin: 0;
  font-family: var(--serif);
  font-size: 0.85rem;
  line-height: 1.5;
  text-align: center;
  color: #8a8279;
  max-width: 17rem;
}

.stage-idle p:empty {
  display: none;
}

.timer {
  position: absolute;
  top: 0.7rem;
  left: 0.7rem;
  display: none;
  align-items: center;
  gap: 0.4rem;
  padding: 0.28rem 0.6rem 0.28rem 0.5rem;
  border-radius: 100px;
  background: rgba(10, 8, 6, 0.55);
  color: #fff;
  font-family: var(--ui);
  font-size: 0.64rem;
  font-variant-numeric: tabular-nums;
  z-index: 3;
}

.timer.is-visible {
  display: flex;
}

.timer i {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #e5484d;
  animation: pulse 1.2s ease-in-out infinite;
}

@keyframes pulse {
  50% {
    opacity: 0.25;
  }
}

/* Camera flip stays on the picture: it is a camera control. */
.flip-cam {
  position: absolute;
  top: 0.7rem;
  right: 0.7rem;
  display: none;
  place-items: center;
  width: 2rem;
  height: 2rem;
  margin: 0;
  border: none;
  border-radius: 50%;
  background: rgba(10, 8, 6, 0.42);
  color: #fff;
  font-size: 0.85rem;
  line-height: 1;
  cursor: pointer;
  z-index: 3;
}

.flip-cam.is-visible {
  display: grid;
}

/* ------------------------------------------------------------- controls */

.controls[hidden] {
  display: none;
}

.controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: clamp(1.5rem, 6vw, 2.75rem);
}

.icon-btn {
  display: grid;
  place-items: center;
  width: 2.5rem;
  height: 2.5rem;
  margin: 0;
  padding: 0;
  border: 1px solid rgba(22, 19, 15, 0.18);
  border-radius: 50%;
  background: #fff;
  color: #6f675e;
  cursor: pointer;
  transition: border-color 0.2s ease, color 0.2s ease, opacity 0.2s ease;
}

.icon-btn:hover {
  border-color: #16130f;
  color: #16130f;
}

.icon-btn svg {
  width: 1.05rem;
  height: 1.05rem;
}

.icon-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.filepick input {
  display: none;
}

.filepick[hidden] {
  display: none;
}

/* Held in place but inert mid-take, so the row never jumps. */
.filepick.is-inert {
  pointer-events: none;
  opacity: 0.3;
}

.shutter {
  position: relative;
  width: 4rem;
  height: 4rem;
  padding: 0;
  border: none;
  background: none;
  border-radius: 50%;
  cursor: pointer;
  flex: 0 0 auto;
  -webkit-tap-highlight-color: transparent;
}

.shutter[hidden] {
  display: none;
}

.shutter .ring {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 2px solid rgba(22, 19, 15, 0.25);
}

.shutter .core {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 3rem;
  height: 3rem;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background: #e5484d;
  transition: width 0.28s cubic-bezier(0.3, 0.9, 0.3, 1),
    height 0.28s cubic-bezier(0.3, 0.9, 0.3, 1), border-radius 0.28s ease;
}

.shutter[data-state='recording'] .core {
  width: 1.4rem;
  height: 1.4rem;
  border-radius: 4px;
}

.shutter:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.shutter svg {
  position: absolute;
  inset: -4px;
  width: calc(100% + 8px);
  height: calc(100% + 8px);
  transform: rotate(-90deg);
  pointer-events: none;
}

.shutter svg circle {
  fill: none;
  stroke: #e5484d;
  stroke-width: 2.5;
  stroke-linecap: round;
  opacity: 0;
  transition: opacity 0.2s ease;
}

.shutter[data-state='recording'] svg circle {
  opacity: 1;
}

/* --------------------------------------------------------------- review */

/* Under the picture, not over it, and matched to its width. */
.review {
  display: none;
  gap: 0.55rem;
  width: var(--stage-w);
}

/* A phone has the width to spare, and the drawing pad in particular wants it.
   Above this the block stays matched to the picture. */
@media (max-width: 47.99rem) {
  .review {
    width: 100%;
  }
}

.review.is-visible {
  display: grid;
}

.review input[type='text'],
.review textarea {
  width: 100%;
  font-family: var(--serif);
  /* 16px: below that iOS zooms the page in when the field takes focus. */
  font-size: 1rem;
  color: #16130f;
  padding: 0.5rem 0;
  background: transparent;
  border: none;
  border-bottom: 1px solid rgba(22, 19, 15, 0.16);
  border-radius: 0;
  transition: border-color 0.2s ease;
}

.review textarea {
  resize: none;
  line-height: 1.4;
}

.review input[type='text']::placeholder,
.review textarea::placeholder {
  color: #a49c92;
}

.review input[type='text']:focus,
.review textarea:focus {
  outline: none;
  border-bottom-color: #16130f;
}

.review-row {
  display: flex;
  gap: 0.5rem;
  padding-top: 0.3rem;
}

.pill {
  flex: 1;
  font-family: var(--ui);
  font-size: 0.66rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  padding: 0.65rem 1rem;
  border-radius: 100px;
  border: 1px solid rgba(22, 19, 15, 0.2);
  background: #fff;
  color: #16130f;
  cursor: pointer;
  text-align: center;
  text-decoration: none;
  transition: border-color 0.2s ease, background 0.2s ease, opacity 0.2s ease;
}

.pill:hover:not(:disabled) {
  border-color: #16130f;
}

.pill--dark {
  background: #16130f;
  border-color: #16130f;
  color: #fff;
}

.pill--dark:hover:not(:disabled) {
  background: #16130f;
  opacity: 0.86;
}

.pill:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* ----------------------------------------------------------------- note */

.note {
  display: grid;
  gap: 0.4rem;
}

.note-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.note-label {
  font-family: var(--ui);
  font-size: 0.6rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: #9a9289;
}

.note-modes {
  display: flex;
  gap: 0.3rem;
}

.mode {
  font-family: var(--ui);
  font-size: 0.58rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  padding: 0.3rem 0.6rem;
  border: 1px solid rgba(22, 19, 15, 0.16);
  border-radius: 100px;
  background: #fff;
  color: #8a8279;
  cursor: pointer;
  transition: border-color 0.2s ease, color 0.2s ease, background 0.2s ease;
}

.mode.is-active {
  background: #16130f;
  border-color: #16130f;
  color: #fff;
}

/* ------------------------------------------------------------- sketch pad */

#message[hidden] {
  display: none;
}

.sketch[hidden] {
  display: none;
}

.sketch {
  display: grid;
  gap: 0.45rem;
}

#sketchCanvas {
  width: 100%;
  height: var(--sketch-h, 8rem);
  display: block;
  border: 1px solid rgba(22, 19, 15, 0.16);
  border-radius: 8px;
  background: #fffdfa;
  cursor: crosshair;
  /* Otherwise a finger drag scrolls the page instead of drawing. */
  touch-action: none;
}

/* Wraps rather than overflowing: seven swatches plus the picker and Clear are
   wider than the picture on a phone. */
.sketch-tools {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.3rem 0.35rem;
}

.swatches {
  display: flex;
  flex-wrap: wrap;
  gap: var(--pencil-gap);
  flex: 0 1 auto;
  min-width: 0;
}

.sketch {
  --pencil-gap: 0.28rem;
  --pencil: 1.3rem;
}

.swatch {
  display: block;
  width: var(--pencil);
  height: var(--pencil);
  padding: 0;
  border-radius: 50%;
  border: 1px solid rgba(22, 19, 15, 0.14);
  background: var(--c);
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.swatch:hover {
  transform: scale(1.12);
}

.swatch.is-active {
  box-shadow: 0 0 0 2px #fff, 0 0 0 3.5px #16130f;
}

/* The native colour input cannot be styled at all, and on iOS it renders as a
   system control, so this is a custom picker instead. */
/* A block wrapper leaves a baseline gap under the button, which makes the
   wrapper taller than the circle and lifts it out of line with the pencils. */
.picker-wrap {
  position: relative;
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  line-height: 0;
}

.custom-colour {
  display: block;
  width: var(--pencil);
  height: var(--pencil);
  padding: 0;
  border-radius: 50%;
  border: 1px solid rgba(22, 19, 15, 0.14);
  background: var(--picked, conic-gradient(
      #f2a3b3,
      #f6c99a,
      #f3e3a3,
      #a9d9bd,
      #a3c9e8,
      #c3b3e6,
      #f2a3b3
    ));
  cursor: pointer;
}

.custom-colour.is-active {
  box-shadow: 0 0 0 2px #fff, 0 0 0 3.5px #16130f;
}

.picker {
  position: absolute;
  bottom: calc(100% + 0.5rem);
  left: 50%;
  transform: translateX(-50%);
  z-index: 20;
  display: grid;
  gap: 0.5rem;
  padding: 0.6rem;
  width: 11.5rem;
  border-radius: 14px;
  background: #fff;
  border: 1px solid rgba(22, 19, 15, 0.1);
  box-shadow: 0 10px 30px rgba(22, 19, 15, 0.16);
}

.picker[hidden] {
  display: none;
}

/* A little tail, so it reads as attached to the button. */
.picker::after {
  content: '';
  position: absolute;
  top: 100%;
  left: 50%;
  width: 10px;
  height: 10px;
  margin-left: -5px;
  margin-top: -5px;
  transform: rotate(45deg);
  background: #fff;
  border-right: 1px solid rgba(22, 19, 15, 0.1);
  border-bottom: 1px solid rgba(22, 19, 15, 0.1);
  border-bottom-right-radius: 3px;
}

.picker-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 0.28rem;
}

.tint {
  width: 100%;
  aspect-ratio: 1;
  padding: 0;
  border-radius: 50%;
  border: 1px solid rgba(22, 19, 15, 0.1);
  background: var(--c);
  cursor: pointer;
  transition: transform 0.15s ease;
}

.tint:hover {
  transform: scale(1.15);
}

.hue {
  width: 100%;
  height: 0.7rem;
  border-radius: 100px;
  background: linear-gradient(
    to right,
    #ff5f6d,
    #ffc371,
    #f7f18c,
    #9be7b8,
    #8fd3f4,
    #b8a7e8,
    #ff5f6d
  );
  cursor: pointer;
}

.hue::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 0.95rem;
  height: 0.95rem;
  border-radius: 50%;
  background: #fff;
  border: 1px solid rgba(22, 19, 15, 0.25);
  box-shadow: 0 1px 4px rgba(22, 19, 15, 0.25);
  cursor: pointer;
}

.hue::-moz-range-thumb {
  width: 0.95rem;
  height: 0.95rem;
  border-radius: 50%;
  background: #fff;
  border: 1px solid rgba(22, 19, 15, 0.25);
}

.sketch-tools .mini {
  margin-left: auto;
}

.mini {
  font-family: var(--ui);
  font-size: 0.56rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  padding: 0.3rem 0.55rem;
  border: 1px solid rgba(22, 19, 15, 0.16);
  border-radius: 100px;
  background: #fff;
  color: #8a8279;
  cursor: pointer;
  flex: 0 0 auto;
}

.mini:hover {
  border-color: #16130f;
  color: #16130f;
}

/* --------------------------------------------- the only playback control */

.scrub {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 3px;
  display: none;
  background: rgba(255, 255, 255, 0.28);
  cursor: pointer;
  z-index: 5;
  touch-action: none;
}

.scrub.is-visible {
  display: block;
}

.scrub::before {
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  top: -11px;
  height: 16px;
}

.scrub-fill {
  height: 100%;
  width: 0%;
  background: #fff;
}

/* ----------------------------------------------------------------- misc */

.progress {
  display: none;
}

.progress.is-visible {
  display: block;
  padding-top: 0.2rem;
}

.progress .track {
  height: 1.5px;
  background: rgba(22, 19, 15, 0.12);
  overflow: hidden;
}

.progress .bar {
  height: 100%;
  width: 0%;
  background: #16130f;
  transition: width 0.3s ease;
}

.progress .label {
  margin-top: 0.3rem;
  font-family: var(--ui);
  font-size: 0.6rem;
  color: #8a8279;
  text-align: center;
}

.hint-line {
  margin: 0;
  min-height: 0.9rem;
  text-align: center;
  font-family: var(--ui);
  font-size: 0.62rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: #9a9289;
}

.error {
  max-width: min(26rem, 88vw);
  padding: 0.55rem 0.85rem;
  border-radius: 8px;
  background: rgba(160, 44, 32, 0.08);
  border: 1px solid rgba(160, 44, 32, 0.2);
  color: #8c2b1e;
  font-family: var(--ui);
  font-size: 0.62rem;
  line-height: 1.5;
  text-align: center;
  display: none;
}

.error.is-visible {
  display: block;
}

/* ---------------------------------------------------------------- thanks */

.thanks {
  display: grid;
  justify-items: center;
  gap: 0.6rem;
  text-align: center;
  max-width: 26rem;
  /* The record page stretches its content to fill the screen. This page must
     opt out, or the rows spread apart and the link stretches into a blob. */
  align-self: center;
  align-content: center;
  height: auto;
}

.thanks h1 {
  font-family: var(--serif);
  font-weight: 400;
  font-size: clamp(1.9rem, 6vw, 2.6rem);
  line-height: 1.15;
  margin: 0;
  color: #16130f;
}

.thanks h1 em {
  font-style: italic;
  color: var(--accent);
}

.thanks p {
  margin: 0;
  font-family: var(--serif);
  font-size: 0.95rem;
  line-height: 1.55;
  color: #8a8279;
}

.thanks .pill {
  flex: 0 0 auto;
  align-self: center;
  width: auto;
  height: auto;
  margin-top: 1.4rem;
  padding-inline: 1.6rem;
}
