/* =========================================================
   PULSE VPN — Base Layer
   Reset + Fonts + Body + App Container + Splash + Transitions
   ========================================================= */

@layer reset, base, components, utilities;

/* ============================================================
   FONT FACES
   ============================================================ */
@layer base {
  @font-face {
    font-family: 'IRANSansX';
    src: url('../assets/fonts/IRANSansX-Regular.woff2') format('woff2'),
         url('../assets/fonts/IRANSansX-Regular.woff')  format('woff');
    font-weight: 400; font-style: normal; font-display: swap;
  }
  @font-face {
    font-family: 'IRANSansX';
    src: url('../assets/fonts/IRANSansX-Medium.woff2') format('woff2'),
         url('../assets/fonts/IRANSansX-Medium.woff')  format('woff');
    font-weight: 500; font-style: normal; font-display: swap;
  }
  @font-face {
    font-family: 'IRANSansX';
    src: url('../assets/fonts/IRANSansX-SemiBold.woff2') format('woff2'),
         url('../assets/fonts/IRANSansX-SemiBold.woff')  format('woff');
    font-weight: 600; font-style: normal; font-display: swap;
  }
  @font-face {
    font-family: 'IRANSansX';
    src: url('../assets/fonts/IRANSansX-Bold.woff2') format('woff2'),
         url('../assets/fonts/IRANSansX-Bold.woff')  format('woff');
    font-weight: 700; font-style: normal; font-display: swap;
  }
}

/* ============================================================
   RESET
   ============================================================ */
@layer reset {
  *,
  *::before,
  *::after {
    box-sizing: border-box;
  }

  html {
    direction: rtl;
    -webkit-text-size-adjust: 100%;
    -webkit-tap-highlight-color: transparent;
    text-size-adjust: 100%;
    /* NOTE: no overflow-x here — keeps html as the natural scroll container.
       Using overflow-x: clip (if needed) below on body avoids creating a
       second scroll container that would trap wheel/touchpad events. */
  }

  body {
    margin: 0;
    min-height: 100dvh;
    min-height: 100vh;
    font-family: var(--font-sans);
    font-size: var(--fs-body);
    line-height: var(--lh-body);
    font-weight: var(--fw-body);
    color: var(--c-text);
    background: var(--c-bg);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;

    /* clip does NOT create a scroll container — prevents horizontal overflow
       without breaking wheel/touchpad scrolling. */
    overflow-x: clip;
  }

  h1, h2, h3, h4, h5, h6,
  p, figure, blockquote, dl, dd {
    margin: 0;
  }

  ul, ol {
    margin: 0;
    padding: 0;
    list-style: none;
  }

  a { color: inherit; text-decoration: none; }

  img, svg, video, canvas {
    display: block;
    max-width: 100%;
    height: auto;
  }

  button, input, select, textarea {
    font: inherit;
    color: inherit;
    background: none;
    border: none;
    outline: none;
    margin: 0;
    padding: 0;
    -webkit-appearance: none;
    appearance: none;
  }

  button {
    cursor: pointer;
    user-select: none;
    -webkit-user-select: none;
  }

  [hidden] { display: none !important; }
}

/* ============================================================
   BASE ELEMENTS
   ============================================================ */
@layer base {
  :focus { outline: none; }
  :focus-visible {
    outline: 2px solid var(--c-primary);
    outline-offset: 2px;
    border-radius: var(--r-xs);
  }

  ::selection {
    background: var(--c-primary);
    color: var(--c-text-on-primary);
  }

  ::-webkit-scrollbar { width: 6px; height: 6px; }
  ::-webkit-scrollbar-track { background: transparent; }
  ::-webkit-scrollbar-thumb {
    background: var(--c-border-strong);
    border-radius: var(--r-full);
  }
  ::-webkit-scrollbar-thumb:hover { background: var(--c-text-dim); }

  /* ---------- App Container ---------- */
  .pulse-app {
    position: relative;
    width: 100%;
    max-width: var(--container-max);
    min-height: 100dvh;
    min-height: 100vh;
    margin-inline: auto;
    background: var(--c-bg);
    padding-bottom: var(--safe-bottom);
    padding-left: var(--safe-left);
    padding-right: var(--safe-right);
  }

  @media (min-width: 768px) {
    body {
      background: var(--c-bg-outer);
    }

    .pulse-app {
      border-left: 1px solid var(--c-border);
      border-right: 1px solid var(--c-border);
      box-shadow: 0 0 80px rgba(0, 0, 0, 0.55);
    }
  }

  @media (min-width: 1024px) {
    .pulse-app {
      box-shadow: 0 0 100px rgba(0, 0, 0, 0.65);
    }
  }

  /* ---------- Numeric formatting ---------- */
  .pulse-num {
    font-variant-numeric: tabular-nums;
    font-feature-settings: 'tnum';
    direction: ltr;
    unicode-bidi: isolate;
    display: inline-block;
  }

  /* ---------- Noscript ---------- */
  .pulse-noscript {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--sp-6);
    background: var(--c-bg);
    color: var(--c-text);
    text-align: center;
    font-size: var(--fs-body);
    z-index: var(--z-max);
  }

  /* ---------- Splash ---------- */
  .pulse-splash {
    position: fixed;
    top: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 100%;
    max-width: var(--container-max);
    height: 100dvh;
    height: 100vh;
    z-index: 9998;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: var(--sp-4);
    background: var(--c-bg);
    transition:
      opacity var(--dur-slow) var(--ease-out),
      visibility var(--dur-slow) var(--ease-out);
  }

  .pulse-splash.is-hidden {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
  }

  .pulse-splash__logo {
    width: 120px;
    height: 120px;
    border-radius: var(--r-xl);
    overflow: hidden;
    box-shadow: var(--sh-lg);
  }

  .pulse-splash__logo img {
    width: 100%;
    height: 100%;
    object-fit: cover;
  }

  .pulse-splash__name {
    font-size: 22px;
    font-weight: 800;
    letter-spacing: 0.5px;
    background: var(--grad-text);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
  }

  .pulse-splash__spinner {
    width: 24px;
    height: 24px;
    margin-top: var(--sp-2);
    border: 2.5px solid rgba(99, 102, 241, 0.2);
    border-top-color: var(--c-primary);
    border-radius: 50%;
    animation: pulse-spin 800ms linear infinite;
  }

  @media (max-width: 375px) {
    .pulse-splash__logo {
      width: 100px;
      height: 100px;
    }
    .pulse-splash__name {
      font-size: 20px;
    }
  }

  @media (max-height: 480px) and (orientation: landscape) {
    .pulse-splash {
      flex-direction: row;
      gap: var(--sp-6);
    }
    .pulse-splash__logo {
      width: 80px;
      height: 80px;
    }
    .pulse-splash__name {
      font-size: 18px;
    }
    .pulse-splash__spinner {
      display: none;
    }
  }
}

/* ============================================================
   PAGE TRANSITIONS (outside @layer so animations resolve by name)
   ============================================================ */
@keyframes pulse-page-enter {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes pulse-page-exit {
  from {
    opacity: 1;
    transform: translateY(0);
  }
  to {
    opacity: 0;
    transform: translateY(-6px);
  }
}

.pulse-page.is-entering {
  animation: pulse-page-enter var(--dur-slow) var(--ease-out) both;
}

#screen-root.is-leaving > * {
  animation: pulse-page-exit var(--dur-fast) var(--ease-in) both;
}

@media (prefers-reduced-motion: reduce) {
  .pulse-page.is-entering,
  #screen-root.is-leaving > * {
    animation: none !important;
  }
}
