:root {
  --bg: #101418;
  --card: #181d23;
  --line: #262d36;
  --ink: #eef1f4;
  --muted: #8b95a3;
  --accent: #3ddc84;
  --warn: #ffc23d;
  font-family: ui-sans-serif, system-ui, -apple-system, 'Segoe UI', sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: var(--bg); color: var(--ink); }
button, input { font: inherit; }
[hidden] { display: none !important; }
.mono, .code b { font-family: ui-monospace, 'SF Mono', Menlo, monospace; letter-spacing: 0.08em; }
.muted { color: var(--muted); }
.small { font-size: 12px; }

.lobby { max-width: 440px; margin: 0 auto; padding: max(20px, env(safe-area-inset-top)) 16px 40px; display: grid; gap: 12px; }
.brand h1 { margin: 8px 0 4px; font-size: 32px; letter-spacing: -0.02em; }
.sub { margin: 0; color: var(--muted); line-height: 1.45; }
.status { display: inline-flex; align-items: center; gap: 8px; margin: 12px 0 0; font-size: 13px; color: var(--muted); }
.status::before { content: ''; width: 8px; height: 8px; border-radius: 50%; background: var(--warn); }
.status[data-state='online']::before { background: var(--accent); }
.status[data-state='offline']::before { background: #ff6b4a; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 16px; }
.card h2 { margin: 0 0 8px; font-size: 14px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); }
.row { display: flex; justify-content: space-between; align-items: baseline; }
/* A challenge from someone's "Challenge on X" link (shown in the lobby header) */
.challenge { margin: 12px 0 0; padding: 8px 12px; border-radius: 10px; font-weight: 700; color: var(--warn); background: rgba(255, 194, 61, 0.12); }
.field { display: grid; gap: 6px; font-size: 13px; color: var(--muted); }
input { background: #0d1115; color: var(--ink); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; min-width: 0; }
input:focus-visible, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.swatches { display: flex; gap: 10px; margin-top: 12px; }
.swatch { width: 30px; height: 30px; border-radius: 50%; border: 3px solid transparent; cursor: pointer; }
.swatch[aria-checked='true'] { border-color: #fff; }

.actions { display: grid; gap: 8px; }
.btn { border: 1px solid var(--line); background: #222932; color: var(--ink); border-radius: 12px; padding: 12px 16px; font-weight: 600; cursor: pointer; }
.btn.primary { background: var(--accent); color: #062312; border-color: transparent; }
.btn:disabled { opacity: 0.45; cursor: default; }
.btn.small { padding: 7px 12px; font-size: 13px; }
.link { background: none; border: 0; color: var(--accent); cursor: pointer; padding: 4px; font-size: 13px; }
.link:disabled { color: var(--muted); }
.join { display: grid; grid-template-columns: 1fr auto; gap: 8px; }
.join input { text-transform: uppercase; letter-spacing: 0.2em; font-family: ui-monospace, Menlo, monospace; }

.list { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; }
.list li { display: flex; align-items: center; gap: 10px; padding: 8px 6px; border-radius: 8px; }
.list li:nth-child(odd) { background: rgba(255, 255, 255, 0.025); }
.list li .link { margin-left: auto; }
.board { list-style: none; margin: 0; padding: 0; font-size: 14px; }
.board li { display: grid; grid-template-columns: 2.4em 1fr auto; padding: 6px; border-radius: 8px; }
.board li.me { background: rgba(61, 220, 132, 0.12); }
.board li.gap { display: block; text-align: center; color: var(--muted); }
.board li:has(.empty) { display: block; color: var(--muted); }
.board .rank { color: var(--muted); }
.board .val { font-weight: 700; font-variant-numeric: tabular-nums; }

.room { position: fixed; inset: 0; display: grid; grid-template-rows: auto 1fr; grid-template-columns: 1fr 240px; }
.roombar { grid-column: 1 / -1; display: flex; align-items: center; gap: 12px; padding: max(10px, env(safe-area-inset-top)) 12px 10px; border-bottom: 1px solid var(--line); background: var(--card); }
.code { font-size: 14px; color: var(--muted); }
.code b { color: var(--ink); font-size: 18px; margin: 0 4px; }
.conn { margin-left: auto; font-size: 12px; padding: 3px 8px; border-radius: 999px; background: rgba(61, 220, 132, 0.15); color: var(--accent); }
.conn:not([data-state='open']) { background: rgba(255, 194, 61, 0.15); color: var(--warn); }
#cv { width: 100%; height: 100%; display: block; touch-action: none; cursor: crosshair; transition: background 0.4s; }
.side { border-left: 1px solid var(--line); padding: 14px; overflow: auto; background: var(--card); }
.side h2 { font-size: 14px; margin: 0 0 8px; }
.dot { width: 12px; height: 12px; border-radius: 50%; flex: none; }
.badge { font-size: 11px; padding: 1px 6px; border-radius: 6px; background: #2a323c; color: var(--muted); }
.badge.you { background: rgba(61, 220, 132, 0.18); color: var(--accent); }
.side .btn { margin-top: 12px; width: 100%; }

@media (max-width: 700px) {
  .room { grid-template-columns: 1fr; grid-template-rows: auto 1fr auto; }
  .side { border-left: 0; border-top: 1px solid var(--line); max-height: 34vh; }
  .code button { display: block; padding-left: 0; }
}

.toast { position: fixed; z-index: 10; left: 50%; bottom: max(20px, env(safe-area-inset-bottom)); transform: translateX(-50%); background: var(--ink); color: var(--bg);
  padding: 10px 16px; border-radius: 12px; font-weight: 600; font-size: 14px; box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4); animation: rise 0.3s ease-out; max-width: calc(100% - 32px); }
@keyframes rise { from { transform: translate(-50%, 10px); opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .toast, #cv { animation: none; transition: none; } }
