/* ---------- Theme ---------- */
:root {
  --paper:        #fbfaf3;
  --paper-edge:   #efeadb;
  --grid-minor:   #b9b3a0;
  --grid-major:   #6e6852;
  --ink:          #2a2620;
  --ink-soft:     #6b6657;
  --panel:        #ffffff;
  --panel-border: #d8d2bf;
  --shadow:       0 8px 24px rgba(0,0,0,0.10), 0 2px 6px rgba(0,0,0,0.06);
  --strip-bg:     #f6f2e2;
}

* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0; height: 100%;
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  color: var(--ink);
  background: var(--paper-edge);
  -webkit-tap-highlight-color: transparent;
  user-select: none; -webkit-user-select: none;
}
#app { display: flex; flex-direction: column; height: 100%; }

/* ---------- Header ---------- */
#header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--panel-border);
  box-shadow: 0 2px 8px rgba(0,0,0,0.04);
  flex: 0 0 auto;
  gap: 12px;
  z-index: 10;
  position: relative;
}
.brand { font-weight: 700; font-size: 18px; letter-spacing: 0.5px; line-height: 1.1; flex: 0 0 auto; }
.brand small {
  display: block; font-weight: 400; font-size: 11px;
  color: var(--ink-soft); letter-spacing: 0; margin-top: 2px; font-style: italic;
}
.scoreboard {
  display: flex; gap: 10px; flex: 1 1 auto;
  align-items: stretch; justify-content: center; min-width: 0;
}
.player-panel {
  flex: 1 1 0; max-width: 320px;
  display: flex; align-items: center; gap: 10px;
  padding: 8px 12px;
  background: var(--panel);
  border: 2px solid var(--panel-border);
  border-radius: 10px;
  transition: border-color 0.3s, background 0.3s;
  position: relative; overflow: hidden;
}
.player-panel.inactive { opacity: 0.55; }
.player-panel.active {
  border-color: var(--player-color, #888);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--player-color, #888) 25%, transparent);
}
.player-panel.active.idle { animation: turnFlash 2.4s ease-in-out infinite; }
@keyframes turnFlash {
  0%   { background: var(--panel); }
  4%   { background: color-mix(in srgb, var(--player-color, #888) 22%, var(--panel)); }
  8%   { background: var(--panel); }
  12%  { background: color-mix(in srgb, var(--player-color, #888) 22%, var(--panel)); }
  16%  { background: var(--panel); }
  20%  { background: color-mix(in srgb, var(--player-color, #888) 22%, var(--panel)); }
  24%  { background: var(--panel); }
  100% { background: var(--panel); }
}
.avatar {
  width: 44px; height: 44px;
  border-radius: 50%; overflow: hidden;
  flex: 0 0 auto;
  background: var(--paper);
  border: 2px solid var(--panel-border);
  display: flex; align-items: center; justify-content: center;
  font-size: 24px; line-height: 1;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }
.player-panel .avatar { border-color: var(--player-color, var(--panel-border)); }
.player-info { min-width: 0; flex: 1 1 auto; }
.player-name {
  font-weight: 600; font-size: 15px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  display: flex; align-items: center; gap: 6px;
}
.color-swatch {
  display: inline-block; width: 12px; height: 12px;
  border-radius: 50%;
  background: var(--player-color, #888);
  flex: 0 0 auto;
  border: 1px solid rgba(0,0,0,0.15);
}
.player-stats {
  font-size: 12px; color: var(--ink-soft); margin-top: 2px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.player-stats b { color: var(--ink); font-weight: 600; }
.you-badge {
  display: inline-block; font-size: 9px;
  background: var(--ink); color: var(--paper);
  padding: 1px 6px; border-radius: 999px;
  letter-spacing: 0.6px; text-transform: uppercase; font-weight: 700;
  margin-left: 6px;
}
.header-actions { display: flex; gap: 8px; flex: 0 0 auto; }
.icon-btn {
  width: 38px; height: 38px;
  border-radius: 8px;
  border: 1px solid var(--panel-border);
  background: var(--panel);
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  color: var(--ink); font-size: 18px; padding: 0;
  transition: background 0.15s, border-color 0.15s;
}
.icon-btn:hover { background: var(--paper); border-color: var(--ink-soft); }
.icon-btn:active { transform: scale(0.95); }

/* ---------- Match strip ---------- */
#match-strip {
  flex: 0 0 auto;
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: 6px 16px;
  background: var(--strip-bg);
  border-bottom: 1px solid var(--panel-border);
  font-size: 13px; color: var(--ink-soft);
  z-index: 9; flex-wrap: wrap;
}
#match-strip .left, #match-strip .right { display: flex; align-items: center; gap: 8px; min-width: 0; }
#match-strip b { color: var(--ink); font-weight: 600; }
.upnext-chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 10px 3px 4px;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 999px;
  font-size: 12px; color: var(--ink);
}
.mini-avatar {
  width: 22px; height: 22px; border-radius: 50%;
  background: var(--paper);
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; overflow: hidden; flex: 0 0 auto;
  border: 1px solid var(--panel-border);
}
.mini-avatar img { width: 100%; height: 100%; object-fit: cover; }

#main { flex: 1 1 auto; position: relative; overflow: hidden; background: var(--paper-edge); }

/* ---------- Screens ---------- */
.screen {
  position: absolute; inset: 0; overflow: auto; padding: 24px;
  display: flex; align-items: center; justify-content: center;
}
.screen-inner { width: 100%; max-width: 760px; }
.screen-title { text-align: center; margin: 0 0 8px; font-size: 28px; font-weight: 700; }
.screen-sub { text-align: center; margin: 0 0 22px; color: var(--ink-soft); font-size: 15px; }
.center-narrow { max-width: 480px; margin: 0 auto; }

.panel-card {
  background: var(--panel);
  border: 2px solid var(--panel-border);
  border-radius: 14px;
  padding: 18px;
  box-shadow: var(--shadow);
}

.section-label {
  font-size: 13px; text-transform: uppercase; letter-spacing: 1.2px;
  color: var(--ink-soft); font-weight: 700; margin: 0 0 10px;
}

/* ---------- Sign-up / lobby ---------- */
.lobby-grid {
  display: grid; gap: 14px;
  grid-template-columns: 1fr 1fr;
}
@media (max-width: 720px) { .lobby-grid { grid-template-columns: 1fr; } }
.lobby-card {
  background: var(--panel);
  border: 2px solid var(--panel-border);
  border-radius: 14px;
  padding: 18px;
  display: flex; flex-direction: column; gap: 10px;
}
.lobby-card h3 { margin: 0 0 4px; font-size: 18px; }

.input {
  width: 100%; padding: 10px 12px;
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  font-size: 15px; font-family: inherit;
  color: var(--ink); background: var(--paper);
  text-transform: uppercase;
  letter-spacing: 2px;
  font-weight: 700;
  text-align: center;
}
.input:focus { outline: 2px solid var(--ink); outline-offset: -1px; }
.input.normal { text-transform: none; letter-spacing: 0; font-weight: 400; text-align: left; }

.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

.profile-card {
  display: flex; align-items: center; gap: 12px;
  padding: 10px;
  background: var(--paper);
  border-radius: 10px;
  border: 1px dashed var(--panel-border);
}
.profile-card .avatar { width: 56px; height: 56px; font-size: 30px; }
.profile-card .name { font-weight: 600; font-size: 17px; }
.profile-card .hint { font-size: 12px; color: var(--ink-soft); }

/* ---------- Buttons ---------- */
.btn {
  appearance: none;
  border: 1px solid var(--panel-border);
  background: var(--panel);
  color: var(--ink);
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 14px; font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.1s;
  font-family: inherit;
}
.btn:hover { background: var(--paper); border-color: var(--ink-soft); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.btn.primary:hover { background: #000; }
.btn.primary:disabled { background: #b8b3a0; border-color: #b8b3a0; cursor: not-allowed; transform: none; }
.btn.danger { color: #b91c1c; border-color: #f3c5c5; }
.btn.danger:hover { background: #fdf2f2; }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: var(--paper); border-color: var(--panel-border); }
.btn.block { display: block; width: 100%; }

/* ---------- Roster (in-room view) ---------- */
.roster-list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 12px; }
.roster-row {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px;
  background: var(--paper);
  border: 1px solid var(--panel-border);
  border-radius: 10px;
}
.roster-row .num {
  width: 22px; height: 22px;
  border-radius: 50%;
  background: var(--ink); color: var(--paper);
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 700; flex: 0 0 auto;
}
.roster-row .name { flex: 1 1 auto; font-weight: 600; }
.roster-row .badges { display: flex; gap: 4px; }
.roster-row .badge {
  font-size: 10px; padding: 2px 6px; border-radius: 999px;
  background: var(--strip-bg); color: var(--ink-soft); text-transform: uppercase; letter-spacing: 0.6px;
  font-weight: 700;
}
.roster-row .badge.you { background: var(--ink); color: var(--paper); }
.roster-empty {
  padding: 18px; text-align: center;
  color: var(--ink-soft); font-style: italic;
  background: var(--paper);
  border: 1px dashed var(--panel-border); border-radius: 10px;
}
.spectator-list {
  display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px;
}
.spectator-chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px 4px 4px;
  background: var(--paper);
  border: 1px solid var(--panel-border);
  border-radius: 999px;
  font-size: 12px;
}

/* ---------- Color picker ---------- */
.color-slots { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
@media (max-width: 720px) { .color-slots { grid-template-columns: 1fr; } }
.color-slot {
  background: var(--panel);
  border: 2px solid var(--panel-border);
  border-radius: 14px;
  padding: 16px;
  box-shadow: var(--shadow);
}
.color-slot.disabled-slot { opacity: 0.55; }
.color-slot-head { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.color-slot-head .name { font-weight: 700; font-size: 17px; }
.color-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.color-cell {
  height: 56px; border-radius: 10px;
  cursor: pointer;
  border: 3px solid transparent;
  position: relative;
  transition: transform 0.1s, border-color 0.15s, opacity 0.2s;
}
.color-cell:hover { transform: scale(1.04); }
.color-cell.selected { border-color: var(--ink); transform: scale(1.04); }
.color-cell.disabled { opacity: 0.25; cursor: not-allowed; transform: none; }
.color-cell.disabled:hover { transform: none; }
.color-cell.locked { cursor: default; }
.color-cell.locked:hover { transform: none; }
.color-cell .check {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  color: white; font-size: 24px; font-weight: 700;
  text-shadow: 0 1px 3px rgba(0,0,0,0.35);
  opacity: 0; transition: opacity 0.15s;
}
.color-cell.selected .check { opacity: 1; }

/* ---------- Game board ---------- */
#board-wrap {
  position: absolute; inset: 0; overflow: hidden;
  cursor: grab; touch-action: none;
  background: var(--paper-edge);
}
#board-wrap.grabbing { cursor: grabbing; }
#board-wrap.locked { cursor: default; }
#board-svg { display: block; width: 100%; height: 100%; }

.board-overlay { position: absolute; pointer-events: none; z-index: 5; }
.board-overlay.bottom {
  bottom: 14px; left: 50%; transform: translateX(-50%);
  display: flex; gap: 8px; pointer-events: auto;
}
.pill-btn {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  color: var(--ink);
  padding: 8px 14px; border-radius: 999px;
  font-size: 13px; font-weight: 600;
  box-shadow: var(--shadow);
  cursor: pointer;
  display: flex; align-items: center; gap: 6px;
  pointer-events: auto;
}
.pill-btn:hover { background: var(--paper); }
.pill-btn.label { cursor: default; }
.pill-btn.label:hover { background: var(--panel); }

.edge-arrow {
  position: absolute; width: 36px; height: 36px;
  border-radius: 50%;
  background: rgba(255,255,255,0.85);
  border: 1px solid var(--panel-border);
  color: var(--ink);
  display: flex; align-items: center; justify-content: center;
  font-size: 18px; font-weight: 700;
  pointer-events: none; opacity: 0;
  transition: opacity 0.2s; z-index: 4;
  box-shadow: var(--shadow);
}
.edge-arrow.show { opacity: 0.85; }

.winner-banner {
  position: absolute; inset: 0;
  pointer-events: none;
  display: flex; align-items: center; justify-content: center;
  z-index: 6;
  opacity: 0; transition: opacity 0.4s;
}
.winner-banner.show { opacity: 1; }
.winner-banner .card {
  background: rgba(255,255,255,0.96);
  padding: 22px 28px;
  border-radius: 18px;
  box-shadow: 0 16px 50px rgba(0,0,0,0.25), 0 0 0 6px var(--win-color, var(--ink));
  text-align: center;
  transform: scale(0.85);
  transition: transform 0.4s cubic-bezier(.18,1.18,.6,1.2);
  max-width: 80%;
}
.winner-banner.show .card { transform: scale(1); }
.winner-banner .label {
  text-transform: uppercase; letter-spacing: 2px;
  font-size: 12px; color: var(--ink-soft);
  font-weight: 700; margin-bottom: 6px;
}
.winner-banner .name {
  font-size: 32px; font-weight: 800;
  color: var(--win-color, var(--ink));
  margin-bottom: 4px;
}
.winner-banner .sub { font-size: 13px; color: var(--ink-soft); margin-bottom: 6px; }

.board-dim {
  position: absolute; inset: 0;
  background: rgba(20, 18, 12, 0.18);
  z-index: 3; pointer-events: none;
  opacity: 0; transition: opacity 0.3s;
}
.board-dim.show { opacity: 1; }

/* ---------- Modal ---------- */
#modal-root {
  position: fixed; inset: 0;
  background: rgba(20, 18, 12, 0.45);
  display: flex; align-items: center; justify-content: center;
  z-index: 100; padding: 20px;
  animation: fadeIn 0.18s ease;
}
#modal-root.hidden { display: none; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.modal {
  background: var(--panel);
  border-radius: 14px;
  padding: 22px;
  max-width: 480px; width: 100%;
  max-height: 90vh; overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
  border: 1px solid var(--panel-border);
}
.modal h2 { margin: 0 0 8px; font-size: 22px; font-weight: 700; }
.modal p { margin: 0 0 16px; color: var(--ink-soft); line-height: 1.45; }
.modal-actions {
  display: flex; gap: 10px;
  justify-content: flex-end;
  flex-wrap: wrap;
}
.modal label {
  display: block;
  font-size: 13px; font-weight: 600;
  color: var(--ink-soft);
  margin: 12px 0 6px;
  text-transform: uppercase;
  letter-spacing: 0.8px;
}
.modal input[type="text"] {
  width: 100%; padding: 10px 12px;
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  font-size: 15px; font-family: inherit;
  color: var(--ink); background: var(--paper);
}
.modal input[type="text"]:focus { outline: 2px solid var(--ink); outline-offset: -1px; }

.emoji-grid { display: grid; grid-template-columns: repeat(8, 1fr); gap: 6px; margin-top: 6px; }
@media (max-width: 480px) { .emoji-grid { grid-template-columns: repeat(6, 1fr); } }
.emoji-cell {
  aspect-ratio: 1;
  border: 2px solid transparent;
  border-radius: 8px;
  background: var(--paper);
  display: flex; align-items: center; justify-content: center;
  font-size: 24px; cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.emoji-cell:hover { background: color-mix(in srgb, var(--ink) 5%, var(--paper)); }
.emoji-cell.selected { border-color: var(--ink); background: color-mix(in srgb, var(--ink) 10%, var(--paper)); }

.upload-zone {
  margin-top: 8px; padding: 14px;
  border: 2px dashed var(--panel-border);
  border-radius: 10px; text-align: center;
  cursor: pointer;
  background: var(--paper);
  color: var(--ink-soft); font-size: 13px;
}
.upload-zone:hover { border-color: var(--ink-soft); color: var(--ink); }
.upload-zone.has-image { background: var(--panel); border-style: solid; }
.upload-preview {
  width: 64px; height: 64px;
  border-radius: 50%;
  margin: 0 auto 8px;
  object-fit: cover;
  display: block;
  border: 2px solid var(--panel-border);
}

.winner-display {
  display: flex; flex-direction: column; align-items: center;
  gap: 8px; padding: 18px 0 8px;
}
.winner-display .avatar { width: 80px; height: 80px; font-size: 40px; border-width: 4px; }
.winner-name { font-size: 22px; font-weight: 700; }
.winner-sub { color: var(--ink-soft); font-size: 14px; }

.head-to-head {
  margin-top: 16px; padding: 12px;
  background: var(--paper); border-radius: 10px;
  text-align: center; font-size: 13px; color: var(--ink-soft);
}
.head-to-head .h2h-line { font-size: 16px; font-weight: 600; color: var(--ink); margin-top: 4px; }

.standings {
  margin-top: 14px;
  background: var(--paper);
  border-radius: 10px;
  padding: 10px 12px;
}
.standings-title {
  font-size: 12px; text-transform: uppercase; letter-spacing: 1.2px;
  color: var(--ink-soft); font-weight: 700; margin-bottom: 6px;
}
.standings-row {
  display: flex; align-items: center; gap: 10px;
  padding: 6px 4px;
  border-bottom: 1px solid var(--panel-border);
  font-size: 14px;
}
.standings-row:last-child { border-bottom: none; }
.standings-row .pos {
  width: 22px; height: 22px;
  border-radius: 50%;
  background: var(--ink-soft); color: var(--paper);
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 700; flex: 0 0 auto;
}
.standings-row.first .pos { background: #ca8a04; }
.standings-row .avatar { width: 32px; height: 32px; font-size: 18px; }
.standings-row .name { flex: 1 1 auto; font-weight: 600; }
.standings-row .wins { font-weight: 700; color: var(--ink); }

.match-settings {
  background: var(--paper);
  padding: 12px;
  border-radius: 10px;
  border: 1px solid var(--panel-border);
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
}
.match-settings label { margin: 0; font-size: 13px; color: var(--ink); text-transform: none; letter-spacing: 0; font-weight: 600; }
.match-settings select {
  padding: 6px 10px;
  border-radius: 6px;
  border: 1px solid var(--panel-border);
  background: var(--panel);
  font-size: 14px; font-family: inherit;
}

/* Room code display */
.room-code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 28px;
  font-weight: 800;
  letter-spacing: 6px;
  text-align: center;
  padding: 14px;
  background: var(--paper);
  border: 2px dashed var(--ink-soft);
  border-radius: 12px;
  color: var(--ink);
  cursor: copy;
}
.room-code:hover { background: color-mix(in srgb, var(--ink) 5%, var(--paper)); }
.room-code-help {
  text-align: center;
  font-size: 13px;
  color: var(--ink-soft);
  margin-top: 6px;
}

/* ---------- Toast ---------- */
.toast {
  position: fixed; bottom: 80px; left: 50%;
  transform: translateX(-50%);
  background: var(--ink); color: var(--paper);
  padding: 10px 18px; border-radius: 999px;
  font-size: 14px; font-weight: 500;
  z-index: 200;
  opacity: 0; pointer-events: none;
  transition: opacity 0.2s;
  box-shadow: var(--shadow);
}
.toast.show { opacity: 1; }
.toast.error { background: #b91c1c; }

.hidden { display: none !important; }

/* ---------- Lounge layout (single global lounge) ---------- */
#lounge-layout {
  position: absolute; inset: 0;
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: 0;
}
@media (max-width: 720px) {
  #lounge-layout { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
}

#lineup-panel {
  background: var(--panel);
  border-right: 1px solid var(--panel-border);
  overflow-y: auto;
  padding: 14px;
  display: flex; flex-direction: column;
  gap: 14px;
}
@media (max-width: 720px) {
  #lineup-panel { border-right: none; border-bottom: 1px solid var(--panel-border); max-height: 38vh; }
}

.lineup-section { display: flex; flex-direction: column; gap: 8px; }
.lineup-section.action-section {
  background: var(--paper);
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  padding: 12px;
}
.btn.big { font-size: 16px; padding: 14px 18px; }
.helper-text {
  font-size: 12px; color: var(--ink-soft); text-align: center;
  line-height: 1.35;
}

.lineup-list { display: flex; flex-direction: column; gap: 6px; }
.lineup-empty {
  font-size: 12px; color: var(--ink-soft); font-style: italic;
  padding: 8px 4px;
}

.lineup-row {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px;
  background: var(--paper);
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  position: relative; overflow: hidden;
}
.lineup-row.active {
  border-left: 4px solid var(--row-color, var(--ink));
  background: var(--panel);
}
.lineup-row.me { box-shadow: 0 0 0 2px var(--ink) inset; }
.lineup-row .avatar { width: 36px; height: 36px; font-size: 18px; }
.lineup-row .row-body { flex: 1 1 auto; min-width: 0; }
.lineup-row .row-name {
  font-weight: 600; font-size: 14px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  display: flex; align-items: center;
}
.lineup-row .row-meta { font-size: 11px; color: var(--ink-soft); margin-top: 2px; }
.lineup-row .row-badges { flex: 0 0 auto; }
.lineup-row .badge {
  font-size: 10px; padding: 2px 8px; border-radius: 999px;
  font-weight: 700; letter-spacing: 0.5px;
  background: var(--strip-bg); color: var(--ink-soft);
  white-space: nowrap;
}
.lineup-row .badge.turn { background: #16a34a; color: white; animation: pulseBadge 1.4s infinite; }
.lineup-row .badge.winner { background: #f59e0b; color: white; }
.lineup-row .badge.pos { background: var(--ink); color: var(--paper); }
@keyframes pulseBadge { 0%,100% { opacity: 1; } 50% { opacity: 0.55; } }

#board-area { position: relative; overflow: hidden; }
#board-wrap {
  position: absolute; inset: 0; overflow: hidden;
  cursor: grab; touch-action: none;
  background: var(--paper-edge);
}
#board-wrap.grabbing { cursor: grabbing; }
#board-svg { display: block; width: 100%; height: 100%; }

.board-empty {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  padding: 24px; text-align: center;
  background: var(--paper-edge);
  z-index: 2;
}
.empty-card {
  background: var(--panel);
  border: 2px dashed var(--panel-border);
  border-radius: 16px;
  padding: 28px 32px;
  max-width: 440px;
  box-shadow: var(--shadow);
}
/* Demo overlay (small corner card while demo plays) */
.board-empty.demo-overlay {
  background: transparent;
  pointer-events: none;
  align-items: flex-start;
  justify-content: flex-end;
  padding: 14px;
}
.demo-card {
  background: rgba(255,255,255,0.92);
  border: 1px solid var(--panel-border);
  border-radius: 999px;
  padding: 6px 14px 6px 8px;
  display: flex; align-items: center; gap: 10px;
  box-shadow: var(--shadow);
  font-size: 12px;
  pointer-events: auto;
}
.demo-pill {
  display: inline-flex; align-items: center; gap: 6px;
  font-weight: 700; color: var(--ink);
  background: var(--ink); color: var(--paper);
  padding: 3px 10px; border-radius: 999px;
}
.demo-pill .dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: #f59e0b;
  animation: pulseDot 1.4s ease-in-out infinite;
}
@keyframes pulseDot { 0%,100% { opacity: 0.4; } 50% { opacity: 1; } }
.demo-line { color: var(--ink-soft); }

/* Center overlay (Start button + color picker, on top of the board) */
.board-overlay-center {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  z-index: 6; pointer-events: none; padding: 16px;
}
.board-overlay-center.hidden { display: none; }
.center-card {
  background: rgba(255,255,255,0.97);
  border: 2px solid var(--panel-border);
  border-radius: 16px;
  padding: 22px 26px;
  box-shadow: 0 16px 40px rgba(0,0,0,0.18);
  max-width: 92%;
  pointer-events: auto;
  text-align: center;
}
.center-card.small { padding: 12px 18px; }
.center-card.wide { max-width: 640px; width: 100%; }
.center-title {
  font-size: 14px; text-transform: uppercase; letter-spacing: 1.4px;
  color: var(--ink-soft); font-weight: 700; margin-bottom: 14px;
}
.center-hint {
  margin-top: 10px; font-size: 12px; color: var(--ink-soft);
}
.vs-row {
  display: flex; align-items: center; justify-content: center; gap: 18px;
  margin-bottom: 14px;
}
.vs-row.tiny { gap: 8px; font-size: 13px; margin-bottom: 6px; }
.vs-side { display: flex; flex-direction: column; align-items: center; gap: 6px; }
.vs-side .avatar.big { width: 64px; height: 64px; font-size: 32px; }
.vs-side .vs-name { font-weight: 700; font-size: 14px; }
.vs-x {
  font-weight: 800; color: var(--ink-soft);
  font-size: 18px; letter-spacing: 0.5px;
}

/* Mini color picker (inline in the center card) */
.color-slots { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
@media (max-width: 600px) { .color-slots { grid-template-columns: 1fr; } }
.color-slot {
  background: var(--paper);
  border: 2px solid var(--panel-border);
  border-radius: 12px;
  padding: 12px;
}
.color-slot.disabled-slot { opacity: 0.55; }
.color-slot-head { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.color-slot-head .avatar { width: 32px; height: 32px; font-size: 16px; }
.color-slot-name { font-weight: 700; font-size: 14px; }
.color-grid-mini { display: grid; grid-template-columns: repeat(8, 1fr); gap: 6px; }
.color-cell-mini {
  aspect-ratio: 1;
  border-radius: 6px;
  cursor: pointer;
  border: 3px solid transparent;
  transition: transform 0.1s, border-color 0.15s, opacity 0.2s;
}
.color-cell-mini:hover { transform: scale(1.08); }
.color-cell-mini.selected { border-color: var(--ink); transform: scale(1.08); }
.color-cell-mini.disabled { opacity: 0.25; cursor: not-allowed; }
.color-cell-mini.disabled:hover { transform: none; }
.color-cell-mini.locked { cursor: default; }
.color-cell-mini.locked:hover { transform: none; }

.empty-card .empty-icon { font-size: 48px; margin-bottom: 12px; }
.empty-card .empty-icon.mascot {
  font-size: 128px;
  display: inline-block;
  animation: mascotWobble 2.4s ease-in-out infinite;
  transform-origin: 50% 80%;
}
@keyframes mascotWobble {
  0%, 100% { transform: rotate(-6deg); }
  50%      { transform: rotate(6deg); }
}
.brand-mascot {
  display: inline-block;
  font-size: 22px;
  margin-right: 4px;
  animation: mascotWobble 3s ease-in-out infinite;
  transform-origin: 50% 80%;
}
.empty-card .avatar.big { width: 80px; height: 80px; font-size: 40px; margin: 0 auto 14px; }
.empty-card h2 { margin: 0 0 8px; font-size: 22px; }
.empty-card p { margin: 0; color: var(--ink-soft); }
.empty-card b { color: var(--ink); }

/* Confetti & balloons & loser tease — full window, never clipped by board */
#celebration-layer {
  position: fixed; inset: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: 90;
}
.confetti-layer { /* legacy in-board layer, kept empty */
  position: absolute; inset: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: 7;
}
.confetti {
  position: absolute; top: -20px;
  width: 10px; height: 14px;
  border-radius: 2px;
  animation: confettiFall linear forwards;
  box-shadow: 0 1px 2px rgba(0,0,0,0.15);
}
.confetti.balloon {
  width: 28px; height: 34px;
  border-radius: 50% 50% 45% 45%;
  animation: balloonRise ease-out forwards;
  box-shadow: 0 4px 10px rgba(0,0,0,0.18), inset -6px -6px 12px rgba(0,0,0,0.15);
  position: absolute;
}
.confetti.balloon::after {
  content: '';
  position: absolute; left: 50%; top: 100%;
  width: 1px; height: 30px;
  background: rgba(0,0,0,0.4);
}
@keyframes confettiFall {
  0%   { transform: translateY(-20px) rotate(0deg);   opacity: 1; }
  85%  { opacity: 1; }
  100% { transform: translateY(110vh) rotate(720deg); opacity: 0; }
}
@keyframes balloonRise {
  0%   { transform: translateY(110vh) translateX(0);   opacity: 1; }
  100% { transform: translateY(-30vh) translateX(20px); opacity: 0; }
}

/* Demo cursors — one per slot, color-matched to the player */
.demo-cursor {
  position: absolute;
  top: 0; left: 0;
  width: 28px; height: 28px;
  pointer-events: none;
  z-index: 5;
  transition: opacity 0.3s;
  filter: drop-shadow(0 2px 3px rgba(0,0,0,0.35));
  will-change: transform;
}
.demo-cursor.clicking::after {
  content: '';
  position: absolute;
  left: 0; top: 0;
  width: 28px; height: 28px;
  border-radius: 50%;
  border: 2px solid rgba(31, 41, 55, 0.6);
  animation: demoCursorClick 0.35s ease-out forwards;
}
@keyframes demoCursorClick {
  0%   { transform: scale(0.3); opacity: 0.9; }
  100% { transform: scale(2.2); opacity: 0; }
}

/* Rising loser tease — "pran nan mòpyon!" */
.tease-banner {
  position: absolute;
  left: 50%;
  bottom: 20%;
  transform: translateX(-50%) translateY(0) scale(0.9);
  font-size: clamp(28px, 6vw, 64px);
  font-weight: 900;
  color: #ef4444;
  text-shadow:
    -2px -2px 0 #fff, 2px -2px 0 #fff, -2px 2px 0 #fff, 2px 2px 0 #fff,
    0 0 18px rgba(239, 68, 68, 0.45),
    0 8px 30px rgba(0, 0, 0, 0.25);
  white-space: nowrap;
  pointer-events: none;
  animation: teaseRise 5s cubic-bezier(0.2, 0.7, 0.3, 1) forwards;
  letter-spacing: 0.5px;
  z-index: 9;
  text-align: center;
}
.tease-banner .tease-name { color: #f59e0b; }
@keyframes teaseRise {
  0%   { transform: translateX(-50%) translateY(40px) scale(0.6) rotate(-3deg); opacity: 0; }
  10%  { transform: translateX(-50%) translateY(0) scale(1.1) rotate(2deg);     opacity: 1; }
  25%  { transform: translateX(-50%) translateY(-20px) scale(1) rotate(-2deg); }
  60%  { transform: translateX(-50%) translateY(-40vh) scale(1) rotate(2deg);   opacity: 1; }
  100% { transform: translateX(-50%) translateY(-90vh) scale(1.1) rotate(0);    opacity: 0; }
}

/* ---------- Mobile tweaks ---------- */
@media (max-width: 600px) {
  .brand { font-size: 14px; }
  .brand small { font-size: 9px; }
  .player-panel { padding: 6px 8px; gap: 8px; }
  .avatar { width: 36px; height: 36px; font-size: 20px; }
  .player-name { font-size: 13px; }
  .player-stats { font-size: 11px; }
  .icon-btn { width: 34px; height: 34px; font-size: 16px; }
  .screen-title { font-size: 22px; }
  #match-strip { font-size: 12px; padding: 5px 10px; }
  .winner-banner .name { font-size: 24px; }
  .room-code { font-size: 24px; letter-spacing: 4px; }
}
