/* Page layout and interface components. */

/* ---------- Layout ---------- */

.stage {
  display: grid;
  justify-items: center;
  gap: var(--space-6);
  width: 100%;
  padding: var(--space-8) var(--space-4);
}

.lens-wrap {
  position: relative;
  width: min(100%, 40rem);
}

.lens {
  border-radius: var(--radius-lens);
  padding: clamp(2rem, 7vw, 3.5rem) clamp(1.25rem, 6vw, 3.5rem);
  text-align: center;
  /* The one orchestrated moment: the lens condenses into place on load. */
  animation: lens-condense 1100ms var(--ease-out) both;
}

/* Keep lens-condense in the list so it doesn't replay when the glow ends. */
.lens.is-glowing {
  animation:
    lens-condense 1100ms var(--ease-out) both,
    lens-glow 2600ms var(--ease-out);
}

.view {
  display: grid;
  justify-items: center;
  gap: var(--space-5);
  animation: view-in 450ms var(--ease-out) both;
}

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

.corner-controls {
  position: fixed;
  top: max(var(--space-4), env(safe-area-inset-top));
  right: max(var(--space-4), env(safe-area-inset-right));
  z-index: 10;
  display: flex;
  gap: var(--space-2);
}

.chip {
  display: grid;
  place-items: center;
  width: 2.75rem;
  height: 2.75rem;
  padding: 0;
  border: 0;
  border-radius: 50%;
  transition:
    transform 200ms var(--ease-spring),
    --light-angle 700ms var(--ease-out);
}

.chip:active {
  transform: scale(0.92);
}

.chip svg {
  width: 1.25rem;
  height: 1.25rem;
}

.icon-sun,
.icon-collapse,
[data-theme="dark"] .icon-moon,
.is-fullscreen .icon-expand {
  display: none;
}

[data-theme="dark"] .icon-sun,
.is-fullscreen .icon-collapse {
  display: block;
}

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

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 3rem;
  padding: var(--space-3) var(--space-6);
  border: 0;
  border-radius: var(--radius-pill);
  font-size: var(--text-md);
  font-weight: 600;
  transition: transform 200ms var(--ease-spring);
}

.button:active {
  transform: scale(0.96);
}

.button--solid {
  background: var(--solid);
  color: var(--on-solid);
  box-shadow: 0 0.5rem 1.5rem -0.5rem rgb(20 11 46 / 0.5);
}

/* ---------- Setup ---------- */

.exam-name-input {
  width: 100%;
  padding: var(--space-2) 0 var(--space-3);
  border: 0;
  border-bottom: 1px solid var(--hairline);
  border-radius: 0;
  background: transparent;
  font-family: var(--font-display);
  font-size: var(--text-xl);
  font-weight: 450;
  font-variation-settings: "SOFT" 100, "opsz" 72;
  text-align: center;
  transition: border-color 200ms var(--ease-out);
}

.exam-name-input::placeholder {
  color: var(--text-muted);
  opacity: 1;
}

.exam-name-input:focus-visible {
  outline: none;
  border-bottom-color: var(--focus-ring);
  box-shadow: 0 1px 0 var(--focus-ring);
}

.duration {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: var(--space-4) var(--space-7);
  min-inline-size: 0;
  padding: var(--space-2) 0;
  border: 0;
}

.stepper {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.stepper__field {
  display: flex;
  align-items: baseline;
  justify-content: center;
  min-width: clamp(4.75rem, 14vw, 6.25rem);
}

.stepper__input {
  width: 1.3em;
  padding: 0;
  border: 0;
  border-radius: 0.5rem;
  background: transparent;
  font-family: var(--font-display);
  font-size: var(--text-display);
  font-weight: 380;
  font-variation-settings: "SOFT" 100, "WONK" 0, "opsz" 144;
  font-variant-numeric: tabular-nums lining-nums;
  line-height: 1;
  text-align: center;
  caret-color: var(--orchid);
}

@supports (field-sizing: content) {
  .stepper__input {
    width: auto;
    min-width: 1ch;
    field-sizing: content;
  }
}

.stepper__unit {
  margin-left: 0.1em;
  color: var(--text-muted);
  font-family: var(--font-display);
  font-size: var(--text-lg);
  font-variation-settings: "SOFT" 100, "opsz" 36;
}

.stepper__button {
  display: grid;
  place-items: center;
  width: 2.5rem;
  height: 2.5rem;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: var(--glass-tint-strong);
  box-shadow:
    inset 0 1px 0 rgb(255 255 255 / 0.55),
    inset 0 -1px 0 rgb(20 11 46 / 0.06),
    0 0.25rem 0.75rem -0.25rem rgb(20 11 46 / 0.25);
  transition:
    transform 180ms var(--ease-spring),
    background-color 180ms var(--ease-out);
}

.stepper__button:hover {
  background: rgb(255 255 255 / 0.62);
}

[data-theme="dark"] .stepper__button:hover {
  background: rgb(255 255 255 / 0.22);
}

.stepper__button:active {
  transform: scale(0.88);
}

.stepper__button svg {
  width: 1rem;
  height: 1rem;
  stroke-width: 2;
}

/* ---------- Running ---------- */

.view--running {
  gap: var(--space-3);
}

.exam-title {
  max-width: 28ch;
  font-family: var(--font-display);
  font-size: var(--text-lg);
  font-weight: 500;
  font-variation-settings: "SOFT" 100, "opsz" 36;
  line-height: 1.25;
  overflow-wrap: anywhere;
}

.countdown {
  font-family: var(--font-display);
  font-size: var(--text-countdown);
  font-weight: 330;
  font-variation-settings: "SOFT" 100, "WONK" 0, "opsz" 144;
  font-variant-numeric: tabular-nums lining-nums;
  line-height: 1;
  letter-spacing: -0.03em;
  white-space: nowrap;
}

/* Seconds only appear in the final ten minutes, set smaller so H:MM stays dominant. */
.countdown__seconds {
  font-size: 0.36em;
  letter-spacing: 0;
  color: var(--text-muted);
}

.schedule {
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

/* ---------- Finished ---------- */

.finished-heading {
  font-family: var(--font-display);
  font-size: var(--text-display);
  font-weight: 400;
  font-variation-settings: "SOFT" 100, "WONK" 1, "opsz" 144;
  line-height: 1;
  letter-spacing: -0.02em;
}

.summary {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(7rem, 1fr));
  gap: var(--space-4) var(--space-3);
  width: 100%;
  margin-block: var(--space-2);
  padding-block: var(--space-4);
  border-block: 1px solid var(--hairline);
}

.summary div {
  display: grid;
  align-content: start;
  gap: var(--space-1);
}

.summary dt {
  color: var(--text-muted);
  font-size: var(--text-sm);
}

.summary dd {
  font-family: var(--font-display);
  font-size: clamp(1.125rem, 1rem + 0.5vw, 1.25rem);
  font-variation-settings: "SOFT" 100, "opsz" 36;
  font-variant-numeric: tabular-nums lining-nums;
  white-space: nowrap;
}

/* ---------- Hold to end ---------- */

.hold-button {
  overflow: hidden;
  min-height: 3.25rem;
  padding: var(--space-3) var(--space-6);
  border: 0;
  border-radius: var(--radius-pill);
  font-weight: 600;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  transition:
    transform 200ms var(--ease-spring),
    --light-angle 700ms var(--ease-out);
}

.hold-button.is-holding {
  transform: scale(0.97);
}

.hold-button__label {
  position: relative;
}

/* Liquid that rises while the button is held, with a drifting wave on top. */
.hold-button__fill {
  position: absolute;
  inset: 0;
  background: var(--hold-fill);
  transform: translateY(calc(100% + 0.5rem));
  transition: transform 350ms var(--ease-out);
}

.hold-button__fill::before {
  --wave: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 40 8' preserveAspectRatio='none'%3E%3Cpath d='M0 8V4c5 0 5-3 10-3s5 3 10 3 5-3 10-3 5 3 10 3v4z'/%3E%3C/svg%3E");

  content: "";
  position: absolute;
  bottom: 100%;
  left: 0;
  width: 100%;
  height: 0.5rem;
  background: var(--hold-fill);
  -webkit-mask: var(--wave) 0 100% / 2.5rem 100% repeat-x;
  mask: var(--wave) 0 100% / 2.5rem 100% repeat-x;
  animation: wave-drift 900ms linear infinite;
}

.hold-button.is-holding .hold-button__fill {
  transform: translateY(0);
  transition: transform var(--hold-duration, 1000ms) cubic-bezier(0.45, 0, 0.55, 1);
}

/* ---------- Warning toast ---------- */

.toast {
  position: absolute;
  bottom: calc(100% + var(--space-4));
  left: 50%;
  padding: var(--space-3) var(--space-5);
  border-radius: var(--radius-pill);
  font-weight: 600;
  white-space: nowrap;
  opacity: 0;
  visibility: hidden;
  translate: -50% 0.75rem;
  transition:
    opacity 300ms var(--ease-out),
    translate 500ms var(--ease-spring),
    visibility 0s linear 300ms,
    --light-angle 700ms var(--ease-out);
}

.toast.is-visible {
  opacity: 1;
  visibility: visible;
  translate: -50% 0;
  transition-delay: 0s;
}

/* ---------- Animations ---------- */

@keyframes lens-condense {
  from {
    opacity: 0;
    transform: scale(0.94) translateY(0.75rem);
  }
}

@keyframes view-in {
  from {
    opacity: 0;
    transform: translateY(0.375rem);
  }
}

@keyframes lens-glow {
  0%,
  100% {
    box-shadow: var(--glass-shadow);
  }

  25%,
  65% {
    box-shadow:
      var(--glass-shadow),
      0 0 0 1px rgb(242 184 75 / 0.9),
      0 0 2.5rem rgb(242 184 75 / 0.55),
      0 0 6rem rgb(224 54 155 / 0.4);
  }

  45% {
    box-shadow:
      var(--glass-shadow),
      0 0 0 1px rgb(242 184 75 / 0.5),
      0 0 1.5rem rgb(242 184 75 / 0.3),
      0 0 4rem rgb(224 54 155 / 0.2);
  }
}

@keyframes wave-drift {
  to {
    -webkit-mask-position: 2.5rem 100%;
    mask-position: 2.5rem 100%;
  }
}

@media (prefers-reduced-motion: reduce) {
  .lens,
  .view {
    animation: none;
  }

  .lens.is-glowing {
    animation: lens-glow 2600ms var(--ease-out);
  }

  .chip,
  .hold-button,
  .button,
  .stepper__button {
    transition: none;
  }

  .hold-button__fill::before {
    animation: none;
  }

  .toast {
    translate: -50% 0;
    transition:
      opacity 200ms linear,
      visibility 0s linear 200ms;
  }
}
