/* ================================================================
   style.css — Ludo Multiplayer (Firebase + Vercel)
   Step 1: Home Page
   ================================================================ */


/* ── 1. Design Tokens ─────────────────────────────────────────── */
:root {
  /* Background & surfaces */
  --bg:           #1E1B4B;   /* deep indigo */
  --surface:      #2D2A6E;   /* card surface */
  --surface-alt:  #3730A3;   /* input / button bg */
  --border:       #4338CA;   /* subtle borders */
  --border-light: rgba(99, 102, 241, 0.35);

  /* Text */
  --text:         #F8F7FF;   /* warm white */
  --text-muted:   #A5B4FC;   /* indigo-tinted muted */

  /* Accent */
  --accent:       #7C3AED;   /* electric violet */
  --accent-light: #8B5CF6;
  --accent-glow:  rgba(124, 58, 237, 0.4);

  /* Ludo player colors */
  --red:    #EF4444;
  --blue:   #3B82F6;
  --green:  #22C55E;
  --yellow: #EAB308;

  /* Typography */
  --font-display: 'Baloo 2', cursive;
  --font-body:    'DM Sans', sans-serif;

  /* Spacing */
  --sp-1: 0.25rem;
  --sp-2: 0.5rem;
  --sp-3: 0.75rem;
  --sp-4: 1rem;
  --sp-5: 1.25rem;
  --sp-6: 1.5rem;
  --sp-8: 2rem;
  --sp-10: 2.5rem;
  --sp-12: 3rem;

  /* Radius */
  --r-sm:   8px;
  --r-md:   14px;
  --r-lg:   22px;
  --r-full: 9999px;

  /* Transitions */
  --ease: 200ms ease;
}


/* ── 2. Reset ─────────────────────────────────────────────────── */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
  scroll-behavior: smooth;
}


/* ── 3. Body & layout ─────────────────────────────────────────── */
body {
  font-family: var(--font-body);
  background-color: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--sp-6) var(--sp-4);
  overflow-x: hidden;
  position: relative;
}


/* ── 4. Background grid (subtle dot-grid texture) ─────────────── */
/*
   The grid is made with a radial-gradient repeating pattern —
   a fine dot grid that gives depth without being busy.
*/
.bg-grid {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background-image:
    radial-gradient(circle, rgba(99, 102, 241, 0.18) 1px, transparent 1px);
  background-size: 28px 28px;
  /* Vignette mask so dots fade to black at the edges */
  -webkit-mask-image: radial-gradient(ellipse 80% 80% at 50% 50%, black 40%, transparent 100%);
  mask-image: radial-gradient(ellipse 80% 80% at 50% 50%, black 40%, transparent 100%);
}


/* ── 5. Page (stacking container) ────────────────────────────── */
.page {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 420px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--sp-5);
}


/* ── 6. Hero / logo section ───────────────────────────────────── */
.hero {
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--sp-3);
}

/* ── Animated Ludo token (the signature element) ──────────────
   A stylised game token — circle body + dome cap — cycling
   through the four Ludo colors. This is purely CSS, no images.
   ─────────────────────────────────────────────────────────── */
.ludo-token {
  width: 64px;
  height: 64px;
  position: relative;
  margin-bottom: var(--sp-2);
}

.ludo-token__body {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  background: var(--red);
  box-shadow:
    0 0 0 3px rgba(255,255,255,0.15),
    0 8px 24px rgba(0,0,0,0.5);
  position: relative;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  /* Color cycles through the four Ludo player colors */
  animation: tokenColorCycle 3.2s infinite;
}

/* The dome cap on top of the token */
.ludo-token__dome {
  width: 40%;
  height: 40%;
  border-radius: 50%;
  background: rgba(255,255,255,0.35);
  margin-top: 16%;
}

@keyframes tokenColorCycle {
  0%,  20% { background: var(--red);    box-shadow: 0 0 0 3px rgba(255,255,255,0.12), 0 8px 24px rgba(239,68,68,0.5);   }
  25%, 45% { background: var(--blue);   box-shadow: 0 0 0 3px rgba(255,255,255,0.12), 0 8px 24px rgba(59,130,246,0.5);  }
  50%, 70% { background: var(--green);  box-shadow: 0 0 0 3px rgba(255,255,255,0.12), 0 8px 24px rgba(34,197,94,0.5);   }
  75%, 95% { background: var(--yellow); box-shadow: 0 0 0 3px rgba(255,255,255,0.12), 0 8px 24px rgba(234,179,8,0.5);   }
  100%     { background: var(--red);    box-shadow: 0 0 0 3px rgba(255,255,255,0.12), 0 8px 24px rgba(239,68,68,0.5);   }
}

.hero__title {
  font-family: var(--font-display);
  font-size: 4rem;
  font-weight: 800;
  letter-spacing: 0.14em;
  color: var(--text);
  line-height: 1;
  /* Subtle text glow */
  text-shadow: 0 0 40px rgba(139, 92, 246, 0.6);
}

.hero__tagline {
  font-size: 0.9rem;
  color: var(--text-muted);
  font-weight: 500;
  letter-spacing: 0.03em;
}


/* ── 7. Setup card ────────────────────────────────────────────── */
.card {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border-light);
  border-radius: var(--r-lg);
  padding: var(--sp-8) var(--sp-6);
  box-shadow:
    0 0 0 1px rgba(124, 58, 237, 0.1),
    0 20px 60px rgba(0, 0, 0, 0.5),
    0 4px 16px rgba(0, 0, 0, 0.3);
}


/* ── 8. Form fields ───────────────────────────────────────────── */
.field {
  margin-bottom: var(--sp-6);
}

.field__label {
  display: block;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  margin-bottom: var(--sp-2);
}

.field__input {
  width: 100%;
  background: rgba(255,255,255,0.05);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 1rem;
  font-weight: 500;
  padding: 0.75rem 1rem;
  outline: none;
  transition: border-color var(--ease), box-shadow var(--ease), background var(--ease);
}

.field__input::placeholder {
  color: var(--text-muted);
  opacity: 0.5;
}

.field__input:focus {
  border-color: var(--accent-light);
  background: rgba(255,255,255,0.08);
  box-shadow: 0 0 0 3px rgba(139, 92, 246, 0.25);
}

.field__error {
  display: block;
  font-size: 0.8rem;
  color: #FCA5A5;
  margin-top: var(--sp-2);
  font-weight: 500;
  min-height: 1.1em;
}


/* ── 9. Player-count buttons ──────────────────────────────────── */
.count-group {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--sp-3);
}

.count-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--sp-1);
  padding: var(--sp-4) var(--sp-2);
  background: rgba(255,255,255,0.04);
  border: 1.5px solid var(--border-light);
  border-radius: var(--r-md);
  color: var(--text-muted);
  cursor: pointer;
  font-family: var(--font-body);
  transition:
    border-color var(--ease),
    background var(--ease),
    color var(--ease),
    transform var(--ease),
    box-shadow var(--ease);
  -webkit-tap-highlight-color: transparent;
}

.count-btn:hover {
  border-color: var(--accent-light);
  background: rgba(139, 92, 246, 0.1);
  color: var(--text);
  transform: translateY(-2px);
  box-shadow: 0 4px 16px rgba(124, 58, 237, 0.2);
}

.count-btn:active {
  transform: translateY(0);
}

/* Selected state */
.count-btn--active {
  border-color: var(--accent-light);
  background: rgba(124, 58, 237, 0.18);
  color: var(--text);
  box-shadow:
    0 0 0 1px var(--accent-light),
    0 4px 16px rgba(124, 58, 237, 0.25);
}

/* Mini pip dots (show which colors are in the game) */
.count-btn__pips {
  display: flex;
  gap: 4px;
  height: 18px;
  align-items: center;
}

.count-btn__pips--four {
  flex-wrap: wrap;
  width: 26px;
  gap: 3px;
}

.pip {
  display: inline-block;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  flex-shrink: 0;
}

.pip--red    { background: var(--red); }
.pip--blue   { background: var(--blue); }
.pip--green  { background: var(--green); }
.pip--yellow { background: var(--yellow); }

.count-btn__number {
  font-family: var(--font-display);
  font-size: 1.75rem;
  font-weight: 700;
  line-height: 1;
}

.count-btn__label {
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}


/* ── 10. Create Game button ───────────────────────────────────── */
.btn-create {
  width: 100%;
  margin-top: var(--sp-2);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  padding: 0.875rem var(--sp-6);
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--r-md);
  font-family: var(--font-display);
  font-size: 1.125rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  cursor: pointer;
  transition:
    background var(--ease),
    transform var(--ease),
    box-shadow var(--ease);
  box-shadow: 0 4px 20px rgba(124, 58, 237, 0.45);
  -webkit-tap-highlight-color: transparent;
}

.btn-create:hover {
  background: #6D28D9;
  transform: translateY(-2px);
  box-shadow: 0 8px 28px rgba(124, 58, 237, 0.55);
}

.btn-create:active {
  transform: translateY(0);
  box-shadow: 0 2px 10px rgba(124, 58, 237, 0.3);
}

.btn-create__icon {
  font-size: 1.25rem;
  line-height: 1;
}


/* ── 11. Room panel (shown after Create Game) ─────────────────── */
.room-panel {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border-light);
  border-radius: var(--r-lg);
  padding: var(--sp-6);
  box-shadow: 0 12px 40px rgba(0,0,0,0.4);
  animation: fadeUp 0.3s ease;
}

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(14px); }
  to   { opacity: 1; transform: translateY(0); }
}

.room-panel__eyebrow {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  font-weight: 600;
  color: var(--text-muted);
  text-align: center;
  margin-bottom: var(--sp-4);
}

/* Big room code */
.room-code {
  font-family: var(--font-display);
  font-size: 2.5rem;
  font-weight: 700;
  letter-spacing: 0.3em;
  color: var(--accent-light);
  text-align: center;
  background: rgba(139, 92, 246, 0.1);
  border: 1px solid rgba(139, 92, 246, 0.3);
  border-radius: var(--r-md);
  padding: var(--sp-3) var(--sp-4);
  margin-bottom: var(--sp-4);
}

/* Pop-in animation on new code */
.room-code.pop {
  animation: pop 0.35s cubic-bezier(0.36, 0.07, 0.19, 0.97);
}

@keyframes pop {
  0%   { transform: scale(0.82); opacity: 0.5; }
  65%  { transform: scale(1.05); }
  100% { transform: scale(1);    opacity: 1; }
}

/* Link row */
.link-row {
  display: flex;
  gap: var(--sp-2);
}

.link-row__input {
  flex: 1;
  min-width: 0;
  background: rgba(255,255,255,0.05);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  color: var(--text-muted);
  font-family: var(--font-body);
  font-size: 0.8rem;
  padding: 0.6rem 0.75rem;
  outline: none;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  cursor: text;
}

.link-row__copy {
  flex-shrink: 0;
  padding: 0.6rem var(--sp-4);
  background: rgba(255,255,255,0.07);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  transition: background var(--ease), border-color var(--ease);
}

.link-row__copy:hover {
  background: rgba(139, 92, 246, 0.15);
  border-color: var(--accent-light);
}

.room-panel__hint {
  text-align: center;
  font-size: 0.8rem;
  color: var(--green);
  font-weight: 600;
  margin-top: var(--sp-3);
  min-height: 1.2em;
}


/* ── 12. Footer note ──────────────────────────────────────────── */
.footer-note {
  font-size: 0.75rem;
  color: var(--text-muted);
  opacity: 0.5;
  text-align: center;
  letter-spacing: 0.05em;
}


/* ── 13. Focus visible ring ───────────────────────────────────── */
:focus-visible {
  outline: 2px solid var(--accent-light);
  outline-offset: 3px;
  border-radius: 4px;
}


/* ── 14. Responsive ───────────────────────────────────────────── */

/*
  Mobile strategy:
  • font-size on inputs is set to 1rem (16px) everywhere to prevent
    iOS Safari from auto-zooming the viewport on focus.
  • Tap targets (buttons, inputs) are a minimum of 48px tall.
  • The link row stacks vertically on very small screens so it
    never overflows.
  • Three breakpoints:
      - 600px  : small tablets / large phones (landscape)
      - 460px  : standard phones (portrait)
      - 360px  : small phones (e.g. Galaxy A series, older iPhones)
*/

/* ── Small tablets / large phones in landscape ── */
@media (max-width: 600px) {
  .page {
    gap: var(--sp-4);
  }

  .hero__title {
    font-size: 3.5rem;
  }
}

/* ── Standard phones (portrait) ── */
@media (max-width: 460px) {

  /* Body: start from top so content isn't squished against viewport center */
  body {
    align-items: flex-start;
    padding: var(--sp-4) var(--sp-3);
    /* Prevent rubber-band over-scroll from exposing bg gap */
    min-height: 100dvh;
  }

  .page {
    gap: var(--sp-4);
    /* Let the page fill the full width with small side gutters */
    padding-bottom: var(--sp-8);
  }

  /* ── Hero ── */
  .ludo-token {
    width: 52px;
    height: 52px;
  }

  .hero__title {
    font-size: 3rem;
  }

  .hero__tagline {
    font-size: 0.85rem;
  }

  /* ── Card ── */
  .card {
    padding: var(--sp-5) var(--sp-4);
    border-radius: var(--r-md);
    /* Slightly reduce shadow depth on small screens */
    box-shadow:
      0 0 0 1px rgba(124, 58, 237, 0.1),
      0 10px 30px rgba(0, 0, 0, 0.5);
  }

  .field {
    margin-bottom: var(--sp-5);
  }

  /* Prevent iOS Safari zoom: input font-size must be >= 16px */
  .field__input {
    font-size: 1rem; /* already 1rem — explicit safety */
    /* Increase tap target height */
    padding: 0.875rem 1rem;
    min-height: 48px;
  }

  /* ── Player count buttons ── */
  .count-group {
    gap: var(--sp-2);
  }

  .count-btn {
    padding: var(--sp-3) var(--sp-2);
    /* Minimum 48px touch target */
    min-height: 80px;
    border-radius: var(--r-sm);
    /* Remove hover lift on touch (use :active instead) */
  }

  /* Disable hover transform on touch devices */
  @media (hover: none) {
    .count-btn:hover {
      transform: none;
      box-shadow: none;
    }
  }

  .count-btn__number {
    font-size: 1.5rem;
  }

  .count-btn__label {
    font-size: 0.65rem;
  }

  /* ── Create Game button ── */
  .btn-create {
    font-size: 1rem;
    padding: 0.875rem var(--sp-4);
    min-height: 52px;
    border-radius: var(--r-sm);
  }

  /* Disable hover lift on touch */
  @media (hover: none) {
    .btn-create:hover {
      transform: none;
    }
  }

  /* ── Room panel ── */
  .room-panel {
    padding: var(--sp-5) var(--sp-4);
    border-radius: var(--r-md);
  }

  .room-code {
    font-size: 2rem;
    letter-spacing: 0.2em;
    padding: var(--sp-3);
  }

  /* Stack the link + copy button vertically so they don't squish */
  .link-row {
    flex-direction: column;
    gap: var(--sp-2);
  }

  .link-row__input {
    font-size: 0.85rem;
    padding: 0.75rem;
    min-height: 44px;
    /* Show as much of the URL as possible */
    text-overflow: ellipsis;
  }

  .link-row__copy {
    width: 100%;
    text-align: center;
    padding: 0.75rem var(--sp-4);
    min-height: 48px;
    font-size: 0.9rem;
  }
}

/* ── Very small phones (360px and below) ── */
@media (max-width: 360px) {
  body {
    padding: var(--sp-3) var(--sp-2);
  }

  .hero__title {
    font-size: 2.5rem;
    letter-spacing: 0.1em;
  }

  .ludo-token {
    width: 44px;
    height: 44px;
  }

  .card {
    padding: var(--sp-4) var(--sp-3);
  }

  .room-panel {
    padding: var(--sp-4) var(--sp-3);
  }

  .room-code {
    font-size: 1.6rem;
    letter-spacing: 0.15em;
  }

  .count-btn {
    min-height: 72px;
  }

  .count-btn__number {
    font-size: 1.35rem;
  }
}


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

/* ── 8b. Divider (Create Game  ── OR ──  Join with code) ──────── */
.divider {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  margin: var(--sp-6) 0;
}

.divider__line {
  flex: 1;
  height: 1px;
  background: var(--border-light);
}

.divider__text {
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  color: var(--text-muted);
  text-transform: uppercase;
}

/* ── 8c. Join-with-code row ───────────────────────────────────── */
.field--join {
  margin-bottom: 0;
}

.join-row {
  display: flex;
  gap: var(--sp-2);
}

.join-row__input {
  flex: 1;
  min-width: 0;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-weight: 700;
  text-align: center;
}

.btn-join {
  flex-shrink: 0;
  padding: 0 var(--sp-5);
  background: rgba(255,255,255,0.06);
  border: 1.5px solid var(--border-light);
  border-radius: var(--r-sm);
  color: var(--text);
  font-family: var(--font-display);
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  cursor: pointer;
  transition:
    background var(--ease),
    border-color var(--ease),
    transform var(--ease),
    box-shadow var(--ease);
  -webkit-tap-highlight-color: transparent;
}

.btn-join:hover {
  background: rgba(139, 92, 246, 0.15);
  border-color: var(--accent-light);
  transform: translateY(-2px);
}

.btn-join:active {
  transform: translateY(0);
}

.btn-join:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
}

/* ── 14b. Responsive — join row ───────────────────────────────── */
@media (max-width: 460px) {
  .divider {
    margin: var(--sp-5) 0;
  }

  .join-row__input {
    min-height: 48px;
  }

  .btn-join {
    min-height: 48px;
    padding: 0 var(--sp-4);
  }
}

@media (max-width: 360px) {
  .join-row {
    flex-direction: column;
  }

  .btn-join {
    width: 100%;
    padding: 0.75rem;
  }
}