/* ========================================
   CSS Variables & Theme Configuration
   ======================================== */

:root {
  /* Dark theme (default) */
  --bg-gradient-start: #0f0c29;
  --bg-gradient-mid: #302b63;
  --bg-gradient-end: #24243e;
  --overlay-opacity: 0.5;

  --card-bg: rgba(255, 255, 255, 0.08);
  --card-border: rgba(255, 255, 255, 0.18);
  --card-glow: rgba(120, 100, 255, 0.3);
  --card-shadow: rgba(0, 0, 0, 0.4);

  --text-primary: #ffffff;
  --text-secondary: rgba(255, 255, 255, 0.7);
  --text-muted: rgba(255, 255, 255, 0.5);

  --tag-bg: rgba(255, 255, 255, 0.12);
  --tag-text: rgba(255, 255, 255, 0.9);

  --btn-bg: #667eea;
  --btn-text: #ffffff;
  --btn-hover: #5a6fd6;

  --nav-bg: rgba(255, 255, 255, 0.1);
  --nav-hover: rgba(255, 255, 255, 0.2);
  --nav-text: rgba(255, 255, 255, 0.8);

  --dot-inactive: rgba(255, 255, 255, 0.3);
  --dot-active: #ffffff;

  --focus-ring: rgba(102, 126, 234, 0.6);
}

[data-theme="light"] {
  --bg-gradient-start: #e0c3fc;
  --bg-gradient-mid: #8ec5fc;
  --bg-gradient-end: #f5f7fa;
  --overlay-opacity: 0.25;

  --card-bg: rgba(255, 255, 255, 0.75);
  --card-border: rgba(255, 255, 255, 0.6);
  --card-glow: rgba(102, 126, 234, 0.25);
  --card-shadow: rgba(0, 0, 0, 0.15);

  --text-primary: #1a1a2e;
  --text-secondary: rgba(26, 26, 46, 0.75);
  --text-muted: rgba(26, 26, 46, 0.5);

  --tag-bg: rgba(102, 126, 234, 0.15);
  --tag-text: #4a5568;

  --btn-bg: #667eea;
  --btn-text: #ffffff;
  --btn-hover: #5a6fd6;

  --nav-bg: rgba(0, 0, 0, 0.08);
  --nav-hover: rgba(0, 0, 0, 0.15);
  --nav-text: rgba(26, 26, 46, 0.7);

  --dot-inactive: rgba(26, 26, 46, 0.25);
  --dot-active: #667eea;

  --focus-ring: rgba(102, 126, 234, 0.5);
}

/* ========================================
   Reset & Base Styles
   ======================================== */

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

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

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

/* ========================================
   Background
   ======================================== */

.background {
  position: fixed;
  inset: 0;
  z-index: -2;
  background: url('images/bg_desktop_01.jpg') center center / cover no-repeat;
  background-color: var(--bg-gradient-start);
  transition: opacity 0.4s ease;
}

.background-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, var(--overlay-opacity));
  transition: background 0.4s ease;
}

/* ========================================
   Logo
   ======================================== */

.logo {
  position: fixed;
  top: 24px;
  left: 24px;
  z-index: 100;
  text-decoration: none;
  transition: opacity 0.2s ease;
}

.logo img {
  height: 40px;
  width: auto;
  display: block;
}

.logo:hover {
  opacity: 0.8;
}

.logo:focus {
  outline: 2px solid var(--focus-ring);
  outline-offset: 4px;
  border-radius: 4px;
}

/* ========================================
   Theme Toggle
   ======================================== */

.theme-toggle {
  position: fixed;
  top: 24px;
  right: 24px;
  z-index: 100;
  width: 48px;
  height: 48px;
  border: none;
  border-radius: 50%;
  background: var(--nav-bg);
  color: var(--text-primary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s ease, transform 0.2s ease;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

.theme-toggle:hover {
  background: var(--nav-hover);
  transform: scale(1.05);
}

.theme-toggle:focus {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
}

.theme-toggle .icon-sun,
.theme-toggle .icon-moon {
  position: absolute;
  transition: opacity 0.3s ease, transform 0.3s ease;
}

[data-theme="dark"] .theme-toggle .icon-sun {
  opacity: 1;
  transform: rotate(0deg);
}

[data-theme="dark"] .theme-toggle .icon-moon {
  opacity: 0;
  transform: rotate(-90deg);
}

[data-theme="light"] .theme-toggle .icon-sun {
  opacity: 0;
  transform: rotate(90deg);
}

[data-theme="light"] .theme-toggle .icon-moon {
  opacity: 1;
  transform: rotate(0deg);
}

/* ========================================
   Click Zones (for navigation)
   ======================================== */

.click-zone {
  position: fixed;
  top: 0;
  bottom: 0;
  width: 20%;
  z-index: 5;
  cursor: pointer;
}

.click-zone-left {
  left: 0;
}

.click-zone-right {
  right: 0;
}

/* ========================================
   Slider Container
   ======================================== */

.slider-container {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 80px 24px 100px;
  z-index: 10;
  pointer-events: none;
}

/* ========================================
   Card Styles
   ======================================== */

.slider-viewport {
  position: relative;
  width: 100%;
  max-width: 920px;
  pointer-events: auto;
  display: flex;
  align-items: center;
  justify-content: center;
}

.card {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 100%;
  transform: translate(-50%, -50%);
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: 24px;
  overflow: hidden;
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  box-shadow:
    0 0 0 1px var(--card-border),
    0 0 40px var(--card-glow),
    0 25px 50px -12px var(--card-shadow),
    0 12px 24px -8px var(--card-shadow);
  transform-style: preserve-3d;
  will-change: transform, opacity;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: box-shadow 0.3s ease;
  min-height: 0; /* allow children to size correctly in flex */
}

.card.active {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transform: translate(-50%, -50%);
}

/* Card inner wrapper (header content) */
.card-inner {
  display: flex;
  flex-direction: row;
}

.card-inner .card-image {
  flex: 0 0 45%;
  min-height: 280px;
}

.card-inner .card-content {
  flex: 1;
}

/* Expanded content (hidden by default) */
.card-expanded-content {
  display: none;
}

.card-expanded-content h3 {
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 16px;
}

.card-expanded-content p {
  color: var(--text-secondary);
  line-height: 1.7;
  margin-bottom: 16px;
}

.card-expanded-content ul {
  margin: 16px 0;
  padding-left: 24px;
  color: var(--text-secondary);
}

.card-expanded-content li {
  margin-bottom: 8px;
  line-height: 1.6;
}

.card-expanded-content strong {
  color: var(--text-primary);
}

/* Expand button */
.btn-expand {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 20px;
  background: transparent;
  color: var(--text-secondary);
  font-size: 0.9rem;
  font-weight: 500;
  text-decoration: none;
  border: 1px solid var(--card-border);
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s ease;
  margin-top: 12px;
}

.btn-expand:hover {
  background: var(--tag-bg);
  color: var(--text-primary);
}

.btn-expand:focus {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
}

/* Expanded state (FIXED: full height + no collapse) */
.card.expanded {
  position: relative;
  top: 40px;
  left: 15px;
  right: 15px;
  bottom: 15px;

  /* Force stable sizing */
  width: auto;
  height: calc(100vh - 110px);

  max-width: none;
  transform: none;
  z-index: 200;

  display: flex;
  flex-direction: column;

  /* IMPORTANT: prevent flex children from collapsing */
  min-height: 0;
  margin: 0;
}

/* Header stays at top */
.card.expanded .card-inner {
  flex: 0 0 auto;
}

/* Expanded content fills remaining space and scrolls */
.card.expanded .card-expanded-content {
  display: block;
  flex: 1 1 auto;
  min-height: 0; /* CRITICAL for proper scrolling in flex layouts */
  overflow-y: auto;
  padding: 32px;
  border-top: 1px solid var(--card-border);
  animation: expandContent 0.3s ease forwards;
}

.card.expanded .btn-expand {
  background: var(--tag-bg);
}

/* Lock body scroll when card is expanded */
body:has(.card.expanded) {
  overflow: hidden;
}

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

.card-expanded-content::-webkit-scrollbar-track {
  background: transparent;
}

.card-expanded-content::-webkit-scrollbar-thumb {
  background: var(--card-border);
  border-radius: 4px;
}

.card-expanded-content::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}

@keyframes expandContent {
  from {
    opacity: 0;
    transform: translateY(-10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Hide navigation when card is expanded */
.card.expanded ~ .nav-arrow,
body:has(.card.expanded) .nav-arrow,
body:has(.card.expanded) .dot-indicators,
body:has(.card.expanded) .click-zone {
  opacity: 0;
  pointer-events: none;
}

.card:hover {
  box-shadow:
    0 0 0 1px var(--card-border),
    0 0 60px var(--card-glow),
    0 30px 60px -12px var(--card-shadow),
    0 16px 32px -8px var(--card-shadow);
}

/* Card Image */
.card-image {
  position: relative;
  overflow: hidden;
}

.card-image-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  font-weight: 600;
  color: rgba(255, 255, 255, 0.9);
  text-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
}

/* Maintain 16:9 aspect ratio for image area */
.card-image::before {
  content: '';
  display: block;
  padding-top: 56.25%; /* 16:9 ratio */
}

/* Card Content */
.card-content {
  flex: 1;
  padding: 32px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 16px;
}

.card-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.tag {
  display: inline-block;
  padding: 6px 12px;
  background: var(--tag-bg);
  color: var(--tag-text);
  font-size: 0.75rem;
  font-weight: 500;
  border-radius: 20px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.card-title {
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.2;
}

.card-description {
  font-size: 1rem;
  color: var(--text-secondary);
  line-height: 1.7;
}

/* Contact specific styles */
.card-contact-info {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.contact-email {
  font-size: 1.125rem;
  font-weight: 600;
  color: var(--text-primary);
}

.contact-location {
  color: var(--text-muted);
  font-size: 0.95rem;
}

.btn-cta {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 14px 28px;
  background: var(--btn-bg);
  color: var(--btn-text);
  font-size: 1rem;
  font-weight: 600;
  text-decoration: none;
  border-radius: 12px;
  border: none;
  cursor: pointer;
  transition: background 0.2s ease, transform 0.2s ease;
  align-self: flex-start;
  margin-top: 8px;
}

.btn-cta:hover {
  background: var(--btn-hover);
  transform: translateY(-2px);
}

.btn-cta:focus {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
}

/* Credit Slide (minimal) */
.card-credit {
  background: transparent;
  border: none;
  box-shadow: none;
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
  min-height: 200px;
}

.card-credit:hover {
  box-shadow: none;
}

.card-credit .card-inner {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 200px;
}

.credit-content {
  text-align: center;
}

.credit-name {
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 8px;
  letter-spacing: -0.01em;
}

.credit-author {
  font-size: 1rem;
  font-weight: 400;
  font-style: italic;
  color: var(--text-secondary);
  letter-spacing: 0.02em;
}

/* ========================================
   Navigation Arrows
   ======================================== */

.nav-arrow {
  position: fixed;
  top: 50%;
  transform: translateY(-50%);
  z-index: 50;
  width: 56px;
  height: 56px;
  border: none;
  border-radius: 50%;
  background: var(--nav-bg);
  color: var(--nav-text);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  transition: background 0.2s ease, transform 0.2s ease, opacity 0.2s ease;
}

.nav-arrow:hover {
  background: var(--nav-hover);
  transform: translateY(-50%) scale(1.1);
}

.nav-arrow:focus {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
}

.nav-arrow:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

.nav-arrow:disabled:hover {
  transform: translateY(-50%);
}

.nav-arrow img {
  width: 32px;
  height: 32px;
}

.nav-arrow-left {
  left: 24px;
}

.nav-arrow-left img {
  transform: scaleX(-1);
}

.nav-arrow-right {
  right: 24px;
}

/* ========================================
   Dot Indicators
   ======================================== */

.dot-indicators {
  position: fixed;
  bottom: 32px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 50;
  display: flex;
  gap: 12px;
  padding: 12px 20px;
  background: var(--nav-bg);
  border-radius: 30px;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

.dot {
  width: 12px;
  height: 12px;
  border: none;
  border-radius: 50%;
  background: var(--dot-inactive);
  cursor: pointer;
  transition: background 0.2s ease, transform 0.2s ease;
}

.dot:hover {
  background: var(--dot-active);
  opacity: 0.7;
}

.dot:focus {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
}

.dot.active {
  background: var(--dot-active);
  transform: scale(1.2);
}

/* ========================================
   Card Animations
   ======================================== */

/* Animation states */
.card.slide-out-left {
  animation: slideOutLeft 500ms cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

.card.slide-out-right {
  animation: slideOutRight 500ms cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

.card.slide-in-left {
  animation: slideInLeft 500ms cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

.card.slide-in-right {
  animation: slideInRight 500ms cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

@keyframes slideOutLeft {
  0% {
    transform: translate(-50%, -50%) rotateY(0deg) scale(1);
    opacity: 1;
  }
  100% {
    transform: translate(calc(-50% - 70vw), -50%) rotateY(12deg) scale(0.96);
    opacity: 0;
  }
}

@keyframes slideOutRight {
  0% {
    transform: translate(-50%, -50%) rotateY(0deg) scale(1);
    opacity: 1;
  }
  100% {
    transform: translate(calc(-50% + 70vw), -50%) rotateY(-12deg) scale(0.96);
    opacity: 0;
  }
}

@keyframes slideInLeft {
  0% {
    transform: translate(calc(-50% - 70vw), -50%) rotateY(-12deg) scale(0.96);
    opacity: 0;
    visibility: visible;
  }
  100% {
    transform: translate(-50%, -50%) rotateY(0deg) scale(1);
    opacity: 1;
  }
}

@keyframes slideInRight {
  0% {
    transform: translate(calc(-50% + 70vw), -50%) rotateY(12deg) scale(0.96);
    opacity: 0;
    visibility: visible;
  }
  100% {
    transform: translate(-50%, -50%) rotateY(0deg) scale(1);
    opacity: 1;
  }
}

/* Reduced motion preference */
@media (prefers-reduced-motion: reduce) {
  .card.slide-out-left,
  .card.slide-out-right {
    animation: fadeOut 300ms ease forwards;
  }

  .card.slide-in-left,
  .card.slide-in-right {
    animation: fadeIn 300ms ease forwards;
  }

  @keyframes fadeOut {
    0% { opacity: 1; transform: translate(-50%, -50%); }
    100% { opacity: 0; transform: translate(-50%, -50%); }
  }

  @keyframes fadeIn {
    0% { opacity: 0; visibility: visible; transform: translate(-50%, -50%); }
    100% { opacity: 1; transform: translate(-50%, -50%); }
  }

  .theme-toggle,
  .nav-arrow,
  .dot,
  .btn-cta,
  .card {
    transition: none;
  }
}

/* ========================================
   Responsive Design
   ======================================== */

/* Tablet */
@media (max-width: 900px) {
  .card-inner {
    flex-direction: column;
  }

  .card-inner .card-image {
    flex: 0 0 auto;
    min-height: 200px;
  }

  .card-content {
    padding: 24px;
  }

  .card-title {
    font-size: 1.5rem;
  }

  .nav-arrow {
    width: 48px;
    height: 48px;
  }

  .nav-arrow img {
    width: 24px;
    height: 24px;
  }

  .nav-arrow-left {
    left: 16px;
  }

  .nav-arrow-right {
    right: 16px;
  }
}

/* Mobile */
@media (max-width: 600px) {
  .logo {
    top: 16px;
    left: 16px;
  }

  .logo img {
    height: 32px;
  }

  .theme-toggle {
    top: 16px;
    right: 16px;
    width: 44px;
    height: 44px;
  }

  .slider-container {
    padding: 70px 4vw 90px;
  }

  .slider-viewport {
    width: 92vw;
    max-width: none;
  }

  .card {
    border-radius: 20px;
  }

  .card-inner .card-image {
    min-height: 160px;
  }

  .card-content {
    padding: 20px;
    gap: 12px;
  }

  .card-title {
    font-size: 1.35rem;
  }

  .card-description {
    font-size: 0.9rem;
  }

  .tag {
    padding: 5px 10px;
    font-size: 0.7rem;
  }

  .nav-arrow {
    width: 40px;
    height: 40px;
  }

  .nav-arrow img {
    width: 20px;
    height: 20px;
  }

  .nav-arrow-left {
    left: 8px;
  }

  .nav-arrow-right {
    right: 8px;
  }

  .dot-indicators {
    bottom: 24px;
    padding: 10px 16px;
    gap: 10px;
  }

  .dot {
    width: 10px;
    height: 10px;
  }

  .btn-cta {
    padding: 12px 24px;
    font-size: 0.9rem;
    width: 100%;
    justify-content: center;
  }

  /* Smaller click zones on mobile */
  .click-zone {
    width: 15%;
  }
}

/* Extra small screens */
@media (max-width: 380px) {
  .slider-viewport {
    width: 94vw;
  }

  .card-content {
    padding: 16px;
  }

  .card-title {
    font-size: 1.2rem;
  }
}

/* ========================================
   Focus Visible (keyboard navigation)
   ======================================== */

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

:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
}

/* ========================================
   Selection
   ======================================== */

::selection {
  background: var(--btn-bg);
  color: white;
}

/* ========================================
   Mobile-only: whole expanded card scrolls
   ======================================== */

@media (max-width: 768px) {
  /* Fix blurry text: center without translate(-50%,-50%) */
  .card {
    transform-style: flat;
    will-change: auto;
    top: 0;
    left: 0;
    inset: 0;
    margin: auto;
    height: fit-content;
    transform: none;
  }

  .card.active {
    transform: none;
  }

  /* Animations without the -50% translate offset */
  @keyframes slideOutLeft {
    0%   { transform: scale(1); opacity: 1; }
    100% { transform: translateX(-100vw) scale(0.96); opacity: 0; }
  }
  @keyframes slideOutRight {
    0%   { transform: scale(1); opacity: 1; }
    100% { transform: translateX(100vw) scale(0.96); opacity: 0; }
  }
  @keyframes slideInLeft {
    0%   { transform: translateX(-100vw) scale(0.96); opacity: 0; visibility: visible; }
    100% { transform: none; opacity: 1; }
  }
  @keyframes slideInRight {
    0%   { transform: translateX(100vw) scale(0.96); opacity: 0; visibility: visible; }
    100% { transform: none; opacity: 1; }
  }
  @keyframes fadeOut {
    0%   { opacity: 1; transform: none; }
    100% { opacity: 0; transform: none; }
  }
  @keyframes fadeIn {
    0%   { opacity: 0; visibility: visible; transform: none; }
    100% { opacity: 1; transform: none; }
  }

  .card.expanded {
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    left: 0;
    width: 100%;
  }

  /* Disable inner scroller on mobile to avoid nested scroll */
  .card.expanded .card-expanded-content {
    overflow: visible;
    flex: 0 0 auto;
    min-height: auto;
    padding-bottom: 80px;
  }

  /* Keep toggle visible (sticky at bottom) */
  .card.expanded .btn-expand {
    position: sticky;
    bottom: 12px;
    z-index: 5;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    background: color-mix(in srgb, var(--card-bg) 80%, transparent);
    border: 1px solid var(--card-border);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18);
  }
}
