@layer design.base, design.components;

@layer design.base {
  *,
  *::before,
  *::after {
    box-sizing: border-box;
  }

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

  body {
    margin: 0;
    background: var(--canvas);
    color: var(--ink);
    font: var(--weight-regular) var(--text-md) / var(--leading) var(--font);
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
  }

  h1,
  h2,
  h3,
  h4 {
    margin: 0;
    line-height: var(--leading-tight);
    letter-spacing: -0.015em;
    text-wrap: balance;
  }

  h1 {
    font-size: var(--text-3xl);
    font-weight: var(--weight-display);
    letter-spacing: -0.03em;
  }

  h2 {
    font-size: var(--text-xl);
    font-weight: var(--weight-strong);
  }

  h3 {
    font-size: var(--text-lg);
    font-weight: var(--weight-strong);
  }

  h4 {
    font-size: var(--text-md);
    font-weight: var(--weight-strong);
  }

  p {
    margin: 0;
    text-wrap: pretty;
  }

  small {
    font-size: var(--text-sm);
  }

  a {
    color: var(--accent-strong);
    text-underline-offset: 0.18em;
    text-decoration-thickness: 1px;
  }

  a:hover {
    color: var(--ink);
  }

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

  img,
  svg {
    max-width: 100%;
  }

  [hidden] {
    display: none !important;
  }

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

@layer design.components {
  .muted {
    color: var(--muted);
  }

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

  .sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
  }

  .brand {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    color: var(--ink);
    font-size: var(--text-xl);
    font-weight: var(--weight-display);
    letter-spacing: -0.035em;
    text-decoration: none;
    line-height: 1;
  }

  .brand:hover {
    color: var(--ink);
  }

  .brand-mark {
    width: 22px;
    height: 22px;
    flex: none;
  }

  button,
  .button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    min-height: 38px;
    padding: 0 var(--space-4);
    border: 1px solid var(--line-strong);
    border-radius: var(--radius-sm);
    background: var(--canvas);
    color: var(--ink);
    font: var(--weight-strong) var(--text-sm) / 1 var(--font);
    text-decoration: none;
    white-space: nowrap;
    cursor: pointer;
    transition: background-color 120ms, border-color 120ms, color 120ms;
  }

  button:hover,
  .button:hover {
    border-color: var(--ink);
    color: var(--ink);
  }

  button:disabled,
  .button[aria-disabled="true"] {
    opacity: 0.45;
    cursor: not-allowed;
  }

  button.primary,
  .button.primary {
    border-color: var(--accent);
    background: var(--accent);
    color: var(--on-accent);
  }

  button.primary:hover,
  .button.primary:hover {
    border-color: var(--accent-strong);
    background: var(--accent-strong);
    color: var(--on-accent);
  }

  button.quiet,
  .button.quiet {
    border-color: transparent;
    background: transparent;
    padding: 0 var(--space-2);
  }

  button.quiet:hover,
  .button.quiet:hover {
    background: var(--sunken);
  }

  button.danger,
  .button.danger {
    border-color: color-mix(in srgb, var(--bad) 45%, transparent);
    color: var(--bad);
  }

  button.danger:hover,
  .button.danger:hover {
    border-color: var(--bad);
    background: var(--bad-bg);
    color: var(--bad);
  }

  button.small,
  .button.small {
    min-height: 30px;
    padding: 0 var(--space-3);
    font-size: var(--text-xs);
  }

  label {
    font-size: var(--text-sm);
    font-weight: var(--weight-strong);
  }

  input:not([type="checkbox"], [type="radio"], [type="range"]),
  select,
  textarea {
    width: 100%;
    min-height: 38px;
    padding: var(--space-2) var(--space-3);
    border: 1px solid var(--line-strong);
    border-radius: var(--radius-sm);
    background: var(--canvas);
    color: var(--ink);
    font: var(--weight-regular) var(--text-md) / var(--leading-snug) var(--font);
  }

  input::placeholder,
  textarea::placeholder {
    color: var(--muted);
  }

  input:focus-visible,
  select:focus-visible,
  textarea:focus-visible {
    outline: none;
    border-color: var(--accent);
    box-shadow: var(--focus-ring);
  }

  input[type="checkbox"],
  input[type="radio"] {
    accent-color: var(--accent);
    width: 16px;
    height: 16px;
    margin: 0;
  }

  .field {
    display: grid;
    gap: var(--space-1);
  }

  .panel {
    border: 1px solid var(--line);
    border-radius: var(--radius-md);
    background: var(--canvas);
    padding: var(--space-5);
  }

  .badge {
    display: inline-flex;
    align-items: center;
    gap: var(--space-1);
    min-height: 22px;
    padding: 0 var(--space-2);
    border-radius: var(--radius-full);
    background: var(--sunken);
    color: var(--muted);
    font-size: var(--text-xs);
    font-weight: var(--weight-strong);
    line-height: 1;
    white-space: nowrap;
  }

  .badge.ok {
    background: var(--ok-bg);
    color: var(--ok);
  }

  .badge.warn {
    background: var(--warn-bg);
    color: var(--warn);
  }

  .badge.bad {
    background: var(--bad-bg);
    color: var(--bad);
  }

  .badge.info {
    background: var(--info-bg);
    color: var(--info);
  }

  .badge.accent {
    background: var(--accent-soft);
    color: var(--accent-strong);
  }

  .notice {
    padding: var(--space-3) var(--space-4);
    border-radius: var(--radius-sm);
    background: var(--sunken);
    color: var(--ink);
    font-size: var(--text-sm);
  }

  .notice.ok {
    background: var(--ok-bg);
  }

  .notice.warn {
    background: var(--warn-bg);
  }

  .notice.bad {
    background: var(--bad-bg);
  }

  .notice.info {
    background: var(--info-bg);
  }

  table.data {
    width: 100%;
    border-collapse: collapse;
    font-size: var(--text-sm);
    font-variant-numeric: tabular-nums;
  }

  table.data th,
  table.data td {
    padding: var(--space-2) var(--space-3);
    border-bottom: 1px solid var(--line);
    text-align: left;
    vertical-align: middle;
  }

  table.data th {
    color: var(--muted);
    font-size: var(--text-xs);
    font-weight: var(--weight-strong);
  }

  table.data td.num,
  table.data th.num {
    text-align: right;
  }

  .topbar {
    display: flex;
    align-items: center;
    gap: var(--space-6);
    min-height: 64px;
    padding: 0 var(--space-5);
    border-bottom: 1px solid var(--line);
    background: var(--canvas);
  }

  .topbar nav {
    display: flex;
    align-items: center;
    gap: var(--space-1);
  }

  .topbar nav a {
    padding: var(--space-2) var(--space-3);
    border-radius: var(--radius-sm);
    color: var(--muted);
    font-size: var(--text-sm);
    font-weight: var(--weight-strong);
    text-decoration: none;
  }

  .topbar nav a:hover {
    background: var(--sunken);
    color: var(--ink);
  }

  .topbar nav a[aria-current="page"] {
    color: var(--ink);
    background: var(--sunken);
  }

  dialog {
    width: min(480px, calc(100vw - 32px));
    padding: var(--space-5);
    border: 1px solid var(--line);
    border-radius: var(--radius-md);
    background: var(--canvas);
    color: var(--ink);
    box-shadow: var(--shadow-float);
  }

  dialog::backdrop {
    background: rgb(29 28 26 / 32%);
  }
}
