/* =============================================================================
   CSS CUSTOM PROPERTIES & VARIABLES
   ============================================================================= */

:root {
  /* Colors */
  --bg-color: #ffffff;
  --text-color: #111111;
  --focus-outline-color: #005fcc;
  --keyword-hover-color: #555555;
  --pulsating-circle-color: rgba(0, 0, 0, 0.1);
  --link-underline-hover-bg: rgba(17, 17, 17, 0.4);
  --logo-filter: none;
  --noise-opacity: 0.03;
  --theme-toggle-hover-bg: rgba(128, 128, 128, 0.1);

  /* Spacing */
  --spacing-xs: 0.25rem;
  --spacing-sm: 0.5rem;
  --spacing-md: 1rem;
  --spacing-lg: 2rem;
  --spacing-xl: 4rem;

  /* Typography */
  --font-size-base: 1.125rem;
  --font-size-sm: 1rem;
  --font-size-xs: 0.9rem;
  --font-size-xxs: 0.85rem;
  --font-weight-normal: 400;
  --font-weight-semibold: 600;
  --font-weight-bold: 700;

  /* Layout */
  --logo-size: 40px;
  --logo-size-mobile: 32px;
  --theme-button-height: 40px;
  --theme-button-height-mobile: 32px;
  --circle-size: 20px;
  --circle-container-size: 100px;
  --circle-container-size-mobile: 80px;

  /* Animation */
  --animation-duration-fast: 0.2s;
  --animation-duration-normal: 0.3s;
  --animation-duration-slow: 0.6s;
  --animation-duration-flip: 0.6s;
  --animation-duration-pulse: 4s;
  --animation-easing-smooth: cubic-bezier(0.45, 0, 0.55, 1);
  --animation-easing-flip: cubic-bezier(0.32, 0.72, 0, 1);
}

html.dark-mode {
  --bg-color: #111111;
  --text-color: #ffffff;
  --focus-outline-color: #60afff;
  --keyword-hover-color: #bbbbbb;
  --pulsating-circle-color: rgba(255, 255, 255, 0.1);
  --link-underline-hover-bg: var(--keyword-hover-color);
  --logo-filter: invert(1) hue-rotate(180deg);
  --noise-opacity: 0.02;
}

/* =============================================================================
   ACCESSIBILITY - REDUCED MOTION SUPPORT
   ============================================================================= */

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }

  body {
    animation: none !important;
  }

  .flipper {
    transition: none !important;
  }

  .pulsating-circle {
    animation: none !important;
  }

  .theme-icon .sun,
  .theme-icon .moon,
  .theme-icon .sun-body,
  .theme-icon .sun-rays {
    transition: none !important;
  }
}

/* =============================================================================
   RESET & BASE STYLES
   ============================================================================= */

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

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border-width: 0;
}

body {
  font-family: 'Inter', sans-serif;
  background-color: var(--bg-color);
  color: var(--text-color);
  line-height: 1.6;
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  animation: fadeIn 0.8s ease-out both;
  transition: background-color var(--animation-duration-normal), 
              color var(--animation-duration-normal);
  position: relative;
}

body::before {
  content: "";
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  opacity: var(--noise-opacity);
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noiseFilter'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.65' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noiseFilter)'/%3E%3C/svg%3E");
  pointer-events: none;
  z-index: -1;
  transition: opacity var(--animation-duration-normal) ease-in-out;
}

/* =============================================================================
   ANIMATIONS
   ============================================================================= */

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

@keyframes pulse {
  0% {
    transform: scale(0.5);
    opacity: 0;
  }
  50% {
    opacity: 1;
  }
  100% {
    transform: scale(2.5);
    opacity: 0;
  }
}

@keyframes quickRipple {
  0% {
    transform: scale(0.3);
    opacity: 0;
  }
  20% { 
    opacity: 0.7;
  }
  100% { 
    transform: scale(3.0);
    opacity: 0;
  }
}

/* =============================================================================
   LAYOUT COMPONENTS
   ============================================================================= */

main {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: flex-start;
  max-width: 800px;
  margin: 0 auto;
  text-align: left;
  padding: 0 var(--spacing-lg);
  position: relative; 
  z-index: 1;
}

/* =============================================================================
   SITE LOGO
   ============================================================================= */

.site-logo-container {
  position: fixed;
  top: calc(var(--spacing-md) + env(safe-area-inset-top, 0px));
  left: calc(var(--spacing-md) + env(safe-area-inset-left, 0px));
  z-index: 1000;
  display: block;
  border-radius: 4px;
}

.site-logo-image {
  display: block;
  width: var(--logo-size); 
  height: var(--logo-size); 
  object-fit: contain;
  transition: filter var(--animation-duration-normal) ease-in-out;
  filter: var(--logo-filter);
}

/* =============================================================================
   THEME TOGGLE BUTTON
   ============================================================================= */

.theme-toggle {
  position: fixed; 
  top: calc(var(--spacing-md) + env(safe-area-inset-top, 0px));
  right: calc(var(--spacing-md) + env(safe-area-inset-right, 0px));
  height: var(--theme-button-height);
  background: none;
  border: 1px solid transparent;
  padding: var(--spacing-xs) var(--spacing-sm);
  border-radius: 6px;
  color: var(--text-color);
  font-size: var(--font-size-xs);
  display: flex;
  align-items: center;
  gap: var(--spacing-sm);
  cursor: pointer;
  font-family: 'Inter', sans-serif;
  transition: background-color var(--animation-duration-fast), 
              border-color var(--animation-duration-fast), 
              color var(--animation-duration-normal); 
  z-index: 1000; 
}

.theme-toggle:hover {
  background-color: var(--theme-toggle-hover-bg); 
}

.theme-icon {
  overflow: visible; 
}

.theme-icon .sun {
  transform-origin: center;
  transition: transform var(--animation-duration-slow) var(--animation-easing-smooth), 
              opacity 0.4s 0.05s ease-out;
  opacity: 1;
  transform: rotate(0deg) scale(1);
}

.theme-icon .sun-body { 
  transition: transform var(--animation-duration-slow) var(--animation-easing-smooth);
}

.theme-icon .sun-rays {
  transition: transform var(--animation-duration-slow) var(--animation-easing-smooth);
}

.theme-icon .moon {
  transform-origin: center;
  transition: transform var(--animation-duration-slow) var(--animation-easing-smooth), 
              opacity 0.4s ease-out;
  opacity: 0;
  transform: rotate(-30deg) scale(0.5);
}

html.dark-mode .theme-icon .sun {
  opacity: 0;
  transform: rotate(90deg) scale(0.5);
}

html.dark-mode .theme-icon .moon {
  opacity: 1;
  transform: rotate(0deg) scale(1);
  transition-delay: 0.05s; 
}

/* =============================================================================
   TYPOGRAPHY & TEXT COMPONENTS
   ============================================================================= */

.name-title {
  font-size: var(--font-size-base); 
  font-weight: var(--font-weight-normal); 
  margin-bottom: var(--spacing-xl);
  color: var(--text-color);
  perspective: 800px; 
  display: inline-block; 
  cursor: pointer; 
}

.flipper {
  display: inline-grid; 
  position: relative; 
  transform-style: preserve-3d; 
  transition: transform var(--animation-duration-flip) var(--animation-easing-flip); 
  min-height: 1.2em; 
}

.flipper.is-flipped { 
  transform: rotateX(180deg); 
}

@media (hover: hover) and (pointer: fine) {
  .name-title:hover .flipper { 
    transform: rotateX(180deg);
  }
}

.flipper-front,
.flipper-back {
  grid-column: 1; 
  grid-row: 1;    
  backface-visibility: hidden; 
  -webkit-backface-visibility: hidden; 
  font: inherit; 
  color: inherit; 
  white-space: nowrap; 
  display: block; 
  text-align: left; 
}

.flipper-back {
  transform: rotateX(180deg) translateZ(1px); 
}

p {
  font-size: var(--font-size-base); 
  margin-bottom: var(--spacing-md);
}

.first-paragraph {
  margin-bottom: var(--spacing-md); 
}

.second-paragraph {
  margin-bottom: var(--spacing-lg); 
}

.keyword {
  display: inline-block; 
  transition: color var(--animation-duration-normal) ease;
}

.keyword:hover {
  color: var(--keyword-hover-color); 
}

/* =============================================================================
   LINKS
   ============================================================================= */

.inline-link {
  font-size: var(--font-size-base); 
  color: var(--text-color);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
  position: relative; 
  border-radius: 2px; 
  transition: color var(--animation-duration-normal) ease;
}

.inline-link::after {
  content: "";
  position: absolute;
  left: 0;
  bottom: -3px; 
  width: 0; 
  height: 4px; 
  background-color: var(--link-underline-hover-bg);
  transition: width 0.4s ease, 
              background-color var(--animation-duration-normal) ease;
  border-radius: 2px;
}

.inline-link:hover::after {
  width: 100%; 
}

/* =============================================================================
   PULSATING CIRCLES
   ============================================================================= */

.pulsating-circles-container {
  position: fixed; 
  bottom: calc(20px + env(safe-area-inset-bottom, 0px));
  right: calc(20px + env(safe-area-inset-right, 0px));
  width: var(--circle-container-size);
  height: var(--circle-container-size);
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: auto; 
  cursor: pointer; 
  z-index: 2; 
}

.pulsating-circle {
  position: absolute; 
  border: 2px solid var(--pulsating-circle-color);
  border-radius: 50%;
  animation: pulse var(--animation-duration-pulse) ease-out infinite; 
  opacity: 0; 
  pointer-events: none; 
}

.pulsating-circle:nth-child(1) {
  width: var(--circle-size);
  height: var(--circle-size);
  animation-delay: 0s;
}

.pulsating-circle:nth-child(2) {
  width: var(--circle-size);
  height: var(--circle-size);
  animation-delay: 1s;
}

.pulsating-circle:nth-child(3) {
  width: var(--circle-size);
  height: var(--circle-size);
  animation-delay: 2s;
}

/* =============================================================================
   FOCUS STYLES - WCAG COMPLIANT
   ============================================================================= */

.theme-toggle:focus-visible,
.inline-link:focus-visible,
.name-title:focus-visible, 
.keyword:focus-visible,
.site-logo-container:focus-visible { 
  outline: 2px solid var(--focus-outline-color);
  outline-offset: 2px;
}

/* =============================================================================
   RESPONSIVE DESIGN
   ============================================================================= */

@media (max-width: 600px) {
  .site-logo-container {
    top: calc(var(--spacing-sm) + env(safe-area-inset-top, 0px));
    left: calc(var(--spacing-sm) + env(safe-area-inset-left, 0px));
  }

  .site-logo-image {
    width: var(--logo-size-mobile);
    height: var(--logo-size-mobile);
  }

  .name-title {
    font-size: var(--font-size-base); 
    margin-bottom: var(--spacing-lg);
  }

  .first-paragraph {
    margin-bottom: var(--spacing-lg); 
  }

  p, .inline-link { 
    font-size: var(--font-size-sm); 
  }

  .theme-toggle {
    height: var(--theme-button-height-mobile);
    font-size: var(--font-size-xxs);
    padding: var(--spacing-xs) 0.4rem;
    top: calc(var(--spacing-sm) + env(safe-area-inset-top, 0px)); 
    right: calc(var(--spacing-sm) + env(safe-area-inset-right, 0px));
  }

  .pulsating-circles-container {
    bottom: calc(15px + env(safe-area-inset-bottom, 0px));
    right: calc(15px + env(safe-area-inset-right, 0px));
    width: var(--circle-container-size-mobile);
    height: var(--circle-container-size-mobile);
  }

  .pulsating-circle {
    border-width: 1px; 
  }
}