/* Cards tab (cards.js): OSRS-collection-style cards, the pack and the
   reveal. Each tier has a colour (--tc) and a pale wash behind the
   museum's white-backed drawings (--wash). */
.t-common { --tc: #b9bdc8; --wash: #dcdfe5; --glow: transparent; }
.t-uncommon { --tc: #62d39b; --wash: #d4ecdc; --glow: rgba(98, 211, 155, 0.22); }
.t-rare { --tc: #6fb0ff; --wash: #d3e2f5; --glow: rgba(111, 176, 255, 0.3); }
.t-epic { --tc: #c792ff; --wash: #e6d8f4; --glow: rgba(199, 146, 255, 0.38); }
.t-legendary { --tc: #ffc44d; --wash: #f5e7c0; --glow: rgba(255, 196, 77, 0.5); }

#cards { display: grid; gap: 18px; }
#cards .small { font-size: 0.82rem; }

.cards-wallet { display: grid; gap: 4px; }
.cards-wallet .coins { display: flex; align-items: center; gap: 8px; font-size: 1.05rem; }
.cards-wallet .coins b { font-family: var(--fun); font-size: 1.6rem; font-weight: 600; color: var(--gold); }
.coin {
  width: 22px; height: 22px; border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #fff3c4, #ffcf63 45%, #b8862a);
  box-shadow: inset 0 0 0 2px #a07420;
}

.cards-race { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.racer {
  display: grid; grid-template-columns: auto 1fr; gap: 2px 10px; align-items: baseline;
  padding: 10px 12px; text-align: left; font: inherit; color: var(--text);
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); cursor: pointer;
}
.racer.on { border-color: var(--line-strong); background: var(--surface-2); }
.racer.p1 { --pc: var(--p1); }
.racer.p2 { --pc: var(--p2); }
.racer-who { font-family: var(--fun); font-weight: 600; font-size: 1.2rem; color: var(--pc); }
.racer-score { font-family: var(--fun); font-size: 1.3rem; font-weight: 600; text-align: right; font-variant-numeric: tabular-nums; }
.racer-bar { grid-column: 1 / -1; height: 5px; /* share of the set found */ background: var(--line); border-radius: 3px; overflow: hidden; }
.racer-bar i { display: block; height: 100%; background: var(--pc); }
.racer-sub { grid-column: 1 / -1; font-size: 0.78rem; }

.cards-shelf {
  display: flex; gap: 20px; align-items: center;
  padding: 16px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r);
}
.shelf-text { display: grid; gap: 6px; justify-items: start; }
.shelf-text h2 { margin: 0; font-size: 1.15rem; }
.shelf-text p { margin: 0; }
.odds { display: flex; flex-wrap: wrap; gap: 4px 10px; }
.odd { color: var(--tc); }
.open-pack { margin-top: 4px; }

/* The pack: a foil wrapper with crimped ends. */
.pack { width: 112px; flex: none; filter: drop-shadow(0 6px 14px rgba(0, 0, 0, 0.5)); }
.pack-face {
  position: relative; isolation: isolate; height: 150px; overflow: hidden; display: grid; place-items: end center; padding-bottom: 10px;
  background: linear-gradient(160deg, #2f7a55, #17402e 55%, #0f2a1f);
  border-left: 1px solid #5fa982; border-right: 1px solid #0b1f17;
}
.pack-face::after {
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(115deg, transparent 30%, rgba(255, 255, 255, 0.28) 45%, transparent 60%);
  background-size: 250% 100%; animation: foil 4s ease-in-out infinite;
}
.pack-face img {
  position: absolute; top: 14px; left: 50%; width: 130%; transform: translateX(-50%);
  mix-blend-mode: multiply; filter: grayscale(1) contrast(1.4); opacity: 0.6;
}
.pack-title, .pack-sub { position: relative; z-index: 1; font-family: var(--fun); color: #ffe7a6; text-shadow: 0 2px 0 #0b1f17; line-height: 1; }
.pack-title { font-size: 1.7rem; font-weight: 700; letter-spacing: 0.06em; }
.pack-sub { font-size: 0.7rem; font-weight: 600; letter-spacing: 0.35em; margin-top: 2px; }
.pack-face { grid-template-rows: auto auto; align-content: end; }
.pack-crimp { height: 12px; background: repeating-linear-gradient(90deg, #c8b06a 0 4px, #8f7a3c 4px 6px); }
.pack-crimp.top { border-radius: 2px 2px 0 0; }
.pack-crimp.bottom { border-radius: 0 0 2px 2px; }
@keyframes foil { 0%, 100% { background-position: 100% 0; } 50% { background-position: 0 0; } }

/* A card. */
.card {
  position: relative; display: grid; grid-template-rows: auto auto auto 1fr auto; gap: 5px;
  padding: 6px; min-width: 0;
  background: #2b313c; border: 2px solid color-mix(in srgb, var(--tc) 70%, #000); border-radius: 6px;
  box-shadow: 0 0 0 1px #0007, 0 0 18px var(--glow);
  color: #eef0f6; text-align: center; font-size: 0.78rem; line-height: 1.3;
}
.card-name, .card-tier, .card-score {
  margin: 0; padding: 3px 6px; border-radius: 3px;
  background: color-mix(in srgb, var(--tc) 22%, #1a1e26);
  color: var(--tc); font-weight: 600;
}
.card-name { font-size: 0.86rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card-tier { font-size: 0.72rem; }
.card-score { color: #eef0f6; font-size: 0.75rem; font-variant-numeric: tabular-nums; }
/* The picture panel: each tier has its own background, and the cut-out
   drawings (tools/cardcutout.py) sit on it as stickers; scenes and colour
   renders are framed whole on it. */
.card-pic {
  position: relative; isolation: isolate; aspect-ratio: 4 / 3; border-radius: 3px; overflow: hidden;
  display: grid; place-items: center;
}
/* Pinned to the box's edges: a box sized only by its aspect ratio doesn't
   give a percentage height to its child, so a tall picture would spill out
   and be cropped (Alvarezsaurus showed only its tail). */
.card-pic img { position: absolute; inset: 0; z-index: 1; width: 100%; height: 100%; object-fit: contain; box-sizing: border-box; }
.card-pic.pic-sticker img { padding: 6px; filter: drop-shadow(0 2px 3px rgb(0 0 0 / 0.45)); }
.card-pic.pic-scene img { padding: 8px; filter: drop-shadow(0 2px 4px rgb(0 0 0 / 0.5)); }
.t-common .card-pic { background: radial-gradient(circle at 50% 40%, #434a59, #262b35 75%); }
.t-uncommon .card-pic { background: radial-gradient(circle at 50% 40%, #3a7a5b, #183a2c 75%); }
.t-rare .card-pic {
  background:
    repeating-linear-gradient(135deg, rgb(255 255 255 / 0.05) 0 2px, transparent 2px 9px),
    radial-gradient(circle at 50% 40%, #3b6fb5, #142a4d 75%);
}
.t-epic .card-pic { background: radial-gradient(circle at 50% 40%, #7b4bbd, #2c1650 75%); }
/* Epic: a slow sheen across; Legendary: a faint holo (below). */
.t-epic .card-pic::before, .t-legendary .card-pic::before { content: ""; position: absolute; inset: 0; z-index: 0; pointer-events: none; }
.t-epic .card-pic::before {
  background: linear-gradient(115deg, transparent 30%, rgb(255 255 255 / 0.22) 45%, transparent 60%);
  background-size: 250% 100%; animation: foil 5s ease-in-out infinite;
}
/* Legendary: dark gold with a faint rainbow drifting across it and a soft
   sheen, so the holo hints rather than shouts. */
.t-legendary .card-pic {
  background:
    linear-gradient(115deg, rgb(255 159 184 / 0.22), rgb(255 217 138 / 0.22), rgb(182 245 163 / 0.22), rgb(143 216 255 / 0.22), rgb(199 163 255 / 0.22), rgb(255 159 184 / 0.22)),
    radial-gradient(circle at 50% 40%, #6b5a2c, #2e2612 75%);
  background-size: 300% 300%, auto; animation: holo 14s linear infinite;
}
.t-legendary .card-pic::before {
  background: linear-gradient(115deg, transparent 38%, rgb(255 236 180 / 0.18) 48%, transparent 58%);
  background-size: 250% 100%; animation: foil 6s ease-in-out infinite;
}
@keyframes holo { to { background-position: 300% 300%, 0 0; } }
/* Borders, not padding, so the clamp doesn't show a sliver of a sixth line. */
.card-text {
  margin: 0; padding: 0 6px; border: 6px solid #3a414d; border-width: 6px 0; border-radius: 3px;
  background: #3a414d; color: #d7dbe4;
  display: -webkit-box; -webkit-line-clamp: 5; -webkit-box-orient: vertical; overflow: hidden; height: calc(6.5em + 12px);
}
.card-new {
  position: absolute; top: -17px; left: 50%; transform: translateX(-50%);
  font-family: var(--fun); font-weight: 700; font-size: 0.8rem; color: #ffd84d; text-shadow: 0 1px 0 #6a4b00, 0 0 8px #000;
}
.card-count {
  position: absolute; top: -8px; right: -8px; z-index: 1; padding: 1px 7px; border-radius: 10px;
  background: var(--tc); color: #111; font-family: var(--fun); font-weight: 700; font-size: 0.8rem;
}
.card-pity {
  position: absolute; bottom: -20px; left: 0; right: 0; font-size: 0.72rem; color: var(--gold);
}
.t-legendary.card::before {
  content: ""; position: absolute; inset: 0; border-radius: 4px; pointer-events: none;
  background: linear-gradient(115deg, transparent 35%, rgba(255, 230, 150, 0.22) 48%, transparent 60%);
  background-size: 250% 100%; animation: foil 3.5s ease-in-out infinite;
}

.binder-sub { margin: 8px 0 0; font-size: 0.95rem; font-weight: 450; color: var(--soft); }
.tile-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(76px, 1fr)); gap: 6px; }
.tile {
  display: grid; gap: 2px; padding: 3px; border-radius: 4px; background: #1b1f27;
  border: 1px solid #2a303b; border-bottom: 3px solid color-mix(in srgb, var(--tc) 55%, #1b1f27);
}
/* A card still to find: its tier's background (as on .card-pic, dimmed),
   with a sticker's solid silhouette or a scene blurred past knowing. */
.tile-pic { position: relative; aspect-ratio: 4 / 3; border-radius: 2px; overflow: hidden; }
.tile-pic img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; box-sizing: border-box; }
.tile-pic.pic-sticker img, .tile-pic.pic-sil img { padding: 3px; filter: brightness(0); opacity: 0.8; }
.tile-pic.pic-scene img { padding: 4px; filter: blur(5px) grayscale(1) brightness(0.35); }
.tile.t-common .tile-pic { background: radial-gradient(circle at 50% 40%, #434a59, #262b35 75%); }
.tile.t-uncommon .tile-pic { background: radial-gradient(circle at 50% 40%, #3a7a5b, #183a2c 75%); }
.tile.t-rare .tile-pic { background: radial-gradient(circle at 50% 40%, #3b6fb5, #142a4d 75%); }
.tile.t-epic .tile-pic { background: radial-gradient(circle at 50% 40%, #7b4bbd, #2c1650 75%); }
.tile.t-legendary .tile-pic {
  background:
    linear-gradient(115deg, rgb(255 159 184 / 0.22), rgb(255 217 138 / 0.22), rgb(143 216 255 / 0.22), rgb(199 163 255 / 0.22)),
    radial-gradient(circle at 50% 40%, #6b5a2c, #2e2612 75%);
}
.tile-no { font-size: 0.68rem; color: var(--muted); text-align: center; }

.binder { display: grid; gap: 12px; }
.binder-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px; }
.binder-bar h2 { margin: 0 auto 0 0; font-size: 1.1rem; }
.binder .seg button.on { background: var(--raised); color: var(--text); }
.cards-dialog dl { margin: 0 0 14px; }
.card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 16px 12px; }
.card-grid .card:not(.missing) { cursor: pointer; transition: transform 0.12s; }
.card-grid .card:not(.missing):hover, .card-grid .card:focus-visible { transform: translateY(-3px); outline: none; }

/* Dialogs: a card's details, and opening a pack. */
.cards-dialog {
  max-width: min(880px, calc(100vw - 24px)); width: 100%; max-height: calc(100dvh - 24px);
  padding: 20px; background: var(--surface); color: var(--text); border: 1px solid var(--line-strong); border-radius: 6px;
}
.cards-dialog::backdrop { background: rgba(4, 6, 10, 0.78); }
.detail[open] { display: grid; grid-template-columns: 260px 1fr; gap: 20px; align-items: start; }
.detail .card { font-size: 0.85rem; }
.detail .card-text { -webkit-line-clamp: unset; display: block; height: auto; }
.detail-text p { margin: 0 0 10px; color: var(--soft); }
.facts { display: grid; grid-template-columns: auto 1fr; gap: 3px 12px; margin: 0 0 14px; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; }
.detail-text a { color: var(--accent-hi); }

.reveal[open] { display: grid; justify-items: center; gap: 18px; padding: 28px 16px 20px; overflow: visible auto; }
.reveal-cards { display: grid; grid-template-columns: repeat(5, 150px); gap: 26px 14px; justify-content: center; align-items: stretch; }
.flip-inner, .flip-front, .flip-front .card { height: 100%; }
.reveal-foot { display: grid; justify-items: center; gap: 8px; min-height: 40px; }
.tear .pack { width: 150px; }
.tear .pack-face { height: 200px; }
.tear { animation: shake 0.45s ease-in-out; }
.tear.torn .pack-crimp.top { transform: translate(30px, -60px) rotate(25deg); opacity: 0; transition: all 0.5s ease-in; }
.tear.torn .pack-face { transform: scale(1.08); opacity: 0; transition: all 0.55s ease-in 0.1s; }
.tear.torn .pack-crimp.bottom { opacity: 0; transition: opacity 0.4s; }
@keyframes shake {
  0%, 100% { transform: rotate(0); }
  20% { transform: rotate(-4deg); } 40% { transform: rotate(4deg); }
  60% { transform: rotate(-3deg); } 80% { transform: rotate(2deg); }
}
.reveal:not(.dealt) .reveal-cards, .reveal:not(.dealt) .reveal-foot { display: none; }
.reveal.dealt .flip { animation: deal 0.45s cubic-bezier(0.2, 0.9, 0.3, 1.2) backwards; animation-delay: calc(var(--i) * 90ms); }
@keyframes deal { from { transform: translateY(-120px) rotate(-8deg) scale(0.7); opacity: 0; } }

.flip { position: relative; padding: 0; border: 0; background: none; font: inherit; color: inherit; cursor: pointer; perspective: 900px; }
.flip:disabled { cursor: default; opacity: 1; }
.reveal .flip:hover:not(:disabled) { background: none; border: 0; }
.flip-inner { position: relative; display: grid; transition: transform 0.6s cubic-bezier(0.3, 0.7, 0.3, 1); transform-style: preserve-3d; }
.flip-back, .flip-front { grid-area: 1 / 1; backface-visibility: hidden; }
.flip-front { transform: rotateY(180deg); }
.flip.turned .flip-inner { transform: rotateY(180deg); }
.flip-back {
  display: grid; place-items: center; border-radius: 6px; border: 2px solid #8f7a3c;
  background: repeating-linear-gradient(45deg, #1f4d38 0 8px, #1a4231 8px 16px);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.5);
}
.flip:not(.turned):hover .flip-back { transform: translateY(-4px); box-shadow: 0 10px 22px rgba(0, 0, 0, 0.55); }
.back-mark { font-family: var(--fun); font-weight: 700; font-size: 1.3rem; color: #ffe7a6; letter-spacing: 0.08em; border: 2px solid #c8b06a; padding: 8px 12px; border-radius: 4px; }
/* A rare-or-better card hints through its back before it turns. */
.flip.t-rare:not(.turned) .flip-back, .flip.t-epic:not(.turned) .flip-back, .flip.t-legendary:not(.turned) .flip-back {
  animation: hint 1.6s ease-in-out infinite;
}
/* A Legendary shaking harder and glowing through the drums before it turns. */
.flip.charging .flip-back { animation: charge 0.75s ease-in forwards !important; }
@keyframes charge {
  0% { transform: none; box-shadow: 0 6px 16px rgba(0, 0, 0, 0.5); }
  20% { transform: translateX(-2px) rotate(-1deg); }
  40% { transform: translateX(3px) rotate(1.5deg); }
  60% { transform: translateX(-4px) rotate(-2deg); }
  80% { transform: translateX(5px) rotate(2.5deg) scale(1.03); }
  100% { transform: scale(1.06); box-shadow: 0 6px 16px rgba(0, 0, 0, 0.5), 0 0 40px 10px var(--glow); }
}
@keyframes hint { 50% { box-shadow: 0 6px 16px rgba(0, 0, 0, 0.5), 0 0 22px var(--glow); } }
.spark {
  position: absolute; left: 50%; top: 40%; width: 6px; height: 6px; border-radius: 50%; pointer-events: none;
  background: var(--tc); box-shadow: 0 0 8px var(--tc);
  animation: spark 0.9s ease-out forwards; animation-delay: var(--d);
}
@keyframes spark { to { transform: translate(var(--x), var(--y)) scale(0.2); opacity: 0; } }

@media (max-width: 720px) {
  .reveal-cards { grid-template-columns: repeat(2, minmax(0, 150px)); }
  .reveal-cards .flip:last-child { grid-column: 1 / -1; justify-self: center; width: calc(50% - 7px); }
  .detail[open] { grid-template-columns: 1fr; }
  .detail-card { max-width: 260px; justify-self: center; width: 100%; }
}
@media (max-width: 480px) {
  .cards-shelf { flex-direction: column; text-align: center; }
  .shelf-text { justify-items: center; }
  .odds { justify-content: center; }
  .card-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px 10px; }
  .cards-race { gap: 8px; }
}
@media (prefers-reduced-motion: reduce) {
  .pack-face::after, .t-legendary.card::before, .flip-back, .card-pic, .card-pic::before { animation: none !important; }
  .flip-inner { transition: none; }
  .flip.charging .flip-back { animation: none !important; box-shadow: 0 6px 16px rgba(0, 0, 0, 0.5), 0 0 40px 10px var(--glow); }
}

/* Trades (cards.js tradesEl, tradeBuilder). */
.cards-trades { display: grid; gap: 10px; }
.trades-bar { display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px 14px; }
.trades-bar h2 { margin: 0; font-size: 1.1rem; }
.trades-bar button { margin-left: auto; }
.offer { padding: 12px; border: 1px solid var(--line-strong); border-radius: var(--r); background: var(--surface); }
.offer-head { margin: 0 0 8px; color: var(--soft); }
.offer-sides { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.offer-sides h4, .cards-dialog.trade h3 { margin: 0 0 6px; color: var(--muted); font-size: 0.78rem; font-weight: 500; letter-spacing: 0.04em; text-transform: uppercase; }
.offer-buttons { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.trade-history { margin: 0; padding-left: 1.2em; }
.mini-row { display: flex; flex-wrap: wrap; gap: 6px; }
.mini {
  display: grid; gap: 2px; width: 92px; padding: 3px; border-radius: 4px; text-align: center;
  background: #2b313c; border: 2px solid color-mix(in srgb, var(--tc) 70%, #000); font-size: 0.68rem; line-height: 1.2;
}
.mini .card-pic { aspect-ratio: 4 / 3; }
.mini .card-pic img { padding: 2px; }
.mini-name { color: var(--tc); font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mini-score { color: var(--muted); font-variant-numeric: tabular-nums; }
.mini-row.pick .mini { cursor: pointer; opacity: 0.55; transition: opacity 0.12s, transform 0.12s; }
.mini-row.pick .mini.on { opacity: 1; transform: translateY(-2px); box-shadow: 0 0 0 2px var(--accent); }
.mini-row.pick .mini:focus-visible { outline: 2px solid var(--accent-hi); }
.cards-dialog.trade[open] { display: grid; gap: 10px; }
.cards-dialog.trade h2 { margin: 0; }
.trade-total { margin: 0; color: var(--soft); }
.card-trade {
  position: absolute; left: 50%; bottom: -9px; transform: translateX(-50%); z-index: 1; white-space: nowrap;
  padding: 1px 7px; border-radius: 9px; background: var(--accent); color: #fff; font-size: 0.66rem; font-weight: 600;
}
@media (max-width: 480px) { .offer-sides { grid-template-columns: 1fr; } .mini { width: 84px; } }

/* The Dino pack's jungle, behind the Cards tab only (app.js sets
   body.jungle while it's showing; the winter snow stays on the other tabs):
   a deep green night with fireflies, leaves and vines hanging from the top,
   ferns and leaves along the bottom, all fixed while the page scrolls. */
body.jungle {
  --bg: #08130d;
  background:
    url(jungle-canopy.svg) center top / 900px auto repeat-x,
    url(jungle-floor.svg) center bottom / 900px auto repeat-x,
    radial-gradient(circle at 30% 40%, rgb(214 240 120 / 0.35) 1px, transparent 2.2px) 0 0 / 173px 151px,
    radial-gradient(circle at 70% 70%, rgb(214 240 120 / 0.2) 1.4px, transparent 3px) 0 0 / 263px 229px,
    radial-gradient(ellipse at 50% 0%, #143322, transparent 70%),
    linear-gradient(#0c1d14, #08130d 70%) no-repeat,
    #08130d;
  background-attachment: fixed;
}
/* The fairy lights don't belong in a jungle. */
body.jungle > header::after { opacity: 0; }
@media (max-width: 559px) {
  body.jungle {
    background-size: 600px auto, 600px auto, 173px 151px, 263px 229px, auto, auto, auto;
  }
}
