/* Grand Line Chronicles · Vista carta
   La carta arriva al centro dello schermo come una carta da gioco: lo sfondo
   si sfoca, la si gira col dito o col mouse, e sul retro ci sono gli effetti. */

#cvw {
  position: fixed;
  inset: 0;
  z-index: 10000;
  display: grid;
  grid-template-rows: auto 1fr auto;
  justify-items: center;
  gap: 10px;
  padding: max(14px, env(safe-area-inset-top)) 14px max(14px, env(safe-area-inset-bottom));
  background: radial-gradient(120% 90% at 50% 0%, rgba(32, 20, 8, .82), rgba(6, 5, 4, .94));
  -webkit-backdrop-filter: blur(18px) saturate(.85);
  backdrop-filter: blur(18px) saturate(.85);
  opacity: 0;
  transition: opacity .28s ease;
  touch-action: none;
  overscroll-behavior: contain;
}
#cvw.cvw-on { opacity: 1; }

.cvw-bar {
  width: min(880px, 100%);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  color: #e7dcc6;
  font-family: 'Inter', system-ui, sans-serif;
}
.cvw-bar .cvw-name {
  font-family: 'Cinzel Decorative', 'Marcellus SC', serif;
  font-size: clamp(15px, 3.4vw, 21px);
  color: #ffd394;
  letter-spacing: .04em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.cvw-btn {
  border: 1px solid rgba(240, 164, 65, .5);
  background: rgba(20, 14, 8, .6);
  color: #ffd394;
  border-radius: 999px;
  padding: 9px 16px;
  font: 500 11px/1 'Inter', system-ui, sans-serif;
  letter-spacing: .14em;
  text-transform: uppercase;
  cursor: pointer;
  transition: background .16s, transform .16s, border-color .16s;
}
.cvw-btn:hover { background: rgba(240, 164, 65, .18); transform: translateY(-1px); }
.cvw-btn:focus-visible { outline: 2px solid #ffd394; outline-offset: 3px; }
.cvw-btn.cvw-primary { background: linear-gradient(180deg, #ecca77, #c9a24a); color: #23170a; border-color: transparent; }

/* --- il tavolo e la carta --- */
.cvw-stage {
  width: 100%;
  display: grid;
  place-items: center;
  perspective: 1400px;
  perspective-origin: 50% 45%;
}
.cvw-card {
  --sp: 3.5px;          /* mezzo spessore del cartoncino */
  position: relative;
  width: min(86vw, 380px, calc((100dvh - 190px) * .66));
  aspect-ratio: 2 / 3;
  transform-style: preserve-3d;
  transform: rotateX(var(--rx, 0deg)) rotateY(var(--ry, 0deg)) scale(var(--sc, 1));
  transition: transform .5s cubic-bezier(.22, .9, .25, 1);
  cursor: grab;
  will-change: transform;
}
.cvw-card.cvw-drag { transition: none; cursor: grabbing; }
#cvw.cvw-on .cvw-card { animation: cvwDeal .55s cubic-bezier(.2, .8, .25, 1); }
@keyframes cvwDeal {
  from { transform: translateY(42px) rotateX(18deg) rotateY(-24deg) scale(.86); opacity: 0; }
  to   { transform: rotateX(var(--rx, 0deg)) rotateY(var(--ry, 0deg)) scale(var(--sc, 1)); opacity: 1; }
}

.cvw-face {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  transform: translateZ(var(--sp, 3px));
  border-radius: 18px;
  overflow: hidden;
  border: 1px solid rgba(240, 164, 65, .45);
  background: linear-gradient(168deg, #1b1510, #0b0906 70%);
  box-shadow: 0 30px 70px rgba(0, 0, 0, .65), 0 0 0 1px rgba(255, 211, 148, .08) inset;
  display: flex;
  flex-direction: column;
}
.cvw-back { transform: rotateY(180deg) translateZ(var(--sp, 3px)); }

/* --- spessore: quattro bordi sottili fanno il cartoncino --- */
.cvw-edge {
  position: absolute;
  background: linear-gradient(90deg, #f7e3bc, #b9915a 28%, #6d5230 62%, #d9bd86);
  box-shadow: 0 0 6px rgba(0, 0, 0, .45) inset;
}
.cvw-edge-l, .cvw-edge-r {
  top: 0;
  bottom: 0;
  width: calc(var(--sp, 3px) * 2);
}
.cvw-edge-l { left: 0; transform: translateZ(calc(var(--sp, 3px) * -1)) rotateY(-90deg); transform-origin: left center; }
.cvw-edge-r { right: 0; transform: translateZ(calc(var(--sp, 3px) * -1)) rotateY(90deg); transform-origin: right center; }
.cvw-edge-t, .cvw-edge-b {
  left: 0;
  right: 0;
  height: calc(var(--sp, 3px) * 2);
  background: linear-gradient(180deg, #f7e3bc, #b9915a 30%, #6d5230 64%, #d9bd86);
}
.cvw-edge-t { top: 0; transform: translateZ(calc(var(--sp, 3px) * -1)) rotateX(90deg); transform-origin: center top; }
.cvw-edge-b { bottom: 0; transform: translateZ(calc(var(--sp, 3px) * -1)) rotateX(-90deg); transform-origin: center bottom; }

/* --- finiture: reagiscono a come la carta è girata --- */
.cvw-fin {
  position: absolute;
  inset: 0;
  z-index: 3;
  pointer-events: none;
  border-radius: inherit;
  opacity: 0;
  transition: opacity .3s ease;
}
.cvw-card[data-fin]:not([data-fin="none"]) .cvw-fin { opacity: .72; }

/* il riflesso segue l'inclinazione: --gx e --gy arrivano dal trascinamento */
.cvw-card[data-fin="foil"] .cvw-fin {
  background:
    linear-gradient(calc(var(--ang, 115) * 1deg),
      rgba(255, 0, 128, .16), rgba(255, 214, 0, .14) 18%, rgba(0, 255, 183, .14) 34%,
      rgba(0, 156, 255, .15) 52%, rgba(168, 0, 255, .14) 70%, rgba(255, 0, 128, .16) 88%),
    radial-gradient(60% 45% at calc(var(--gx, 50) * 1%) calc(var(--gy, 40) * 1%), rgba(255, 255, 255, .26), transparent 70%);
  background-size: 260% 260%, 100% 100%;
  background-position: calc(var(--gx, 50) * 1%) calc(var(--gy, 50) * 1%), 0 0;
  mix-blend-mode: color-dodge;
}
.cvw-card[data-fin="oro"] .cvw-fin {
  background:
    linear-gradient(calc(var(--ang, 115) * 1deg), rgba(120, 78, 20, .12), rgba(255, 221, 150, .3) 42%, rgba(255, 248, 224, .42) 50%, rgba(214, 160, 60, .24) 62%, rgba(90, 60, 18, .12)),
    radial-gradient(52% 40% at calc(var(--gx, 50) * 1%) calc(var(--gy, 40) * 1%), rgba(255, 240, 200, .28), transparent 72%);
  background-size: 220% 220%, 100% 100%;
  background-position: calc(var(--gx, 50) * 1%) calc(var(--gy, 50) * 1%), 0 0;
  mix-blend-mode: overlay;
}
.cvw-card[data-fin="prisma"] .cvw-fin {
  background:
    repeating-linear-gradient(calc(var(--ang, 115) * 1deg),
      rgba(255, 255, 255, .14) 0 6px, rgba(0, 234, 255, .12) 6px 12px,
      rgba(255, 0, 191, .11) 12px 18px, rgba(255, 238, 0, .11) 18px 24px, transparent 24px 40px),
    radial-gradient(55% 42% at calc(var(--gx, 50) * 1%) calc(var(--gy, 40) * 1%), rgba(255, 255, 255, .24), transparent 70%);
  background-size: 180% 180%, 100% 100%;
  background-position: calc(var(--gx, 50) * 1%) calc(var(--gy, 50) * 1%), 0 0;
  mix-blend-mode: color-dodge;
}
.cvw-card[data-fin="stelle"] .cvw-fin {
  background:
    radial-gradient(circle at 20% 30%, rgba(255, 255, 255, .7) 0 1.1px, transparent 1.7px),
    radial-gradient(circle at 70% 60%, rgba(255, 240, 200, .6) 0 1.3px, transparent 1.9px),
    radial-gradient(circle at 45% 85%, rgba(200, 235, 255, .6) 0 1px, transparent 1.6px),
    radial-gradient(60% 45% at calc(var(--gx, 50) * 1%) calc(var(--gy, 40) * 1%), rgba(255, 246, 214, .22), transparent 72%);
  background-size: 46px 46px, 62px 62px, 38px 38px, 100% 100%;
  background-position: calc(var(--gx, 50) * .6%) calc(var(--gy, 50) * .6%), calc(var(--gx, 50) * -.8%) calc(var(--gy, 50) * .9%), calc(var(--gx, 50) * .4%) calc(var(--gy, 50) * -.5%), 0 0;
  mix-blend-mode: screen;
}
/* Un velo di luce sempre presente sulle carte con finitura: dà il «vetro». */
.cvw-card[data-fin]:not([data-fin="none"]) .cvw-face::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: linear-gradient(calc(var(--ang, 115) * 1deg), transparent 40%, rgba(255, 255, 255, .08) 50%, transparent 60%);
  background-size: 250% 250%;
  background-position: calc(var(--gx, 50) * 1%) calc(var(--gy, 50) * 1%);
}

/* --- fronte: illustrazione, stemma, citazione, titolo --- */
.cvw-art {
  position: absolute;
  inset: 0;
  background: radial-gradient(80% 60% at 50% 30%, #2a2018, #0a0806);
}
.cvw-art img { width: 100%; height: 100%; object-fit: cover; display: block; }
.cvw-art .cvw-fallback {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  opacity: .5;
}
.cvw-art .cvw-fallback img, .cvw-art .cvw-fallback svg { width: 54%; height: auto; }
.cvw-veil {
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, rgba(8, 6, 4, .62) 0%, rgba(8, 6, 4, 0) 32%, rgba(8, 6, 4, .18) 52%, rgba(8, 6, 4, .92) 88%);
}
.cvw-front-in {
  position: relative;
  z-index: 2;
  display: flex;
  flex-direction: column;
  height: 100%;
  padding: 16px 16px 18px;
  color: #f2e9d8;
  font-family: 'Inter', system-ui, sans-serif;
}
.cvw-edition {
  display: flex;
  justify-content: space-between;
  font-size: 8.5px;
  letter-spacing: .22em;
  text-transform: uppercase;
  color: rgba(242, 233, 216, .72);
}
.cvw-crest {
  margin: 10px auto 0;
  width: 58px;
  height: 58px;
  display: grid;
  place-items: center;
  filter: drop-shadow(0 4px 12px rgba(0, 0, 0, .6));
}
.cvw-crest img, .cvw-crest svg { width: 100%; height: 100%; object-fit: contain; color: #ffd394; }
.cvw-front-foot { margin-top: auto; text-align: center; }
.cvw-quote {
  margin: 0 0 10px;
  font-family: 'Cormorant Garamond', Georgia, serif;
  font-style: italic;
  font-size: clamp(13px, 3.2vw, 16px);
  line-height: 1.3;
  color: #e7d6b4;
}
.cvw-eyebrow {
  font-size: 9px;
  letter-spacing: .24em;
  text-transform: uppercase;
  color: #ffd394;
}
.cvw-title {
  margin: 4px 0 2px;
  font-family: 'Cinzel Decorative', 'Marcellus SC', serif;
  font-size: clamp(19px, 4.6vw, 27px);
  line-height: 1.1;
  color: #fff3dd;
  text-shadow: 0 2px 14px rgba(0, 0, 0, .75);
}
.cvw-sub { font-size: 11.5px; color: rgba(242, 233, 216, .78); }
.cvw-desc {
  margin: 8px 0 0;
  font-family: 'Cormorant Garamond', Georgia, serif;
  font-size: clamp(12.5px, 3vw, 15px);
  line-height: 1.34;
  color: rgba(242, 233, 216, .9);
  display: -webkit-box;
  -webkit-line-clamp: 4;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* --- retro: gli effetti --- */
.cvw-back-in {
  height: 100%;
  overflow: auto;
  touch-action: pan-y;
  padding: 18px 16px 20px;
  color: #f2e9d8;
  font-family: 'Inter', system-ui, sans-serif;
  background:
    radial-gradient(70% 45% at 50% 0%, rgba(240, 164, 65, .12), transparent 70%),
    repeating-linear-gradient(135deg, rgba(240, 164, 65, .05) 0 2px, transparent 2px 9px);
  scrollbar-width: thin;
}
.cvw-back-in h4 {
  margin: 14px 0 6px;
  font-family: 'Marcellus SC', serif;
  font-size: 10.5px;
  letter-spacing: .2em;
  text-transform: uppercase;
  color: #ffd394;
  border-bottom: 1px solid rgba(240, 164, 65, .25);
  padding-bottom: 4px;
}
.cvw-cost { display: flex; flex-wrap: wrap; gap: 8px; }
.cvw-cost div {
  flex: 1 1 64px;
  border: 1px solid rgba(240, 164, 65, .3);
  border-radius: 10px;
  padding: 7px 8px;
  text-align: center;
  background: rgba(20, 14, 8, .5);
}
.cvw-cost strong { display: block; font-size: 17px; color: #ffd394; }
.cvw-cost span { font-size: 8.5px; letter-spacing: .12em; text-transform: uppercase; color: rgba(242, 233, 216, .72); }
.cvw-line { display: flex; gap: 8px; align-items: flex-start; margin: 7px 0; font-size: 12px; line-height: 1.35; }
.cvw-line b { color: #ffd394; font-weight: 600; }
.cvw-line .cvw-ico { flex: none; width: 22px; height: 22px; display: grid; place-items: center; color: #ffd394; }
.cvw-line .cvw-ico img, .cvw-line .cvw-ico svg { width: 100%; height: 100%; object-fit: contain; }
.cvw-line p { margin: 2px 0 0; color: rgba(242, 233, 216, .82); }
.cvw-n { font-family: 'Marcellus SC', serif; color: rgba(240, 164, 65, .8); font-size: 11px; min-width: 18px; }
.cvw-warn { color: #f0c9b0; font-size: 11.5px; margin: 6px 0; }
.cvw-empty { color: rgba(242, 233, 216, .6); font-size: 12px; }

.cvw-hint {
  color: rgba(242, 233, 216, .62);
  font-size: 11px;
  font-family: 'Inter', system-ui, sans-serif;
  text-align: center;
}
.cvw-tools { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }

body.cvw-open { overflow: hidden; }

@media (prefers-reduced-motion: reduce) {
  #cvw, .cvw-card { transition: none; }
  #cvw.cvw-on .cvw-card { animation: none; }
}
