/* Memory (hafiza) — chunky cards on a soft mat. The mat and the card grid get pixel sizes from hafiza.js (computed
 * once from the space the page gives); nothing in here depends on the game state, so the board never changes size. */
.hz-wrap {
  --hz-back: #2b3a5c; --hz-back-lo: #1c2740; --hz-back-edge: #121a2c; --hz-face: #fff8ee; --hz-face-edge: #e8d9c2;
  --hz-p0: var(--brand); --hz-p1: var(--blue); --hz-r: 12px;
  position: relative; box-sizing: border-box; margin: 0 auto; max-width: 100%;
  border-radius: 20px; background: var(--surface-2); border: 1px solid var(--line);
  box-shadow: inset 0 2px 0 rgba(255, 255, 255, .35), 0 10px 26px -18px rgba(10, 16, 30, .45);
  transition: box-shadow .3s;
}
:root[data-theme="dark"] .hz-wrap { --hz-back: #34466d; --hz-back-lo: #22304d; --hz-back-edge: #0b1120; --hz-face: #f6ecdd; --hz-face-edge: #cdbb9f; box-shadow: inset 0 1px 0 rgba(255, 255, 255, .05), 0 10px 26px -14px rgba(0, 0, 0, .7); }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .hz-wrap { --hz-back: #34466d; --hz-back-lo: #22304d; --hz-back-edge: #0b1120; --hz-face: #f6ecdd; --hz-face-edge: #cdbb9f; box-shadow: inset 0 1px 0 rgba(255, 255, 255, .05), 0 10px 26px -14px rgba(0, 0, 0, .7); }
}
.hz-wrap.hz-small { --hz-r: 9px; }
/* your turn: a soft halo in your colour around the mat */
.hz-wrap.mine { box-shadow: 0 0 0 4px var(--brand-soft), 0 0 0 1px color-mix(in srgb, var(--hz-p0) 45%, transparent), 0 10px 26px -18px rgba(10, 16, 30, .45); }
.hz-wrap.mine.p1 { box-shadow: 0 0 0 4px var(--blue-soft), 0 0 0 1px color-mix(in srgb, var(--hz-p1) 45%, transparent), 0 10px 26px -18px rgba(10, 16, 30, .45); }

.hz-grid { display: grid; justify-content: center; align-content: center; perspective: 900px; }

.hz-card {
  appearance: none; -webkit-appearance: none; border: 0; margin: 0; padding: 0; background: transparent; position: relative;
  width: var(--hz-w); height: var(--hz-h); border-radius: var(--hz-r); cursor: default; touch-action: manipulation;
  -webkit-tap-highlight-color: transparent; transition: transform .16s var(--ease, ease); outline: none;
}
.hz-card.can { cursor: pointer; }
/* the hit area reaches half-way into the gaps: a ≥ 44 px target even where the cards are drawn smaller */
.hz-card::before { content: ""; position: absolute; inset: calc(var(--hz-gap, 6px) / -2); }
.hz-card:focus-visible { box-shadow: 0 0 0 3px var(--surface), 0 0 0 6px var(--hz-p0); }
.hz-wrap.p1 .hz-card:focus-visible { box-shadow: 0 0 0 3px var(--surface), 0 0 0 6px var(--hz-p1); }

.hz-inner { position: absolute; inset: 0; transform-style: preserve-3d; transition: transform .34s cubic-bezier(.3, .9, .35, 1.12); }
.hz-card.up .hz-inner { transform: rotateY(180deg); }
.hz-card.noanim .hz-inner { transition: none !important; }
.hz-back, .hz-face { position: absolute; inset: 0; border-radius: var(--hz-r); -webkit-backface-visibility: hidden; backface-visibility: hidden; box-sizing: border-box; }

/* back: navy tile with a fine diagonal weave and the two-dot emblem, chunky bottom edge */
.hz-back {
  background:
    radial-gradient(circle at 40% 50%, #ff6b4a 0 15%, transparent 15.5%),
    radial-gradient(circle at 60% 50%, #3d7bf7 0 15%, transparent 15.5%),
    radial-gradient(circle at 50% 50%, rgba(255, 244, 230, .16) 0 27%, transparent 27.5%),
    repeating-linear-gradient(45deg, rgba(255, 255, 255, .055) 0 4px, transparent 4px 9px),
    repeating-linear-gradient(-45deg, rgba(255, 255, 255, .04) 0 4px, transparent 4px 9px),
    linear-gradient(160deg, var(--hz-back), var(--hz-back-lo));
  border: 2px solid rgba(255, 255, 255, .08);
  box-shadow: inset 0 2px 0 rgba(255, 255, 255, .14), inset 0 -4px 0 var(--hz-back-edge), 0 3px 6px -3px rgba(10, 16, 30, .55);
  transition: filter .15s, transform .15s;
}
.hz-back::after { content: ""; position: absolute; inset: 9%; border-radius: calc(var(--hz-r) - 4px); border: 1.5px dashed rgba(255, 244, 230, .16); }
.hz-card.can:hover .hz-back { filter: brightness(1.15); }
.hz-card.can:hover { transform: translateY(-2px); }
.hz-card.can:active { transform: translateY(1px) scale(.98); }

/* face: cream card with the icon */
.hz-face {
  transform: rotateY(180deg); display: grid; place-items: center; background: var(--hz-face);
  border: 2px solid var(--hz-face-edge); box-shadow: inset 0 -4px 0 rgba(120, 90, 50, .14), 0 3px 6px -3px rgba(10, 16, 30, .45);
}
.hz-face svg { width: 74%; height: 74%; display: block; }
.hz-card.open .hz-face { border-color: #f2b544; box-shadow: inset 0 -4px 0 rgba(120, 90, 50, .14), 0 0 0 3px rgba(255, 197, 61, .55), 0 6px 14px -6px rgba(10, 16, 30, .5); }

/* found pairs: owner-coloured frame and a ribbon in the corner; a touch calmer than the cards still in play */
.hz-card.got .hz-face { border-width: 3px; }
.hz-card.o0 .hz-face { border-color: var(--hz-p0); }
.hz-card.o1 .hz-face { border-color: var(--hz-p1); }
.hz-card.got .hz-face::after { content: ""; position: absolute; right: 6%; top: 6%; width: 16%; aspect-ratio: 1; border-radius: 50%; box-shadow: 0 0 0 2px var(--hz-face); }
.hz-card.o0 .hz-face::after { background: var(--hz-p0); }
.hz-card.o1 .hz-face::after { background: var(--hz-p1); }
.hz-card.got:not(.pop) .hz-face svg { opacity: .82; }

/* waiting for the server after a tap: the card lifts and starts to turn */
.hz-card.lift { transform: translateY(-4px) scale(1.04); z-index: 2; }
.hz-card.lift .hz-inner { transform: rotateY(28deg); }

/* a pair found: pop */
.hz-card.pop { animation: hzpop .5s var(--spring, cubic-bezier(.3, 1.6, .5, 1)); z-index: 2; }
@keyframes hzpop { 0% { transform: scale(1); } 40% { transform: scale(1.13); } 100% { transform: scale(1); } }
/* end of the game: the winner's cards bounce in a wave */
.hz-wrap.waved .hz-card.wv { animation: hzwave .6s var(--wd, 0s) ease-in-out both; }
@keyframes hzwave { 0%, 100% { transform: translateY(0); } 45% { transform: translateY(-14%) scale(1.04); } }
.hz-wrap.done .hz-card:not(.got) .hz-back { filter: saturate(.6) brightness(.9); }

/* The room's "opponent offline · claim the win" line (app.js #claimLine) floats over the status row (hafiza.js puts its
   centre there in --hz-claim-y) instead of taking a row above the board: showing or hiding it never moves the board. */
#boardPanel:has(> #board > .hz-wrap) > #claimLine {
  position: absolute; left: 10px; right: 10px; top: var(--hz-claim-y, 90px); transform: translateY(-50%); z-index: 6;
  min-height: 34px; padding: 2px 10px; margin: 0; border-radius: 12px; flex-wrap: wrap; row-gap: 2px; font-size: 13px; line-height: 1.25;
  background: var(--surface); border: 1px solid var(--line-2); box-shadow: 0 8px 20px -12px rgba(10, 16, 30, .5);
}
#boardPanel:has(> #board > .hz-wrap) > #claimLine.hidden { display: none; }
#boardPanel:has(> #board > .hz-wrap) > #claimLine .btn { height: 28px; }

/* Phone landscape (hafiza.js isShort(): data-short): the two player bars become compact chips on the status row, so
   the 9×4 board gets the whole height under them and the game fits one screen with no scrolling. Sized once. */
body:has(.hz-wrap[data-short="1"]) .content { padding-top: 8px; }
#gameArea #boardPanel:has(> #board > .hz-wrap[data-short="1"]) { display: grid; grid-template-columns: minmax(120px, 1fr) minmax(0, max-content) minmax(120px, 1fr); align-items: center; align-content: start; column-gap: 10px; row-gap: 6px; min-height: 0; padding: 8px; }
#gameArea #boardPanel:has(> #board > .hz-wrap[data-short="1"]) > #pTopRow { display: contents; }
#gameArea #boardPanel:has(> #board > .hz-wrap[data-short="1"]) #pTop { grid-row: 1; grid-column: 1; }
#gameArea #boardPanel:has(> #board > .hz-wrap[data-short="1"]) > #status { grid-row: 1; grid-column: 2; display: block; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; line-height: 22px; }
#gameArea #boardPanel:has(> #board > .hz-wrap[data-short="1"]) > #pBottom { grid-row: 1; grid-column: 3; }
#gameArea #boardPanel:has(> #board > .hz-wrap[data-short="1"]) > #board { grid-row: 2; grid-column: 1 / -1; }
/* the claim line covers the chips row for as long as it shows (same height: nothing moves) */
#gameArea #boardPanel:has(> #board > .hz-wrap[data-short="1"]) > #claimLine { position: static; transform: none; grid-row: 1; grid-column: 1 / -1; align-self: center; height: 32px; min-height: 0; overflow: hidden; flex-wrap: nowrap; white-space: nowrap; }
#gameArea #boardPanel:has(> #board > .hz-wrap[data-short="1"]) .pbar { width: auto; min-width: 0; min-height: 0; height: 32px; padding: 2px 10px 2px 3px; gap: 7px; border-radius: 10px; }
#gameArea #boardPanel:has(> #board > .hz-wrap[data-short="1"]) .pbar .avatar { width: 26px; height: 26px; border-radius: 8px; font-size: 13px; box-shadow: none; }
#gameArea #boardPanel:has(> #board > .hz-wrap[data-short="1"]) .pbar .pn b { font-size: 13px; gap: 5px; }
#gameArea #boardPanel:has(> #board > .hz-wrap[data-short="1"]) .pbar .pn b em { display: none; }
/* the pair count stays on the chip (name · chip · "7 pairs"); the online / level note is left out */
#gameArea #boardPanel:has(> #board > .hz-wrap[data-short="1"]) .pbar .pn { display: flex; align-items: center; gap: 8px; }
#gameArea #boardPanel:has(> #board > .hz-wrap[data-short="1"]) .pbar .pn b { min-width: 0; }
#gameArea #boardPanel:has(> #board > .hz-wrap[data-short="1"]) .pbar .pn small { flex: none; margin-top: 0; white-space: nowrap; font-size: 12px; }
#gameArea #boardPanel:has(> #board > .hz-wrap[data-short="1"]) .pbar .pn small > :nth-child(n+3) { display: none; }
#gameArea #boardPanel:has(> #board > .hz-wrap[data-short="1"]) .pbar .psc { font-size: 17px; min-width: 14px; }
#gameArea #boardPanel:has(> #board > .hz-wrap[data-short="1"]) .pbar .ptag { font-size: 0; gap: 0; }
#gameArea #boardPanel:has(> #board > .hz-wrap[data-short="1"]) .pbar .ptag:not(.think)::before { content: ""; width: 9px; height: 9px; border-radius: 50%; background: currentColor; }
#gameArea #boardPanel:has(> #board > .hz-wrap[data-short="1"]) .pbar .ptag .typing i { width: 5px; height: 5px; }
/* wave16 fix: a chat bubble on a 32 px chip: two small lines, no taller than the chip (as Mangala / Yut / Dominoes) */
#gameArea #boardPanel:has(> #board > .hz-wrap[data-short="1"]) .chat-bub { padding-top: 2px; padding-bottom: 2px; line-height: 1.15; font-size: 11px; }
#gameArea #boardPanel:has(> #board > .hz-wrap[data-short="1"]) .chat-bub span { -webkit-line-clamp: 2; }

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

@media (prefers-reduced-motion: reduce) {
  .hz-inner, .hz-card, .hz-back, .hz-wrap { transition: none !important; }
  .hz-card.pop, .hz-wrap.waved .hz-card.wv { animation: none; }
  .hz-card.lift { transform: none; }
  .hz-card.lift .hz-inner { transform: none; }
  .hz-card.lift .hz-back { filter: brightness(1.35); }
}
