/* ==========================================================================
   EL3AB core: Night Arcade, a modern mobile-game UI kit.
   A quiet ink stage; flat ink tiles for lists; white game cards with a lip;
   flat colour buttons with a lip the finger pushes down; a floating HUD and
   a floating dock. See tokens.css.
   ========================================================================== */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  width: 100%; height: 100%;
  overflow: hidden;
  background-color: var(--stage);
  background-image: var(--stage-pattern);
  background-size: 56px 56px;
  color: var(--text-primary);
  font-family: var(--font-ar);
  font-size: 16px;
  font-weight: 500;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  touch-action: manipulation;
  caret-color: var(--gold);
  font-synthesis: none;
}

/* Two soft pools of light: violet from above, a warm one low in the corner. */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  background:
    radial-gradient(90% 46% at 50% -6%, var(--stage-glow), transparent 72%),
    radial-gradient(70% 38% at 100% 104%, var(--stage-glow-2), transparent 70%);
}

:root { --dir: 1; }
[dir="rtl"] { --dir: -1; }

body, input, button, textarea, select { font-variant-numeric: tabular-nums; }
input, button, textarea, select { font-family: inherit; }
button { color: inherit; }

::selection { background: var(--btn-purple-2); color: #fff; }

:focus { outline: none; }
:focus-visible {
  outline: 3px solid rgba(255, 255, 255, 0.85);
  outline-offset: 3px;
  border-radius: var(--r-sm);
}

/* Line icons (utility glyphs) and sticker icons (game art). */
.i { display: inline-block; flex-shrink: 0; vertical-align: middle; }
[dir="rtl"] .i-dir { transform: scaleX(-1); }
.i-coin, .i-crown { color: var(--gold); }
.i-gem { color: var(--purple); }
.i-online { color: var(--win); }
.i-offline { color: var(--text-dim); }
.gi { display: inline-block; flex-shrink: 0; object-fit: contain; vertical-align: middle; pointer-events: none; -webkit-user-drag: none; }

/* Display type: the voice of the game. */
.display, .screen-title, .section-title, .btn, .chip, .tab-item, .hud-name, .hud-stat, .empty-title, .ribbon {
  font-family: var(--font-display);
  font-weight: 800;
  letter-spacing: 0;
}

#game {
  position: fixed;
  inset: 0;
  z-index: 1;
  overflow: hidden;
}

#scene-container {
  position: absolute;
  inset: 0;
  top: calc(var(--hud-height) + var(--safe-top));
  bottom: calc(var(--tab-height) + var(--safe-bottom));
}

#scene-container.game-mode { top: 0; bottom: 0; }
html.no-chrome #scene-container { top: 0; bottom: 0; }
html.no-chrome #hud, #hud:empty { display: none; }

/* ── The HUD: floating capsules, no bar ─────────────────────────────────── */
#hud {
  position: fixed;
  top: 0; inset-inline: 0;
  height: calc(var(--hud-height) + var(--safe-top));
  padding-top: var(--safe-top);
  padding-inline: var(--hud-padding-x);
  z-index: 100;
  display: flex;
  align-items: center;
  gap: 8px;
  background: linear-gradient(180deg, var(--stage) 55%, rgba(20, 18, 26, 0));
  transition: transform var(--dur-normal) var(--ease-out);
}
#hud.hidden { transform: translateY(calc(-100% - 12px)); }

.hud-profile {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  position: relative;
  min-height: 48px;
  border: none;
  background: none;
  color: inherit;
  padding: 0;
  text-align: start;
}
.hud-avatar {
  position: relative;
  width: var(--hud-avatar-size);
  height: var(--hud-avatar-size);
  border-radius: 15px;
  background: var(--btn-purple-2);
  box-shadow: 0 3px 0 var(--btn-purple-edge);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  color: #fff;
}
.hud-avatar > :first-child { border-radius: inherit; overflow: hidden; }
.hud-avatar img { width: 100%; height: 100%; object-fit: cover; border-radius: inherit; }
.hud-level-badge {
  position: absolute;
  bottom: -7px;
  inset-inline-end: -7px;
  min-width: 24px; height: 24px;
  padding: 0 5px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 12px;
  background: var(--gold);
  box-shadow: 0 0 0 3px var(--stage);
  color: var(--gold-ink);
  font-family: var(--font-display);
  font-size: 13px;
  line-height: 1;
  z-index: 2;
}
.hud-who { display: flex; flex-direction: column; line-height: 1.1; min-width: 0; }
.hud-name {
  font-size: 15px;
  color: var(--text-primary);
  max-width: 26vw;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.hud-level { font-size: 12px; font-weight: 700; color: var(--gold-soft); }
.hud-xp { display: block; width: 68px; height: 6px; margin-top: 5px; border-radius: 3px; background: var(--back-600); overflow: hidden; }
.hud-xp > span { display: block; height: 100%; width: 100%; border-radius: inherit; background: var(--sky); transform: scaleX(var(--xp, 0)); transform-origin: 0 50%; transition: transform 600ms var(--ease-out); }
[dir="rtl"] .hud-xp > span { transform-origin: 100% 50%; }

.hud-stats {
  display: flex;
  align-items: center;
  gap: var(--hud-stat-gap);
  margin-inline-start: auto;
}

/* The purse: an ink capsule, the coin at its start, a green plus at its end. */
.hud-stat {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  height: 36px;
  min-width: 74px;
  padding-inline: 4px 32px;
  border-radius: 18px;
  background: var(--back-700);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.05), 0 3px 0 var(--back-950);
  font-size: var(--hud-stat-font);
  color: #fff;
  cursor: pointer;
  border: none;
}
.hud-stat .icon {
  display: flex;
  margin-inline-start: -2px;
}
.hud-stat .icon .gi { width: 28px; height: 28px; }
.hud-stat .hud-plus {
  position: absolute;
  inset-inline-end: 4px;
  top: 50%;
  transform: translateY(-50%);
  width: 26px; height: 26px;
  border-radius: 13px;
  background: var(--btn-green-2);
  box-shadow: 0 2px 0 var(--btn-green-edge);
  display: flex; align-items: center; justify-content: center;
  color: #fff;
}
.hud-stat.is-gaining { animation: purseGain 560ms var(--ease-pop); }
.hud-stat.is-gaining .icon { animation: coinSpin 600ms var(--ease-out); }
@keyframes purseGain { 0% { scale: 1; } 30% { scale: 1.16; } 100% { scale: 1; } }
@keyframes coinSpin { from { transform: rotateY(0); } to { transform: rotateY(360deg); } }

.hud-actions { display: flex; align-items: center; gap: 6px; }

/* Phones: the purses keep their plus keys; the avatar with its level badge
   stands for the player and the name moves to the profile. */
@media (max-width: 400px) {
  #hud { gap: 6px; padding-inline: 10px; }
  .hud-who { display: none; }
  .hud-stat { min-width: 0; padding-inline-end: 30px; }
  .hud-stat .icon .gi { width: 24px; height: 24px; }
}

.hud-btn {
  width: var(--hud-btn-size);
  height: var(--hud-btn-size);
  border-radius: 15px;
  background: var(--back-700);
  border: none;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.05), 0 3px 0 var(--back-950);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  position: relative;
  color: var(--text-primary);
  padding: 0;
}
.hud-btn.is-pressed { translate: 0 2px; box-shadow: 0 1px 0 var(--back-950); }

.hud-badge {
  position: absolute;
  top: -6px;
  inset-inline-end: -6px;
  min-width: var(--hud-badge-size);
  height: var(--hud-badge-size);
  line-height: var(--hud-badge-size);
  background: var(--red);
  box-shadow: 0 0 0 3px var(--stage);
  color: #fff;
  font-family: var(--font-display);
  font-size: var(--hud-badge-font);
  border-radius: var(--r-full);
  text-align: center;
  padding: 0 5px;
  display: none;
}
.hud-badge:not(:empty) { display: block; animation: popIn 420ms var(--ease-pop); }
.hud-btn.is-ringing .gi, .hud-btn.is-ringing .i { animation: bellRing 900ms ease-out; transform-origin: 50% 12%; }
@keyframes bellRing { 0%, 100% { rotate: 0deg; } 15% { rotate: 20deg; } 30% { rotate: -16deg; } 45% { rotate: 12deg; } 60% { rotate: -8deg; } 75% { rotate: 4deg; } }

#overlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  pointer-events: none;
  display: flex;
  align-items: center;
  justify-content: center;
}
#overlay.active { pointer-events: all; background: rgba(8, 7, 12, 0.72); backdrop-filter: blur(6px); }

/* ── Toasts: a white pill that drops in ─────────────────────────────────── */
#toast-container {
  position: fixed;
  top: calc(var(--hud-height) + var(--safe-top) + 8px);
  inset-inline: var(--gutter);
  z-index: 300;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--s-2);
  pointer-events: none;
}
.toast {
  position: relative;
  max-width: 440px;
  background: var(--card);
  color: var(--ink);
  border-radius: 20px;
  padding: 12px 18px;
  font-size: var(--fs-base);
  font-weight: 700;
  box-shadow: 0 4px 0 var(--card-edge), 0 16px 30px -8px rgba(0, 0, 0, 0.6);
  animation: toastIn 520ms var(--ease-pop);
  pointer-events: all;
}
.toast.out { animation: toastOut 220ms var(--ease-in) forwards; }
.toast.reward { background: var(--gold); color: var(--gold-ink); box-shadow: 0 4px 0 var(--btn-gold-edge), 0 0 30px rgba(255, 197, 49, 0.45); }
.toast.error { background: var(--btn-red-2); color: #fff; box-shadow: 0 4px 0 var(--btn-red-edge), 0 16px 30px -8px rgba(0, 0, 0, 0.6); }
@keyframes toastIn { 0% { opacity: 0; transform: translateY(-36px) scale(0.85); } 60% { opacity: 1; transform: translateY(4px) scale(1.03); } 100% { transform: none; } }
@keyframes toastOut { to { opacity: 0; transform: translateY(-16px) scale(0.92); } }

/* ── The dock: floats above the bottom edge; play stands up out of it ───── */
.tab-bar {
  position: fixed;
  bottom: calc(10px + var(--safe-bottom));
  inset-inline: 12px;
  max-width: 540px;
  margin-inline: auto;
  height: 68px;
  padding-inline: 6px;
  border-radius: 26px;
  background: rgba(29, 26, 37, 0.94);
  -webkit-backdrop-filter: blur(18px);
  backdrop-filter: blur(18px);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.06), 0 4px 0 var(--back-950), 0 18px 36px -10px rgba(0, 0, 0, 0.7);
  display: flex;
  align-items: stretch;
  justify-content: space-around;
  z-index: 100;
  transition: transform var(--dur-normal) var(--ease-out), visibility 0s;
}
.tab-bar.hidden {
  transform: translateY(calc(100% + 64px + var(--safe-bottom)));
  visibility: hidden;
  transition: transform var(--dur-normal) var(--ease-in), visibility 0s linear var(--dur-normal);
}

.tab-item {
  position: relative;
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--tab-item-gap);
  padding: 4px 2px;
  color: var(--text-muted);
  font-size: var(--tab-label-font);
  cursor: pointer;
  min-width: var(--tab-item-min-size);
  min-height: var(--tab-item-min-size);
  background: none;
  border: none;
  border-radius: 20px;
  transition: color var(--dur-fast);
}
.tab-item .tab-icon {
  width: var(--tab-icon-size); height: var(--tab-icon-size);
  display: flex; align-items: center; justify-content: center;
  transition: transform 300ms var(--ease-pop), filter 200ms, opacity 200ms;
  filter: grayscale(0.85);
  opacity: 0.55;
}
.tab-icon img, .tab-icon svg { width: 100%; height: 100%; object-fit: contain; }
.tab-item.active { color: var(--text-primary); }
.tab-item.active .tab-icon { transform: translateY(-2px) scale(1.14); filter: none; opacity: 1; animation: tabPop 460ms var(--ease-pop); }
@keyframes tabPop { 0% { scale: 0.7; } 60% { scale: 1.12; } 100% { scale: 1; } }

/* Play is the heart of the game: a big green key standing out of the dock. */
.tab-item[data-world="play"] { justify-content: flex-end; padding-bottom: 6px; }
.tab-item[data-world="play"] .tab-icon {
  position: absolute;
  top: -20px;
  width: 58px; height: 58px;
  border-radius: 20px;
  background: var(--btn-green-2);
  box-shadow: 0 5px 0 var(--btn-green-edge), 0 0 0 5px rgba(29, 26, 37, 0.94), 0 14px 24px -6px rgba(0, 0, 0, 0.6);
  padding: 8px;
  filter: none;
  opacity: 1;
}
.tab-item[data-world="play"] .tab-icon .gi { filter: drop-shadow(0 2px 0 rgba(0, 0, 0, 0.18)); }
.tab-item[data-world="play"].active .tab-icon { transform: none; animation: playBreathe 2.6s ease-in-out infinite; }
@keyframes playBreathe { 0%, 100% { scale: 1; } 50% { scale: 1.05; } }
.tab-item[data-world="play"].active span:last-child { color: var(--btn-green-1); }
.tab-item[data-world="play"]:not(.active) .tab-icon { background: var(--back-500); box-shadow: 0 5px 0 var(--back-950), 0 0 0 5px rgba(29, 26, 37, 0.94); }

/* ── Scenes, and how they change (scene.js keeps the old one as a ghost) ─ */
.scene {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.scene::-webkit-scrollbar { display: none; }

.scene-enter { animation: sceneIn var(--dur-slow) var(--ease-deal); }
.scene-in-push, .ghost-pop {
  background-color: var(--stage);
  background-image: radial-gradient(90% 46% at 50% -6%, var(--stage-glow), transparent 72%), var(--stage-pattern);
  background-size: 100% 100vh, 56px 56px;
  background-repeat: no-repeat, repeat;
  background-attachment: fixed, fixed;
  box-shadow: var(--shadow-lg);
}
.scene-in-push { z-index: 2; animation: scenePushIn 420ms var(--ease-deal) both; }
.scene-in-pop { z-index: 1; animation: scenePopIn 360ms var(--ease-deal) both; }
.scene-in-world-next { animation: sceneWorldIn 360ms var(--ease-deal) both; --from: calc(var(--dir) * 24%); }
.scene-in-world-prev { animation: sceneWorldIn 360ms var(--ease-deal) both; --from: calc(var(--dir) * -24%); }
.scene-ghost { pointer-events: none; overflow: hidden; }
.ghost-push { z-index: 1; animation: ghostSink 420ms var(--ease-deal) forwards; }
.ghost-pop { z-index: 3; animation: ghostFlick 340ms cubic-bezier(0.5, 0, 0.75, 0) forwards; }
.ghost-world-next { animation: ghostWorld 360ms var(--ease-deal) forwards; --to: calc(var(--dir) * -24%); }
.ghost-world-prev { animation: ghostWorld 360ms var(--ease-deal) forwards; --to: calc(var(--dir) * 24%); }

@keyframes sceneIn { from { opacity: 0; transform: scale(0.96); } }
@keyframes scenePushIn { 0% { transform: translateX(calc(var(--dir) * 100%)); } 70% { transform: translateX(calc(var(--dir) * -1.5%)); } 100% { transform: none; } }
@keyframes scenePopIn { from { transform: scale(0.94); opacity: 0.4; } }
@keyframes sceneWorldIn { from { transform: translateX(var(--from)); opacity: 0; } }
@keyframes ghostSink { to { transform: scale(0.92); opacity: 0.3; } }
@keyframes ghostFlick { to { transform: translateX(calc(var(--dir) * 100%)); } }
@keyframes ghostWorld { to { transform: translateX(var(--to)); opacity: 0; } }

/* ── Touch: everything squashes under the finger and springs back ────────
   feel.js toggles these. 'scale'/'translate' compose with any transform. */
.is-pressed { scale: 0.95; transition: scale 70ms ease-out, translate 70ms ease-out, box-shadow 70ms ease-out, filter 70ms; filter: brightness(0.96); }
.deck-card.is-pressed { scale: 0.97; translate: 0 3px; }
.is-released { animation: pressPop 380ms var(--ease-pop); }
@keyframes pressPop { 0% { scale: 0.95; } 50% { scale: 1.05; } 75% { scale: 0.99; } 100% { scale: 1; } }

/* Content is dealt in when a screen opens (feel.js staggers it). */
.dealt-auto { animation: dealIn 480ms var(--ease-pop) var(--deal-delay, 0ms) both; }
@keyframes dealIn { 0% { opacity: 0; transform: translateY(18px) scale(0.94); } 100% { opacity: 1; transform: none; } }

.is-counting { display: inline-block; scale: 1.12; color: var(--gold-soft); transition: scale 120ms; }
.is-landed { display: inline-block; animation: numberLand 440ms var(--ease-pop); }
@keyframes numberLand { 0% { scale: 1.35; } 100% { scale: 1; } }

/* ── Screen furniture ───────────────────────────────────────────────────── */
.screen {
  position: relative;
  width: 100%;
  max-width: 560px;
  margin-inline: auto;
  padding: 8px var(--gutter) 28px;
}

/* A screen header: round back key, a big title, actions at the end. */
.screen-head {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 56px;
  margin-bottom: 14px;
}
.screen-head-text { flex: 1; min-width: 0; display: flex; flex-direction: column; align-items: center; text-align: center; }
.screen-head-actions { display: flex; align-items: center; gap: var(--s-2); }
.screen-head > [data-back], .screen-head > .icon-btn:first-child { flex-shrink: 0; }
.screen-head:has(> [data-back]):not(:has(.screen-head-actions)) .screen-head-text { margin-inline-end: 56px; }

.screen-title {
  font-size: var(--fs-xl);
  line-height: 1.15;
  color: var(--text-primary);
  text-wrap: balance;
}
.screen-head .screen-title {
  max-width: 100%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.screen-sub { margin-top: 6px; font-size: var(--fs-sm); font-weight: 600; color: var(--text-secondary); }

/* A ribbon is now a flat tag. */
.ribbon {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 6px 18px;
  background: var(--btn-red-2);
  border-radius: 14px;
  box-shadow: 0 4px 0 var(--btn-red-edge);
  color: #fff;
  font-size: var(--fs-lg);
  text-shadow: var(--text-outline);
}
.ribbon.gold { background: var(--btn-gold-2); box-shadow: 0 4px 0 var(--btn-gold-edge); color: var(--gold-ink); text-shadow: none; }
.ribbon.green { background: var(--btn-green-2); box-shadow: 0 4px 0 var(--btn-green-edge); }
.ribbon.blue { background: var(--btn-blue-2); box-shadow: 0 4px 0 var(--btn-blue-edge); }

.section-title {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 24px 0 10px;
  font-size: var(--fs-md);
  color: var(--text-primary);
}
.section-title .link { margin-inline-start: auto; font-size: var(--fs-sm); color: var(--sky); }

/* Round keys for icons; the back key is the same, with a bold arrow. */
.icon-btn {
  width: 46px; height: 46px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 16px;
  background: var(--back-700);
  border: none;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.05), 0 4px 0 var(--back-950);
  color: var(--text-primary);
  cursor: pointer;
  flex-shrink: 0;
  padding: 0;
}
.icon-btn.is-pressed { translate: 0 3px; box-shadow: 0 1px 0 var(--back-950); }
[data-back].icon-btn .i { stroke-width: 2.8; }

/* ── Profile avatar ─────────────────────────────────────────────────────── */
.profile-avatar-wrap { position: relative; width: 96px; height: 96px; margin: 0 auto; cursor: pointer; }
.profile-avatar {
  width: 96px; height: 96px;
  border-radius: 30px;
  background: var(--btn-purple-2);
  box-shadow: 0 5px 0 var(--btn-purple-edge);
  display: flex; align-items: center; justify-content: center;
  color: #fff;
  overflow: hidden;
}
.profile-avatar-edit {
  position: absolute;
  bottom: -6px; inset-inline-end: -6px;
  width: 34px; height: 34px;
  border-radius: 12px;
  background: var(--btn-green-2);
  box-shadow: 0 0 0 3px var(--stage), 0 3px 0 var(--btn-green-edge);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
}

/* ── Panels: flat ink, a step up from the stage ─────────────────────────── */
.card, .tray {
  position: relative;
  background: var(--back-800);
  border-radius: var(--r-xl);
  padding: var(--s-4);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.04), 0 4px 0 var(--back-950);
}

/* ── Game cards: white, with a lip ──────────────────────────────────────── */
.deck-card {
  position: relative;
  background: var(--card);
  color: var(--ink);
  border-radius: var(--r-card);
  box-shadow: var(--shadow-card);
  isolation: isolate;
}
.deck-card { --suit: var(--ink); }
.deck-card.ink-red { --suit: var(--red-ink); }
.deck-card .index {
  position: absolute;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
  color: var(--suit);
  font-family: var(--font-display);
  line-height: 1;
}
.deck-card .index.top { top: 13px; inset-inline-start: 13px; }
.deck-card .index.bottom { bottom: 13px; inset-inline-end: 13px; transform: rotate(180deg); }
button.deck-card, .deck-card[role="button"] { border: none; cursor: pointer; font: inherit; text-align: inherit; }
.deck-card.is-pressed { box-shadow: 0 1px 0 var(--card-edge), 0 6px 14px -6px rgba(0, 0, 0, 0.5); }

/* Locked or not yet: the card lies face down, showing the violet back. */
.deck-back,
.deck-card.face-down {
  background-color: var(--btn-purple-2);
  background-image: var(--back-pattern);
  background-size: 18px 18px;
  color: #fff;
}
.deck-card.face-down { box-shadow: 0 5px 0 var(--btn-purple-edge), 0 14px 28px -10px rgba(0, 0, 0, 0.55); }

/* Spent: a punched corner. */
.deck-card.spent {
  -webkit-mask: radial-gradient(circle 12px at calc(100% - 18px) 18px, transparent 98%, #000 100%);
          mask: radial-gradient(circle 12px at calc(100% - 18px) 18px, transparent 98%, #000 100%);
}
[dir="rtl"] .deck-card.spent {
  -webkit-mask: radial-gradient(circle 12px at 18px 18px, transparent 98%, #000 100%);
          mask: radial-gradient(circle 12px at 18px 18px, transparent 98%, #000 100%);
}

/* ── Buttons: flat colour on a solid lip ────────────────────────────────── */
button,
[role="button"],
input[type="button"],
input[type="submit"] { min-block-size: var(--tap-min, 44px); }

a { color: var(--sky); text-underline-offset: 3px; }
a:not(.btn):not([class*="tab"]) { display: inline-flex; align-items: center; min-block-size: var(--tap-min, 44px); }

.icon-btn, .hud-btn, #emote-inline-toggle, .bgg-action-btn, #back-btn { min-inline-size: var(--tap-min, 44px); }

.btn {
  --b1: var(--btn-wood-1); --b2: var(--btn-wood-2); --be: var(--btn-wood-edge); --bt: #fff;
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0 22px;
  min-height: var(--btn-min-height);
  border: none;
  border-radius: var(--r-btn);
  background: linear-gradient(180deg, var(--b1), var(--b2));
  color: var(--bt);
  font-size: var(--fs-md);
  line-height: 1.1;
  text-shadow: var(--text-outline);
  cursor: pointer;
  box-shadow: 0 var(--btn-lip) 0 var(--be);
  transition: filter var(--dur-fast);
  -webkit-user-select: none;
  isolation: isolate;
}
.btn .i { stroke-width: 2.6; }
.btn.is-pressed { translate: 0 4px; box-shadow: 0 1px 0 var(--be); }
.btn:disabled, .btn[aria-disabled="true"] { filter: grayscale(0.9) brightness(0.75); cursor: default; }

.btn-primary, .btn-game { --b1: var(--btn-green-1); --b2: var(--btn-green-2); --be: var(--btn-green-edge); }
/* Small keys carry 13-14px text, which needs 4.5:1: a deeper green. */
.btn-sm.btn-primary, .btn-sm.btn-game { --b1: var(--btn-green-deep); --b2: var(--btn-green-deep); --be: var(--btn-green-deep-edge); }
.btn-card, .btn-blue { --b1: var(--btn-blue-1); --b2: var(--btn-blue-2); --be: var(--btn-blue-edge); }
.btn-gold { --b1: var(--btn-gold-1); --b2: var(--btn-gold-2); --be: var(--btn-gold-edge); --bt: var(--gold-ink); text-shadow: none; }
.btn-danger, .btn-red { --b1: var(--btn-red-1); --b2: var(--btn-red-2); --be: var(--btn-red-edge); }
.btn-purple { --b1: var(--btn-purple-1); --b2: var(--btn-purple-2); --be: var(--btn-purple-edge); }
.btn-orange { --b1: var(--btn-orange-1); --b2: var(--btn-orange-2); --be: var(--btn-orange-edge); }
.btn-white { --b1: var(--btn-white-1); --b2: var(--btn-white-2); --be: var(--btn-white-edge); --bt: var(--ink); text-shadow: none; }
.btn-secondary, .btn-wood { --b1: var(--btn-wood-1); --b2: var(--btn-wood-2); --be: var(--btn-wood-edge); --bt: var(--text-primary); }
.btn-ghost {
  background: transparent;
  box-shadow: inset 0 0 0 2px var(--back-line-strong);
  color: var(--text-secondary);
  text-shadow: none;
}
.btn-primary .gi-refresh, .btn-primary .gi-check, .btn-primary .gi-plus, .btn-primary .gi-up,
.btn-primary .gi-puzzle, .btn-primary .gi-friends, .btn-primary .gi-team { filter: brightness(0) invert(1); }   /* green stickers vanish on a green key */
.btn-ghost.is-pressed { translate: 0 1px; box-shadow: inset 0 0 0 2px var(--back-line-strong); }

/* The big calls to play catch the light now and then. */
.btn-lg.btn-primary, .btn-lg.btn-gold, .btn-xl { overflow: hidden; }
.btn-lg.btn-primary::before, .btn-lg.btn-gold::before, .btn-xl::before {
  content: '';
  position: absolute;
  inset: -20% auto -20% 0;
  width: 30%;
  background: linear-gradient(100deg, transparent, rgba(255, 255, 255, 0.32), transparent);
  transform: translateX(-160%) skewX(-18deg);
  animation: glint 4s var(--ease-in-out) 1.2s infinite;
  pointer-events: none;
  z-index: -1;
}
@keyframes glint { 0%, 72% { transform: translateX(-160%) skewX(-18deg); } 100% { transform: translateX(440%) skewX(-18deg); } }

.btn-block { width: 100%; }
.btn-lg { min-height: 62px; font-size: var(--fs-lg); padding-inline: 26px; border-radius: 20px; }
.btn-xl { min-height: 70px; font-size: var(--fs-xl); padding-inline: 30px; border-radius: 22px; --btn-lip: 6px; }
.btn-sm { min-height: 40px; font-size: var(--fs-sm); padding-inline: 14px; border-radius: 14px; --btn-lip: 3px; }

/* ── Game-mode buttons and the room hero (ui.modeButton / ui.roomHero) ── */
.mode-btn {
  justify-content: flex-start;
  gap: 14px;
  min-height: 84px;
  padding: 10px 14px;
  border-radius: 24px;
  text-align: start;
}
.mode-btn + .mode-btn { margin-top: 14px; }
.mode-icon {
  width: 60px; height: 60px;
  flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.2);
}
.mode-icon.is-live .gi { animation: idleBob 2.4s ease-in-out infinite; }
.mode-text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.mode-title { font-family: var(--font-display); font-size: var(--fs-lg); line-height: 1.1; }
.mode-sub { font-family: var(--font-ar); font-weight: 600; font-size: var(--fs-xs); opacity: 0.9; text-shadow: none; line-height: 1.3; }
.mode-chev { flex-shrink: 0; opacity: 0.85; }

.room-hero { display: flex; justify-content: center; margin: 4px 0 22px; }
.room-hero-card { width: min(62vw, 240px); padding: 0; overflow: hidden; }
.room-hero-art { display: block; margin: 8px 8px 0; height: calc(min(62vw, 240px) * 0.62); border-radius: 16px; overflow: hidden; }
.room-hero-art .game-art { width: 100%; height: 100%; display: block; }
.room-hero-name { display: block; padding: 8px 0 10px; text-align: center; font-family: var(--font-display); font-size: var(--fs-lg); color: var(--ink); }
.room-hero-card:not(:has(.room-hero-name)) .room-hero-art { margin-bottom: 8px; }

/* ── Inputs ─────────────────────────────────────────────────────────────── */
.input {
  width: 100%;
  padding: 12px 16px;
  background: var(--back-700);
  border: 2px solid transparent;
  border-radius: var(--r-input);
  color: var(--text-primary);
  font-family: var(--font-ar);
  font-size: 17px;
  font-weight: 600;
  outline: none;
  transition: border-color var(--dur-fast), background var(--dur-fast);
  min-height: 54px;
  user-select: text;
}
.input:focus { border-color: var(--btn-purple-1); background: var(--back-600); }
.input::placeholder { color: var(--text-dim); }

/* ── Chips: pills; the chosen one is white ──────────────────────────────── */
.chips {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  scrollbar-width: none;
  padding: 2px 2px 8px;
}
.chips::-webkit-scrollbar { display: none; }
.chip {
  position: relative;
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 42px;
  padding: 0 16px;
  border-radius: 21px;
  border: none;
  background: var(--back-700);
  box-shadow: 0 3px 0 var(--back-950);
  color: var(--text-secondary);
  font-size: var(--fs-sm);
  cursor: pointer;
}
.chip.is-pressed { translate: 0 2px; box-shadow: 0 1px 0 var(--back-950); }
.chip.active, .chip[aria-pressed="true"], .chip[aria-selected="true"] {
  background: var(--card);
  box-shadow: 0 3px 0 var(--card-edge);
  color: var(--ink);
}
.chip.active *, .chip[aria-pressed="true"] *, .chip[aria-selected="true"] * { font-weight: inherit; }

/* ── Rows: each one its own ink tile ────────────────────────────────────── */
.rows {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.rows:empty { display: none; }
.row {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 64px;
  padding: 10px 14px;
  border-radius: 20px;
  background: var(--back-800);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.04), 0 3px 0 var(--back-950);
}
.row-main { flex: 1; min-width: 0; }
.row-title { font-size: var(--fs-base); font-weight: 700; color: var(--text-primary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-sub { font-size: var(--fs-sm); font-weight: 500; color: var(--text-muted); }

.avatar {
  width: 44px; height: 44px;
  border-radius: 15px;
  background: var(--btn-purple-2);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  overflow: hidden;
  flex-shrink: 0;
  font-family: var(--font-display);
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }

/* Count badges anywhere: a red bead ringed in the stage colour. */
.badge {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 22px; height: 22px; padding: 0 6px;
  border-radius: 11px;
  background: var(--red);
  box-shadow: 0 0 0 3px var(--stage);
  color: #fff;
  font-family: var(--font-display);
  font-size: 13px;
  line-height: 1;
}

/* ── Empty states: one big quiet mark and one honest line ───────────────── */
.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 12px;
  padding: 40px 24px;
  color: var(--text-secondary);
}
.empty .deck-back {
  width: 92px; height: 92px;
  border-radius: 30px;
  background: var(--back-700);
  background-image: none;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.05), 0 5px 0 var(--back-950);
  display: flex; align-items: center; justify-content: center;
  color: var(--text-muted);
  animation: float 3.4s ease-in-out infinite;
}
.empty .deck-back .i { width: 40px; height: 40px; }
.empty-title { font-size: var(--fs-lg); color: var(--text-primary); }
.empty-sub { font-size: var(--fs-sm); font-weight: 500; max-width: 34ch; color: var(--text-muted); }

/* ── Utility ────────────────────────────────────────────────────────────── */
.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-center { justify-content: center; }
.justify-between { justify-content: space-between; }
.gap-2 { gap: var(--s-2); }
.gap-3 { gap: var(--s-3); }
.gap-4 { gap: var(--s-4); }
.text-center { text-align: center; }
.text-gold { color: var(--gold); }
.text-secondary { color: var(--text-secondary); }
.w-full { width: 100%; }
.p-4 { padding: var(--s-4); }
.mt-4 { margin-top: var(--s-4); }
.num { font-variant-numeric: tabular-nums; direction: ltr; unicode-bidi: isolate; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.skeleton {
  background: linear-gradient(90deg, var(--back-800) 25%, var(--back-700) 50%, var(--back-800) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite linear;
  border-radius: var(--r-md);
}
@keyframes shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }

/* ── Motion vocabulary (names kept: scene code calls them) ──────────────── */
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.55; } }
@keyframes float { 0%, 100% { translate: 0 0; } 50% { translate: 0 -6px; } }
@keyframes glow { 0%, 100% { box-shadow: 0 0 0 0 rgba(255, 197, 49, 0); } 50% { box-shadow: 0 0 22px 4px rgba(255, 197, 49, 0.5); } }
@keyframes shake { 0%,100% { transform: translateX(0); } 20% { transform: translateX(-6px); } 40% { transform: translateX(6px); } 60% { transform: translateX(-3px); } 80% { transform: translateX(3px); } }
@keyframes popIn { 0% { transform: scale(0.4); opacity: 0; } 70% { transform: scale(1.1); opacity: 1; } 100% { transform: scale(1); } }
@keyframes slamIn { 0% { transform: scale(2.2) rotate(-10deg); opacity: 0; } 55% { transform: scale(0.9) rotate(2deg); opacity: 1; } 75% { transform: scale(1.06); } 100% { transform: none; } }
@keyframes slideUp { from { transform: translateY(100%); } to { transform: translateY(0); } }
@keyframes slideUpBounce { 0% { transform: translateY(100%); } 70% { transform: translateY(-4%); } 100% { transform: translateY(0); } }
@keyframes bounceIn { 0% { transform: scale(0.5); opacity: 0; } 60% { transform: scale(1.08); opacity: 1; } 80% { transform: scale(0.97); } 100% { transform: scale(1); } }
@keyframes breatheGlow { 0%, 100% { box-shadow: 0 0 0 0 rgba(255, 197, 49, 0); } 50% { box-shadow: 0 0 18px 3px rgba(255, 197, 49, 0.45); } }
@keyframes bgGradientMove { 0%, 100% { background-position: 0 0; } }
@keyframes numberPop { 0% { transform: scale(1); } 50% { transform: scale(1.25); } 100% { transform: scale(1); } }
@keyframes ringExpand { 0% { transform: scale(0.5); opacity: 1; } 100% { transform: scale(2.4); opacity: 0; } }
@keyframes wobble { 0%,100% { transform: rotate(0); } 25% { transform: rotate(-4deg); } 75% { transform: rotate(4deg); } }
@keyframes shimmerBorder { 0%, 100% { border-color: rgba(255, 197, 49, 0.3); } 50% { border-color: rgba(255, 197, 49, 0.9); } }
@keyframes fadeIn { from { opacity: 0; } }
@keyframes deal { from { opacity: 0; transform: translateY(-40px) rotate(var(--deal-rot, -8deg)) scale(0.9); } }
@keyframes flipIn { 0% { transform: perspective(900px) rotateY(90deg) scale(0.9); } 60% { transform: perspective(900px) rotateY(-10deg) scale(1.04); } 100% { transform: perspective(900px) rotateY(0) scale(1); } }
@keyframes wiggle { 0%, 82%, 100% { rotate: 0deg; } 86% { rotate: -9deg; } 90% { rotate: 8deg; } 94% { rotate: -5deg; } 97% { rotate: 3deg; } }
@keyframes idleBob { 0%, 100% { translate: 0 0; } 50% { translate: 0 -4px; } }

.pulse { animation: pulse 1.6s ease-in-out infinite; }
.float { animation: float 3.2s ease-in-out infinite; }
.shake { animation: shake 0.34s ease; }
.pop-in { animation: popIn 420ms var(--ease-out); }
.slam-in { animation: slamIn 560ms var(--ease-out); }
.bounce-in { animation: bounceIn 520ms var(--ease-out); }
.slide-up { animation: slideUp var(--dur-normal) var(--ease-out); }
.slide-up-bounce { animation: slideUpBounce 460ms var(--ease-deal); }
.breathe-glow { animation: breatheGlow 2.2s ease-in-out infinite; }
.wobble { animation: wobble 0.5s ease; }
.wiggle { animation: wiggle 3s ease-in-out infinite; }
.number-pop { animation: numberPop 300ms var(--ease-out); }
.dealt { animation: deal 520ms var(--ease-pop) both; }
.flip-in { animation: flipIn 640ms var(--ease-deal) both; }

::-webkit-scrollbar { width: 4px; height: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, 0.15); border-radius: 2px; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 1ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 1ms !important;
  }
}

/* Native app mode */
.native-app .tab-bar { padding-bottom: calc(var(--safe-bottom) + 8px); }
