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

  html {
    -webkit-text-size-adjust: 100%;
    tab-size: 4;
    background-color: var(--c-navy-950);
    color: var(--c-ink-900);
    font-family: var(--f-main);
    font-size: 16px;
    line-height: var(--lh-body);
    font-feature-settings: "kern", "liga", "clig", "calt";
  }

  body {
    min-height: 100vh;
    min-height: 100svh;
    background-color: var(--c-navy-950);
    color: var(--c-ink-900);
    overflow-x: hidden;
    position: relative;
    display: flex;
    flex-direction: column;
  }

  #main {
    flex: 1 0 auto;
  }

  /* Typography rules */
  html[lang='fa'] {
    font-family: var(--f-fa);
    font-feature-settings: "kern", "liga", "calt";
    letter-spacing: 0 !important;
  }

  html[lang='fa'] * {
    letter-spacing: 0 !important;
  }

  html[lang='en'] {
    font-family: var(--f-en);
  }

  h1, h2, h3, h4, h5, h6 {
    color: var(--c-navy-900);
    font-weight: 600;
    line-height: var(--lh-head);
    text-wrap: balance;
  }

  html[lang='fa'] h1,
  html[lang='fa'] h2,
  html[lang='fa'] h3 {
    font-weight: 700;
    /* Extra bottom padding for descenders inside overflow masks */
    padding-block-end: 0.15em;
  }

  p {
    color: var(--c-ink-700);
    line-height: var(--lh-body);
    max-inline-size: 68ch;
    text-wrap: pretty;
  }

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

  img, svg, video, canvas {
    display: block;
    max-inline-size: 100%;
  }

  button, input, select, textarea {
    font: inherit;
    color: inherit;
    background: transparent;
    border: none;
  }

  button {
    cursor: pointer;
  }

  ul, ol {
    list-style: none;
  }

  /* Latin terms inside Farsi text */
  .latin {
    display: inline-block;
    font-family: var(--f-en);
    font-style: normal;
    direction: ltr;
    unicode-bidi: isolate;
  }

  /* Accessible focus indicators */
  :focus-visible {
    outline: 2px solid var(--c-blue-600);
    outline-offset: 3px;
  }

  /* Dark mode / dark section focus indicators */
  [data-theme='dark'] :focus-visible,
  .is-dark :focus-visible,
  #loader :focus-visible,
  .hd[data-theme='dark'] :focus-visible {
    outline-color: var(--c-green-500);
  }

  /* Directional mirroring rules (Section 0.5) */
  html[dir='rtl'] .icon--dir,
  html[dir='rtl'] .flip-rtl {
    transform: scaleX(-1);
  }

  /* Skip Link (Section 0.9) */
  .skip-link {
    position: fixed;
    inset-block-start: -120px;
    inset-inline-start: var(--gutter);
    z-index: 9999;
    padding: var(--s-3) var(--s-5);
    background: var(--c-navy-900);
    color: var(--c-white);
    border: 1px solid var(--c-blue-600);
    border-radius: var(--r-s);
    font-size: var(--fs-small);
    font-weight: 600;
    text-decoration: none;
    transition: inset-block-start var(--d-fast) var(--ease-out);
  }

  .skip-link:focus,
  .skip-link:focus-visible {
    inset-block-start: var(--s-4);
  }

  /* Screen reader utility */
  .sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
  }

  /* Stub sections for subsequent stages (Section 1.1) */
  [data-section] {
    min-block-size: 100svh;
    position: relative;
    box-sizing: border-box;
  }

  [data-section='footer'],
  [data-section='floating'],
  footer.ft {
    min-block-size: auto !important;
  }

  html.dev [data-section] {
    outline: 1px dashed var(--c-blue-300);
  }

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