/* =============  CSS VARIABLES & CONFIGURATION  ============= */
:root {
  /* Layout configuration */
  --cols: 5;
  --rows: 1.75;
  --bar-thickness: 15px;
  --pane-width: calc((100% - ((var(--cols) + 1) * var(--bar-thickness))) / var(--cols));
  --pane-height: calc((100% - ((var(--rows) + 1) * var(--bar-thickness))) / var(--rows));
  
  /* Dark mode color palette (default) */
  --color-black: black;
  --color-red-primary: #ff0000;
  --color-red-dark: #560000;
  --color-red-darker: #3e0202;
  --color-text-light: #ddfff7;
  --color-text-shadow: #ffffff4e;
  --color-red-shadow: #ff00004e;
  --color-transparent: transparent;
  --color-background-gradient-start: var(--color-black);
  --color-background-gradient-mid: var(--color-black);
  --color-background-gradient-end1: var(--color-red-dark);
  --color-background-gradient-end2: var(--color-red-darker);
  --color-scene-gradient-start: #3e0202;
  --color-scene-gradient-end: #ff0000;
  --color-header-primary: #ddfff7;
  --color-header-secondary: #ddfff7;
  --color-experience-title: rgb(0, 24, 121);
  --color-experience-subtitle: #3d0101;
  --color-handwritten-text: #33497f;
  --color-handwritten-heading: #c0392b;

  /* Theme transition timing (single source of truth) */
  --theme-transition-duration: 0.6s;
  --theme-transition-ease: cubic-bezier(0.4, 0.0, 0.2, 1);

  /* Image filter controls (kept identical in both themes for smooth interpolation) */
  --img-filter-invert: 0;
  --img-filter-rotate: 0deg;
}

/* Light mode color palette */
[data-theme="light"] {
  --color-black: white;
  --color-red-primary: #0080ff;
  --color-red-dark: #e0f0ff;
  --color-red-darker: #f0f8ff;
  --color-text-light: #2c3e50;
  --color-text-shadow: #00000020;
  --color-red-shadow: #0080ff4e;
  --color-background-gradient-start: #ffffff;
  --color-background-gradient-mid: #f8f9fa;
  --color-background-gradient-end1: #e0f0ff;
  --color-background-gradient-end2: #f0f8ff;
  --color-scene-gradient-start: #f0f8ff;
  --color-scene-gradient-end: #0080ff;
  --color-header-primary: #2c3e50;
  --color-header-secondary: #34495e;
  --color-experience-title: #0080ff;
  --color-experience-subtitle: #2c3e50;

  /* Light values for image filter animation */
  --img-filter-invert: 1;
  --img-filter-rotate: 60deg;
}

/* =============  QUICK SETTINGS STACK  ============= */
/* Wrapper that anchors both language + theme toggles bottom-right with a responsive gap */
.toggle-stack {
  position: fixed;
  right: 1.25rem; /* ~20px */
  bottom: 1.25rem; /* ~20px */
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: clamp(0.5rem, 1.6vw, 0.9rem);
  z-index: 1000;
}

/* When toggles are inside the stack, they should not be fixed individually */
.toggle-stack .theme-toggle,
.toggle-stack .language-toggle {
  position: relative; /* keeps dropdown anchored to the language toggle */
  right: auto;
  bottom: auto;
}

/* =============  THEME TOGGLE BUTTON  ============= */
.theme-toggle {
  position: fixed; /* default: supports legacy layout if used alone */
  bottom: 20px;
  right: 20px;
  transform: none;
  width: 50px;
  height: 50px;
  border: none;
  border-radius: 50%;
  background: var(--color-red-primary);
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  transition: all 0.5s cubic-bezier(0.4, 0.0, 0.2, 1);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.theme-toggle:hover {
  transform: scale(1.06);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.2);
}

.theme-toggle .sun-icon {
  display: block;
}

.theme-toggle .moon-icon {
  display: none;
}

[data-theme="light"] .theme-toggle .sun-icon {
  display: none;
}

[data-theme="light"] .theme-toggle .moon-icon {
  display: block;
}

/* =============  LANGUAGE TOGGLE  ============= */
.language-toggle {
  position: fixed; /* default: supports legacy layout if used alone */
  bottom: 82px; /* legacy spacing above theme button */
  right: 20px;
  z-index: 1000;
}

.language-toggle .language-button {
  width: 50px;
  height: 50px;
  border-radius: 50%;
  border: none;
  background: var(--color-red-primary);
  color: #fff;
  font-weight: 700;
  letter-spacing: 0.5px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
  transition: transform var(--theme-transition-duration) var(--theme-transition-ease), box-shadow var(--theme-transition-duration) var(--theme-transition-ease);
}

.language-toggle:hover .language-button {
  transform: scale(1.06);
  box-shadow: 0 6px 20px rgba(0,0,0,0.2);
}

.language-toggle .language-menu {
  list-style: none;
  margin: 0;
  padding: 8px 6px;
  background: linear-gradient(145deg, rgba(10, 0, 0, 0.95), rgba(20, 5, 5, 0.92));
  border: 1px solid rgba(255,0,0,0.4);
  border-radius: 12px;
  box-shadow: 0 8px 25px rgba(255,0,0,0.25), 0 2px 10px rgba(0,0,0,0.6), inset 0 1px 0 rgba(255,255,255,0.1);
  opacity: 0;
  visibility: hidden;
  transform: translateY(8px);
  transition: all 0.25s cubic-bezier(0.23, 1, 0.32, 1);
  position: absolute;
  right: 0;
  bottom: calc(100% + 8px); /* open upward */
}

.language-toggle:hover .language-menu,
.language-toggle.open .language-menu {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.language-toggle .language-menu li {
  color: #ddfff7;
  font-family: 'Bangers', sans-serif;
  font-size: 1.1rem;
  padding: 6px 10px;
  border-radius: 8px;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.25s ease, color 0.25s ease, transform 0.2s ease;
}

.language-toggle .language-menu li[aria-selected="true"] {
  color: #ff2929;
}

.language-toggle .language-menu li:hover {
  color: #ff0000;
  background: rgba(255,0,0,0.1);
  transform: translateX(2px);
}

/* Light theme variants */
[data-theme="light"] .language-toggle .language-menu {
  background: linear-gradient(145deg, rgba(255,255,255,0.95), rgba(248,249,250,0.92));
  border: 1px solid rgba(0,128,255,0.4);
  box-shadow: 0 8px 25px rgba(0,128,255,0.25), 0 2px 10px rgba(0,0,0,0.1), inset 0 1px 0 rgba(255,255,255,0.8);
}

[data-theme="light"] .language-toggle .language-menu li {
  color: #2c3e50;
}

[data-theme="light"] .language-toggle .language-menu li[aria-selected="true"] {
  color: #2793ff;
}

[data-theme="light"] .language-toggle .language-menu li:hover {
  color: #0080ff;
  background: rgba(0,128,255,0.12);
}

/* =============  GLOBAL SCROLL BEHAVIOR & OFFSET  ============= */
html {
  scroll-behavior: smooth;
}

section {
  scroll-snap-align: center;
}

section#home,
section#about, 
section#experience,
section#education,
section#contact {
  margin-bottom: 12rem;
  scroll-snap-align: center;
}

/* =============  GLOBAL RESET  ============= */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: 'Roboto', sans-serif;
  background: linear-gradient(to bottom, var(--color-background-gradient-start) 0%, var(--color-background-gradient-mid) 80%, var(--color-background-gradient-end1) 95%, var(--color-background-gradient-end2) 100%);
  overflow-x: hidden;
  transition: background var(--theme-transition-duration) var(--theme-transition-ease);
}

main {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
  gap: 11rem;
}

/* =============  HERO SECTION  ============= */
.hero-scene {
  height: 100vh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  position: relative;
  overflow: hidden; /* prevent overlays from shifting layout */
}

.scene {
  position: relative;
  z-index: -3; /* window background behind everything */
  width: 810px;
  height: 380px;
  background: linear-gradient(var(--color-scene-gradient-start) 0%, var(--color-scene-gradient-end) 40%);
  overflow: hidden;
  z-index: -5;
  transition: background var(--theme-transition-duration) var(--theme-transition-ease);
  box-shadow: inset 0 0 0 3px var(--color-black);

}

/* FIXED TASSELS - Scale with scene width, anchor to top */
.tassels {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;           /* fill scene height */
  object-fit: cover;      /* crop from bottom/sides, keep top visible */
  object-position: top center;
  display: block;
  pointer-events: none;
  z-index: -1;          /* under dust, above curtains */
  user-select: none;
  /* Establish a defined base state and GPU hinting for smooth sync */
  filter: invert(var(--img-filter-invert)) hue-rotate(var(--img-filter-rotate)) brightness(1);
  will-change: filter;
  transition: none;
}

/* Curtains */
.curtain {
  user-select: none;        /* Prevent text selection */
  display: block;
  position: absolute;
  top: 0;
  height: 100%;
  width: auto;
  pointer-events: none;
  z-index: -2; /* above bars and plants, below dust */
  /* Establish a defined base state and GPU hinting for smooth sync */
  filter: invert(var(--img-filter-invert)) hue-rotate(var(--img-filter-rotate)) brightness(1);
  will-change: filter;
  transition: none;
}
.curtain-left  { left: 0; }
.curtain-right { right: 0; }

/* Light mode values are applied via CSS variables above for smooth interpolation */

/* Window pane bars */
.bars {
  position: absolute; 
  inset: 0;
  pointer-events: none;
  z-index: -3; /* behind curtains, above plants */
  background-image:
    repeating-linear-gradient(
      to right,
      var(--color-black) 0px calc(var(--bar-thickness) + 0.5px),
      var(--color-transparent) calc(var(--bar-thickness) + 0.5px) calc(var(--pane-width) + var(--bar-thickness))
    ),
    repeating-linear-gradient(
      to bottom,
      var(--color-black) 0px calc(var(--bar-thickness) + 0.5px),
      var(--color-transparent) calc(var(--bar-thickness) + 0.5px) calc(var(--pane-height) + var(--bar-thickness))
    );
}

/* Swaying plants under bars and curtains */
.plant1,
.plant2,
.leaf-silhouette,
.leaf-silhouette1 {
  position: absolute;
  bottom: -30%;
  height: auto;
  pointer-events: none;
  opacity: 1;
  transform-origin: bottom center;
  animation: plant-sway 7s ease-in-out infinite alternate;
  z-index: -4; /* behind bars and curtains */
  will-change: transform;
  backface-visibility: hidden;
  transform: translateZ(0);
  /* Establish a defined base state and GPU hinting for smooth sync */
  filter: invert(var(--img-filter-invert)) hue-rotate(var(--img-filter-rotate)) brightness(1);
  will-change: filter;
  transition: none;
}

.plant1 { bottom: -15%; right: -23%; animation-delay: 0s;  width: 500px; }
.plant2 { left: 45%; animation-delay: 1.2s; width: 550px; }
.leaf-silhouette  { bottom: -10%; left: -5%;  transform-origin: bottom left;  width: 300px; }  /* left bush */
.leaf-silhouette1 { bottom: -20%; right: 10%; transform-origin: middle; width: 400px; }/* middle branch */

/* Name and nickname above dust */
.name-text {
  font-family: 'Bangers', cursive;
  font-weight: 300; /* Reduced from default */
  margin-top: 2rem;
  text-align: center;
  font-size: 44px;
  line-height: 1.2;
  color: var(--color-text-light);
  text-shadow: 0 0 40px var(--color-text-shadow);
  position: relative;
  z-index: 5;
  transition: color 0.5s cubic-bezier(0.4, 0.0, 0.2, 1), text-shadow 0.5s cubic-bezier(0.4, 0.0, 0.2, 1);
}

.nickname {
  font-family: 'Bangers', cursive;
  font-weight: 300; /* Reduced from default */
  font-size: 2rem;
  color: var(--color-red-primary);
  text-shadow: 0 0 20px var(--color-red-shadow);
  position: relative;
  z-index: 5;
  transition: color 0.5s cubic-bezier(0.4, 0.0, 0.2, 1), text-shadow 0.5s cubic-bezier(0.4, 0.0, 0.2, 1);
}

/* =============  DUST LAYER  ============= */
#dust-layer {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: -1;
  pointer-events: none;
  transform: translateZ(0);
  will-change: auto;
}

/* =============  ANIMATIONS  ============= */
@keyframes branch-sway {
  0%   { transform: rotate(0deg) translate(0,0) skew(0,0); }
  25%  { transform: rotate(0.39deg) translate(1.3px,2.6px) skew(0.13deg,0); }
  50%  { transform: rotate(-0.52deg) translate(-1.3px,1.3px) skew(-0.2deg,0.07deg); }
  75%  { transform: rotate(0.26deg) translate(0,-1.3px) skew(0.07deg,-0.13deg); }
  100% { transform: rotate(0deg) translate(0,2.6px) skew(0,0); }
}

@keyframes plant-sway {
  0%   { transform: rotate(0deg) translate(0,0) skew(0,0); }
  25%  { transform: rotate(0.52deg) translate(0.65px,1.3px) skew(0.13deg,0.13deg); }
  50%  { transform: rotate(-0.39deg) translate(-0.65px,0.65px) skew(-0.13deg,0); }
  75%  { transform: rotate(0.26deg) translate(0,-0.65px) skew(0.07deg,-0.13deg); }
  100% { transform: rotate(0deg) translate(0,0) skew(0,0); }
}


/* =============  MOBILE RESPONSIVE  ============= */

@media (max-width: 768px) {
  .scene {
    width: 90vw;
    height: calc(90vw * 360 / 810);
  }

  .bars {
    background-image:
      repeating-linear-gradient(to right, var(--color-black) 0% 1.9%, var(--color-transparent) 1.9% calc(1.9% + (100% - 6 * 1.9%) / 5)),
      repeating-linear-gradient(to bottom, var(--color-black) 0% 4.2%, var(--color-transparent) 4.2% calc(4.2% + (100% - 3 * 4.2%) / 2));

/* Respect user reduced motion preference: pause sway animations */
@media (prefers-reduced-motion: reduce) {
  .plant1,
  .plant2,
  .leaf-silhouette,
  .leaf-silhouette1 {
    animation: none !important;
  }
}

/* Pause sway under Konami video overlay */
.hero-scene.konami-active .plant1,
.hero-scene.konami-active .plant2,
.hero-scene.konami-active .leaf-silhouette,
.hero-scene.konami-active .leaf-silhouette1 {
  animation: none !important;
}
  }

  .name-text { font-size: 2rem; margin-top: 15px; }
  .nickname   { font-size: 1.5rem; }
  .plant1 { width: 49.38%; }
  .plant2 { width: 67.90%; }
  .leaf-silhouette,
  .leaf-silhouette1 { width: 49.38%; }
  .curtain { height: 100%; }

  /* Adjust theme toggle for mobile */
  .theme-toggle {
    width: 45px;
    height: 45px;
  }
  .language-toggle .language-button {
    width: 45px;
    height: 45px;
  }

  .theme-toggle svg {
    width: 18px;
    height: 18px;
  }

  /* Stack spacing scales via clamp gap; no per-toggle offsets needed */
}

@media (max-width: 480px) {
  .scene {
    width: 95vw;
    height: calc(95vw * 360 / 810);
  }
  
  .name-text { font-size: 1.5rem; margin-top: 10px; }
  .nickname   { font-size: 1.2rem; }
  /* Stack spacing scales via clamp gap; no per-toggle offsets needed */

  /* Further adjust theme toggle for small mobile */
  .theme-toggle {
    width: 40px;
    height: 40px;
  }
  .language-toggle .language-button {
    width: 40px;
    height: 40px;
  }

  .theme-toggle svg {
    width: 16px;
    height: 16px;
  }
}

/* =============  KONAMI CODE EASTER EGG STYLES  ============= */
#konami-modal {
  position: absolute;
  top: 2.55rem;  /* shift modal down a little more to clear tassels */
  left: 0;
  width: 100%;
  height: calc(100% - 28px);  /* adjust height accordingly */
  z-index: -4; /* put behind decorative elements */
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s ease, visibility 0.3s ease;
}

#konami-modal.konami-show {
  opacity: 1;
  visibility: visible;
}

/* Keep iframe invisible until ready to avoid UI flash */
#konami-modal:not(.konami-ready) #konami-hero-video {
  opacity: 0;
  visibility: hidden;
}
#konami-modal.konami-ready #konami-hero-video {
  opacity: 1;
  visibility: visible;
}

#konami-modal.konami-hide {
  opacity: 0;
  visibility: hidden;
}

.konami-hero-overlay {
  position: absolute;
  inset: 0;
  animation: konamiOverlayIn 0.3s ease;
  overflow: hidden; /* contain video bleed */
  pointer-events: auto; /* allow interaction inside overlay */
  z-index: -5; /* ensure overlay is behind decorative elements */
}

#konami-hero-video {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  border: none;
  outline: none;
  pointer-events: auto; /* allow clicks on video controls */
  z-index: -6; /* ensure video is behind letterbox bars */
}

/* Letterbox bars - identical positioning and styling */
.konami-hero-overlay::before,
.konami-hero-overlay::after {
  content: '';
  position: absolute;
  top: 0;
  bottom: 0;
  width: 20%;
  background-color: black; /* Default black bars for dark mode */
  pointer-events: none;
  z-index: -5;
  transition: background-color 0.5s cubic-bezier(0.4, 0.0, 0.2, 1);
}

.konami-hero-overlay::before {
  left: 0;
}

.konami-hero-overlay::after {
  right: 0;
}

/* Light mode: show white letterbox bars */
[data-theme="light"] .konami-hero-overlay::before,
[data-theme="light"] .konami-hero-overlay::after {
  background-color: white;
}

/* Elevate the scene and Konami overlay above other hero elements when active */
.hero-scene.konami-active .scene {
  z-index: 100; /* bring scene above name text and others */
}
.hero-scene.konami-active #konami-modal {
  z-index: -3.5; /* put video behind curtains, tassels, and window bars */
}
.hero-scene.konami-active .name-text {
  pointer-events: none; /* prevent intercepting pointer over the scene */
}

/* YouTube iframe wrapper technique to hide UI elements */
.konami-frame-wrapper {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  overflow: hidden; /* Prevent page stretching */
}

.konami-frame-container {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 300%; /* Oversized to push UI elements out of view */
  height: 300%;
  transform: translate(-50%, -50%); /* Center the oversized container */
}

/* Hide YouTube controls by default, show on hover */
#konami-hero-video {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  border: none;
  outline: none;
  pointer-events: auto;
  transition: opacity 0.3s ease;
}

/* YouTube controls will show automatically on hover due to autohide=1 parameter */

/* Red multiply overlay on top of video */
.konami-red-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: var(--color-red-primary);
  mix-blend-mode: multiply;
  pointer-events: none; /* Allow clicks to pass through to video */
  z-index: 1; /* Above video but below controls */
  transition: background-color 0.5s cubic-bezier(0.4, 0.0, 0.2, 1);
}

/* Animations */
@keyframes konamiOverlayIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}