:root {
  --bg: #0f1117;
  --surface: #171a23;
  --surface-2: #1e222e;
  --border: #2a2f3d;
  --text: #e8eaf0;
  --muted: #9aa1b4;
  --accent: #6366f1;
  --accent-soft: #4338ca;
  --success: #22c55e;
  --danger: #ef4444;
  --gold: #fbbf24;
  --radius: 12px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;

  /* LSBingo brand */
  --brand-l: #0171bb;
  --brand-s: #a3b61c;
  --brand-b: #f07901;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f5f6fa;
    --surface: #ffffff;
    --surface-2: #eef0f6;
    --border: #d9dde8;
    --text: #14161d;
    --muted: #666e85;
  }
}

* { box-sizing: border-box; }

/* Any rule that sets `display` outbids the [hidden] attribute's UA style, which
   silently leaves elements on screen. Make the attribute always win. */
[hidden] { display: none !important; }

body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

.sr-only {
  position: absolute; width: 1px; height: 1px;
  padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* --------------------------------------------------------------- wordmark --- */

.wordmark {
  font-weight: 800;
  letter-spacing: -0.015em;
  white-space: nowrap;
}
.wordmark .wm-l { color: var(--brand-l); }
.wordmark .wm-s { color: var(--brand-s); }
.wordmark .wm-b { color: var(--brand-b); }

.wordmark-lg { font-size: 34px; margin: 0 0 10px; }

/* The board's own name, shown only when it differs from the app name. */
.board-title {
  color: var(--muted);
  font-size: 14px;
  font-weight: 500;
}

/* ------------------------------------------------------------------ login --- */

.login-body {
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 40px 32px;
  width: min(100%, 400px);
  text-align: center;
  box-shadow: 0 20px 50px rgb(0 0 0 / 0.25);
}

.login-card .board-title { margin: 0 0 6px; }
.muted { color: var(--muted); font-size: 14px; line-height: 1.55; margin: 14px 0 24px; }

input[type="email"] {
  width: 100%;
  padding: 12px 14px;
  font-size: 15px;
  font-family: inherit;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  margin-bottom: 12px;
}
input[type="email"]:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgb(99 102 241 / 0.25);
}

button {
  font-family: inherit;
  font-size: 15px;
  cursor: pointer;
  border: none;
  border-radius: 10px;
}

#submit {
  width: 100%;
  padding: 12px 16px;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  transition: background 0.15s;
}
#submit:hover:not(:disabled) { background: var(--accent-soft); }
#submit:disabled { opacity: 0.6; cursor: default; }

.message { font-size: 14px; line-height: 1.5; margin: 16px 0 0; min-height: 20px; }
.message.error { color: var(--danger); }
.message.success { color: var(--success); }
.message a { color: var(--accent); }

/* ----------------------------------------------------------------- topbar --- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
}

.topbar-left, .topbar-right { display: flex; align-items: center; gap: 12px; }
.topbar h1 { font-size: 19px; margin: 0; }
.topbar .board-title {
  padding-left: 12px;
  border-left: 1px solid var(--border);
  max-width: 30ch;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.pill {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 3px 9px;
  border-radius: 999px;
}
.pill-online { background: rgb(34 197 94 / 0.15); color: var(--success); }
.pill-offline { background: rgb(239 68 68 / 0.15); color: var(--danger); }
.pill-connecting, .pill-reconnecting { background: rgb(251 191 36 / 0.15); color: var(--gold); }

.presence { display: flex; }

.avatar {
  display: grid;
  place-items: center;
  width: 30px; height: 30px;
  border-radius: 50%;
  font-size: 11px;
  font-weight: 700;
  color: #fff;
  border: 2px solid var(--surface);
  margin-left: -8px;
  cursor: default;
  text-shadow: 0 1px 2px rgb(0 0 0 / 0.3);
}
.avatar:first-child { margin-left: 0; }
.avatar.you { box-shadow: 0 0 0 2px var(--accent); }

.icon-button {
  background: var(--surface-2);
  color: var(--text);
  width: 32px; height: 32px;
  font-size: 16px;
  line-height: 1;
  border: 1px solid var(--border);
}
.icon-button:hover { background: var(--border); }

.menu { position: relative; }

.menu-panel {
  position: absolute;
  right: 0; top: calc(100% + 8px);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 6px;
  min-width: 220px;
  box-shadow: 0 12px 32px rgb(0 0 0 / 0.3);
  display: flex;
  flex-direction: column;
}
.menu-panel button {
  background: none;
  color: var(--text);
  text-align: left;
  padding: 9px 12px;
  font-size: 14px;
  border-radius: 7px;
}
.menu-panel button:hover { background: var(--surface-2); }
.menu-panel button.danger { color: var(--danger); }
.menu-panel hr { border: none; border-top: 1px solid var(--border); margin: 6px 4px; width: calc(100% - 8px); }
.menu-who { font-size: 12px; color: var(--muted); padding: 4px 12px 8px; word-break: break-all; }

/* ------------------------------------------------------------------ board --- */

main {
  max-width: 1000px;
  margin: 0 auto;
  padding: 24px 20px 48px;
}

.stats {
  display: flex;
  gap: 20px;
  justify-content: center;
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.stats strong { color: var(--text); font-size: 15px; }
.stat-bingo strong { color: var(--gold); }

.board {
  display: grid;
  grid-template-columns: repeat(var(--size, 5), 1fr);
  grid-auto-rows: 1fr; /* rows share the square evenly instead of growing with content */
  gap: 8px;
  aspect-ratio: 1;
}

.cell {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  text-align: center;
  cursor: pointer;
  overflow: hidden;
  min-width: 0;
  min-height: 0;
  transition: transform 0.12s, background 0.15s, border-color 0.15s;
  container-type: inline-size;
}
.cell:hover { border-color: var(--accent); transform: translateY(-1px); }
.cell:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.cell-text {
  font-size: clamp(10px, 13cqw, 15px);
  line-height: 1.25;
  font-weight: 500;
  overflow-wrap: anywhere;
  max-height: 100%;
  overflow: hidden;
}

.cell.empty { background: transparent; border-style: dashed; }
.cell-placeholder { color: var(--muted); font-size: 20px; opacity: 0.5; }

.cell-byline {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 4px;
  max-width: 100%;
  min-width: 0;
  font-size: clamp(7px, 6cqw, 10px);
  color: var(--muted);
  opacity: 0.8;
}

/* The name gives way first; the timestamp is never truncated. */
.cell-who {
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.cell-time {
  flex: none;
  font-variant-numeric: tabular-nums;
  opacity: 0.9;
}

.cell.marked {
  background: linear-gradient(160deg, var(--accent) 0%, var(--accent-soft) 100%);
  border-color: transparent;
  color: #fff;
}
.cell.marked .cell-byline { color: rgb(255 255 255 / 0.8); }

.cell.winning {
  box-shadow: 0 0 0 2px var(--gold), 0 0 18px rgb(251 191 36 / 0.4);
  animation: pop 0.4s ease;
}

.cell.locked { cursor: default; }
.cell.locked:hover { transform: none; border-color: var(--border); }

.cell.being-edited { border-color: var(--editor-color, var(--accent)); }

.cell-editing {
  position: absolute;
  bottom: 0; left: 0; right: 0;
  font-size: 9px;
  font-weight: 600;
  color: #fff;
  padding: 2px 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.cell.editing { cursor: text; padding: 4px; }

.cell-input {
  width: 100%;
  height: 100%;
  resize: none;
  border: none;
  background: transparent;
  color: inherit;
  font-family: inherit;
  font-size: clamp(10px, 13cqw, 15px);
  line-height: 1.25;
  text-align: center;
  padding: 4px;
}
.cell-input:focus { outline: none; }

.hint {
  text-align: center;
  color: var(--muted);
  font-size: 12.5px;
  margin-top: 18px;
}

@keyframes pop {
  0% { transform: scale(1); }
  50% { transform: scale(1.06); }
  100% { transform: scale(1); }
}

/* ----------------------------------------------------------------- toasts --- */

.toasts {
  position: fixed;
  bottom: 20px; left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
  z-index: 50;
  pointer-events: none;
}

.toast {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 9px 16px;
  border-radius: 999px;
  font-size: 13px;
  box-shadow: 0 8px 24px rgb(0 0 0 / 0.3);
  animation: rise 0.25s ease;
}
.toast.error { border-color: var(--danger); color: var(--danger); }
.toast.leaving { opacity: 0; transition: opacity 0.3s; }

@keyframes rise {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ----------------------------------------------------------------- banner --- */

.bingo-banner {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  pointer-events: none;
  z-index: 40;
}

.bingo-banner-inner {
  background: linear-gradient(135deg, var(--gold), #f97316);
  color: #1a1200;
  padding: 24px 48px;
  border-radius: 20px;
  text-align: center;
  box-shadow: 0 24px 60px rgb(0 0 0 / 0.4);
  animation: pop 0.5s ease;
}
.bingo-word { display: block; font-size: 44px; font-weight: 900; letter-spacing: 0.06em; }
.bingo-banner-inner span:last-child { font-size: 14px; font-weight: 600; opacity: 0.8; }

/* ------------------------------------------------------------------ small --- */

@media (max-width: 620px) {
  .topbar { padding: 10px 12px; }
  .topbar h1 { font-size: 15px; }
  main { padding: 16px 10px 32px; }
  .board { gap: 5px; }
  .cell { border-radius: 8px; padding: 4px; }
  .stats { gap: 12px; }
}
