@layer tokens, base, ui, shell, surface;
@layer base {
  /* ============================================================================
     Base: reset + primitives. No component or layout rules here.
     ========================================================================== */

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

  * {
    margin: 0;
  }

  html,
  body {
    height: 100%;
  }

  body {
    font-family: var(--font-sans);
    font-size: var(--text-md);
    font-weight: var(--weight-regular);
    line-height: var(--leading-normal);
    color: var(--color-ink);
    background: var(--grad-desk) fixed;
    background-color: var(--color-bg);
    -webkit-font-smoothing: antialiased;
    overflow: hidden; /* single page app: the canvas owns scroll/pan */
    overscroll-behavior: none; /* no browser back/forward swipe while panning */
  }

  h1,
  h2,
  h3 {
    font-weight: var(--weight-semibold);
    line-height: var(--leading-tight);
  }

  h1,
  h2 {
    font-family: var(--font-display);
  }

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

  p {
    line-height: var(--leading-normal);
  }

  /* Scrollbars: thin, trackless, faint thumb that firms up on hover. WebKit/Blink
     use the pseudo-elements (a non-auto scrollbar-width/color on an element would
     switch Blink to the standard path and drop these); Firefox gets the standard
     properties. Elements that hide their scrollbar keep scrollbar-width: none. */
  ::-webkit-scrollbar {
    width: 8px;
    height: 8px;
  }
  ::-webkit-scrollbar-track,
  ::-webkit-scrollbar-corner {
    background: transparent;
  }
  ::-webkit-scrollbar-thumb {
    background: color-mix(in srgb, var(--color-ink) 16%, transparent);
    background-clip: padding-box;
    border: 2px solid transparent;
    border-radius: var(--radius-pill);
  }
  ::-webkit-scrollbar-thumb:hover {
    background-color: color-mix(in srgb, var(--color-ink) 32%, transparent);
  }
  @supports not selector(::-webkit-scrollbar) {
    * {
      scrollbar-width: thin;
      scrollbar-color: color-mix(in srgb, var(--color-ink) 18%, transparent) transparent;
    }
  }

  button {
    font: inherit;
    color: inherit;
    background: none;
    border: none;
    padding: 0;
    cursor: pointer;
  }

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

  /* iOS Safari zooms the whole page when a text control smaller than 16px
     gains focus. Coarse pointers get a hard 16px floor on entry controls.
     (!important is deliberate: it must beat per-component font sizes set in
     later stylesheets.) Checkbox/radio/range don't open the keyboard.
     In-place editors that must match the text they replace (the canvas text
     editor sizes itself from the item at any zoom) opt out: `.cv-editor`, or
     `data-native-size` on any other such control. */
  @media (hover: none), (pointer: coarse) {
    input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="button"]):not(
      [type="submit"]
    ):not([type="color"]):not([data-native-size]),
    textarea:not(.cv-editor):not([data-native-size]),
    select,
    [contenteditable="true"]:not([data-native-size]) {
      font-size: var(--type-16) !important;
    }
  }

  /* ---- touch feel (docs/archive/mobile-app.md §5.1 P10) ----------------------------
     No grey flash on tap anywhere; shell chrome is controls, not text, so a
     long-press neither selects it nor opens the iOS callout. */
  html {
    -webkit-tap-highlight-color: transparent;
  }

  .os-bar,
  .os-window__header,
  .os-launcher-menu,
  .btn,
  .icon-btn,
  [role="tab"],
  [role="menuitem"],
  [role="toolbar"] {
    -webkit-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
  }

  /* A finger needs 44px. Component sheets size their own controls; this floor
     is !important so it holds whatever loads after it. min-* only: a control
     already larger keeps its size, and inline layout is untouched. Phones only
     (`:root[data-form="phone"]`, ui/device.js): touch laptops and tablets on the desktop
     layout keep its dense controls. */
  @media (pointer: coarse) {
    :root[data-form="phone"]
      :is(
        .btn,
        .icon-btn,
        .os-window__action,
        .os-bar__button,
        [role="tab"],
        [role="menuitem"]
      ) {
      min-height: var(--touch-target) !important;
    }

    :root[data-form="phone"] :is(.icon-btn, .os-window__action, .os-bar__button) {
      min-width: var(--touch-target) !important;
    }
  }

  a {
    color: inherit;
  }

  svg {
    display: block;
    flex-shrink: 0;
  }

  :focus-visible {
    outline: var(--focus-outline);
    outline-offset: var(--focus-offset);
  }

  ::placeholder {
    color: var(--color-ink-faint);
  }

  ::selection {
    background: var(--color-wash);
    color: inherit;
  }

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

  /* ---- Every theme ------------------------------------------------------------ */

  /* Icons take the theme's stroke; zero specificity so a component's own stroke wins. */
  :where(svg[data-icon]) {
    stroke-width: var(--icon-stroke);
    stroke-linecap: var(--icon-cap);
    stroke-linejoin: var(--icon-join);
  }

  /* Millennium's icons are colourful and two-tone: a colour per family, a soft fill in the outline's
     closed shape. Painted strips and the taskbar keep white icons. */
}
