@layer reset, base, tokens, layout, components, utilities, animations;

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

  html {
    -webkit-text-size-adjust: 100%;
    scrollbar-gutter: stable;
  }

  body {
    min-block-size: 100dvh;
    text-rendering: optimizeSpeed;
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    overflow-x: hidden;
  }

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

  input, button, textarea, select {
    font: inherit;
  }

  button {
    cursor: pointer;
    background: none;
    border: none;
  }

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

@layer tokens {
  :root {
    color-scheme: light dark;

    /* Typography */
    --font-sans: 'Inter', system-ui, -apple-system, sans-serif;
    --font-heading: 'Space Grotesk', var(--font-sans);

    /* Fonts sizes */
    --fs-xs: clamp(0.75rem, 0.7rem + 0.25vw, 0.875rem);
    --fs-sm: clamp(0.875rem, 0.8rem + 0.35vw, 1rem);
    --fs-base: clamp(1rem, 0.95rem + 0.25vw, 1.125rem);
    --fs-md: clamp(1.125rem, 1.05rem + 0.4vw, 1.35rem);
    --fs-lg: clamp(1.35rem, 1.2rem + 0.75vw, 1.75rem);
    --fs-xl: clamp(1.75rem, 1.5rem + 1.25vw, 2.5rem);
    --fs-xxl: clamp(2.5rem, 2rem + 2.5vw, 4rem);

    /* Motherboard Copper, Gold, and Fiberglass Theme variables */
    --gold: oklch(75% 0.14 85); /* Shiny gold trace highlights */
    --copper: oklch(62% 0.15 50);
    --cyan: oklch(72% 0.18 195);
    --indigo: oklch(60% 0.22 270);
    --coral: oklch(66% 0.19 25);
    --xray-blue: #8fc5e0;
    --xray-metal: #b3b9c0;
    --vein-green: #2cba6e;

    /* Dark Theme (Forest green fiberglass circuit substrate) */
    --bg-dark: oklch(14% 0.02 145);
    --bg-surface-dark: oklch(18% 0.03 145 / 75%);
    --bg-surface-hover-dark: oklch(22% 0.04 145 / 85%);
    --text-dark: oklch(93% 0.01 145);
    --text-muted-dark: oklch(72% 0.02 145);
    --border-dark: oklch(26% 0.04 145 / 50%);
    --border-hover-dark: oklch(42% 0.08 145 / 80%);

    /* Light Theme (Chalk green fiberglass) */
    --bg-light: oklch(93% 0.01 145);
    --bg-surface-light: oklch(96% 0.01 145 / 70%);
    --bg-surface-hover-light: oklch(98% 0.01 145 / 90%);
    --text-light: oklch(16% 0.02 145);
    --text-muted-light: oklch(42% 0.02 145);
    --border-light: oklch(84% 0.02 145 / 80%);
    --border-hover-light: oklch(70% 0.03 145 / 90%);

    /* Unified mappings */
    --bg-main: light-dark(var(--bg-light), var(--bg-dark));
    --bg-card: light-dark(var(--bg-surface-light), var(--bg-surface-dark));
    --bg-card-hover: light-dark(var(--bg-surface-hover-light), var(--bg-surface-hover-dark));
    --text-main: light-dark(var(--text-light), var(--text-dark));
    --text-muted: light-dark(var(--text-muted-light), var(--text-muted-dark));
    --border-color: light-dark(var(--border-light), var(--border-dark));
    --border-color-hover: light-dark(var(--border-hover-light), var(--border-hover-dark));
    --accent-glow: light-dark(oklch(90% 0.02 145 / 15%), oklch(18% 0.04 145 / 45%));

    /* Spacing */
    --space-xs: 0.5rem;
    --space-sm: 1rem;
    --space-md: 1.5rem;
    --space-lg: 2.5rem;
    --space-xl: 3.5rem;
    --space-xxl: 6rem;

    /* RADIUS & TIMELINES */
    --radius-sm: 6px;
    --radius-md: 12px;
    --radius-lg: 24px;
    --transition-fast: 0.2s cubic-bezier(0.2, 0.8, 0.2, 1);
    --transition-smooth: 0.4s cubic-bezier(0.16, 1, 0.3, 1);

    --in-oklab: ;
  }

  @supports (linear-gradient(in oklab, white, black)) {
    :root {
      --in-oklab: in oklab;
    }
  }
}

@layer base {
  body {
    font-family: var(--font-sans);
    font-size: var(--fs-base);
    color: var(--text-main);
    background-color: var(--bg-main);
    
    /* Motherboard background fully visible - One large cover background, NOT repeated */
    background-image: 
      linear-gradient(to bottom, light-dark(rgba(240, 248, 240, 0.85), rgba(4, 12, 6, 0.94)), light-dark(rgba(240, 248, 240, 0.9), rgba(2, 6, 3, 0.97))),
      url('assets/motherboard_bg.png');
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    background-attachment: fixed;
    
    scrollbar-color: light-dark(oklch(80% 0.02 145), oklch(30% 0.03 145)) transparent;
    scrollbar-width: thin;
  }

  h1, h2, h3, h4 {
    font-family: var(--font-heading);
    font-weight: 700;
    line-height: 1.15;
    letter-spacing: -0.02em;
    text-wrap: balance;
    color: light-dark(oklch(12% 0.02 145), oklch(98% 0 0));
  }

  p, li, blockquote {
    text-wrap: pretty;
  }

  :focus-visible {
    outline: 2px solid var(--cyan);
    outline-offset: 4px;
    border-radius: 4px;
  }

  ::selection {
    background-color: light-dark(oklch(85% 0.1 200), oklch(35% 0.15 240));
    color: light-dark(oklch(10% 0.01 245), oklch(100% 0 0));
  }
}

@layer layout {
  .container {
    inline-size: 100%;
    max-inline-size: 1280px;
    margin-inline: auto;
    padding-inline: var(--space-md);
  }

  header {
    position: sticky;
    top: 0;
    z-index: 100;
    background-color: light-dark(oklch(93% 0.01 145 / 0.92), oklch(14% 0.02 145 / 0.88));
    backdrop-filter: saturate(140%) blur(12px);
    -webkit-backdrop-filter: saturate(140%) blur(12px);
    border-bottom: 1px solid var(--border-color);
    padding-block: var(--space-sm);
  }

  .nav-flex {
    display: flex;
    justify-content: space-between;
    align-items: center;
  }

  .nav-links {
    display: flex;
    gap: var(--space-md);
    list-style: none;
  }

  .nav-links a {
    font-size: var(--fs-sm);
    font-weight: 600;
    transition: color var(--transition-fast);
  }

  .nav-links a:hover {
    color: var(--cyan);
  }

  /* Split layout Sizing */
  .split-layout {
    display: flex;
    flex-direction: column;
    position: relative;
    inline-size: 100%;
  }

  .content-side {
    inline-size: 100%;
    padding: var(--space-md) var(--space-md) var(--space-xxl);
    position: relative;
    z-index: 2;
  }

  .visual-side {
    inline-size: 100%;
    position: fixed;
    inset: 0;
    z-index: -1;
    opacity: 0.15;
    pointer-events: none;
  }

  @media (min-width: 1024px) {
    .split-layout {
      flex-direction: row;
    }

    .content-side {
      inline-size: 38%;
      padding-inline-start: var(--space-lg);
      padding-inline-end: var(--space-md);
    }

    .visual-side {
      inline-size: 62%;
      position: sticky;
      top: 0;
      height: 100vh;
      z-index: 1;
      opacity: 1;
      pointer-events: auto;
    }
  }

  section {
    padding-block: var(--space-lg);
    margin-block-end: var(--space-xl);
  }
}

@layer components {
  /* Logo Spacing & Microchips */
  .logo {
    display: inline-flex;
    align-items: center;
  }

  .logo-head-container {
    width: 74px;
    height: 74px;
    overflow: visible;
    /* Borderless, cropped transparent head mark only! */
    background: none;
    border: none;
    box-shadow: none;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 0;
  }

  .logo-head {
    width: auto;
    height: 100%;
    object-fit: contain;
    filter: drop-shadow(0 0 5px rgba(44,186,110,0.35));
  }

  .logo-text {
    font-family: var(--font-heading);
    font-size: clamp(1.4rem, 1.25rem + 0.6vw, 1.85rem);
    font-weight: 800;
    letter-spacing: 0.08em;
    color: light-dark(oklch(15% 0.02 145), oklch(98% 0 0));
    display: flex;
    align-items: center;
  }

  .brand-x {
    color: var(--vein-green);
    margin-inline: 8px;
    font-weight: 900;
  }

  .ltr-blue { color: var(--xray-blue); }
  .ltr-metal { color: var(--xray-metal); }
  .logo-wm-img { height: 90px; width: auto; display: block; }
  .logo-lockup { height: 92px; width: auto; display: block; border-radius: 8px; }

  /* Microchips are smaller and centered vertically so they do not stand out too much */
  .chip-spacer-svg {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    margin-inline: 2px;
    color: var(--vein-green);
    vertical-align: middle;
    filter: drop-shadow(0 0 2px rgba(44,186,110,0.75));
  }

  .chip-spacer-svg svg {
    width: 100%;
    height: 100%;
    display: block;
  }

  /* Glassmorphic card panels */
  .glass-card {
    background-color: var(--bg-card);
    backdrop-filter: blur(12px);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: var(--space-md);
    box-shadow: 0 10px 30px -10px rgba(0, 0, 0, 0.15);
    transition: transform var(--transition-smooth), border-color var(--transition-smooth), background-color var(--transition-smooth);
    position: relative;
    overflow: hidden;
  }

  .glass-card::before {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: inherit;
    padding: 1px;
    background: linear-gradient(135deg var(--in-oklab), rgba(255, 255, 255, 0.1), rgba(255, 255, 255, 0.02));
    mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
    -webkit-mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
    -webkit-mask-composite: xor;
    mask-composite: exclude;
    pointer-events: none;
  }

  .glass-card:hover {
    border-color: var(--border-color-hover);
    background-color: var(--bg-card-hover);
    transform: translateY(-2px);
  }

  /* Badges */
  .badge {
    display: inline-block;
    padding: 0.2rem 0.6rem;
    border-radius: 50px;
    font-size: var(--fs-xs);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
  }

  .badge-tickin {
    background-color: oklch(75% 0.15 150 / 10%);
    color: oklch(75% 0.18 150);
    border: 1px solid oklch(75% 0.15 150 / 20%);
  }

  .badge-pickdy {
    background-color: oklch(65% 0.18 330 / 10%);
    color: oklch(68% 0.2 330);
    border: 1px solid oklch(65% 0.18 330 / 20%);
  }

  /* Buttons */
  .btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-xs);
    padding: 0.75rem 1.5rem;
    border-radius: var(--radius-sm);
    font-size: var(--fs-sm);
    font-weight: 600;
    transition: all var(--transition-fast);
  }

  .btn-primary {
    background: linear-gradient(135deg var(--in-oklab), var(--cyan) 0%, var(--gold) 100%);
    color: oklch(10% 0.02 145);
    box-shadow: 0 4px 15px rgba(200, 180, 100, 0.2);
  }

  .btn-primary:hover {
    transform: translateY(-1px);
    box-shadow: 0 8px 25px rgba(200, 180, 100, 0.35);
    filter: brightness(1.05);
  }

  .btn-secondary {
    background-color: var(--bg-card);
    border: 1px solid var(--border-color);
    color: var(--text-main);
  }

  .btn-secondary:hover {
    background-color: var(--bg-card-hover);
    border-color: var(--border-color-hover);
    transform: translateY(-1px);
  }

  /* Hero Section */
  .hero-wrapper {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    text-align: left;
    gap: var(--space-md);
    padding-block: var(--space-xl);
  }

  .hero-tagline {
    font-size: var(--fs-sm);
    font-weight: 700;
    letter-spacing: 0.15em;
    text-transform: uppercase;
    color: var(--gold);
  }

  .hero-title {
    font-size: var(--fs-xxl);
    line-height: 1.05;
    letter-spacing: -0.03em;
    background: linear-gradient(to right var(--in-oklab), light-dark(oklch(15% 0.02 145), oklch(98% 0 0)) 30%, var(--gold) 75%, var(--coral) 100%);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
  }

  .hero-description {
    font-size: var(--fs-md);
    color: var(--text-muted);
  }

  /* Centered T-Pose Viewport - Borderless, Crop-Hiding, and Boxless */
  .xray-sticky-viewport {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    padding: var(--space-md);
  }

  .xray-view-window {
    width: 95%;
    height: 95%;
    max-width: 1200px;
    aspect-ratio: 1 / 1;
    overflow: hidden; /* Clips the scaled body, letting only head/shoulders display at start */
    border: none;
    background: none;
    box-shadow: none;
    backdrop-filter: none;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  /* Translating Body Wrapper houses both the graphic, */
  /* ensuring the whole body floats majestically as it scrolls! */
  .xray-body-wrapper {
    width: 100%;
    height: 100%;
    position: relative;
    animation: xrayScroll linear;
    animation-timeline: scroll(root);
    animation-range: 0% 100%;
  }

  .xray-image {
    width: 100%;
    height: 100%;
    object-fit: contain; /* Keeps the square PCB artwork in proper ratio */
    display: block;
    border-radius: 18px;
    filter: drop-shadow(0 15px 30px rgba(0, 0, 0, 0.55));
    pointer-events: none;
  }

  /* Symmetrical app logo elements */
  .app-logo-img {
    width: 44px;
    height: 44px;
    border-radius: 10px;
    border: 1px solid var(--border-color);
    background-color: light-dark(oklch(100% 0 0), oklch(14% 0.02 145));
    box-shadow: 0 4px 10px rgba(0,0,0,0.1);
  }

  /* Hotspots removed - interactive mapping disabled */

  /* Multi-Agent Board Simulator */
  .board-sim {
    inline-size: 100%;
    border-radius: var(--radius-md);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    block-size: 420px;
    border: 1px solid var(--border-color);
    background-color: var(--bg-card);
    box-shadow: 0 15px 40px -15px rgba(0, 0, 0, 0.3);
  }

  .board-sim-header {
    background-color: light-dark(oklch(93% 0.01 245 / 40%), oklch(15% 0.02 245));
    border-bottom: 1px solid var(--border-color);
    padding: var(--space-sm);
    display: flex;
    justify-content: space-between;
    align-items: center;
  }

  .board-sim-title {
    font-size: var(--fs-sm);
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: var(--space-xs);
  }

  .board-sim-status {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background-color: oklch(75% 0.18 150);
    box-shadow: 0 0 8px oklch(75% 0.18 150);
  }

  .board-sim-controls {
    display: flex;
    gap: 6px;
  }

  .sim-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background-color: var(--border-color);
  }

  .board-sim-body {
    flex: 1;
    overflow-y: auto;
    padding: var(--space-md);
    display: flex;
    flex-direction: column;
    gap: var(--space-md);
    scrollbar-width: thin;
  }

  /* Reset any margin so the parent flex `gap` is the single source of truth
     for spacing between chat messages — keeps the rhythm uniform regardless
     of bubble height (Tim 2026-06-14). */
  .board-sim-body > .chat-msg { margin: 0; }

  .board-sim-footer {
    padding: var(--space-sm);
    background-color: light-dark(oklch(93% 0.01 245 / 20%), oklch(15% 0.02 245 / 40%));
    border-top: 1px solid var(--border-color);
    display: flex;
    gap: var(--space-xs);
  }

  .board-sim-input {
    flex: 1;
    background-color: light-dark(oklch(100% 0 0), oklch(12% 0.01 245));
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: 0.5rem 1rem;
    font-size: var(--fs-sm);
    color: var(--text-main);
    transition: border-color var(--transition-fast);
  }

  .board-sim-input:focus {
    outline: none;
    border-color: var(--cyan);
  }

  /* Chat Message blocks */
  .chat-msg {
    display: flex;
    flex-direction: column;
    gap: var(--space-xs);
    max-inline-size: 85%;
    animation: messageReveal 0.3s cubic-bezier(0.16, 1, 0.3, 1) forwards;
  }

  .chat-msg-user {
    align-self: flex-end;
  }

  .chat-msg-agent {
    align-self: flex-start;
  }

  .msg-meta {
    font-size: var(--fs-xs);
    font-weight: 600;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    gap: 6px;
  }

  .agent-avatar {
    inline-size: 16px;
    block-size: 16px;
    border-radius: 50%;
    background-color: var(--cyan);
  }

  .msg-bubble {
    background-color: light-dark(oklch(93% 0.01 245 / 40%), oklch(20% 0.03 245 / 80%));
    border: 1px solid var(--border-color);
    padding: 0.75rem 1rem;
    border-radius: var(--radius-md);
    font-size: var(--fs-sm);
    line-height: 1.55;
  }

  .chat-msg-user .msg-bubble {
    background: linear-gradient(135deg var(--in-oklab), var(--indigo) 0%, oklch(45% 0.2 260) 100%);
    color: oklch(100% 0 0);
    border: none;
  }

  .avatar-cos { background-color: var(--indigo); }
  .avatar-designer { background-color: var(--coral); }
  .avatar-engineer { background-color: var(--cyan); }
  .avatar-memory { background-color: oklch(75% 0.15 150); }
  .avatar-researcher { background-color: oklch(60% 0.18 200); }
}

@layer animations {
  .reveal-on-scroll {
    opacity: 0.3;
    transform: translateY(20px);
    animation: fadeReveal linear forwards;
    animation-timeline: view();
    animation-range: entry 100px cover 30%;
  }

  @keyframes fadeReveal {
    to {
      opacity: 1;
      transform: translateY(0);
    }
  }

  @keyframes messageReveal {
    from {
      opacity: 0;
      transform: translateY(8px);
    }
    to {
      opacity: 1;
      transform: translateY(0);
    }
  }

  @keyframes ringPulse {
    from {
      transform: scale(0.6);
      opacity: 1;
    }
    to {
      transform: scale(1.8);
      opacity: 0;
    }
  }

  /* Symmetrical scroll-driven zoom in on .xray-body-wrapper. */
  /* Keeps the head/shoulders zoomed on load, panning down to the legs/feet at the bottom. */
  .xray-body-wrapper {
    animation: xrayScroll linear;
    animation-timeline: scroll(root);
    animation-range: 0% 100%;
  }

  @keyframes xrayScroll {
    0% {
      /* Full head + chip visible at top (35% aligns image top to window top at 1.7x) */
      transform: translateY(35%) scale(1.7);
    }
    38% {
      /* Chest (AI chest chip connecting heart and robot) visible */
      transform: translateY(17%) scale(1.7);
    }
    68% {
      /* Torso and organs fully visible */
      transform: translateY(-12%) scale(1.7);
    }
    100% {
      /* Panned fully down so the toes/feet are completely visible at the bottom */
      transform: translateY(-35%) scale(1.7);
    }
  }
}

@layer utilities {
  .mt-xs { margin-block-start: var(--space-xs); }
  .mt-sm { margin-block-start: var(--space-sm); }
  .mt-md { margin-block-start: var(--space-md); }
  .mt-lg { margin-block-start: var(--space-lg); }
  .mt-xl { margin-block-start: var(--space-xl); }
}
