/* Satwat Al-Bunuk — v9 dark velvet noir.
   Local fonts only (no Google Fonts): Markazi Text for big Arabic
   headings, Playfair Display for Latin numbers/codes, IBM Plex Sans
   Arabic for UI text. Tokens are verbatim from the v9 mockups
   (v9-source/style.css :root); the --accent/--border/--dim/--surface
   aliases keep the JS inline styles (which reference those names)
   painting in v9 colours. */
@font-face { font-family: "Markazi Text"; src: url("../assets/fonts/MarkaziText-Variable.woff2") format("woff2"); font-weight: 100 900; font-style: normal; font-display: swap; }
@font-face { font-family: "Playfair Display"; src: url("../assets/fonts/PlayfairDisplay-Variable.woff2") format("woff2"); font-weight: 100 900; font-style: normal; font-display: swap; }
@font-face { font-family: "IBM Plex Sans Arabic"; src: url("../assets/fonts/IBMPlexSansArabic-Regular.woff2") format("woff2"); font-weight: 400; font-style: normal; font-display: swap; }
@font-face { font-family: "IBM Plex Sans Arabic"; src: url("../assets/fonts/IBMPlexSansArabic-Medium.woff2") format("woff2"); font-weight: 500; font-style: normal; font-display: swap; }
@font-face { font-family: "IBM Plex Sans Arabic"; src: url("../assets/fonts/IBMPlexSansArabic-SemiBold.woff2") format("woff2"); font-weight: 600; font-style: normal; font-display: swap; }
@font-face { font-family: "IBM Plex Sans Arabic"; src: url("../assets/fonts/IBMPlexSansArabic-Bold.woff2") format("woff2"); font-weight: 700; font-style: normal; font-display: swap; }

:root {
  color-scheme: dark;
  --ground: #090305;
  --line: rgba(214, 176, 108, .38);
  --line2: rgba(236, 226, 214, .13);
  --cream: #efe5d8;
  --mut: rgba(239, 229, 216, .70);
  --gold: #d2ab68;
  --gold2: #ecd29a;
  --blue: #7fa2cc;
  --silver: #c6d2de;
  --turquoise: #3ec9b2;
  --yellow: #ecd35f;
  --danger: #8e4a54;
  --live: #6fbf87;
  /* Aliases the JS inline styles reference (live names, v9 values). */
  --bg: #090305;
  --bg-deep: #090305;
  --surface: rgba(42, 14, 22, .72);
  --surface-2: rgba(14, 4, 8, .84);
  --text: #efe5d8;
  --dim: rgba(239, 229, 216, .70);
  --ink: #efe5d8;
  --ink-dim: rgba(239, 229, 216, .70);
  --panel-text: #efe5d8;
  --panel-dim: rgba(239, 229, 216, .70);
  --border: rgba(214, 176, 108, .38);
  --accent: #d2ab68;
  --accent-ink: #241a08;
  --gold-grad: linear-gradient(180deg, #f0d9a2, #d4ad69 55%, #a97f3d);
  --radius: 20px;
  --font-display: "Markazi Text", serif;
  --font-lat: "Playfair Display", serif;
  --font-ui: "IBM Plex Sans Arabic", system-ui, sans-serif;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; overscroll-behavior-y: none; touch-action: manipulation; }
body { overflow-x: clip; }
/* Touch polish for the game room: no pinch/double-tap zoom gestures,
   no blue tap flash, and no accidental text selection while tapping
   cards and buttons during play. */
button, .bcard, [role="button"] {
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}
/* Seamless refresh, part 1: the page background colour is known
   from the very first paint (before the body background image is
   even applied), so a reload never flashes white. */
html { background: #090305; }
/* Seamless refresh, part 2: the tiny boot script in the head
   stamps the last visited screen onto <html data-boot="…">, and
   that screen is displayed immediately — ahead of any script or
   network work — instead of every screen starting hidden and
   popping in later. The main script removes the attribute on
   its first showScreen() call, after which the normal .hidden
   classes rule again. */
html[data-boot="home"] #screen-home,
html[data-boot="login"] #screen-login,
html[data-boot="admin"] #screen-admin,
html[data-boot="wait"] #screen-wait,
html[data-boot="game"] #screen-game { display: block !important; }
body {
  background-color: #090305;
  background-image: url("../assets/images/heroes/bg-velvet-mobile-720x1280.webp");
  background-size: cover;
  background-position: center top;
  background-repeat: no-repeat;
  background-attachment: fixed;
  color: var(--cream);
  font-family: var(--font-ui);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  min-height: 100vh;
}
@media (min-width: 768px) {
  body { background-image: url("../assets/images/heroes/bg-velvet-desktop-1600x900.webp"); }
}
button, input { font-family: inherit; }
/* Touch targets: 44px minimum on every button/input. */
button, [role="button"], select, summary, input:not([type="checkbox"], [type="radio"]) { min-height: 2.75rem; }
.font-display { font-family: var(--font-display); }
/* Buttons carry .font-display in the markup for weight, but their
   text renders in the UI font (Markazi is for headings only). */
.btn-gold.font-display, .btn-ghost.font-display { font-family: var(--font-ui); }
.hidden { display: none !important; }

/* ---------- Screens: one centred phone-width column ---------- */
.screen { margin: 0 auto; width: 100%; max-width: 30rem; padding: 0 1rem 3rem; }
.screen-narrow { max-width: 28rem; }
.screen-wide { max-width: 30rem; padding: 0 0.625rem 1.5rem; }

/* ---------- Top bar / brand / hero ---------- */
.top { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; padding-top: 0.75rem; }
.pills { display: flex; gap: 0.375rem; align-items: center; }
.brand {
  font-family: var(--font-display);
  font-size: 2.1rem; font-weight: 700; line-height: 1.1;
  color: var(--gold2);
  text-shadow: 0 2px 18px rgba(210, 171, 108, .35);
  white-space: nowrap;
}
.brand-sm { font-size: 1.45rem; }
.hero { display: block; margin-top: 0.75rem; }
.hero img {
  display: block; width: 100%; height: 220px;
  object-fit: cover; object-position: center 25%;
  border-radius: 18px; border: 1px solid var(--line);
  box-shadow: 0 18px 40px rgba(0, 0, 0, .55);
}
.hero-sm img { height: 170px; }
.h1 {
  font-family: var(--font-display);
  font-size: 2rem; font-weight: 700; line-height: 1.25;
  text-align: center; color: var(--cream);
  margin: 0.9rem 0 0;
}
.lead { text-align: center; color: var(--mut); font-size: 0.95rem; line-height: 1.7; margin: 0.4rem auto 0; max-width: 26rem; }

/* ---------- Glass panels ---------- */
.glass, .panel, .panel-flat {
  margin-top: 1rem;
  background: linear-gradient(180deg, rgba(42, 14, 22, .72), rgba(14, 4, 8, .84));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 18px 40px rgba(0, 0, 0, .5);
  color: var(--panel-text);
  padding: 1rem;
}
.glass h2.font-display, .panel h2.font-display, .panel-flat h2.font-display { margin: 0; font-size: 1.25rem; font-weight: 700; }
.glass > .dim, .panel > .dim, .panel-flat > .dim { margin: 0.25rem 0 0; font-size: 0.8rem; }
.label { display: block; font-size: 0.9rem; font-weight: 700; color: var(--cream); margin-bottom: 0.5rem; }

/* ---------- Buttons ---------- */
.btn-gold {
  background: var(--gold-grad);
  color: var(--accent-ink);
  border: 1.5px solid rgba(36, 26, 8, 0.5);
  border-radius: 999px;
  cursor: pointer;
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.45), inset 0 1px 0 rgba(255, 255, 255, 0.55);
  transition: transform 0.15s ease, box-shadow 0.15s ease, filter 0.15s ease;
}
.btn-gold:not(:disabled):hover { filter: brightness(1.04); transform: translateY(-1px); }
.btn-gold:disabled { opacity: 0.5; cursor: default; }
.btn-ghost {
  background: rgba(9, 3, 5, 0.45);
  border: 1px solid var(--line);
  color: var(--cream);
  border-radius: 999px;
  padding: 0.45rem 1rem;
  font-size: 0.8rem;
  font-weight: 700;
  cursor: pointer;
}
.btn-ghost:disabled { opacity: 0.45; cursor: default; }
.lang-btn { font-weight: 800; letter-spacing: 0.02em; }

/* ---------- Home: watch code + strip + rules ---------- */
#join-form { margin-top: 0.75rem; display: flex; gap: 0.5rem; }
.codebox-input {
  min-width: 0; flex: 1;
  border-radius: 12px;
  border: 1px solid rgba(210, 171, 108, 0.5);
  background: rgba(9, 3, 5, 0.6);
  color: var(--gold2);
  padding: 0.75rem 1rem;
  text-align: center;
  font-family: var(--font-lat);
  font-size: 1.25rem; font-weight: 700; letter-spacing: 0.3em;
}
.codebox-input::placeholder { color: rgba(236, 210, 154, 0.4); letter-spacing: 0.3em; }
.codebox-input:focus { outline: 2px solid rgba(210, 171, 104, 0.65); outline-offset: 1px; }
/* Wrong-code error (mockup screen 3): the codebox itself turns red. */
.codebox-input.input-error { border-color: rgba(224, 120, 120, 0.8); background: rgba(142, 74, 84, 0.25); color: #fca5a5; }
#join-btn { flex-shrink: 0; border-radius: 12px; padding: 0.75rem 1.25rem; font-size: 1rem; font-weight: 800; }
#join-name-row { margin-top: 0.5rem; display: flex; gap: 0.5rem; align-items: center; }
#join-name {
  min-width: 0; flex: 1;
  border-radius: 12px; border: 1px solid var(--line2);
  background: rgba(9, 3, 5, 0.55); color: var(--cream);
  padding: 0.6rem 1rem; font-size: 1rem; font-weight: 600;
}
#join-name:disabled { opacity: 1; color: var(--panel-dim); }
#join-name-edit { flex-shrink: 0; padding: 0.6rem 1rem; font-size: 0.9rem; }
#join-error { margin: 0.5rem 0 0; }
.home-strip { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; margin-top: 1rem; }
.strip-tile {
  position: relative;
  background: rgba(14, 4, 8, 0.6);
  border: 1px solid var(--line2);
  border-radius: 12px;
  padding: 4px 2px 6px;
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  cursor: pointer; overflow: hidden;
}
.strip-tile img { width: 100%; aspect-ratio: 3 / 4; object-fit: cover; object-position: center 20%; border-radius: 8px; }
.strip-tile span:last-child { font-size: 9px; font-weight: 700; color: var(--cream); line-height: 1.3; }
.rules { margin: 0.75rem 0 0; padding-inline-start: 1.25rem; font-size: 0.9rem; line-height: 1.8; color: var(--mut); }

/* ---------- Login ---------- */
#screen-login .glass h1.font-display { margin: 0; text-align: center; font-size: 1.6rem; font-weight: 700; }
#login-form { margin-top: 1.25rem; display: grid; gap: 0.75rem; }
#login-form > label.dim { display: block; font-size: 0.75rem; font-weight: 700; }
.pass-wrap { position: relative; margin-top: 0.375rem; }
#login-pass { padding-inline-start: 2.75rem; }
#toggle-pass {
  position: absolute; top: 0; bottom: 0; inset-inline-start: 0;
  width: 2.5rem; min-height: 0;
  display: flex; align-items: center; justify-content: center;
  background: none; border: none; cursor: pointer; color: var(--dim);
}
#login-error { margin: 0; }
#login-btn { width: 100%; border-radius: 999px; padding: 0.8rem; font-size: 1rem; font-weight: 800; }
.login-note { margin: 0.9rem 0 0; text-align: center; font-size: 0.8rem; line-height: 1.7; }

/* ---------- Admin / create ---------- */
.admin-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 0.5rem; padding-top: 1.5rem; }
.admin-head p { margin: 0; font-size: 0.9rem; }
#admin-name { color: var(--cream); }
.setup-block { margin-top: 1rem; }
#team-count-group { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0.5rem; }
#setup-names { display: grid; grid-template-columns: 1fr; gap: 0.5rem; }
.stat-cards { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0.5rem; }
.stat-card {
  display: flex; flex-direction: column; align-items: center; gap: 0.1rem;
  padding: 0.7rem 0.25rem; border-radius: 14px;
  border: 1px solid var(--line2); background: rgba(9, 3, 5, 0.5);
}
.stat-card b.num { font-family: var(--font-lat); font-size: 1.5rem; font-weight: 700; color: var(--gold2); }
.stat-card span { font-size: 0.72rem; color: var(--mut); font-weight: 700; }
.setup-note { margin-top: 0.9rem; font-size: 0.85rem; line-height: 1.7; }
#create-error { margin: 0.75rem 0 0; }
#create-btn { margin-top: 1rem; width: 100%; border-radius: 999px; padding: 0.9rem; font-size: 1.1rem; font-weight: 800; }

/* ---------- Wait screen ---------- */
#wait-title { margin: 0; font-size: 1.25rem; font-weight: 700; padding-top: 4rem; }
#wait-text { margin: 0.5rem 0 0; font-size: 0.9rem; }
#wait-back { margin-top: 1.25rem; padding: 0.6rem 1.25rem; font-size: 0.9rem; }

/* ---------- Fields / errors / dim ---------- */
.field {
  width: 100%;
  background: rgba(9, 3, 5, 0.55);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 10px;
  padding: 0.6rem 0.75rem;
  font-size: 0.9rem;
  font-weight: 700;
}
.field:focus { outline: 2px solid rgba(210, 171, 104, 0.65); outline-offset: 1px; }
.err { color: #fca5a5; font-size: 0.9rem; font-weight: 700; }
.dim { color: var(--mut); }

/* ---------- Team strip: solid colour pills, name dead-centre ---------- */
.team-strip { display: flex; gap: 0.375rem; margin-top: 0.5rem; }
.team-pill {
  display: grid;
  place-items: center;
  height: 2.5rem;
  min-width: 0;
  flex: 1;
  border-radius: 999px;
  border: 1px solid rgba(0, 0, 0, 0.28);
  padding: 0 0.25rem;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.25);
}
.team-pill .tname {
  display: block;
  width: 100%;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-align: center;
  font-size: 11px;
  font-weight: 800;
  line-height: 1.75;
  padding-block: 0.14em;
  font-family: var(--font-ui);
}
.team-pill.is-turn {
  border-color: #ecd29a;
  box-shadow: 0 0 0 2px #090305, 0 0 0 4px #d2ab68, 0 0 18px rgba(210, 171, 104, 0.65), 0 6px 14px rgba(0, 0, 0, 0.3);
}
.team-pill.eliminated { opacity: .6; filter: grayscale(1); }
.team-pill.eliminated.is-turn { opacity: .92; filter: grayscale(.35); }
.team-pill .tname-wrap {
  display: flex; align-items: center; justify-content: center;
  gap: 0.3rem; width: 100%; min-width: 0;
}
.team-pill .tname-wrap .tname { width: auto; flex: 0 1 auto; }
.loser-badge {
  flex: none; font-size: 8.5px; font-weight: 900; line-height: 1.5;
  padding: 0.22rem 0.4rem; border-radius: 999px;
  background: rgba(10, 14, 22, .78); color: #E8EDF4;
  border: 1px solid rgba(255, 255, 255, .55);
}
.team-pill.host { cursor: pointer; }
.team-pill input {
  height: 2rem; min-height: 2rem; width: 100%; min-width: 0;
  border-radius: 999px; border: 1px solid;
  background: var(--surface); color: var(--text);
  text-align: center; font-size: 11px; font-weight: 700; padding: 0 0.375rem;
}

/* ---------- Message banner: centred grid cell ---------- */
.msg-banner {
  margin-top: 0.5rem;
  display: grid;
  place-items: center;
  min-height: 2.5rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: linear-gradient(180deg, rgba(42, 14, 22, .72), rgba(14, 4, 8, .84));
  color: var(--panel-text);
  padding: 0.5rem 0.75rem;
  box-shadow: 0 10px 20px rgba(0, 0, 0, 0.35);
}
.msg-banner.pending { background: linear-gradient(170deg, rgba(210, 171, 104, 0.28), rgba(42, 14, 22, 0.8)); border-color: var(--gold); }
.msg-banner p { margin: 0; width: 100%; text-align: center; font-size: 0.9rem; font-weight: 700; line-height: 1.45; font-family: var(--font-display); }

/* ---------- Host controls: withdraw first, then next (mockup order) ---------- */
#host-controls { margin-top: 0.5rem; display: flex; align-items: center; justify-content: center; gap: 0.5rem; flex-wrap: wrap; }
#host-controls.hidden { display: none; }
#withdraw-btn { order: 1; }
#next-btn { order: 2; }
#skip-btn { order: 3; }

/* ---------- Board ---------- */
.board-wrap { margin-top: 0.75rem; border-radius: var(--radius); background: rgba(14, 4, 8, 0.55); border: 1px solid var(--line2); padding: 0.375rem; }
.board { display: grid; grid-template-columns: repeat(5, 1fr); gap: 0.375rem; }
@media (min-width: 640px) { .board { gap: 0.625rem; } .board-wrap { padding: 0.625rem; } }
.bcard {
  position: relative;
  aspect-ratio: 4 / 3;
  border-radius: 10px;
  border: 1px solid rgba(214, 176, 108, 0.28);
  overflow: hidden;
  padding: 0;
  width: 100%;
  background: #160509;
  transition: none;
}
button.bcard { cursor: pointer; }
button.bcard:disabled { cursor: default; }
.bcard.face-down {
  display: flex; align-items: center; justify-content: center;
  background: #1a060d;
  border-color: rgba(210, 171, 104, 0.4);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.14), inset 0 -8px 14px rgba(0, 0, 0, 0.45), 0 8px 16px rgba(0, 0, 0, 0.35);
  transition: transform .15s ease, filter .15s ease;
}
button.bcard.face-down:not(:disabled):hover { transform: translateY(-2px); filter: brightness(1.5); }
/* The number rides over the card-back art on a dark radial disc,
   so it stays legible on the ornate red/gold back. */
.bcard .num {
  position: relative; z-index: 2;
  display: flex; align-items: center; justify-content: center;
  width: 2.1rem; height: 2.1rem; border-radius: 50%;
  background: radial-gradient(circle, rgba(0, 0, 0, 0.78) 0 55%, rgba(0, 0, 0, 0.35) 75%, transparent 100%);
  font-family: var(--font-lat); font-size: 1.25rem; font-weight: 700; color: #ecd29a;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.7);
}
@media (min-width: 640px) { .bcard .num { font-size: 1.5rem; } }
.bcard img.art { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; object-position: center 20%; }
/* Revealed-card art fades in on load (art-ok) and falls back to the
   number (art-num) on error — never a blank card: every handler
   resolves one way or the other. */
.bcard img.art, .guide-item img, .badge-img { opacity: 0; transition: opacity .25s ease; }
.bcard img.art.art-ok, .guide-item img.art-ok, .badge-img.art-ok { opacity: 1; }
.bcard img.art.art-missing, .guide-item img.art-missing, .badge-img.art-missing { display: none; }
.art-num {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  font-family: var(--font-lat); font-size: 1.25rem; font-weight: 700; color: var(--gold2);
}
/* v9: the card's name at its foot, and its gang's colour as a 4px
   bar along the bottom edge (mockup .c.up). */
.card-lab {
  position: absolute; left: 0; right: 0; bottom: 5px; z-index: 3;
  text-align: center; font-size: 10px; font-weight: 800; color: #fff;
  text-shadow: 0 1px 3px #000, 0 0 6px rgba(0, 0, 0, 0.8);
  pointer-events: none;
}
.bcard:not(.face-down)::after {
  content: ""; position: absolute; left: 0; right: 0; bottom: 0; height: 4px;
  background: var(--tc, transparent); z-index: 3;
}
.bcard.killed { opacity: .5; filter: grayscale(1); }
/* While a target must be chosen, every non-selectable card drops to
   ~35% opacity, heavily desaturated and darkened, so the available
   targets stand out at a glance. */
.bcard.dimmed { opacity: .35; filter: saturate(.3) brightness(.55); }
/* The revealed boss of an eliminated gang: a boss is never
   killed, so his card is withdrawn from play and greyed out as
   a loser instead of carrying the «مقتول» stamp. */
.bcard.boss-out { opacity: .5; filter: grayscale(1); }
.bars {
  pointer-events: none; position: absolute; inset: 0; z-index: 2;
  background:
    linear-gradient(0deg, rgba(148, 163, 184, .95) 0 4px, transparent 4px calc(100% - 4px), rgba(148, 163, 184, .95) calc(100% - 4px)),
    repeating-linear-gradient(90deg, rgba(10, 10, 20, .12) 0 8px, rgba(203, 213, 225, .9) 8px 11px, rgba(71, 85, 105, .95) 11px 12px),
    rgba(127, 29, 29, .16);
}
.stamp-wrap { pointer-events: none; position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; z-index: 4; }
.stamp {
  font-family: var(--font-display);
  transform: rotate(-18deg);
  border: 3px solid #ef4444;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.4);
  padding: 0.1rem 0.6rem;
  font-size: 0.85rem; font-weight: 900; color: #f87171;
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.85);
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.5);
}
.boss-crown { position: absolute; top: 4px; inset-inline-end: 4px; width: 20px; height: 20px; border-radius: 999px; background: rgba(0, 0, 0, 0.45); display: flex; align-items: center; justify-content: center; z-index: 4; }

@keyframes flipIn { from { transform: rotateY(90deg); opacity: 0.4; } to { transform: rotateY(0deg); opacity: 1; } }
.card-flip { animation: flipIn 0.1s ease-out; }
@keyframes pulseGlow { 0%, 100% { box-shadow: 0 0 0 0 rgba(210, 171, 104, 0.55); } 50% { box-shadow: 0 0 0 7px rgba(210, 171, 104, 0); } }
@keyframes targetPulse {
  0%, 100% { box-shadow: 0 0 0 2px #d2ab68, 0 0 12px rgba(210, 171, 104, 0.6); filter: brightness(1.08); }
  50% { box-shadow: 0 0 0 3px #ecd29a, 0 0 24px rgba(210, 171, 104, 0.95); filter: brightness(1.25); }
}
/* Selectable targets stay fully bright with a thick glowing gold
   border and a gentle pulse — the opposite of .dimmed above. */
.target-glow {
  animation: targetPulse 1s ease-in-out infinite;
  border: 2px solid #d2ab68 !important;
  box-shadow: 0 0 0 2px #d2ab68, 0 0 18px rgba(210, 171, 104, 0.8);
  filter: brightness(1.15);
  position: relative; z-index: 1;
  cursor: pointer;
}
@keyframes winnerPop { 0% { transform: scale(0.85); opacity: 0; } 60% { transform: scale(1.04); } 100% { transform: scale(1); opacity: 1; } }
.winner-pop { animation: winnerPop 0.5s ease-out; }
@keyframes badgeFloat { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-6px); } }
.badge-float { animation: badgeFloat 5s ease-in-out infinite; }
@media (prefers-reduced-motion: reduce) {
  .card-flip, .target-glow, .winner-pop, .badge-float { animation: none; }
  .btn-gold { transition: none; }
}

/* ---------- Bank ---------- */
.bank-wrap { margin-top: 0.75rem; }
.bank-panel { border: 1px solid var(--border); border-radius: var(--radius); padding: 0.5rem; background: linear-gradient(180deg, rgba(42, 14, 22, .72), rgba(14, 4, 8, .84)); color: var(--panel-text); box-shadow: 0 16px 32px rgba(0, 0, 0, 0.4); }
.bank-panel.unlocked { border-color: #d2ab68; background: linear-gradient(180deg, rgba(42, 14, 22, 0.85), rgba(14, 4, 8, 0.9)); box-shadow: 0 0 0 1px rgba(210, 171, 104, 0.35), 0 0 22px rgba(210, 171, 104, 0.25), 0 16px 32px rgba(0, 0, 0, 0.4); }
.bank-head { display: flex; align-items: center; justify-content: center; gap: 0.375rem; flex-wrap: wrap; }
.bank-head h3 { margin: 0; text-align: center; font-size: 0.9rem; font-weight: 700; }
#bank-status { font-size: 10px; font-weight: 700; }
.bank-grid { margin-top: 0.5rem; display: grid; grid-template-columns: repeat(3, 1fr); gap: 0.375rem; }
.bank-grid .bcard { aspect-ratio: 3 / 2; }
@media (min-width: 640px) { .bank-grid { gap: 0.625rem; } }
.bank-num {
  position: absolute; bottom: 4px; inset-inline-start: 4px; z-index: 3;
  width: 24px; height: 24px; border-radius: 999px;
  border: 1px solid rgba(210, 171, 104, 0.55);
  background: rgba(10, 10, 25, 0.72);
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-lat); font-size: 13px; font-weight: 700; color: #fff;
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.8);
}
.bank-lock { position: absolute; top: 4px; inset-inline-end: 4px; width: 24px; height: 24px; border-radius: 999px; background: rgba(0, 0, 0, 0.55); color: #e4e4e7; display: flex; align-items: center; justify-content: center; z-index: 3; }

/* ---------- Viewer panel (v9 screen 9, viewers only) ---------- */
.viewer-panel { margin-top: 0.75rem; }
.viewer-panel > .label { margin: 0.75rem 0 0; font-size: 0.75rem; font-weight: 700; color: var(--mut); }
.viewer-hero {
  display: flex; gap: 0.75rem; padding: 0.75rem;
  border: 1px solid var(--line); border-radius: 16px;
  background: linear-gradient(180deg, rgba(42, 14, 22, .72), rgba(14, 4, 8, .84));
}
.viewer-hero-art { position: relative; width: 96px; height: 128px; flex-shrink: 0; border-radius: 12px; overflow: hidden; border: 1px solid var(--line); }
.viewer-hero-art img { width: 100%; height: 100%; object-fit: cover; object-position: center 20%; }
.viewer-hero-text { min-width: 0; }
.viewer-hero-text .label { margin: 0; font-size: 0.72rem; font-weight: 700; color: var(--mut); }
.viewer-hero-title { margin: 0.25rem 0 0; font-family: var(--font-display); font-size: 1.15rem; font-weight: 700; line-height: 1.4; color: var(--cream); }
.viewer-hero-sub { margin: 0.3rem 0 0; font-size: 0.8rem; line-height: 1.6; color: var(--mut); }
.viewer-progress { margin-top: 0.75rem; display: grid; gap: 0.4rem; }
.vrow { display: flex; align-items: center; gap: 0.5rem; padding: 0.4rem 0.6rem; border: 1px solid var(--line2); border-radius: 12px; background: rgba(9, 3, 5, 0.5); }
.vname { font-size: 0.85rem; font-weight: 800; min-width: 3.5rem; }
.vsegs { display: flex; gap: 3px; flex: 1; }
.vsegs .p { flex: 1; height: 6px; border-radius: 3px; background: rgba(239, 229, 216, 0.14); }
.vsegs .p.on { background: var(--tc); }
.vcount { font-size: 0.72rem; font-weight: 700; color: var(--mut); white-space: nowrap; }
.mini-board { display: grid; grid-template-columns: repeat(10, 1fr); gap: 3px; margin-top: 0.4rem; }
.mini-cell { position: relative; aspect-ratio: 4 / 3; border-radius: 4px; overflow: hidden; background: #160509; border: 1px solid rgba(214, 176, 108, 0.18); display: flex; align-items: center; justify-content: center; }
.mini-cell.down b { font-family: var(--font-lat); font-size: 9px; font-weight: 700; color: rgba(236, 210, 154, 0.75); }
.mini-cell.up img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; object-position: center 20%; }
.mini-cell.up::after { content: ""; position: absolute; left: 0; right: 0; bottom: 0; height: 2px; background: var(--tc, transparent); }
.viewer-moves { margin-top: 0.4rem; display: grid; gap: 0.35rem; }
.vmove { padding: 0.45rem 0.6rem; border-inline-start: 2px solid var(--gold); border-radius: 8px; background: rgba(9, 3, 5, 0.5); font-size: 0.82rem; line-height: 1.6; color: var(--cream); }

/* ---------- End-screen standings ---------- */
.standings { margin-top: 0.9rem; display: grid; gap: 0.35rem; text-align: start; }
.standing-row { display: flex; align-items: center; gap: 0.5rem; padding: 0.4rem 0.6rem; border-radius: 12px; background: rgba(239, 229, 216, 0.06); border: 1px solid var(--line2); }
.standing-name { font-size: 0.9rem; font-weight: 800; }
.standing-result { margin-inline-start: auto; font-size: 0.85rem; font-weight: 800; }
.standing-result.won { color: #6fbf87; }
.standing-result.lost { color: rgba(239, 229, 216, 0.55); }

/* ---------- Guide popup ---------- */
.overlay { position: fixed; inset: 0; z-index: 50; background: rgba(0, 0, 0, 0.7); display: flex; align-items: flex-end; justify-content: center; padding: 0.75rem; }
@media (min-width: 640px) { .overlay { align-items: center; } }
.dialog { max-height: 85vh; width: 100%; max-width: 32rem; overflow-y: auto; background: linear-gradient(180deg, rgba(42, 14, 22, 0.95), rgba(14, 4, 8, 0.97)); color: var(--panel-text); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem; box-shadow: 0 24px 48px rgba(0, 0, 0, 0.5); }
.guide-grid { display: grid; grid-template-columns: 1fr; gap: 0.5rem; }
@media (min-width: 640px) { .guide-grid { grid-template-columns: 1fr 1fr; } }
.guide-item { display: flex; gap: 0.75rem; border: 1px solid var(--border); border-radius: 12px; padding: 0.75rem; background: rgba(14, 4, 8, 0.6); }
.guide-art { position: relative; width: 64px; height: 84px; flex-shrink: 0; border-radius: 10px; overflow: hidden; border: 1px solid var(--line2); }
.guide-art img { width: 100%; height: 100%; object-fit: cover; object-position: center 20%; }
.guide-item p { margin: 0; }
.guide-item .gname { font-family: var(--font-display); font-size: 0.9rem; font-weight: 700; }
.guide-item .gdesc { margin-top: 0.15rem; font-size: 0.75rem; line-height: 1.6; color: var(--dim); }

.badge-img { border-radius: 26%; object-fit: cover; flex-shrink: 0; }
.chip { border-radius: 999px; padding: 0.25rem 0.75rem; font-size: 0.75rem; font-weight: 700; color: #fff; box-shadow: 0 8px 16px rgba(0, 0, 0, 0.3); display: inline-flex; align-items: center; gap: 0.375rem; }
.chip-live { background: linear-gradient(270deg, rgba(210, 171, 104, 0.35), rgba(14, 4, 8, 0.7)); border: 1px solid var(--line); }
#viewer-count-num.stale { opacity: .55; }
.live-dot { display: inline-block; width: 8px; height: 8px; border-radius: 999px; background: #fff; animation: pulseGlow 1.4s infinite; }
.code-text { font-family: var(--font-lat); letter-spacing: 0.15em; color: var(--cream); font-size: 0.9rem; }
.resume-banner .code-text, .glass .code-text, .panel .code-text, .panel-flat .code-text { color: var(--gold2); }
.save-note { text-align: center; font-size: 0.75rem; font-weight: 700; color: #fca5a5; margin-top: 0.5rem; }

/* ---------- Offline banner ----------
   Fixed at the very top of the page, OUTSIDE every app screen,
   so it shows over home / login / admin / game / wait alike.
   It is out of flow (position: fixed), so it never pushes the
   game layout; z-index 90 keeps it above the guide popup (50)
   and the pull-to-refresh chip (80). Shown the moment the
   browser reports `offline` (or the page loads offline) and
   hidden the moment `online` fires. */
#offline-banner {
  position: fixed; top: 0; left: 0; right: 0; z-index: 90;
  background: #6E1420; color: #fff;
  text-align: center; font-size: 0.8rem; font-weight: 700; line-height: 1.5;
  padding: 0.45rem 0.75rem;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.35);
  pointer-events: none;
}

/* ---------- Resume last game banner ---------- */
.resume-banner {
  margin-top: 1rem;
  border: 2px solid rgba(210, 171, 104, 0.55);
  border-radius: var(--radius);
  background: linear-gradient(180deg, rgba(42, 14, 22, 0.72), rgba(14, 4, 8, 0.84));
  color: var(--panel-text);
  padding: 1rem 1.1rem;
  box-shadow: 0 18px 36px rgba(0, 0, 0, 0.4), 0 0 0 4px rgba(210, 171, 104, 0.1);
  text-align: center;
}
.resume-banner .resume-title { margin: 0; font-size: 1.15rem; font-weight: 700; color: var(--gold2); }
.resume-banner .resume-text { margin: 0.5rem auto 0; font-size: 0.88rem; line-height: 1.7; max-width: 30rem; color: var(--mut); }
.resume-banner .resume-code { margin: 0.65rem 0 0; font-size: 0.85rem; font-weight: 700; }
.resume-banner .resume-actions { margin-top: 0.85rem; display: flex; flex-wrap: wrap; gap: 0.5rem; justify-content: center; }
.resume-banner .resume-btn { border-radius: 999px; padding: 0.75rem 1.4rem; font-size: 1rem; font-weight: 800; min-width: 13rem; }
.resume-banner .resume-error { margin: 0.6rem 0 0; }

/* ---------- Game screen top ----------
   Row 1 is a 1fr/auto/1fr grid, so the brand sits exactly in
   the middle of the bar whatever the guide button's width, with
   the guide button at one end and a balancing spacer at the other.
   Row 2 packs the watch code, viewer counter and the copy/exit
   buttons side by side in wrapping horizontal rows instead of
   stacking them vertically, keeping the whole header short. */
.game-brand { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 0.5rem; padding-top: 0.375rem; }
.game-brand .guide-slot { justify-self: start; }
.game-brand .brand-sm { justify-self: center; }
.game-brand #guide-btn { border-radius: 999px; padding: 0.4rem 0.85rem; font-size: 0.72rem; font-weight: 800; white-space: nowrap; }
.game-meta { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 0.375rem; margin-top: 0.375rem; }
.game-meta .btn-ghost { min-height: 2rem; padding: 0.3rem 0.7rem; font-size: 0.72rem; white-space: nowrap; }
.game-meta .chip { min-height: 2rem; padding: 0.3rem 0.7rem; font-size: 0.72rem; white-space: nowrap; }
.game-meta #role-chip:empty { display: none; }
#viewer-names { font-size: 0.75rem; font-weight: 700; color: var(--dim); }
.code-pill {
  display: inline-flex; align-items: center; gap: 0.3rem;
  min-height: 2rem; border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(9, 3, 5, 0.55);
  padding: 0.3rem 0.7rem;
  font-size: 0.72rem; font-weight: 700; color: var(--mut);
  white-space: nowrap;
}
.code-pill .code-text { font-size: 0.82rem; color: var(--gold2); }

/* ---------- Pull-to-refresh (Facebook style) ----------
   The browser's own pull-to-refresh is disabled above
   (overscroll-behavior-y: none) and replaced by this custom
   one: dragging down from the very top pulls the visible
   screen down with the finger while this spinner chip is
   revealed above it; releasing past the threshold re-fetches
   the live data in place (no page reload, no white flash),
   then the screen springs smoothly back to the top. */
#ptr {
  position: fixed; top: 0; left: 50%; z-index: 80;
  width: 42px; height: 42px; margin-left: -21px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.35);
  display: flex; align-items: center; justify-content: center;
  opacity: 0; pointer-events: none;
  transform: translateY(-56px);
}
.ptr-spinner {
  width: 22px; height: 22px; border-radius: 50%;
  border: 3px solid rgba(38, 75, 111, 0.25);
  border-top-color: #264B6F;
}
#ptr.spinning .ptr-spinner { animation: ptrSpin 0.7s linear infinite; }
@keyframes ptrSpin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
  #ptr.spinning .ptr-spinner { animation-duration: 1.6s; }
}
/* Language switch: the page CONTENT crossfades — it eases down
   to a soft ghost of itself while the language and direction
   swap underneath, then eases back up in the new language. No
   cover flashes over the page and no spinner appears, so the
   switch reads as one calm fade rather than a blink; the
   wrapper also swallows taps for the fraction of a second the
   layout is mid-flip. */
#lang-fade { transition: opacity 0.16s ease; }
#lang-fade.fading { opacity: 0.12; pointer-events: none; }
#lang-fade.returning { transition: opacity 0.3s ease; }
@media (prefers-reduced-motion: reduce) {
  #lang-fade, #lang-fade.returning { transition: none; }
}
