* { box-sizing: border-box; margin: 0; padding: 0; }
:root {
  --ink: #1e293b; --muted: #64748b; --line: #e2e8f0;
  --accent: #f59e0b; --accent2: #e85d3f;
  --success: #16a34a; --danger: #dc2626;
  --bg: #f1f5f9; --surface: #ffffff;
  --r: 10px;
}

body {
  font-family: 'Sora', sans-serif;
  background: linear-gradient(135deg, #f1f5f9, #ede9fe, #f1f5f9, #e0f2fe);
  background-size: 300% 300%;
  animation: bgShift 18s ease infinite;
  color: var(--ink);
  height: 100vh; height: 100dvh;
  padding: 10px 12px 0;
  overflow: hidden;
  display: flex; flex-direction: column;
}
@keyframes bgShift { 0% { background-position: 0% 50%; } 50% { background-position: 100% 50%; } 100% { background-position: 0% 50%; } }

.wrap { max-width: 480px; width: 100%; margin: 0 auto; flex: 1; min-height: 0; display: flex; flex-direction: column; }

/* -- Platform logo strip: infinite marquee, same as every other game page -- */
.platform-strip { position: relative; overflow: hidden; padding: 8px 0; flex-shrink: 0; }
.platform-strip::before, .platform-strip::after {
  content: ''; position: absolute; top: 0; bottom: 0; width: 32px; z-index: 2; pointer-events: none;
}
.platform-strip::before { left: 0; background: linear-gradient(to right, var(--bg), transparent); }
.platform-strip::after { right: 0; background: linear-gradient(to left, var(--bg), transparent); }
.platform-track {
  display: flex; align-items: center; gap: 10px; width: max-content;
  animation: platformMarquee 36s linear infinite;
}
.platform-strip:hover .platform-track { animation-play-state: paused; }
@keyframes platformMarquee { from { transform: translateX(0); } to { transform: translateX(-50%); } }
.platform-card {
  flex: 0 0 auto; width: 76px; height: 42px; border-radius: 12px;
  background: #fff; border: 1px solid #e2e8f0; box-shadow: 0 1px 3px rgba(0,0,0,.06);
  display: flex; align-items: center; justify-content: center;
  transition: transform .15s;
}
.platform-card:active { transform: scale(.92); }
.platform-card img { height: 22px; width: auto; max-width: 90%; object-fit: contain; display: block; }
@media (prefers-reduced-motion: reduce) { .platform-track { animation: none; } }

/* ── Header ── */
.header { position: relative; text-align: center; padding: 6px 0 4px; flex-shrink: 0; }
.logo-img { max-height: 60px; width: auto; display: inline-block; }
.header-left { position: absolute; top: 4px; left: 4px; display: flex; align-items: center; gap: 6px; }
.header-right { position: absolute; top: 4px; right: 4px; display: flex; align-items: center; gap: 6px; }
.back-btn, .icon-btn-sm {
  display: flex; align-items: center; justify-content: center;
  width: 26px; height: 26px; flex-shrink: 0;
  border-radius: 50%; background: var(--surface); border: 1.5px solid var(--line);
  color: var(--muted); font-weight: 800; font-size: 14px; text-decoration: none;
  box-shadow: 0 1px 4px rgba(0,0,0,.08); cursor: pointer;
  transition: transform .15s cubic-bezier(.34,1.56,.64,1);
}
.back-btn:active, .icon-btn-sm:active { transform: scale(.88); }

/* ── Login gate (mandatory login, unlike Connect's free-text name gate) ── */
.logingate-overlay {
  display: none; position: fixed; inset: 0; z-index: 400;
  background: rgba(15,23,42,.6); backdrop-filter: blur(4px);
  align-items: center; justify-content: center; padding: 20px;
}
.logingate-overlay.show { display: flex; }
.logingate-card {
  background: var(--surface); border-radius: 20px; padding: 28px 24px;
  max-width: 340px; width: 100%; text-align: center;
  box-shadow: 0 20px 60px rgba(0,0,0,.35);
}
.logingate-logo { max-height: 56px; margin-bottom: 12px; }
.logingate-title { font-size: 19px; font-weight: 800; margin-bottom: 6px; }
.logingate-sub { font-size: 13px; color: var(--muted); margin-bottom: 18px; line-height: 1.5; }
.logingate-btn {
  width: 100%; padding: 13px; border: none; border-radius: 12px;
  background: linear-gradient(120deg, #7c3aed, #a855f7); color: #fff;
  font-family: inherit; font-size: 14px; font-weight: 800; cursor: pointer;
}

/* ── Views ── */
#lobbyView, #rankingView { display: none; flex: 1; min-height: 0; flex-direction: column; }
#lobbyView.show, #rankingView.show { display: flex; }
/* matchView scrolls as a safety net -- on a short/cramped viewport (phones especially)
   the board + header + reaction bar can add up to more than the visible height; without
   this the reaction bar at the bottom becomes completely unreachable instead of just
   requiring a scroll. */
#matchView { display: none; flex: 1; min-height: 0; flex-direction: column; overflow-y: auto; }
#matchView.show { display: flex; }

/* ── Match board: fixed 5x4 card grid ── */
.board-wrap {
  background: var(--surface); border: 0;
  border-radius: 16px; padding: 1px;
  box-shadow: 0 2px 14px rgba(0,0,0,.055);
  /* flex:0 (not 1) -- match-board sizes itself from width via aspect-ratio
     and never actually grows to fill extra height, so a flex-grow board-wrap
     just ballooned into a huge blank white rectangle around a small centered
     card grid on any viewport taller than the board itself needs. Shrinks
     (but never below min-height) on a cramped screen, doesn't grow on a
     tall one. */
  flex: 0 1 auto; min-height: 220px;
  display: flex; align-items: center; justify-content: center;
}
.match-board {
  display: grid; grid-template-columns: repeat(5, 1fr); gap: 2px;
  width: 100%; max-width: 100%; max-height: 100%;
  aspect-ratio: 15 / 16; /* 5 cols x 3-wide cards by 4 rows x 4-tall cards */
  margin: auto;
}

/* -- The 3D card: perspective flip, layered-gradient "chunky glossy" back
      matching Pop Arrow's material language (color-mix bevel + gloss). -- */
.card { aspect-ratio: 3 / 4; perspective: 700px; cursor: pointer; }
.card.matched { cursor: default; }
.card-inner {
  position: relative; width: 100%; height: 100%;
  transform-style: preserve-3d;
  transition: transform .45s cubic-bezier(.34,1.56,.64,1);
}
.card.flipped .card-inner { transform: rotateY(180deg); }
.card.picked .card-front { box-shadow: inset 0 0 0 1.5px var(--line), 0 0 0 3px rgba(124,58,237,.55), 0 3px 6px rgba(0,0,0,.1); }
/* Fade lives on .card-front itself, not .card-inner -- putting `filter` on an
   ancestor that has transform-style:preserve-3d breaks backface-visibility in
   some browsers, showing the wrong (mirrored) face once matched. */
.card.matched .card-front { transition: opacity .3s ease .15s, filter .3s ease .15s; opacity: .38; filter: saturate(.35); }

.card-face {
  position: absolute; inset: 0; backface-visibility: hidden;
  border-radius: 14%;
  display: flex; align-items: center; justify-content: center;
}

.card-back {
  --card-red: #e51c2e; --card-crimson: #920b19;
  --card-wine: #3d050c; --card-black: #100306;
  --card-gold: #f3c46b;
  background:
    radial-gradient(ellipse 78% 42% at 38% 8%, rgba(255,205,207,.27), rgba(255,85,96,.09) 52%, transparent 73%),
    radial-gradient(ellipse 74% 55% at 53% 48%, rgba(225,28,47,.20), transparent 72%),
    radial-gradient(ellipse 105% 48% at 50% 104%, rgba(0,0,0,.40), transparent 70%),
    linear-gradient(45deg, #090204 0%, var(--card-black) 22%, var(--card-wine) 43%, var(--card-crimson) 68%, var(--card-red) 100%);
  border: 1px solid #650914;
  overflow: hidden;
  box-shadow:
    inset 0 2px 2px rgba(255,255,255,.38),
    inset 3px 2px 5px rgba(255,91,101,.15),
    inset -3px -3px 6px rgba(0,0,0,.34),
    inset 0 -5px 7px rgba(0,0,0,.28),
    0 2px 1px #080103,
    0 4px 6px rgba(27,2,6,.22);
}
.card-back::before {
  content: ''; position: absolute; inset: 7%; border-radius: 10%;
  border: 1px solid color-mix(in srgb, var(--card-gold) 72%, transparent);
  background:
    radial-gradient(ellipse 58% 14% at 32% 2%, rgba(255,255,255,.30), transparent 76%),
    linear-gradient(160deg, rgba(255,255,255,.07), transparent 38%);
  box-shadow:
    0 0 0 1px rgba(26,1,5,.72),
    inset 0 0 0 1px rgba(255,236,183,.16),
    inset 0 1px 5px rgba(255,70,84,.10),
    0 1px 0 rgba(255,255,255,.08);
}
.card-back::after {
  content: '';
  position: relative; z-index: 1; width: 42%; height: 42%;
  background: url('../media/lg.png') center / contain no-repeat;
  opacity: .96;
  filter:
    sepia(.18) saturate(.82)
    drop-shadow(-1px -1px 0 rgba(0,0,0,.92))
    drop-shadow(1px 1px 0 rgba(255,211,126,.62))
    drop-shadow(0 2px 2px rgba(0,0,0,.48));
}
.card:not(.matched):active .card-back { filter: brightness(1.06); }

.card-front {
  transform: rotateY(180deg);
  background: transparent;
  box-shadow: none;
  padding: 0;
}
.card-front img { width: 100%; height: 100%; object-fit: contain; filter: drop-shadow(0 2px 2px rgba(15,23,42,.14)); }

/* ── Home button (top of lobby) ── */
.match-logo { max-height: 54px; }
