/* ============================================================
   BASE STYLES
   ============================================================ */

@layer base {

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

  html {
    /* Smooth scrolling respects prefers-reduced-motion */
    scroll-behavior: smooth;
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
    /* Better font rendering on mobile */
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
  }

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

  body {
    font-family: var(--font-body);
    font-size: 1rem;
    line-height: 1.6;
    color: var(--text-primary);
    background-color: var(--bg-page);
    min-block-size: 100dvh;
    overflow-x: hidden;
    /* Xiaomi 13T: 393px – use dvh for dynamic viewport */
    padding-bottom: calc(var(--sp-8) + var(--safe-bottom));
  }

  /* Focus styles – accessible, not ugly */
  :focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 3px;
    border-radius: var(--r-sm);
  }

  /* Interactive elements */
  button, a {
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
  }

  button {
    cursor: pointer;
    border: none;
    background: none;
    font-family: inherit;
  }

  a {
    color: var(--link);
    text-decoration: underline;
    text-underline-offset: 3px;
    text-decoration-color: oklch(from var(--link) l c h / 0.4);
    transition: color var(--duration-fast) var(--ease-in-out),
                text-decoration-color var(--duration-fast) var(--ease-in-out);
  }

  a:hover {
    color: var(--link-hover);
    text-decoration-color: var(--link-hover);
  }

  /* Typography scale */
  h1, h2, h3, h4, h5, h6 {
    font-family: var(--font-display);
    line-height: 1.2;
    font-weight: 600;
    color: var(--text-primary);
  }

  p { max-inline-size: 70ch; }

  /* Dialog reset */
  dialog {
    border: none;
    padding: 0;
    background: transparent;
    max-inline-size: 100%;
    max-block-size: 100%;
  }

  dialog::backdrop {
    background: oklch(10% 0.01 80 / 0);
    transition: background var(--duration-modal) var(--ease-in-out);
  }

  dialog[open]::backdrop {
    background: oklch(10% 0.01 80 / 0.6);
  }

  /* Scrollbar – minimal, matches palette */
  ::-webkit-scrollbar { width: 4px; height: 4px; }
  ::-webkit-scrollbar-track { background: transparent; }
  ::-webkit-scrollbar-thumb {
    background: var(--stone-300);
    border-radius: var(--r-pill);
  }
  ::-webkit-scrollbar-thumb:hover { background: var(--stone-400); }

  /* Selection */
  ::selection {
    background: var(--terra-200);
    color: var(--terra-800);
  }

  img {
    max-inline-size: 100%;
    block-size: auto;
    display: block;
  }

    picture {
      display: contents;
    }

  /* Reduced data mode – skip decorative images */
  @media (prefers-reduced-data: reduce) {
    .decorative-img { display: none; }
  }
}
