/* Card backs from the shop (bt tin, bw walnut, vt velvet, pc pumpkin, bs squared paper): paint only, drawn here in CSS and inline SVG.
   /cardkit/backs.js sets <html data-card-back="<id>"> when this browser owns the chosen back, and never on the card
   tables (blackjack and holdem don't load it). Without the attribute every rule below is inert and the usual back
   in cards.css shows. Sizes are in var(--cw), the card's width, so a back reads the same on a 34 px Spider card and
   a 90 px Solitaire one. .cardback is a loose swatch of the same back: the chooser's buttons and Benchwork's draw
   pile. A swatch with data-back="<id>" shows that back whatever is chosen; one without follows the choice. */

.cardback { --cw: 26px; position: relative; display: inline-block; flex: none; box-sizing: border-box; width: var(--cw); height: calc(var(--cw) * 1.4); overflow: hidden; border: 1px solid var(--ink, #171815); border-radius: calc(var(--cw) * .09); background: url(/favicon.png) center / 58% no-repeat, repeating-linear-gradient(45deg, #e3ff5914 0 3px, transparent 3px 7px), #171815; box-shadow: inset 0 0 0 calc(var(--cw) * .05) #171815, inset 0 0 0 calc(var(--cw) * .05 + 1px) var(--acid, #e3ff59); vertical-align: middle; }

/* Tin: pressed sheet with a raised rim, a grid of embossed dimples and a cold sheen across it. */
html[data-card-back="bt"] .felt .back, html[data-card-back="bt"] .cardback:not([data-back]), .cardback[data-back="bt"] {
  border-color: #4d5559;
  background:
    radial-gradient(circle at 50% 50%, transparent 0 calc(var(--cw) * .13), #4d555940 calc(var(--cw) * .13) calc(var(--cw) * .145), #eef1f2aa calc(var(--cw) * .15) calc(var(--cw) * .165), transparent calc(var(--cw) * .17)) center / 100% 100% no-repeat,
    radial-gradient(circle at 38% 36%, #f2f5f6 0 9%, #c9d0d3 18%, #8d969b 30%, #5f686d 36%, transparent 41%) center / calc(var(--cw) * .2) calc(var(--cw) * .2),
    linear-gradient(125deg, #c9d0d3 0%, #8d969b 34%, #dfe4e6 50%, #8d969b 66%, #b3bbbf 100%);
  box-shadow: inset 0 0 0 calc(var(--cw) * .065) #a9b1b5, inset 1.5px 1.5px 0 calc(var(--cw) * .065) #eef1f2, inset -1.5px -1.5px 0 calc(var(--cw) * .065) #4d5559;
}

/* Walnut: book-matched cathedral grain rising from the foot, fine straight pores, a boxwood stringing line. */
html[data-card-back="bw"] .felt .back, html[data-card-back="bw"] .cardback:not([data-back]), .cardback[data-back="bw"] {
  border-color: #2e1d10;
  background:
    repeating-linear-gradient(90deg, #2e1d101c 0 1px, transparent 1px 3px),
    repeating-radial-gradient(55% 170% at 50% 118%, #5a3a22 0 calc(var(--cw) * .045), #74492b calc(var(--cw) * .045) calc(var(--cw) * .075), #8a5d3b calc(var(--cw) * .075) calc(var(--cw) * .088), #5f3d24 calc(var(--cw) * .088) calc(var(--cw) * .13)),
    #5a3a22;
  box-shadow: inset 0 0 0 calc(var(--cw) * .05) #2e1d10, inset 0 0 0 calc(var(--cw) * .05 + 1.5px) #d6a878, inset 0 0 calc(var(--cw) * .2) #2e1d10aa;
}

/* Velvet: bank-carpet purple, a nap you can see the light move across, a brass piping and one fingerprint. */
html[data-card-back="vt"] .felt .back, html[data-card-back="vt"] .cardback:not([data-back]), .cardback[data-back="vt"] {
  border-color: #1e0f25;
  background:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 40 50'%3E%3Cg fill='none' stroke='%23c9a6d6' stroke-width='1.2' stroke-dasharray='9 2.5 14 2' stroke-linecap='round'%3E%3Cellipse cx='20' cy='25' rx='3' ry='5'/%3E%3Cellipse cx='20' cy='25' rx='6.5' ry='9.5'/%3E%3Cellipse cx='20' cy='25' rx='10' ry='14'/%3E%3Cellipse cx='20' cy='25' rx='13.5' ry='18.5'/%3E%3Cellipse cx='20' cy='25' rx='17' ry='23'/%3E%3C/g%3E%3C/svg%3E") 74% 70% / 34% auto no-repeat,
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='96' height='96'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 .9 0 0 0 0 .75 0 0 0 0 1 0 0 0 .22 0'/%3E%3C/filter%3E%3Crect width='96' height='96' filter='url(%23n)'/%3E%3C/svg%3E") 0 0 / 48px 48px,
    linear-gradient(118deg, transparent 22%, #8d5aa255 40%, transparent 58%, #1e0f2566 80%),
    radial-gradient(120% 90% at 30% 20%, #6b3a7d 0%, #3d1f4a 55%, #1e0f25 100%);
  background-blend-mode: soft-light, normal, normal, normal;
  box-shadow: inset 0 0 0 calc(var(--cw) * .05) #1e0f25, inset 0 0 0 calc(var(--cw) * .05 + 1.5px) #c9a24a, inset 0 0 calc(var(--cw) * .16) #1e0f25;
}

/* Pumpkin: small pumpkins in a half-drop repeat on dark orange, an ink frame with a light line inside. */
html[data-card-back="pc"] .felt .back, html[data-card-back="pc"] .cardback:not([data-back]), .cardback[data-back="pc"] {
  border-color: #2b1a0c;
  background:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 40 40'%3E%3Cdefs%3E%3Cg id='p' stroke='%232b1a0c' stroke-width='.9'%3E%3Cpath d='M0-5.6c.2-2 1-3.2 2.4-3.8' fill='none' stroke-width='1.9' stroke-linecap='round'/%3E%3Cpath d='M1.2-6.6c1.8-1.6 3.6-1.4 4.6-.4-1.6.8-3 1-4.6.4z' fill='%23697a2a' stroke-width='.6'/%3E%3Cellipse cx='-3.4' cy='0' rx='4.6' ry='5.6' fill='%23e0701f'/%3E%3Cellipse cx='3.4' cy='0' rx='4.6' ry='5.6' fill='%23e0701f'/%3E%3Cellipse cx='0' cy='0' rx='3.6' ry='6.2' fill='%23f5a54a'/%3E%3C/g%3E%3C/defs%3E%3Cuse href='%23p' x='10' y='11'/%3E%3Cuse href='%23p' x='30' y='31'/%3E%3C/svg%3E") center / calc(var(--cw) * .44) calc(var(--cw) * .44),
    radial-gradient(110% 80% at 50% 40%, #b0521a 0%, #8a3a0e 100%);
  box-shadow: inset 0 0 0 calc(var(--cw) * .05) #2b1a0c, inset 0 0 0 calc(var(--cw) * .05 + 1.5px) #f5a54a;
}

/* Squared paper: an exercise book's page, a faint blue grid, a red margin down one side, an ink border. */
html[data-card-back="bs"] .felt .back, html[data-card-back="bs"] .cardback:not([data-back]), .cardback[data-back="bs"] {
  border-color: #171815;
  background:
    linear-gradient(90deg, transparent calc(var(--cw) * .2), #e07a7a calc(var(--cw) * .2) calc(var(--cw) * .2 + 1px), transparent calc(var(--cw) * .2 + 1px)),
    repeating-linear-gradient(0deg, #9fc0e6 0 1px, transparent 1px calc(var(--cw) * .1)),
    repeating-linear-gradient(90deg, #9fc0e6 0 1px, transparent 1px calc(var(--cw) * .1)),
    #fbfaf5;
  box-shadow: inset 0 0 0 calc(var(--cw) * .05) #fbfaf5, inset 0 0 0 calc(var(--cw) * .05 + 1px) #171815;
}

/* A slopaganda poster as the back (backs.js sets data-card-back="poster" and --card-deck, the poster's 256 px thumb).
   The poster is cropped to the card (cover, from a little below its top, so the headline and the picture both show)
   and toned under an ink veil that is heavier along the top edge, inside the same ink frame and a cream line: in a
   face-down pile only the top strip of each card shows, and each strip still starts ink, cream, then a darkened band,
   so the cards read as separate cards whatever the poster. The card is a physical object: the same in every theme
   but High contrast and forced colours, which fall back to the plain back. */
html[data-card-back="poster"]:not([data-theme="contrast"]) .felt .back, html[data-card-back="poster"]:not([data-theme="contrast"]) .cardback:not([data-back]) {
  border-color: #171815;
  background:
    linear-gradient(180deg, #171815d9 0, #17181599 calc(var(--cw) * .1), #17181533 calc(var(--cw) * .28), #17181526 100%),
    var(--card-deck) 50% 22% / cover no-repeat,
    #171815;
  box-shadow: inset 0 0 0 calc(var(--cw) * .05) #171815, inset 0 0 0 calc(var(--cw) * .05 + 1.5px) #efd9ad;
}
/* forced colours: no picture, the system's own card edge (High contrast simply keeps the usual back: the rule above
   skips data-theme="contrast", which theme.js also sets when the device asks for more contrast) */
@media (forced-colors: active) {
  html[data-card-back="poster"]:not([data-theme="contrast"]) .felt .back, html[data-card-back="poster"]:not([data-theme="contrast"]) .cardback:not([data-back]) { background: Canvas; border: 1px solid CanvasText; box-shadow: inset 0 0 0 3px Canvas, inset 0 0 0 4px CanvasText; }
}

/* A chosen back must not hide the nope shake's red ring. */
html[data-card-back] .felt .card.nope .back { box-shadow: 0 0 0 2px var(--red); }

/* The chooser: a swatch of the back you are playing with, then a labelled "Deck" select (the usual back, owned shop
   backs, the posters by title). Built by backs.js. 44 px tall; the select keeps the platform's own keyboard and
   screen-reader behaviour, and its label names the deck, the selected option the poster. */
.back-pick { display: inline-flex; align-items: center; gap: 6px; min-height: 44px; font: 700 12px Arial, Helvetica, sans-serif; color: var(--ink, #171815); }
.back-pick[hidden] { display: none; }
.back-pick .cardback { --cw: 24px; }
.back-pick .lbl { cursor: pointer; }
.back-pick select { min-height: 44px; max-width: 13.5em; padding: 0 28px 0 10px; border: 1px solid var(--ink, #171815); border-radius: 8px; background: var(--paper, #f4f1e8) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 10 6'%3E%3Cpath d='M0 0h10L5 6z' fill='%23808080'/%3E%3C/svg%3E") right 10px center / 10px 6px no-repeat; color: var(--ink, #171815); font: 700 13px Arial, Helvetica, sans-serif; text-overflow: ellipsis; cursor: pointer; appearance: none; -webkit-appearance: none; }
.back-pick select:hover { background-color: color-mix(in srgb, var(--ink, #171815) 8%, var(--paper, #f4f1e8)); }
.back-pick select:focus-visible { outline: 3px solid var(--focus, #728600); outline-offset: 2px; }
.back-pick option, .back-pick optgroup { background: var(--paper, #f4f1e8); color: var(--ink, #171815); }
@media (forced-colors: active) { .back-pick select { appearance: auto; -webkit-appearance: auto; background-image: none; border-color: ButtonText; } }
/* phones held sideways: the side column is narrow, so the swatch goes and the word Deck is kept for screen readers only */
@media (max-height: 480px) and (orientation: landscape) {
  .back-pick .cardback { display: none; }
  .back-pick .lbl { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
  .back-pick select { max-width: 9.5em; }
}
