:root {
  /* Configurable animation timing */
  --flip-duration: 200ms;
  --sequential-delay: 100ms;
  --bg-animation-duration: 20s;
  
  /* Holographic effect */
  --holo-speed: 3s;
  --gyro-sensitivity: 0.1;
  
  /* Color system */
  --primary-gradient: linear-gradient(45deg, #f7eaff 0%, #fde2ea 100%);
  --text-primary: #2d1b69;
  --text-secondary: #6366f1;
  --focus-color: #4f46e5;
  --card-shadow: 0 8px 25px rgba(0, 0, 0, 0.15);
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
  line-height: 1.6;
  color: var(--text-primary);
  min-height: 100vh;
  background: var(--primary-gradient);
  position: relative;
  overflow-x: hidden;
}

/* Faster animated background for workshop projection */
body::before {
  content: '';
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: -1;
  background: 
    radial-gradient(ellipse 80% 60% at 5% 40%, rgba(175, 109, 255, 0.48), transparent 67%),
    radial-gradient(ellipse 70% 60% at 45% 45%, rgba(255, 100, 180, 0.41), transparent 67%),
    radial-gradient(ellipse 62% 52% at 83% 76%, rgba(255, 235, 170, 0.44), transparent 63%),
    radial-gradient(ellipse 60% 48% at 75% 20%, rgba(120, 190, 255, 0.36), transparent 66%),
    var(--primary-gradient);
  animation: backgroundShift 12s ease-in-out infinite;
}

@keyframes backgroundShift {
  0% { 
    filter: hue-rotate(0deg) saturate(1.0) brightness(1.0);
  }
  25% { 
    filter: hue-rotate(8deg) saturate(1.1) brightness(1.05);
  }
  50% { 
    filter: hue-rotate(18deg) saturate(0.9) brightness(0.95);
  }
  75% { 
    filter: hue-rotate(25deg) saturate(1.2) brightness(1.1);
  }
  100% { 
    filter: hue-rotate(30deg) saturate(1.0) brightness(1.0);
  }
}

/* Screen reader only */
.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;
}

/* Main layout with mobile optimization */
main {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0.5rem;
  min-height: auto;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  gap: 0.25rem;
}

@media (min-width: 768px) {
  main {
    padding: 2rem 1rem;
    min-height: calc(100vh - 120px);
    justify-content: flex-start;
    gap: 1rem;
  }
}

header {
  text-align: center;
  margin-bottom: 0;
  flex-shrink: 0;
}

/* Desktop: side-by-side layout */
@media (min-width: 768px) {
  header {
    margin-bottom: 1rem;
  }
  
  .header-content {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 2rem;
    align-items: center;
    text-align: left;
    max-width: 1000px;
    margin: 0 auto;
  }
  
  .header-content h1 {
    margin-bottom: 0;
    justify-self: start;
  }
  
  .header-content p {
    justify-self: start;
    margin: 0;
  }
}

h1 {
  font-size: clamp(1.5rem, 4vw, 3.5rem);
  font-weight: 700;
  margin-bottom: 0.5rem;
  background: linear-gradient(135deg, var(--text-primary), var(--text-secondary));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

@media (min-width: 768px) {
  h1 {
    font-size: clamp(2.5rem, 5vw, 3.5rem);
    margin-bottom: 1rem;
  }
}

header p {
  font-size: 1rem;
  max-width: calc(100% - 80px); /* Account for CTA on mobile */
  margin: 0 auto 1.5rem auto;
  opacity: 0.8;
  padding-right: 0.5rem; /* Extra clearance on mobile */
}

@media (min-width: 768px) {
  header p {
    font-size: 1.1rem;
    max-width: 600px;
    margin: 0 auto;
    padding-right: 0;
  }
}

/* Controls */
.controls {
  text-align: center;
  margin-bottom: 1.5rem;
  flex-shrink: 0;
}

@media (min-width: 768px) {
  .controls {
    margin-bottom: 0;
  }
}

.primary-button {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  border: none;
  padding: 1rem 2rem;
  font-size: 1.1rem;
  font-weight: 600;
  border-radius: 50px;
  cursor: pointer;
  transition: all 0.3s ease;
  box-shadow: 0 4px 15px rgba(102, 126, 234, 0.4);
  position: relative;
  overflow: hidden;
}

.primary-button:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 25px rgba(102, 126, 234, 0.6);
}

/* Hide focus outline by default (mouse users) */
.primary-button:focus {
  outline: none;
}

/* Show focus outline only for keyboard users */
body.keyboard-navigation .primary-button:focus {
  outline: 4px dashed #667eea;
  outline-offset: 4px;
  animation: focusGlow 2s ease-in-out infinite alternate;
}

.primary-button:active {
  transform: translateY(0);
}

/* Card grid - direct placement with optimized mobile spacing */
.card-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.5rem;
  max-width: 95vw;
  margin: 0 auto;
  flex: 0 0 auto;
  padding: 0.5rem 0.5rem 1rem 0.5rem;
  place-items: center;
  align-content: center;
}

@media (min-width: 768px) {
  .card-grid {
    gap: 2rem;
    max-width: 80vw;
    padding: 1rem;
    flex: 1;
  }
}

@media (min-width: 1200px) {
  .card-grid {
    gap: 2.5rem;
    max-width: 70vw;
  }
}

/* Cards - direct img elements with subtle drop shadows */
.card {
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: 30vh;
  cursor: pointer;
  border-radius: 20px; /* Match PNG corner radius */
  transition: opacity 0.3s ease-out, transform 0.2s ease-out, filter 0.2s ease-out;
  display: block;
  object-fit: contain;
  filter: drop-shadow(0 4px 12px rgba(0, 0, 0, 0.15));
}

@media (min-width: 768px) {
  .card {
    max-height: 40vh;
  }
}

@media (min-width: 1200px) {
  .card {
    max-height: 45vh;
  }
}

.card:hover {
  transform: scale(1.02);
  filter: drop-shadow(0 8px 20px rgba(0, 0, 0, 0.25));
}

/* Hide focus outline by default (mouse users) */
.card:focus {
  outline: none;
}

/* Show whimsical focus outline only for keyboard users */
body.keyboard-navigation .card:focus {
  outline: 4px dashed;
  outline-color: #ff6b6b;
  outline-offset: 6px;
  border-radius: 20px;
  animation: focusGlow 2s ease-in-out infinite alternate;
}

@keyframes focusGlow {
  0% { 
    outline-color: #ff6b6b; 
    outline-width: 3px; 
  }
  25% { 
    outline-color: #4ecdc4; 
    outline-width: 4px; 
  }
  50% { 
    outline-color: #45b7d1; 
    outline-width: 5px; 
  }
  75% { 
    outline-color: #96ceb4; 
    outline-width: 4px; 
  }
  100% { 
    outline-color: #feca57; 
    outline-width: 3px; 
  }
}

.card:active {
  transform: scale(0.98);
}

/* Fade transition for card changes */
.card.changing {
  opacity: 0.3;
}

/* Card containers and cards should display properly now */

/* Card animations */
.card.animating {
  pointer-events: none;
}

/* Sequential animation delays */
.card[data-category="Arketyp"] {
  animation-delay: 0ms;
}

.card[data-category="Egenskap"] {
  animation-delay: calc(var(--sequential-delay) * 1);
}

.card[data-category="Handling"] {
  animation-delay: calc(var(--sequential-delay) * 2);
}

.card[data-category="Objekt"] {
  animation-delay: calc(var(--sequential-delay) * 3);
}

/* Fixed Holographic CTA - position based on screen size */
.holographic-cta {
  position: fixed;
  bottom: 2rem;
  right: 2rem;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 70px;
  height: 70px;
  font-size: 0.9rem;
  font-weight: bold;
  text-decoration: none;
  color: white;
  background: 
    radial-gradient(circle at 30% 30%, rgba(255, 255, 255, 0.3) 0%, transparent 60%),
    linear-gradient(135deg, #1a1a2e, #16213e, #0f3460, #533483);
  border: 2px solid rgba(255, 255, 255, 0.2);
  border-radius: 50%;
  overflow: hidden;
  transition: all 0.3s ease;
  transform: perspective(500px) rotateX(var(--rotate-x, 0deg)) rotateY(var(--rotate-y, 0deg));
  box-shadow: 
    0 15px 40px rgba(0, 0, 0, 0.5),
    inset 0 3px 8px rgba(255, 255, 255, 0.2);
  cursor: pointer;
}

/* Desktop: upper-right, larger */
@media (min-width: 769px) {
  .holographic-cta {
    top: 2rem;
    bottom: auto;
    width: 100px;
    height: 100px;
    font-size: 1.2rem;
  }
}

/* Mobile: upper-right, smaller size */
@media (max-width: 768px) {
  .holographic-cta {
    top: 0.5rem;
    bottom: auto;
    right: 0.5rem;
    width: 60px;
    height: 60px;
    font-size: 0.8rem;
  }
}

.holographic-cta:hover {
  transform: scale(1.05) perspective(500px) rotateX(var(--rotate-x, 0deg)) rotateY(var(--rotate-y, 0deg));
}


/* Hide focus outline by default (mouse users) */
.holographic-cta:focus {
  outline: none;
}

/* Show focus outline only for keyboard users */
body.keyboard-navigation .holographic-cta:focus {
  outline: 4px dashed #4ecdc4;
  outline-offset: 4px;
  animation: focusGlow 2s ease-in-out infinite alternate;
}

.cta-text {
  position: relative;
  z-index: 3;
  pointer-events: none;
  color: #f8f9fa;
  text-shadow: 0 0 10px rgba(255, 255, 255, 0.5);
  font-size: 1.05em;
}

/* Multi-layer holographic effect - slower and more subtle */
.holo-effect {
  position: absolute;
  top: -50%;
  left: -50%;
  right: -50%;
  bottom: -50%;
  background: 
    radial-gradient(circle at var(--pointer-x, 50%) var(--pointer-y, 50%), 
      rgba(255, 255, 255, 0.4) 0%,
      rgba(255, 0, 255, 0.2) 20%,
      rgba(0, 255, 255, 0.2) 40%,
      rgba(255, 255, 0, 0.15) 60%,
      transparent 70%);
  opacity: 0.3;
  border-radius: 50%;
  animation: holoRotate 8s ease-in-out infinite;
  transform: perspective(500px) rotateX(var(--rotate-x, 0deg)) rotateY(var(--rotate-y, 0deg));
  filter: blur(2px);
  mix-blend-mode: screen;
}


/* Additional shimmer layer - much slower and subtle */
.holographic-cta::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(45deg,
    transparent 40%,
    rgba(255, 255, 255, 0.2) 50%,
    transparent 60%);
  border-radius: 50%;
  animation: shimmer 6s linear infinite;
  mix-blend-mode: overlay;
}

.holographic-cta::after {
  content: '';
  position: absolute;
  top: 10%;
  left: 10%;
  right: 60%;
  bottom: 60%;
  background: radial-gradient(ellipse, rgba(255, 255, 255, 0.3) 0%, transparent 60%);
  border-radius: 50%;
  animation: highlight 8s ease-in-out infinite alternate;
}


/* Slower, more subtle holographic animations to reduce distraction */
@keyframes holoRotate {
  0% { transform: rotate(0deg) scale(1.0); }
  20% { transform: rotate(72deg) scale(1.1); }
  40% { transform: rotate(144deg) scale(0.95); }
  60% { transform: rotate(216deg) scale(1.05); }
  80% { transform: rotate(288deg) scale(1.0); }
  100% { transform: rotate(360deg) scale(1.0); }
}

@keyframes shimmer {
  0% { transform: translateX(-150%) rotate(30deg) scale(0.9); opacity: 0.1; }
  25% { transform: translateX(-75%) rotate(35deg) scale(1.0); opacity: 0.3; }
  50% { transform: translateX(0%) rotate(30deg) scale(1.1); opacity: 0.2; }
  75% { transform: translateX(75%) rotate(25deg) scale(1.0); opacity: 0.4; }
  100% { transform: translateX(150%) rotate(30deg) scale(0.9); opacity: 0.1; }
}

@keyframes highlight {
  0% { opacity: 0.1; transform: scale(0.8); }
  33% { opacity: 0.3; transform: scale(1.1); }
  66% { opacity: 0.15; transform: scale(0.9); }
  100% { opacity: 0.1; transform: scale(0.8); }
}



/* Footer with mobile optimization */
footer {
  background: transparent;
  border-top: 1px solid rgba(255, 255, 255, 0.2);
  padding: 1rem;
  text-align: center;
  flex-shrink: 0;
  margin-top: auto;
}

@media (min-width: 768px) {
  footer {
    background: rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(10px);
    padding: 2rem;
    margin-top: auto;
  }
}

.footer-content p {
  margin-bottom: 0.5rem;
}

footer a {
  color: var(--text-secondary);
  text-decoration: none;
  font-weight: 500;
}

footer a:hover {
  text-decoration: underline;
}

footer a:focus {
  outline: 2px solid var(--focus-color);
  outline-offset: 2px;
  border-radius: 3px;
}

/* Reduced motion preferences */
@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
  
  .card {
    transition: transform 0.1s ease;
  }
  
  .holographic-cta {
    transform: none;
    animation: none;
  }
  
  .holographic-cta:hover {
    transform: scale(1.02);
  }
  
  body::before {
    animation: none;
  }
}

/* High contrast mode */
@media (prefers-contrast: high) {
  :root {
    --text-primary: #000;
    --text-secondary: #000;
    --focus-color: #000;
  }
  
  body.keyboard-navigation .card:focus {
    outline: 4px solid #000;
  }
  
  body.keyboard-navigation .primary-button:focus,
  body.keyboard-navigation .holographic-cta:focus {
    outline: 4px solid #000;
  }
}