/* Element defaults on top of the reset (reset.css): the page's type and
   color, native form controls drawn as the admin's fields without a class,
   focus rings, links in running text. Components and helpers beat all of it
   (later layers). */
@layer base {
  html,
  body {
    overflow-x: clip;
  }

  /* Always keep the scrollbar's room, so a page that scrolls and one that
     doesn't are the same width: moving between them no longer shifts the
     layout sideways as the scrollbar comes and goes. */
  html {
    scrollbar-gutter: stable;
  }

  body {
    background-color: var(--surface);
    color: var(--foreground);
    -moz-osx-font-smoothing: grayscale;
    -webkit-font-smoothing: antialiased;
    -webkit-text-size-adjust: none;
    /* Inter's single-storey a and open digits, where it's installed. */
    font-feature-settings: "cv11", "ss01";
    font-size: var(--text-sm);
    interpolate-size: allow-keywords;
    line-height: var(--leading-sm);
    min-block-size: 100dvh;
  }

  p,
  li,
  h1,
  h2,
  h3,
  h4 {
    overflow-wrap: break-word;
  }

  a:not([class]) {
    color: var(--primary);
    text-decoration: underline;
    text-decoration-color: color-mix(in oklch, currentColor 40%, transparent);
    text-underline-offset: 2px;

    &:hover {
      text-decoration-color: currentColor;
    }
  }

  button,
  summary,
  [role="button"],
  label:has(input[type="checkbox"], input[type="radio"]) {
    cursor: pointer;
  }

  summary {
    list-style: none;

    &::-webkit-details-marker {
      display: none;
    }
  }

  :is(a, button, input, select, textarea, summary, [tabindex]):focus-visible {
    outline: var(--focus-ring);
    outline-offset: 2px;
  }

  :is(button, input, select, textarea):disabled {
    cursor: not-allowed;
    opacity: 0.5;
  }

  :is(a, button, input, select, textarea) {
    transition: 120ms ease-out;
    transition-property: background-color, border-color, box-shadow, color, outline-color;
    touch-action: manipulation;
  }

  /* Text-like controls, selects and textareas without a class: drawn as the
     kit's ui-input (shadcn's Input), so a control a view hasn't classed yet
     still matches the rest. */
  :where(input:not([type="checkbox"], [type="radio"], [type="range"], [type="color"], [type="file"], [type="hidden"], [type="submit"], [type="button"], [type="reset"], [type="image"])),
  :where(select),
  :where(textarea) {
    background-color: transparent;
    border: 1px solid var(--input);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-xs);
    color: var(--foreground);
    font-size: var(--text-sm);
    line-height: var(--leading-sm);
    max-inline-size: 100%;
    min-block-size: 2.25rem;
    padding: 0.25rem 0.75rem;

    &::placeholder {
      color: var(--muted-foreground);
      opacity: 1;
    }

    &:focus-visible {
      border-color: var(--ring);
      box-shadow: var(--ring-focus);
      outline: none;
    }

    &[aria-invalid="true"] {
      border-color: var(--destructive);
      box-shadow: var(--ring-invalid);
    }
  }

  :where(select:not([multiple], [size])) {
    appearance: none;
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3e%3cpath stroke='%239ca3af' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='M6 8l4 4 4-4'/%3e%3c/svg%3e");
    background-position: right var(--space-2) center;
    background-repeat: no-repeat;
    background-size: 1.25em 1.25em;
    padding-inline-end: 2.25rem;
  }

  :where(textarea) {
    field-sizing: content;
    min-block-size: 5lh;
  }

  :where(input[type="checkbox"], input[type="radio"], progress, input[type="range"]) {
    accent-color: var(--primary);
  }

  :where(input[type="checkbox"], input[type="radio"]) {
    block-size: 1rem;
    flex-shrink: 0;
    inline-size: 1rem;
    margin: 0;
  }

  :where(input[type="file"]) {
    font-size: var(--text-sm);

    &::file-selector-button {
      background: transparent;
      border: 1px solid var(--input);
      border-radius: var(--radius-md);
      color: var(--foreground);
      cursor: pointer;
      font-weight: var(--weight-medium);
      margin-inline-end: var(--space-3);
      padding: var(--space-1) var(--space-3);
    }
  }

  :where(fieldset) {
    border: 0;
    margin: 0;
    min-inline-size: 0;
    padding: 0;
  }

  kbd {
    background: var(--muted);
    border: 0;
    border-radius: var(--radius-sm);
    color: var(--muted-foreground);
    font-family: var(--font-mono);
    font-size: 0.75em;
    font-weight: var(--weight-medium);
    padding: 0 0.35em;
    white-space: nowrap;
  }

  code {
    font-size: 0.9em;
  }

  dialog {
    border: 0;
    padding: 0;
  }

  ::selection {
    background-color: color-mix(in oklch, var(--primary) 25%, transparent);
  }

  :where(ul, ol):where([role="list"]) {
    list-style: none;
    margin: 0;
    padding: 0;
  }

  video {
    max-inline-size: 100%;
  }

  @page {
    margin: 1in;
  }

  turbo-frame,
  turbo-cable-stream-source {
    display: contents;
  }

  .turbo-progress-bar {
    visibility: hidden;
  }

  [hidden] {
    display: none !important;
  }

  @media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
      animation-duration: 0.01ms !important;
      animation-iteration-count: 1 !important;
      scroll-behavior: auto !important;
      transition-duration: 0.01ms !important;
    }
  }

  @media screen and (-webkit-min-device-pixel-ratio: 0) and (min-resolution: 0.001dpcm) {
    * {
      scrollbar-color: var(--input) transparent;
      scrollbar-width: thin;
    }
  }
}
