/**
 * Anime Phoenix — Base Styles & Architecture
 * Semantic Reset, Typography, Accessibility, RTL, Layout Utilities
 */

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

html {
  font-size: 16px;
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  background-color: var(--bg-primary);
  color: var(--text-secondary);
  font-family: var(--font-arabic);
  font-weight: 400;
  line-height: 1.7;
  direction: rtl;
  text-align: right;
  position: relative;
  min-height: 100vh;
  min-height: 100dvh;
  /* Contain horizontal overflow without breaking position: sticky. */
  overflow-x: clip;
}

/* Anchor targets must clear the fixed header. */
section[id],
[id].scroll-target {
  scroll-margin-top: calc(var(--header-height) + var(--space-4));
}

/* Custom Scrollbar */
::-webkit-scrollbar {
  width: 9px;
}

::-webkit-scrollbar-track {
  background: var(--bg-primary);
}

::-webkit-scrollbar-thumb {
  background: #252530;
  border-radius: var(--radius-full);
  border: 2px solid var(--bg-primary);
}

::-webkit-scrollbar-thumb:hover {
  background: var(--color-primary);
}

html {
  scrollbar-color: #252530 var(--bg-primary);
}

/* Skip Navigation Link for Screen Readers & Keyboard Nav */
.skip-link {
  position: fixed;
  top: -100px;
  right: var(--space-4);
  background: var(--color-primary);
  color: #ffffff;
  font-weight: 700;
  padding: var(--space-3) var(--space-6);
  border-radius: var(--radius-md);
  z-index: var(--z-toast);
  text-decoration: none;
  transition: top var(--transition-fast);
}

.skip-link:focus {
  top: var(--space-4);
  outline: 3px solid #ffffff;
}

/* Visually hidden but exposed to assistive technology. */
.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;
}

/* Headings Hierarchy */
h1, h2, h3, h4, h5, h6 {
  color: var(--text-primary);
  font-family: var(--font-arabic);
  font-weight: 700;
  line-height: 1.3;
  letter-spacing: -0.02em;
  text-wrap: balance;
}

h1 {
  font-size: clamp(var(--text-4xl), 5vw + 1rem, var(--text-7xl));
  font-weight: 900;
}

h2 {
  font-size: clamp(var(--text-2xl), 3vw + 0.75rem, var(--text-5xl));
  font-weight: 800;
}

h3 {
  font-size: clamp(var(--text-xl), 2vw + 0.5rem, var(--text-3xl));
  font-weight: 700;
}

h4 {
  font-size: var(--text-xl);
  font-weight: 600;
}

p {
  margin-bottom: var(--space-4);
  color: var(--text-secondary);
  font-size: var(--text-base);
  text-wrap: pretty;
}

p.lead {
  font-size: clamp(var(--text-lg), 1.2vw + 0.5rem, var(--text-xl));
  color: var(--text-secondary);
  line-height: 1.8;
}

a {
  color: var(--color-primary-text);
  text-decoration: none;
  transition: color var(--transition-fast), border-color var(--transition-fast);
}

a:hover {
  color: #ffffff;
}

img,
svg {
  display: block;
  max-width: 100%;
  height: auto;
}

ul, ol {
  list-style: none;
}

button {
  font-family: inherit;
}

/* Focus States for WCAG 2.1 AA Compliance */
:focus-visible {
  outline: 2px solid var(--color-primary-text);
  outline-offset: 3px;
  border-radius: var(--radius-xs);
}

/* On crimson surfaces a red ring is invisible; use white instead. */
.btn-primary-flare:focus-visible,
.btn-gold:focus-visible,
.genre-chip.active:focus-visible,
.footer-social-link:focus-visible {
  outline: 2px solid #ffffff;
  outline-offset: 3px;
}

/* Layout Containers */
.container {
  width: 100%;
  max-width: var(--max-width-container);
  margin-left: auto;
  margin-right: auto;
  padding-left: var(--space-6);
  padding-right: var(--space-6);
}

.container-narrow {
  width: 100%;
  max-width: var(--max-width-narrow);
  margin-left: auto;
  margin-right: auto;
  padding-left: var(--space-6);
  padding-right: var(--space-6);
}

.container-wide {
  width: 100%;
  max-width: var(--max-width-wide);
  margin-left: auto;
  margin-right: auto;
  padding-left: var(--space-6);
  padding-right: var(--space-6);
}

@media (max-width: 480px) {
  .container,
  .container-narrow,
  .container-wide {
    padding-left: var(--space-4);
    padding-right: var(--space-4);
  }
}

/* Section Wrapper Base */
.section {
  position: relative;
  padding-top: clamp(var(--space-16), 8vw, var(--space-32));
  padding-bottom: clamp(var(--space-16), 8vw, var(--space-32));
  z-index: var(--z-normal);
  /*
   * Contains the decorative ambient orbs, which are absolutely positioned at
   * negative offsets and would otherwise extend the document's scroll width
   * past the viewport. On mobile that overflow makes the browser inflate the
   * layout viewport (a 375px device reporting innerWidth 401), which then
   * distorts every width measured from it.
   */
  overflow: hidden;
}

/* Section Header Typography */
.section-header {
  margin-bottom: clamp(var(--space-10), 5vw, var(--space-20));
  text-align: center;
  position: relative;
}

.section-header.text-right {
  text-align: right;
}

.section-tag {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-1) var(--space-4);
  background: rgba(182, 9, 45, 0.12);
  border: 1px solid rgba(182, 9, 45, 0.3);
  border-radius: var(--radius-full);
  color: var(--color-primary-text);
  font-size: var(--text-xs);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: var(--space-4);
}

.section-title {
  color: var(--text-primary);
  margin-bottom: var(--space-4);
}

.section-subtitle {
  color: var(--text-muted);
  font-size: clamp(var(--text-base), 1vw + 0.5rem, var(--text-lg));
  max-width: 680px;
  margin-left: auto;
  margin-right: auto;
  line-height: 1.7;
}

.section-header.text-right .section-subtitle {
  margin-right: 0;
  margin-left: auto;
}

/* Text Gradient Utilities (Red & Black Theme) */
.text-gradient-flame,
.text-gradient-red {
  background: var(--grad-red-glow);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.text-gradient-sunfire {
  background: linear-gradient(135deg, #e21844 0%, #b6092d 50%, #8a0621 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.text-gradient-ember {
  background: linear-gradient(135deg, #e21844 0%, #b6092d 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

/*
 * Windows High Contrast / forced-colors strips background images, which would
 * leave transparent-filled text completely invisible. Restore a solid colour.
 */
@media (forced-colors: active) {
  .text-gradient-flame,
  .text-gradient-red,
  .text-gradient-sunfire,
  .text-gradient-ember {
    background: none;
    -webkit-text-fill-color: currentColor;
    color: CanvasText;
  }
}

/* Ambient Background Atmosphere Elements */
.bg-ambient-layer {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: var(--z-negative);
  overflow: hidden;
}

.ambient-flare {
  position: absolute;
  border-radius: 50%;
  filter: blur(80px);
  pointer-events: none;
  opacity: 0.15;
}

/* ==========================================================================
   Layout & Typography Utilities
   Replace ad-hoc inline styles so the CSP can drop style-src 'unsafe-inline'.
   ========================================================================== */
.stack {
  display: flex;
  flex-direction: column;
}

.row {
  display: flex;
  flex-direction: row;
  align-items: center;
}

.row-wrap {
  flex-wrap: wrap;
}

.row-start {
  align-items: flex-start;
}

.row-center {
  justify-content: center;
}

.flex-1 {
  flex: 1 1 0%;
}

.shrink-0 {
  flex-shrink: 0;
}

.gap-1 { gap: var(--space-1); }
.gap-2 { gap: var(--space-2); }
.gap-3 { gap: var(--space-3); }
.gap-4 { gap: var(--space-4); }
.gap-5 { gap: var(--space-5); }
.gap-6 { gap: var(--space-6); }

.mb-0 { margin-bottom: 0; }
.mb-2 { margin-bottom: var(--space-2); }
.mb-3 { margin-bottom: var(--space-3); }
.mb-4 { margin-bottom: var(--space-4); }
.mb-5 { margin-bottom: var(--space-5); }
.mb-6 { margin-bottom: var(--space-6); }
.mt-4 { margin-top: var(--space-4); }

.text-center { text-align: center; }
.text-start { text-align: start; }

.text-xs { font-size: var(--text-xs); }
.text-sm { font-size: var(--text-sm); }
.text-base { font-size: var(--text-base); }
.text-lg { font-size: var(--text-lg); }
.text-xl { font-size: var(--text-xl); }
.text-2xl { font-size: var(--text-2xl); }
.text-3xl { font-size: var(--text-3xl); }

.fw-600 { font-weight: 600; }
.fw-700 { font-weight: 700; }
.fw-800 { font-weight: 800; }
.fw-900 { font-weight: 900; }

.c-primary { color: var(--text-primary); }
.c-secondary { color: var(--text-secondary); }
.c-muted { color: var(--text-muted); }
.c-brand { color: var(--color-primary-text); }
.c-gold { color: var(--color-primary-text); }

.lh-tight { line-height: 1.5; }
.lh-normal { line-height: 1.7; }
.lh-loose { line-height: 1.8; }

.measure {
  max-width: 600px;
  margin-inline: auto;
}

.icon-14 { width: 14px; height: 14px; }
.icon-15 { width: 15px; height: 15px; }
.icon-18 { width: 18px; height: 18px; }
.icon-24 { width: 24px; height: 24px; }

/* Small inline note rows used inside technical cards. */
.note-tile {
  background: var(--bg-tertiary);
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  gap: var(--space-3);
  font-size: var(--text-xs);
  color: var(--text-primary);
}

.note-tile svg {
  color: var(--color-primary-text);
  flex-shrink: 0;
}

/* Reduced Motion Override */
@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;
    scroll-behavior: auto !important;
  }
}

/* Print: content-first, ink-light. Chrome, background-graphics off, fixed
 * chrome (header/drawer/embers/toasts) is meaningless on paper. */
@media print {
  .site-header,
  .mobile-drawer,
  .mobile-drawer-overlay,
  .mobile-nav-toggle,
  .hero-bg-canvas,
  .hero-core-wrapper,
  .toast-container,
  .footer-social-row {
    display: none !important;
  }

  body {
    background: #ffffff !important;
    color: #111111 !important;
  }

  a {
    color: inherit !important;
    text-decoration: underline;
  }

  .section {
    break-inside: auto;
  }

  h1, h2, h3 {
    break-after: avoid;
  }
}
