/* Toast (a floating layer, so it carries the shadow) and the dot loader. */

.toaster {
  position: fixed;
  right: var(--s-6);
  bottom: var(--s-6);
  z-index: 50;
  display: grid;
  gap: var(--s-2);
  width: min(360px, calc(100vw - 2 * var(--s-4)));
  pointer-events: none;
}

.toast {
  --edge: var(--text-2);
  --toast-life: 4s;
  position: relative;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: var(--s-1) var(--s-3);
  align-items: start;
  padding: var(--s-3) var(--s-2) var(--s-3) var(--s-4);
  border-radius: var(--r-panel);
  background: var(--surface);
  box-shadow: inset 2px 0 0 var(--edge), var(--shadow-float);
  pointer-events: auto;
  animation: toast-in var(--d-enter) var(--ease-enter) backwards;
}

.toast--ok { --edge: var(--ok); }
.toast--warn { --edge: var(--warn); }
.toast--bad { --edge: var(--bad); }

.toast__label {
  font-size: var(--fs-12);
  font-weight: 600;
  line-height: 1.5;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--edge);
}

.toast__text {
  grid-column: 1;
  font-size: var(--fs-15);
  line-height: 1.45;
}

.toast__close {
  grid-column: 2;
  grid-row: 1 / span 2;
  width: 32px;
  height: 32px;
  min-width: 0;
  padding: 0;
  color: var(--text-2);
}

.toast__timer {
  grid-column: 1 / -1;
  display: flex;
  gap: var(--dot-gap-timer);
  padding-top: var(--s-1);
}

.toast__timer span {
  width: 3px;
  height: 3px;
  border-radius: 50%;
  background: var(--edge);
  animation: timer-dot var(--d-hover) linear forwards;
  animation-delay: calc(var(--toast-life) * (var(--i) + 1) / 12 - var(--d-hover));
}

.toast:hover .toast__timer span,
.toast:focus-within .toast__timer span,
.toast.is-held .toast__timer span {
  animation-play-state: paused;
}

.toast.is-leaving {
  animation: toast-out var(--d-hover) var(--ease-state) forwards;
}

@keyframes timer-dot {
  to { opacity: .2; }
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
}

@keyframes toast-out {
  to { opacity: 0; }
}

/* Loader: a straight port of the Uiverse ring by MikeAndrewDesigner
   (assets/reference/uiverse/loader-ring). A 45%-radius ring, one side in --accent, turning once
   every 0.7s. The colours, the size token and the names differ from the source, and the ring is a
   little thicker at the owner's request: whole pixels (3px at 35px, 2px at 20px), because browsers
   round border widths down to device pixels and a fractional width showed no change on 1x screens.
   Content-box like the source; the outside size stays --loader-size.
   e2e/tests/loader.spec.js compares it frame by frame with the reference file. */
.loader {
  --loader-size: 35px;
  --loader-ring: 3px;
  --loader-speed: .7s;
  position: relative;
  display: inline-block;
  flex: none;
  box-sizing: content-box;
  width: calc(var(--loader-size) - 2 * var(--loader-ring));
  height: calc(var(--loader-size) - 2 * var(--loader-ring));
  border: var(--loader-ring) solid var(--line-strong);
  border-left-color: var(--accent);
  border-radius: 45%;
  animation: loader-spin var(--loader-speed) linear infinite;
}

.loader--small {
  --loader-size: 20px;
  --loader-ring: 2px;
}

@keyframes loader-spin {
  to { transform: rotate(360deg); }
}

/* Reduced motion: the ring stays still and fades in and out. */
@keyframes loader-fade {
  0%, 100% { opacity: 1; }
  50% { opacity: .35; }
}

@media (max-width: 599px) {
  .toaster {
    right: var(--s-4);
    left: var(--s-4);
    bottom: var(--s-4);
    width: auto;
  }
}

@media (prefers-reduced-motion: reduce) {
  .toast {
    animation-name: fade-in;
  }

  .loader {
    animation: loader-fade calc(var(--loader-speed) * 2) ease-in-out infinite;
  }
}
