* { box-sizing: border-box; }

body {
  font-family: system-ui, sans-serif;
  background: #14121a;
  color: #eee;
  margin: 0;
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.card {
  background: #1f1c28;
  border-radius: 16px;
  padding: 32px;
  max-width: 480px;
  width: 100%;
  text-align: center;
}

h1 { margin-top: 0; }

a.button, button {
  display: inline-block;
  background: #7c3aed;
  color: white;
  border: none;
  border-radius: 10px;
  padding: 14px 20px;
  font-size: 1rem;
  cursor: pointer;
  text-decoration: none;
  margin-top: 12px;
  width: 100%;
}

button:disabled { opacity: 0.5; cursor: not-allowed; }

input[type="text"] {
  width: 100%;
  padding: 14px;
  border-radius: 10px;
  border: 1px solid #444;
  background: #14121a;
  color: white;
  font-size: 1rem;
}

.qr img { background: white; padding: 12px; border-radius: 12px; }

ul.players {
  list-style: none;
  padding: 0;
  text-align: left;
}

ul.players li {
  background: #14121a;
  padding: 10px 14px;
  border-radius: 8px;
  margin-bottom: 6px;
}

.code {
  font-size: 1.4rem;
  letter-spacing: 4px;
  font-weight: bold;
  color: #a78bfa;
}

.error { color: #f87171; margin-top: 8px; }

/* --- 16-seat player grid (see public/grid.js) --- */

.player-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin: 12px 0;
}

.pg-cell {
  position: relative;
  /* the top padding is always there, bubble or not: cells must not jump
     around when somebody points at somebody else */
  padding: 26px 3px 8px;
  border: 2px solid transparent;
  border-radius: 12px;
  background: #14121a;
  text-align: center;
}

.pg-empty {
  border: 2px dashed #2a2733;
  background: transparent;
  opacity: 0.35;
}

.pg-figure { position: relative; display: inline-block; }
.pg-avatar { display: block; width: 34px; height: 41px; }

.pg-slot-num {
  position: absolute;
  right: -6px;
  bottom: -2px;
  min-width: 17px;
  padding: 0 3px;
  border-radius: 999px;
  background: #0d0c12;
  border: 1px solid #3f3b4d;
  font-size: 0.68rem;
  font-weight: bold;
  line-height: 16px;
}

.pg-empty .pg-slot-num {
  position: static;
  display: inline-block;
  margin-top: 22px;
  background: transparent;
  border: none;
}

.pg-name {
  margin-top: 6px;
  font-size: 0.68rem;
  line-height: 1.15;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Dead players: a red slash corner to corner, bottom-left to top-right. The
   skull in the corner alone was easy to miss when scanning the grid. Drawn
   with a gradient rather than a rotated bar so it keeps hitting the corners
   whatever the cell's size. */
.pg-dead::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 12px;
  pointer-events: none;
  background: linear-gradient(
    to bottom right,
    transparent calc(50% - 2px),
    rgba(239, 68, 68, 0.9) calc(50% - 2px),
    rgba(239, 68, 68, 0.9) calc(50% + 2px),
    transparent calc(50% + 2px)
  );
}

.pg-dead .pg-figure { opacity: 0.4; }
.pg-dead .pg-name {
  opacity: 0.5;
  text-decoration: line-through;
  padding-right: 20px;
}

/* the vote badge sits in the bottom-left corner, over where a long name would
   run: shift the name clear of it, mirroring what .pg-dead does on the right */
.pg-has-votes .pg-name { padding-left: 22px; }

/* skull, or the role icon when the narrator enabled role reveal: bottom-right
   corner of the cell, clear of both the figure and the seat number — over the
   figure the emoji was unreadable */
.pg-deadmark {
  position: absolute;
  /* above the slash, which is an ::after and would otherwise paint over it */
  z-index: 1;
  bottom: 2px;
  right: 2px;
  width: 26px;
  height: 26px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: #0d0c12;
  border: 1px solid #3f3b4d;
  font-size: 1.05rem;
}

.pg-me {
  border-color: #fbbf24;
  box-shadow: 0 0 0 2px rgba(251, 191, 36, 0.3);
}

.pg-me-badge {
  position: absolute;
  top: -7px;
  left: -6px;
  padding: 1px 5px;
  border-radius: 999px;
  background: #fbbf24;
  color: #14121a;
  font-size: 0.6rem;
  font-weight: bold;
  line-height: 14px;
}

/* seer's night result (wolf y/n): same corner spot as .pg-deadmark, colour is
   what actually carries the meaning since both use an emoji badge */
.pg-resultmark {
  position: absolute;
  bottom: 2px;
  right: 2px;
  width: 26px;
  height: 26px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: #0d0c12;
  border: 2px solid #3f3b4d;
  font-size: 1.05rem;
}
.pg-resultmark-bad { border-color: #ef4444; }
.pg-resultmark-good { border-color: #4ade80; }
/* neither camp: its own colour, never a washed-out version of the other two */
.pg-resultmark-unknown { border-color: #fbbf24; }

.pg-selectable { cursor: pointer; }
.pg-selectable:hover { border-color: #7c3aed; }
.pg-selected { border-color: #a78bfa; background: #241f36; }

/* speech bubble: who this player is pointing at, by seat number */
.pg-bubble {
  position: absolute;
  top: 2px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 1px 7px;
  border-radius: 999px;
  background: #eee;
  color: #14121a;
  font-size: 0.72rem;
  font-weight: bold;
  white-space: nowrap;
}

.pg-bubble::after {
  content: "";
  position: absolute;
  bottom: -4px;
  left: 50%;
  transform: translateX(-50%);
  border-left: 4px solid transparent;
  border-right: 4px solid transparent;
  border-top: 5px solid #eee;
}

/* how many votes a player is taking (see voteCounts in grid.js): bottom-left
   corner, opposite the skull/role mark */
.pg-votecount {
  position: absolute;
  bottom: 2px;
  left: 2px;
  min-width: 22px;
  height: 22px;
  padding: 0 5px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  background: #0d0c12;
  border: 1px dashed #f87171;
  color: #fca5a5;
  font-size: 0.75rem;
  font-weight: bold;
  line-height: 1;
}

/* every vote on this player is final: no more changing minds */
.pg-votecount-final {
  border-style: solid;
  background: #b91c1c;
  border-color: #fca5a5;
  color: #fff;
}

.pg-bubble-confirmed { background: #4ade80; }
.pg-bubble-confirmed::after { border-top-color: #4ade80; }
.pg-bubble-check { font-size: 0.7rem; }

.pg-bubble-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
  flex-shrink: 0;
}

/* --- public chat (see public/chat.js) ---
   Fixed panel: vertical column on the right on a PC, collapsible strip at the
   bottom on a phone. z-index stays below nav.js's bar (1000). */

.chat-panel {
  position: fixed;
  z-index: 900;
  /* phone default: strip at the bottom of the screen */
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  flex-direction: column;
  background: #1f1c28;
  border: 1px solid #2a2733;
  border-bottom: none;
  border-radius: 14px 14px 0 0;
  font-size: 0.9rem;
  text-align: left;
}

.chat-head {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  margin: 0;
  padding: 12px 14px;
  border-radius: 0;
  background: #14121a;
  color: #eee;
  font-size: 0.95rem;
  font-weight: bold;
  text-align: left;
}

.chat-head .chat-caret { margin-left: auto; opacity: 0.6; }

.chat-badge {
  min-width: 20px;
  padding: 1px 6px;
  border-radius: 999px;
  background: #7c3aed;
  font-size: 0.72rem;
  text-align: center;
}

.chat-panel[data-open="false"] .chat-body { display: none; }

.chat-body {
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: 10px;
  gap: 8px;
}

.chat-log {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.chat-msg {
  background: #14121a;
  border-radius: 10px;
  padding: 7px 10px;
}

.chat-msg-mine { background: #241f36; }
.chat-msg-narrator { border-left: 3px solid #7c3aed; }

.chat-msg-head {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.72rem;
  opacity: 0.75;
}

.chat-who { display: flex; align-items: center; gap: 5px; font-weight: bold; }
.chat-time { margin-left: auto; }

.chat-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 3px;
}

.chat-text { margin-top: 3px; word-break: break-word; white-space: pre-wrap; }

.chat-note {
  margin: 0;
  font-size: 0.78rem;
  opacity: 0.65;
  display: none;
}

.chat-form { display: flex; gap: 6px; }

.chat-form input[type="text"] {
  flex: 1;
  padding: 10px;
  font-size: 0.95rem;
}

.chat-send {
  width: auto;
  margin-top: 0;
  padding: 10px 14px;
}

/* on a phone the open log takes ~45vh, no more, or it swallows the buttons */
.chat-panel .chat-body { height: 45vh; }

/* PC: full-height column on the right */
@media (min-width: 900px) {
  .chat-panel {
    left: auto;
    top: 56px;
    right: 0;
    bottom: 0;
    width: 320px;
    border-radius: 0;
    border-right: none;
    border-top: none;
    border-bottom: 1px solid #2a2733;
    transition: width 0.18s ease;
  }

  .chat-panel .chat-body { height: auto; flex: 1; }

  /* Out of the way: the column folds against the right edge and leaves a
     handle to pull it back. It used to only hide its body, which kept a third
     of a wide screen reserved for a panel nobody was reading. */
  .chat-panel[data-open="false"] { width: 44px; }
  .chat-panel[data-open="false"] .chat-head {
    flex-direction: column;
    gap: 8px;
    padding: 12px 0;
    justify-content: flex-start;
  }
  .chat-panel[data-open="false"] .chat-label { display: none; }
  .chat-panel[data-open="false"] .chat-caret { margin-left: 0; }
  /* the unread count is the whole reason to notice a closed panel */
  .chat-panel[data-open="false"] .chat-badge { padding: 1px 4px; font-size: 0.68rem; }
}
