/* Clash Royale Stats 3.0.0 - Arena shell layout (T-002 / R-001 / R-005).

   Three layouts over one DOM:
     <768px    single column, sticky app bar + global chip row, fixed bottom tab
               bar (84px + safe-area inset), content padded clear of it.
     768-1023  same chrome, plus the opt-in `.grid-2` two-column card utility.
     >=1024px  240px sidebar (brand, player switcher, nav, live/health/version
               footer), a top bar that carries the screen title, the chip row and
               a right-side actions slot, content capped at 1440px. No tab bar.

   Height uses `100dvh` with a `100vh` fallback so the mobile URL bar cannot clip
   the tab bar; `env(safe-area-inset-*)` keeps it off the home indicator. The tab
   bar hides itself while a text input has focus so an on-screen keyboard never
   pushes it over the field (PLAN amendment 8).

   4.0 (T5-006) adds the PUBLIC pane (#public: a small brand header over the
   landing / auth / legal screens - each screen styles itself in its own
   per-screen file), the follow pane's account line and the forbidden card's
   note. */

/* ---------- roots ---------- */

.sprite { display: none; }

/* A focused control must never come to rest UNDER the fixed bottom tab bar
   (WCAG 2.4.11 Focus Not Obscured; R1-08). The browser scrolls a focused
   element into view to the edge of the scrollport, and the scrollport's edge is
   the bottom of the viewport - which is where the tab bar sits, so Tab/Shift+Tab
   parked Cards rows, Battles rows, "Show all" buttons and Home tiles fully
   behind it (a row at top 784 under a bar that starts at 760). `scroll-padding`
   tells the browser the bar is not part of the scrollport: the same 84px the
   bar is tall (+ the home-indicator inset), plus 12px of air. Set once on the
   scrolling element, so no screen needs a hack of its own; every
   scrollIntoView() / focus() / anchor jump on the page honours it. It applies
   wherever the bar is drawn (< 1024px, see the desktop block below). */
html { scroll-padding-bottom: calc(var(--tabbar-h) + 12px + env(safe-area-inset-bottom)); }

.app {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

/* ---------- top bar (app bar + chip row + actions slot) ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  flex: none;
  background: rgba(11,14,20,.94);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
  padding-top: env(safe-area-inset-top);
}

/* The app bar on a phone (R-001): avatar (opens the player switcher) - screen
   title - DEMO tag - trophies - live dot. The title is the one flexible column
   and ellipsises, so a long title can never push the trophies, the live dot or
   the DEMO tag (INV-5) off a 390px screen. The player's name + tag (`.appbar-id`)
   stay in the DOM - the switcher sheet and the sidebar still show identity - but
   are not drawn here: the bar's job is to say WHERE you are, and the avatar
   already says WHO. The ticking seconds text (`#live-text`) is not drawn at any
   width either; the same words live in the dot's title + aria-label. */
.appbar { min-width: 0; gap: 10px; }
.appbar-id { display: none; }
.appbar-trophies { display: flex; align-items: center; gap: 4px; flex: none; }
.appbar-trophies .num { font-size: 18px; }
.appbar-live { display: flex; align-items: center; justify-content: center; gap: 5px; flex: none; min-width: 20px; min-height: 20px; }
#live-text { display: none; }
.appbar .appbar-title {
  flex: 1 1 auto; min-width: 0;
  font-size: 22px; line-height: 1.15;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
/* A 320px phone (T4-038, G5 walkthrough): the avatar, the DEMO tag, the trophies
   and the live dot take 176px and the four 10px gaps 40px, which left the title
   72.17px - and "Trends" needs 72.22px, so the ellipsis fired on a sub-pixel
   overflow ("Tren..."). Below 360px the gaps are 6px: the title gets 88px at 320
   (room for a five-digit trophy count too), so every title of 7 characters or fewer
   shows in full. The other pieces are still `flex: none` - the trophies, the live
   dot and the DEMO tag (INV-5) never leave the screen; a long title ("Weekly
   recap", Battles with its count) still ellipsises, which is the designed
   fallback. 360px and up is untouched. */
@media (max-width: 359px) {
  .appbar { gap: 6px; }
}

#mock-badge { flex: none; }
.avatar { border: 0; }

/* One row under the app bar: the single filter summary chip on the left, the
   screen's own actions (Home's compare button, ...) on the right. Padding lives
   on the children's bottom margin, not on the row, so a row whose children are
   both empty takes no height at all. */
.topbar-row { display: flex; align-items: center; gap: 8px; padding: 0 16px; min-width: 0; }
.topbar-row > * { margin-bottom: 8px; }

.chiprow {
  display: flex;
  gap: 8px;
  padding: 0;
  min-width: 0;
  overflow-x: auto;
  scrollbar-width: none;
}
.chiprow::-webkit-scrollbar { display: none; }
.chiprow:empty { display: none; }

.topbar-actions { display: flex; align-items: center; gap: 8px; margin-left: auto; flex: none; }
.topbar-actions:empty { display: none; }

/* ---------- content / screens ---------- */

.content {
  flex: 1;
  width: 100%;
  padding: 10px 16px calc(var(--tabbar-h) + 16px + env(safe-area-inset-bottom));
}

.screen { display: none; }
.screen.on { display: block; }
.screen-live:empty { display: none; }
.screen-live { margin-bottom: 20px; }

/* 20px between a screen's sections (R-012 polish). A screen that lays its
   sections out as direct children of one wrapper opts in with `.screen-stack`;
   screens that own their own grid keep it. */
.screen-stack { display: flex; flex-direction: column; gap: 20px; }

/* ---------- bottom tab bar ---------- */

.tabbar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 50;
  padding-bottom: calc(22px + env(safe-area-inset-bottom));
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
}
body.typing .tabbar { display: none; }

/* ---------- sidebar (desktop only) ---------- */

.side { display: none; }
.side-brand { display: flex; align-items: center; gap: 10px; padding: 4px 10px 14px; }
.side-brand .h2 { font-size: 18px; }
.side-player {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; margin-bottom: 10px; width: 100%; text-align: left;
}
.side-player-id { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.side-player-name { font-size: 12px; font-weight: 800; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.side-nav { display: flex; flex-direction: column; gap: 6px; }
/* Sidebar groups (R-003): a small muted uppercase label before the first
   "explore" entry and a thin rule before the settings entry (More). */
.nav-group-label {
  padding: 12px 12px 2px;
  font-size: 11px; font-weight: 800; letter-spacing: .1em; text-transform: uppercase;
  color: var(--ink-3);
}
.nav-sep { height: 1px; margin: 8px 12px 4px; background: var(--line); }
.side-foot {
  margin-top: auto;
  display: flex; flex-direction: column; gap: 8px;
  padding: 12px 12px 4px; border-top: 1px solid var(--line);
}
.side-foot-live { display: flex; align-items: center; gap: 8px; }

/* ---------- landing ---------- */

.landing { display: flex; justify-content: center; padding: 8vh 20px; }
/* `width: 100%; min-width: 0` (G3 R2-17): the card is a flex item of .landing, and
   a flex item's automatic minimum width is its MIN-CONTENT width - here the
   form's tag field at its intrinsic ~20 characters beside the button, 372px -
   so on a 320 or 360px phone the card could not shrink to the screen, centred
   itself instead and hung ~26px off BOTH sides: the page scrolled sideways and
   the card's left edge sat off-screen. It now fills the space the 20px gutters
   leave, up to 520px. */
.landing-card {
  width: 100%; min-width: 0; max-width: 520px; text-align: center;
  background: var(--s1); border: 1px solid var(--line);
  border-radius: 16px; padding: 36px 32px;
  overflow-wrap: anywhere;
}
/* The follow pane's and the retry pane's title is the page's ONE visible h1
   (T5-028b: the app bar's h1 is hidden with #app). `.landing-title` draws it
   exactly as the h2 it used to be - the h2 size, 1.5em, not an h1's 2em - and
   it is a class rather than `.landing-card h1`, which would out-rank the auth
   cards' own `.auth-title` (those cards are `.landing-card`s too). */
.landing-card h2, .landing-title { font-family: var(--display); font-weight: 800; font-size: 1.5em; letter-spacing: -0.02em; margin: 10px 0; }
.landing-card p { color: var(--ink-2); }
.landing-card form { display: flex; gap: 8px; margin-top: 18px; }
.landing-crown { color: var(--gold); display: flex; justify-content: center; }
/* The follow pane's "Signed in as {email} · Sign out" (4.0). An address can be
   long: it wraps (the card's overflow-wrap) rather than widening the card. */
.landing-account { margin: 16px 0 0; }
.landing-account #landing-email { color: var(--ink-2); }
/* Its Account link (T5-030b) reads exactly like the Sign out `.linkbtn` beside it. */
.landing-account a { padding: 4px 2px; color: var(--gold); text-decoration: underline; }
/* A refused follow marks the tag field (aria-invalid, set by web/app.js) with
   the --bad border, as every auth form does (auth.css). */
#landing-form .field[aria-invalid="true"] { border-color: var(--bad); }
/* "Following…" while the first follow runs (T5-030b): dimmed like the auth
   forms' busy submit (auth.css). */
#landing-form .btn:disabled { opacity: .55; cursor: progress; }
/* A phone: the tag field and its button stack (side by side the field was left
   ~75px at 320, narrower than its own placeholder) and the card gives its side
   padding back to the content. */
@media (max-width: 420px) {
  .landing-card { padding: 28px 20px; }
  .landing-card form { flex-direction: column; }
  .landing-card form .field { flex: none; width: 100%; }
  .landing-card form .btn { width: 100%; }
}

.field {
  flex: 1; min-width: 0;
  background: var(--s2); border: 1px solid var(--line-2); color: var(--ink);
  border-radius: 12px; padding: 0 14px; height: 44px; font-size: 14px;
}
.field::placeholder { color: var(--ink-3); }
.error-text { color: var(--bad); margin-top: 8px; font-size: 13px; }

/* A button that reads as an inline link (the follow pane's "Sign out"). It is a
   real <button>: keyboard-operable, no href to follow. */
.linkbtn {
  background: none; border: 0; padding: 4px 2px; margin: 0;
  font: inherit; color: var(--gold); text-decoration: underline; cursor: pointer;
}

/* ---------- public pane (4.0, T5-006) ----------
   The pane the signed-out screens live in: welcome, login, signup, forgot,
   reset, verify, setup, legal. A column, not the centred card of `.landing`
   (which it still carries, for the shared show/hide and gutters): a small
   brand header - crown + site name, the Demo tag (INV-5), the version - over
   whichever screen is on. Each screen owns its own width and layout in its own
   stylesheet; this only keeps the column readable (1040px max) and the header
   on one line at 320px. */
.landing.public-pane {
  flex-direction: column; align-items: center; justify-content: flex-start;
  padding: calc(16px + env(safe-area-inset-top)) 16px calc(32px + env(safe-area-inset-bottom));
}
.public-wrap { width: 100%; min-width: 0; max-width: 1040px; display: flex; flex-direction: column; gap: 20px; }
.public-head { display: flex; align-items: center; gap: 10px; min-width: 0; }
.public-brand {
  display: inline-flex; align-items: center; gap: 10px; min-width: 0;
  color: var(--ink); text-decoration: none;
}
.public-brand .h2 { font-size: 18px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#public-demo { flex: none; }
#public-version { margin-left: auto; flex: none; }
.public-wrap > .screen { min-width: 0; }

/* The forbidden card (CRUI.forbiddenCard, 4.0): its one muted line under the
   title. */
.forbidden-card .forbidden-note { margin: 6px 0 0; }

/* ---------- kernel-owned sheets (player switcher, deck picker) ---------- */

.player-list, .deck-picker { display: flex; flex-direction: column; }
.player-row, .deck-pick-row { width: 100%; text-align: left; cursor: pointer; }
.player-row.on, .deck-pick-row.on { color: var(--gold); }
.player-meta { display: flex; flex-direction: column; min-width: 0; }
.player-name { font-weight: 800; }
.deck-pick-nums { margin-left: auto; flex: none; }
/* The picker's failed load (R1-11): the reason, then the Retry under it. */
.deck-picker-error { display: flex; flex-direction: column; align-items: flex-start; gap: 10px; }

/* ---------- content grid utilities ----------
   (T-002's temporary "SKELETON LAYOUT" block for the filter sheet and the More
   screen lived here; web/css/filters.css and web/css/more.css own those
   selectors since T-005/T-014, so T-016 deleted the duplicates. The unused
   `.grid-12` twelve-column utility went with them - every screen composes its
   own grid; the 1440px content cap that R-001 asks for is on `.content`.) */

.grid-2 { display: grid; grid-template-columns: 1fr; gap: 12px; }

@media (min-width: 768px) {
  .grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
  .content { padding-left: 24px; padding-right: 24px; }
}

/* ---------- desktop ---------- */

@media (min-width: 1024px) {
  /* No tab bar here (it is `display: none` below), so nothing to scroll clear of. */
  html { scroll-padding-bottom: 0; }

  .app { padding-left: var(--side-w); }

  .side {
    display: flex;
    position: fixed; top: 0; bottom: 0; left: 0;
    z-index: 60;
    overflow-y: auto;
  }

  .topbar {
    display: flex; align-items: center; gap: 12px;
    padding: 12px 28px;
    background: var(--bg);
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
  }
  .appbar { order: 1; height: 44px; padding: 0; gap: 10px; flex: none; }
  .appbar .avatar { display: none; }
  .appbar .appbar-title { flex: none; font-size: 26px; margin-right: 8px; overflow: visible; }
  .topbar-row { order: 2; flex: 1; padding: 0; }
  .topbar-row > * { margin-bottom: 0; }
  .chiprow { overflow: visible; flex-wrap: wrap; }

  /* 16px of air under the top bar on EVERY screen (T4-010). It used to be 0 on
     Battles/Decks/Cards/More and a different hand-tuned offset (2-16px) on the
     screens that carried their own, so the first block looked glued to the
     header. The screens no longer add a top offset of their own. */
  .content {
    padding: 16px 28px 28px;
    max-width: calc(var(--content-max) + 56px);
    margin: 0 auto;
    width: 100%;
  }

  .tabbar { display: none; }
}
