// Turnix — Hub screens (Home, Create, Join, Lobby)

// ── Game card visuals ─────────────────────────────────────────────────────
function GameCard({ game, onPlay }) {
  const Visual = { impostor: ImpostorVisual, letter: LetterVisual, wrong: WrongVisual }[game.id];
  return (
    <button type="button" onClick={onPlay} className="tx-card tx-game-card" data-game={game.id}
      style={{
        textAlign: "left", display: "grid", gridTemplateColumns: "1fr auto", gap: 16,
        cursor: "pointer", overflow: "hidden", minHeight: 200,
        background: `linear-gradient(180deg, color-mix(in oklab, ${game.accentRaw} 7%, var(--bg-2)) 0%, var(--bg-1) 100%)`,
        border: `1px solid color-mix(in oklab, ${game.accentRaw} 25%, transparent)`,
      }}>
      <div style={{ display: "flex", flexDirection: "column", gap: 12, justifyContent: "space-between" }}>
        <div>
          <div className="tx-eyebrow" style={{ color: game.accentRaw, marginBottom: 10 }}>
            {game.id === "impostor" ? "Bluff" : game.id === "letter" ? "Lexical" : "Chaos"}
          </div>
          <div className="tx-title" style={{ fontSize: 26 }}>{game.name}</div>
          <div className="tx-sub" style={{ marginTop: 6, maxWidth: 320 }}>{game.short}</div>
        </div>
        <div style={{ display: "flex", alignItems: "center", gap: 10, flexWrap: "wrap" }}>
          <Chip mono>4–8 players</Chip>
          <Chip mono>~45s rounds</Chip>
        </div>
      </div>
      <div style={{ position: "relative", width: 140, alignSelf: "stretch" }}>
        <Visual accent={game.accentRaw} />
      </div>
    </button>
  );
}

function ImpostorVisual({ accent }) {
  return (
    <svg viewBox="0 0 140 200" width="100%" height="100%" style={{ position: "absolute", inset: 0 }}>
      <defs>
        <radialGradient id="ip-glow" cx="50%" cy="50%">
          <stop offset="0%" stopColor={accent} stopOpacity="0.4" />
          <stop offset="100%" stopColor={accent} stopOpacity="0" />
        </radialGradient>
      </defs>
      <circle cx="70" cy="100" r="80" fill="url(#ip-glow)" />
      {[0, 1, 2].map(i => (
        <g key={i} transform={`translate(${30 + i * 30}, ${110 + (i === 1 ? -16 : 0)})`}>
          <circle r="22" fill="rgba(255,255,255,0.04)" stroke={i === 1 ? accent : "rgba(255,255,255,0.18)"} strokeWidth="1.4" />
          <circle cx="-7" cy="-3" r="3" fill={i === 1 ? accent : "rgba(255,255,255,0.6)"} />
          <circle cx="7"  cy="-3" r="3" fill={i === 1 ? accent : "rgba(255,255,255,0.6)"} />
          <path d={i === 1 ? "M-8 8 Q0 14 8 8" : "M-8 8 Q0 4 8 8"} stroke="rgba(255,255,255,0.5)" strokeWidth="1.4" fill="none" strokeLinecap="round" />
        </g>
      ))}
    </svg>
  );
}

function LetterVisual({ accent }) {
  return (
    <svg viewBox="0 0 140 200" width="100%" height="100%" style={{ position: "absolute", inset: 0 }}>
      <defs>
        <radialGradient id="lt-glow" cx="50%" cy="50%">
          <stop offset="0%" stopColor={accent} stopOpacity="0.35" />
          <stop offset="100%" stopColor={accent} stopOpacity="0" />
        </radialGradient>
      </defs>
      <circle cx="70" cy="100" r="80" fill="url(#lt-glow)" />
      {["S","T","R","A"].map((ch, i) => (
        <g key={ch} transform={`translate(${22 + i * 26}, 100)`}>
          <rect x="-12" y="-16" width="24" height="32" rx="5"
            fill={i === 3 ? accent : "rgba(255,255,255,0.06)"}
            stroke={i === 3 ? accent : "rgba(255,255,255,0.18)"} strokeWidth="1" />
          <text x="0" y="5" textAnchor="middle" fontFamily="ui-monospace,monospace" fontSize="14" fontWeight="700"
            fill={i === 3 ? "#04101e" : "rgba(255,255,255,0.85)"}>{ch}</text>
        </g>
      ))}
    </svg>
  );
}

function WrongVisual({ accent }) {
  return (
    <svg viewBox="0 0 140 200" width="100%" height="100%" style={{ position: "absolute", inset: 0 }}>
      <defs>
        <radialGradient id="wr-glow" cx="50%" cy="50%">
          <stop offset="0%" stopColor={accent} stopOpacity="0.35" />
          <stop offset="100%" stopColor={accent} stopOpacity="0" />
        </radialGradient>
      </defs>
      <circle cx="70" cy="100" r="80" fill="url(#wr-glow)" />
      <g transform="translate(70 100)">
        {["?","✗","!"].map((ch, i) => (
          <g key={i} transform={`rotate(${(i - 1) * 12}) translate(${(i - 1) * 32}, 0)`}>
            <rect x="-22" y="-28" width="44" height="56" rx="8"
              fill={i === 1 ? accent : "rgba(255,255,255,0.05)"}
              stroke={i === 1 ? accent : "rgba(255,255,255,0.16)"} strokeWidth="1" />
            <text x="0" y="8" textAnchor="middle" fontFamily="Inter,sans-serif" fontSize="22" fontWeight="700"
              fill={i === 1 ? "#1a0a02" : "rgba(255,255,255,0.85)"}>{ch}</text>
          </g>
        ))}
      </g>
    </svg>
  );
}

// ── HOME ──────────────────────────────────────────────────────────────────
function HomeScreen({ nick, setNick, onPlay, onCreate, onJoin }) {
  return (
    <div className="tx-screen" style={{ padding: "32px 36px 28px", gap: 28, overflow: "auto" }}>
      <header style={{ display: "flex", alignItems: "center", justifyContent: "space-between" }}>
        <Logo size="lg" />
        <div style={{ display: "flex", alignItems: "center", gap: 10 }}>
          <NickPill nick={nick} setNick={setNick} />
        </div>
      </header>

      <section style={{ display: "flex", flexDirection: "column", gap: 8, marginTop: 4 }}>
        <div className="tx-eyebrow">Tonight's lineup</div>
        <h1 className="tx-title xl" style={{ maxWidth: 720 }}>
          Three games. <span style={{ color: "var(--fg-2)" }}>One room.</span>
        </h1>
        <p className="tx-sub" style={{ maxWidth: 540, fontSize: 16 }}>
          Quick rounds, voice on Discord, no install. Pick a game or spin up a room.
        </p>
      </section>

      <section style={{ display: "flex", gap: 12, alignItems: "center", flexWrap: "wrap" }}>
        <button className="tx-btn primary lg" onClick={onCreate}>
          <span style={{ fontSize: 18, lineHeight: 1, marginRight: 2 }}>＋</span>
          Create Room
        </button>
        <button className="tx-btn ghost lg" onClick={onJoin}>
          Join with Code
        </button>
      </section>

      <section style={{ display: "grid", gridTemplateColumns: "repeat(3, 1fr)", gap: 16 }}>
        {Object.values(GAMES).map(g => (
          <GameCard key={g.id} game={g} onPlay={() => onPlay(g.id)} />
        ))}
      </section>

      <section style={{ display: "grid", gridTemplateColumns: "1fr 1fr", gap: 16 }}>
        <div className="tx-card" style={{ display: "flex", flexDirection: "column", gap: 8 }}>
          <div className="tx-eyebrow">How to play</div>
          <div style={{ fontSize: 14, color: "var(--fg-1)", lineHeight: 1.55 }}>
            Create a room → share the 4-letter code → friends join → host starts the game. Rounds last ~45s.
          </div>
        </div>
        <div className="tx-card" style={{ display: "flex", flexDirection: "column", gap: 8 }}>
          <div className="tx-eyebrow">Shortcuts</div>
          <ShortcutRow keys={["N"]} label="New room" />
          <ShortcutRow keys={["J"]} label="Join with code" />
          <ShortcutRow keys={["Esc"]} label="Back to home" />
        </div>
      </section>
    </div>
  );
}

function NickPill({ nick, setNick }) {
  const [editing, setEditing] = React.useState(false);
  const ref = React.useRef(null);
  React.useEffect(() => { if (editing) ref.current?.focus(); }, [editing]);
  return (
    <div className="tx-chip" style={{ height: 36, padding: "0 14px 0 6px", gap: 8 }}>
      <span className="tx-avatar" style={{ width: 24, height: 24, fontSize: 10, background: "#2a2f3d" }}>
        {initials(nick || "?")}
      </span>
      {editing ? (
        <input ref={ref} value={nick}
          onChange={e => setNick(e.target.value.slice(0, 14))}
          onBlur={() => setEditing(false)}
          onKeyDown={e => { if (e.key === "Enter") setEditing(false); }}
          style={{ background: "transparent", border: 0, outline: 0, color: "inherit", font: "inherit", fontWeight: 500, width: 90 }} />
      ) : (
        <button onClick={() => setEditing(true)}
          style={{ background: "transparent", border: 0, color: "inherit", cursor: "pointer", fontWeight: 500, fontSize: 13, padding: 0 }}>
          {nick || "Set name"}
        </button>
      )}
    </div>
  );
}

function ShortcutRow({ keys, label }) {
  return (
    <div style={{ display: "flex", alignItems: "center", justifyContent: "space-between", padding: "6px 0" }}>
      <span style={{ fontSize: 13, color: "var(--fg-1)" }}>{label}</span>
      <span style={{ display: "flex", gap: 4 }}>
        {keys.map(k => (
          <kbd key={k} style={{ fontFamily: "var(--font-mono)", fontSize: 11, background: "rgba(255,255,255,0.05)", border: "1px solid var(--line-2)", borderRadius: 5, padding: "2px 7px" }}>{k}</kbd>
        ))}
      </span>
    </div>
  );
}

// ── CREATE ROOM ───────────────────────────────────────────────────────────
function CreateScreen({ onBack, onCreate }) {
  const [game, setGame] = React.useState("impostor");
  const [maxPlayers, setMaxPlayers] = React.useState(8);
  const [rounds, setRounds] = React.useState(5);

  return (
    <div className="tx-screen" style={{ padding: "32px 36px", gap: 24, overflow: "auto" }}>
      <header style={{ display: "flex", alignItems: "center", justifyContent: "space-between" }}>
        <button className="tx-btn ghost sm" onClick={onBack}>← Back</button>
        <Logo />
        <div style={{ width: 64 }} />
      </header>

      <div style={{ display: "grid", gridTemplateColumns: "1.1fr 1fr", gap: 28, marginTop: 8 }}>
        <div>
          <div className="tx-eyebrow" style={{ marginBottom: 8 }}>Step 1 · Pick a game</div>
          <h1 className="tx-title lg" style={{ marginBottom: 24 }}>Create a room</h1>
          <div style={{ display: "flex", flexDirection: "column", gap: 10 }}>
            {Object.values(GAMES).map(g => (
              <GamePickRow key={g.id} game={g} selected={game === g.id} onClick={() => setGame(g.id)} />
            ))}
          </div>
          <div className="tx-eyebrow" style={{ marginTop: 28, marginBottom: 12 }}>Step 2 · Settings</div>
          <div className="tx-card" style={{ display: "flex", flexDirection: "column", gap: 16 }}>
            <SettingRow label="Max players" hint={`${maxPlayers} players`}>
              <SegSlider value={maxPlayers} setValue={setMaxPlayers} min={2} max={10} />
            </SettingRow>
            <SettingRow label="Rounds" hint={`${rounds} rounds`}>
              <SegSlider value={rounds} setValue={setRounds} min={3} max={10} />
            </SettingRow>
          </div>
        </div>

        <div>
          <div className="tx-eyebrow" style={{ marginBottom: 8 }}>Preview</div>
          <div className="tx-card" style={{
            background: `linear-gradient(180deg, color-mix(in oklab, ${GAMES[game].accentRaw} 14%, var(--bg-1)) 0%, var(--bg-1) 100%)`,
            border: `1px solid color-mix(in oklab, ${GAMES[game].accentRaw} 30%, transparent)`,
            padding: 22, display: "flex", flexDirection: "column", gap: 14, minHeight: 280,
          }}>
            <Chip mono style={{ borderColor: GAMES[game].accentRaw, color: GAMES[game].accentRaw }}>{GAMES[game].name}</Chip>
            <div className="tx-title">{GAMES[game].name}</div>
            <div className="tx-sub" style={{ maxWidth: 360 }}>{GAMES[game].short}</div>
            <div style={{ display: "flex", flexDirection: "column", gap: 8, marginTop: 4 }}>
              <PreviewMeta label="Players" value={`Up to ${maxPlayers}`} />
              <PreviewMeta label="Rounds"  value={`${rounds}`} />
              <PreviewMeta label="Avg time" value={`${Math.round(rounds * 0.9)}–${rounds * 2} min`} />
            </div>
          </div>
          <button className="tx-btn accent lg" data-game={game}
            style={{ width: "100%", marginTop: 16 }}
            onClick={() => onCreate({ game, maxPlayers, rounds })}>
            Create Room →
          </button>
          <div style={{ fontSize: 12, color: "var(--fg-3)", marginTop: 10, textAlign: "center" }}>
            You'll get a 4-letter code to share with friends.
          </div>
        </div>
      </div>
    </div>
  );
}

function GamePickRow({ game, selected, onClick }) {
  return (
    <button onClick={onClick} className="tx-card"
      style={{
        display: "flex", alignItems: "center", gap: 14, cursor: "pointer", textAlign: "left", padding: 16,
        borderColor: selected ? game.accentRaw : "var(--line)",
        background: selected ? `linear-gradient(180deg, color-mix(in oklab, ${game.accentRaw} 14%, var(--bg-2)) 0%, var(--bg-1) 100%)` : undefined,
        boxShadow: selected ? `0 0 0 1px ${game.accentRaw}55, 0 8px 30px ${game.accentRaw}22` : "none",
        transition: "all 180ms ease",
      }}>
      <span style={{ width: 8, height: 40, borderRadius: 4, background: game.accentRaw }} />
      <span style={{ flex: 1 }}>
        <div style={{ fontWeight: 600, fontSize: 16 }}>{game.name}</div>
        <div style={{ color: "var(--fg-2)", fontSize: 13, marginTop: 2 }}>{game.short}</div>
      </span>
      <span style={{ width: 22, height: 22, borderRadius: "50%", border: `1.5px solid ${selected ? game.accentRaw : "var(--line-3)"}`, background: selected ? game.accentRaw : "transparent", display: "flex", alignItems: "center", justifyContent: "center" }}>
        {selected && <span style={{ width: 8, height: 8, background: "#0a0b10", borderRadius: "50%" }} />}
      </span>
    </button>
  );
}

function SettingRow({ label, hint, children }) {
  return (
    <div style={{ display: "grid", gridTemplateColumns: "120px 1fr", alignItems: "center", gap: 18 }}>
      <div>
        <div style={{ fontSize: 13, fontWeight: 500 }}>{label}</div>
        {hint && <div style={{ fontSize: 11, color: "var(--fg-3)", marginTop: 2 }}>{hint}</div>}
      </div>
      <div>{children}</div>
    </div>
  );
}

function SegSlider({ value, setValue, min, max }) {
  return (
    <div style={{ display: "flex", gap: 6 }}>
      {Array.from({ length: max - min + 1 }, (_, i) => min + i).map(n => (
        <button key={n} onClick={() => setValue(n)} style={{
          flex: 1, height: 36, borderRadius: 8, cursor: "pointer",
          background: value === n ? "var(--fg-0)" : "rgba(255,255,255,0.04)",
          color: value === n ? "#0a0b10" : "var(--fg-1)",
          border: "1px solid " + (value === n ? "var(--fg-0)" : "var(--line-2)"),
          font: "inherit", fontFamily: "var(--font-mono)", fontWeight: 600, fontSize: 13,
          transition: "all 120ms ease",
        }}>{n}</button>
      ))}
    </div>
  );
}

function PreviewMeta({ label, value }) {
  return (
    <div style={{ display: "flex", justifyContent: "space-between", padding: "6px 0", borderBottom: "1px dashed var(--line)" }}>
      <span style={{ color: "var(--fg-2)", fontSize: 13 }}>{label}</span>
      <span style={{ fontSize: 13, fontWeight: 500 }}>{value}</span>
    </div>
  );
}

// ── JOIN ROOM ─────────────────────────────────────────────────────────────
function JoinScreen({ onBack, onJoin }) {
  const [code, setCode] = React.useState(["", "", "", ""]);
  const refs = [React.useRef(), React.useRef(), React.useRef(), React.useRef()];
  React.useEffect(() => { refs[0].current?.focus(); }, []);

  const setChar = (i, v) => {
    const ch = (v || "").toUpperCase().slice(-1).replace(/[^A-Z0-9]/g, "");
    setCode(prev => { const next = prev.slice(); next[i] = ch; return next; });
    if (ch && i < 3) refs[i + 1].current?.focus();
  };
  const onKey = (i, e) => {
    if (e.key === "Backspace" && !code[i] && i > 0) refs[i - 1].current?.focus();
    if (e.key === "Enter" && code.every(Boolean)) onJoin(code.join(""));
  };
  const onPaste = (e) => {
    const text = (e.clipboardData.getData("text") || "").toUpperCase().replace(/[^A-Z0-9]/g, "").slice(0, 4);
    if (!text) return;
    e.preventDefault();
    const next = ["", "", "", ""];
    for (let i = 0; i < text.length; i++) next[i] = text[i];
    setCode(next);
    refs[Math.min(text.length, 3)].current?.focus();
  };
  const ready = code.every(Boolean);

  return (
    <div className="tx-screen" style={{ padding: "32px 36px", overflow: "auto" }}>
      <header style={{ display: "flex", alignItems: "center", justifyContent: "space-between" }}>
        <button className="tx-btn ghost sm" onClick={onBack}>← Back</button>
        <Logo />
        <div style={{ width: 64 }} />
      </header>
      <div style={{ flex: 1, display: "flex", flexDirection: "column", alignItems: "center", justifyContent: "center", textAlign: "center", gap: 24 }}>
        <div className="tx-eyebrow">Join a room</div>
        <h1 className="tx-title xl">Enter the code</h1>
        <div className="tx-sub" style={{ maxWidth: 380 }}>Four characters. Ask the host, or paste it in.</div>
        <div style={{ display: "flex", gap: 12, marginTop: 8 }} onPaste={onPaste}>
          {code.map((c, i) => (
            <input key={i} ref={refs[i]} value={c}
              onChange={e => setChar(i, e.target.value)}
              onKeyDown={e => onKey(i, e)}
              maxLength={1} inputMode="text"
              style={{
                width: 76, height: 92, fontSize: 44, fontWeight: 700, textAlign: "center",
                fontFamily: "var(--font-mono)",
                background: "rgba(255,255,255,0.03)",
                border: `1.5px solid ${c ? "var(--fg-0)" : "var(--line-2)"}`,
                borderRadius: 16, color: "var(--fg-0)", outline: 0,
                transition: "border-color 140ms", caretColor: "var(--fg-0)",
              }} />
          ))}
        </div>
        <button className="tx-btn primary lg" disabled={!ready} onClick={() => onJoin(code.join(""))} style={{ minWidth: 220, marginTop: 8 }}>
          Join Room
        </button>
      </div>
    </div>
  );
}

// ── LOBBY ─────────────────────────────────────────────────────────────────
// Receives roomState from app.jsx — no local simulation
function LobbyScreen({ roomState, isHost, myId, onAction, onLeave }) {
  const { players, game: gameId, code, maxPlayers } = roomState;
  const room = { code: roomState.code || "????", game: gameId, maxPlayers, rounds: roomState.rounds };
  const g = GAMES[gameId];
  const [copied, setCopied] = React.useState(false);

  const readyCount = players.filter(p => p.ready).length;
  const youReady = players.find(p => p.id === myId)?.ready;
  const allReady = readyCount === players.length && players.length >= 2;

  const copy = () => {
    navigator.clipboard?.writeText(room.code).catch(() => {});
    setCopied(true);
    setTimeout(() => setCopied(false), 1500);
  };

  return (
    <div className="tx-screen" style={{ padding: "24px 32px", gap: 22, overflow: "auto" }}>
      <header style={{ display: "flex", alignItems: "center", justifyContent: "space-between" }}>
        <div style={{ display: "flex", gap: 12, alignItems: "center" }}>
          <button className="tx-btn ghost sm" onClick={onLeave}>← Leave</button>
          <Logo />
        </div>
        {!isHost && (
          <Chip><StatusDot kind="ok" /> Waiting for host</Chip>
        )}
      </header>

      <div style={{ display: "grid", gridTemplateColumns: "1.4fr 1fr", gap: 22 }}>
        <div style={{ display: "flex", flexDirection: "column", gap: 18 }}>
          <div className="tx-card" style={{
            padding: 28,
            background: `linear-gradient(160deg, color-mix(in oklab, ${g.accentRaw} 14%, var(--bg-2)) 0%, var(--bg-1) 100%)`,
            border: `1px solid color-mix(in oklab, ${g.accentRaw} 28%, transparent)`,
          }}>
            <Chip mono style={{ borderColor: g.accentRaw, color: g.accentRaw }}>{g.name}</Chip>
            <h1 className="tx-title lg" style={{ marginTop: 14 }}>Lobby</h1>
            <div className="tx-sub" style={{ marginTop: 6 }}>{g.short}</div>
          </div>

          <div className="tx-card" style={{ padding: 22 }}>
            <div className="tx-eyebrow" style={{ marginBottom: 12 }}>Room code — share this!</div>
            <div style={{ display: "flex", alignItems: "center", gap: 16 }}>
              <div style={{ fontFamily: "var(--font-mono)", fontWeight: 700, fontSize: 48, letterSpacing: "0.18em", color: "var(--fg-0)" }}>
                {room.code}
              </div>
              <div style={{ flex: 1 }} />
              <button className="tx-btn ghost" onClick={copy}>
                {copied ? "✓ Copied" : "Copy code"}
              </button>
            </div>
            <div style={{ marginTop: 14, fontSize: 12, color: "var(--fg-3)" }}>
              Friends open Turnix → Join with Code → type this code
            </div>
          </div>
        </div>

        <div className="tx-card" style={{ padding: 22, display: "flex", flexDirection: "column", gap: 12, minHeight: 360 }}>
          <div style={{ display: "flex", justifyContent: "space-between", alignItems: "baseline" }}>
            <div className="tx-eyebrow">Players · {readyCount}/{players.length} ready</div>
            <span style={{ color: "var(--fg-3)", fontSize: 12 }}>Up to {maxPlayers}</span>
          </div>

          <div style={{ display: "flex", flexDirection: "column", gap: 6 }}>
            {players.map(p => <PlayerRow key={p.id} player={{ ...p, you: p.id === myId }} />)}
            {Array.from({ length: Math.max(0, maxPlayers - players.length) }).map((_, i) => (
              <div key={`slot-${i}`} style={{ display: "flex", alignItems: "center", gap: 12, padding: "10px 4px", color: "var(--fg-3)", fontSize: 13, borderTop: "1px dashed var(--line)" }}>
                <span style={{ width: 36, height: 36, borderRadius: "50%", border: "1.5px dashed var(--line-3)", display: "flex", alignItems: "center", justifyContent: "center", fontSize: 18 }}>＋</span>
                <span>Open slot</span>
              </div>
            ))}
          </div>

          <div style={{ flex: 1 }} />

          <div style={{ display: "flex", gap: 10, marginTop: 4 }}>
            <button
              className={clsx("tx-btn", youReady ? "ghost" : "primary")}
              onClick={() => onAction({ type: "toggleReady" })}
              style={{ flex: 1 }}>
              {youReady ? "Unready" : "I'm Ready"}
            </button>
            {isHost && (
              <button className="tx-btn accent" data-game={gameId}
                disabled={!allReady}
                onClick={() => onAction({ type: "startGame" })}
                style={{ flex: 1 }}
                title={allReady ? "Start the game" : players.length < 2 ? "Need at least 2 players" : "Waiting on players"}>
                {allReady ? "Start →" : `Waiting · ${players.length - readyCount}`}
              </button>
            )}
            {!isHost && (
              <div style={{ flex: 1, display: "flex", alignItems: "center", justifyContent: "center", fontSize: 13, color: "var(--fg-3)" }}>
                Waiting for host…
              </div>
            )}
          </div>
        </div>
      </div>
    </div>
  );
}

function PlayerRow({ player }) {
  return (
    <div style={{ display: "flex", alignItems: "center", gap: 12, padding: "10px 4px", borderTop: "1px solid var(--line)" }}>
      <Avatar player={player} speaking={player.speaking} />
      <div style={{ flex: 1 }}>
        <div style={{ fontSize: 14, fontWeight: 500 }}>
          {player.name}
          {player.you && <span style={{ color: "var(--fg-3)", fontWeight: 400, marginLeft: 6 }}>· you</span>}
          {player.host && <span style={{ marginLeft: 8, fontSize: 10, color: "var(--fg-2)", border: "1px solid var(--line-2)", borderRadius: 4, padding: "1px 5px", letterSpacing: "0.06em", textTransform: "uppercase" }}>Host</span>}
        </div>
      </div>
      <span style={{ fontSize: 12, fontWeight: 500, color: player.ready ? "var(--ok)" : "var(--fg-3)", display: "flex", alignItems: "center", gap: 6 }}>
        <StatusDot kind={player.ready ? "ok" : "default"} />
        {player.ready ? "Ready" : "Waiting"}
      </span>
    </div>
  );
}

Object.assign(window, {
  HomeScreen, CreateScreen, JoinScreen, LobbyScreen,
  GameCard, NickPill, PlayerRow,
});
