*,
*::after,
*::before {
  box-sizing: border-box;
}

:root {
  font-size: 14px;
  --color-text: #fff;
  --color-bg: #0f0e0e;
  --color-link: #ffffff;
  --color-link-hover: rgba(255, 255, 255, 0.6);
  --color-turquoise: #40e0d0;
  --page-padding: 0.5rem;
  --aspect: 4/5;
  --grid-item-height: 20vh;
  --c-gap: 3rem;
  --r-gap: 3rem;
  --column: 80px;
  --column-count: 3;
  --border-radius: 4px;
}

html {
  height: 100%;
  overflow-x: hidden;
  overflow-y: auto; /* Allow vertical scrolling by default */
}

/* Hide scrollbar and disable scrolling when locked */
html.scroll-locked {
  overflow: hidden !important;
}

/* Ensure body doesn't scroll when modal is open */
body.modal-open {
  overflow: hidden !important;
  position: fixed;
  width: 100%;
  height: 100%;
}

/* Hide scrollbar but keep scroll functionality */
html.hide-scrollbar {
  scrollbar-width: none; /* Firefox */
  -ms-overflow-style: none; /* Internet Explorer 10+ */
}

html.hide-scrollbar::-webkit-scrollbar {
  width: 0;
  height: 0;
  display: none; /* Chrome, Safari, and Opera */
}

body {
  height: auto; /* Allow body to expand */
  min-height: 100%;
  width: 100%;
  font-family: 'forma-djr-mono', 'Courier New', 'Monaco', 'Consolas', monospace;
  text-transform: uppercase;
  margin: 0;
  color: var(--color-text);
  background-color: var(--color-bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

@media (scripting: enabled) {
  /* Flattened from nested syntax */
  .loading::before,
  .loading::after {
    content: '';
    position: fixed;
    z-index: 10000;
  }

  .loading::before {
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--color-bg);
  }

  .loading::after {
    top: 50%;
    left: 50%;
    width: 100px;
    height: 1px;
    margin: 0 0 0 -50px;
    background: var(--color-link);
    animation: loaderAnim 1.5s ease-in-out infinite alternate forwards;
  }
}

@keyframes loaderAnim {
  0% {
    transform: scaleX(0);
    transform-origin: 0% 50%;
  }

  50% {
    transform: scaleX(1);
    transform-origin: 0% 50%;
  }

  50.1% {
    transform: scaleX(1);
    transform-origin: 100% 50%;
  }

  100% {
    transform: scaleX(0);
    transform-origin: 100% 50%;
  }
}

a {
  text-decoration: none;
  color: var(--color-link);
  outline: none;
  cursor: pointer;
  transition: all 0.3s ease;
}

/* Only apply touch target sizing to actual interactive links */
a:not(.frame__title):not(.non-interactive) {
  min-height: 44px;
  min-width: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.5rem;
  border-radius: var(--border-radius);
}

a:hover {
  text-decoration: none;
  color: var(--color-link-hover);
}

a:focus {
  outline: 2px solid var(--color-link);
  outline-offset: 2px;
  background: rgba(255, 255, 255, 0.1);
}

a:focus:not(:focus-visible) {
  outline: none;
  background: transparent;
}

a:focus-visible {
  outline: 2px solid var(--color-link);
  outline-offset: 2px;
  background: rgba(255, 255, 255, 0.1);
}

.line {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  position: relative;
  vertical-align: top;
  padding: 0.75rem 1rem;
  transition: color 0.4s ease;
  z-index: 1;
  min-height: 44px;
  border-radius: var(--border-radius);
}

.line::before {
  background: var(--color-link);
  bottom: 0;
  content: '';
  height: 1px;
  left: 0;
  position: absolute;
  width: 100%;
  z-index: -1;
}

.line::after {
  background: var(--color-link);
  bottom: 0;
  content: '';
  height: 100%;
  left: 0;
  position: absolute;
  width: 100%;
  transform: scaleY(0);
  transform-origin: bottom center;
  transition: transform 0.4s ease;
  z-index: -1;
}

.line:hover {
  color: #000;
}

.line:hover::after {
  transform: scaleY(1);
}

.frame {
  display: grid;
  z-index: 1000;
  width: 100%;
  height: 100vh;
  position: fixed;
  grid-column-gap: var(--c-gap);
  grid-row-gap: 0.5rem;
  pointer-events: none;
  justify-items: start;
  padding: var(--page-padding);
  align-content: space-between;
  justify-content: space-between;
  align-items: end;
  grid-template-areas: 'title links' 'tags sponsor';
}

.frame .frame__title {
  font-size: inherit;
  margin: 0;
  font-weight: inherit;
  grid-area: title;
  text-align: left;
  align-self: start;
  /* Remove interactive styling */
  pointer-events: none;
  padding: 0;
  line-height: 1.2;
}

.frame .frame__links {
  display: flex;
  gap: 1rem;
  align-items: start;
  grid-area: links;
  justify-self: end;
  align-self: start;
}

.frame .frame__tags {
  display: flex;
  gap: 1rem;
  align-items: end;
  grid-area: tags;
  justify-self: start;
  align-self: end;
  flex-wrap: wrap;
}

.frame .frame__tags a,
.frame .frame__links a {
  padding: 0.75rem 1rem;
  border-radius: var(--border-radius);
  transition: background-color 0.3s ease;
  white-space: nowrap;
}

.frame .frame__tags a:hover,
.frame .frame__links a:hover {
  background-color: rgba(255, 255, 255, 0.1);
}

.frame.frame--footer {
  position: absolute;
  left: 50%;
  bottom: 50%;
  display: flex;
  min-height: 300px;
  align-items: end;
  justify-content: space-between;
}

.scene {
  perspective: 900px;
  position: relative;
  height: 100vh;
  min-height: 100vh; /* Ensure minimum height */
  display: flex;
  justify-content: center;
  align-items: center;
}

/* Ensure scene wrapper allows scrolling */
.scene-wrapper {
  position: relative;
  z-index: 1;
}

.scene__title {
  position: relative;
  z-index: 10;
  margin: 0;
}

.scene__title a {
  display: block;
}

.scene__title span {
  display: inline-block;
}

.scene__title .char {
  display: inline-block;
  transform-style: preserve-3d;
  transform-origin: 50% 0%;
}

.carousel {
  width: 400px;
  height: 500px;
  max-width: min(400px, 80vw);
  max-height: min(500px, 80vh);
  top: 50%;
  left: 50%;
  margin: -250px 0 0 -200px;
  position: absolute;
  transform-style: preserve-3d;
  will-change: transform;
  transform: translateZ(-550px) rotateY(0deg);
  /* Prevent oversizing on refresh */
  box-sizing: border-box;
}

.scene:nth-child(even) .carousel {
  transform: translateZ(-550px) rotateY(45deg);
}

.carousel__cell {
  position: absolute;
  width: 350px;
  height: 420px;
  max-width: min(350px, 70vw);
  max-height: min(420px, 70vh);
  left: 0;
  top: 0;
  transform-style: preserve-3d;
  /* Ensure cells scale with viewport */
  box-sizing: border-box;
}

.card {
  width: 100%;
  height: 100%;
  position: relative;
  transform-style: preserve-3d;
  /* Add role and accessibility support */
  cursor: pointer;
  border-radius: var(--border-radius);
  overflow: hidden;
}

.card[aria-label] {
  /* Style for cards with aria-label (acting as images) */
  position: relative;
}

.card[aria-label]:focus {
  outline: 2px solid var(--color-link);
  outline-offset: 2px;
}

.card__face {
  width: 100%;
  height: 100%;
  position: absolute;
  backface-visibility: hidden;
  background-image: var(--img);
  background-size: cover;
}

.card__face img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: var(--border-radius);
}

.card__face--back {
  transform: rotateY(180deg);
}

.preview {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100vh;
  max-height: 100vh;
  padding: 0;
  display: flex;
  flex-direction: column;
  opacity: 0;
  pointer-events: none;
  overflow: hidden;
  background: var(--color-bg);
  z-index: 9999;
}

.preview[style*="autoAlpha: 1"], .preview.active {
  pointer-events: auto;
  opacity: 1;
}

.preview__header {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  width: 100%;
  align-items: flex-end;
  justify-content: space-between;
  line-height: 1;
  padding: 2rem 15vw 1rem;
  background: var(--color-bg);
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  flex-shrink: 0;
}

.preview__content {
  flex: 1;
  overflow-y: auto !important;
  overflow-x: hidden;
  padding: 2rem 15vw 4rem;
  max-width: 100vw;
  height: 100%;
  /* Ensure smooth scrolling on all devices */
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

/* Custom scrollbar for preview content */
.preview__content::-webkit-scrollbar {
  width: 8px;
}

.preview__content::-webkit-scrollbar-track {
  background: rgba(255, 255, 255, 0.1);
  border-radius: 4px;
}

.preview__content::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.3);
  border-radius: 4px;
}

.preview__content::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.5);
}

.preview__title {
  margin-top: 1em;
}

.preview__close {
  background: none;
  text-transform: inherit;
  border: 0;
  padding: 1rem;
  margin: 0;
  font: inherit;
  cursor: pointer;
  color: var(--color-close);
  min-height: 44px;
  min-width: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--border-radius);
  transition: background-color 0.3s ease;
}

.preview__close:hover,
.preview__close:focus {
  outline: none;
  color: var(--color-link-hover);
  background-color: rgba(255, 255, 255, 0.1);
}

/* Project Content Styles */
.project-section {
  margin: 3rem 0;
  padding: 2rem 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.project-section:last-child {
  border-bottom: none;
}

.project-section h3 {
  font-size: 1.2rem;
  margin-bottom: 1rem;
  color: var(--color-link);
}

.project-highlight {
  background: rgba(255, 255, 255, 0.05);
  padding: 1.5rem;
  border-radius: var(--border-radius);
  margin: 2rem 0;
  border-left: 3px solid var(--color-link);
}

.project-process {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 2rem;
  margin: 2rem 0;
}

.process-step {
  padding: 1.5rem;
  background: rgba(255, 255, 255, 0.03);
  border-radius: var(--border-radius);
}

.process-step h4 {
  font-size: 1rem;
  margin-bottom: 0.5rem;
  color: var(--color-link);
}

.project-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1rem;
  margin: 2rem 0;
}

.stat-item {
  text-align: center;
  padding: 1rem;
  background: rgba(255, 255, 255, 0.05);
  border-radius: var(--border-radius);
}

.stat-number {
  font-size: 2rem;
  color: var(--color-link);
  display: block;
}

.stat-label {
  font-size: 0.8rem;
  opacity: 0.7;
}

.project-details {
  margin-bottom: 2rem;
  line-height: 1.6;
}

/* About page specific styles */
.preview-about .preview__content {
  max-width: 900px;
  margin: 0 auto;
  padding: 0 2rem;
}

.about-intro {
  display: flex;
  flex-direction: column;
  gap: 2rem;
  margin-bottom: 3rem;
}

.about-intro-text {
  flex: 1;
}

.about-intro-image {
  flex: 0 0 300px;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
  align-self: center;
}

.about-intro-image img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.about-philosophy {
  background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
  border-left: 4px solid #6c63ff;
  padding: 2rem;
  margin: 3rem 0;
  border-radius: 8px;
  font-style: italic;
  position: relative;
}

.about-philosophy::before {
  content: '"';
  font-size: 4rem;
  color: #6c63ff;
  position: absolute;
  top: -10px;
  left: 20px;
  font-family: serif;
}

.about-two-column {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 3rem;
  margin: 3rem 0;
}

.about-image-gallery {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1rem;
  margin: 2rem 0;
}

.about-image-item {
  position: relative;
  border-radius: 12px;
  overflow: hidden;
  aspect-ratio: 1;
  cursor: pointer;
  transition: transform 0.3s ease;
  background-size: cover;
  background-position: center;
}

.about-image-item:hover {
  transform: scale(1.05);
}

.about-image-caption {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background: linear-gradient(transparent, rgba(0, 0, 0, 0.8));
  color: white;
  padding: 1rem;
  transform: translateY(100%);
  transition: transform 0.3s ease;
  font-size: 0.9rem;
}

.about-image-item:hover .about-image-caption {
  transform: translateY(0);
}

.skills-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 2rem;
  margin: 2rem 0;
}

.skill-category {
  background: #f8f9fa;
  border-radius: 12px;
  padding: 1.5rem;
  border: 1px solid #e9ecef;
}

.skill-category h4 {
  color: #6c63ff;
  margin-bottom: 1rem;
  font-size: 1.1rem;
}

.skill-category ul {
  list-style: none;
  padding: 0;
  margin: 0;
}

.skill-category li {
  padding: 0.5rem 0;
  color: #666;
  border-bottom: 1px solid #e9ecef;
}

.skill-category li:last-child {
  border-bottom: none;
}

.grid {
  padding: 1rem 0;
  display: grid;
  grid-template-columns: repeat(var(--column-count), minmax(var(--column), 1fr));
  grid-column-gap: var(--c-gap);
  grid-row-gap: var(--r-gap);
  width: 100%;
  perspective: 900px;
}

.grid__item {
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  will-change: transform, clip-path;
  overflow: hidden;
  border-radius: var(--border-radius);
  position: relative;
  transform-style: preserve-3d;
}

/* Ensure figure elements are properly styled */
figure.grid__item {
  margin: 0;
  padding: 0;
}

.grid__item-image {
  width: 100%;
  aspect-ratio: var(--aspect);
  background-size: cover;
  background-position: 50% 50%;
  transition: opacity 0.15s cubic-bezier(0.2, 0, 0.2, 1);
  cursor: pointer;
  border-radius: var(--border-radius);
  min-height: 120px;
  /* Improve accessibility */
  border: 2px solid transparent;
  transition: border-color 0.3s ease, opacity 0.15s cubic-bezier(0.2, 0, 0.2, 1);
}

.grid__item-image:focus {
  outline: none;
  border-color: var(--color-link);
}

.grid__item-image[aria-label] {
  /* Ensure images with aria-label are treated as interactive elements */
  position: relative;
}

/* Scroll Indicator Styles */
.scroll-indicator {
  position: fixed;
  bottom: 2rem;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  z-index: 1000;
  opacity: 1;
  transition: opacity 0.3s ease, transform 0.3s ease;
  pointer-events: none;
  user-select: none;
}

.scroll-indicator.at-bottom {
  pointer-events: auto;
  cursor: pointer;
  padding: 1rem;
  border-radius: 25px;
  min-height: 44px;
  transition: background-color 0.3s ease;
}

.scroll-indicator.at-bottom:hover {
  background: rgba(255, 255, 255, 0.1);
}

.scroll-indicator.at-bottom:hover .scroll-arrow {
  transform: rotate(180deg) scale(1.1);
  animation: bounceFlippedHover 2s infinite;
}

.scroll-indicator.hidden {
  opacity: 0;
  transform: translateX(-50%) translateY(20px);
}

.scroll-text {
  font-size: 0.9rem;
  color: var(--color-link);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  background: rgba(0, 0, 0, 0.8);
  padding: 0.5rem 1rem;
  border-radius: 20px;
  backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.1);
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
  transition: background 0.3s ease, transform 0.3s ease;
}

.scroll-arrow {
  font-size: 1.2rem;
  color: var(--color-link);
  animation: bounce 2s infinite;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.5);
  transition: transform 0.3s ease;
}

.scroll-indicator.at-bottom .scroll-arrow {
  transform: rotate(180deg);
  animation: bounceFlipped 2s infinite;
}

/* Update text content when at bottom */
.scroll-indicator.at-bottom .scroll-text::after {
  content: "Scroll to top";
}

.scroll-indicator:not(.at-bottom) .scroll-text::after {
  content: "Scroll to explore";
}

/* Hide the original text content and use ::after for dynamic text */
.scroll-indicator .scroll-text {
  font-size: 0; /* Hide original text */
}

.scroll-indicator .scroll-text::after {
  font-size: 0.9rem; /* Restore font size for pseudo-element */
}

@keyframes bounce {
  0%, 20%, 50%, 80%, 100% {
    transform: translateY(0);
  }
  40% {
    transform: translateY(-10px);
  }
  60% {
    transform: translateY(-5px);
  }
}

@keyframes bounceFlipped {
  0%, 20%, 50%, 80%, 100% {
    transform: rotate(180deg) translateY(0);
  }
  40% {
    transform: rotate(180deg) translateY(-10px);
  }
  60% {
    transform: rotate(180deg) translateY(-5px);
  }
}

@keyframes bounceFlippedHover {
  0%, 20%, 50%, 80%, 100% {
    transform: rotate(180deg) scale(1.1) translateY(0);
  }
  40% {
    transform: rotate(180deg) scale(1.1) translateY(-10px);
  }
  60% {
    transform: rotate(180deg) scale(1.1) translateY(-5px);
  }
}