/*
  Base styles and the hooks Blazor itself renders (the error bar, error boundaries, form validation, the reconnect
  dialog). The shell is in css/shell.css and the components in css/components.css; all colours come from
  css/tokens.css.
*/
*,
*::before,
*::after {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--f-body);
  font-size: var(--fs-body);
  line-height: var(--lh-body);
}

h1,
h2,
h3 {
  margin: 0;
  font-family: var(--f-display);
  font-weight: 600;
  letter-spacing: .005em;
  text-wrap: balance;
}

h1 {
  font-size: var(--fs-h1);
  line-height: 1.15;
}

h2 {
  font-size: var(--fs-h2);
}

h3 {
  font-size: var(--fs-h3);
}

p {
  margin: 0;
}

a {
  color: var(--accent);
  text-underline-offset: 2px;
}

button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

/* The heading receives focus after each navigation (FocusOnNavigate) so screen readers announce the page; a ring
   around it would only confuse sighted users. */
h1:focus,
h1:focus-visible {
  outline: none;
}

.num {
  font-variant-numeric: tabular-nums;
}

.mono {
  font-family: var(--f-mono);
  font-size: var(--fs-small);
}

/* Visually hidden, still read aloud. */
.sr {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* Blazor's error bar: shown by Blazor (display: block) when a circuit fails. */
#blazor-error-ui {
  display: none;
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 1000;
  padding: 10px max(var(--gutter), env(safe-area-inset-right, 0px)) calc(10px + env(safe-area-inset-bottom, 0px)) max(var(--gutter), env(safe-area-inset-left, 0px));
  background: var(--bad-soft);
  color: var(--fg);
  border-top: 4px solid var(--bad);
  font-size: var(--fs-sub);
}

#blazor-error-ui .reload {
  margin-left: 8px;
  font-weight: 600;
}

#blazor-error-ui .dismiss {
  position: absolute;
  right: max(var(--gutter), env(safe-area-inset-right, 0px));
  top: 8px;
  cursor: pointer;
  border: 0;
  background: none;
  font-size: 18px;
  line-height: 1;
  color: var(--muted);
}

/* An error boundary without its own error content (the layout gives the page one). */
.blazor-error-boundary {
  padding: 12px 16px;
  border-radius: var(--r);
  border-left: 4px solid var(--bad);
  background: var(--bad-soft);
  color: var(--fg);
}

/* Form validation from Blazor's input components. */
.invalid {
  outline: 1px solid var(--bad);
}

.validation-message {
  color: var(--bad);
  font-size: var(--fs-small);
}

/* The reconnect dialog (Components/Layout/ReconnectModal.razor). Blazor sets the state classes on the dialog. The
   id in every selector keeps these rules above component classes such as .btn, whatever the order of the sheets. */
#components-reconnect-modal .components-reconnect-first-attempt-visible,
#components-reconnect-modal .components-reconnect-repeated-attempt-visible,
#components-reconnect-modal .components-reconnect-failed-visible,
#components-reconnect-modal .components-pause-visible,
#components-reconnect-modal .components-resume-failed-visible,
#components-reconnect-modal .components-rejoining-animation {
  display: none;
}

#components-reconnect-modal.components-reconnect-show .components-reconnect-first-attempt-visible,
#components-reconnect-modal.components-reconnect-show .components-rejoining-animation,
#components-reconnect-modal.components-reconnect-paused .components-pause-visible,
#components-reconnect-modal.components-reconnect-resume-failed .components-resume-failed-visible,
#components-reconnect-modal.components-reconnect-retrying,
#components-reconnect-modal.components-reconnect-retrying .components-reconnect-repeated-attempt-visible,
#components-reconnect-modal.components-reconnect-retrying .components-rejoining-animation,
#components-reconnect-modal.components-reconnect-failed,
#components-reconnect-modal.components-reconnect-failed .components-reconnect-failed-visible {
  display: block;
}

#components-reconnect-modal {
  width: min(22rem, calc(100vw - 2 * var(--gutter)));
  margin: 20vh auto;
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: var(--r-sheet);
  background: var(--surface);
  color: var(--fg);
  box-shadow: var(--shadow-sheet);
}

#components-reconnect-modal::backdrop {
  background: var(--scrim);
}

#components-reconnect-modal p {
  margin: 0;
  text-align: center;
}

.components-reconnect-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
}

.components-rejoining-animation {
  position: relative;
  width: 64px;
  height: 64px;
}

.components-rejoining-animation div {
  position: absolute;
  border: 3px solid var(--accent);
  border-radius: 50%;
  animation: components-rejoining 1.5s cubic-bezier(0, .2, .8, 1) infinite;
}

.components-rejoining-animation div:nth-child(2) {
  animation-delay: -.5s;
}

@keyframes components-rejoining {
  0%,
  4.9% {
    top: 32px;
    left: 32px;
    width: 0;
    height: 0;
    opacity: 0;
  }

  5% {
    top: 32px;
    left: 32px;
    width: 0;
    height: 0;
    opacity: 1;
  }

  100% {
    top: 0;
    left: 0;
    width: 64px;
    height: 64px;
    opacity: 0;
  }
}

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