/* ============================================================================
 * PokerEngine v1.2 — demo-sites base.css
 *
 * Layout primitives shared by all demo themes. Mobile-first (390px baseline),
 * desktop enhancements via @media (min-width: 768px). Consumes tokens.css
 * vars exclusively — zero hardcoded colors / fonts / radii.
 *
 * Sections :
 *   1. Reset + box-sizing
 *   2. Document + body root
 *   3. Typography
 *   4. Nav bar (mobile stack → desktop horizontal)
 *   5. Main content + footer
 *   6. Theme picker grid (1×9 mobile → 3×3 desktop)
 *   7. Embed slot container
 *   8. Auth forms (login + signup)
 *   9. Buttons + links
 *  10. Accessibility (focus states, sr-only)
 * ============================================================================ */

/* ---- 1. Reset + box-sizing ---- */
*,
*::before,
*::after {
  box-sizing: border-box;
}

body,
h1, h2, h3, h4, p, ul, ol, figure, blockquote {
  margin: 0;
}

ul, ol {
  padding: 0;
  list-style: none;
}

img,
picture {
  max-width: 100%;
  display: block;
}

button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}

/* ---- 2. Document + body root ---- */
html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

body.demo-site {
  background: var(--demo-bg);
  color: var(--demo-fg);
  font-family: var(--demo-font-body);
  line-height: 1.5;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ---- 3. Typography ---- */
h1, h2, h3 {
  font-family: var(--demo-font-display);
  line-height: 1.2;
  font-weight: 600;
}

h1 { font-size: 1.75rem; }
h2 { font-size: 1.4rem; }
h3 { font-size: 1.15rem; }

@media (min-width: 768px) {
  h1 { font-size: 2.25rem; }
  h2 { font-size: 1.65rem; }
  h3 { font-size: 1.25rem; }
}

a {
  color: var(--demo-accent);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

p {
  color: var(--demo-fg);
}

.demo-muted {
  color: var(--demo-muted);
}

/* ---- 4. Nav bar (mobile single-row hamburger → desktop horizontal) ----
 * Mobile (<768px) layout :
 *   row 1 : [brand] ........................... [hamburger button]
 *   row 2 : [.demo-nav__links] (open dropdown, includes user chrome
 *           at the very bottom, separated by a top border)
 * The user chrome (`Hi, $name` + Sign out) is hidden from the bar row
 * on mobile and surfaced inside the open dropdown via the adjacent-
 * sibling selector (.demo-nav__links.is-open ~ .demo-nav__user). This
 * keeps the closed bar balanced (brand left / hamburger right, no
 * empty space) at the cost of one extra tap to reach Sign out — owner-
 * validated trade-off 2026-05-06 (Option C).
 * Desktop (≥768px) :
 *   single horizontal row [brand] [links] [user] — hamburger hidden.
 */
.demo-nav {
  background: var(--demo-card-bg);
  border-bottom: 1px solid var(--demo-border);
  padding: 0.75rem 1rem;
}

.demo-nav__inner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 0.75rem;
  max-width: 1200px;
  margin: 0 auto;
}

.demo-nav__brand {
  font-family: var(--demo-font-display);
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--demo-fg);
  flex: 1 1 auto;
}

.demo-nav__brand a {
  color: inherit;
  text-decoration: none;
}

/* Hamburger : 3-bar icon, 44×44 hit target, animates to a close X
 * when aria-expanded="true". Hidden ≥768px. */
.demo-nav__toggle {
  appearance: none;
  background: transparent;
  border: 1px solid var(--demo-border);
  border-radius: var(--demo-radius);
  width: 44px;
  height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--demo-fg);
  flex-shrink: 0;
  order: 3; /* visually last on mobile (after brand + user chrome) */
}

.demo-nav__toggle:focus-visible {
  outline: 2px solid var(--demo-accent);
  outline-offset: 2px;
}

.demo-nav__toggle-icon {
  display: inline-block;
  position: relative;
  width: 18px;
  height: 14px;
}

.demo-nav__toggle-icon span {
  position: absolute;
  left: 0;
  width: 100%;
  height: 2px;
  background: currentColor;
  border-radius: 2px;
  transition: transform 160ms ease, opacity 160ms ease, top 160ms ease;
}

.demo-nav__toggle-icon span:nth-child(1) { top: 0; }
.demo-nav__toggle-icon span:nth-child(2) { top: 6px; }
.demo-nav__toggle-icon span:nth-child(3) { top: 12px; }

/* Hamburger → X morph when expanded */
.demo-nav__toggle[aria-expanded="true"] .demo-nav__toggle-icon span:nth-child(1) {
  top: 6px;
  transform: rotate(45deg);
}
.demo-nav__toggle[aria-expanded="true"] .demo-nav__toggle-icon span:nth-child(2) {
  opacity: 0;
}
.demo-nav__toggle[aria-expanded="true"] .demo-nav__toggle-icon span:nth-child(3) {
  top: 6px;
  transform: rotate(-45deg);
}

.demo-nav__links {
  /* Mobile default : collapsed dropdown. Expands to a full-width
   * vertical list (flex-basis 100%) only when .is-open is toggled on
   * by the hamburger JS, so the bar row stays compact. */
  display: none;
  flex-direction: column;
  gap: 0;
  flex-basis: 100%;
  order: 4; /* below the bar row : brand+user+hamburger row → links row */
  margin-top: 0.5rem;
  border-top: 1px solid var(--demo-border);
}

.demo-nav__links.is-open {
  display: flex;
}

.demo-nav__links a {
  color: var(--demo-fg);
  font-size: 0.95rem;
  padding: 0.75rem 0.5rem;
  min-height: 44px;
  display: flex;
  align-items: center;
  border-bottom: 1px solid var(--demo-border);
  text-decoration: none;
}

.demo-nav__links a:last-child {
  border-bottom: none;
}

.demo-nav__links a:hover,
.demo-nav__links a[aria-current="page"] {
  color: var(--demo-accent);
}

.demo-nav__user {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-size: 0.9rem;
  flex-shrink: 0;
  order: 2;
}

/* Mobile bar balance (T16r.0b Option C 2026-05-06) : on viewports
 * below the desktop breakpoint, the user chrome leaves the bar row
 * entirely and re-appears as the last item of the open dropdown.
 * Adjacent-sibling selector reaches the user div via the .is-open
 * trigger on .demo-nav__links — no DOM reorder, pure CSS state shift. */
@media (max-width: 767px) {
  .demo-nav__user {
    display: none;
  }
  .demo-nav__links.is-open ~ .demo-nav__user {
    display: flex;
    flex-basis: 100%;
    order: 5;
    padding: 0.75rem 0.5rem;
    border-top: 1px solid var(--demo-border);
    justify-content: flex-start;
  }
}

@media (min-width: 768px) {
  .demo-nav {
    padding: 1rem 1.5rem;
  }

  .demo-nav__inner {
    flex-wrap: nowrap;
    justify-content: space-between;
  }

  /* Hide hamburger entirely on desktop ; the links row is always
   * visible inline so no toggle is needed. */
  .demo-nav__toggle {
    display: none;
  }

  /* Desktop : links revert to inline horizontal list, always visible
   * regardless of the .is-open class (which is mobile-only state). */
  .demo-nav__links,
  .demo-nav__links.is-open {
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    gap: 0.5rem 1rem;
    flex: 1;
    flex-basis: auto;
    margin: 0 1.5rem;
    order: 1;
    border-top: none;
  }

  .demo-nav__links a {
    padding: 0.5rem 0.25rem;
    border-bottom: none;
  }

  .demo-nav__user {
    order: 2;
  }
}

/* ---- 4b. Secondary game-type nav (T16r.0 — layout only, switch logic
 * lands T16r.C). Sticky alone at top:0 because the primary `.demo-nav`
 * stays static (per scope-strict directive : no main-nav modification).
 * Once the user scrolls past the primary nav, the game-nav pins to the
 * viewport top so the cash/tournament selector stays accessible.
 *
 * Scope rationale per group (post T16r.0b cleanup 2026-05-06) :
 *   - Cash Games  : Hold'em NL active, Omaha PLO active.
 *   - Tournaments : MTT / Sit & Go / Spin & Go all disabled.
 * The visual cue for "coming soon" is now opacity 0.5 + cursor:not-
 * allowed alone — the prior Soon badge spans were dropped to free
 * horizontal space (was forcing scroll-overflow at 390px on every
 * theme). Click handlers + cookie persistence land in T16r.C; this
 * layer only carries `data-game` attributes for that wiring to
 * consume.
 */
.demo-game-nav {
  position: sticky;
  top: 0;
  z-index: 50;
  background: var(--demo-card-bg);
  border-bottom: 1px solid var(--demo-border);
  /* Min-height keeps the bar visually stable across themes whose font
   * rendering changes button intrinsic height. Padding-Y is small to
   * keep the bar ~44px total — finer than the primary nav on purpose. */
  min-height: 44px;
}

.demo-game-nav__scroll {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  max-width: 1200px;
  margin: 0 auto;
  padding: 0.25rem 1rem;
  /* Mobile : horizontal scroll instead of wrap. wrap would double the
   * bar height and consume vertical space; scroll preserves the 44px
   * height at the cost of swipe-to-discover. Owner directive. */
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: thin;
  white-space: nowrap;
  -webkit-overflow-scrolling: touch;
}

.demo-game-nav__group {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  flex-shrink: 0;
}

.demo-game-nav__label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--demo-muted);
  margin-right: 0.25rem;
  user-select: none;
}

.demo-game-nav__divider {
  flex-shrink: 0;
  width: 1px;
  height: 60%;
  min-height: 18px;
  background: var(--demo-border);
  margin: 0 0.25rem;
}

.demo-game-nav__item {
  appearance: none;
  background: transparent;
  border: 0;
  border-bottom: 2px solid transparent;
  border-radius: 0;
  color: var(--demo-fg);
  font-family: var(--demo-font-body);
  font-size: 0.9rem;
  font-weight: 500;
  /* Hit target ≥ 36px x 36px ; padding-Y deliberately smaller than the
   * primary nav links (which target 44px) so the secondary bar reads
   * as denser / utility. */
  padding: 0.4rem 0.6rem;
  min-height: 36px;
  cursor: pointer;
  transition: color 120ms ease, border-color 120ms ease, background 120ms ease;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

.demo-game-nav__item:hover:not([disabled]) {
  color: var(--demo-accent);
  background: rgba(127, 127, 127, 0.06);
}

.demo-game-nav__item:focus-visible {
  outline: 2px solid var(--demo-accent);
  outline-offset: -2px;
}

.demo-game-nav__item.is-active {
  color: var(--demo-accent);
  border-bottom-color: var(--demo-accent);
  background: rgba(127, 127, 127, 0.06);
}

.demo-game-nav__item.is-coming-soon,
.demo-game-nav__item[disabled] {
  opacity: 0.5;
  cursor: not-allowed;
  color: var(--demo-muted);
}

/* ---- 5. Main content + footer ---- */
.demo-main {
  flex: 1;
  padding: 1.5rem 1rem;
  max-width: 1200px;
  width: 100%;
  margin: 0 auto;
}

.demo-main--narrow {
  max-width: 640px;
}

.demo-footer {
  background: var(--demo-card-bg);
  border-top: 1px solid var(--demo-border);
  padding: 1rem;
  font-size: 0.85rem;
  color: var(--demo-muted);
  text-align: center;
}

@media (min-width: 768px) {
  .demo-main {
    padding: 2.5rem 1.5rem;
  }
}

/* ---- 6. Theme picker grid ---- */
.demo-picker {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1rem;
}

.demo-picker__card {
  background: var(--demo-card-bg);
  border: 1px solid var(--demo-border);
  border-radius: var(--demo-radius);
  box-shadow: var(--demo-shadow);
  overflow: hidden;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.demo-picker__card:hover {
  transform: translateY(-2px);
  box-shadow: var(--demo-shadow);
}

.demo-picker__card a {
  display: block;
  color: inherit;
  text-decoration: none;
  padding: 1rem;
  min-height: 44px;
}

.demo-picker__card a:hover {
  text-decoration: none;
}

.demo-picker__preview {
  height: 120px;
  border-radius: calc(var(--demo-radius) - 2px);
  margin-bottom: 0.75rem;
  position: relative;
  overflow: hidden;
}

.demo-picker__title {
  font-family: var(--demo-font-display);
  font-size: 1.05rem;
  font-weight: 600;
  margin-bottom: 0.25rem;
}

.demo-picker__tagline {
  font-size: 0.85rem;
  color: var(--demo-muted);
}

@media (min-width: 768px) {
  .demo-picker {
    grid-template-columns: repeat(3, 1fr);
    gap: 1.5rem;
  }

  .demo-picker__preview {
    height: 160px;
  }
}

/* ---- 7. Embed slot container ---- */
.embed-slot {
  background: var(--demo-card-bg);
  border: 1px dashed var(--demo-border);
  border-radius: var(--demo-radius);
  padding: 2rem 1rem;
  text-align: center;
  color: var(--demo-muted);
  min-height: 320px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.95rem;
}

.embed-slot iframe {
  width: 100%;
  border: 0;
  display: block;
  border-radius: calc(var(--demo-radius) - 2px);
}

@media (min-width: 768px) {
  .embed-slot {
    min-height: 480px;
    padding: 3rem 2rem;
  }
}

/* ---- 7b. Cross-origin lobby iframe (D-DEMO-INTEGRATION T16) ---- */
.demo-lobby-iframe {
  width: 100%;
  min-height: 560px;
  border: 1px solid var(--demo-border);
  border-radius: var(--demo-radius);
  background: var(--demo-card-bg);
  display: block;
}

@media (max-width: 540px) {
  .demo-lobby-iframe {
    min-height: 720px;
  }
}

/* ---- 8. Auth forms (login + signup) ----
 * Form card respects the active theme (uses `--demo-card-bg`, `--demo-fg`,
 * `--demo-border`) so each of the 9 themes keeps its identity. Only the
 * INPUT fields themselves are forced white solid + near-black text — that
 * is the surface where the user types and white guarantees readable contrast
 * cross-theme regardless of card background (owner directive 2026-05-06).
 * Focus state uses `--demo-accent` so the theme accent still expresses
 * itself on the typing surface.
 * ui-ux-pro-max skill applied : §1 focus-states, §5 viewport-units 100dvh,
 * §6 contrast-readability (text on input only), §8 input-labels +
 * touch-friendly-input + focus-management.
 */
.demo-form {
  background: var(--demo-card-bg);
  color: var(--demo-fg);
  border: 1px solid var(--demo-border);
  border-radius: var(--demo-radius);
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  box-shadow: var(--demo-shadow);
}

@media (min-width: 540px) {
  .demo-form {
    padding: 1.75rem;
  }
}

.demo-form__field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.demo-form__field label {
  font-size: 0.9rem;
  font-weight: 500;
  color: inherit;
}

.demo-form__field input {
  padding: 0.7rem 0.85rem;
  border: 1px solid rgba(0, 0, 0, 0.18);
  border-radius: calc(var(--demo-radius) - 2px);
  background: #ffffff;
  color: #111827;
  font-size: 16px;
  min-height: 44px;
  width: 100%;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.demo-form__field input::placeholder {
  color: rgba(17, 24, 39, 0.45);
}

.demo-form__field input:focus,
.demo-form__field input:focus-visible {
  outline: none;
  border-color: var(--demo-accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--demo-accent) 30%, transparent);
}

.demo-form__error {
  color: #b91c1c;
  font-size: 0.9rem;
  padding: 0.6rem 0.85rem;
  background: #fef2f2;
  border: 1px solid #fecaca;
  border-radius: calc(var(--demo-radius) - 2px);
}

.demo-form__seed {
  background: var(--demo-card-bg);
  color: inherit;
  border: 1px solid var(--demo-border);
  padding: 0.85rem 1rem;
  border-radius: calc(var(--demo-radius) - 2px);
  font-size: 0.85rem;
  margin-top: 0.5rem;
  box-shadow: var(--demo-shadow);
}

.demo-form__seed strong {
  display: block;
  margin-bottom: 0.35rem;
  color: inherit;
}

.demo-form__seed code {
  font-family: ui-monospace, "SFMono-Regular", Consolas, monospace;
  font-size: 0.85em;
  background: rgba(0, 0, 0, 0.18);
  padding: 0.1em 0.3em;
  border-radius: 3px;
}

.demo-form__seed a {
  color: var(--demo-accent);
}

/* Centered auth experience : flex-center the form vertically + horizontally
 * on the viewport. Applied via body modifier `demo-centered` set by router
 * for /login + /signup. Picker / does NOT receive this class (its 9-card
 * grid fills viewport naturally).
 */
.demo-centered .demo-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100dvh;
  padding-block: 2rem;
}

.demo-centered .demo-main > * {
  width: 100%;
  max-width: 460px;
  margin-inline: auto;
}

.demo-centered .demo-form,
.demo-centered .demo-form__seed {
  width: 100%;
  max-width: 460px;
  margin-inline: auto;
}

@media (min-width: 768px) {
  .demo-centered .demo-main {
    padding-block: 3rem;
  }
}

/* ---- 9. Buttons + links ---- */
.demo-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 0.6rem 1.2rem;
  border: 0;
  border-radius: var(--demo-radius);
  background: var(--demo-button-bg);
  color: var(--demo-button-fg);
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  transition: opacity 0.15s ease;
}

.demo-btn:hover {
  opacity: 0.9;
  text-decoration: none;
}

.demo-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.demo-btn--ghost {
  background: transparent;
  color: var(--demo-fg);
  border: 1px solid var(--demo-border);
}

/* ---- 10. Accessibility (focus + sr-only) ---- */
.demo-btn:focus-visible,
.demo-form__field input:focus-visible,
.demo-nav__links a:focus-visible,
.demo-picker__card a:focus-visible {
  outline: 2px solid var(--demo-accent);
  outline-offset: 2px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
