/* ==========================================================================
   Tome — Premium Trading Card CSS (v2)
   Collectible card with hero image, stat rings, element theming, rarity FX.
   ========================================================================== */

/* --------------------------------------------------------------------------
   0. Custom Properties & Defaults
   -------------------------------------------------------------------------- */

:root {
  --card-bg: #12141a;
  --card-text: #e4e8f0;
  --card-text-muted: #888e9e;
  --card-font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto,
    Oxygen-Sans, Ubuntu, Cantarell, 'Helvetica Neue', sans-serif;

  /* Element defaults (overridden per .element-*) */
  --element-primary: #888;
  --element-secondary: #aaa;
  --element-glow: rgba(136, 136, 136, 0.3);
}

/* --------------------------------------------------------------------------
   1. Element Types
   -------------------------------------------------------------------------- */

.card.element-fire {
  --element-primary: #FF6B35;
  --element-secondary: #FF9A5C;
  --element-glow: rgba(255, 107, 53, 0.4);
}

.card.element-water {
  --element-primary: #3B82F6;
  --element-secondary: #60A5FA;
  --element-glow: rgba(59, 130, 246, 0.4);
}

.card.element-earth {
  --element-primary: #92713F;
  --element-secondary: #B8956A;
  --element-glow: rgba(146, 113, 63, 0.4);
}

.card.element-air {
  --element-primary: #A3E4D7;
  --element-secondary: #D5F5E3;
  --element-glow: rgba(163, 228, 215, 0.35);
}

.card.element-electric {
  --element-primary: #FFD700;
  --element-secondary: #FFF176;
  --element-glow: rgba(255, 215, 0, 0.45);
}

.card.element-shadow {
  --element-primary: #6B21A8;
  --element-secondary: #9333EA;
  --element-glow: rgba(107, 33, 168, 0.45);
}

.card.element-light {
  --element-primary: #FFF8DC;
  --element-secondary: #FFFAED;
  --element-glow: rgba(255, 248, 220, 0.35);
}

.card.element-void {
  --element-primary: #4a0080;
  --element-secondary: #7c3aed;
  --element-glow: rgba(74, 0, 128, 0.5);
}

/* --------------------------------------------------------------------------
   2. Card Shell
   -------------------------------------------------------------------------- */

.card {
  position: relative;
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 380px;
  background: var(--card-bg);
  color: var(--card-text);
  font-family: var(--card-font);
  border-radius: 16px;
  border: 2px solid var(--element-primary);
  box-shadow:
    0 8px 32px rgba(0, 0, 0, 0.5),
    0 2px 8px rgba(0, 0, 0, 0.3),
    0 0 20px var(--element-glow);
  overflow: hidden;
  container-type: inline-size;
  opacity: 1;
}

/* Subtle inner edge highlight — mimics gloss print of a real card */
.card::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: inherit;
  pointer-events: none;
  z-index: 10;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08);
}

/* --------------------------------------------------------------------------
   3. Card Art (Image Area)
   -------------------------------------------------------------------------- */

.card-art {
  position: relative;
  overflow: hidden;
  flex-shrink: 0;
}

.card-art img {
  display: block;
  width: 100%;
  height: 240px;
  object-fit: cover;
  object-position: center 30%;
}

/* Radial vignette — darkens edges for focus on subject */
.card-vignette {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 1;
  background: radial-gradient(
    ellipse 70% 60% at 50% 40%,
    transparent 40%,
    rgba(0, 0, 0, 0.5) 100%
  );
}

/* Bottom gradient — fades image into card body seamlessly */
.card-gradient {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 50%;
  pointer-events: none;
  z-index: 2;
  background: linear-gradient(
    to bottom,
    transparent 0%,
    rgba(18, 20, 26, 0.3) 30%,
    rgba(18, 20, 26, 0.7) 60%,
    #12141a 100%
  );
}

/* --------------------------------------------------------------------------
   4. Badges (float on image)
   -------------------------------------------------------------------------- */

.card-badges {
  position: absolute;
  top: 12px;
  left: 12px;
  right: 12px;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  z-index: 5;
  pointer-events: none;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  font-size: 0.65rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-radius: 99px;
  background: rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: #fff;
  pointer-events: auto;
  white-space: nowrap;
}

.badge-icon {
  font-size: 0.7rem;
  line-height: 1;
}

.badge-element {
  color: var(--element-secondary);
}

.badge-rarity {
  color: #d4d4d4;
}

/* --------------------------------------------------------------------------
   5. Title Bar (overlays gradient zone)
   -------------------------------------------------------------------------- */

.card-title-bar {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 0 20px 14px;
  z-index: 3;
}

.card-name {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 700;
  line-height: 1.25;
  color: #fff;
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.6);
}

.card-subtitle {
  margin: 2px 0 0;
  font-size: 0.75rem;
  color: rgba(255, 255, 255, 0.55);
  line-height: 1.3;
}

/* --------------------------------------------------------------------------
   6. Card Body
   -------------------------------------------------------------------------- */

.card-body {
  display: flex;
  flex-direction: column;
  padding: 0 20px 16px;
}

/* --------------------------------------------------------------------------
   7. Stat Rings (2x2 or 4-across grid)
   -------------------------------------------------------------------------- */

.card-stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  padding: 16px 0;
}

.stat-cell {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

/* The ring container */
.stat-ring {
  position: relative;
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: conic-gradient(
    var(--element-primary) calc(var(--pct) * 1%),
    rgba(255, 255, 255, 0.08) calc(var(--pct) * 1%)
  );
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Inner circle — punches out the center to create a ring */
.stat-ring::before {
  content: '';
  position: absolute;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--card-bg);
}

/* Stat value text — centered in ring */
.stat-val {
  position: relative;
  z-index: 1;
  font-size: 1rem;
  font-weight: 700;
  color: #fff;
  line-height: 1;
}

/* Stat label below ring */
.stat-label {
  font-size: 0.65rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--card-text-muted);
  text-align: center;
  line-height: 1.2;
}

/* --------------------------------------------------------------------------
   8. Description
   -------------------------------------------------------------------------- */

.card-desc {
  font-size: 0.8rem;
  line-height: 1.5;
  color: #b0b8c8;
  margin-top: 12px;
}

/* --------------------------------------------------------------------------
   9. Card Bottom (flavor text + tags)
   -------------------------------------------------------------------------- */

.card-bottom {
  border-top: 1px solid rgba(255, 255, 255, 0.06);
  padding-top: 12px;
  margin-top: 12px;
}

.card-flavor {
  font-size: 0.75rem;
  font-style: italic;
  color: #888;
  line-height: 1.4;
  margin: 0 0 8px;
}

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

.tag {
  display: inline-block;
  padding: 2px 8px;
  font-size: 0.6rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  border-radius: 99px;
  background: rgba(255, 255, 255, 0.06);
  color: #888;
}

/* ==========================================================================
   10. Rarity Tiers
   ========================================================================== */

/* --- Common: clean, minimal -------------------------------------------- */
.card.rarity-common {
  border-color: rgba(255, 255, 255, 0.1);
  box-shadow:
    0 8px 32px rgba(0, 0, 0, 0.5),
    0 2px 8px rgba(0, 0, 0, 0.3);
}

/* --- Uncommon: slightly brighter border -------------------------------- */
.card.rarity-uncommon {
  border-color: color-mix(in srgb, var(--element-primary) 70%, #fff 30%);
  box-shadow:
    0 8px 32px rgba(0, 0, 0, 0.5),
    0 2px 8px rgba(0, 0, 0, 0.3),
    0 0 12px var(--element-glow);
}

/* --- Rare: gold-tinted border + glow ----------------------------------- */
.card.rarity-rare {
  border-color: #d4a843;
  box-shadow:
    0 8px 32px rgba(0, 0, 0, 0.5),
    0 2px 8px rgba(0, 0, 0, 0.3),
    0 0 16px rgba(212, 168, 67, 0.25),
    0 0 40px rgba(212, 168, 67, 0.1);
}

/* Gold shimmer sweep */
.card.rarity-rare::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: inherit;
  pointer-events: none;
  z-index: 11;
  background: linear-gradient(
    105deg,
    transparent 40%,
    rgba(212, 168, 67, 0.07) 44%,
    rgba(212, 168, 67, 0.14) 50%,
    rgba(212, 168, 67, 0.07) 56%,
    transparent 60%
  );
  background-size: 250% 100%;
  animation: shimmer-sweep 4s ease-in-out infinite;
}

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

/* --- Epic: purple border + glow + pulse -------------------------------- */
.card.rarity-epic {
  border-color: #6366f1;
  box-shadow:
    0 8px 32px rgba(0, 0, 0, 0.5),
    0 2px 8px rgba(0, 0, 0, 0.3),
    0 0 24px rgba(99, 102, 241, 0.35),
    0 0 48px rgba(139, 92, 246, 0.15);
  animation: epic-border-pulse 3s ease-in-out infinite;
}

@keyframes epic-border-pulse {
  0%, 100% {
    border-color: #6366f1;
    box-shadow:
      0 8px 32px rgba(0, 0, 0, 0.5),
      0 2px 8px rgba(0, 0, 0, 0.3),
      0 0 24px rgba(99, 102, 241, 0.35),
      0 0 48px rgba(139, 92, 246, 0.15);
  }
  50% {
    border-color: #818cf8;
    box-shadow:
      0 8px 32px rgba(0, 0, 0, 0.5),
      0 2px 8px rgba(0, 0, 0, 0.3),
      0 0 32px rgba(99, 102, 241, 0.5),
      0 0 64px rgba(139, 92, 246, 0.25);
  }
}

/* --- Legendary: animated rainbow border + strong glow + foil ----------- */
.card.rarity-legendary {
  border: 3px solid transparent;
  background-clip: padding-box;
  box-shadow:
    0 8px 32px rgba(0, 0, 0, 0.5),
    0 0 28px rgba(255, 200, 50, 0.35),
    0 0 64px rgba(255, 150, 50, 0.18);
  animation: legendary-glow-pulse 3s ease-in-out infinite;
}

@keyframes legendary-glow-pulse {
  0%, 100% {
    box-shadow:
      0 8px 32px rgba(0, 0, 0, 0.5),
      0 0 28px rgba(255, 200, 50, 0.35),
      0 0 64px rgba(255, 150, 50, 0.18);
  }
  50% {
    box-shadow:
      0 8px 32px rgba(0, 0, 0, 0.5),
      0 0 36px rgba(255, 200, 50, 0.55),
      0 0 80px rgba(255, 150, 50, 0.3);
  }
}

/* Holographic rainbow border via rotating gradient + mask */
.card.rarity-legendary::after {
  content: '';
  position: absolute;
  inset: -3px;
  border-radius: calc(16px + 3px);
  padding: 3px;
  background: linear-gradient(
    var(--legendary-angle, 0deg),
    #ff6b6b,
    #ffd93d,
    #6bcb77,
    #4d96ff,
    #9b59b6,
    #ff6b6b
  );
  -webkit-mask:
    linear-gradient(#fff 0 0) content-box,
    linear-gradient(#fff 0 0);
  -webkit-mask-composite: xor;
  mask:
    linear-gradient(#fff 0 0) content-box,
    linear-gradient(#fff 0 0);
  mask-composite: exclude;
  z-index: 11;
  pointer-events: none;
  animation: legendary-border-rotate 4s linear infinite;
}

@property --legendary-angle {
  syntax: '<angle>';
  initial-value: 0deg;
  inherits: false;
}

@keyframes legendary-border-rotate {
  to { --legendary-angle: 360deg; }
}

/* Fallback for browsers without @property */
@supports not (background: paint(something)) {
  @keyframes legendary-border-rotate {
    0%   { filter: hue-rotate(0deg); }
    100% { filter: hue-rotate(360deg); }
  }
}

/* Holographic foil overlay (optional .card-foil child) */
.card.rarity-legendary .card-foil {
  position: absolute;
  inset: 0;
  border-radius: inherit;
  z-index: 12;
  pointer-events: none;
  mix-blend-mode: overlay;
  opacity: 0.1;
  background:
    repeating-linear-gradient(
      115deg,
      transparent 0px,
      transparent 2px,
      rgba(255, 255, 255, 0.15) 2px,
      rgba(255, 255, 255, 0.15) 4px
    ),
    repeating-linear-gradient(
      65deg,
      transparent 0px,
      transparent 3px,
      rgba(200, 180, 255, 0.1) 3px,
      rgba(200, 180, 255, 0.1) 5px
    ),
    linear-gradient(
      135deg,
      rgba(255, 100, 100, 0.1),
      rgba(100, 255, 100, 0.1),
      rgba(100, 100, 255, 0.1),
      rgba(255, 255, 100, 0.1)
    );
}

/* CSS-only foil when no .card-foil child exists */
.card.rarity-legendary > .card-art::after {
  content: '';
  position: absolute;
  inset: 0;
  z-index: 6;
  pointer-events: none;
  mix-blend-mode: color-dodge;
  opacity: 0.08;
  background: linear-gradient(
    135deg,
    rgba(255, 0, 0, 0.2) 0%,
    rgba(255, 165, 0, 0.2) 17%,
    rgba(255, 255, 0, 0.2) 33%,
    rgba(0, 255, 0, 0.2) 50%,
    rgba(0, 0, 255, 0.2) 67%,
    rgba(75, 0, 130, 0.2) 83%,
    rgba(238, 130, 238, 0.2) 100%
  );
  animation: legendary-foil-shift 6s ease-in-out infinite alternate;
}

@keyframes legendary-foil-shift {
  0%   { filter: hue-rotate(0deg); }
  100% { filter: hue-rotate(60deg); }
}

/* ==========================================================================
   11. Entrance Animation
   ========================================================================== */

.card-enter {
  animation: card-fade-in-up 0.4s cubic-bezier(0.22, 1, 0.36, 1) forwards;
}

@keyframes card-fade-in-up {
  from {
    opacity: 0;
    transform: translateY(16px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ==========================================================================
   12. Export Mode
   ========================================================================== */

.card.export-mode {
  width: 380px;
  max-width: none;
  border-radius: 16px;
  box-shadow: none !important;
  animation: none !important;
}

.card.export-mode *,
.card.export-mode *::before,
.card.export-mode *::after {
  animation: none !important;
  transition: none !important;
}

/* Remove backdrop-filter for export (not rasterizable) */
.card.export-mode .badge {
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
  background: rgba(0, 0, 0, 0.55);
}

/* ==========================================================================
   13. Responsive
   ========================================================================== */

/* Container queries for cards inside flex/grid parents */
@container (max-width: 340px) {
  .stat-ring {
    width: 50px;
    height: 50px;
  }

  .stat-ring::before {
    width: 40px;
    height: 40px;
  }

  .stat-val {
    font-size: 0.85rem;
  }

  .card-stats {
    gap: 8px;
    padding: 12px 0;
  }

  .card-body {
    padding: 0 14px 12px;
  }

  .card-title-bar {
    padding: 0 14px 10px;
  }

  .card-name {
    font-size: 1rem;
  }

  .card-badges {
    top: 8px;
    left: 8px;
    right: 8px;
  }

  .badge {
    font-size: 0.6rem;
    padding: 3px 8px;
  }
}

/* Fallback for browsers without container queries */
@media (max-width: 340px) {
  .stat-ring {
    width: 50px;
    height: 50px;
  }

  .stat-ring::before {
    width: 40px;
    height: 40px;
  }

  .stat-val {
    font-size: 0.85rem;
  }

  .card-stats {
    gap: 8px;
    padding: 12px 0;
  }

  .card-body {
    padding: 0 14px 12px;
  }

  .card-title-bar {
    padding: 0 14px 10px;
  }

  .card-name {
    font-size: 1rem;
  }
}

/* ==========================================================================
   14. Print
   ========================================================================== */

@media print {
  .card {
    break-inside: avoid;
    box-shadow: none;
    border: 1px solid #ccc;
  }
  .card *,
  .card *::before,
  .card *::after {
    animation: none !important;
  }
}
