@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

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

:root {
  --card-size: clamp(280px, 32vmin, 380px);
  --fold-duration: 0.8s;
  --fold-ease: cubic-bezier(0.45, 0.05, 0.25, 0.95);

  --color-bg: #ffffff;

  --color-center-bg: #f5f4f2;
  --color-center-fg: #2a2a2a;

  --color-top-inside: #e8f0f0;
  --color-top-outside: #5ba3a3;
  --color-right-inside: #ede8f2;
  --color-right-outside: #8b6cad;
  --color-bottom-inside: #f2ece6;
  --color-bottom-outside: #d48a6a;
  --color-left-inside: #f0eddf;
  --color-left-outside: #c4a84d;

  --color-face-fg: #2a2a2a;
  --color-accent: #5ba3a3;
}

body {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--color-bg);
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  overflow: hidden;
  color: var(--color-face-fg);
}

.page {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100dvh;
}

/* ── Card container ─────────────────────────────────────── */

.fold-card {
  position: relative;
  width: var(--card-size);
  height: var(--card-size);
  cursor: pointer;
  outline: none;
  -webkit-tap-highlight-color: transparent;
  transform-style: preserve-3d;
  perspective: 1000px;
  transition: transform 0.3s ease;
}

/* ── Center panel ────────────────────────────────────────── */

.fold-card__center {
  position: absolute;
  inset: 0;
  background: var(--color-center-bg);
  color: var(--color-center-fg);
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 3px;
  box-shadow: 0 1px 8px rgba(0, 0, 0, 0.08);
  z-index: 1;
}

/* Subtle noise texture on center */
.fold-card__center::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noise)'/%3E%3C/svg%3E");
  opacity: 0.02;
  pointer-events: none;
}

/* ── Flap base ───────────────────────────────────────────── */

.fold-card__flap {
  position: absolute;
  width: var(--card-size);
  height: var(--card-size);
  transform-style: preserve-3d;
  transition:
    transform var(--fold-duration) var(--fold-ease),
    z-index 0s calc(var(--fold-duration) * 0.5);
  z-index: 2;
}

.fold-card__flap.folded {
  transition:
    transform var(--fold-duration) var(--fold-ease),
    z-index 0s 0s;
}

/* ── Flap positions (unfolded, relative to center) ───────── */

.fold-card__flap--top {
  left: 0;
  bottom: 100%;
  transform-origin: center bottom;
}

.fold-card__flap--right {
  top: 0;
  left: 100%;
  transform-origin: left center;
}

.fold-card__flap--bottom {
  left: 0;
  top: 100%;
  transform-origin: center top;
}

.fold-card__flap--left {
  top: 0;
  right: 100%;
  transform-origin: right center;
}

/* ── Folded transforms ───────────────────────────────────── */

.fold-card__flap--top.folded {
  transform: rotateX(-180deg);
}

.fold-card__flap--bottom.folded {
  transform: rotateX(180deg);
}

.fold-card__flap--left.folded {
  transform: rotateY(180deg);
}

.fold-card__flap--right.folded {
  transform: rotateY(-180deg);
}

/* ── Z-index stacking when folded ────────────────────────── */

.fold-card__flap--left.folded  { z-index: 3; }
.fold-card__flap--right.folded { z-index: 4; }
.fold-card__flap--bottom.folded { z-index: 5; }
.fold-card__flap--top.folded   { z-index: 6; }

/* ── Faces (inside / outside) ────────────────────────────── */

.fold-card__face {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  border-radius: 3px;
  overflow: hidden;
}

/* Noise texture on all faces */
.fold-card__face::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noise)'/%3E%3C/svg%3E");
  opacity: 0.03;
  pointer-events: none;
  z-index: 1;
}

.fold-card__face--inside {
  z-index: 1;
  color: var(--color-face-fg);
}

.fold-card__face--outside {
  z-index: 0;
  color: #ffffff;
}

/* Outside faces rotated to form the backface of each flap */
.fold-card__flap--top .fold-card__face--outside    { transform: rotateX(180deg); }
.fold-card__flap--bottom .fold-card__face--outside { transform: rotateX(-180deg); }
.fold-card__flap--left .fold-card__face--outside   { transform: rotateY(-180deg); }
.fold-card__flap--right .fold-card__face--outside  { transform: rotateY(180deg); }

/* ── Face colors ─────────────────────────────────────────── */

.fold-card__flap--top .fold-card__face--inside    { background: var(--color-top-inside); }
.fold-card__flap--top .fold-card__face--outside   { background: var(--color-top-outside); }
.fold-card__flap--right .fold-card__face--inside  { background: var(--color-right-inside); }
.fold-card__flap--right .fold-card__face--outside { background: var(--color-right-outside); }
.fold-card__flap--bottom .fold-card__face--inside { background: var(--color-bottom-inside); }
.fold-card__flap--bottom .fold-card__face--outside{ background: var(--color-bottom-outside); }
.fold-card__flap--left .fold-card__face--inside   { background: var(--color-left-inside); }
.fold-card__flap--left .fold-card__face--outside  { background: var(--color-left-outside); }

/* ── Content layout ──────────────────────────────────────── */

.fold-card__content {
  position: relative;
  z-index: 2;
  padding: 1.5rem;
  text-align: center;
  max-width: 100%;
}

.fold-card__content h1 {
  font-size: clamp(1.3rem, 2.8vmin, 1.7rem);
  font-weight: 700;
  margin-bottom: 0.6rem;
  letter-spacing: -0.01em;
  line-height: 1.2;
}

.fold-card__content h2 {
  font-size: clamp(1rem, 2.2vmin, 1.3rem);
  font-weight: 600;
  margin-bottom: 0.5rem;
  letter-spacing: -0.01em;
  line-height: 1.2;
}

.fold-card__content p {
  font-size: clamp(0.72rem, 1.5vmin, 0.88rem);
  line-height: 1.6;
  opacity: 0.7;
  font-weight: 400;
}

.fold-card__icon {
  font-size: clamp(1.2rem, 3.5vmin, 2rem);
  opacity: 0.35;
  display: block;
}

/* ── Tap hint icon ──────────────────────────────────────── */

.fold-card__tap-hint {
  position: absolute;
  bottom: 12px;
  right: 12px;
  z-index: 10;
  pointer-events: none;
  color: #ffffff;
  transform: rotate(-15deg);
  opacity: 1;
  visibility: visible;
  animation: tap-pulse 2s ease-in-out 3;
  transition: opacity 0.3s ease, visibility 0.3s ease;
}

.fold-card:not([data-step="0"]) .fold-card__tap-hint,
.fold-card.closing .fold-card__tap-hint {
  opacity: 0;
  visibility: hidden;
  animation: none;
}

@keyframes tap-pulse {
  0%, 100% { transform: rotate(-15deg) scale(1); }
  50% { transform: rotate(-15deg) scale(1.15); }
}

/* ── Progress dots ───────────────────────────────────────── */

.fold-card__dots {
  position: absolute;
  bottom: 10px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 6px;
  z-index: 10;
  pointer-events: none;
  transition: opacity 0.25s ease;
}

.fold-card.closing .fold-card__dots {
  opacity: 0;
}

.fold-card__dots span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.35);
  transition: background 0.3s ease, transform 0.3s ease;
}

.fold-card[data-step="0"] .fold-card__dots span:nth-child(1),
.fold-card[data-step="1"] .fold-card__dots span:nth-child(2),
.fold-card[data-step="2"] .fold-card__dots span:nth-child(3),
.fold-card[data-step="3"] .fold-card__dots span:nth-child(4),
.fold-card[data-step="4"] .fold-card__dots span:nth-child(5) {
  background: rgba(255, 255, 255, 0.9);
  transform: scale(1.35);
}

.fold-card.fully-open .fold-card__dots span {
  background: rgba(0, 0, 0, 0.15);
}

.fold-card.fully-open .fold-card__dots span:nth-child(5) {
  background: rgba(0, 0, 0, 0.5);
  transform: scale(1.35);
}

/* ── Hover affordance ────────────────────────────────────── */

.fold-card:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: 8px;
  border-radius: 4px;
}

/* ── Responsive adjustments ──────────────────────────────── */

@media (max-width: 400px) {
  .fold-card__content {
    padding: 1rem;
  }
}

/* ── Reduced motion ──────────────────────────────────────── */

@media (prefers-reduced-motion: reduce) {
  .fold-card__flap {
    transition-duration: 0.01ms;
  }

  .fold-card,
  .fold-card:hover,
  .fold-card:active {
    transition: none;
    transform: none;
  }
}
