/* ========================================
   CRITICAL STYLES - ABOVE THE FOLD
   ======================================== */

/* CSS Reset and Base Styles */
*,
*::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);
  --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;
}

body {
  height: auto;
  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;
}

/* Loading screen - less intrusive, shorter duration */
@media (scripting: enabled) {
  .loading::before,
  .loading::after {
    content: '';
    position: fixed;
    z-index: 10000;
    transition: opacity 0.3s ease-out;
  }

  .loading::before {
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--color-bg);
    opacity: 0.95; /* Slightly transparent to hint at content behind */
  }

  .loading::after {
    top: 50%;
    left: 50%;
    width: 60px; /* Smaller loader */
    height: 1px;
    margin: 0 0 0 -30px;
    background: var(--color-link);
    animation: loaderAnim 1s ease-in-out infinite alternate forwards;
  }
  
  /* Ensure content is visible when not loading */
  body:not(.loading)::before,
  body:not(.loading)::after {
    opacity: 0;
    pointer-events: none;
  }
}

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

/* Critical layout styles to prevent FOUC */
.frame {
  position: fixed;
  z-index: 1000;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  width: 100%;
  height: 100vh;
  pointer-events: none;
  display: grid;
  grid-column-gap: var(--c-gap);
  grid-row-gap: 0.5rem;
  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 > * {
  pointer-events: auto;
}

.frame__title {
  grid-area: title;
  font-size: 1rem;
  margin: 0;
  font-weight: normal;
  line-height: 1.2;
  color: var(--color-text);
  text-align: left;
}

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

.frame__tags {
  grid-area: tags;
  display: flex;
  gap: 1rem;
  align-items: start;
}

/* Links styling */
a {
  color: var(--color-link);
  text-decoration: none;
}

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

/* Main content area */
main {
  min-height: 100vh;
  position: relative;
}

/* Critical carousel constraints to prevent oversizing */
.scene {
  perspective: 900px;
  position: relative;
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.carousel {
  width: 400px;
  height: 500px;
  max-width: 80vw;
  max-height: 80vh;
  position: absolute;
  top: 50%;
  left: 50%;
  margin: -250px 0 0 -200px;
  transform-style: preserve-3d;
  will-change: transform;
  transform: translateZ(-550px) rotateY(0deg);
}

.carousel__cell {
  position: absolute;
  width: 350px;
  height: 420px;
  max-width: 70vw;
  max-height: 70vh;
  left: 0;
  top: 0;
  transform-style: preserve-3d;
}

.card {
  width: 100%;
  height: 100%;
  position: relative;
  transform-style: preserve-3d;
}

/* Mobile critical fixes */
@media (max-width: 800px) {
  :root {
    font-size: 12px;
    --page-padding: 1rem;
  }
  
  body {
    font-size: 12px;
  }
  
  .frame {
    display: grid;
    grid-template-areas:
      "title links";
    grid-template-columns: 1fr auto;
    grid-template-rows: auto;
    align-items: start;
    justify-content: space-between;
    padding: var(--page-padding);
    column-gap: 1rem;
    height: auto;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: auto;
  }
  
  .frame__title {
    grid-area: title;
    text-align: left;
    margin: 0;
    font-size: 0.85rem;
    line-height: 1.2;
  }
  
  .frame__links {
    grid-area: links;
    display: flex;
    justify-content: flex-end;
    gap: 1rem;
    align-self: start;
  }
  
  .frame__tags {
    position: fixed;
    bottom: 3rem;
    left: var(--page-padding);
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
    z-index: 1000;
    grid-area: unset;
  }
}

/* Accessibility improvements */
.card[aria-label] {
  /* Ensure interactive cards are keyboard accessible */
  position: relative;
  cursor: pointer;
}

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

/* Skip link for accessibility */
.skip-link {
  position: absolute;
  top: -40px;
  left: 6px;
  background: #000;
  color: #fff;
  padding: 8px;
  text-decoration: none;
  border-radius: 4px;
  z-index: 100;
}

.skip-link:focus {
  top: 6px;
}

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

/* Focus indicators for better accessibility */
*:focus {
  outline: 2px solid var(--color-link);
  outline-offset: 2px;
}

*:focus:not(:focus-visible) {
  outline: none;
}

*:focus-visible {
  outline: 2px solid var(--color-link);
  outline-offset: 2px;
}