.app-shell {
  display: flex;
  min-height: 100vh;
  width: 100%;
  background: var(--bg-main);
  align-items: stretch;
}

.app-sidebar,
.app-topbar {
  --text-primary:   #ffffff;
  --text-secondary: #f0f0f0;
  --text-muted:     #c0c0c0;
}
.app-footer {
  --text-primary:   #d0d0d0;
  --text-secondary: #b8b8b8;
  --text-muted:     #909090;
}

/* Light-theme chrome: every text token collapses to near-black; hierarchy
   from font-weight + size, not shade. */
[data-theme="light"] .app-sidebar,
[data-theme="light"] .app-topbar,
[data-theme="light"] .app-footer {
  --text-primary:   #0c0a09;
  --text-secondary: #0c0a09;
  --text-muted:     #0c0a09;
}

.app-sidebar {
  flex: 0 0 auto;
  width: 240px;
  background: var(--bg-panel);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: width 0.2s ease, border-right-color 0.2s ease;
  /* Sticky on desktop; mobile @media below makes this a fixed bottom bar. */
  position: sticky;
  top: 0;
  align-self: flex-start;
  height: 100vh;
  max-height: 100vh;
  z-index: 50;
}
.app-sidebar-brand {
  display: flex; align-items: center; gap: 10px;
  height: 60px; /* matches .app-topbar — bottom borders align */
  padding: 0 18px;
  border-bottom: 1px solid var(--border-color);
  user-select: none;
  box-sizing: border-box;
  flex: 0 0 auto;
}
.app-sidebar-logo {
  width: 32px; height: 32px;
  flex: 0 0 auto;
  /* SVG uses fill="currentColor" so it themes via --accent-gold. */
  color: var(--accent-gold);
}
.app-sidebar-brandname {
  color: var(--text-primary);
  font-weight: 700;
  font-size: 0.98rem;
  letter-spacing: 0.3px;
  /* Multi-word brand wraps to a tidy stack instead of truncating in the 240px sidebar. */
  line-height: 1.1;
  white-space: normal;
  flex: 1 1 auto;
  min-width: 0;
}
.app-sidebar-collapse {
  flex: 0 0 auto;
  width: 26px; height: 26px;
  padding: 0;
  background: transparent;
  border: 0;
  color: var(--text-muted);
  font: inherit;
  font-size: 0.85rem;
  cursor: pointer;
  border-radius: 4px;
  display: flex; align-items: center; justify-content: center;
  transition: background 0.12s ease, color 0.12s ease;
}
.app-sidebar-collapse:hover {
  background: var(--bg-hover);
  color: var(--accent-gold);
}

.app-sidebar-nav {
  padding: 10px 8px 16px;
  flex: 1 1 auto;
  overflow-y: auto;
  overflow-x: hidden;
  display: flex; flex-direction: column; gap: 4px;
}

.app-nav-section {
  display: flex; flex-direction: column; gap: 2px;
  padding: 6px 0;
}
.app-nav-section + .app-nav-section {
  border-top: 1px solid rgba(255, 255, 255, 0.04);
  margin-top: 4px;
  padding-top: 10px;
}
.app-nav-label {
  color: var(--text-muted);
  font-size: 0.66rem;
  text-transform: uppercase;
  letter-spacing: 0.9px;
  padding: 4px 12px 6px;
  font-weight: 700;
}

.app-nav-item {
  display: flex; align-items: center; justify-content: flex-start;
  gap: 12px;
  width: 100%;
  text-align: left;
  padding: 8px 12px;
  background: transparent;
  border: 1px solid transparent;
  border-left: 3px solid transparent;
  border-radius: 6px;
  color: var(--text-secondary);
  font: inherit;
  font-size: 0.92rem;
  cursor: pointer;
  transition: background 0.12s ease, color 0.12s ease, border-color 0.12s ease;
  white-space: nowrap;
  overflow: hidden;
}
.app-nav-item:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}
.app-nav-item.is-active {
  background: color-mix(in srgb, var(--accent-gold) 10%, transparent);
  color: var(--accent-gold);
  font-weight: 600;
  border-left-color: var(--accent-gold);
}
.app-nav-item-icon {
  flex: 0 0 auto;
  width: 20px; height: 20px;
  display: inline-flex; align-items: center; justify-content: center;
}
.app-nav-item-icon svg {
  width: 100%; height: 100%;
  display: block;
}
.app-nav-item-label {
  flex: 1 1 auto;
  overflow: hidden;
  text-overflow: ellipsis;
}
.app-nav-item-ext {
  flex: 0 0 auto;
  opacity: 0.55;
  font-size: 0.78rem;
}

/* Live-match rejoin card. Timer driven by online-match.js writing into
   #app-sidebar-live-timer. */
.app-sidebar-live-match {
  display: flex; align-items: center; gap: 10px;
  width: calc(100% - 4px);
  margin: 2px 2px 10px;
  padding: 10px 12px;
  background: linear-gradient(135deg, rgba(201, 64, 64, 0.16), rgba(201, 64, 64, 0.06));
  border: 1px solid rgba(201, 64, 64, 0.55);
  border-radius: 8px;
  color: var(--text-primary);
  font: inherit;
  cursor: pointer;
  text-align: left;
  box-shadow: 0 0 0 0 rgba(201, 64, 64, 0.4);
  transition: background 0.15s ease, border-color 0.15s ease,
              transform 0.12s ease, box-shadow 0.2s ease;
}
.app-sidebar-live-match:hover {
  background: linear-gradient(135deg, rgba(201, 64, 64, 0.26), rgba(201, 64, 64, 0.10));
  border-color: var(--accent-red);
  transform: translateY(-1px);
  box-shadow: 0 2px 10px -2px rgba(201, 64, 64, 0.5);
}
.app-sidebar-live-dot {
  flex: 0 0 auto;
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--accent-red);
  box-shadow: 0 0 0 0 rgba(201, 64, 64, 0.75);
  animation: sidebar-live-pulse 1.8s ease-out infinite;
}
@keyframes sidebar-live-pulse {
  0%   { box-shadow: 0 0 0 0   rgba(201, 64, 64, 0.65); }
  70%  { box-shadow: 0 0 0 8px rgba(201, 64, 64, 0);    }
  100% { box-shadow: 0 0 0 0   rgba(201, 64, 64, 0);    }
}
.app-sidebar-live-body {
  flex: 1 1 auto;
  min-width: 0;
  display: flex; flex-direction: column;
  gap: 2px;
  overflow: hidden;
}
.app-sidebar-live-head {
  display: flex; align-items: baseline; gap: 6px;
}
.app-sidebar-live-label {
  color: var(--accent-red);
  font-weight: 700;
  font-size: 0.72rem;
  letter-spacing: 0.7px;
  text-transform: uppercase;
}
.app-sidebar-live-timer {
  color: var(--text-primary);
  font-weight: 600;
  font-size: 0.82rem;
  font-variant-numeric: tabular-nums;
}
.app-sidebar-live-timer:not(:empty)::before {
  /* CSS escape is `\NNNN` (no `u` prefix); `\u00B7` would render literal text. */
  content: "\00B7";
  margin-right: 4px;
  color: var(--text-muted);
  font-weight: 400;
}
.app-sidebar-live-opponent {
  color: var(--text-secondary);
  font-size: 0.78rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.app-sidebar-live-arrow {
  flex: 0 0 auto;
  color: var(--text-muted);
  font-size: 0.9rem;
  transition: transform 0.15s ease, color 0.15s ease;
}
.app-sidebar-live-match:hover .app-sidebar-live-arrow {
  transform: translateX(2px);
  color: var(--accent-red);
}

.app-shell.is-collapsed .app-sidebar-live-match {
  width: 44px;
  margin: 2px auto 10px;
  padding: 10px 0;
  gap: 0;
  justify-content: center;
}
.app-shell.is-collapsed .app-sidebar-live-body,
.app-shell.is-collapsed .app-sidebar-live-arrow {
  display: none;
}

.app-sidebar-bottom {
  margin-top: auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding-top: 10px;
}
.app-nav-divider {
  height: 1px;
  background: var(--border-color);
  margin: 0 6px;
  flex: 0 0 auto;
}

.app-main {
  flex: 1 1 auto;
  display: flex; flex-direction: column;
  min-width: 0;
  min-height: 0;
}

.app-topbar {
  display: flex; align-items: center; justify-content: flex-start;
  gap: 16px;
  padding: 0 24px;
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border-color);
  height: 60px; /* matches .app-sidebar-brand — top borders align */
  flex: 0 0 auto;
  box-sizing: border-box;
}
.app-topbar-right { margin-left: auto; }
.app-page-title {
  font-size: 1.3rem;
  color: var(--text-primary);
  margin: 0;
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 0 0 auto;
}

@media (max-width: 1100px) {
  .app-page-title { display: none; }
}
@media (max-width: 900px) {
  .app-topbar-donate        { display: none; }
}
@media (max-width: 640px) {
  .app-topbar-focus         { display: none; }
}

.app-sidebar-presence {
  display: flex; align-items: center; justify-content: flex-start;
  gap: 10px;
  margin: 0 4px 6px;
  padding: 8px 12px;
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid rgba(255, 255, 255, 0.05);
  border-radius: 6px;
  color: var(--text-secondary);
  font-size: 0.82rem;
  line-height: 1;
  white-space: nowrap;
  overflow: hidden;
  user-select: none;
  text-align: left;
}
.app-sidebar-presence-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--accent-green);
  box-shadow: 0 0 6px rgba(129, 182, 76, 0.6);
  flex: 0 0 auto;
}
.app-sidebar-presence-count {
  color: var(--text-primary);
  font-weight: 700;
  flex: 0 0 auto;
}
.app-sidebar-presence-label {
  color: var(--text-muted);
  flex: 1 1 auto;
  overflow: hidden;
  text-overflow: ellipsis;
}

.app-topbar-right {
  position: relative;
  display: flex; align-items: center; gap: 10px;
  flex: 0 0 auto;
}

.app-topbar-quickplay {
  white-space: nowrap;
  min-width: 140px;
  padding-left: 22px;
  padding-right: 22px;
}

.app-topbar-quickplay,
.app-topbar-donate,
.app-topbar-focus {
  border-radius: 999px;
}
.app-topbar-quickplay.is-queued {
  background: rgba(201, 64, 64, 0.15);
  border: 1px solid rgba(201, 64, 64, 0.55);
  color: var(--accent-red);
}
.app-topbar-quickplay.is-queued:hover {
  background: rgba(201, 64, 64, 0.25);
  border-color: var(--accent-red);
}

.app-topbar-donate {
  display: inline-flex; align-items: center; justify-content: center;
  background: transparent;
  border: 1px solid var(--border-color);
  color: var(--accent-red);
  font-size: 1rem;
  padding: 4px 10px;
}
.app-topbar-donate:hover {
  background: rgba(192, 96, 96, 0.12);
  border-color: var(--accent-red);
  color: var(--accent-red);
}
.app-topbar-focus {
  display: inline-flex; align-items: center; gap: 6px;
  white-space: nowrap;
  background: transparent;
  border: 1px solid var(--border-color);
  color: var(--text-muted);
}
.app-topbar-focus:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}
.app-topbar-focus.is-active {
  background: color-mix(in srgb, var(--accent-gold) 12%, transparent);
  border-color: var(--accent-gold);
  color: var(--accent-gold);
}
.app-topbar-focus-icon {
  display: inline-flex; align-items: center; justify-content: center;
  width: 16px; height: 16px;
  flex: 0 0 auto;
}
.app-topbar-focus-icon svg {
  width: 100%; height: 100%; display: block;
}

/* Shell-hosted screen padding (rem-based for a11y scaling). */
.app-content > .screen {
  display: block;
  width: 100%;
  max-width: none;
  margin: 0 auto;
  padding: 1rem 3rem 3rem;
  box-sizing: border-box;
  align-items: stretch;
}
@media (max-width: 640px) {
  .app-content > .screen { padding: 0.5rem; }
}
/* Per-screen max-width restorations — specificity (0,3,0) beats shell's (0,2,0). */
.app-content > .screen.recruit-screen     { max-width: 1300px; }
.app-content > .screen.deploy-screen,
.app-content > .screen.map-select-screen,
.app-content > .screen.game-screen        { max-width: 1600px; }
.app-content > .screen > * + * {
  margin-top: 1.5rem;
}
@media (max-width: 640px) {
  .app-content > .screen > * + * { margin-top: 1rem; }
}
/* width:100% on direct children stops short sections shrink-wrapping. */
.app-content > .screen.legal-screen > *,
.app-content > .screen.about-screen > *,
.app-content > .screen.static-page > * {
  width: 100%;
  box-sizing: border-box;
}

/* Gameover overrides shell default; owns vertical rhythm via gap. */
.app-content > .screen.gameover-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  max-width: 1500px;
}
.app-content > .screen.gameover-screen > * + * { margin-top: 0; }



.app-shell.is-focus .app-sidebar,
.app-shell.is-focus .app-topbar,
.app-shell.is-focus .app-footer {
  display: none;
}
.app-shell.is-focus .app-main {
  margin-left: 0;
}
.app-shell.is-focus .app-content {
  height: 100vh;
  max-height: 100vh;
}

.app-focus-exit {
  display: none;
  position: fixed;
  top: 12px; right: 12px;
  z-index: 1200;
  align-items: center; gap: 6px;
  padding: 6px 12px;
  background: var(--bg-card);
  border: 1px solid var(--accent-gold);
  border-radius: 999px;
  color: var(--accent-gold);
  font-size: 0.82rem;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(0,0,0,0.35);
  transition: background 0.12s ease, transform 0.12s ease;
}
.app-focus-exit:hover {
  background: color-mix(in srgb, var(--accent-gold) 12%, transparent);
  transform: translateY(-1px);
}
.app-focus-exit svg {
  width: 16px; height: 16px; display: block;
}
.app-shell.is-focus .app-focus-exit {
  display: inline-flex;
}

.app-user-chip {
  display: flex; align-items: center; gap: 8px;
  padding: 5px 12px 5px 5px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 999px;
  cursor: pointer;
  user-select: none;
  font: inherit;
  color: var(--text-primary);
  transition: background 0.12s ease, border-color 0.12s ease;
}
.app-user-chip:hover {
  background: var(--bg-hover);
  border-color: color-mix(in srgb, var(--accent-gold) 40%, transparent);
}
.app-user-avatar {
  width: 28px; height: 28px;
  border-radius: 50%;
  background: var(--accent-gold);
  color: #000;
  font-weight: 800;
  display: flex; align-items: center; justify-content: center;
  font-size: 0.88rem;
  flex: 0 0 auto;
  transition: background 0.2s ease, box-shadow 0.2s ease;
}
/* Admin avatar shared by topbar (28px) + profile card (64px below).
   `:where()` keeps base specificity at (0,1,0) so the profile.css
   .profile-avatar-large.is-admin override (0,2,0) wins regardless of import order. */
:where(.app-user-avatar, .profile-avatar-large).is-admin {
  --admin-avatar-ring:             1px;
  --admin-avatar-glow-r:           6px;
  --admin-avatar-glow-r-peak:     10px;
  --admin-avatar-glow-spread:      1px;
  --admin-avatar-glow-spread-peak: 2px;
  --admin-avatar-glow-color:       color-mix(in srgb, var(--accent-gold) 55%, transparent);
  --admin-avatar-glow-color-peak:  color-mix(in srgb, var(--accent-gold) 70%, transparent);

  background:
    linear-gradient(135deg,
      var(--accent-imperial-hi)     0%,
      var(--accent-imperial)       55%,
      var(--accent-imperial-shadow) 100%);
  color: var(--accent-gold);
  box-shadow:
    0 0 0 var(--admin-avatar-ring) var(--accent-gold),
    0 0 var(--admin-avatar-glow-r) var(--admin-avatar-glow-spread) var(--admin-avatar-glow-color),
    inset 0 1px 0 0 rgba(255, 235, 180, 0.35);
  animation: admin-avatar-pulse 3s ease-in-out infinite alternate;
  text-shadow: 0 1px 0 rgba(0, 0, 0, 0.4);
}
.profile-avatar-large.is-admin {
  --admin-avatar-ring:             2px;
  --admin-avatar-glow-r:          14px;
  --admin-avatar-glow-r-peak:     22px;
  --admin-avatar-glow-spread:      2px;
  --admin-avatar-glow-spread-peak: 4px;
}
/* var() evaluates per-element; one keyframe drives both sizes. */
@keyframes admin-avatar-pulse {
  from { box-shadow:
    0 0 0 var(--admin-avatar-ring) var(--accent-gold),
    0 0 var(--admin-avatar-glow-r) var(--admin-avatar-glow-spread) var(--admin-avatar-glow-color),
    inset 0 1px 0 0 rgba(255, 235, 180, 0.35); }
  to   { box-shadow:
    0 0 0 var(--admin-avatar-ring) var(--accent-gold),
    0 0 var(--admin-avatar-glow-r-peak) var(--admin-avatar-glow-spread-peak) var(--admin-avatar-glow-color-peak),
    inset 0 1px 0 0 rgba(255, 235, 180, 0.45); }
}
@media (prefers-reduced-motion: reduce) {
  :where(.app-user-avatar, .profile-avatar-large).is-admin { animation: none; }
}
.app-user-chip.is-admin:hover .app-user-avatar.is-admin {
  box-shadow:
    0 0 0 var(--admin-avatar-ring) var(--accent-gold),
    0 0 12px 2px color-mix(in srgb, var(--accent-gold) 75%, transparent),
    inset 0 1px 0 0 rgba(255, 235, 180, 0.45);
}
.app-user-identity {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  line-height: 1.1;
}
.app-user-name {
  font-size: 0.9rem;
  line-height: 1;
}
.app-user-elo {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--accent-gold);
  letter-spacing: 0.3px;
}
.app-user-elo-loading {
  visibility: hidden;
}
.app-user-elo .elo-stars,
.app-user-elo .elo-stars-full,
.app-user-elo .elo-stars-compact {
  font-size: 0.7rem;
  line-height: 1;
}
.app-user-menu {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  min-width: 180px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.5);
  overflow: hidden;
  z-index: 1000;
}
.app-user-menu-item {
  display: block;
  width: 100%;
  text-align: left;
  padding: 10px 14px;
  background: transparent;
  border: 0;
  color: var(--text-primary);
  cursor: pointer;
  font: inherit;
  font-size: 0.9rem;
  transition: background 0.1s ease;
}
.app-user-menu-item:hover {
  background: var(--bg-hover);
}
.app-user-menu-sep {
  height: 1px;
  background: var(--border-color);
  margin: 2px 0;
}

/* position:relative anchors dropdown under the bell, not user-chip. */
.app-topbar-bell-wrap {
  position: relative;
  display: inline-flex;
}
.app-topbar-bell {
  position: relative;
  background: transparent;
  border: 1px solid var(--border-color);
  color: var(--text-muted);
  font-size: 1rem;
  padding: 4px 10px;
}
.app-topbar-bell:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}
.app-topbar-bell.has-notif {
  border-color: var(--accent-gold);
  color: var(--accent-gold);
}
.app-topbar-bell-dot {
  position: absolute;
  top: 4px;
  right: 6px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent-red);
  box-shadow: 0 0 0 2px var(--bg-card);
}
.app-notif-menu {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  min-width: 280px;
  max-width: 360px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.5);
  overflow: hidden;
  z-index: 1000;
}
.app-notif-empty {
  padding: 14px 16px;
  color: var(--text-muted);
  font-size: 0.88rem;
  text-align: center;
}
.app-notif-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border-color);
}
.app-notif-item:last-child { border-bottom: 0; }
.app-notif-body {
  flex: 1 1 auto;
  color: var(--text-primary);
  font-size: 0.9rem;
  line-height: 1.4;
}
.app-notif-actions {
  display: flex;
  gap: 6px;
  flex: 0 0 auto;
}
.app-notif-btn {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 1px solid var(--border-color);
  background: var(--bg-panel);
  color: var(--text-primary);
  font-size: 1rem;
  cursor: pointer;
  transition: background 0.12s ease, border-color 0.12s ease, color 0.12s ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.app-notif-btn:hover { background: var(--bg-hover); }
.app-notif-btn-accept:hover {
  background: color-mix(in srgb, var(--accent-green) 18%, transparent);
  border-color: var(--accent-green);
  color: var(--accent-green);
}
.app-notif-btn-decline:hover {
  background: color-mix(in srgb, var(--accent-red) 18%, transparent);
  border-color: var(--accent-red);
  color: var(--accent-red);
}

.app-content {
  flex: 1 1 auto;
  overflow-y: auto;
  overflow-x: hidden;
  min-height: 0;
  min-width: 0;
  background: var(--bg-main);
}

/* Override screens with their own min-height: 100vh inside the shell. */
.app-content .admin-feedback-screen {
  min-height: 100% !important;
}

.app-shell.is-collapsed .app-sidebar { width: 56px; }

.app-shell.is-collapsed .app-sidebar-brandname,
.app-shell.is-collapsed .app-sidebar-logo,
.app-shell.is-collapsed .app-nav-label,
.app-shell.is-collapsed .app-nav-item-label,
.app-shell.is-collapsed .app-nav-item-ext { display: none; }

.app-shell.is-collapsed .app-sidebar-brand {
  justify-content: center;
  padding: 0;
  /* height stays 60px so brand border remains aligned with topbar border. */
}
.app-shell.is-collapsed .app-sidebar-collapse {
  transform: scaleX(-1); /* flip ❮ to point right */
  margin: 0 auto; /* defeat expanded-layout's margin-left: auto */
  width: 32px; height: 32px;
  font-size: 0.95rem;
}
.app-shell.is-collapsed .app-sidebar-nav {
  padding-left: 4px;
  padding-right: 4px;
}
.app-shell.is-collapsed .app-sidebar-presence {
  justify-content: center;
  padding: 10px 0;
  margin: 0 auto 6px;
  width: 44px;
  gap: 0;
}
.app-shell.is-collapsed .app-sidebar-presence-count,
.app-shell.is-collapsed .app-sidebar-presence-label {
  display: none;
}
.app-shell.is-collapsed .app-nav-section {
  padding: 4px 0;
}
.app-shell.is-collapsed .app-nav-item {
  width: 44px;
  margin: 0 auto;
  justify-content: center;
  padding: 10px 0;
  gap: 0;
  border-left: 0;
  border-radius: 8px;
}
.app-shell.is-collapsed .app-nav-item.is-active {
  border-left: 0;
  background: color-mix(in srgb, var(--accent-gold) 14%, transparent);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--accent-gold) 50%, transparent);
}

/* Hidden on desktop; mobile @media re-surfaces. */
.app-nav-item.nav-item-mobile-more { display: none; }

.app-mobile-more-close { display: none; }

.app-mobile-more-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 499; /* behind sidebar (z:500), above page */
  cursor: pointer;
  animation: app-backdrop-fade 180ms ease-out;
}
.app-shell.is-mobile-more-open .app-mobile-more-backdrop {
  display: block;
}
@keyframes app-backdrop-fade {
  from { opacity: 0; }
  to   { opacity: 1; }
}
@media (prefers-reduced-motion: reduce) {
  .app-mobile-more-backdrop { animation: none; }
  .app-sidebar { transition: none !important; }
}

@media (max-width: 900px) {
  .app-sidebar { width: 200px; }
  .app-sidebar-brandname { font-size: 0.98rem; }
  .app-topbar { padding: 10px 16px; }
}

/* Mobile: sidebar becomes a fixed bottom-nav bar; desktop "collapsed" is ignored. */
@media (max-width: 640px) {
  .app-shell {
    display: block;
    min-height: 100vh;
  }
  .app-main {
    padding-bottom: 64px; /* room for the fixed bottom bar */
    min-height: 100vh;
  }
  .app-sidebar {
    position: fixed;
    /* CRITICAL: reset top to auto. Base desktop sets `top: 0` for sticky;
       in fixed positioning, top always wins over bottom when both set —
       without this reset the sidebar renders at viewport top (60px tall). */
    top: auto;
    bottom: 0; left: 0; right: 0;
    width: 100%;
    height: 60px;
    max-height: 60px;
    border-right: 0;
    border-top: 1px solid var(--border-color);
    z-index: 500;
    transition: height 0.22s ease, max-height 0.22s ease;
  }
  .app-shell.is-collapsed .app-sidebar { width: 100%; }
  .app-sidebar-brand { display: none; }
  .app-sidebar-nav {
    flex-direction: row;
    padding: 4px 6px;
    gap: 0;
    overflow-x: auto;
    overflow-y: hidden;
    align-items: stretch;
  }
  /* display:contents dissolves section wrappers so .app-nav-item becomes a
     direct flex child — enables global ordering across sections via `order:`. */
  .app-nav-section {
    display: contents;
  }
  .app-nav-label { display: none; }
  .app-sidebar-live-match {
    flex: 0 0 44px;
    width: 44px;
    margin: 0 4px;
    padding: 6px 0;
    gap: 0;
    justify-content: center;
    align-items: center;
    border-radius: 8px;
  }
  .app-sidebar-live-body,
  .app-sidebar-live-arrow { display: none; }
  .app-sidebar-live-dot { width: 10px; height: 10px; }
  .app-sidebar-bottom {
    display: contents;
    margin-top: 0;
  }
  .app-nav-divider { display: none; }
  .app-nav-item {
    flex: 1 1 0;
    min-width: 60px;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    padding: 6px 4px 4px;
    /* Kill desktop borders (1px hairlines on HiDPI). Active indicator moves to ::after. */
    border: 0;
    border-radius: 0;
    font-size: 0.68rem;
    position: relative;
  }
  .app-nav-item::after {
    content: "";
    position: absolute;
    left: 18%;
    right: 18%;
    bottom: 0;
    height: 2px;
    background: transparent;
    border-radius: 2px;
    pointer-events: none;
  }
  .app-nav-item.is-active::after {
    background: var(--accent-gold);
  }
  .app-nav-item-icon { width: 24px; height: 24px; }
  /* Bottom bar is icons-only; labels re-show in More drawer via override below. */
  .app-nav-item-label { display: none !important; }
  .app-nav-item.is-active {
    background: transparent;
    box-shadow: none;
    color: var(--accent-gold);
  }
  .app-nav-item-ext { display: none; }

  /* Mobile bar: hide all, re-show 3 primaries + More toggle; overflow → drawer. */
  .app-nav-item                        { display: none; order: 99; }
  .app-nav-item.nav-item-battlefield    { display: flex; order: 1; }
  .app-nav-item.nav-item-warroom        { display: flex; order: 2; }
  .app-nav-item.nav-item-feedback       { display: flex; order: 3; }
  .app-nav-item.nav-item-mobile-more    { display: flex; order: 4; }
  /* Orders below control vertical ordering when drawer is open. */
  .app-nav-item.nav-item-rules          { order: 5; }
  .app-nav-item.nav-item-leaderboard    { order: 6; }
  .app-nav-item.nav-item-profile        { order: 7; }
  .app-nav-item.nav-item-discord        { order: 8; }
  .app-nav-item.nav-item-dashboard      { order: 9; }
  .app-nav-item.nav-item-scenarios      { order: 10; }
  .app-nav-item.nav-item-feedback-inbox { order: 11; }

  .app-shell.is-mobile-more-open .app-sidebar {
    height: calc(100vh - 0px);
    max-height: 100vh;
    overflow-y: auto;
    box-shadow: 0 -16px 40px rgba(0, 0, 0, 0.55);
    padding-top: env(safe-area-inset-top, 0px);
  }
  .app-shell.is-mobile-more-open .app-mobile-more-close {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 10;
    padding: 10px 14px;
    background: var(--bg-card);
    border-bottom: 1px solid var(--border-color);
  }
  .app-shell.is-mobile-more-open .app-mobile-more-close button {
    width: 36px; height: 36px;
    padding: 0;
    border-radius: 50%;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    font-size: 1.4rem; line-height: 1;
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    transition: background 0.12s ease, color 0.12s ease;
  }
  .app-shell.is-mobile-more-open .app-mobile-more-close button:hover {
    background: var(--bg-hover);
    color: var(--accent-gold);
  }
  .app-shell.is-mobile-more-open .app-sidebar-nav {
    flex-direction: column;
    align-items: stretch;
    padding: 12px 10px 76px;
    gap: 2px;
    overflow: visible;
  }
  .app-shell.is-mobile-more-open .app-nav-label {
    display: block;
    padding: 10px 12px 6px;
    font-size: 0.66rem;
    color: var(--text-muted);
  }
  .app-shell.is-mobile-more-open .app-nav-item {
    display: flex;
    flex: 0 0 auto;
    flex-direction: row;
    justify-content: flex-start;
    align-items: center;
    width: 100%;
    min-width: 0;
    padding: 12px 16px;
    gap: 14px;
    font-size: 0.95rem;
    border-radius: 6px;
  }

  .app-shell.is-mobile-more-open .app-nav-item,
  .app-shell.is-mobile-more-open .app-nav-label {
    order: 0;
  }
  .app-shell.is-mobile-more-open .app-nav-item.nav-item-mobile-more {
    display: none;
  }
  /* Drawer rows show labels — !important beats bottom-bar's `display:none !important`. */
  .app-shell.is-mobile-more-open .app-nav-item-label {
    display: block !important;
    font-size: 0.9rem;
    text-transform: none;
    letter-spacing: 0.2px;
    text-align: left;
  }
  .app-shell.is-mobile-more-open .app-nav-item-icon {
    width: 22px; height: 22px;
    flex: 0 0 auto;
  }
  .app-shell.is-mobile-more-open .app-nav-item-label {
    text-align: left;
    text-transform: none;
    letter-spacing: 0;
    font-size: 0.95rem;
    line-height: 1.2;
    width: auto;
  }
  .app-shell.is-mobile-more-open .app-nav-item.is-active {
    background: color-mix(in srgb, var(--accent-gold) 10%, transparent);
    color: var(--accent-gold);
  }
  .app-shell.is-mobile-more-open .app-nav-item::after {
    display: none;
  }
  .app-sidebar-collapse { display: none; }
  .app-topbar { padding: 10px 12px; gap: 8px; }
  .app-user-identity { display: none; }
  .app-user-chip { padding: 5px; }
  .app-page-title { font-size: 1.05rem; }
  .app-topbar-quickplay { padding: 6px 10px; font-size: 0.82rem; }
  .app-topbar-focus { padding: 6px 8px; }
  .app-sidebar-presence { display: none; }
}
@media (max-width: 480px) {
}

@media (max-width: 640px), (max-height: 600px) {
  .app-shell.is-focus .game-screen .game-main > .left-col-wrap,
  .app-shell.is-focus .game-screen .game-main > .right-panel,
  .app-shell.is-focus .game-screen .group-status-bar,
  .app-shell.is-focus .game-screen .ai-mode-panel,
  .app-shell.is-focus .game-screen .setup-stepper,
  .app-shell.is-focus .game-screen .readiness-bar {
    display: none !important;
  }
  .app-shell.is-focus .game-screen .game-main {
    padding: 0;
    margin: 0;
    gap: 8px;
  }
  .app-shell.is-focus .game-screen .game-main > .board-area {
    width: 100%;
    padding: 0;
  }
}

@media (orientation: landscape) and (max-height: 600px) {
  .game-screen .game-main { flex-direction: column; align-items: center; }
  .game-screen .board-area {
    --cell-size: clamp(15px, 4.2vh, 38px);
    max-height: none;
    align-items: center;
  }
  /* Keep the stat bar from forcing the board-area wider than the board itself. */
  .game-screen .player-bar { flex-wrap: wrap; }
  .game-screen .game-main > .left-col-wrap,
  .game-screen .game-main > .right-panel {
    width: 100%;
    max-width: 600px;
    max-height: none;
    overflow: visible;
  }
}

/* Ultra-focus: pref-gated. Shell carries .is-ultra-focus + .is-focus; strips
   side panels, replaces with slim action stack. Board-area stays. */
.ultra-focus-actions { display: none; }
.app-shell.is-ultra-focus .game-screen .game-main > .left-col-wrap,
.app-shell.is-ultra-focus .game-screen .game-main > .right-panel,
.app-shell.is-ultra-focus .game-screen .game-end-turn-mobile {
  display: none !important;
}
.app-shell.is-ultra-focus .game-screen .ultra-focus-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px 8px;
  width: 100%;
  max-width: 420px;
  margin: 0 auto;
  box-sizing: border-box;
}
.app-shell.is-ultra-focus .game-screen .ultra-focus-actions > .btn-end-turn {
  width: 100%;
  justify-content: center;
  padding: 12px 16px;
  font-size: 1rem;
  font-weight: 700;
}
.app-shell.is-ultra-focus .game-screen .ultra-focus-actions-row {
  display: flex;
  gap: 8px;
}
.app-shell.is-ultra-focus .game-screen .ultra-focus-actions-row > .btn {
  flex: 1 1 0;
  min-width: 0;
  justify-content: center;
}
.app-shell.is-ultra-focus .game-screen .game-main {
  justify-content: center;
}
