:root {
  color-scheme: dark;

  /* Base colors - fixed dark theme */
  --primary-color: #ffffff;
  --secondary-color: #03dac6;
  --background: #121212;
  --surface: #1e1e1e;
  --surface-hover: #2a2a2a;

  /* Text colors */
  --on-background: #ffffff;
  --on-surface: #ffffff;

  /* Hover states */
  --primary-hover: #d1b3ff;
  --surface-hover-color: #2a2a2a;

  /* Spacing scale */
  --space-xs: 0.25rem;
  --space-sm: 0.5rem;
  --space-md: 1rem;
  --space-lg: 1.5rem;
  --space-xl: 2rem;
  --space-2xl: 3rem;

  /* Font sizes using clamp for fluid typography */
  --text-xs: clamp(0.75rem, 0.7rem + 0.25vw, 0.875rem);
  --text-sm: clamp(0.875rem, 0.8rem + 0.375vw, 1rem);
  --text-base: clamp(1rem, 0.9rem + 0.5vw, 1.125rem);
  --text-lg: clamp(1.125rem, 1rem + 0.625vw, 1.25rem);
  --text-xl: clamp(1.25rem, 1.1rem + 0.75vw, 1.5rem);
  --text-2xl: clamp(1.5rem, 1.3rem + 1vw, 2rem);

  /* Border radius scale */
  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-xl: 16px;
  --radius-full: 50%;

  /* Shadows */
  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1),
    0 4px 6px -4px rgb(0 0 0 / 0.1);
}

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

body {
  font-family: "Namdhinggo";
  background-color: var(--background);
  color: var(--on-background);
  line-height: 1.6;
  scrollbar-gutter: stable;
  padding-bottom: 60px; /* Space for fixed social links */

  @media (prefers-reduced-motion: no-preference) {
    scroll-behavior: smooth;
  }
}

header {
  padding: var(--space-xs);
  text-align: center;
  background-color: var(--surface);
  box-shadow: var(--shadow-md);
  position: relative;
}

h1,
h2 {
  font-weight: 300;
  font-size: var(--text-2xl);
  color: var(--background);
  font-weight: 700;
}

footer {
  padding: var(--space-lg);
  text-align: center;
  margin-top: auto;
  padding-bottom: 100px; /* Space for the floating pill */
}

.social-links {
  position: fixed;
  bottom: 6px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 999;
  display: flex;
  align-items: center;
  gap: var(--space-lg);
  padding: 12px 24px;
  background-color: rgb(18 18 18 / 0.8);
  backdrop-filter: blur(8px);
  border-radius: 9999px;
  box-shadow: var(--shadow-lg);
  border: 1px solid rgb(255 255 255 / 0.1);
}

.social-links a {
  display: block;
  transition: transform 0.3s ease;
  line-height: 0;
}

.social-links a:hover {
  transform: scale(1.1);
}

.social-links img {
  width: 28px;
  height: 28px;
  filter: invert(1);
  opacity: 0.8;
  transition: opacity 0.3s ease;
}

.social-links a:hover img {
  opacity: 1;
}

@media (width >= 768px) {
  .social-links {
    gap: var(--space-xl);
    padding: 16px 32px;
  }

  .social-links img {
    width: 32px;
    height: 32px;
  }
}

#header-title {
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  background-clip: "border-box";
  padding: var(--space-xl);

  @media (width >= 2000px) {
    max-width: 1800px;
    margin-inline: auto;
  }
}

#projects-grid {
  padding: var(--space-md);
  max-width: 1800px;
  margin: 0 auto;
}



/* Theme sections for the new sectioned view */
.theme-section {
  margin-block-end: var(--space-2xl);

  @media (width >= 768px) {
    margin-block-end: calc(var(--space-2xl) * 1.5);
  }
}

.theme-section:last-child {
  margin-block-end: 0;
}

.theme-title {
  font-size: var(--text-xl);
  font-weight: 400;
  color: var(--primary-color);
  margin-block-end: var(--space-lg);
  padding-block-end: var(--space-sm);
  border-bottom: 2px solid var(--primary-color);
  text-align: center;

  @media (width >= 768px) {
    text-align: left;
    font-size: var(--text-2xl);
    margin-block-end: var(--space-xl);
  }
}

.theme-projects {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--space-md);

  @media (width >= 768px) {
    grid-template-columns: repeat(2, 1fr);
    gap: var(--space-lg);
  }

  @media (width >= 1024px) {
    grid-template-columns: repeat(3, 1fr);
  }

  @media (width >= 1440px) {
    grid-template-columns: repeat(4, 1fr);
    gap: var(--space-xl);
  }
}

.project-card {
  background-color: var(--surface);
  border-radius: var(--radius-md);
  overflow: hidden;
  box-shadow: var(--shadow-md);
  transition: transform 0.3s ease;

  &:hover {
    transform: translateY(-4px);

    .project-title {
      color: var(--primary-hover);
    }
  }

  .project-thumbnail {
    width: 100%;
    height: 200px;
    object-fit: cover;

    @media (width >= 1440px) {
      height: 250px;
    }
  }

  .project-info {
    padding: var(--space-xs);
    text-align: center;
    display: flex;
    align-items: center;
  }

  .project-title {
    font-size: var(--text-lg);
    margin-block-end: var(--space-sm);
    color: var(--on-surface);
    cursor: pointer;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    transition: color 0.3s ease;
    margin: 0 auto;
  }
}

/* Responsive images optimization */
picture {
  display: block;
  width: 100%;
  height: 100%;

  img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: opacity 0.3s ease;
  }
}

/* Image optimization and lazy loading */
img {
  image-rendering: auto;
  image-rendering: crisp-edges;
  image-rendering: -webkit-optimize-contrast;
  transition: opacity 0.3s ease;

  &[loading="lazy"] {
    transition: opacity 0.3s ease;
  }

  @media (min-resolution: 2dppx) {
    image-rendering: -webkit-optimize-contrast;
  }
}

/* Modal styles */
.modal {
  display: none;
  position: fixed;
  inset: 0;
  background-color: rgb(0 0 0 / 0.95);
  z-index: 1000;

  &.active {
    display: flex;
    justify-content: center;
    align-items: center;
  }
}

.modal-content {
  width: 100%;
  height: 100svh; /* Use small viewport height */
  display: flex;
  flex-direction: column;
  padding: var(--space-md) var(--space-xl);
  box-sizing: border-box;
  overflow: hidden;
  position: relative;

  @media (width >= 2000px) {
    margin-inline: auto;
    padding-inline: max(var(--space-xl), calc((100vw - 1800px) / 2));
  }
}

.modal-title {
  color: var(--primary-color);
  text-align: center;
  margin-block: 0 var(--space-md);
  font-size: var(--text-xl);
  font-weight: 500;
  margin: 0 auto;
}

.carousel {
  position: relative;
  flex: 1;
  display: flex;
  justify-content: center;
  align-items: center;
  margin: 0;
  min-height: 0; /* Needed for Firefox */
  overflow: hidden; /* Hide content outside bounds when zoomed */
  touch-action: none; /* Disable default touch behaviors */

  img {
    max-width: 100%;
    max-height: calc(100svh - 220px);
    object-fit: contain;
  }
}

/* Zoom wrapper for pinch-zoom functionality */
.zoom-wrapper {
  transform-origin: center center;
  transition: transform 0.1s ease-out;
  will-change: transform;

  img {
    display: block;
    user-select: none;
    -webkit-user-drag: none;
    pointer-events: none;
  }
}

.thumbnails-preview {
  height: 90px;
  margin: var(--space-md) auto 0;
  max-width: min(100%, 1200px);
  display: flex;
  gap: var(--space-sm);
  padding: var(--space-sm);
  overflow-x: auto;
  overflow-y: hidden;
  background-color: rgb(0 0 0 / 0.5);
  border-radius: var(--radius-md);
  scrollbar-width: none; /* Firefox */
  -ms-overflow-style: none; /* IE and Edge */

  /* Hide scrollbar for Chrome, Safari and Opera */
  &::-webkit-scrollbar {
    display: none;
  }

  img {
    height: 80px;
    width: auto;
    border-radius: var(--radius-sm);
    cursor: pointer;
    opacity: 0.6;
    transition: opacity 0.3s ease;

    &:hover {
      opacity: 0.8;
    }

    &.active {
      opacity: 1;
      box-shadow: 0 0 0 2px var(--primary-color);
    }
  }
}

/* Bio Modal Styles */
#context-modal .modal-content {
  max-width: 800px;
  margin: 0 auto;
  padding: var(--space-xl);
  justify-content: flex-start;
  align-items: stretch;
  overflow-y: auto;
}

.context-content {
  color: var(--on-surface);
  line-height: 1.6;
  padding: var(--space-md) 0;
}

.context-text h3 {
  color: var(--primary-color);
  font-size: var(--text-xl);
  margin-bottom: var(--space-md);
  font-weight: 600;
}

.context-text p {
  margin-bottom: var(--space-md);
  text-align: justify;
}

.context-text p:last-child {
  margin-bottom: 0;
}

/* Bio modal responsive adjustments */
@media (max-width: 768px) {
  #context-modal .modal-content {
    padding: var(--space-md);
    max-height: 90vh;
  }

  .context-text p {
    text-align: left;
  }
} /* Modal Close Button */
span.material-icons.close-button {
  position: fixed;
  inset-block-start: var(--space-md);
  inset-inline-end: var(--space-md);
  border-radius: var(--radius-full);
  background-color: rgb(0 0 0 / 0.2);
  color: white;
  border: none;
  cursor: pointer;
  z-index: 1001;
  backdrop-filter: blur(10px);
  opacity: 0.7;
  transition: all 0.3s ease;
  display: flex !important;
  align-items: center;
  justify-content: center;
  line-height: 1 !important;
  width: clamp(32px, 6vw, 64px);
  height: clamp(32px, 6vw, 64px);
  font-size: clamp(32px, 6vw, 64px) !important;

  &:hover {
    background-color: rgb(0 0 0 / 0.5) !important;
    opacity: 1 !important;
    transform: scale(1.1);
  }
}

/* Desktop Gallery Navigation Buttons */
.gallery-nav-button {
  display: none !important; /* Hidden by default and on mobile */
  position: fixed;
  inset-block-start: 50%;
  transform: translateY(-50%);
  width: 8vw;
  height: 8vw;
  min-width: 80px;
  min-height: 80px;
  max-width: 200px;
  max-height: 200px;
  border-radius: var(--radius-full);
  background-color: rgb(0 0 0 / 0.2);
  color: white;
  border: none;
  cursor: pointer;
  z-index: 1000;
  transition: all 0.3s ease;
  backdrop-filter: blur(10px);
  align-items: center;
  justify-content: center;
  opacity: 0.7;

  .material-icons {
    font-size: clamp(32px, 3.5vw, 80px);
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  &:hover {
    background-color: rgb(0 0 0 / 0.5);
    opacity: 1;
    transform: translateY(-50%) scale(1.1);
  }

  /* Only show on devices with hover capability (non-touch) */
  @media (hover: hover) and (pointer: fine) and (width >= 1024px) {
    display: flex !important;
  }

  &.gallery-nav-prev {
    inset-inline-start: 1vw;

    @media (width >= 1440px) {
      inset-inline-start: 0.5vw;
    }
  }

  &.gallery-nav-next {
    inset-inline-end: 1vw;

    @media (width >= 1440px) {
      inset-inline-end: 0.5vw;
    }
  }
}

/* Back button */
.back-button {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  padding: var(--space-md);
  margin-block-end: var(--space-md);
  background-color: var(--surface);
  border-radius: var(--radius-lg);
  cursor: pointer;
  transition: all 0.3s ease;
  color: var(--primary-color);
  font-weight: 500;
  font-size: var(--text-base);

  .material-icons {
    font-size: 1.2rem;
    width: 1.2rem;
    height: 1.2rem;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  &:hover {
    background-color: var(--surface-hover-color);
    transform: translateX(-4px);
  }
}
