:root {
  --bg: #0b1020;
  --bg2: #131a33;
  --panel: #182146;
  --ink: #eef1ff;
  --muted: #9aa3c7;
  --line: #2a3566;
  --accent: #ff5a8a;
  --accent2: #37e0c8;
  --good: #33d17a;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
html, body { margin: 0; }
body {
  background: radial-gradient(1200px 600px at 50% -10%, #1a2350 0%, var(--bg) 60%);
  color: var(--ink);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  min-height: 100dvh; /* dynamic viewport height — accounts for iOS Safari toolbars */
  padding-bottom: env(safe-area-inset-bottom);
  overscroll-behavior-y: none; /* no rubber-band bounce */
}
/* iOS: honor the notch / dynamic island on the sticky bar */
.topbar { padding-top: calc(14px + env(safe-area-inset-top)); }
.hidden { display: none !important; }

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: 14px 16px; position: sticky; top: 0; z-index: 5;
  background: rgba(11, 16, 32, 0.85); backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; letter-spacing: 0.2px; }
.switch {
  background: transparent; color: var(--muted); border: 1px solid var(--line);
  padding: 7px 12px; border-radius: 999px; font-size: 13px; cursor: pointer;
}
.switch:active { transform: scale(0.97); }

main { max-width: 640px; margin: 0 auto; padding: 20px 16px 40px; }

h1 { font-size: 22px; margin: 0 0 4px; }
.sub, .hint { color: var(--muted); font-size: 14px; }

/* Picker */
.picker { text-align: center; padding-top: 8px; }
.pick-title {
  font-size: clamp(22px, 7vw, 30px); text-transform: uppercase; letter-spacing: 2px;
  margin-bottom: 6px;
  background: linear-gradient(180deg, #ffffff, #aeb8ea);
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.players { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-top: 18px; }
.player-btn {
  appearance: none; border: 2px solid var(--line); border-radius: 16px;
  background: #0f1734; color: var(--ink); padding: 0; cursor: pointer;
  position: relative; overflow: hidden; aspect-ratio: 1 / 1; width: 100%; display: block;
  transition: transform .06s ease, border-color .12s ease;
}
.player-btn:active { transform: scale(0.97); border-color: var(--accent); }
.player-name {
  position: absolute; left: 0; right: 0; bottom: 0; padding: 28px 10px 10px;
  font-size: 18px; font-weight: 800; letter-spacing: .3px; text-align: center; color: #fff;
  text-shadow: 0 2px 8px rgba(0,0,0,.85);
  background: linear-gradient(180deg, transparent, rgba(6,9,20,.9));
}

/* Character avatars (image with emoji fallback) */
.avatar {
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 50%; overflow: hidden; background: #0f1734;
  border: 1px solid var(--line); flex: none; line-height: 1;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }
.avatar-sm { width: 36px; height: 36px; }
.avatar-sm.avatar-emoji { font-size: 20px; }
/* full-bleed hero variant used in the picker tiles */
.avatar.hero {
  display: block; width: 100%; height: 100%; border: 0; border-radius: 0;
  background: linear-gradient(180deg, #26356a, #0f1734);
}
.avatar.hero.avatar-emoji { display: flex; align-items: center; justify-content: center; font-size: 60px; }
#who-name { display: flex; align-items: center; gap: 10px; }

/* Board */
.board-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.status { color: var(--muted); font-size: 13px; white-space: nowrap; }
.status.win { color: var(--good); font-weight: 700; }

/* subtle blurred hero photo behind the whole card */
.board { position: relative; }
.board.has-hero::before {
  content: ""; position: fixed; inset: 0; z-index: -1;
  background-image: var(--hero); background-size: cover; background-position: center top;
  filter: blur(18px) brightness(0.45) saturate(1.1);
  opacity: 0.22; transform: scale(1.12);
}

.grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 5px; }
.cell {
  position: relative; aspect-ratio: 1 / 1; border: 1px solid var(--line);
  border-radius: 10px; background: linear-gradient(180deg, #141c3e, #101736);
  color: var(--ink); padding: 4px;
  font-size: clamp(8.5px, 2.5vw, 12px); line-height: 1.12;
  display: flex; align-items: center; justify-content: center; text-align: center;
  cursor: pointer; overflow: hidden; user-select: none;
  transition: transform .06s ease;
  touch-action: manipulation; /* no 300ms delay, no double-tap zoom */
  hyphens: auto; -webkit-hyphens: auto; overflow-wrap: anywhere;
}
.cell span { display: block; }
.cell:active { transform: scale(0.96); }
.cell.free { background: linear-gradient(180deg, #2a2350, #211a44); color: var(--accent2); font-weight: 800; letter-spacing: 1px; }
/* center FREE square shows the player's hero photo */
.cell.free-hero { padding: 0; border-color: var(--accent2); }
.cell.free-hero img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.cell.free-hero span {
  position: absolute; left: 0; right: 0; bottom: 0; z-index: 1;
  font-size: 9px; letter-spacing: 1px; padding: 2px 0; color: #fff;
  background: linear-gradient(180deg, transparent, rgba(6,9,20,.9));
}
.cell.marked { background: linear-gradient(180deg, var(--accent), #d83a6d); color: #fff; border-color: #ff85a9; font-weight: 600; }
.cell.marked::after {
  content: "✓"; position: absolute; top: 3px; right: 5px; font-size: 11px; opacity: .9;
}
.cell.win { box-shadow: 0 0 0 2px var(--good) inset, 0 0 14px rgba(51,209,122,.5); }

.hint { margin-top: 14px; text-align: center; }

/* keep the grid from getting oversized on big screens so cells stay tappable/legible */
@media (min-width: 560px) { main { max-width: 520px; } }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  background: var(--good); color: #04210f; font-weight: 800; padding: 12px 20px;
  border-radius: 999px; box-shadow: 0 10px 30px rgba(0,0,0,.4); z-index: 20;
}
