/* The home screen, as sketched: four icons across the top, the board between the live button
   and the league, two ways in to a friend's table, the friends, and four ways to play. It fits
   one screen and does not scroll. Loaded after style.css so these rules win. */
#screen-menu .menu-wrap {
  /* Fits one screen at 1x; at 1.3x font scale it scrolls rather than clips.
     The tab bar is fixed, so it stays in view either way. */
  overflow-x: hidden; overflow-y: auto; max-height: 100dvh; scrollbar-width: none; overscroll-behavior: contain;
  justify-content: flex-start; align-items: stretch;
  gap: clamp(6px, 1.4dvh, 14px); text-align: center;
  /* Clear of the Android status bar: the WebView draws under it and reports no inset. */
  padding: max(var(--sat, env(safe-area-inset-top, 0px)), 32px) 16px 8px;
}
body.has-tabbar #screen-menu .menu-wrap { padding-bottom: calc(var(--tabbar-h, 72px) + 10px); }

/* Row 1: profile · help · (space) · shop · settings */
#screen-menu .home-top { display: grid; grid-template-columns: auto auto 1fr auto; align-items: center; gap: 10px; width: 100%; }
#screen-menu .home-top .hud-corner { padding: 0; }
#screen-menu .home-top .hud-corner-label { display: none; }
#screen-menu .home-top .hud-corner-box { width: 46px; height: 46px; border-radius: 13px; }
#screen-menu .home-top .hud-avatar { width: 38px; height: 38px; }
#screen-menu .home-top .chip-help { width: 46px; height: 46px; border-radius: 50%; margin: 0; }
#screen-menu .home-top .shop-bar {
  justify-self: end; width: auto; height: 46px; margin: 0; padding: 0 14px; gap: 7px; border-radius: 13px;
}
#screen-menu .home-top .shop-bar .shop-ico { color: var(--brass); }
#screen-menu .home-top .shop-bar .coin-dot { display: none; }
#screen-menu .home-top .shop-bar-label { display: none; }
#screen-menu .home-top .shop-bar { padding: 0 12px; }
#screen-menu .home-top .shop-bar-new { display: none; }   /* no room for a word up here */


/* Row 2: live button · board · league */
#screen-menu .home-mid { display: grid; grid-template-columns: 74px 1fr 74px; align-items: center; gap: 8px; width: 100%; }
#screen-menu .home-mid .brand { margin: 0; }
#screen-menu .home-mid .brand-mark { display: block; width: clamp(64px, 11dvh, 104px); height: clamp(64px, 11dvh, 104px); }
#screen-menu .home-mid .brand .deva { font-size: clamp(18px, 2.8dvh, 24px); margin: 3px 0 0; }
#screen-menu .home-live {
  justify-self: start; display: grid; justify-items: center; gap: 3px; padding: 0; border: 0; background: none; color: var(--ink); cursor: pointer; font: inherit;
}
#screen-menu .home-live[hidden] { display: none; }
#screen-menu .home-live-ico { width: 46px; height: 46px; border-radius: 13px; display: grid; place-items: center; color: #ff8e8e; border: 1px solid var(--edge); background: linear-gradient(180deg, var(--surface), var(--surface-2)); }
#screen-menu .home-live-label { font-size: 11px; color: var(--ink-2); }
#screen-menu .home-live:disabled { opacity: .5; }
#screen-menu .home-mid .chip-league {
  justify-self: end; display: grid; justify-items: center; gap: 3px; width: 70px; padding: 8px 4px; border-radius: 13px; margin: 0;
  font-size: 11px; line-height: 1.15; text-align: center;
}
#screen-menu .home-mid .chip-league svg { width: 22px; height: 22px; }

/* Hidden on purpose: Nearby is on the Rooms screen, the league is the chip above, setup is in the
   computer-game picker, the table size is the badge on Play online, games in progress are on Turns. */
#screen-menu .table-size-caption, #screen-menu .seg-online, #screen-menu #opt-table-size,
#screen-menu .brand .tagline, #screen-menu #league-card, #screen-menu .menu-setup,
#screen-menu #async-games { display: none !important; }

#screen-menu .friend-play { margin: 0; }
#screen-menu .friend-play-title { display: block; margin-bottom: 5px; }
#screen-menu .friend-play-btn { min-height: 46px; }

#screen-menu .friends-strip { margin: 0; }
#screen-menu .friends-strip .async-games-title { margin: 0 0 4px; font-size: 12px; text-align: left; }
/* The strip scrolls sideways (style.css): family icons come first, then friends, however many there are. */
#screen-menu .friends-strip-row { overflow-x: auto; overflow-y: hidden; }

/* The four ways to play share whatever height is left. */
#screen-menu .mode-row.is-grid { flex: 1; min-height: 0; grid-template-rows: minmax(0, 1fr) minmax(0, 1fr) auto; grid-auto-rows: minmax(0, 1fr); gap: 10px; width: 100%; }
#screen-menu .mode-tile.is-big { min-height: 0; padding: 8px 8px; gap: 4px; justify-content: center; }
#screen-menu .mode-tile.is-big .mode-tile-ico { width: clamp(30px, 5.2dvh, 44px); height: clamp(30px, 5.2dvh, 44px); }
#screen-menu .mode-tile.is-big em { font-size: 12px; line-height: 1.2; }
#screen-menu .mode-tile .hero-badge { cursor: pointer; padding: 3px 9px; }
/* Older rules hide the logo and the tile captions below 800px; there is room for both now. */
#screen-menu .mode-tile.is-big em { display: block; }
#screen-menu .home-mid .brand .deva { display: block; }
@media (max-height: 560px) { #screen-menu .mode-tile.is-big em, #screen-menu .home-mid .brand .deva { display: none; } }
@media (max-height: 700px) { #screen-menu .friends-strip { display: none; } }

/* The family banner: gold, full width, right under the two ways to reach a friend. */
#screen-menu .home-family {
  display: flex; align-items: center; gap: 12px; width: 100%; padding: 10px 14px; cursor: pointer; text-align: left;
  border-radius: 16px; border: 1px solid rgba(230, 185, 79, .32); color: var(--ink); font: inherit;
  background: linear-gradient(100deg, rgba(246, 217, 138, .28), rgba(212, 160, 55, .12) 55%, rgba(0, 0, 0, .12));
  box-shadow: 0 0 0 1px rgba(246, 217, 138, .12) inset, 0 6px 16px rgba(0, 0, 0, .28);
}
#screen-menu .home-family:active { transform: scale(.98); }
#screen-menu .home-family-crest { width: 44px; height: 44px; border-radius: 12px; flex: none; display: grid; place-items: center; font-size: 26px; color: #e6b94f; background: none; }
#screen-menu .home-family-copy { display: grid; gap: 1px; flex: 1; min-width: 0; }
#screen-menu .home-family-copy b { font-size: 15.5px; color: #ffe6a0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#screen-menu .home-family-copy em { font-style: normal; font-size: 12px; color: var(--ink-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
/* Painted chevron instead of the text "›" (back.webp, mirrored to point forward). */
#screen-menu .home-family-go {
  width: 18px; height: 18px; flex: none; font-size: 0; color: transparent;
  background: url("../img/icons/back.webp") center / contain no-repeat; transform: scaleX(-1);
}
/* Only Play online carries the gold hairline; the other tiles sit borderless. */
#screen-menu .mode-tile:not(#btn-play-random), #screen-menu .mode-tile:not(#btn-play-random):hover { border-color: transparent; }
#screen-menu #btn-play-random { border-color: rgba(228, 184, 96, .55); }

/* ── Rooms: small cards, eight to a screen, the list scrolls for more ───────── */
#screen-rooms .scroller.rooms-screen {
  display: flex; flex-direction: column; gap: 10px; overflow: hidden; padding: 4px 16px 10px;
}
/* Half and half: the rooms on top (their own scroll), the families underneath. */
#screen-rooms .rooms-top { flex: 1 1 0; min-height: 0; overflow-y: auto; display: flex; flex-direction: column; gap: 10px; }
#screen-rooms .rooms-fams { flex: 0 0 auto; border-top: 1px solid var(--edge-soft); padding-top: 8px; }
#screen-rooms .rooms-fams .hint { margin: 2px 0 4px; font-size: 12px; }
#screen-rooms .rooms-fams .lf-row { padding: 6px 10px; }
#screen-rooms .rooms-fams .lf-row .crest-img { width: 40px; height: 40px; }
body.has-tabbar #screen-rooms .scroller.rooms-screen { padding-bottom: calc(var(--tabbar-h, 72px) + 10px); }
.rooms-actions { display: grid; grid-template-columns: 1.2fr 1fr; gap: 10px; flex: none; }
.rooms-actions .btn { min-height: 44px; white-space: nowrap; font-size: 14px; padding: 8px 10px; }
/* Four rows of two cards fit one screen; each row's height follows the screen so they still do on a short phone. */
#screen-rooms #rooms-list { display: grid; grid-template-columns: 1fr 1fr; grid-auto-rows: clamp(78px, 13.4dvh, 124px); gap: 8px; flex: none; }
#screen-rooms #rooms-list:empty { display: none; }
#screen-rooms .room-card { padding: 0; gap: 0; overflow: hidden; min-height: 0; border-radius: 12px; }
#screen-rooms .room-board { flex: 1; min-height: 0; aspect-ratio: auto; border: 0; border-radius: 0; background: rgba(0, 0, 0, .14); padding: 4px 8px; gap: 4px; }
/* "Ritu  Vs  ?" on one line. */
#screen-rooms .room-board.is-seats-2 { display: flex; align-items: center; justify-content: space-between; }
#screen-rooms .room-board.is-seats-2 .room-seat { padding: 0; background: none; border: 0; font-size: 13px; min-width: 0; }
#screen-rooms .room-board.is-seats-2 .room-seat:nth-of-type(1) { order: 1; flex: 1 1 auto; justify-content: flex-start; }
#screen-rooms .room-board.is-seats-2 .room-vs { order: 2; flex: none; }
#screen-rooms .room-board.is-seats-2 .room-seat:nth-of-type(2) { order: 3; flex: 1 1 auto; justify-content: flex-end; font-size: 17px; }
#screen-rooms .room-vs { position: static; transform: none; font-size: 11px; font-weight: 800; letter-spacing: .05em; color: var(--brass); padding: 1px 6px; border-radius: 7px; background: var(--surface-2); }
#screen-rooms .room-board.is-seats-3, #screen-rooms .room-board.is-seats-4 { grid-template-columns: 1fr 1fr; grid-template-rows: 1fr 1fr; }
#screen-rooms .room-board.is-seats-3 .room-seat, #screen-rooms .room-board.is-seats-4 .room-seat { font-size: 11px; padding: 0 2px; }
#screen-rooms .room-board.is-seats-3 .room-vs, #screen-rooms .room-board.is-seats-4 .room-vs { display: none; }
#screen-rooms .room-seat em { display: none; }       /* the BOT tag is in the footer's word, not repeated */
/* Footer: "Easy | Join", two halves. */
#screen-rooms .room-foot { display: grid; grid-template-columns: 1fr 1fr; gap: 0; border-top: 1px solid var(--edge); flex: none; }
#screen-rooms .room-tag { display: grid; place-items: center; padding: 6px 2px; font-size: 12px; font-weight: 700; color: var(--ink-2); border-right: 1px solid var(--edge); }
#screen-rooms .room-join { display: grid; place-items: center; border-radius: 0; padding: 6px 2px; font-size: 12px; }
.rooms-pager { display: none !important; }
#screen-rooms #rooms-empty { margin: auto; text-align: center; }

/* ── Pages instead of scrolling (js/pager.js) ─────────────────── */
.scroller.is-paged {
  display: block; overflow-x: auto; overflow-y: hidden; column-fill: auto; scrollbar-width: none;
  overscroll-behavior-x: contain; -webkit-overflow-scrolling: touch;
}
.scroller.is-paged::-webkit-scrollbar { display: none; }
/* Keep each card and panel whole on one page where it can fit. */
.scroller.is-paged .panel, .scroller.is-paged .shop-card, .scroller.is-paged .shop-row, .scroller.is-paged .shop-gift,
.scroller.is-paged .room-card, .scroller.is-paged li, .scroller.is-paged .async-game, .scroller.is-paged .friend-row,
.scroller.is-paged .fold, .scroller.is-paged details, .scroller.is-paged .setup-row, .scroller.is-paged h3 { break-inside: avoid; }
.scroller.is-paged h3, .scroller.is-paged h2 { break-after: avoid; }
/* The scroller itself clears the floating tab bar, so a one-page screen
   (pager bar hidden) no longer runs its last card under the bar. When the
   pager bar is showing, it sits between the two and carries the clearance. */
body.has-tabbar .scroller.is-paged, body.has-tabbar.is-offline .scroller.is-paged { padding-bottom: calc(var(--tabbar-h, 72px) + 8px); }
body.has-tabbar .scroller.is-paged:has(+ .pager-bar:not([hidden])) { padding-bottom: 8px; }
.pager-bar { display: flex; align-items: center; justify-content: center; gap: 16px; flex: none; min-height: 40px; padding: 2px 16px 4px; }
.pager-bar[hidden] { display: none; }
body.has-tabbar .pager-bar { margin-bottom: var(--tabbar-h, 72px); }
.pager-bar .icon-btn { width: 44px; height: 36px; font-size: 0; color: transparent; line-height: 1; position: relative; }
/* Painted chevrons in place of the text "‹" / "›"; forward is back.webp mirrored. */
.pager-bar .icon-btn::before {
  content: ""; position: absolute; inset: 0; margin: auto; width: 20px; height: 20px;
  background: url("../img/icons/back.webp") center / contain no-repeat;
}
.pager-bar .icon-btn[data-d="1"]::before { transform: scaleX(-1); }
.pager-bar .icon-btn:disabled { opacity: .3; }
/* Dots match the daily-spin track (css/spin.css .spin-track). */
.pager-dots { display: inline-flex; gap: 7px; }
.pager-dots i { width: 9px; height: 9px; border-radius: 50%; border: 1px solid var(--hair, rgba(228, 184, 96, .34)); background: rgba(0, 0, 0, .28); transition: background .15s, border-color .15s; }
.pager-dots i.is-on { background: linear-gradient(180deg, var(--gold-satin-hi, #f6dc9a), var(--gold-satin-lo, #b9862f)); border-color: rgba(255, 238, 190, .6); }

/* Play nearby (Bluetooth / Wi-Fi, no internet): a wide banner under the four modes. */
#screen-menu #btn-nearby-menu { grid-column: 1 / -1; display: flex; flex-direction: row; align-items: center; justify-content: flex-start; gap: 12px; min-height: 0; height: 58px; padding: 6px 14px; text-align: left; }
#screen-menu #btn-nearby-menu .mode-tile-ico { width: 38px; height: 38px; flex: 0 0 auto; margin: 0; }
#screen-menu #btn-nearby-menu b { display: block; font-size: 15px; }
#screen-menu #btn-nearby-menu em { display: block; font-size: 12px; }
#screen-menu #btn-nearby-menu::after { content: ""; margin-left: auto; width: 16px; height: 16px; flex: none; opacity: .75; background: url("../img/icons/back.webp") center / contain no-repeat; transform: scaleX(-1); }
#screen-menu .home-family-crest.has-crest { background: none; padding: 0; }
#screen-menu .home-family-crest .crest-img { width: 44px; height: 44px; }

/* Play a family now: three bot families to pick from */
.lf-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.lf-head h3 { margin: 0; }
.lf-shuffle { flex: none; min-height: 34px; padding: 0 12px; font-size: 13px; }
.lf-list { display: grid; gap: 8px; margin-top: 8px; }
.lf-row { display: flex; align-items: center; gap: 12px; padding: 8px 10px; border-radius: 14px; background: var(--well); border: 1px solid var(--edge-soft); }
.lf-row .crest-img { width: 48px; height: 48px; flex: none; }
.lf-row .lf-copy { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.lf-row b { font-size: 15px; line-height: 1.15; }
.lf-row em { font-style: normal; font-size: 12px; color: var(--ink-2); }
.lf-row .lf-tag { display: inline-block; margin-right: 6px; padding: 0 6px; border-radius: 999px; background: rgba(0,0,0,.35); font-size: 11px; }
.lf-row .btn { flex: none; min-height: 38px; padding: 0 14px; }

/* The family match sheet */
.fm-card h2 { margin: 0 0 10px; text-align: center; }
.fm-vs { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 8px; margin-bottom: 10px; }
.fm-side { display: flex; flex-direction: column; align-items: center; gap: 4px; text-align: center; }
.fm-side .crest-img { width: 72px; height: 72px; }
.fm-side .fm-house { width: 72px; height: 72px; display: grid; place-items: center; border-radius: 50%; border: 2px dashed var(--edge); color: var(--ink-2); font-size: 28px; }
.fm-side b { font-size: 14px; line-height: 1.15; }
.fm-side em { font-style: normal; font-size: 11px; color: var(--ink-2); }
.fm-vsmark { font-weight: 800; letter-spacing: .08em; color: #e6b94f; }
.fm-record { margin: 0 0 10px; text-align: center; font-size: 12.5px; color: #f6d98a; }

/* With friends on the home screen there is a row less to spend: the strip goes compact and the four
   play tiles drop their small print, so nothing is squeezed into anything else. */
#screen-menu:has(#friends-strip:not([hidden])) .mode-row.is-grid { gap: 8px; }
#screen-menu:has(#friends-strip:not([hidden])) .mode-tile.is-big em { display: none; }
#screen-menu:has(#friends-strip:not([hidden])) .mode-tile.is-big .mode-tile-ico { width: clamp(26px, 4.2dvh, 34px); height: clamp(26px, 4.2dvh, 34px); }
#screen-menu:has(#friends-strip:not([hidden])) .mode-tile.is-big b { font-size: 15px; }
#screen-menu:has(#friends-strip:not([hidden])) .mode-tile.is-big .hero-badge { padding: 1px 7px; font-size: 11px; }
#screen-menu:has(#friends-strip:not([hidden])) .friends-strip .async-games-title { margin: 0 0 2px; font-size: 11px; }
#screen-menu:has(#friends-strip:not([hidden])) .friends-strip-row { gap: 6px; }
#screen-menu:has(#friends-strip:not([hidden])) .friends-strip .friend-avatar { width: 38px; height: 38px; font-size: 16px; }
#screen-menu:has(#friends-strip:not([hidden])) .friends-strip .friend-chip b { font-size: 11px; max-width: 54px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#screen-menu:has(#friends-strip:not([hidden])) .friends-strip .friend-chip { gap: 2px; padding: 0; }
#screen-menu .home-top .hud-avatar.has-img { background: none; box-shadow: none; padding: 0; }
#screen-menu .home-top .hud-avatar img { width: 100%; height: 100%; object-fit: contain; display: block; }

/* Play online tile: live "N players waiting" (js/ui.js paintWaiting). Swaps in
   for the sub-line only while a real count is known; hidden wherever the em is. */
#screen-menu #btn-play-random.has-live em { display: none; }
#btn-play-random .online-live[hidden] { display: none; }
#btn-play-random .online-live { display: inline-flex; align-items: center; justify-content: center; gap: 6px; font-size: 12px; line-height: 1.2; color: var(--ink-2); white-space: nowrap; max-width: 100%; overflow: hidden; text-overflow: ellipsis; }
#btn-play-random .online-live-dot { flex: none; width: 7px; height: 7px; border-radius: 50%; background: #2fbf5b; box-shadow: 0 0 0 0 rgba(47, 191, 91, .55); animation: online-live-pulse 1.8s ease-out infinite; }
@keyframes online-live-pulse { 0% { box-shadow: 0 0 0 0 rgba(47, 191, 91, .55); } 80%, 100% { box-shadow: 0 0 0 6px rgba(47, 191, 91, 0); } }
@media (prefers-reduced-motion: reduce) { #btn-play-random .online-live-dot { animation: none; } }
@media (max-height: 560px) { #screen-menu #btn-play-random .online-live { display: none; } }
#screen-menu:has(#friends-strip:not([hidden])) #btn-play-random .online-live { display: none; }
