/* Full-viewport variants (MATCH_PENDING) keep this rule for the legacy
   layout. Shell-hosted Battlefield overrides this below. */
.battlefield-screen {
  display: flex; flex-direction: column;
  padding: 0;
  width: 100%; max-width: 100%;
  align-items: stretch;
}
.battlefield-header {
  display: flex; align-items: center; justify-content: space-between;
  gap: 14px; flex-wrap: wrap;
  padding: 18px 32px;
  background: var(--bg-card);
  border-bottom: 1px solid var(--bg-hover);
}
.battlefield-title-group { display: flex; align-items: center; gap: 10px; min-width: 0; }
.battlefield-emblem      { font-size: 1.4rem; line-height: 1; }
.battlefield-title       {
  font-size: 1.2rem; font-weight: 700; letter-spacing: 0.3px;
  color: var(--accent-gold);
}
.battlefield-user-bar    { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.battlefield-username    { font-size: 0.88rem; color: var(--text-secondary); }
.battlefield-role-badge  { background: var(--accent-gold); color: #000; font-size: 0.7rem; font-weight: 700; padding: 2px 9px; border-radius: 10px; letter-spacing: 0.4px; }
.battlefield-logout-btn  { font-size: 0.78rem; padding: 4px 10px; }

.battlefield-elo-badge  { background: var(--bg-hover); color: var(--text-secondary); font-size: 0.72rem; padding: 2px 8px; border-radius: 10px; }

.battlefield-form-row   { display: flex; flex-direction: column; gap: 4px; }
.battlefield-label      { font-size: 0.72rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.5px; }
.battlefield-rated-wrap { display: flex; align-items: center; gap: 6px; font-size: 0.82rem; cursor: pointer; }

/* Native <input type="checkbox"> restyled via appearance:none → becomes
   the visible pill. Label-click toggle, keyboard focus, form state all
   work for free. */
.battlefield-rated-toggle {
  gap: 8px;
  padding: 4px 10px 4px 6px;
  border-radius: 999px;
  /* Matches dropdown grey on same row; slider-track drops to --bg-input
     for internal depth without vanishing against page bg. */
  background: var(--bg-hover);
  border: 1px solid var(--bg-hover);
  transition: border-color 0.15s ease, background 0.15s ease;
  user-select: none;
  line-height: 1;
}
.battlefield-rated-toggle:hover {
  border-color: var(--accent-gold);
}
.battlefield-rated-toggle input[type="checkbox"] {
  appearance: none;
  -webkit-appearance: none;
  width: 30px;
  height: 16px;
  margin: 0;
  padding: 0;
  border: none;
  border-radius: 999px;
  /* Slider track sits inside wrapper pill (--bg-hover); drops to
     --bg-input for clear depth as an inset rail. */
  background: var(--bg-input);
  position: relative;
  cursor: pointer;
  flex: 0 0 auto;
  transition: background 0.18s ease;
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.35);
}
.battlefield-rated-toggle input[type="checkbox"]::before {
  content: '';
  position: absolute;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--text-muted, #888);
  top: 1px;
  left: 2px;
  transition: transform 0.18s ease, background 0.18s ease;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
}
.battlefield-rated-toggle input[type="checkbox"]:checked {
  background: var(--accent-gold);
}
.battlefield-rated-toggle input[type="checkbox"]:checked::before {
  transform: translateX(14px);
  background: #1a1a1a;
}
.battlefield-rated-toggle input[type="checkbox"]:focus-visible {
  outline: 2px solid var(--accent-gold);
  outline-offset: 2px;
}
.battlefield-rated-text {
  display: inline-flex;
  align-items: center;
  font-weight: 600;
  letter-spacing: 0.3px;
  color: var(--text-muted);
  transition: color 0.18s ease;
}
.battlefield-rated-toggle input[type="checkbox"]:checked ~ .battlefield-rated-text {
  color: var(--accent-gold);
}
@media (prefers-reduced-motion: reduce) {
  .battlefield-rated-toggle,
  .battlefield-rated-toggle input[type="checkbox"],
  .battlefield-rated-toggle input[type="checkbox"]::before,
  .battlefield-rated-text {
    transition: none;
  }
}

/* Shell-hosted Phase.BATTLEFIELD: 3-card grid (Quick Match / Create Game /
   Play vs AI) + Open Games list. Lives inside shell content area (no
   header — top-bar handles chrome). */
.battlefield-screen {
  width: 100%;
  max-width: 1280px; margin: 0 auto;
  padding: 24px 20px;
  gap: 24px;
  box-sizing: border-box;
  align-items: stretch;
}
.battlefield-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  /* Each card sizes to own content; stretch made every card match the
     create-game card's height which read as "too much". */
  align-items: start;
}
/* Single-card variant: only Create Game lives here now (Quick Match
   moved to topbar; Play-vs-AI folded into Opponent dropdown). */
.battlefield-grid-single {
  grid-template-columns: 1fr;
}
.battlefield-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  padding: 12px 14px 12px;
  display: flex; flex-direction: column; gap: 8px;
  min-width: 0;
}
.battlefield-card-title {
  font-size: 0.78rem; font-weight: 700; margin: 0;
  color: var(--accent-gold);
  text-transform: uppercase; letter-spacing: 0.6px;
}
.battlefield-card-cta { width: 100%; margin-top: 2px; }
.battlefield-card .battlefield-form-row { gap: 2px; }
.battlefield-card .battlefield-select   { padding: 4px 8px; font-size: 0.82rem; }
.battlefield-card .battlefield-rated-wrap { font-size: 0.8rem; gap: 6px; }
.battlefield-card .battlefield-label    { font-size: 0.66rem; }

/* Inline form: [Opponent | Time | Rated | CTA] one line; wraps on narrow.
   Password row lives OUTSIDE the row so it can drop to its own line when
   visibility=Private. CTA gets pushed right via margin-left:auto. */
.battlefield-card-create .battlefield-card-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}
.battlefield-card-create .battlefield-card-row .battlefield-form-row {
  flex: 0 0 auto;
  min-width: 0;
}
.battlefield-card-create .battlefield-card-row .cg-opponent-row {
  flex: 0 0 auto;
  min-width: 0;
}
.battlefield-card-create .battlefield-card-row .battlefield-select {
  width: auto;
  min-width: 130px;
  max-width: 200px;
}
.battlefield-card-create .battlefield-card-row .battlefield-rated-wrap {
  align-self: center;
  white-space: nowrap;
  margin-bottom: 0;
}
.battlefield-card-create .battlefield-card-cta-inline {
  width: auto;
  margin-top: 0;
  margin-left: auto;
  flex: 0 0 auto;
  padding-left: 18px;
  padding-right: 18px;
  align-self: stretch;
}
.battlefield-card-create .battlefield-password-row {
  max-width: 360px;
}

.battlefield-open-games {
  display: flex; flex-direction: column; gap: 10px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  padding: 14px 16px;
}

/* Non-blocking; user can still browse Open Games + Create Game while searching. */
.battlefield-queue-banner {
  display: flex; align-items: center; gap: 14px;
  padding: 12px 16px;
  background: color-mix(in srgb, var(--accent-gold) 8%, transparent);
  border: 1px solid color-mix(in srgb, var(--accent-gold) 45%, transparent);
  border-radius: 10px;
}
.battlefield-queue-spinner {
  width: 22px; height: 22px;
  border: 2px solid var(--bg-hover);
  border-top-color: var(--accent-gold);
  border-radius: 50%;
  animation: battlefield-spin 0.9s linear infinite;
  flex: 0 0 auto;
}
.battlefield-queue-text {
  display: flex; align-items: baseline; gap: 10px;
  flex: 1 1 auto;
  min-width: 0;
}
.battlefield-queue-label {
  color: var(--text-primary);
  font-weight: 600;
  font-size: 0.95rem;
}
.battlefield-queue-timer {
  color: var(--accent-gold);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  font-size: 1.05rem;
}
.battlefield-queue-cancel {
  flex: 0 0 auto;
}
@media (prefers-reduced-motion: reduce) {
  .battlefield-queue-spinner { animation: none; }
}
/* Green-tinted: local user hosting private game waiting for join. */
.battlefield-host-banner {
  background: rgba(46, 139, 87, 0.10);
  border: 1px solid rgba(111, 207, 138, 0.45);
}
.battlefield-host-banner .battlefield-queue-spinner {
  border-top-color: var(--accent-green);
}
.battlefield-host-banner .battlefield-queue-timer {
  color: var(--accent-green);
}

/* Replaces queue/host banner briefly (~1.5s) on MATCH_FOUND before server
   promotes to ONLINE_MAP_SELECT. */
.battlefield-matchfound-banner {
  background: color-mix(in srgb, var(--accent-gold) 18%, transparent);
  border: 1px solid color-mix(in srgb, var(--accent-gold) 70%, transparent);
  animation: battlefield-matchfound-pulse 1.4s ease-in-out infinite;
}
.battlefield-matchfound-banner .battlefield-queue-spinner {
  border-top-color: var(--accent-gold);
}
.battlefield-matchfound-sub {
  color: var(--text-primary);
  font-size: 0.9rem;
  opacity: 0.9;
}
.battlefield-matchfound-sub strong { color: var(--accent-gold); }
@keyframes battlefield-matchfound-pulse {
  0%, 100% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--accent-gold) 45%, transparent); }
  50%      { box-shadow: 0 0 0 6px color-mix(in srgb, var(--accent-gold) 0%, transparent); }
}
@media (prefers-reduced-motion: reduce) {
  .battlefield-matchfound-banner { animation: none; }
}

.battlefield-password-row input.battlefield-select {
  padding: 4px 8px;
  font-size: 0.82rem;
  background: var(--bg-input);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
  border-radius: 4px;
  width: 100%;
  box-sizing: border-box;
}
.battlefield-password-row input.battlefield-select:focus {
  outline: none;
  border-color: var(--accent-gold);
}
/* Applied briefly when user tries to Create a private game without a
   password — field focused + shaken + inline error renders below. */
.battlefield-password-row input.cg-password-shake {
  border-color: var(--accent-red);
  animation: cg-password-shake 0.32s cubic-bezier(0.36, 0.07, 0.19, 0.97) both;
}
@keyframes cg-password-shake {
  10%, 90% { transform: translateX(-1px); }
  20%, 80% { transform: translateX( 2px); }
  30%, 50%, 70% { transform: translateX(-4px); }
  40%, 60% { transform: translateX( 4px); }
}
@media (prefers-reduced-motion: reduce) {
  .battlefield-password-row input.cg-password-shake { animation: none; }
}
/* Inline error rendered beneath password input; empty by default,
   populated by battlefieldCreateGame() on submit, cleared on next keystroke. */
.battlefield-password-error {
  min-height: 1em; /* reserve space so layout doesn't jump on first error */
  margin-top: 4px;
  font-size: 0.75rem;
  color: var(--accent-red);
  line-height: 1.3;
}
.battlefield-password-error:empty { min-height: 0; margin-top: 0; }
.battlefield-section-title {
  font-size: 0.82rem; font-weight: 700; margin: 0;
  color: var(--accent-gold);
  text-transform: uppercase; letter-spacing: 0.6px;
}
@media (max-width: 900px) {
  .battlefield-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .battlefield-grid.battlefield-grid-single { grid-template-columns: 1fr; }
}
@media (max-width: 640px) {
  .battlefield-grid { grid-template-columns: 1fr; }
  .battlefield-screen { padding: 14px 12px; gap: 16px; }
  .battlefield-card-create .battlefield-card-row {
    flex-direction: column;
    align-items: stretch;
  }
  .battlefield-card-create .battlefield-card-row .battlefield-rated-wrap {
    align-self: flex-start;
  }
  .battlefield-card-create .battlefield-card-cta-inline { width: 100%; }
}

.battlefield-game-list    { display: flex; flex-direction: column; gap: 8px; }
/* host (flex:1) → meta (fixed-width cluster, right-anchored) → Join (right).
   Meta has stable min-width so badge cluster's left edge stays at the same
   x across every row regardless of label variant or hostname length. */
.battlefield-game-row     { display: flex; align-items: center; gap: 12px; background: var(--bg-input); border-radius: 8px; padding: 10px 14px; }
.battlefield-game-host    { display: flex; flex-direction: column; flex: 1 1 0; min-width: 0; }
.battlefield-game-hostname{ font-size: 0.9rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.battlefield-game-elo     { font-size: 0.75rem; color: var(--text-muted); }
/* Fixed-track grid: every slot occupies the same x-range across rows.
   Each child pinned via grid-column so an absent badge leaves an empty
   slot without shifting neighbours. Order: [hostflag][rated][tc][age].
   AI + Private SHARE the hostflag slot — mutually exclusive (bots are
   always public; Private is a human-host marker). */
.battlefield-game-meta    {
  display: grid;
  /* Track widths sized for widest variant per slot at 0.68rem: "🔒 Private",
     "Unrated — AI", "10min/turn", ">24h ago". */
  grid-template-columns:
    [hostflag-slot] 76px
    [rated-slot]    90px
    [tc-slot]       80px
    [age-slot]      72px;
  align-items: center;
  justify-items: center;
  /* 10px gap so adjacent tag pills don't touch (tabular nums at 4px gap did). */
  column-gap: 10px;
  flex-shrink: 0;
}
/* AI nudges to slot end so dead space between hostname and RATED doesn't
   read as disconnect; Private stays centred (narrower + lock glyph balances). */
.battlefield-game-meta > .tag-ai         { grid-column: hostflag-slot; justify-self: end; }
.battlefield-game-meta > .tag-private    { grid-column: hostflag-slot; }
.battlefield-game-meta > .tag-rated,
.battlefield-game-meta > .tag-unrated    { grid-column: rated-slot; }
.battlefield-game-meta > .tag-tc         { grid-column: tc-slot; }
.battlefield-game-meta > .battlefield-game-time { grid-column: age-slot; }
/* Inherits tag-tc styling; only tabular nums + right-justify differ. */
.battlefield-game-time {
  font-variant-numeric: tabular-nums;
  justify-self: end;
}
.battlefield-tag          {
  font-size: 0.68rem;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 8px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  white-space: nowrap;
  border: 1px solid rgba(255, 255, 255, 0.08);
}
/* Tag palette bound to theme so light/dark stay coherent:
     RATED+PRIVATE  accent-red   (positive ladder + locked)
     UNRATED        65% red+black (muted sibling of rated; AA on dark+light)
     AI             accent-info  (blue tech/intel)
     TC + TIME      bg-hover     (data fields, not semantic flags) */
.tag-rated   { background: var(--accent-red); color: #fff; }
.tag-unrated { background: color-mix(in srgb, var(--accent-red) 65%, black); color: #fff; }
.tag-private { background: var(--accent-red);   color: #fff; }
.tag-ai      { background: var(--accent-info);  color: #fff; }
.tag-tc      { background: var(--bg-hover); color: var(--text-primary); }
.battlefield-join-btn     { white-space: nowrap; flex-shrink: 0; }
.battlefield-game-row-mine {
  border: 1px solid color-mix(in srgb, var(--accent-gold) 55%, transparent);
  background: color-mix(in srgb, var(--accent-gold) 6%, transparent);
}
/* Subtle indigo so AI rows read at a glance without overpowering the
   primary-accent gold of user's own hosted row. */
.battlefield-game-row-ai {
  border: 1px solid rgba(154, 166, 255, 0.35);
  background: rgba(154, 166, 255, 0.05);
}
.battlefield-game-you {
  color: var(--accent-gold);
  font-weight: 700;
  font-size: 0.72rem;
  margin-left: 4px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.battlefield-empty        { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; color: var(--text-muted); gap: 10px; padding: 60px 0; }

.battlefield-conn-status  { font-size: 0.72rem; font-weight: 600; padding: 3px 10px; border-radius: 10px; }
.conn-ok   { background: #1a4a2e; color: #6fcf8a; }
.conn-wait { background: #3a3000; color: var(--accent-gold); }
.conn-err  { background: #4a1a1a; color: #e07070; }

@media (max-width: 700px) {
  .battlefield-game-row { flex-wrap: wrap; }
  /* Narrow: relax fixed-track grid to wrapping flex so badge cluster can
     break across lines. Column alignment matters less when layout stacks. */
  .battlefield-game-meta {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-start;
    grid-template-columns: none;
    column-gap: 0;
    gap: 6px;
  }
  .battlefield-game-meta > .tag-ai,
  .battlefield-game-meta > .tag-rated,
  .battlefield-game-meta > .tag-unrated,
  .battlefield-game-meta > .tag-tc,
  .battlefield-game-meta > .tag-private,
  .battlefield-game-meta > .battlefield-game-time { grid-column: auto; justify-self: auto; }
}
