/* Reset + base layers. Owned by the design system (D1). Tokens live in
   tokens.css, which also declares the layer order. */

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

  html {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
    tab-size: 4;
    -webkit-tap-highlight-color: transparent;
  }

  body,
  h1,
  h2,
  h3,
  h4,
  h5,
  h6,
  p,
  figure,
  blockquote,
  dl,
  dd,
  pre {
    margin: 0;
  }

  ul,
  ol {
    margin: 0;
    padding: 0;
  }

  ul[role='list'],
  ol[role='list'] {
    list-style: none;
  }

  img,
  picture,
  video,
  canvas {
    display: block;
    max-width: 100%;
  }

  svg {
    flex: none;
  }

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

  button {
    padding: 0;
    border: 0;
    background: none;
    cursor: pointer;
    text-align: inherit;
  }

  button:disabled,
  [aria-disabled='true'] {
    cursor: not-allowed;
  }

  a {
    color: inherit;
    text-decoration: none;
  }

  table {
    border-collapse: collapse;
    border-spacing: 0;
  }

  hr {
    border: 0;
    margin: 0;
  }

  [hidden] {
    display: none !important;
  }

  textarea {
    resize: vertical;
  }

  summary {
    cursor: pointer;
  }
}

@layer base {
  html {
    height: 100%;
    color-scheme: dark;
    scrollbar-color: var(--border-strong) transparent;
    scrollbar-width: thin;
    background-color: var(--bg-0);
  }

  body {
    min-height: 100%;
    min-height: 100dvh;
    font-family: var(--font-body);
    font-size: var(--fs-md);
    line-height: var(--lh);
    color: var(--text);
    background-color: var(--bg-0);
    /* Deep space: a cool nebula behind the globe and a faint accent halo. */
    background-image:
      radial-gradient(1100px 720px at 72% 36%, color-mix(in oklab, var(--bg-2) 92%, var(--accent-2)) 0%, transparent 62%),
      radial-gradient(900px 640px at 8% 96%, color-mix(in oklab, var(--bg-1) 84%, var(--accent)) 0%, transparent 60%),
      radial-gradient(circle at 50% 50%, var(--bg-1) 0%, var(--bg-0) 78%);
    background-attachment: fixed;
    background-repeat: no-repeat;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
  }

  h1,
  h2,
  h3,
  h4,
  h5,
  h6 {
    font-family: var(--font-display);
    font-weight: 600;
    line-height: var(--lh-tight);
    letter-spacing: 0.01em;
    text-wrap: balance;
  }

  h1 { font-size: var(--fs-3xl); }
  h2 { font-size: var(--fs-xl); }
  h3 { font-size: var(--fs-lg); }
  h4 { font-size: var(--fs-md); }

  p {
    text-wrap: pretty;
  }

  a:not([class]) {
    color: var(--accent);
    text-underline-offset: 3px;
  }

  a:not([class]):hover {
    text-decoration: underline;
  }

  code,
  kbd,
  samp,
  pre {
    font-family: var(--font-mono);
    font-size: 0.92em;
  }

  ::selection {
    background: color-mix(in oklab, var(--accent) 38%, transparent);
    color: var(--text);
  }

  ::placeholder {
    color: var(--text-mute);
    opacity: 1;
  }

  /* Visible keyboard focus everywhere; pointer users do not see it. */
  :focus {
    outline: none;
  }

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

  :is(input, textarea, select):focus-visible {
    outline-offset: 0;
  }

  html.is-scroll-locked,
  html.is-scroll-locked body {
    overflow: hidden;
  }

  /* Slim themed scrollbars (WebKit; Firefox uses scrollbar-color above). */
  ::-webkit-scrollbar {
    width: 10px;
    height: 10px;
  }

  ::-webkit-scrollbar-track {
    background: transparent;
  }

  ::-webkit-scrollbar-thumb {
    background: var(--border-strong);
    border: 3px solid transparent;
    border-radius: var(--radius-pill);
    background-clip: content-box;
  }

  ::-webkit-scrollbar-thumb:hover {
    background: var(--text-mute);
    background-clip: content-box;
    border: 3px solid transparent;
  }

  /* ----------------------------------------------------------- utilities */

  .u-truncate {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    min-width: 0;
  }

  .u-clamp-2 {
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    overflow: hidden;
  }

  .u-scroll {
    overflow: auto;
    overscroll-behavior: contain;
    scrollbar-width: thin;
    scrollbar-color: var(--border-strong) transparent;
  }

  /* Visually hidden but available to assistive technology. */
  .u-sr {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
    border: 0;
  }

  .u-mono {
    font-family: var(--font-mono);
    font-variant-numeric: tabular-nums;
  }

  /* HUD micro-label: display font, uppercase, wide tracking. */
  .u-label {
    font-family: var(--font-display);
    font-size: var(--fs-xs);
    font-weight: 600;
    letter-spacing: var(--tracking-wide);
    text-transform: uppercase;
    color: var(--text-dim);
  }

  .u-dim { color: var(--text-dim); }
  .u-mute { color: var(--text-mute); }
  .u-accent { color: var(--accent); }

  /* ------------------------------------------------ view transitions */
  /* Only #view animates (tokens.css names it); the root keeps rendering. */

  ::view-transition-old(view) {
    animation: base-view-out var(--dur-2) var(--ease-in-out) both;
  }

  ::view-transition-new(view) {
    animation: base-view-in var(--dur-3) var(--ease-out) both;
  }

  @keyframes base-view-out {
    to {
      opacity: 0;
      transform: translateY(-6px);
    }
  }

  @keyframes base-view-in {
    from {
      opacity: 0;
      transform: translateY(10px);
    }
  }

  @media (prefers-reduced-motion: reduce) {
    html {
      scroll-behavior: auto;
    }

    ::view-transition-old(view),
    ::view-transition-new(view) {
      animation: none;
    }
  }

  :root[data-reduce-motion] {
    scroll-behavior: auto;
  }

  :root[data-reduce-motion]::view-transition-old(view),
  :root[data-reduce-motion]::view-transition-new(view) {
    animation: none;
  }
}
