:root {
  --bg: #0f172a;
  --text: #e2e8f0;
  --cell: #1e293b;
  --accent: #22d3ee;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;

  --surface: rgba(255, 255, 255, 0.04);
  --surface-strong: rgba(255, 255, 255, 0.08);
  --border: rgba(255, 255, 255, 0.12);
  --muted: rgba(226, 232, 240, 0.6);
  --danger: #f87171;
  --radius: 14px;
  --shadow: 0 10px 40px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
}

body {
  font-family: var(--font);
  background:
    radial-gradient(1200px 600px at 10% -10%, rgba(34, 211, 238, 0.12), transparent 60%),
    radial-gradient(1000px 500px at 110% 10%, rgba(139, 92, 246, 0.12), transparent 60%),
    var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

.screen {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.hidden { display: none !important; }

/* ---------------- Home ---------------- */
.brand {
  text-align: center;
  margin: 48px 16px 24px;
}
.brand h1 {
  font-size: clamp(2rem, 5vw, 3rem);
  margin: 0;
  letter-spacing: -0.02em;
}
.tagline { color: var(--muted); margin: 8px 0 0; }

.card {
  width: min(560px, 92vw);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(6px);
}

.tabs {
  display: flex;
  gap: 4px;
  background: rgba(0, 0, 0, 0.2);
  border-radius: 10px;
  padding: 4px;
  margin-bottom: 18px;
}
.tab {
  flex: 1;
  padding: 10px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font-weight: 600;
  cursor: pointer;
  font-size: 0.95rem;
}
.tab.active { background: var(--surface-strong); color: var(--text); }

.panel { display: none; flex-direction: column; gap: 14px; }
.panel.active { display: flex; }

.field { display: flex; flex-direction: column; gap: 6px; }
.field > span { font-size: 0.82rem; color: var(--muted); font-weight: 600; }
.field small { font-weight: 400; }

input[type="text"], textarea, select {
  width: 100%;
  padding: 11px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: rgba(0, 0, 0, 0.25);
  color: var(--text);
  font-size: 0.95rem;
  font-family: inherit;
}
input[type="text"]:focus, textarea:focus, select:focus {
  outline: 2px solid var(--accent);
  outline-offset: 0;
  border-color: transparent;
}
textarea { resize: vertical; line-height: 1.5; }

.row { display: flex; gap: 14px; }
.row .field { flex: 1; }

.field.checkbox {
  flex-direction: row;
  align-items: center;
  gap: 8px;
  align-self: flex-end;
  padding-bottom: 11px;
}
.field.checkbox span { color: var(--text); }
input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--accent); }

input[type="color"] {
  width: 100%;
  height: 40px;
  padding: 2px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: rgba(0, 0, 0, 0.25);
  cursor: pointer;
}

.quick-fill { display: flex; gap: 8px; flex-wrap: wrap; margin-top: -6px; }

.primary {
  padding: 13px;
  border: 0;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--accent), #6366f1);
  color: #06121a;
  font-weight: 800;
  font-size: 1rem;
  cursor: pointer;
  transition: transform 0.08s ease, filter 0.2s ease;
}
.primary:hover { filter: brightness(1.08); }
.primary:active { transform: translateY(1px); }

.ghost {
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  font-size: 0.85rem;
  font-family: inherit;
}
.ghost:hover { background: var(--surface-strong); }
.ghost.small { padding: 7px 10px; }

.link-btn {
  background: none; border: 0; color: var(--accent);
  cursor: pointer; text-decoration: underline; font-size: inherit; padding: 0;
}

.error { color: var(--danger); font-size: 0.85rem; margin: 0; min-height: 1em; }

.theme-editor summary { cursor: pointer; color: var(--muted); font-weight: 600; font-size: 0.9rem; }
.theme-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  margin-top: 14px;
}
.font-field { grid-column: 1 / -1; }

.identity-line { color: var(--muted); margin: 18px 0 40px; font-size: 0.9rem; }
.avatar-inline {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px; height: 26px;
  border-radius: 50%;
  vertical-align: middle;
  font-size: 0.95rem;
}

/* ---------------- Game ---------------- */
.game-shell { width: min(1100px, 96vw); margin: 0 auto; }

.game-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 4px;
  flex-wrap: wrap;
}
.title-block { display: flex; align-items: center; gap: 12px; min-width: 0; }
.title-block h2 { margin: 0; font-size: 1.4rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.code-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px dashed var(--border);
  background: var(--surface);
  color: var(--text);
  font-weight: 700;
  letter-spacing: 0.08em;
  cursor: pointer;
}
.code-chip:hover { background: var(--surface-strong); }
.copy-icon { opacity: 0.6; }

.game-body {
  display: grid;
  grid-template-columns: 240px 1fr;
  gap: 20px;
  align-items: start;
  padding-bottom: 60px;
}

.participants {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  position: sticky;
  top: 16px;
}
.participants h3 { margin: 0 0 12px; font-size: 1rem; display: flex; align-items: center; gap: 8px; }
.pill {
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--muted);
  background: rgba(0, 0, 0, 0.25);
  padding: 2px 8px;
  border-radius: 999px;
}
#participant-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.participant {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px;
  border-radius: 10px;
}
.participant .avatar {
  width: 30px; height: 30px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 1rem;
  flex-shrink: 0;
  position: relative;
  border: 2px solid transparent;
}
.participant .p-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 0.9rem; }
.participant .p-name.you::after { content: " (you)"; color: var(--muted); font-weight: 400; }
.status-dot {
  width: 9px; height: 9px; border-radius: 50%;
  background: #475569;
  flex-shrink: 0;
}
.status-dot.online { background: #22c55e; box-shadow: 0 0 8px #22c55e88; }
.trophy { font-size: 0.9rem; }

/* Board */
.board-area { display: flex; justify-content: center; }
.board {
  display: grid;
  gap: 8px;
  width: 100%;
  max-width: 720px;
  aspect-ratio: 1 / 1;
}
.tile {
  position: relative;
  background: var(--cell);
  border: 2px solid transparent;
  border-radius: 12px;
  padding: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  cursor: pointer;
  color: var(--text);
  font-weight: 600;
  line-height: 1.15;
  overflow: hidden;
  transition: transform 0.08s ease, border-color 0.15s ease, background 0.15s ease;
  container-type: inline-size;
}
.tile:hover { transform: translateY(-2px); border-color: var(--border); }
.tile .tile-text {
  font-size: clamp(0.85rem, 13cqw, 1.6rem);
  line-height: 1.12;
  word-break: break-word;
  hyphens: auto;
  max-height: 100%;
}
.tile.checked {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 22%, var(--cell));
}
.tile.checked::before {
  content: "✓";
  position: absolute;
  top: 4px; left: 6px;
  color: var(--accent);
  font-weight: 900;
  font-size: 0.85rem;
}
.tile.free { cursor: default; }
.tile.free .tile-text { font-weight: 800; letter-spacing: 0.05em; opacity: 0.85; }
.tile.free:hover { transform: none; }
.tile.win {
  animation: winpulse 1s ease infinite alternate;
  border-color: var(--accent);
}
@keyframes winpulse {
  from { box-shadow: 0 0 0 rgba(0,0,0,0); }
  to { box-shadow: 0 0 18px var(--accent); }
}

/* Marks (icons of who checked the cell) */
.marks {
  position: absolute;
  bottom: 4px; right: 4px;
  display: flex;
  flex-wrap: wrap-reverse;
  justify-content: flex-end;
  gap: 2px;
  max-width: 80%;
}
.mark {
  width: 18px; height: 18px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 0.7rem;
  border: 1.5px solid var(--cell);
  box-shadow: 0 1px 2px rgba(0,0,0,0.3);
}

/* ---------------- Side panel (theme) ---------------- */
.side-panel {
  position: fixed;
  top: 0; right: 0;
  height: 100vh;
  width: min(320px, 90vw);
  background: rgba(15, 23, 42, 0.96);
  border-left: 1px solid var(--border);
  box-shadow: -10px 0 40px rgba(0,0,0,0.4);
  padding: 20px;
  z-index: 40;
  backdrop-filter: blur(8px);
  overflow-y: auto;
}
.side-panel-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.side-panel-head h3 { margin: 0; }
.hint { color: var(--muted); font-size: 0.8rem; margin-top: 14px; }

/* ---------------- Modal ---------------- */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.6);
  display: flex; align-items: center; justify-content: center;
  z-index: 50;
  padding: 16px;
}
.modal {
  background: #0f172a;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  width: min(400px, 92vw);
  display: flex; flex-direction: column; gap: 14px;
  box-shadow: var(--shadow);
}
.modal h3 { margin: 0; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; }

/* ---------------- Bingo banner + confetti ---------------- */
.bingo-banner {
  position: fixed;
  top: 24px; left: 50%;
  transform: translateX(-50%) translateY(-140%);
  background: linear-gradient(135deg, var(--accent), #6366f1);
  color: #06121a;
  padding: 16px 28px;
  border-radius: 999px;
  font-weight: 800;
  font-size: 1.15rem;
  box-shadow: var(--shadow);
  z-index: 60;
  transition: transform 0.4s cubic-bezier(0.2, 1.2, 0.4, 1);
  display: flex; align-items: center; gap: 10px;
  max-width: 90vw;
}
.bingo-banner.show { transform: translateX(-50%) translateY(0); }

#confetti {
  position: fixed; inset: 0;
  pointer-events: none;
  z-index: 55;
}

/* ---------------- Toast ---------------- */
.toast {
  position: fixed;
  bottom: 24px; left: 50%;
  transform: translateX(-50%) translateY(140%);
  background: var(--surface-strong);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 18px;
  border-radius: 999px;
  z-index: 60;
  transition: transform 0.3s ease;
  backdrop-filter: blur(8px);
  font-size: 0.9rem;
}
.toast.show { transform: translateX(-50%) translateY(0); }

/* ---------------- Responsive ---------------- */
@media (max-width: 720px) {
  .game-body { grid-template-columns: 1fr; }
  .participants {
    position: static;
    order: 2;
  }
  #participant-list { flex-direction: row; flex-wrap: wrap; }
  .participant { padding: 4px 8px; background: rgba(0,0,0,0.2); border-radius: 999px; }
  .participant .p-name { max-width: 90px; }
}
