/* ==========================================================================
   1. CASCADE LAYERS SETUP
   ========================================================================== */
@layer tokens, base, layout, components, sections, animations, utilities;

/* ==========================================================================
   2. GLOBAL DESIGN TOKENS
   ========================================================================== */
@layer tokens {
  :root {
    /* --- Typography Controls --- */
    --font-body: "Inter", system-ui, -apple-system, sans-serif;
    --font-heading: "Poppins", system-ui, -apple-system, sans-serif;
    --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;

    /* --- Spacing & Dimensions --- */
    --radius-sm: 8px;
    --radius-md: 16px;
    --radius-lg: 24px;
    --radius-full: 9999px;
    --header-height: 70px;
    --bottom-nav-height: 65px;

    /* --- Motion Controls --- */
    --speed-fast: 0.15s;
    --speed-base: 0.3s;
    --speed-slow: 0.6s;
    --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
    --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);

    /* --- MODERN LIGHT THEME (Darker, Anti-Glare Muted Slate) --- */
    --color-primary: #0f766e; 
    --color-primary-hover: #115e59;
    --color-primary-subtle: rgba(15, 118, 110, 0.08);

    --bg-primary: #e2e8f0; /* Darker slate gray eliminates harsh whites */
    --bg-surface: #cbd5e1; 
    --bg-elevated: #94a3b8; 

    --text-heading: #0f172a; 
    --text-main: #334155;
    --text-muted: #475569;

    --border-color: rgba(15, 23, 42, 0.08);
    --border-hover: rgba(15, 23, 42, 0.18);

    --shadow-sm: 0 2px 8px rgba(15, 23, 42, 0.03);
    --shadow-md: 0 10px 25px -5px rgba(15, 23, 42, 0.06);

    --header-bg: rgba(226, 232, 240, 0.8);
    --header-shadow: 0 4px 20px -2px rgba(15, 23, 42, 0.04);
  }

  /* --- MODERN DARK THEME OVERRIDES (Deep Cyber Obsidian) --- */
  [data-theme="dark"] {
    --color-primary: #2dd4bf; 
    --color-primary-hover: #99f6e4;
    --color-primary-subtle: rgba(45, 212, 191, 0.12);

    --bg-primary: #030712; 
    --bg-surface: #0b1329; 
    --bg-elevated: #111c44; 

    --text-heading: #f8fafc;
    --text-main: #e2e8f0;
    --text-muted: #94a3b8;

    --border-color: rgba(255, 255, 255, 0.08);
    --border-hover: rgba(45, 212, 191, 0.3); 

    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.5);
    --shadow-md: 0 12px 30px rgba(0, 0, 0, 0.7);

    --header-bg: rgba(3, 7, 18, 0.8);
    --header-shadow: 0 8px 24px -4px rgba(0, 0, 0, 0.6);
  }

  /* OS Preference Auto Switcher */
  @media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
      --color-primary: #2dd4bf;
      --color-primary-hover: #99f6e4;
      --color-primary-subtle: rgba(45, 212, 191, 0.12);

      --bg-primary: #030712;
      --bg-surface: #0b1329;
      --bg-elevated: #111c44;

      --text-heading: #f8fafc;
      --text-main: #e2e8f0;
      --text-muted: #94a3b8;

      --border-color: rgba(255, 255, 255, 0.08);
      --border-hover: rgba(45, 212, 191, 0.3);

      --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.5);
      --shadow-md: 0 12px 30px rgba(0, 0, 0, 0.7);

      --header-bg: rgba(3, 7, 18, 0.8);
      --header-shadow: 0 8px 24px -4px rgba(0, 0, 0, 0.6);
    }
  }
}


/* ==========================================================================
   3. GLOBAL BASE STYLES
   ========================================================================== */
@layer base {
  *, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
  }

  html {
    scroll-behavior: smooth;
    scroll-padding-top: var(--header-height);
  }

  body {
    font-family: var(--font-body);
    background-color: var(--bg-primary) !important;
    color: var(--text-main) !important;
    line-height: 1.6;
    transition: color var(--speed-base) var(--ease-out);
    overflow-x: hidden;
  }

  /* Universal Headings Rule */
  h1, h2, h3, h4, h5, h6, 
  .h1, .h2, .h3, .h4, .h5, .h6 {
    color: var(--text-heading) !important;
    font-family: var(--font-heading);
    font-weight: 700;
    letter-spacing: -0.02em;
  }

  p, li, span, div, strong, em, label {
    color: inherit;
  }

  p {
    margin-bottom: 1rem;
  }

  /* Universal Link Styling */
  a {
    color: var(--color-primary);
    text-decoration: none !important;
    transition: color var(--speed-fast) ease;
  }

  a:hover {
    color: var(--color-primary-hover);
  }

  .text-muted {
    color: var(--text-muted) !important;
  }

  .text-primary {
    color: var(--color-primary) !important;
  }

  .bg-primary {
    background-color: var(--color-primary) !important;
  }
}

/* ==========================================================================
   4. LAYOUT & NAVIGATION
   ========================================================================== */
@layer layout {
  /* Site Header */
  .site-header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--header-height);
    background-color: var(--header-bg) !important;
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border-color);
    box-shadow: var(--header-shadow);
    z-index: 1000;
    transition: all var(--speed-base) var(--ease-out);
  }

  .site-header .sitename {
    color: var(--text-heading) !important;
  }

  /* Navigation Links */
  .nav-link-item,
  .nav-links a {
    color: var(--text-muted) !important;
    font-weight: 500;
    padding: 8px 16px;
    border-radius: var(--radius-sm);
    transition: all var(--speed-fast) var(--ease-out);
  }

  .nav-link-item:hover,
  .nav-links a:hover {
    color: var(--color-primary) !important;
    background-color: var(--color-primary-subtle);
  }

  .nav-link-item.active,
  .nav-links a.active {
    color: var(--color-primary) !important;
    background-color: var(--color-primary-subtle);
    font-weight: 600;
  }

  /* Social Links & Theme Switcher Button */
  .social-links a,
  .theme-toggle-btn {
    width: 38px;
    height: 38px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-full);
    background-color: var(--bg-surface);
    color: var(--text-muted) !important;
    border: 1px solid var(--border-color);
    transition: all var(--speed-fast) var(--ease-out);
  }

  .social-links a:hover,
  .theme-toggle-btn:hover {
    background-color: var(--color-primary-subtle);
    color: var(--color-primary) !important;
    border-color: var(--color-primary);
    transform: translateY(-2px);
  }

  /* Mobile Bottom Navigation Bar */
  .bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: var(--bottom-nav-height);
    background-color: var(--header-bg) !important;
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-top: 1px solid var(--border-color);
    z-index: 1000;
  }

  .bottom-nav-item a {
    color: var(--text-muted) !important;
    display: flex;
    flex-direction: column;
    align-items: center;
    font-size: 0.75rem;
  }

  .bottom-nav-item a.active,
  .bottom-nav-item a:hover {
    color: var(--color-primary) !important;
  }

  /* Footer */
  #footer, .footer {
    border-top: 1px solid var(--border-color) !important;
    background-color: var(--bg-surface) !important;
    padding: 2.5rem 0 calc(var(--bottom-nav-height) + 1.5rem) 0 !important;
    color: var(--text-muted) !important;
    position: relative;
    z-index: 1;
  }

  @media (min-width: 992px) {
    .bottom-nav {
      display: none !important;
    }

    #footer, .footer {
      padding: 2.5rem 0 !important;
    }
  }
}

/* ==========================================================================
   5. COMPONENTS
   ========================================================================== */
@layer components {
  /* Base Card Rules */
  .card, 
  .about-card {
    background-color: var(--bg-surface) !important;
    color: var(--text-main) !important;
    border: 1px solid var(--border-color) !important;
    border-radius: var(--radius-md);
    padding: 1.5rem;
    box-shadow: var(--shadow-sm);
    transition: transform var(--speed-base) var(--ease-spring),
                border-color var(--speed-base) ease,
                box-shadow var(--speed-base) ease;
  }

  .card:hover, 
  .about-card:hover {
    border-color: var(--border-hover) !important;
    box-shadow: var(--shadow-md);
    transform: translateY(-4px);
  }

  .card-title,
  .about-card h3 {
    color: var(--text-heading) !important;
  }

  .card-text {
    color: var(--text-muted) !important;
  }

  /* Buttons */
  .btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.6rem 1.25rem;
    font-weight: 500;
    border-radius: var(--radius-full);
    transition: all var(--speed-fast) var(--ease-spring);
    cursor: pointer;
  }

  .btn-primary {
    background-color: var(--color-primary) !important;
    border-color: var(--color-primary) !important;
    color: #ffffff !important;
  }

  .btn-primary:hover {
    background-color: var(--color-primary-hover) !important;
    border-color: var(--color-primary-hover) !important;
    transform: translateY(-2px);
  }

  .btn-outline-primary {
    background-color: transparent !important;
    border: 1px solid var(--color-primary) !important;
    color: var(--color-primary) !important;
  }

  .btn-outline-primary:hover {
    background-color: var(--color-primary) !important;
    color: #ffffff !important;
  }
}

/* ==========================================================================
   6. SECTION SPECIFIC STYLES & SMOOTH PER-SECTION FADE
   ========================================================================== */
@layer sections {
  /* Base section style: set base color and explicit transition properties */
  section.section {
    padding: 5rem 0;
    position: relative;
    background-color: var(--bg-primary);
    transition: background-color 2s cubic-bezier(0.16, 1, 0.3, 1) !important;
  }

  /* --- LIGHT THEME SECTION ACCENTS --- */
  section.section#about.is-active,
  section.section#portfolio.is-active {
    background-color: #e2e8f0;
  }

  section.section#skills.is-active,
  section.section#contact.is-active,
  section.section#hero.is-active {
    background-color: #f1f5f9;
  }

  /* --- DARK THEME SECTION ACCENTS --- */
  [data-theme="dark"] section.section#about.is-active,
  [data-theme="dark"] section.section#portfolio.is-active {
    background-color: #0f172a;
  }

  [data-theme="dark"] section.section#skills.is-active,
  [data-theme="dark"] section.section#contact.is-active,
  [data-theme="dark"] section.section#hero.is-active {
    background-color: #0b0f19;
  }

  /* Typography & Component Specifics within Sections */
  .section-title h2 {
    color: var(--text-heading) !important;
    position: relative;
    padding-bottom: 0.5rem;
  }

  .section-title p {
    color: var(--text-muted) !important;
  }

  #hero {
    position: relative;
    min-height: 100vh;
    min-height: 100dvh;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  /* --- HERO SVG LINE ANIMATION CONTAINERS (Strictly Contained Mobile Fix) --- */
  .hero-bg-line {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 0;
    opacity: 0.35;
    color: var(--color-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
  }

  .hero-bg-line svg {
    width: 100%;
    height: 100%;
    display: block;
    /* Forces the full SVG bounds to fit entirely inside the container viewport */
    preserveAspectRatio: xMidYMid meet;
  }

  #hero .container,
  #hero .hero-content {
    position: relative;
    z-index: 1;
    width: 100%;
  }

  .about-card .stat-badge {
    display: inline-block;
    color: var(--color-primary) !important;
    background-color: var(--color-primary-subtle);
    padding: 6px 14px;
    border-radius: var(--radius-full);
    font-size: 0.85rem;
    font-weight: 600;
    margin-bottom: 0.75rem;
  }

  .about-card .info-list {
    list-style: none;
    padding-left: 0;
    margin-bottom: 0;
  }

  .about-card .info-list li {
    color: var(--text-main) !important;
    margin-bottom: 0.75rem;
  }

  .about-card .info-list li i {
    color: var(--color-primary) !important;
    margin-right: 0.5rem;
  }

  .resume .resume-item {
    border-left: 2px solid var(--color-primary) !important;
  }

  .resume .resume-item h5 {
    background-color: var(--color-primary-subtle) !important;
    color: var(--color-primary) !important;
    display: inline-block;
    padding: 4px 12px;
    border-radius: var(--radius-sm);
    font-size: 0.875rem;
    font-weight: 600;
    margin-bottom: 0.75rem;
  }

  /* Portfolio Pagination Styling */
  .portfolio-pagination .page-item .page-link {
    background-color: var(--bg-surface) !important;
    color: var(--text-main) !important;
    border: 1px solid var(--border-color) !important;
    padding: 0.5rem 0.75rem;
    transition: all var(--speed-fast) var(--ease-out);
  }

  .portfolio-pagination .page-item .page-link:hover {
    background-color: var(--color-primary-subtle) !important;
    color: var(--color-primary) !important;
    border-color: var(--color-primary) !important;
  }

  .portfolio-pagination .page-item.active .page-link {
    background-color: var(--color-primary) !important;
    border-color: var(--color-primary) !important;
    color: #ffffff !important;
  }

  .portfolio-pagination .page-item.disabled .page-link {
    background-color: var(--bg-surface) !important;
    color: var(--text-muted) !important;
    opacity: 0.5;
    border-color: var(--border-color) !important;
  }
}

/* ==========================================================================
   7. SLEEK MODERN ANIMATIONS
   ========================================================================== */
@layer animations {
  [data-aos="fade-up"] {
    opacity: 0;
    transform: translateY(30px) scale(0.98);
    transition: opacity var(--speed-slow) var(--ease-out),
                transform var(--speed-slow) var(--ease-out);
  }

  [data-aos="fade-up"].aos-animate {
    opacity: 1;
    transform: translateY(0) scale(1);
  }

  /* --- CUSTOM PATH LINE DRAWING KEYFRAMES (Slower & Fluid) --- */
  .animated-custom-line {
    stroke-dasharray: 5500;
    stroke-dashoffset: 5500;
    animation: drawCustomLine 9.5s cubic-bezier(0.16, 1, 0.3, 1) forwards infinite alternate;
    filter: drop-shadow(0 0 12px var(--color-primary));
  }

  @keyframes drawCustomLine {
    0% {
      stroke-dashoffset: 5500;
      opacity: 0.15;
    }
    50% {
      opacity: 0.9;
    }
    100% {
      stroke-dashoffset: 0;
      opacity: 0.7;
    }
  }
}