/* Shared styles for every page: tokens, reset, buttons, header. */

:root {
  --bg: #140b29;            /* deep night purple */
  --bg-2: #1f1142;
  --surface: #2a1856;
  --surface-2: #3a2378;
  --border: rgba(255, 255, 255, 0.1);
  --text: #ffffff;
  --muted: #b8a8e3;

  --gold: #ffc53d;          /* main call to action */
  --gold-dark: #d98a00;
  --on-gold: #3a1d00;
  --violet: #8b5cf6;
  --violet-dark: #5b30c9;
  --danger: #ff4d6d;

  --p-red: #ff4d5e;
  --p-blue: #3fa2ff;
  --p-yellow: #ffcf33;
  --p-green: #35d07f;

  --radius: 16px;
  --radius-lg: 26px;
  --shadow: 0 14px 34px rgba(5, 0, 20, 0.55);

  --font-display: "Baloo Bhaijaan 2", "Cairo", system-ui, sans-serif;
  --font-body: "Cairo", system-ui, -apple-system, "Segoe UI", sans-serif;

  /* Faint card-suit pattern used as a game-table texture. */
  --suits: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='120' height='120' fill='white' fill-opacity='0.035' font-size='22' font-family='Arial'%3E%3Ctext x='10' y='30'%3E%E2%99%A0%3C/text%3E%3Ctext x='70' y='40'%3E%E2%99%A5%3C/text%3E%3Ctext x='30' y='95'%3E%E2%99%A6%3C/text%3E%3Ctext x='88' y='105'%3E%E2%99%A3%3C/text%3E%3C/svg%3E");
}

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 17px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  /* It's a game: taps and drags shouldn't select text or pop up the
     long-press menu. Text fields stay selectable. */
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}
input, textarea, [contenteditable] { -webkit-user-select: text; user-select: text; }

img, svg { display: block; max-width: 100%; }
a { color: inherit; }
h1, h2, h3 { font-family: var(--font-display); line-height: 1.15; margin: 0; }
p { margin: 0; }
[hidden] { display: none !important; }

.container {
  width: 100%;
  max-width: 1240px;
  margin-inline: auto;
  padding-inline: 20px;
}

.muted { color: var(--muted); }

:focus-visible {
  outline: 3px solid var(--gold);
  outline-offset: 3px;
  border-radius: 8px;
}

/* Buttons: chunky, game-style, with a solid bottom edge. */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 20px;
  border-radius: 999px;
  border: 0;
  font: 800 16px/1.2 var(--font-display);
  letter-spacing: 0.3px;
  text-decoration: none;
  cursor: pointer;
  transition: transform 0.12s ease, filter 0.12s ease, box-shadow 0.12s ease;
  white-space: nowrap;
}
.btn:hover { transform: translateY(-2px); filter: brightness(1.06); }
.btn:active { transform: translateY(3px); box-shadow: none; }

.btn-primary {
  background: linear-gradient(180deg, #ffd96b, var(--gold));
  color: var(--on-gold);
  box-shadow: 0 4px 0 var(--gold-dark), inset 0 2px 0 rgba(255, 255, 255, 0.5);
}

.btn-secondary {
  background: linear-gradient(180deg, #a57dff, var(--violet));
  color: #fff;
  box-shadow: 0 4px 0 var(--violet-dark), inset 0 2px 0 rgba(255, 255, 255, 0.3);
}

.btn-ghost {
  background: transparent;
  color: var(--text);
}
.btn-ghost:hover { background: rgba(255, 255, 255, 0.08); }

.btn-sm { padding: 8px 16px; font-size: 15px; }
.btn-lg { padding: 14px 30px; font-size: 19px; }

/* --- Top bar (landing, lobby and the account pages) ---
   Logo on the left, the main tabs in a pill in the middle, your coins and
   menu on the right. On phones the tabs become a tab bar at the bottom. */
.topbar {
  position: sticky;
  top: 0;
  z-index: 60;
  flex: none;
  background: linear-gradient(180deg, rgba(28, 15, 58, 0.92), rgba(20, 11, 41, 0.78));
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  box-shadow: 0 10px 30px rgba(5, 0, 20, 0.35);
}
.topbar::after { /* thin glowing line under the bar */
  content: "";
  position: absolute;
  inset: auto 0 -1px;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(255, 197, 61, 0.55), rgba(178, 60, 255, 0.55), transparent);
}
.topbar-inner {
  display: flex;
  align-items: center;
  gap: 16px;
  width: 100%;
  max-width: 1240px;
  height: 66px;
  margin-inline: auto;
  padding-inline: clamp(14px, 3vw, 28px);
}
.topbar .brand { flex: none; gap: 10px; }
.topbar .brand img { width: 38px; height: 38px; filter: drop-shadow(0 3px 6px rgba(0, 0, 0, 0.45)); }
.topbar .brand-name {
  font-size: 24px;
  background: linear-gradient(180deg, #fff7d1, #ffc53d);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 2px 0 rgba(138, 61, 0, 0.8));
}

.topbar .nav-links {
  margin-inline: auto;
  gap: 4px;
  padding: 5px;
  border-radius: 999px;
  background: rgba(10, 4, 30, 0.55);
  border: 1px solid rgba(255, 255, 255, 0.08);
  box-shadow: inset 0 2px 6px rgba(0, 0, 0, 0.35);
}
.topbar .nav-link {
  gap: 7px;
  padding: 8px 16px;
  border: 0;
  background: transparent;
  color: var(--muted);
  transition: color 0.15s ease, background 0.15s ease;
}
.topbar .nav-link:hover { color: #fff; background: rgba(255, 255, 255, 0.07); }
.topbar .nav-link svg { color: currentColor; }
.topbar .nav-link[aria-current="page"] {
  background: linear-gradient(180deg, #ffd96b, var(--gold));
  color: var(--on-gold);
  box-shadow: 0 3px 0 var(--gold-dark), 0 0 16px rgba(255, 197, 61, 0.35);
}
.topbar-end { flex: none; display: flex; align-items: center; gap: 10px; }
.nav-coins:empty { display: none; }
.topbar .coin-chip { padding-block: 6px; font-size: 17px; }
.topbar .nav-trigger { background: rgba(10, 4, 30, 0.55); }

/* Phones: logo, coins and menu on top; the tabs in a bar at the bottom. */
@media (max-width: 760px) {
  /* A blurred bar would trap the fixed tab bar inside it, so phones get a solid one. */
  .topbar { backdrop-filter: none; -webkit-backdrop-filter: none; background: linear-gradient(180deg, #23124a, #1a0d38); }
  .topbar-inner { height: 58px; gap: 10px; }
  .topbar-end { margin-inline-start: auto; }
  .topbar .brand-name { font-size: 21px; }
  .topbar .nav-links {
    position: fixed;
    z-index: 70;
    left: 0;
    right: 0;
    bottom: 0;
    display: grid;
    grid-auto-flow: column;
    grid-auto-columns: 1fr;
    gap: 0;
    margin: 0;
    padding: 6px 6px max(6px, env(safe-area-inset-bottom));
    border-radius: 22px 22px 0 0;
    background: linear-gradient(180deg, rgba(36, 19, 74, 0.97), rgba(20, 11, 41, 0.98));
    border: 0;
    border-top: 1px solid rgba(255, 255, 255, 0.12);
    box-shadow: 0 -10px 30px rgba(5, 0, 20, 0.5);
  }
  .topbar .nav-link {
    flex-direction: column;
    gap: 2px;
    padding: 6px 2px;
    border-radius: 14px;
    font-size: 11px;
  }
  .topbar .nav-link span { display: block; }
  .topbar .nav-link svg { width: 24px; height: 24px; }
  .topbar .nav-link[aria-current="page"] {
    background: none;
    color: var(--gold);
    box-shadow: none;
  }
  .topbar .nav-link[aria-current="page"]::before { /* a glow pill behind the active icon */
    content: "";
    position: absolute;
    top: 3px;
    left: 50%;
    width: 46px;
    height: 32px;
    margin-left: -23px;
    border-radius: 12px;
    background: rgba(255, 197, 61, 0.16);
  }
  .topbar .nav-badge { top: 2px; inset-inline-end: calc(50% - 22px); }
  .topbar-login { display: none; } /* it's in the menu */
  body.has-tabbar { padding-bottom: calc(66px + env(safe-area-inset-bottom)); }
}

/* Header */
.site-header {
  position: sticky;
  top: 0;
  z-index: 50;
  background: rgba(20, 11, 41, 0.7);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}

.header-inner {
  display: flex;
  align-items: center;
  gap: 24px;
  height: 64px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
}
.brand-name {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 24px;
  letter-spacing: 0.3px;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-inline-start: auto;
}

.lang-toggle {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 999px;
  padding: 6px 14px;
  font: 700 15px/1.2 var(--font-body);
  cursor: pointer;
}
.lang-toggle:hover { background: rgba(255, 255, 255, 0.12); }

/* Full-screen game screens (lobby, login, sign up). */
body.game-screen {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  background:
    radial-gradient(ellipse 50% 45% at 50% 55%, rgba(139, 92, 246, 0.35), transparent 70%),
    radial-gradient(ellipse 40% 40% at 0% 0%, rgba(255, 79, 163, 0.18), transparent 70%),
    radial-gradient(ellipse 40% 40% at 100% 100%, rgba(63, 162, 255, 0.16), transparent 70%),
    var(--suits),
    var(--bg);
}

/* Top bar on game screens */
.hud {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px clamp(14px, 3vw, 28px);
}

.hud-btn {
  flex: none;
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
  border-radius: 14px;
  background: linear-gradient(180deg, #4a2d93, #33196f);
  box-shadow: 0 4px 0 #1d0c46, inset 0 2px 0 rgba(255, 255, 255, 0.15);
  color: #fff;
  transition: transform 0.12s ease;
}
.hud-btn:hover { transform: translateY(-2px); }
.hud-btn svg { width: 22px; height: 22px; }

/* Pop-up message at the bottom of game screens (errors by default) */
.toast {
  position: fixed;
  inset-inline: 0;
  bottom: 24px;
  z-index: 100;
  width: fit-content;
  max-width: calc(100% - 32px);
  margin-inline: auto;
  padding: 12px 22px;
  border-radius: 999px;
  background: linear-gradient(180deg, #ff6b85, var(--danger));
  color: #fff;
  font-weight: 700;
  text-align: center;
  box-shadow: 0 5px 0 #b3203d, var(--shadow);
  animation: toast-in 0.3s cubic-bezier(0.3, 1.5, 0.6, 1);
}
.toast.is-info {
  background: linear-gradient(180deg, #4fe39a, var(--p-green));
  color: #063a20;
  box-shadow: 0 5px 0 #1b8a50, var(--shadow);
}
@keyframes toast-in { from { opacity: 0; transform: translateY(20px) scale(0.9); } }

/* Dialog over a dimmed screen (room and game pages) */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: grid;
  place-items: center;
  padding: 24px 16px;
  background: rgba(8, 3, 22, 0.72);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}
.dialog {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 14px;
  width: 100%;
  max-width: 380px;
  padding: 46px 26px 24px;
  border-radius: 28px;
  background:
    radial-gradient(ellipse 90% 40% at 50% 0%, rgba(255, 255, 255, 0.14), transparent 70%),
    linear-gradient(180deg, #3a2378, #241250);
  border: 2px solid rgba(255, 255, 255, 0.16);
  box-shadow: 0 10px 0 #120634, 0 30px 70px rgba(139, 92, 246, 0.35);
  text-align: center;
  animation: toast-in 0.3s cubic-bezier(0.3, 1.5, 0.6, 1);
}
.dialog h2 { font-size: 28px; font-weight: 800; }
.dialog .muted b { color: #fff; letter-spacing: 2px; }
.dialog .btn-start { font-size: 20px; padding: 14px 20px; }
.dialog-link { color: var(--muted); font-weight: 700; text-decoration: none; }
.dialog-link:hover { color: #fff; text-decoration: underline; }

.emblem {
  position: absolute;
  top: -32px;
  left: 50%;
  display: grid;
  place-items: center;
  width: 64px;
  height: 64px;
  margin-left: -32px;
  /* The logo; the "J" text inside stays for screen readers only. */
  background: url(/logo.svg) center / contain no-repeat;
  filter: drop-shadow(0 8px 14px rgba(0, 0, 0, 0.5));
  color: transparent;
  font-size: 0;
}

/* Gold coin balance */
.coin-chip {
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 12px 4px 5px;
  border-radius: 999px;
  background: rgba(10, 4, 30, 0.6);
  border: 1px solid rgba(255, 197, 61, 0.45);
  color: var(--gold);
  font: 800 16px/1.2 var(--font-display);
  text-decoration: none;
}
[dir="rtl"] .coin-chip { padding: 4px 5px 4px 12px; }
.coin { width: 24px; height: 24px; flex: none; }
.coin-sm { width: 18px; height: 18px; }

/* Segmented picker (table size, team mode) */
.seg {
  display: flex;
  padding: 3px;
  border-radius: 999px;
  background: rgba(10, 4, 30, 0.6);
  border: 1px solid var(--border);
}
.seg-btn {
  padding: 6px 14px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  font: 800 15px/1.2 var(--font-display);
  cursor: pointer;
  white-space: nowrap;
}
.seg-btn:hover { color: #fff; }
.seg-btn[aria-pressed="true"] {
  background: linear-gradient(180deg, #ffd96b, var(--gold));
  color: var(--on-gold);
  box-shadow: 0 2px 0 var(--gold-dark);
}
.seg-btn[disabled] { cursor: progress; }
/* Navbar buttons: Shop, Leaderboard, coins */
.nav-links { display: flex; align-items: center; gap: 6px; flex: none; }
.nav-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 13px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--border);
  color: #fff;
  font: 800 15px/1.2 var(--font-display);
  text-decoration: none;
  white-space: nowrap;
}
.nav-link:hover { background: rgba(255, 255, 255, 0.12); }
.nav-link[aria-current="page"] { border-color: rgba(255, 197, 61, 0.6); color: var(--gold); }
.nav-link svg { width: 18px; height: 18px; flex: none; color: var(--gold); }
.nav-link { position: relative; }
.nav-badge {
  position: absolute;
  top: -5px;
  inset-inline-end: -5px;
  display: grid;
  place-items: center;
  min-width: 18px;
  height: 18px;
  padding: 0 4px;
  border-radius: 999px;
  background: var(--danger);
  color: #fff;
  font: 800 11px/1 var(--font-body);
  font-style: normal;
  box-shadow: 0 0 0 2px var(--bg);
}

/* Invite pop-ups (bottom of the screen, newest on top) */
.invite-stack {
  position: fixed;
  z-index: 120;
  left: 50%;
  bottom: max(16px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: min(420px, calc(100% - 24px));
}
.invite-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 20px;
  background: linear-gradient(180deg, #4a2d93, #2b1660);
  border: 2px solid var(--gold);
  box-shadow: 0 8px 0 #120634, 0 18px 40px rgba(5, 0, 20, 0.6), 0 0 24px rgba(255, 197, 61, 0.3);
  animation: toast-in 0.3s cubic-bezier(0.3, 1.5, 0.6, 1);
}
.invite-card .chip-avatar { width: 42px; height: 42px; }
.invite-text { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.25; }
.invite-text b { font: 800 16px var(--font-display); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.invite-text span { font-size: 14px; color: var(--muted); font-weight: 700; }
.invite-close {
  flex: none;
  width: 30px;
  height: 30px;
  border: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
  cursor: pointer;
}

/* Narrow screens: icons only */
@media (max-width: 760px) {
  .nav-link { padding: 7px; }
  .nav-link span { display: none; }
}
@media (max-width: 420px) {
  .hide-xs { display: none; }
}

/* Navbar menu: avatar + name (or ☰) opening a dropdown */
.nav-menu { position: relative; flex: none; }
.nav-trigger {
  display: flex;
  align-items: center;
  gap: 8px;
  max-width: 220px;
  padding: 4px 10px 4px 4px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--border);
  color: #fff;
  font: 800 15px/1.2 var(--font-display);
  cursor: pointer;
}
[dir="rtl"] .nav-trigger { padding: 4px 4px 4px 10px; }
.nav-trigger:hover,
.nav-menu.is-open .nav-trigger { background: rgba(255, 255, 255, 0.12); }
.nav-trigger.is-guest { padding: 8px; }
.nav-trigger svg { width: 22px; height: 22px; flex: none; }
.nav-trigger .nav-caret { width: 16px; height: 16px; color: var(--muted); transition: transform 0.15s ease; }
.nav-menu.is-open .nav-caret { transform: rotate(180deg); }
.nav-dropdown {
  position: absolute;
  top: calc(100% + 8px);
  inset-inline-end: 0;
  z-index: 95;
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 230px;
  padding: 8px;
  border-radius: 20px;
  background: linear-gradient(180deg, #3a2378, #241250);
  border: 2px solid rgba(255, 255, 255, 0.14);
  box-shadow: 0 8px 0 #120634, 0 24px 50px rgba(5, 0, 20, 0.6);
  animation: dd-in 0.16s ease-out;
}
.nav-dropdown[hidden] { display: none; }
@keyframes dd-in { from { opacity: 0; transform: translateY(-6px); } }
.nav-dropdown a,
.nav-dropdown button {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 10px 12px;
  border: 0;
  border-radius: 12px;
  background: none;
  color: #fff;
  font: 700 16px/1.2 var(--font-body);
  text-align: start;
  text-decoration: none;
  cursor: pointer;
}
.nav-dropdown a:hover,
.nav-dropdown button:hover { background: rgba(255, 255, 255, 0.09); }
.nav-dropdown a[aria-current="page"] { background: rgba(255, 197, 61, 0.14); color: var(--gold); }
.nav-dropdown svg { width: 20px; height: 20px; flex: none; color: var(--gold); }
.nav-dropdown .is-danger svg { color: #ff8a9c; }
.nav-dropdown .nav-lang b {
  margin-inline-start: auto;
  padding: 2px 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.1);
  font: 700 14px/1.4 var(--font-body);
}
.nav-dropdown hr { width: 100%; margin: 4px 0; border: 0; border-top: 1px solid rgba(255, 255, 255, 0.12); }
.nav-dd-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 6px 10px 10px;
  margin-bottom: 4px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.12);
}
.nav-dd-head b { font: 800 17px/1.2 var(--font-display); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
@media (max-width: 520px) {
  .nav-trigger .chip-name { display: none; }
  .nav-trigger { padding-inline-end: 6px; }
}
.chip-avatar {
  display: grid;
  place-items: center;
  font: 800 16px/1 var(--font-display);
  color: #fff;
  flex: none;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  overflow: hidden;
  background: radial-gradient(circle at 35% 30%, #fff 0, #fff 6%, var(--violet) 30%, #3b1d8f 90%);
  box-shadow: 0 0 0 2px var(--gold);
}
.chip-avatar img { width: 100%; height: 100%; object-fit: cover; }
.chip-name {
  max-width: 14ch;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 800;
}

@media (max-width: 520px) {
  .hide-sm { display: none; }
  .header-inner { gap: 12px; height: 58px; }
  .brand-name { font-size: 21px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}

/* Seat colours (same as the marbles on the board). Anything with
   data-color="<seat>" gets --c and --c-dark. */
[data-color="0"] { --c: #e23b3b; --c-dark: #8f1717; }
[data-color="1"] { --c: #2f7df2; --c-dark: #123f8f; }
[data-color="2"] { --c: #f4c21b; --c-dark: #9a7300; }
[data-color="3"] { --c: #2fae5f; --c-dark: #11612f; }
[data-color="4"] { --c: #9b5cf6; --c-dark: #4b1d9c; }
[data-color="5"] { --c: #ff8a1f; --c-dark: #a34a00; }
[data-color="6"] { --c: #22c7d6; --c-dark: #0b6b75; }
[data-color="7"] { --c: #ff5fa2; --c-dark: #a3195a; }

/* Very narrow phones: logo only in the top bar. */
@media (max-width: 360px) {
  .topbar .brand-name { display: none; }
}
