/* Packripper looks like a sheet of stickers on a pastel binder: soft periwinkle paper, chunky
   grape outlines, candy-coloured fills, and a solid offset edge instead of a blurry shadow.
   Rarity reads by colour: cloud (no value), white, mint, sky, lemon, bubblegum.

   No animation or transitions on purpose. State hooks for adding motion later:
   main[data-screen], .card[data-state="top|stacked"], .mini[data-state="seen"], [data-tier]. */

@font-face { font-family: "Bagel Fat One"; src: url("fonts/bagel-fat-one.woff2") format("woff2"); font-display: swap; }
@font-face { font-family: "Atkinson Hyperlegible"; src: url("fonts/atkinson-400.woff2") format("woff2"); font-weight: 400; font-display: swap; }
@font-face { font-family: "Atkinson Hyperlegible"; src: url("fonts/atkinson-700.woff2") format("woff2"); font-weight: 700; font-display: swap; }

:root {
  color-scheme: light;
  --page: #c7d4ff;      /* periwinkle binder */
  --grape: #2b1b5e;     /* outlines and text */
  --grape-soft: #4f437f;
  --paper: #ffffff;
  --cloud: #e9e4f7;     /* energy and other no-value cards */
  --mint: #8fe4bd;      /* uncommon */
  --sky: #9fc8ff;       /* rare */
  --lemon: #ffd84d;     /* hit */
  --bubble: #ff8cbd;    /* big chase */
  --lilac: #b8a4ff;

  --line: 3px;
  --lift: 0 5px 0 var(--grape);

  --display: "Bagel Fat One", "Arial Rounded MT Bold", system-ui, sans-serif;
  --text: "Atkinson Hyperlegible", system-ui, sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background-color: var(--page);
  /* Binder-paper dots. */
  background-image: radial-gradient(rgb(43 27 94 / .09) 1.5px, transparent 1.6px);
  background-size: 22px 22px;
  color: var(--grape);
  font: 1.0625rem/1.5 var(--text);
  overflow-x: hidden;
}
h1, h2, h3, p, ol, figure { margin: 0; padding: 0; }
ol { list-style: none; }
button { color: inherit; font: inherit; cursor: pointer; touch-action: manipulation; }
:focus-visible { outline: 4px solid var(--grape); outline-offset: 4px; }
[tabindex="-1"]:focus { outline: none; }

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* ---- Page ---- */

main {
  max-width: 28rem;
  margin: 0 auto;
  padding:
    max(1.25rem, env(safe-area-inset-top))
    max(1rem, env(safe-area-inset-right))
    max(2.5rem, env(safe-area-inset-bottom))
    max(1rem, env(safe-area-inset-left));
}
.screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.25rem;
  text-align: center;
}
h2 { font: 400 clamp(1.9rem, 9vw, 2.4rem)/1.05 var(--display); text-wrap: balance; }
p { text-wrap: pretty; }
.notice, .error-detail { max-width: 24rem; }

/* ---- Buttons ---- */

.button {
  min-height: 3rem;
  padding: .6rem 1.5rem;
  border: var(--line) solid var(--grape);
  border-radius: 999px;
  background: var(--grape);
  color: var(--paper);
  font-weight: 700;
}
.button.big {
  min-width: 12rem;
  min-height: 3.75rem;
  padding: .5rem 2rem;
  background: var(--bubble);
  color: var(--grape);
  font: 400 1.6rem/1 var(--display);
  box-shadow: var(--lift);
}
.button.quiet { background: var(--paper); color: var(--grape); }
.actions { display: flex; flex-direction: column; align-items: center; gap: .85rem; width: 100%; }
.actions .button { width: min(100%, 18rem); }

.back {
  align-self: flex-start;
  min-height: 2.75rem;
  padding: .4rem .9rem .4rem .7rem;
  border: 0;
  border-radius: 999px;
  background: rgb(255 255 255 / .6);
  font-weight: 700;
}
.back::before { content: "‹ "; font-size: 1.2em; line-height: 1; }

/* ---- Landing ---- */

.wordmark {
  margin-top: 1.5rem;
  font: 400 clamp(3.2rem, 17vw, 4.75rem)/.9 var(--display);
  letter-spacing: -.02em;
  color: var(--paper);
  /* A die-cut sticker outline around each letter. */
  -webkit-text-stroke: 10px var(--grape);
  paint-order: stroke fill;
  text-shadow: 0 6px 0 var(--grape);
  rotate: -3deg;
}
.tagline { max-width: 20rem; font-size: 1.125rem; font-weight: 700; line-height: 1.35; }

.games { display: grid; gap: 1rem; width: 100%; margin-top: .5rem; }
.game {
  display: grid;
  grid-template-columns: 3.5rem 1fr;
  grid-template-rows: auto auto;
  column-gap: .9rem;
  align-items: center;
  min-height: 5.5rem;
  padding: .9rem 1.1rem;
  border: var(--line) solid var(--grape);
  border-radius: 1.4rem;
  background: var(--paper);
  box-shadow: var(--lift);
  text-align: left;
}
.game:nth-child(3n + 1) { background: var(--lemon); }
.game:nth-child(3n + 2) { background: var(--mint); }
.game:nth-child(3n + 3) { background: var(--bubble); }
.game-icon {
  grid-row: 1 / 3;
  display: grid;
  place-items: center;
  width: 3.5rem;
  height: 3.5rem;
  border: var(--line) solid var(--grape);
  border-radius: 50%;
  background: var(--paper);
  font-size: 1.7rem;
  line-height: 1;
}
.game-name { font: 400 1.7rem/1.05 var(--display); }
.game-series { font-weight: 700; font-size: .95rem; }

/* ---- Today's pack ---- */

/* A foil pack with crimped ends, printed with the set name on a label. */
.pack {
  --pack: var(--lilac);
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: .9rem;
  width: min(100%, 17rem);
  min-height: 16rem;
  margin: 1.25rem 0 .5rem;
  padding: 2.25rem 1.25rem;
  background: var(--pack);
  border-radius: .5rem;
}
.pack::before, .pack::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  height: 14px;
  background:
    linear-gradient(-45deg, var(--pack) 7px, transparent 0),
    linear-gradient(45deg, var(--pack) 7px, transparent 0);
  background-size: 14px 14px;
  background-repeat: repeat-x;
}
.pack::before { top: -13px; background-position: left bottom; }
.pack::after { bottom: -13px; background-position: left bottom; rotate: 180deg; }
/* Tear line along the top. */
.pack-game {
  position: absolute;
  top: .9rem;
  left: 1rem;
  right: 1rem;
  padding-bottom: .5rem;
  border-bottom: 2px dashed var(--grape);
  font-weight: 700;
  font-size: .95rem;
}
.pack-series {
  max-width: 100%;
  padding: .7rem 1rem .8rem;
  border: var(--line) solid var(--grape);
  border-radius: 1rem;
  background: var(--paper);
  box-shadow: var(--lift);
  overflow-wrap: anywhere;
  rotate: -3deg;
}
.pack-date { font-weight: 700; font-size: .95rem; text-wrap: balance; }
.intro-copy { max-width: 20rem; }

/* ---- The face-up stack ---- */

.reveal-head { display: grid; gap: .3rem; justify-items: center; }
#reveal-title { font-size: clamp(1.5rem, 7vw, 1.9rem); }
.counter {
  min-width: 5.5rem;
  padding: .15rem .8rem;
  border: var(--line) solid var(--grape);
  border-radius: 999px;
  background: var(--paper);
  font-weight: 700;
}

.stack-area {
  --card-w: clamp(10rem, min(68vw, 16rem, calc((100vh - 25rem) * .716)), 16rem);
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
}
@supports (height: 100svh) {
  .stack-area { --card-w: clamp(10rem, min(68vw, 16rem, calc((100svh - 25rem) * .716)), 16rem); }
}

.stack {
  position: relative;
  width: var(--card-w);
  aspect-ratio: 63 / 88;
  /* Each card underneath peeks out one step down and right. Space below the stack is
     reserved for the deepest it gets in this pack (--max-edges, set from the pack size),
     plus a fixed gap, so the plate never touches the edges and doesn't move between cards. */
  --edge-x: 3px;
  --edge-y: 6px;
  --edge-gap: 1.25rem;
  margin: .5rem 0 calc(var(--max-edges, 5) * var(--edge-y) + var(--edge-gap));
  padding: 0;
  border: 0;
  border-radius: 1rem;
  background: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
}
.stack:focus-visible { outline: 3px dashed var(--grape); outline-offset: 14px; }

.card {
  position: absolute;
  inset: 0;
  display: block;
  border: var(--line) solid var(--grape);
  border-radius: 1rem;
}
/* Edges of the cards still in the stack: blank, candy-coloured, stepping down and right. */
.card.edge {
  translate: calc(var(--depth) * var(--edge-x, 3px)) calc(var(--depth) * var(--edge-y, 6px));
  background: var(--paper);
}
.card.edge:nth-child(4n + 1) { background: var(--mint); }
.card.edge:nth-child(4n + 2) { background: var(--lemon); }
.card.edge:nth-child(4n + 3) { background: var(--bubble); }
.card.edge:nth-child(4n + 4) { background: var(--sky); }

.card.top {
  padding: 6px;
  background: var(--tier, var(--paper));
}
.art {
  display: grid;
  place-items: center;
  width: 100%;
  height: 100%;
  overflow: hidden;
  border-radius: .6rem;
  background: var(--paper);
}
.art img { width: 100%; height: 100%; object-fit: contain; display: block; }

/* No picture: show the name and rarity on a dotted card face instead. */
.art.no-image {
  align-content: center;
  gap: .4rem;
  padding: .75rem;
  background-color: var(--paper);
  background-image: radial-gradient(var(--dot, var(--cloud)) 3px, transparent 3.2px);
  background-size: 16px 16px;
  text-align: center;
}
.ph-name {
  padding: .3rem .6rem;
  border-radius: .6rem;
  background: var(--paper);
  font: 400 1.35rem/1.1 var(--display);
  overflow-wrap: anywhere;
}
.ph-rarity, .ph-note { padding: 0 .5rem; border-radius: 999px; background: var(--paper); font-weight: 700; font-size: .875rem; }
.ph-note { font-weight: 400; }

/* Rarity colours. */
[data-tier] { --dot: var(--tier); }
[data-tier="basic"] { --tier: var(--cloud); --dot: #d6cdf2; }
[data-tier="common"] { --tier: var(--paper); --dot: #d6cdf2; }
[data-tier="uncommon"] { --tier: var(--mint); }
[data-tier="rare"] { --tier: var(--sky); }
[data-tier="hit"] { --tier: var(--lemon); }
[data-tier="chase"] { --tier: var(--bubble); }

/* Hits get a thicker frame; chases get a lemon ring outside the outline as well. */
.card.top[data-tier="hit"], .card.top[data-tier="chase"] { padding: 10px; }
.card.top[data-tier="chase"], .best-card[data-tier="chase"] {
  box-shadow: 0 0 0 5px var(--lemon), 0 0 0 8px var(--grape);
}
.card.top[data-best="true"] { box-shadow: 0 0 0 5px var(--paper), 0 0 0 8px var(--grape); }
.card.top[data-best="true"][data-tier="chase"] {
  box-shadow: 0 0 0 5px var(--lemon), 0 0 0 8px var(--grape), 0 0 0 13px var(--paper), 0 0 0 16px var(--grape);
}

.sticker {
  position: absolute;
  top: -.9rem;
  right: -1.1rem;
  z-index: 1;
  padding: .3rem .8rem .4rem;
  border: var(--line) solid var(--grape);
  border-radius: 999px;
  background: var(--lemon);
  font: 400 1.05rem/1 var(--display);
  white-space: nowrap;
  rotate: 8deg;
}
[data-tier="hit"] > .sticker { background: var(--bubble); }

/* The card's label plate: name, rarity and price of the top card. */
.caption {
  display: grid;
  justify-items: center;
  gap: .45rem;
  width: min(100%, 21rem);
  padding: .8rem 1rem .9rem;
  border: var(--line) solid var(--grape);
  border-radius: 1.2rem;
  background: var(--paper);
  box-shadow: var(--lift);
}
.card-name { font: 400 1.45rem/1.1 var(--display); overflow-wrap: anywhere; }
.tags { display: flex; flex-wrap: wrap; justify-content: center; gap: .4rem; }
.badge, .finish {
  padding: .1rem .7rem;
  border: 2px solid var(--grape);
  border-radius: 999px;
  font-weight: 700;
  font-size: .9rem;
}
.badge { background: var(--tier, var(--paper)); }
.finish { background: var(--paper); border-style: dashed; }
.price { font: 400 1.6rem/1 var(--display); }
.price.none, .row-price.none { font: 700 .95rem/1.2 var(--text); color: var(--grape-soft); }

.hint { font-weight: 700; }

.seen-wrap { display: grid; gap: .5rem; width: 100%; margin-top: .25rem; }
.seen-title, .list-title { font-weight: 700; font-size: 1rem; }
.seen {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(2.6rem, 1fr));
  gap: .45rem;
  padding: .7rem;
  border-radius: 1rem;
  background: rgb(255 255 255 / .55);
}
.mini {
  display: grid;
  aspect-ratio: 63 / 88;
  padding: 2px;
  border: 2px solid var(--grape);
  border-radius: .45rem;
  background: var(--tier, var(--paper));
}
.mini .art { border-radius: .25rem; }
.mini .art.no-image > * { display: none; }
.mini .art.no-image { background-size: 10px 10px; background-image: radial-gradient(var(--dot) 2px, transparent 2.2px); }

/* While loading: a blank stack of card edges waiting to be filled. */
.loading-stack {
  position: relative;
  display: block;
  width: 9rem;
  aspect-ratio: 63 / 88;
  margin: .5rem 0 2rem;
}
.loading-stack .card:last-child { background: var(--paper); }

/* ---- Results ---- */

.totals { display: grid; grid-template-columns: 1fr 1fr; gap: .9rem; width: 100%; }
.total {
  display: grid;
  gap: .2rem;
  padding: .9rem .5rem 1rem;
  border: var(--line) solid var(--grape);
  border-radius: 1.2rem;
  box-shadow: var(--lift);
}
.total strong { font: 400 clamp(1.6rem, 8vw, 2.2rem)/1 var(--display); overflow-wrap: anywhere; }
.total span { font-weight: 700; font-size: .95rem; }
.total.value { background: var(--lemon); rotate: -2deg; }
.total.rarity { background: var(--mint); rotate: 2deg; }

.best { display: grid; justify-items: center; gap: .9rem; margin-top: .75rem; }
.best-card {
  position: relative;
  display: block;
  width: 11.5rem;
  aspect-ratio: 63 / 88;
  padding: 8px;
  border: var(--line) solid var(--grape);
  border-radius: 1rem;
  background: var(--tier, var(--paper));
}
.best figcaption { display: grid; justify-items: center; gap: .4rem; }

.list-title { align-self: flex-start; }
.recap {
  display: grid;
  width: 100%;
  margin-top: -.6rem;
  border: var(--line) solid var(--grape);
  border-radius: 1.2rem;
  background: var(--paper);
  overflow: hidden;
  text-align: left;
}
.row {
  display: grid;
  grid-template-columns: 2.4rem 1fr auto;
  align-items: center;
  gap: .75rem;
  padding: .5rem .8rem;
}
.row + .row { border-top: 2px dotted rgb(43 27 94 / .3); }
.row-art {
  width: 2.4rem;
  aspect-ratio: 63 / 88;
  height: auto;
  border: 2px solid var(--grape);
  border-radius: .35rem;
  background: var(--tier, var(--paper));
}
.row .art.no-image > * { display: none; }
.row-text { display: grid; min-width: 0; line-height: 1.25; }
.row-name { font-weight: 700; overflow-wrap: anywhere; }
.row-rarity {
  justify-self: start;
  margin-top: .15rem;
  padding: 0 .5rem;
  border-radius: 999px;
  background: var(--tier, var(--paper));
  font-size: .85rem;
}
.row[data-tier="common"] .row-rarity { box-shadow: inset 0 0 0 1.5px var(--grape); }
.row-price { font-weight: 700; white-space: nowrap; }

.share-box { display: grid; gap: .6rem; width: 100%; margin-top: .5rem; }
.share-box .list-title { justify-self: start; }
#share {
  width: 100%;
  padding: .8rem .9rem;
  border: var(--line) solid var(--grape);
  border-radius: 1rem;
  background: var(--paper);
  color: var(--grape);
  font: 1rem/1.5 var(--text);
  resize: none;
  overflow: hidden;
}
#copy { justify-self: center; min-width: 12rem; }
.copy-status { min-height: 1.5em; font-weight: 700; }

/* Wider screens: the same column, with a little more air. */
@media (min-width: 40rem) {
  main { padding-top: 3rem; }
}
