:root {
  color-scheme: light dark;
}

html,
body {
  height: 100%;
  overflow: hidden;
}

body {
  margin: 0;
  font-family: 'Faustina', Georgia, 'Times New Roman', Times, serif;
  background: radial-gradient(circle at center, #81c8fb, #0066b0, #000f1a) no-repeat fixed;
  background-size: cover;
  font-size: clamp(18px, 2.2vw, 20px);
}

main {
  max-width: 960px;
  margin: 4rem auto 2rem auto;
  padding: 0 1.25rem;
}

h1 {
  font-size: clamp(28px, 7vw, 40px);
  margin-bottom: 0.5rem;
}

p {
  opacity: 0.8;
}

.card-page {
  display: grid;
  gap: 1.5rem;
}

#card-stage {
  display: grid;
  place-items: center;
  min-height: 50vh;
  position: relative;
}

#card-stage::before {
  content: '';
  position: absolute;
  inset: 0;
  background-image: url('https://i.pecards.co.za/static/images/loading_swirl1.png'), url('https://i.pecards.co.za/static/images/loading_swirl2.png');
  background-position: center;
  background-repeat: no-repeat;
  background-size: contain;
  animation: spin-dual 9s linear infinite;
  pointer-events: none;
  z-index: 0;
}

@keyframes spin-dual {
  from {
    transform: rotate(0deg);
  }
  to {
    transform: rotate(360deg);
  }
}

.card-3d {
  width: min(74vw, 320px);
  height: calc(min(74vw, 320px) * 1.4);
  position: relative;
  transform-style: preserve-3d;
  transform: rotateY(-12deg) rotateX(6deg);
  transition: transform 120ms ease-out;
  cursor: grab;
  z-index: 1;
}

.card-3d:hover {
  transform: rotateY(-6deg) rotateX(3deg) scale(1.02);
}

.card-face {
  position: absolute;
  inset: 0;
  /* use generic card back artwork behind the framed image */
  background: url('/static/images/card_back.jpg') center / cover no-repeat #fff4cc;
  backface-visibility: hidden;
  border-radius: 12px;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.55), 0 6px 16px rgba(0, 0, 0, 0.35);
}

.card-image {
  position: absolute;
  inset: 10px 10px 50px 10px;
  background-size: cover;
  background-position: center;
  border-radius: 8px;
}

.card-frame-border {
  position: absolute;
  inset: 10px 10px 50px 10px;
  /* larger bottom edge space */
  border: 1px solid rgba(0, 0, 0, 0.9);
  /* fine solid black line */
  border-radius: 10px;
  box-shadow: none;
}

.card-plaque {
  position: absolute;
  left: 10px;
  right: 10px;
  bottom: 10px;
  height: 28px;
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.35);
  color: #f8f8f8;
  display: grid;
  place-items: center;
  font-weight: 500;
  font-size: clamp(14px, 2.5vw, 16px);
  letter-spacing: 0.2px;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.35);
}

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

.card-back-border {
  position: absolute;
  inset: 14px;
  /* equal margin all around */
  border: 1px solid rgba(0, 0, 0, 0.9);
  border-radius: 10px;
}

.card-back-content {
  position: absolute;
  inset: 14px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  gap: 0;
  text-align: center;
  color: #000;
  padding: 30px 8px;
}

.card-back-logo {
  width: 48%;
  height: auto;
  filter: none;
  margin-top: 8px;
  margin-bottom: 12px;
}

.card-back-info {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0;
}

.card-back-qr {
  width: auto;
  height: 60px;
  margin-top: 8px;
  margin-bottom: 4px;
  max-width: 96px;
  max-height: 96px;
}

.card-back-text {
  font-weight: 400;
  font-size: clamp(14px, 3vw, 18px);
  line-height: 1.2;
  letter-spacing: 0.1px;
  margin: 0;
}

.card-back-description {
  font-weight: 300;
  font-size: clamp(10px, 2.2vw, 14px);
  line-height: 1.3;
  letter-spacing: 0.05px;
  margin: 8px 0 12px 0;
  opacity: 0.85;
  font-style: italic;
}

/* Prevent text/image selection while dragging the card */
.card-3d,
.card-face,
.card-image,
.card-plaque,
.card-back-content,
.card-back-text,
.card-back-logo {
  -webkit-user-select: none;
  -ms-user-select: none;
  user-select: none;
}

/* Landing page */
#logo {
  position: fixed;
  top: 12px;
  left: 12px;
  width: clamp(120px, 24vw, 200px);
  height: auto;
  z-index: 20;
}

#about-link {
  position: fixed;
  top: 16px;
  right: 120px;
  color: white;
  text-decoration: none;
  font-size: clamp(14px, 3vw, 16px);
  opacity: 0.85;
  padding: 6px 10px;
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.25);
  z-index: 20;
}

#cardbook-link {
  position: fixed;
  top: 16px;
  right: 16px;
  color: white;
  text-decoration: none;
  font-size: clamp(14px, 3vw, 16px);
  opacity: 0.85;
  padding: 6px 10px;
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.25);
  z-index: 20;
}

.swirl-stage {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  pointer-events: none;
}

.not-found {
  font-size: clamp(20px, 4vw, 36px);
  font-weight: 600;
  color: white;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.45);
}

/* Card book */
.cardbook-page {
  position: fixed;
  inset: 0;
  overflow-y: auto;
  padding: 0;
  -webkit-mask-image: linear-gradient(to bottom, 
    transparent 0%, 
    transparent 55px,
    rgba(0, 0, 0, 0.5) 75px,
    black 95px);
  mask-image: linear-gradient(to bottom, 
    transparent 0%, 
    transparent 55px,
    rgba(0, 0, 0, 0.5) 75px,
    black 95px);
}

.cardbook {
  display: grid;
  gap: 2rem;
  padding-top: 120px;
  max-width: calc(100vw - 240px);
  /* Reserve space for at least one card width on each side */
  margin: 0 auto;
  min-width: 320px;
  /* Ensure minimum usable width */
  padding-bottom: 3rem;
}

.set {
  background: rgba(0, 0, 0, 0.18);
  padding: 12px;
  border-radius: 12px;
}

.set h2 {
  margin: 0 0 8px 0;
  font-size: clamp(18px, 4vw, 22px);
  color: #fff;
  opacity: 0.9;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.set-complete-badge {
  font-size: clamp(12px, 2.5vw, 14px);
  font-weight: 700;
  background: linear-gradient(45deg, #ffd700, #ffed4e);
  color: #000;
  padding: 2px 8px;
  border-radius: 12px;
  animation: badgeGlow 2s ease-in-out infinite;
  white-space: nowrap;
}

.set-completed {
  background: rgba(255, 215, 0, 0.1);
  border: 1px solid rgba(255, 215, 0, 0.3);
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 18px;
}

.slot {
  aspect-ratio: 2.5 / 3.5;
  border-radius: 8px;
  display: grid;
  place-items: center;
  overflow: hidden;
  position: relative;
}

.slot.empty {
  outline: 2px dashed rgba(255, 255, 255, 0.25);
  color: rgba(255, 255, 255, 0.25);
  font-weight: 600;
}

.slot img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.card-overlay {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background: rgba(0, 0, 0, 0.5);
  color: white;
  padding: 4px 6px;
  font-size: clamp(8px, 1.8vw, 11px);
  font-weight: 600;
  line-height: 1.2;
  text-align: center;
  border-radius: 0 0 8px 8px;
}

/* Mobile-first tweaks */
@media (max-width: 600px) {
  main {
    margin: 4.5rem auto 1.25rem auto;
    padding: 0 1rem;
  }

  .swirl-wrap {
    width: min(80vmin, 520px);
  }

  .grid {
    grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
    gap: 15px;
  }

  .card-plaque {
    height: 32px;
    font-size: 15px;
  }

  .slot.empty {
    font-size: 12px;
  }
}

/* Medium screen adjustments */
@media (max-width: 768px) {
  .cardbook {
    max-width: calc(100vw - 200px);
    min-width: 300px;
  }
}

/* Additional mobile improvements */
@media (max-width: 480px) {
  body {
    font-size: 20px;
  }

  h1 {
    font-size: clamp(32px, 8vw, 44px);
  }

  #logo {
    width: clamp(140px, 28vw, 220px);
  }

  .card-3d {
    width: min(70vw, 280px);
  }

  .grid {
    grid-template-columns: repeat(auto-fill, minmax(90px, 1fr));
    gap: 12px;
  }

  .set {
    padding: 10px;
  }

  .cardbook {
    gap: 1.5rem;
    padding-top: 60px;
    max-width: calc(100vw - 180px);
    /* Smaller margins on mobile but still preserve card width */
    min-width: 280px;
  }
}

.swirl-wrap {
  position: relative;
  width: min(70vmin, 480px);
  aspect-ratio: 1;
}

.swirl {
  position: absolute;
  inset: 0;
  background-position: center;
  background-repeat: no-repeat;
  background-size: contain;
  animation-name: spin;
  animation-timing-function: linear;
  animation-iteration-count: infinite;
}

.swirl.one {
  background-image: url('https://i.pecards.co.za/static/images/loading_swirl1.png');
  animation-duration: 9s;
}

.swirl.two {
  background-image: url('https://i.pecards.co.za/static/images/loading_swirl2.png');
  animation-duration: 6s;
}

@keyframes spin {
  from {
    transform: rotate(0deg);
  }

  to {
    transform: rotate(360deg);
  }
}

/* Card page header centering */
.card-page header {
  text-align: center;
}

/* Card page mobile adjustments */
@media (max-width: 600px) {
  .card-page header h1 {
    font-size: clamp(22px, 6vw, 32px);
    margin-bottom: 0.3rem;
  }
  
  .card-page header p {
    font-size: clamp(14px, 3.5vw, 16px);
    margin: 0.2rem 0;
  }
  
  .card-page {
    gap: 1rem;
  }
  
  main {
    padding: 0 0.8rem;
    margin: 5rem auto 1rem auto;
  }
}

.discover-banner {
  font-size: clamp(12px, 5.5vw, 24px);
  font-weight: 800;
  color: #fff;
  text-shadow: 0 3px 12px rgba(0, 0, 0, 0.5);
  transform: rotate(-5deg);
  display: inline-block;
  animation: pulseScale 1.6s ease-in-out infinite;
}

.discover-banner.set-completion {
  transform: rotate(0deg);
  animation: celebrateCompletion 2s ease-in-out infinite;
}

.completion-main {
  font-size: clamp(24px, 6vw, 52px);
  font-weight: 900;
  margin-bottom: 0.3rem;
  background: linear-gradient(45deg, #ffd700, #ffed4e, #ffd700);
  background-size: 200% 200%;
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  animation: shimmer 1.5s ease-in-out infinite;
}

.completion-sub {
  font-size: clamp(16px, 3.5vw, 24px);
  font-weight: 700;
  margin-bottom: 0.2rem;
  color: #fff;
}

.completion-detail {
  font-size: clamp(14px, 3vw, 20px);
  font-weight: 600;
  color: #81c8fb;
}

@keyframes pulseScale {

  0%,
  100% {
    transform: rotate(-5deg) scale(1);
  }

  50% {
    transform: rotate(-5deg) scale(1.08);
  }
}

@keyframes celebrateCompletion {
  0%, 100% {
    transform: scale(1);
  }
  25% {
    transform: scale(1.05);
  }
  50% {
    transform: scale(1.1);
  }
  75% {
    transform: scale(1.05);
  }
}

@keyframes shimmer {
  0% {
    background-position: 0% 50%;
  }
  50% {
    background-position: 100% 50%;
  }
  100% {
    background-position: 0% 50%;
  }
}

@keyframes badgeGlow {
  0%, 100% {
    box-shadow: 0 0 5px rgba(255, 215, 0, 0.5);
    transform: scale(1);
  }
  50% {
    box-shadow: 0 0 15px rgba(255, 215, 0, 0.8);
    transform: scale(1.05);
  }
}

/* About page styles */
.about-page {
  position: fixed;
  inset: 0;
  overflow-y: auto;
  padding: 0;
  -webkit-mask-image: linear-gradient(to bottom, 
    transparent 0%, 
    transparent 85px,
    rgba(0, 0, 0, 0.5) 75px,
    black 105px);
  mask-image: linear-gradient(to bottom, 
    transparent 0%, 
    transparent 85px,
    rgba(0, 0, 0, 0.5) 75px,
    black 105px);
}

.about-content {
  position: relative;
  max-width: 600px;
  margin: 0 auto;
  text-align: left;
  color: white;
  font-size: clamp(16px, 2.5vw, 18px);
  line-height: 1.6;
  padding: 140px 1.25rem 3rem 1.25rem;
}

.about-content h1 {
  font-size: clamp(19px, 2.8vw, 22px);
  font-weight: 600;
  margin-top: 2rem;
  margin-bottom: 0.8rem;
  opacity: 1;
}

.about-content h1:first-child {
  margin-top: 0;
}

.about-content p {
  margin-bottom: 1.2rem;
  opacity: 0.9;
}

.about-content a {
  color: #81c8fb;
  text-decoration: underline;
}

.about-content a:hover {
  color: #a8d8ff;
}

/* What is this link below card */
.what-is-this-link {
  text-align: center;
  margin-top: 1rem;
  font-size: clamp(12px, 2vw, 14px);
}

.what-is-this-link a {
  color: rgba(255, 255, 255, 0.7);
  text-decoration: none;
  transition: color 0.2s ease;
}

.what-is-this-link a:hover {
  color: rgba(255, 255, 255, 0.95);
}