:root,
:root[data-theme="paper"] {
  --theme-bg: #f4f1ea;
  --theme-fg: #141414;
  --theme-panel: #ffffff;
}

:root[data-theme="midnight"] {
  --theme-bg: #0b1026;
  --theme-fg: #f5d76e;
  --theme-panel: #161d3a;
}

:root[data-theme="postbox"] {
  --theme-bg: #fffaf0;
  --theme-fg: #c1121f;
  --theme-panel: #ffffff;
}

:root[data-theme="clay"] {
  --theme-bg: #c8553d;
  --theme-fg: #fff4e4;
  --theme-panel: #d66a52;
}

:root {
  --theme-muted: color-mix(in srgb, var(--theme-fg) 62%, var(--theme-panel));
}

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

html,
body {
  height: 100%;
}

body {
  display: grid;
  grid-template-rows: 1fr auto;
  margin: 0;
  overflow: hidden;
  background: var(--theme-panel);
  color: var(--theme-fg);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

.error {
  display: grid;
  align-content: center;
  justify-items: start;
  gap: 10px;
  width: 100%;
  max-width: 560px;
  margin: 0 auto;
  padding: 24px 16px;
}

.error__code {
  margin: 0;
  font-family: "Archivo Black", "Arial Black", sans-serif;
  font-size: clamp(72px, 22vw, 140px);
  line-height: 0.9;
  letter-spacing: -0.03em;
}

.error__title {
  margin: 0;
  font-size: clamp(26px, 6vw, 36px);
  font-weight: 600;
}

.error__detail {
  margin: 0;
  font-size: 16px;
  color: var(--theme-muted);
}

.error__host {
  font-family: ui-monospace, "SFMono-Regular", Menlo, monospace;
  color: var(--theme-fg);
}

.error__retry {
  margin-top: 18px;
  padding: 12px 22px;
  border: 2px solid var(--theme-fg);
  border-radius: 999px;
  background: var(--theme-fg);
  color: var(--theme-panel);
  font-size: 15px;
  font-weight: 600;
  text-decoration: none;
  transition: background-color 150ms ease, color 150ms ease;
}

.error__retry:hover,
.error__retry:focus-visible {
  background: transparent;
  color: var(--theme-fg);
}

.error__retry:focus-visible {
  outline: 2px solid var(--theme-fg);
  outline-offset: 3px;
}

.error__retry[aria-disabled="true"] {
  pointer-events: none;
  opacity: 0.6;
}

.error__hint {
  margin: 6px 0 0;
  font-family: ui-monospace, "SFMono-Regular", Menlo, monospace;
  font-size: 13px;
  color: var(--theme-muted);
  opacity: 0;
  transition: opacity 300ms ease;
}

.error__hint--visible {
  opacity: 1;
}

.error__dots::after {
  content: "";
  animation: dots 900ms steps(4, end) infinite;
}

@keyframes dots {
  0% { content: ""; }
  25% { content: "."; }
  50% { content: ".."; }
  75% { content: "..."; }
}

.error--glitch {
  animation: glitch 360ms steps(2, end) 2;
}

@keyframes glitch {
  0% { transform: translate(0, 0); filter: none; }
  25% { transform: translate(-6px, 2px) skewX(-6deg); filter: hue-rotate(90deg); }
  50% { transform: translate(5px, -3px); filter: invert(1); }
  75% { transform: translate(-3px, 1px) skewX(4deg); filter: none; }
  100% { transform: translate(0, 0); }
}

.legal {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px 20px;
  padding: 16px;
  font-size: 13px;
}

.legal__link {
  color: var(--theme-muted);
  text-underline-offset: 3px;
}

.legal__link:hover,
.legal__link:focus-visible {
  color: var(--theme-fg);
}

.arrival {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 8px;
  background: var(--theme-bg);
  color: var(--theme-fg);
  transform: translateX(100%);
}

.arrival--in {
  box-shadow: -24px 0 48px rgb(0 0 0 / 0.25);
  animation: arrive 650ms cubic-bezier(0.22, 1, 0.36, 1) forwards;
}

@keyframes arrive {
  from { transform: translateX(100%); }
  to { transform: translateX(0); }
}

.arrival__name {
  margin: 0;
  font-family: "Archivo Black", "Arial Black", sans-serif;
  font-size: clamp(96px, min(34vw, 56vh), 560px);
  letter-spacing: -0.03em;
  line-height: 0.9;
}

.arrival__url {
  margin: 0;
  font-family: ui-monospace, "SFMono-Regular", Menlo, monospace;
  font-size: 13px;
  opacity: 0.6;
}

@media (prefers-reduced-motion: reduce) {
  .error--glitch,
  .error__dots::after {
    animation: none;
  }

  .arrival--in {
    animation-duration: 1ms;
  }
}
