/* The post-tutorial card pack (views/tinybits/cardPack.jsx, played by
   public/card-pack.js). The overlay walks is-waiting → is-tearing → is-open →
   is-revealed, and everything that moves keys off those classes.

   The pack is drawn here, not painted: a crimson foil pouch with the crest,
   crimped edges and a tear strip along the top. The cards are the real game
   cards (views/card.jsx, 100×200), scaled by --pack-card-scale. */

.card-pack-overlay {
  --pack-gold: #e3bd5f;
  --pack-gold-deep: #a77a1f;
  --pack-crimson: #b3222d;
  --pack-crimson-deep: #5b0b14;
  --pack-card-scale: 1.2;
  --pack-card-gap: 1.1;

  position: fixed;
  inset: 0;
  z-index: 10030; /* above the info modals (10000), e.g. the Daily modal it opens from */
  display: flex;
  padding: 16px;
  box-sizing: border-box;
  overflow-y: auto;
  background:
    radial-gradient(ellipse at 50% 45%, rgba(227, 189, 95, 0.22), transparent 55%),
    rgba(12, 7, 3, 0.9);
  color: #f3e6c8;
  animation: card-pack-fade-in 0.35s ease both;
}

.card-pack-overlay.is-closing {
  animation: card-pack-fade-out 0.3s ease both;
  pointer-events: none;
}

.card-pack-stage {
  /* Centred with auto margins rather than the overlay's align-items, so on a
     screen shorter than the stage the top stays reachable by scrolling
     instead of being pushed off above it. */
  margin: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  width: 100%;
  max-width: 560px;
  text-align: center;
}

.card-pack-eyebrow {
  margin: 0;
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--pack-gold);
}

.card-pack-title {
  margin: 4px 0 0;
  font-family: "Cinzel", serif;
  font-size: clamp(1.4rem, 5vw, 2rem);
  color: #fff4d6;
  text-shadow: 0 2px 0 #2a1600, 0 0 18px rgba(227, 189, 95, 0.45);
}

/* ── The table: pack and cards share one centre point ─────────────────────── */
.card-pack-table {
  position: relative;
  width: 100%;
  height: calc(200px * var(--pack-card-scale) + 70px);
}

/* ── The pack ─────────────────────────────────────────────────────────────── */
.card-pack {
  position: absolute;
  left: 50%;
  top: 50%;
  z-index: 2;
  width: 150px;
  height: 212px;
  margin: -106px 0 0 -75px;
  padding: 0;
  border: none;
  background: none;
  cursor: pointer;
  font: inherit;
  color: inherit;
  transition: transform 0.5s cubic-bezier(0.5, 0, 0.75, 0), opacity 0.45s ease;
}

.card-pack:focus-visible {
  outline: 3px solid var(--pack-gold);
  outline-offset: 6px;
  border-radius: 12px;
}

.card-pack-body,
.card-pack-flap {
  position: absolute;
  left: 0;
  right: 0;
  box-sizing: border-box;
  border: 2px solid var(--pack-gold);
  background:
    linear-gradient(115deg, transparent 30%, rgba(255, 255, 255, 0.16) 45%, transparent 60%),
    linear-gradient(160deg, var(--pack-crimson) 0%, #8c1622 45%, var(--pack-crimson-deep) 100%);
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.55), inset 0 0 0 3px rgba(91, 11, 20, 0.6);
}

/* The tear strip. A dashed line marks where it rips. */
.card-pack-flap {
  top: 0;
  height: 30px;
  border-radius: 10px 10px 0 0;
  border-bottom: 2px dashed rgba(227, 189, 95, 0.75);
  transform-origin: 85% 100%;
}

/* Crimped edge along the very top of the strip and the bottom of the pouch. */
.card-pack-flap::before,
.card-pack-body::after {
  content: "";
  position: absolute;
  left: 4px;
  right: 4px;
  height: 7px;
  background: repeating-linear-gradient(90deg, rgba(0, 0, 0, 0.35) 0 3px, rgba(255, 220, 150, 0.25) 3px 6px);
  border-radius: 2px;
}
.card-pack-flap::before { top: 5px; }
.card-pack-body::after { bottom: 6px; }

.card-pack-body {
  top: 30px;
  bottom: 0;
  border-top: none;
  border-radius: 0 0 10px 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding-bottom: 12px;
}

.card-pack-crest {
  width: 68px;
  height: 68px;
  filter: drop-shadow(0 3px 4px rgba(0, 0, 0, 0.6));
}

.card-pack-name {
  font-family: "Cinzel", serif;
  font-weight: 700;
  font-size: 0.95rem;
  color: var(--pack-gold);
  text-shadow: 0 1px 0 #2a1600;
}

.card-pack-count {
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: #f3dca0;
  opacity: 0.85;
}

/* A highlight that sweeps across the foil while the pack waits. */
.card-pack-shine {
  position: absolute;
  inset: 0;
  border-radius: 10px;
  overflow: hidden;
  pointer-events: none;
}
.card-pack-shine::before {
  content: "";
  position: absolute;
  top: -20%;
  bottom: -20%;
  width: 40%;
  left: -60%;
  background: linear-gradient(90deg, transparent, rgba(255, 245, 210, 0.45), transparent);
  transform: skewX(-18deg);
}

.is-waiting .card-pack {
  animation: card-pack-bob 2.4s ease-in-out infinite;
}
.is-waiting .card-pack-shine::before {
  animation: card-pack-shine 2.8s ease-in-out infinite;
}

.is-tearing .card-pack {
  animation: card-pack-shake 0.5s ease-in-out both;
}
.is-tearing .card-pack-flap,
.is-open .card-pack-flap,
.is-revealed .card-pack-flap {
  animation: card-pack-tear 0.55s cubic-bezier(0.3, 0, 0.6, 1) both;
}

/* Spent: the empty pouch drops out of the way. */
.is-open .card-pack,
.is-revealed .card-pack {
  transform: translateY(160px) scale(0.85);
  opacity: 0;
  pointer-events: none;
}

/* Gone once the cards are out, or its dropped position adds scroll height. */
.is-revealed .card-pack { display: none; }

/* ── The cards ────────────────────────────────────────────────────────────── */
.card-pack-card {
  /* Offset from the middle card: -1, 0, 1 for three. */
  --o: calc(var(--i) - (var(--n) - 1) / 2);
  position: absolute;
  left: 50%;
  top: 50%;
  z-index: 1;
  width: 100px;
  height: 200px;
  margin: -100px 0 0 -50px;
  perspective: 900px;
  opacity: 0;
  transform: translateY(30px) scale(0.8);
}

.is-open .card-pack-card,
.is-revealed .card-pack-card {
  opacity: 1;
  z-index: 3;
  transform:
    translateX(calc(var(--o) * var(--pack-card-w, 100px) * var(--pack-card-scale) * var(--pack-card-gap)))
    translateY(calc(var(--o) * var(--o) * 10px))
    rotate(calc(var(--o) * 7deg))
    scale(var(--pack-card-scale));
}

.is-open .card-pack-card {
  animation: card-pack-rise 0.75s cubic-bezier(0.2, 0.8, 0.3, 1) both;
  animation-delay: calc(var(--i) * 60ms);
}

.card-pack-card-inner {
  position: relative;
  width: 100%;
  height: 100%;
  transform-style: preserve-3d;
  transition: transform 0.52s cubic-bezier(0.4, 0, 0.2, 1);
}

.card-pack-card.is-flipped .card-pack-card-inner {
  transform: rotateY(180deg);
}

.card-pack-card-back,
.card-pack-card-front {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}

.card-pack-card-back img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 6px;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.55);
}

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

/* The game card outside a game: no hand margins, hover lifts or animations,
   and always its full 100×200, since the hand's sizing rules (e.g. 70px wide
   on short landscape screens, mobile.css) would leave it smaller than the
   card back behind it. */
.card-pack-card .card-pack-card-front .card-container {
  width: 100px;
  height: 200px;
  margin: 0;
  transform: none;
  animation: none;
}

/* Hide whichever side is turned away halfway through the flip as well, for
   browsers that don't honour backface-visibility (some in-app webviews
   showed the back around the face). */
.card-pack-card-front { opacity: 0; transition: opacity 0s linear 0.26s; }
.card-pack-card.is-flipped .card-pack-card-front { opacity: 1; }
.card-pack-card.is-flipped .card-pack-card-back { opacity: 0; transition: opacity 0s linear 0.26s; }

.card-pack-card.is-flipped .card-pack-card-front .card {
  box-shadow: 0 0 0 2px rgba(227, 189, 95, 0.6), 0 0 26px rgba(227, 189, 95, 0.55), 0 10px 24px rgba(0, 0, 0, 0.6);
}

/* ── Words and buttons ────────────────────────────────────────────────────── */
.card-pack-hint {
  margin: 0;
  font-size: 0.9rem;
  color: #f3dca0;
  opacity: 0;
  transition: opacity 0.3s ease;
}
.is-waiting .card-pack-hint {
  opacity: 1;
  animation: card-pack-pulse 1.6s ease-in-out infinite;
}

.card-pack-result {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  opacity: 0;
  visibility: hidden;
  transform: translateY(12px);
  transition: opacity 0.4s ease, transform 0.4s ease, visibility 0s linear 0.4s;
}
.is-revealed .card-pack-result {
  opacity: 1;
  visibility: visible;
  transform: none;
  transition: opacity 0.4s ease, transform 0.4s ease;
}

.card-pack-note {
  margin: 0;
  font-size: 0.95rem;
}

.card-pack-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 10px 14px;
}

/* Its own gold plate: the victory screen's button styles are scoped to the
   game-over panel, and the harness page has none at all. */
.card-pack-primary {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 11px 22px;
  border: 1px solid var(--pack-gold-deep);
  border-radius: 6px;
  background: linear-gradient(to bottom, #f0d77a 0%, #d0a032 55%, #b7892b 100%);
  color: #2b1a00;
  font-family: "Cinzel", serif;
  font-weight: 700;
  font-size: 1rem;
  letter-spacing: 0.4px;
  text-decoration: none;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.4), 0 3px 10px rgba(0, 0, 0, 0.45);
  transition: filter 0.15s ease, transform 0.1s ease;
}
.card-pack-primary:hover { filter: brightness(1.08); color: #2b1a00; }
.card-pack-primary:active { transform: translateY(1px); }

.card-pack-close {
  padding: 10px 22px;
  border: 1px solid rgba(243, 220, 160, 0.55);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.06);
  color: #f3e6c8;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}
.card-pack-close:hover {
  background: rgba(255, 255, 255, 0.14);
}

.card-pack-more {
  margin: 0;
  font-size: 0.82rem;
  color: rgba(243, 230, 200, 0.75);
}
.card-pack-more i {
  color: var(--pack-gold);
}

@media (max-width: 480px) {
  .card-pack-overlay {
    --pack-card-scale: 0.95;
    --pack-card-gap: 1.06;
  }
}

/* Short screens (landscape phones, game portals' small iframes): smaller
   cards and tighter spacing so heading, cards and buttons fit together. */
@media (max-height: 560px) {
  .card-pack-overlay {
    --pack-card-scale: 0.78;
    padding: 10px 16px;
  }
  .card-pack-stage { gap: 8px; }
  .card-pack-eyebrow { font-size: 0.7rem; }
  .card-pack-title { font-size: 1.3rem; margin-top: 2px; }
  .card-pack-table { height: calc(200px * var(--pack-card-scale) + 34px); }
  .card-pack { width: 120px; height: 170px; margin: -85px 0 0 -60px; }
  .card-pack-crest { width: 50px; height: 50px; }
  .card-pack-result { gap: 8px; }
  .card-pack-note { font-size: 0.85rem; }
  .card-pack-primary { padding: 8px 16px; font-size: 0.9rem; }
  .card-pack-close { padding: 7px 16px; }
  .card-pack-more { font-size: 0.75rem; }
}

/* ── Closing into the deck button (card-pack.js flyToDeck) ─────────────────── */
.card-pack-overlay.is-flying {
  pointer-events: none;
  background: transparent;
  transition: background 0.35s ease;
}
.is-flying .card-pack-heading,
.is-flying .card-pack-result,
.is-flying .card-pack-hint {
  opacity: 0;
  transition: opacity 0.2s ease;
}

/* The navbar icon catching each card. */
.card-pack-catch {
  animation: card-pack-catch 0.6s cubic-bezier(0.3, 1.6, 0.5, 1);
}
.card-pack-catch i {
  color: var(--pack-gold, #e3bd5f);
  filter: drop-shadow(0 0 8px rgba(227, 189, 95, 0.95));
}

/* ── Keyframes ────────────────────────────────────────────────────────────── */
@keyframes card-pack-fade-in { from { opacity: 0; } }
@keyframes card-pack-catch {
  0% { transform: scale(1); }
  35% { transform: scale(1.45); }
  100% { transform: scale(1); }
}
@keyframes card-pack-fade-out { to { opacity: 0; } }

@keyframes card-pack-bob {
  0%, 100% { transform: translateY(0) rotate(-1.5deg); }
  50% { transform: translateY(-8px) rotate(1.5deg); }
}

@keyframes card-pack-shine {
  0%, 35% { left: -60%; }
  75%, 100% { left: 130%; }
}

@keyframes card-pack-pulse {
  50% { opacity: 0.55; }
}

@keyframes card-pack-shake {
  0%, 100% { transform: translateX(0) rotate(0); }
  20% { transform: translateX(-6px) rotate(-3deg); }
  40% { transform: translateX(6px) rotate(3deg); }
  60% { transform: translateX(-4px) rotate(-2deg) scale(1.04); }
  80% { transform: translateX(3px) rotate(1deg) scale(1.06); }
}

@keyframes card-pack-tear {
  0% { transform: none; opacity: 1; }
  40% { transform: translate(6px, -4px) rotate(8deg); opacity: 1; }
  100% { transform: translate(70px, -90px) rotate(38deg); opacity: 0; }
}

/* Up out of the pouch, then down into the fan (the static transform above). */
@keyframes card-pack-rise {
  0% {
    opacity: 1;
    transform: translateY(30px) scale(0.8);
  }
  45% {
    transform:
      translateX(calc(var(--o) * 30px))
      translateY(calc(-60px * var(--pack-card-scale)))
      rotate(calc(var(--o) * 4deg))
      scale(0.9);
  }
}

@media (prefers-reduced-motion: reduce) {
  .card-pack-overlay,
  .card-pack-overlay * {
    animation: none !important;
    transition: none !important;
  }
}

/* Landscape phones (about 400px tall or less). */
@media (max-height: 420px) {
  .card-pack-overlay { --pack-card-scale: 0.68; padding: 6px 16px; }
  .card-pack-more { display: none; }
}

/* Short landscape screens restyle every game card to 70×140
   (landscape-mobile.css: name, icons, costs and all), so the pack's slots
   take that size too and scale it up, rather than forcing a 100×200 box the
   card's insides no longer fill. */
@media (orientation: landscape) and (max-height: 500px) {
  .card-pack-overlay { --pack-card-w: 70px; --pack-card-scale: 1.1; --pack-card-gap: 1.12; }
  .card-pack-card { width: 70px; height: 140px; margin: -70px 0 0 -35px; }
  .card-pack-card .card-pack-card-front .card-container { width: 70px; height: 140px; }
  .card-pack-table { height: calc(140px * var(--pack-card-scale) + 34px); }
}
@media (orientation: landscape) and (max-height: 420px) {
  .card-pack-overlay { --pack-card-scale: 0.98; }
}
