/*
 * BoardBazi game home: shared look for the screens outside active play
 * (the lobby, in browse and room states, and the results). Copy this file into the game unchanged as
 * /bb/game-home.css and load it before the game's own stylesheet.
 *
 * Everything is prefixed `bh-` so it never collides with the game's classes.
 * A game sets only the variables in the "Per game" block, on .bh-root.
 * Spec: README.md next to this file. Version 1.3 (2026-11-03).
 */

/* ---------- Tokens ---------- */
.bh-root {
  /* Per game: the only values a game may change */
  --bh-game: #f2b33d;                /* game accent, from its key art */
  --bh-game-soft: rgba(242, 179, 61, 0.16);
  --bh-art-pos: 50% 30%;             /* object-position of the blurred poster */

  /* Hub (fixed: same in every game) */
  --bh-font: 'Vazirmatn', system-ui, -apple-system, 'Segoe UI', Tahoma, sans-serif;
  --bh-bg: #0a0b10;
  --bh-raised: #12141c;
  --bh-elevated: #1a1d28;
  --bh-line: rgba(255, 255, 255, 0.08);
  --bh-line-strong: rgba(255, 255, 255, 0.16);
  --bh-text: #f5f3ee;
  --bh-muted: #a8a59c;
  --bh-dim: #6f6c66;
  --bh-gold: #f2b33d;
  --bh-gold-strong: #ffc65c;
  --bh-on-gold: #1d1404;
  --bh-ok: #34d399;
  --bh-warn: #fbbf24;
  --bh-danger: #fb7185;
  --bh-r-sm: 8px;
  --bh-r-md: 12px;
  --bh-r-lg: 18px;
  --bh-r-full: 9999px;
  --bh-ease: cubic-bezier(0.16, 1, 0.3, 1);
  --bh-tap: 44px;
  --bh-max: 720px;

  position: relative;
  isolation: isolate;
  font-family: var(--bh-font);
  background: var(--bh-bg);
  color: var(--bh-text);
  line-height: 1.7;
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
}

.bh-root *,
.bh-root *::before,
.bh-root *::after {
  box-sizing: border-box;
}

.bh-root :focus-visible {
  outline: 2px solid var(--bh-gold);
  outline-offset: 2px;
}

/* Lobby states: one screen, content swaps between "browse" and "room" */
.bh-screen[data-state='browse'] [data-when='room'],
.bh-screen[data-state='room'] [data-when='browse'] {
  display: none !important;
}

.bh-root [hidden],
.bh-hidden {
  display: none !important;
}

/* ---------- Screen frame ---------- */
.bh-screen {
  display: flex;
  flex-direction: column;
  min-height: calc(100dvh - 40px); /* 40px = BoardBazi bar */
  padding-bottom: env(safe-area-inset-bottom);
}

.bh-body {
  width: 100%;
  max-width: var(--bh-max);
  margin: 0 auto;
  padding: 0 16px 32px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* ---------- Art: the game's poster, blurred, behind every screen ---------- */
/* One per page, first child of .bh-root. Hide it (hidden) during active play. */
.bh-art {
  position: fixed;
  inset: 0;
  z-index: -1;
  overflow: hidden;
  pointer-events: none;
  background: var(--bh-bg);
}

.bh-art img {
  position: absolute;
  inset: -48px;
  width: calc(100% + 96px);
  height: calc(100% + 96px);
  object-fit: cover;
  object-position: var(--bh-art-pos);
  filter: blur(4px) saturate(1.2) brightness(0.7);
}

/* Lets the art show at the top, then calms it to near-solid behind the content */
.bh-art::after {
  content: '';
  position: absolute;
  inset: 0;
  background:
    radial-gradient(130% 80% at 50% 0%, rgba(10, 11, 16, 0), rgba(10, 11, 16, 0.5) 75%),
    linear-gradient(to bottom, rgba(10, 11, 16, 0.1) 0%, rgba(10, 11, 16, 0.4) 50%, rgba(10, 11, 16, 0.8) 100%);
}

/* ---------- Hero: game name over the art (no cover or box image) ---------- */
.bh-hero {
  width: 100%;
  max-width: var(--bh-max);
  margin: 0 auto;
  padding: 28px 16px 20px;
}

.bh-hero.bh-compact {
  padding-top: 16px;
}

/* Back to BoardBazi: top of the lobby hero */
.bh-back {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 36px;
  margin-bottom: 16px;
  padding-inline: 10px 14px;
  border-radius: var(--bh-r-full);
  background: rgba(10, 11, 16, 0.55);
  border: 1px solid var(--bh-line-strong);
  backdrop-filter: blur(8px);
  color: var(--bh-text);
  font-size: 0.85rem;
  font-weight: 700;
  text-decoration: none;
  transition: border-color 0.2s, background 0.2s;
}

.bh-back:hover {
  border-color: var(--bh-gold);
  background: rgba(10, 11, 16, 0.75);
}

.bh-back svg {
  flex-shrink: 0;
}

/* The arrow points to the start side: left in LTR, right in RTL */
[dir='rtl'] .bh-back svg {
  transform: scaleX(-1);
}

.bh-title {
  margin: 0;
  font-size: clamp(2.2rem, 9vw, 3.6rem);
  font-weight: 900;
  line-height: 1.15;
  background: linear-gradient(to bottom, #fff6d8 0%, #ffd77a 35%, var(--bh-gold) 60%, #b8721f 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 2px 0 #5a3208) drop-shadow(0 8px 20px rgba(0, 0, 0, 0.75));
}

.bh-compact .bh-title {
  font-size: clamp(1.6rem, 6vw, 2.2rem);
}

.bh-lead {
  margin: 8px 0 0;
  max-width: 34em;
  color: rgba(255, 255, 255, 0.9);
  font-size: 1rem;
  text-shadow: 0 2px 10px rgba(0, 0, 0, 0.8);
}

.bh-facts {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 14px 0 0;
  padding: 0;
  list-style: none;
}

/* ---------- Chips and tags ---------- */
.bh-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 12px;
  border-radius: var(--bh-r-full);
  background: rgba(10, 11, 16, 0.6);
  border: 1px solid var(--bh-line-strong);
  backdrop-filter: blur(8px);
  font-size: 0.85rem;
  font-weight: 600;
  white-space: nowrap;
}

.bh-chip-game {
  border-color: var(--bh-game);
  color: var(--bh-game);
}

.bh-tag {
  display: inline-block;
  padding: 0 8px;
  border-radius: var(--bh-r-full);
  background: var(--bh-game-soft);
  color: var(--bh-game);
  font-size: 0.75rem;
  font-weight: 700;
  line-height: 1.6rem;
  white-space: nowrap;
}

.bh-tag-bot {
  background: rgba(255, 255, 255, 0.08);
  color: var(--bh-muted);
}

/* ---------- Buttons ---------- */
.bh-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: var(--bh-tap);
  padding: 0 20px;
  border: 1px solid transparent;
  border-radius: var(--bh-r-full);
  font: inherit;
  font-size: 0.95rem;
  font-weight: 700;
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
  transition: transform 0.2s var(--bh-ease), background 0.2s, border-color 0.2s, box-shadow 0.2s;
}

.bh-btn:disabled,
.bh-btn[aria-disabled='true'] {
  opacity: 0.5;
  cursor: default;
}

.bh-btn-primary {
  background: var(--bh-gold);
  color: var(--bh-on-gold);
  box-shadow: 0 6px 20px rgba(242, 179, 61, 0.28);
}

.bh-btn-primary:hover:not(:disabled) {
  background: var(--bh-gold-strong);
  transform: translateY(-1px);
}

.bh-btn-ghost {
  background: rgba(255, 255, 255, 0.06);
  border-color: var(--bh-line-strong);
  color: var(--bh-text);
}

.bh-btn-ghost:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.12);
}

.bh-btn-danger {
  background: transparent;
  border-color: rgba(251, 113, 133, 0.4);
  color: var(--bh-danger);
}

.bh-btn-danger:hover:not(:disabled) {
  background: rgba(251, 113, 133, 0.12);
}

.bh-btn-link {
  min-height: var(--bh-tap);
  padding: 0 8px;
  background: none;
  border: 0;
  color: var(--bh-muted);
  font-weight: 600;
  text-decoration: underline;
  text-underline-offset: 4px;
}

.bh-btn-link:hover {
  color: var(--bh-text);
}

.bh-btn-lg {
  min-height: 52px;
  padding: 0 28px;
  font-size: 1.05rem;
}

.bh-btn-sm {
  min-height: 36px;
  padding: 0 14px;
  font-size: 0.85rem;
}

.bh-btn-block {
  width: 100%;
}

.bh-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

/* ---------- Cards ---------- */
.bh-card {
  padding: 18px;
  border-radius: var(--bh-r-lg);
  background: rgba(18, 20, 28, 0.86);
  border: 1px solid var(--bh-line);
  backdrop-filter: blur(12px);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.bh-card-feature {
  border-color: rgba(242, 179, 61, 0.35);
  background: linear-gradient(160deg, rgba(242, 179, 61, 0.12), rgba(18, 20, 28, 0.86) 55%);
}

/* One-line notice, e.g. "You were invited to room KX4P" */
.bh-note {
  margin: 0;
  padding: 10px 14px;
  border-radius: var(--bh-r-md);
  background: var(--bh-game-soft);
  border: 1px solid var(--bh-game);
  font-size: 0.92rem;
}

.bh-card-title {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 800;
  line-height: 1.4;
}

.bh-card-text,
.bh-muted {
  margin: 0;
  color: var(--bh-muted);
  font-size: 0.92rem;
}

.bh-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 260px), 1fr));
  gap: 12px;
}

.bh-section-title {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 8px 0 0;
  font-size: 1rem;
  font-weight: 800;
  color: var(--bh-muted);
}

.bh-section-title::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--bh-line-strong);
}

/* Resume banner: a game in progress for this player */
.bh-resume {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border-radius: var(--bh-r-md);
  background: rgba(52, 211, 153, 0.1);
  border: 1px solid rgba(52, 211, 153, 0.4);
}

.bh-resume > :first-child {
  flex: 1;
  min-width: 0;
}

.bh-pulse {
  display: inline-block;
  width: 8px;
  height: 8px;
  margin-inline-end: 6px;
  border-radius: 50%;
  background: var(--bh-ok);
  box-shadow: 0 0 0 0 rgba(52, 211, 153, 0.6);
  animation: bh-pulse 1.8s infinite;
}

@keyframes bh-pulse {
  70% { box-shadow: 0 0 0 8px rgba(52, 211, 153, 0); }
  100% { box-shadow: 0 0 0 0 rgba(52, 211, 153, 0); }
}

/* ---------- Form controls ---------- */
.bh-input {
  flex: 1;
  min-width: 0;
  min-height: var(--bh-tap);
  padding: 0 14px;
  border-radius: var(--bh-r-full);
  border: 1px solid var(--bh-line-strong);
  background: var(--bh-bg);
  color: var(--bh-text);
  font: inherit;
}

.bh-input:focus {
  border-color: var(--bh-gold);
  outline: none;
}

.bh-input-code {
  font-family: ui-monospace, 'SFMono-Regular', Menlo, monospace;
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: 0.25em;
  text-transform: uppercase;
  text-align: center;
}

.bh-row {
  display: flex;
  gap: 8px;
}

.bh-setting {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: var(--bh-tap);
  padding: 10px 0;
  border-top: 1px solid var(--bh-line);
  cursor: pointer;
}

.bh-setting small {
  display: block;
  color: var(--bh-muted);
  font-size: 0.82rem;
}

.bh-switch {
  appearance: none;
  flex-shrink: 0;
  position: relative;
  width: 44px;
  height: 26px;
  margin: 0;
  border-radius: var(--bh-r-full);
  background: rgba(255, 255, 255, 0.16);
  cursor: pointer;
  transition: background 0.2s;
}

.bh-switch::after {
  content: '';
  position: absolute;
  top: 3px;
  inset-inline-start: 3px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #fff;
  transition: inset-inline-start 0.2s var(--bh-ease);
}

.bh-switch:checked {
  background: var(--bh-gold);
}

.bh-switch:checked::after {
  inset-inline-start: 21px;
}

/* ---------- Open rooms list (lobby) ---------- */
.bh-rooms {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.bh-room-item {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 64px;
  padding: 10px 12px;
  border-radius: var(--bh-r-md);
  background: rgba(18, 20, 28, 0.86);
  border: 1px solid var(--bh-line);
  backdrop-filter: blur(12px);
  transition: border-color 0.2s;
}

.bh-room-item:hover {
  border-color: var(--bh-line-strong);
}

.bh-room-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  line-height: 1.5;
}

.bh-room-host {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 700;
}

.bh-room-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 10px;
  color: var(--bh-muted);
  font-size: 0.8rem;
}

/* Seat dots: filled = taken, outline = free */
.bh-room-dots {
  display: inline-flex;
  gap: 3px;
}

.bh-room-dots i {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  border: 1.5px solid var(--bh-game);
}

.bh-room-dots i.on {
  background: var(--bh-game);
}

.bh-room-item .bh-btn {
  flex-shrink: 0;
}

.bh-empty {
  padding: 20px 16px;
  border-radius: var(--bh-r-md);
  border: 1px dashed var(--bh-line-strong);
  color: var(--bh-muted);
  text-align: center;
  font-size: 0.92rem;
}

.bh-live {
  display: inline-flex;
  align-items: center;
  color: var(--bh-dim);
  font-size: 0.75rem;
  font-weight: 600;
}

/* ---------- Room (waiting) ---------- */
.bh-room-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.bh-room-code {
  font-family: ui-monospace, 'SFMono-Regular', Menlo, monospace;
  font-size: 2rem;
  font-weight: 800;
  letter-spacing: 0.2em;
  line-height: 1.2;
  color: var(--bh-gold);
}

.bh-label {
  display: block;
  color: var(--bh-dim);
  font-size: 0.78rem;
  font-weight: 700;
}

.bh-seats {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.bh-seat {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 56px;
  padding: 8px 12px;
  border-radius: var(--bh-r-md);
  background: var(--bh-elevated);
  border: 1px solid var(--bh-line);
}

.bh-seat-empty {
  background: transparent;
  border-style: dashed;
  color: var(--bh-dim);
}

.bh-seat-me {
  border-color: var(--bh-game);
}

.bh-seat-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 700;
}

.bh-seat-meta {
  color: var(--bh-muted);
  font-size: 0.82rem;
  white-space: nowrap;
}

.bh-avatar {
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--bh-seat-color, linear-gradient(135deg, var(--bh-gold), #e07b39));
  color: var(--bh-on-gold);
  font-weight: 800;
}

.bh-avatar-bot {
  background: rgba(255, 255, 255, 0.1);
  color: var(--bh-muted);
}

.bh-offline .bh-avatar {
  filter: grayscale(1);
  opacity: 0.5;
}

/* Sticky bottom bar for the main lobby / results actions on phones */
.bh-dock {
  position: sticky;
  bottom: 0;
  z-index: 5;
  margin: auto -16px 0;
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  background: linear-gradient(to top, var(--bh-bg) 70%, rgba(10, 11, 16, 0));
}

/* ---------- Results ---------- */
.bh-winner {
  text-align: center;
  padding: 24px 16px;
}

.bh-winner .bh-avatar {
  width: 72px;
  height: 72px;
  font-size: 1.8rem;
  box-shadow: 0 0 0 3px var(--bh-bg), 0 0 0 5px var(--bh-gold);
}

.bh-winner-name {
  margin: 12px 0 0;
  font-size: 1.5rem;
  font-weight: 900;
}

.bh-rank {
  flex-shrink: 0;
  width: 28px;
  text-align: center;
  font-weight: 900;
  color: var(--bh-dim);
}

.bh-delta {
  font-weight: 700;
  font-size: 0.85rem;
  white-space: nowrap;
  direction: ltr;
  unicode-bidi: isolate;
}

.bh-up { color: var(--bh-ok); }
.bh-down { color: var(--bh-danger); }

/* ---------- Overlays: sheet, toast, splash ---------- */
.bh-backdrop {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  background: rgba(0, 0, 0, 0.6);
}

.bh-sheet {
  width: 100%;
  max-width: 520px;
  max-height: 85dvh;
  overflow-y: auto;
  padding: 20px 16px calc(20px + env(safe-area-inset-bottom));
  border-radius: var(--bh-r-lg) var(--bh-r-lg) 0 0;
  background: var(--bh-raised);
  border: 1px solid var(--bh-line-strong);
  border-bottom: 0;
  animation: bh-up 0.3s var(--bh-ease);
}

@media (min-width: 640px) {
  .bh-backdrop { align-items: center; }
  .bh-sheet { border-radius: var(--bh-r-lg); border-bottom: 1px solid var(--bh-line-strong); }
}

@keyframes bh-up {
  from { transform: translateY(24px); opacity: 0; }
}

.bh-toasts {
  position: fixed;
  inset-inline: 0;
  bottom: calc(16px + env(safe-area-inset-bottom));
  z-index: 110;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
}

.bh-toast {
  max-width: calc(100% - 32px);
  padding: 10px 16px;
  border-radius: var(--bh-r-full);
  background: var(--bh-elevated);
  border: 1px solid var(--bh-line-strong);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
  font-size: 0.9rem;
  font-weight: 600;
  animation: bh-up 0.3s var(--bh-ease);
}

.bh-toast-error { border-color: rgba(251, 113, 133, 0.5); }

.bh-splash {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  background: var(--bh-bg);
  transition: opacity 0.4s;
}

.bh-splash.bh-done {
  opacity: 0;
  pointer-events: none;
}

.bh-splash-bar {
  width: 160px;
  height: 4px;
  border-radius: var(--bh-r-full);
  background: rgba(255, 255, 255, 0.12);
  overflow: hidden;
}

.bh-splash-fill {
  width: 0;
  height: 100%;
  background: var(--bh-gold);
  transition: width 0.3s;
}

.bh-skeleton {
  border-radius: var(--bh-r-md);
  background: linear-gradient(100deg, var(--bh-raised) 30%, var(--bh-elevated) 50%, var(--bh-raised) 70%);
  background-size: 300% 100%;
  animation: bh-shimmer 1.4s linear infinite;
}

@keyframes bh-shimmer {
  from { background-position: 100% 0; }
  to { background-position: 0 0; }
}

/* ---------- Wide screens ---------- */
@media (min-width: 1024px) and (min-height: 600px) {
  .bh-root { --bh-max: 960px; }
  .bh-hero { padding-top: 48px; }
}

/* ---------- Phone in landscape: shorter hero ---------- */
@media (max-height: 480px) and (orientation: landscape) {
  .bh-hero { padding-top: 12px; }
  .bh-back { margin-bottom: 8px; }
  .bh-lead { display: none; }
}

/* ---------- Narrow phones ---------- */
@media (max-width: 360px) {
  .bh-btn-lg { padding: 0 20px; }
  .bh-room-code { font-size: 1.6rem; }
  .bh-card { padding: 14px; }
}

@media (prefers-reduced-motion: reduce) {
  .bh-root *,
  .bh-root *::before,
  .bh-root *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
