/* Core Layout System - Phase 2: Responsive Page Skeleton */
/* Following design principles from documentation/design/design_principles.md */

:root {
  /* Base spacing unit: 8px grid foundation */
  --space-unit: 0.5rem;
  
  /* Spacing scale */
  --space-xs:  calc(var(--space-unit) * 0.5);   /* 4px */
  --space-sm:  calc(var(--space-unit) * 1);     /* 8px */
  --space-md:  calc(var(--space-unit) * 2);     /* 16px */
  --space-lg:  calc(var(--space-unit) * 3);     /* 24px */
  --space-xl:  calc(var(--space-unit) * 4);     /* 32px */
  --space-2xl: calc(var(--space-unit) * 6);     /* 48px */
  --space-3xl: calc(var(--space-unit) * 8);     /* 64px */
  
  /* Responsive spacing */
  --page-padding: clamp(var(--space-lg), 4vw, var(--space-3xl));
  --stack-gap: clamp(var(--space-2xl), 6vh, var(--space-3xl));
  
  /* Card sizing - following design principles - converted to rem */
  --card-width-desktop: min(50rem, 50vw); /* 50rem = 800px equivalent */
  --card-width-mobile: min(90vw, calc(100vw - var(--space-2xl)));
  --card-height-mobile: clamp(31.25rem, calc(var(--vh, 1vh) * 65), 55rem); /* Use dynamic visible viewport height on mobile */
  
  /* Canvas region sizing - more square for desktop */
  --canvas-width-desktop: min(37.5rem, 40vw); /* 37.5rem = 600px equivalent, original comfortable sizing */
  --canvas-height-desktop: clamp(37.5rem, 55vh, 60rem); /* 600px–960px, adapts with viewport for balanced composition */
  
  /* Z-index layers for separation */
  --z-background: -1;
  --z-content: 1;
  --z-overlay: 10;
  
  /* Motion scale for reduced-motion support */
  --motion-scale: 1;
}

@media (prefers-reduced-motion: reduce) {
  :root {
    --motion-scale: 0;
  }
}

/* App root container with night sky background */
.app-root {
  position: relative;
  width: 100%;
  display: flex;
  flex-direction: column;
  height: 100vh; /* establish a definite height so % heights resolve */
  min-height: 100vh;
  /* iOS Safari viewport fix: prefer fill-available to avoid extra scroll space */
  min-height: -webkit-fill-available;
  /* Dynamic viewport height driven by JS var (falls back to 100vh if unset) */
  min-height: calc(var(--vh, 1vh) * 100);
  overflow-x: hidden;
  
  /* Deep space gradient - darker atmospheric vibes */
  background:
    /* Stronger vignetting for deep space feel */
    radial-gradient(ellipse at center, transparent 30%, rgba(0, 0, 0, 0.6) 100%),
    /* Main deep space gradient */
    linear-gradient(135deg,
      #0b0b0d 0%,     /* Very dark gray-black */
      #1a1a1c 25%,    /* Dark charcoal */
      #0f0f11 50%,    /* Deep charcoal */
      #121214 75%,    /* Dark gray-black */
      #070708 100%    /* Near pure black */
    );
  
  /* Ensure consistent background */
  background-attachment: fixed;
  background-size: cover;
}

/* Two-layer system implementation */

/* Background layer - fixed positioning above CSS gradient but behind content */
.background-layer {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 0; /* Above CSS gradient (-1), but behind content layer (1) */
  pointer-events: none;
}

/* Content layer - centered as a complete unit */
.content-layer {
  position: relative;
  z-index: var(--z-content);
  display: flex;
  flex-direction: column;
  padding-inline: var(--page-padding);
  padding-block: var(--space-xs); /* minimize vertical padding to avoid overflow */
  justify-content: center; /* center header + canvas stack vertically for equal top/bottom gap */
  flex: 1;
  min-height: 0; /* prevent overflow from flex children */
}

/* Site header with product title - much closer to card container */
.site-header {
  display: flex;
  justify-content: center;
  align-items: center;
  padding-block: 0; /* remove extra top padding */
  margin-bottom: var(--space-xs); /* small gap above canvas */
}

.product-title {
  font-size: clamp(1.75rem, 4vw, 2.5rem);
  font-weight: 600;
  text-align: center;
  color: rgba(255, 255, 255, 0.95);
}

/* Main content area - minimal spacing to keep tight title-to-canvas distance */
.main-content {
  flex: 0; /* let content size to intrinsic height so centering on parent is effective */
  display: flex;
  justify-content: center;
  align-items: stretch;
  padding-top: 0; /* remove extra top gap above card */
  min-height: auto; /* size to contents */
}

/* Card container - responsive sizing following design principles */
.card-container {
  width: 100%;
  max-width: var(--card-width-desktop);
  margin: 0 auto;
  height: auto; /* allow intrinsic height so canvas can cap itself */
  box-sizing: border-box;
  /* Visual styling will be added in Phase 4 */
}

/* Desktop card container - match canvas region width for proper centering */
@media (min-width: 1024px) {
  .card-container {
    max-width: var(--canvas-width-desktop); /* Match canvas width to maintain centering */
  }
}

/* Mobile composition - tall rectangle */
@media (max-width: 767px) {
  /* Disable fixed backgrounds on iOS/Android mobile to prevent extra scroll area */
  .app-root {
    background-attachment: scroll;
  }

  /* Also avoid fixed-position background layer issues on iOS by making it absolute */
  .background-layer {
    position: absolute;
  }

  /* Let the main content fill available space without overflowing viewport */
  .content-layer {
    flex: 1;
    min-height: 0; /* critical with flex children to prevent height overflow */
    box-sizing: border-box; /* include padding in height calculations */
    /* Cap vertical padding on mobile so total height stays under visible viewport */
    padding-inline: var(--page-padding);
    padding-block: clamp(12px, 3vh, 24px);
  }

  /* Tighten vertical spacing to avoid bottom overscroll while preserving pull-to-refresh */
  .site-header {
    margin-bottom: var(--space-xs);
  }

  .main-content {
    padding-top: 0;
  }

  .card-container {
    max-width: var(--card-width-mobile);
    min-height: auto;
    /* Move the responsive inset spacing to the container for perfectly symmetric gaps */
    padding-inline: clamp(1.25rem, 5vw, 2rem);
    box-sizing: border-box;
  }

  /* Reset canvas-region margins; width is auto so it will fill the padded container symmetrically */
  .canvas-region {
    margin: 0;
    box-sizing: border-box;
    height: var(--card-height-mobile); /* use JS-driven var(--vh) clamp; stable mobile height */
  }
}

/* Remove conflicting desktop rule - already handled above at line 129-133 */

/* Canvas region with stable height to prevent CLS */
.canvas-region {
  width: 100%;
  height: var(--card-height-mobile); /* default to mobile height; desktop override below */
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  box-sizing: border-box; /* include borders/shadows in height calc to avoid overflow */
  /* Future: Phase 5 React Flow canvas will mount here */
}

/* ===== CRITICAL iOS SAFARI FIX =====
 *
 * PROBLEM: iOS Safari has a known bug where CSS containment breaks transform composition.
 * When `contain: layout style` is active on a parent element, child elements using
 * `transform: translate(x, y)` for positioning get visually stuck at their initial
 * render position, even though the logical position updates correctly.
 *
 * SYMPTOMS ON iOS SAFARI:
 * - Nodes appear clustered at top-left corner visually
 * - Edges connect to correct (invisible) logical positions
 * - Dragging updates logical position but not visual position
 * - Desktop browsers and emulation work fine (they handle containment correctly)
 *
 * ROOT CAUSE: React Flow uses `transform: translate(x, y)` for ALL node positioning.
 * When containment creates an isolated rendering context on iOS Safari, these transforms
 * fail to update the visual layer, creating a disconnect between visual and logical layers.
 *
 * SOLUTION: Disable CSS containment on mobile devices where the bug occurs.
 * Desktop keeps containment for performance optimization since it handles it correctly.
 *
 * REFERENCES:
 * - React Flow positioning system relies on transform composition
 * - iOS Safari containment bug is well-documented in the WebKit bug tracker
 * - See also: GraphCanvas.module.css:79 which documents containment conflicts with React Flow
 */

/* Desktop: Keep CSS containment for performance optimization */
@media (min-width: 1024px) {
  .canvas-region {
    contain: layout style;
  }
}

/* Mobile: NO containment - fixes iOS Safari transform composition bug */
@media (max-width: 767px) {
  .canvas-region {
    contain: none;
  }
}

/* Desktop canvas region - more square dimensions */
@media (min-width: 1024px) {
  .canvas-region {
    width: var(--canvas-width-desktop); /* More square: ~600x600 instead of 800x600 */
    height: var(--canvas-height-desktop); /* fixed by variable; tuned via root clamp */
    max-width: var(--canvas-width-desktop); /* Override card container width */
  }
}

/* Desktop overflow guard to eliminate tiny scrollbar from subpixel rounding */
@media (min-width: 1024px) {
  html, body {
    overflow-y: hidden;
  }
}

/* IMPORTANT: Canvas Region Visual Treatment - Phase 4 Functionality Implemented Here
 *
 * This styling provides all Phase 4 objectives directly on the canvas region:
 * ✅ Light surface treatment with glassmorphism
 * ✅ Multi-layer shadow system for elevation
 * ✅ Rounded corners and generous padding
 * ✅ Responsive sizing and proper contrast
 *
 * DO NOT REMOVE: Phase 5 React Flow will replace placeholder content but
 * should preserve these visual styles for the canvas container.
 *
 * See: documentation/dev-docs/phase_4_skip_summary.md for complete rationale
 */
.placeholder-content {
  /* Fill the entire canvas-region */
  width: 100%;
  height: 100%;
  
  /* Center content within the region */
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  
  /* Visual styling */
  padding: var(--space-2xl);
  text-align: center;
  font-size: 1.125rem;
  color: rgba(255, 255, 255, 0.8);
  background: rgba(255, 255, 255, 0.95);
  border-radius: var(--space-md);
  backdrop-filter: blur(10px);
  box-shadow:
    0 1px 2px rgba(0, 0, 0, 0.04),
    0 4px 8px rgba(0, 0, 0, 0.06),
    0 12px 24px rgba(0, 0, 0, 0.08);
  
  /* Ensure it doesn't overflow the canvas-region */
  box-sizing: border-box;
}

.placeholder-content p {
  color: rgba(0, 0, 0, 0.8);
  margin: var(--space-sm) 0;
  
  /* Ensure text doesn't break the layout */
  max-width: 100%;
  word-wrap: break-word;
}

/* Responsive utilities */

/* Fluid typography base */
.fluid-text {
  font-size: clamp(1rem, 2.5vw, 1.25rem);
}


/* Print styles */
@media print {
  .background-layer {
    display: none;
  }
  
  .content-layer {
    padding: 0;
    min-height: auto;
  }
  
  .card-container {
    max-width: none;
    min-height: auto;
  }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
  .card-container {
    border: 2px solid;
  }
  
  .placeholder-content {
    border: 1px solid;
  }
}
/* Removed @supports height overrides to avoid conflicts with JS-driven --vh sizing */
/* Prefer modern dynamic viewport height when supported to match visible viewport on iOS Chrome */
@supports (height: 100dvh) {
  .app-root {
    height: 100dvh;
    min-height: auto; /* avoid stacking with existing min-height fallbacks */
  }
}

/* Glowing shimmer effect for site header title */
.shine-text {
  /* White/gray gradient sweep at 135 degrees */
  background: linear-gradient(
    135deg,
    #ffffff 0%,
    #e2e8f0 35%,
    #ffffff 50%,
    #e2e8f0 65%,
    #ffffff 100%
  );
  
  /* Clip gradient to text */
  background-clip: text;
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  
  /* Subtle graduated glow: strong near text, gentle at edges, blends with dark background */
  text-shadow:
    0 0 0.3em rgba(255, 255, 255, 0.5),
    0 0 0.6em rgba(255, 255, 255, 0.3),
    0 0 1em rgba(226, 232, 240, 0.2),
    0 0 1.5em rgba(148, 163, 184, 0.1);
  
  /* Oversized gradient for animation travel */
  background-size: 200% 100%;
}

/* Animate shimmer only when no motion preference is set */
@media (prefers-reduced-motion: no-preference) {
  .shine-text {
    animation: shimmer 3s ease-in-out infinite;
  }
}

/* Disable animation when user prefers reduced motion */
@media (prefers-reduced-motion: reduce) {
  .shine-text {
    animation: none;
  }
}

/* Shimmer keyframes - moves gradient from right to left and back */
@keyframes shimmer {
  0% {
    background-position: 200% 0;
  }
  50% {
    background-position: -200% 0;
  }
  100% {
    background-position: 200% 0;
  }
}