/* Patiens – the table, the cards (dark neon faces, the Bläck back with the FH mark) and the in-game buttons.
   Every size on the table follows the card's width --cw, which patiens.js sets from the box's size. */

.pt-stage {
  --aspect: 16 / 10;
  /* the card back (owner's choice 2026-11-23, docs/LOGGA_PLAN.md "The card back") */
  --edge: #141a21;
  --field: #0c1015;
  --tint: #1b2a3c;
  --tint-a: 0.5;
  --grad: linear-gradient(175deg, #ffe94d 0%, #ff8a3d 30%, #ff3fb4 62%, #7a2cff 100%);
  --k: 0.2;                 /* one tile of the pattern = this share of the card's width */
  --ratio: 1.284;           /* tile height / width (set again by patiens.js) */
  --px: 0.35;               /* where the light is (0..1 over the box), moved by the pointer */
  --py: 0.3;
  --hyp: 0.4;
  --tool: calc(2.6rem * max(1, var(--ui, 1)));      /* never smaller than the corner buttons (patiens.js measure() too) */
  --red: #ff3fb4;
  --black: #5ef0ff;
  /* the table: a deep purple felt (the site's own purple), lighter than the ink-black cards so they stand out;
     a fine grain (an SVG noise picture) makes it feel like cloth */
  background:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0.07 0'/%3E%3C/filter%3E%3Crect width='160' height='160' filter='url(%23n)'/%3E%3C/svg%3E"),
    radial-gradient(ellipse at 50% 30%, #3a2b86 0%, #2a1f66 50%, #1a1342 100%);
}

/* Phones held upright: a taller box */
@media (orientation: portrait) and (max-width: 700px) {
  .pt-stage { --aspect: 3 / 4; }
}

.pt-table {
  position: absolute;
  inset: 0;
  touch-action: none;
}

/* ---------- the empty spots ---------- */
.pt-slot {
  position: absolute;
  left: 0;
  top: 0;
  width: var(--cw);
  height: var(--ch);
  display: grid;
  place-items: center;
  border-radius: calc(var(--cw) * 0.07);
  border: max(1px, calc(var(--cw) * 0.018)) solid rgba(94, 240, 255, 0.22);
  background: rgba(10, 6, 30, 0.25);
  color: rgba(94, 240, 255, 0.22);
}
.pt-slot svg { width: 46%; height: auto; }
.pt-slot.is-hearts, .pt-slot.is-diamonds { color: rgba(255, 63, 180, 0.25); border-color: rgba(255, 63, 180, 0.18); }
.pt-slot.is-stock { cursor: pointer; }
/* the stock is empty but the waste is not: the arrows breathe – tap to turn the waste over */
.pt-slot.can-recycle { color: rgba(94, 240, 255, 0.75); animation: pt-breathe 1.6s ease-in-out infinite; }
.pt-slot.is-empty-stock svg { opacity: 0; }

@keyframes pt-breathe {
  50% { transform: scale(1.06); filter: drop-shadow(0 0 calc(var(--cw) * 0.08) rgba(94, 240, 255, 0.8)); }
}

/* ---------- a card ---------- */
.pt-card {
  --w: var(--cw);
  position: absolute;
  left: 0;
  top: 0;
  width: var(--cw);
  height: var(--ch);
  border-radius: calc(var(--cw) * 0.07);
  transition: transform 0.2s cubic-bezier(0.2, 0.8, 0.3, 1);
  will-change: transform;
  cursor: default;
}
.pt-card.is-up { cursor: grab; }
.pt-card.is-dragging { transition: none; cursor: grabbing; }
.pt-card.is-dragging .pt-inner { box-shadow: 0 calc(var(--cw) * 0.1) calc(var(--cw) * 0.22) rgba(0, 0, 0, 0.6); }
.pt-card.is-hidden { visibility: hidden; }

.pt-inner {
  position: absolute;
  inset: 0;
  border-radius: inherit;
  box-shadow: 0 calc(var(--cw) * 0.02) calc(var(--cw) * 0.08) rgba(5, 3, 20, 0.7);
}
.pt-card.is-flipping .pt-inner { animation: pt-flip 0.24s ease-in-out; }
@keyframes pt-flip {
  50% { transform: scaleX(0.02); }
}
.pt-card.is-wrong .pt-inner { animation: pt-wrong 0.3s ease-in-out; }
@keyframes pt-wrong {
  25% { transform: translateX(calc(var(--cw) * -0.06)) rotate(-2deg); }
  75% { transform: translateX(calc(var(--cw) * 0.06)) rotate(2deg); }
}

/* ---------- the face: ink black, the rank + suit in neon ---------- */
.pt-front {
  --suit: var(--black);
  position: absolute;
  inset: 0;
  display: none;
  overflow: hidden;
  border-radius: inherit;
  color: var(--suit);
  background:
    radial-gradient(ellipse at 50% 58%, color-mix(in srgb, var(--suit) 9%, transparent) 0%, transparent 70%),
    linear-gradient(165deg, #1b2431 0%, #0f141b 100%);
  border: max(1px, calc(var(--cw) * 0.012)) solid color-mix(in srgb, var(--suit) 45%, transparent);
}
.pt-card.is-red .pt-front { --suit: var(--red); }
.pt-card.is-up .pt-front { display: block; }
.pt-card.is-up .pt-back { display: none; }

/* the index (the owner's model card): a small rank with a much smaller suit under it, top left – and the same turned
   round bottom right, so the card reads the same upside down (a card in a column shows only its top strip) */
.pt-index {
  position: absolute;
  left: calc(var(--cw) * 0.045);
  top: calc(var(--cw) * 0.035);
  width: calc(var(--cw) * 0.18);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: calc(var(--cw) * 0.01);
}
.pt-index.is-low { left: auto; top: auto; right: calc(var(--cw) * 0.045); bottom: calc(var(--cw) * 0.035); transform: rotate(180deg); }
.pt-rank {
  font-family: var(--font-display);
  font-weight: 900;
  font-style: italic;
  font-size: max(calc(var(--cw) * 0.17), 10px);    /* still readable on a phone's small cards */
  line-height: 1;
  letter-spacing: -0.06em;
  white-space: nowrap;
  text-shadow: 0 0 calc(var(--cw) * 0.05) color-mix(in srgb, var(--suit) 70%, transparent);
}
.pt-front .pt-isuit { width: calc(var(--cw) * 0.09); height: calc(var(--cw) * 0.09); }
/* Kn, D, K have no pips: their suit in the index is bigger, so the suit reads at once (owner, 2026-11-23) */
.pt-card.is-court .pt-isuit {
  width: calc(var(--cw) * 0.16);
  height: calc(var(--cw) * 0.16);
  filter: drop-shadow(0 0 calc(var(--cw) * 0.03) color-mix(in srgb, var(--suit) 70%, transparent));
}

/* 2-10: BIG pips in their classic places, the lower half turned round (--pip = the size, set per rank) */
.pt-pip {
  position: absolute;
  width: calc(var(--cw) * var(--pip, 0.26));
  height: calc(var(--cw) * var(--pip, 0.26));
  transform: translate(-50%, -50%);
}
.pt-pip.is-low { transform: translate(-50%, -50%) rotate(180deg); }
/* the ace: one big symbol */
.pt-ace {
  position: absolute;
  left: 50%;
  top: 50%;
  width: calc(var(--cw) * 0.5);
  height: calc(var(--cw) * 0.5);
  transform: translate(-50%, -50%);
  filter: drop-shadow(0 0 calc(var(--cw) * 0.06) color-mix(in srgb, var(--suit) 60%, transparent));
}
/* Kn, D, K: the robot double-headed, as wide as the card (its narrow head clears the indexes in the corners) – its upper body in the top half, the same turned
   round in the bottom half (the pictures are one-colour masks in bilder/, filled with the suit's colour) */
.pt-court {
  position: absolute;
  left: 6%;
  right: 6%;
  top: 4%;
  bottom: 4%;
  overflow: hidden;
}
.pt-court::after {           /* the line where the two halves meet */
  content: "";
  position: absolute;
  left: 12%;
  right: 12%;
  top: 50%;
  border-top: max(1px, calc(var(--cw) * 0.01)) solid color-mix(in srgb, var(--suit) 40%, transparent);
}
.pt-head {
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  height: 50%;
}
.pt-head.is-low { top: 50%; transform: rotate(180deg); }
.pt-robot {
  position: absolute;
  inset: 5% 4% 0;
  background: var(--suit);
  -webkit-mask-size: contain; mask-size: contain;
  -webkit-mask-repeat: no-repeat; mask-repeat: no-repeat;
  -webkit-mask-position: 50% 100%; mask-position: 50% 100%;
  filter: drop-shadow(0 0 calc(var(--cw) * 0.02) color-mix(in srgb, var(--suit) 70%, transparent));
}
.pt-robot.is-pipen { -webkit-mask-image: url("bilder/pipen.webp"); mask-image: url("bilder/pipen.webp"); }
.pt-robot.is-ramel { -webkit-mask-image: url("bilder/ramel.webp"); mask-image: url("bilder/ramel.webp"); }
.pt-robot.is-mega { -webkit-mask-image: url("bilder/mega.webp"); mask-image: url("bilder/mega.webp"); }
.pt-pip svg, .pt-ace svg { display: block; width: 100%; height: 100%; }
.pt-front svg { display: block; }

/* ---------- the back: the FH mark in one colour, mirrored every other row, sunset colours, holographic foil ---------- */
.pt-back {
  --inset: calc(var(--w) * 0.055);
  --r: calc(var(--w) * 0.07);
  --tw: calc(var(--w) * var(--k));
  --th: calc(var(--w) * var(--k) * var(--ratio));
  position: absolute;
  inset: 0;
  overflow: hidden;
  isolation: isolate;
  border-radius: inherit;
  background: var(--edge);
  box-shadow: inset 0 0 0 1px rgba(255, 225, 200, 0.12);
}
.pt-back > div { position: absolute; pointer-events: none; }
.pb-in { inset: var(--inset); border-radius: calc(var(--r) * 0.55); }
.pb-field { background: radial-gradient(ellipse at 50% 45%, transparent 45%, rgba(0, 0, 0, 0.35) 100%), var(--field); }
.pb-tint {
  background: radial-gradient(ellipse 75% 60% at 50% 46%, var(--tint) 0%, transparent 100%),
    linear-gradient(175deg, var(--tint) 0%, transparent 35%, transparent 65%, var(--tint) 100%);
  opacity: var(--tint-a);
}
.pb-m {
  -webkit-mask-image: var(--tile); mask-image: var(--tile);
  -webkit-mask-size: var(--tw) var(--th); mask-size: var(--tw) var(--th);
  -webkit-mask-repeat: repeat; mask-repeat: repeat;
  -webkit-mask-position: 50% 50%; mask-position: 50% 50%;
}
.pb-shade { background: rgba(0, 0, 0, 0.6); transform: translate(0.5px, 0.7px); }
.pb-ink { background: var(--grad); }
.pb-rainbow {
  background-image: repeating-linear-gradient(115deg,
    hsl(0 100% 62%) 0%, hsl(45 100% 60%) 4%, hsl(110 100% 58%) 8%, hsl(180 100% 60%) 12%,
    hsl(235 100% 66%) 16%, hsl(290 100% 64%) 20%, hsl(360 100% 62%) 24%);
  background-size: 400% 400%;
  background-position: calc(10% + var(--px) * 80%) calc(10% + var(--py) * 80%);
  mix-blend-mode: color-dodge;
  filter: brightness(0.48) contrast(1.6) saturate(1.3);
  opacity: calc(0.3 + var(--hyp) * 0.5);
}
.pb-glitter {
  background-image: var(--glit);
  background-size: 150px 150px;
  background-position: calc(var(--px) * -30px) calc(var(--py) * -30px);
  mix-blend-mode: color-dodge;
  opacity: calc(0.2 + var(--hyp) * 0.8);
}
.pb-spot {
  background: radial-gradient(circle at calc(var(--px) * 100%) calc(var(--py) * 100%),
    rgba(255, 255, 255, 0.95) 0%, rgba(255, 255, 255, 0.35) 14%, rgba(255, 255, 255, 0) 38%);
  mix-blend-mode: screen;
  opacity: 0.5;
}
.pb-frame {
  inset: calc(var(--inset) + var(--w) * 0.022);
  border-radius: calc(var(--r) * 0.4);
  border: max(1px, calc(var(--w) * 0.006)) solid transparent;
  background: var(--grad) border-box;
  -webkit-mask: linear-gradient(#000 0 0) padding-box, linear-gradient(#000 0 0);
  -webkit-mask-composite: xor;
  mask-composite: exclude;
  opacity: 0.85;
}

/* ---------- what lights up ---------- */
/* while dragging: where the card may go */
.pt-slot.is-target,
.pt-card.is-target .pt-inner {
  box-shadow: 0 0 0 max(2px, calc(var(--cw) * 0.03)) var(--yellow), 0 0 calc(var(--cw) * 0.18) rgba(255, 233, 77, 0.6);
}
/* the hint: the card(s) to move pulse, the place glows */
.pt-card.is-hint .pt-inner { animation: pt-hint 0.8s ease-in-out 3; }
@keyframes pt-hint {
  50% { box-shadow: 0 0 0 max(2px, calc(var(--cw) * 0.03)) var(--yellow), 0 0 calc(var(--cw) * 0.25) var(--yellow); }
}

.pt-hand {
  position: absolute;
  left: 0;
  top: 0;
  z-index: 3000;
  width: calc(var(--cw) * 0.55);
  height: calc(var(--cw) * 0.55);
  color: var(--yellow);
  filter: drop-shadow(0 0 6px rgba(0, 0, 0, 0.8)) drop-shadow(0 0 10px rgba(255, 233, 77, 0.5));
  pointer-events: none;
  opacity: 0;
}
.pt-hand svg { display: block; width: 100%; height: 100%; }

/* ---------- the win ---------- */
.pt-party {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 2500;
  pointer-events: none;
}
.pt-again {
  position: absolute;
  left: 50%;
  top: 50%;
  z-index: 2600;
  transform: translate(-50%, -50%);
  display: inline-flex;
  align-items: center;
  gap: 0.5em;
  font-size: calc(1.4rem * var(--ui, 1));
  animation: pt-breathe-button 1.6s ease-in-out infinite;
}
.pt-again[hidden] { display: none; }
.pt-again svg { width: 1.3em; height: 1.3em; }
@keyframes pt-breathe-button { 50% { transform: translate(-50%, -50%) scale(1.06); } }

/* ---------- the in-game buttons: a column on the right (a row at the bottom on a phone held upright) ---------- */
.pt-tool {
  position: absolute;
  z-index: 2;
  right: calc(0.6rem + var(--safe-right));
  display: grid;
  place-items: center;
  width: var(--tool);
  height: var(--tool);
  padding: 0;
  color: var(--text);
  background: rgba(14, 10, 36, 0.7);
  border: 2px solid var(--cyan);
  cursor: pointer;
}
/* the icon's box is 58 % of the button, centred (the svg fills its box) */
.pt-tool > [data-icon] { display: grid; place-items: center; width: 58%; height: 58%; }
.pt-tool > [data-icon] svg { display: block; width: 100%; height: 100%; }
.pt-tool:hover, .pt-tool:focus-visible { box-shadow: 0 0 10px var(--cyan); }
.pt-tool:disabled { opacity: 0.3; cursor: default; box-shadow: none; }
#undo { top: calc(0.6rem + var(--safe-top) + 2.6rem + 0.7rem); }
#hint { top: calc(0.6rem + var(--safe-top) + 2.6rem + 0.7rem + var(--tool) + 0.5rem); }
#new-deal { top: calc(0.6rem + var(--safe-top) + 2.6rem + 0.7rem + (var(--tool) + 0.5rem) * 2); }
#hint.is-stuck svg { color: rgba(234, 246, 255, 0.35); }

/* "Ny giv?" folds out on the first tap; a second tap deals (js/game-ui.js setupBackToMenu) */
.pt-new { width: auto; min-width: var(--tool); display: flex; justify-content: center; padding: 0; }
.pt-new.is-open { padding: 0 calc(var(--tool) * 0.2); }
.pt-new-icon { flex: none; display: grid; place-items: center; width: calc(var(--tool) * 0.58); height: calc(var(--tool) * 0.58); }
.pt-new-icon svg { width: 100%; height: 100%; }
.pt-new-text {
  order: -1;
  max-width: 0;
  overflow: hidden;
  white-space: nowrap;
  opacity: 0;
  font-weight: 800;
  font-style: italic;
  text-transform: uppercase;
  font-size: calc(1rem * var(--ui, 1));
  transition: max-width 0.3s ease-out, opacity 0.25s, margin 0.3s ease-out;
}
.pt-new.is-open { color: #0e0a24; background: var(--yellow); border-color: var(--yellow); box-shadow: 0 0 10px var(--yellow); }
.pt-new.is-open .pt-new-text { max-width: 8em; opacity: 1; margin-right: 0.4em; }

/* upright phone: the buttons sit in a row along the bottom, fullscreen and sound at the right end */
.pt-stage.is-tall .pt-tool,
.pt-stage.is-tall #undo,
.pt-stage.is-tall #hint,
.pt-stage.is-tall #new-deal { top: auto; bottom: calc(0.6rem + var(--safe-bottom)); right: auto; }
.pt-stage.is-tall #new-deal { left: calc(0.6rem + var(--safe-left)); }
.pt-stage.is-tall .pt-new-text { order: 1; }
.pt-stage.is-tall .pt-new.is-open .pt-new-text { margin: 0 0 0 0.4em; }
.pt-stage.is-tall #hint { left: calc(0.6rem + var(--safe-left) + var(--tool) + 0.5rem); }
.pt-stage.is-tall #undo { left: calc(0.6rem + var(--safe-left) + (var(--tool) + 0.5rem) * 2); }
.pt-stage.is-tall .fullscreen-button { top: auto; bottom: calc(0.6rem + var(--safe-bottom)); right: calc(0.6rem + var(--safe-right) + 2.6rem + 0.5rem); }
.pt-stage.is-tall.pt-new-open #hint,
.pt-stage.is-tall.pt-new-open #undo { visibility: hidden; }

@media (prefers-reduced-motion: reduce) {
  .pt-card { transition: none; }
  .pt-slot.can-recycle, .pt-again { animation: none; }
}
