/* ============================================================
   BlitzBrawl — portal styles
   Dark base, electric-blue accent. Dependency-free.
   ============================================================ */

:root {
  --bg: #0e0f13;
  --bg-elev: #15171d;
  --bg-card: #16181f;
  --bg-card-hover: #1c1f29;
  --border: #262a35;
  --border-hover: #394150;
  --text: #f4f4f5;
  --text-dim: #9aa0ad;
  --text-faint: #8b919e; /* AA on both --bg and --bg-card for small text */
  --accent: #3b82f6;            /* brand accent: borders, glows, chips */
  --accent-hover: #2f6fe0;
  --accent-strong: #2563eb;     /* white-text-on-accent (AA): buttons, live badge */
  --accent-strong-hover: #1d4ed8;
  --accent-soft: rgba(59, 130, 246, 0.14);
  --accent-glow: rgba(59, 130, 246, 0.35);
  --danger: #f87171;
  --ok: #4ade80;
  --radius: 14px;
  --radius-sm: 9px;
  --maxw: 1160px;
  --font: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body { height: 100%; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  line-height: 1.5;
  overflow-x: hidden;
}
body.bb-modal-open { overflow: hidden; }

a { color: inherit; text-decoration: none; }
button { font-family: inherit; cursor: pointer; }
img { display: block; max-width: 100%; }

.hidden { display: none !important; }
/* The hidden attribute must win even over class-set display (e.g. .bb-btn). */
[hidden] { display: none !important; }

/* Ambient glow behind the page */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  background:
    radial-gradient(60% 50% at 50% -10%, rgba(59, 130, 246, 0.14), transparent 70%),
    radial-gradient(40% 40% at 90% 10%, rgba(124, 92, 255, 0.08), transparent 70%);
  pointer-events: none;
  z-index: 0;
}

/* ── Buttons (shared) ── */
.bb-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-elev);
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
  transition: background .15s, border-color .15s, transform .1s, box-shadow .15s;
}
.bb-btn:hover { border-color: var(--border-hover); background: var(--bg-card-hover); }
.bb-btn:active { transform: translateY(1px); }
.bb-btn-primary {
  background: var(--accent-strong);
  border-color: var(--accent-strong);
  color: #fff;
  box-shadow: 0 0 0 0 var(--accent-glow);
}
.bb-btn-primary:hover { background: var(--accent-strong-hover); border-color: var(--accent-strong-hover); box-shadow: 0 6px 24px var(--accent-glow); }

/* Visible keyboard focus on every interactive control (WCAG 2.4.7). */
:where(a, button, input, select, textarea, [tabindex]):focus-visible {
  outline: 2px solid #9ec5ff;
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}
.bb-btn-danger { color: var(--danger); border-color: rgba(248, 113, 113, .3); background: rgba(248, 113, 113, .06); }
.bb-btn-danger:hover { background: rgba(248, 113, 113, .12); border-color: rgba(248, 113, 113, .5); }
.bb-link {
  background: none; border: 0; color: var(--accent); font-size: 13px; padding: 6px 0; cursor: pointer;
}
.bb-link:hover { text-decoration: underline; }

/* ============================================================
   Inputs
   ============================================================ */
.bb-input {
  padding: 11px 13px; font-size: 16px; font-family: inherit;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: #1a1c22; color: var(--text); outline: none; width: 100%;
}
.bb-input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

/* ============================================================
   Top nav
   ============================================================ */
.bb-nav {
  position: sticky; top: 0; z-index: 50;
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px;
  padding: 14px clamp(16px, 4vw, 40px);
  background: rgba(14, 15, 19, 0.78);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.bb-nav-logo { height: 30px; width: auto; }
.bb-nav-actions { display: flex; align-items: center; gap: 10px; }
#bb-account-btn.is-signed-in { border-color: var(--accent); color: #fff; background: var(--accent-soft); }

/* ============================================================
   Layout shell
   ============================================================ */
.bb-main { position: relative; z-index: 1; max-width: var(--maxw); margin: 0 auto; padding: 0 clamp(16px, 4vw, 40px) 64px; }

.bb-hero { text-align: center; padding: clamp(40px, 8vw, 88px) 0 clamp(28px, 5vw, 52px); }
.bb-hero h1 {
  font-size: clamp(2rem, 7vw, 3.6rem);
  font-weight: 800;
  letter-spacing: -0.03em;
  line-height: 1.05;
}
.bb-hero h1 .accent { color: var(--accent); }
.bb-hero p { margin-top: 14px; color: var(--text-dim); font-size: clamp(1rem, 2.5vw, 1.2rem); }

.bb-section-head {
  display: flex; align-items: baseline; gap: 10px;
  margin: 8px 0 18px;
}
.bb-section-head h2 { font-size: 1.1rem; font-weight: 700; letter-spacing: -0.01em; }
.bb-section-head .muted { color: var(--text-faint); font-size: .85rem; }

/* ============================================================
   Game grid + tiles
   ============================================================ */
.bb-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 20px;
}
.game-card {
  display: flex; flex-direction: column;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  transition: transform .18s, border-color .18s, box-shadow .18s;
}
.game-card:hover {
  transform: translateY(-6px);
  border-color: var(--border-hover);
  box-shadow: 0 16px 44px rgba(0, 0, 0, .5);
}
.tile-art { position: relative; aspect-ratio: 16 / 9; overflow: hidden; background: #0c0d12; }
/* Square icons (1:1) for the platform catalog — overrides 16:9 when present. */
.tile-art.tile-art-square { aspect-ratio: 1 / 1; border-radius: var(--radius) var(--radius) 0 0; }
.tile-art img { width: 100%; height: 100%; object-fit: cover; transition: transform .35s; }
.game-card:hover .tile-art img { transform: scale(1.06); }
.tile-art::after {
  content: ''; position: absolute; inset: 0;
  box-shadow: inset 0 -60px 60px -40px rgba(0, 0, 0, .7);
  pointer-events: none;
}
/* Square tiles get a per-game accent glow on hover. */
.game-card:hover .tile-art-square {
  box-shadow: 0 0 0 1px var(--tile-accent, var(--accent)), 0 0 24px rgba(var(--tile-accent, 59, 130, 246), .2);
}
.tile-badge {
  position: absolute; top: 10px; right: 10px;
  font-size: 11px; font-weight: 700; letter-spacing: .3px;
  padding: 5px 9px; border-radius: 999px;
  backdrop-filter: blur(4px);
}
.tile-badge-live { background: var(--accent-strong); color: #fff; box-shadow: 0 0 16px var(--accent-glow); }
.tile-badge-soon { background: rgba(255, 255, 255, .1); color: var(--text); border: 1px solid rgba(255, 255, 255, .14); }

.tile-body { padding: 14px 16px 16px; display: flex; flex-direction: column; gap: 6px; }
.tile-title { font-size: 1.05rem; font-weight: 700; letter-spacing: -0.01em; }
.tile-tagline { color: var(--text-dim); font-size: .9rem; }
.tile-meta { display: flex; align-items: center; gap: 8px; margin-top: 6px; }
.tile-players { color: var(--text-faint); font-size: .8rem; }
.chip {
  font-size: .72rem; font-weight: 600; letter-spacing: .4px;
  padding: 3px 9px; border-radius: 999px;
  background: var(--accent-soft); color: #bcd2ff; border: 1px solid rgba(59, 130, 246, .25);
}

/* ============================================================
   Footer
   ============================================================ */
.bb-footer {
  position: relative; z-index: 1;
  border-top: 1px solid var(--border);
  padding: 28px clamp(16px, 4vw, 40px);
  display: flex; flex-direction: column; align-items: center; gap: 10px;
  text-align: center;
}
.bb-footer-links { display: flex; gap: 20px; font-size: .85rem; color: var(--text-dim); flex-wrap: wrap; justify-content: center; }
.bb-footer-links a:hover { color: var(--text); }
.bb-footer-copy { font-size: .78rem; color: var(--text-faint); }

/* ============================================================
   Account modal
   ============================================================ */
.bb-modal-backdrop {
  position: fixed; inset: 0; z-index: 1100;
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
  background: rgba(6, 7, 10, .68);
  backdrop-filter: blur(4px);
}
.bb-modal-backdrop[hidden] { display: none; }
.bb-modal {
  position: relative;
  width: 100%; max-width: 400px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px 24px 22px;
  box-shadow: 0 30px 80px rgba(0, 0, 0, .6);
}
.bb-modal-close {
  position: absolute; top: 12px; right: 14px;
  background: none; border: 0; color: var(--text-dim);
  font-size: 24px; line-height: 1; padding: 4px 8px; border-radius: 6px;
}
.bb-modal-close:hover { color: var(--text); background: var(--bg-card-hover); }
.bb-modal-title { font-size: 1.25rem; font-weight: 800; margin-bottom: 6px; }
.bb-modal-sub { color: var(--text-dim); font-size: .92rem; margin-bottom: 16px; }
.bb-modal [data-form] { display: flex; flex-direction: column; gap: 10px; }
.bb-modal-note { color: var(--text-faint); font-size: .8rem; margin-top: 12px; }
.bb-field { display: block; font-size: .8rem; color: var(--text-dim); margin: 4px 0 0; }
.bb-row { display: flex; gap: 8px; margin-top: 6px; }
.bb-row .bb-input { flex: 1; }
.bb-modal-actions { display: flex; gap: 10px; margin-top: 18px; }
.bb-modal-actions .bb-btn { flex: 1; }
.bb-modal-status { min-height: 1.2em; margin-top: 12px; font-size: .85rem; }
.bb-modal-status.is-error { color: var(--danger); }
.bb-modal-status.is-success { color: var(--ok); }

/* ============================================================
   Play page
   ============================================================ */
body.bb-play { display: flex; flex-direction: column; min-height: 100vh; min-height: 100dvh; }
.bb-playbar {
  position: sticky; top: 0; z-index: 50;
  display: flex; align-items: center; gap: 14px;
  padding: 10px clamp(12px, 3vw, 24px);
  /* Keep controls clear of the notch in landscape (viewport-fit=cover). */
  padding-left: max(clamp(12px, 3vw, 24px), env(safe-area-inset-left));
  padding-right: max(clamp(12px, 3vw, 24px), env(safe-area-inset-right));
  background: rgba(14, 15, 19, .9);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.bb-playbar .back { display: inline-flex; align-items: center; gap: 6px; color: var(--text-dim); font-weight: 600; font-size: .9rem; }
.bb-playbar .back:hover { color: var(--text); }
.bb-playbar .spacer { flex: 1; }
#bb-play-title { font-size: 1rem; font-weight: 700; }

/* ── Auto-hide the playbar during play, with a pull-out reveal tab ──
   The bar is lifted OUT OF FLOW (position: fixed) so the game gets the whole
   viewport; the tab slides it back. Applied on small screens while a game is
   mounted (.bb-playing), and at any width in pseudo-fullscreen (.bb-pseudo-fs,
   the fallback where the browser has no element-fullscreen API). */
.bb-bar-toggle {
  display: none;
  position: fixed; top: 0; left: 50%; transform: translateX(-50%);
  z-index: 60; align-items: center; gap: 6px;
  padding: 3px 12px 5px;
  background: var(--bg-elev);
  border: 1px solid var(--border); border-top: 0;
  border-radius: 0 0 12px 12px;
  color: var(--text-dim);
  box-shadow: 0 4px 14px rgba(0, 0, 0, .4);
}
.bb-bar-toggle img { width: 18px; height: 18px; }
.bb-bar-toggle .chev { transition: transform .25s ease; }
body.bb-bar-open .bb-bar-toggle .chev { transform: rotate(180deg); }

@media (max-width: 768px) {
  body.bb-playing .bb-playbar {
    position: fixed; top: 0; left: 0; right: 0;
    transform: translateY(-100%);
    transition: transform .25s ease;
  }
  body.bb-playing.bb-bar-open .bb-playbar { transform: translateY(0); }
  body.bb-playing .bb-bar-toggle { display: inline-flex; }
}

body.bb-pseudo-fs .bb-playbar {
  position: fixed; top: 0; left: 0; right: 0;
  transform: translateY(-100%);
  transition: transform .25s ease;
}
body.bb-pseudo-fs.bb-bar-open .bb-playbar { transform: translateY(0); }
body.bb-pseudo-fs .bb-bar-toggle { display: inline-flex; }

.bb-stage {
  flex: 1; position: relative;
  display: flex; align-items: center; justify-content: center;
  background: radial-gradient(60% 60% at 50% 30%, #14161d, var(--bg));
  z-index: 1;
}
.bb-frame { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }
.bb-stage-msg {
  text-align: center; max-width: 460px; padding: 40px 24px;
}
.bb-stage-icon img { width: 240px; height: auto; margin: 0 auto 20px; border-radius: var(--radius); border: 1px solid var(--border); }
.bb-stage-msg h2 { font-size: 1.5rem; font-weight: 800; margin-bottom: 10px; }
.bb-stage-msg p { color: var(--text-dim); margin-bottom: 22px; }

/* ============================================================
   Legal pages
   ============================================================ */
.legal {
  position: relative; z-index: 1;
  max-width: 720px; margin: 0 auto; padding: 40px clamp(16px, 4vw, 24px) 72px;
}
.legal .back { display: inline-block; color: var(--accent); font-size: .85rem; margin-bottom: 24px; }
.legal h1 { font-size: 1.8rem; font-weight: 800; margin-bottom: 8px; }
.legal .updated { color: var(--text-faint); font-size: .82rem; margin-bottom: 28px; }
.legal h2 { font-size: 1.15rem; font-weight: 700; margin: 28px 0 10px; }
.legal p, .legal li { color: var(--text-dim); margin-bottom: 12px; }
.legal ul { padding-left: 22px; }
.legal a { color: var(--accent); }

/* ============================================================
   iOS "Add to Home Screen" hint (one-time, dismissible)
   ============================================================ */
.bb-a2hs {
  position: fixed; z-index: 80;
  left: 12px; right: 12px; bottom: calc(12px + env(safe-area-inset-bottom, 0px));
  display: flex; align-items: center; gap: 12px;
  padding: 12px 14px;
  background: var(--bg-elev);
  border: 1px solid var(--border-hover);
  border-radius: var(--radius);
  box-shadow: 0 10px 30px rgba(0, 0, 0, .5);
}
.bb-a2hs-icon { width: 44px; height: 44px; border-radius: 10px; flex: 0 0 auto; }
.bb-a2hs-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.bb-a2hs-text strong { font-size: .95rem; font-weight: 700; }
.bb-a2hs-text span { color: var(--text-dim); font-size: .82rem; line-height: 1.35; }
.bb-a2hs-dismiss {
  flex: 0 0 auto; align-self: stretch;
  padding: 0 14px; border: 0; border-radius: var(--radius-sm);
  background: var(--accent-strong); color: #fff; font-weight: 600; font-size: .85rem;
}
.bb-a2hs-dismiss:hover { background: var(--accent-strong-hover); }

/* ============================================================
   Responsive
   ============================================================ */
@media (max-width: 560px) {
  .bb-grid { grid-template-columns: 1fr; gap: 16px; }
  .bb-nav-logo { height: 26px; }
}

/* Respect reduced-motion: neutralize hover lift, zoom, and transitions. */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
  .game-card:hover { transform: none; }
  .game-card:hover .tile-art img { transform: none; }
}
