:root {
  --bg: #0f0d0b;
  --panel: #1c1916;
  --panel-2: #26211c;
  --border: #3a322a;
  --text: #efe6d8;
  --muted: #a89b88;
  --gold: #c9a45c;
  --red: #b3261e;
  --red-bright: #e0463c;
  --blue: #4a7fc1;
  --radius: 12px;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.4;
}

h1, h2, h3, .title {
  font-family: 'Cinzel', 'Trajan Pro', Georgia, serif;
  letter-spacing: 0.04em;
  color: var(--gold);
  margin: 0 0 0.5rem;
}

h1 { font-size: 1.6rem; }
h2 { font-size: 1.2rem; }
h3 { font-size: 1rem; }

a { color: var(--gold); }

.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.hidden { display: none !important; }

.wrap {
  max-width: 720px;
  margin: 0 auto;
  padding: 16px;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
}

button, .btn {
  font: inherit;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  border-radius: 10px;
  padding: 10px 14px;
  cursor: pointer;
  min-height: 44px;
  white-space: nowrap;
}
button:hover { border-color: var(--gold); }
button:disabled { opacity: 0.5; cursor: not-allowed; }
button.primary { background: var(--gold); color: #1a140c; border-color: var(--gold); font-weight: 600; }
button.danger { background: var(--red); border-color: var(--red); color: #fff; }
button.small { min-height: 34px; padding: 6px 10px; font-size: 0.85rem; }

input, select, textarea {
  font: inherit;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  min-height: 44px;
  width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--gold); outline-offset: 1px; }

.row { display: flex; gap: 8px; align-items: center; }
.row > .grow { flex: 1; min-width: 0; }
.stack > * + * { margin-top: 8px; }

.error { color: var(--red-bright); min-height: 1.4em; }

/* ---- header / banner ---------------------------------------------------- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
  position: sticky;
  top: 0;
  z-index: 5;
}
.topbar .title { margin: 0; font-size: 1.1rem; }
/* On a narrow phone the name gets its own line and the buttons sit under it. */
.topbar { flex-wrap: wrap; }
.topbar .title { white-space: nowrap; }
.topbar > .row { margin-left: auto; }

.banner {
  background: linear-gradient(90deg, #3b0f0c, #2a1a10);
  border: 1px solid var(--red);
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-bottom: 16px;
}
.banner .label { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.1em; color: var(--muted); }

/* ---- login -------------------------------------------------------------- */

.name-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 10px;
}
.name-grid button { min-height: 60px; font-size: 1.05rem; }
.name-grid .name-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 14px 8px 12px;
}
.name-card .avatar { border-color: #5a4a2c; }
.name-card:hover .avatar { border-color: var(--gold); }
.name-card .nm { font-weight: 600; line-height: 1.2; }
.name-card .fate { font-size: 0.75rem; color: var(--red-bright); }
.name-grid .name-card.out .nm { text-decoration: line-through; opacity: 0.6; }
.name-grid .name-card.out .avatar { filter: grayscale(1) brightness(0.7); }

.pin-input {
  font-size: 2rem;
  letter-spacing: 0.6em;
  text-align: center;
  font-family: ui-monospace, monospace;
}

/* ---- tabs --------------------------------------------------------------- */

.tabs {
  display: flex;
  gap: 4px;
  padding: 8px 16px 0;
  max-width: 720px;
  margin: 0 auto;
  overflow-x: auto;
}
.tabs button {
  border-radius: 10px 10px 0 0;
  border-bottom: none;
  background: transparent;
  color: var(--muted);
  white-space: nowrap;
}
.tabs button.active { background: var(--panel); color: var(--gold); border-color: var(--border); }
.tabs button.turret-tab { color: var(--red-bright); }
.tabs button.turret-tab.active { background: #2a0e0c; border-color: var(--red); }

@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(224, 70, 60, 0.6); }
  50% { box-shadow: 0 0 0 6px rgba(224, 70, 60, 0); }
}
.pulse { animation: pulse 1.6s infinite; }

/* ---- chat --------------------------------------------------------------- */

.chat {
  display: flex;
  flex-direction: column;
  height: calc(100dvh - 280px);
  min-height: 300px;
}
.chat .messages {
  flex: 1;
  overflow-y: auto;
  padding: 8px 4px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.chat form { margin-top: 8px; }

.msg {
  max-width: 85%;
  background: var(--panel-2);
  border: 1px solid var(--border);
  padding: 8px 12px;
  border-radius: 14px 14px 14px 4px;
  align-self: flex-start;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}
.msg.mine { align-self: flex-end; background: #2f2819; border-color: #5a4a2c; border-radius: 14px 14px 4px 14px; }
.msg.host { border-color: var(--gold); }
.msg.system {
  align-self: center;
  max-width: 95%;
  text-align: center;
  background: #2a0e0c;
  border-color: var(--red);
  border-radius: 10px;
}
.msg .who { font-size: 0.75rem; color: var(--gold); font-weight: 600; margin-bottom: 2px; }
.msg .when { font-size: 0.7rem; color: var(--muted); margin-left: 6px; font-weight: 400; }

.turret-panel { background: #1a0b0a; border-color: var(--red); }
.turret-panel h2 { color: var(--red-bright); }

.empty { text-align: center; color: var(--muted); padding: 24px 8px; }

/* ---- role card ---------------------------------------------------------- */

.role-card {
  text-align: center;
  padding: 32px 16px;
  cursor: pointer;
  user-select: none;
}
.role-card .role { font-family: 'Cinzel', Georgia, serif; font-size: 2.2rem; margin: 8px 0; }
.role-card.traitor .role { color: var(--red-bright); }
.role-card.faithful .role { color: var(--blue); }

/* ---- player list -------------------------------------------------------- */

.player-list { list-style: none; margin: 0; padding: 0; }
.player-list li {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.player-list li:last-child { border-bottom: none; }
.player-list .name { flex: 1; min-width: 120px; font-weight: 600; }

.tag {
  display: inline-block;
  font-size: 0.75rem;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid var(--border);
  color: var(--muted);
  white-space: nowrap;
}
.tag.traitor { color: #fff; background: var(--red); border-color: var(--red); }
.tag.faithful { color: #fff; background: var(--blue); border-color: var(--blue); }
.tag.murdered, .tag.banished { color: var(--red-bright); border-color: var(--red); }
.tag.target { color: #1a140c; background: var(--gold); border-color: var(--gold); }

@media (max-width: 480px) {
  .wrap { padding: 12px; }
  .panel { padding: 12px; }
}

/* ---- avatars / jackpot / shield / recruit ------------------------------- */

.avatar {
  border-radius: 50%;
  object-fit: cover;
  flex: none;
  border: 2px solid var(--border);
  background: var(--panel-2);
}
.avatar.placeholder {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--gold);
  font-family: 'Cinzel', Georgia, serif;
  font-weight: 700;
}
.avatar-btn { padding: 0; border: none; background: none; min-height: 0; border-radius: 50%; }
.avatar-btn:hover .avatar { border-color: var(--gold); }

.jackpot-amount {
  font-family: 'Cinzel', Georgia, serif;
  font-size: 2.6rem;
  color: var(--gold);
  text-shadow: 0 0 18px rgba(201, 164, 92, 0.35);
  margin: 4px 0 8px;
}
.jackpot-pill { color: var(--gold); border-color: #5a4a2c; }
.gain { color: #6fbf73; font-weight: 600; }
.loss { color: var(--red-bright); font-weight: 600; }

.tag.shield { color: #1a140c; background: #9fc3e6; border-color: #9fc3e6; }
.shield-note {
  background: #14243a;
  border: 1px solid var(--blue);
  border-radius: 10px;
  padding: 10px;
  color: #cfe0f5;
}

.tabs .tab-link {
  margin-left: auto;
  background: transparent;
  border-color: transparent;
  color: var(--muted);
  text-decoration: none;
  white-space: nowrap;
  min-height: 0;
  display: flex;
  align-items: center;
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.8);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 20;
}
.modal-card {
  background: #1a0b0a;
  border: 1px solid var(--red);
  border-radius: var(--radius);
  padding: 24px 20px;
  max-width: 420px;
  width: 100%;
  text-align: center;
  box-shadow: 0 0 60px rgba(179, 38, 30, 0.4);
}
.modal-card h2 { color: var(--red-bright); }

a.btn { text-decoration: none; display: inline-flex; align-items: center; }
#night-label, #whoami { white-space: nowrap; }

@media (max-width: 480px) {
  .topbar { padding: 10px 12px; }
  .topbar .title { font-size: 1rem; }
  .tabs { padding: 8px 12px 0; }
  .tabs button, .tabs .tab-link { padding: 8px 10px; }
}

/* Red X over a murdered player's round picture */
.avatar-x { position: relative; display: inline-flex; flex: none; }
.avatar-x .avatar { filter: grayscale(1) brightness(0.7); }
.avatar-x::before,
.avatar-x::after {
  content: '';
  position: absolute;
  left: -8%;
  right: -8%;
  top: 50%;
  height: 16%;
  min-height: 4px;
  margin-top: -8%;
  background: #e0140c;
  border-radius: 3px;
  box-shadow: 0 0 0 1px #7a0000, 0 0 4px rgba(120, 0, 0, 0.8);
  transform: rotate(45deg);
  z-index: 1; /* above the photo, whose filter gives it its own layer */
}
.avatar-x::after { transform: rotate(-45deg); }

/* ---- Ghost Table -------------------------------------------------------- */

.tabs button.ghost-tab { color: #b9c8e0; }
.tabs button.ghost-tab.active { background: #161c26; border-color: #56657d; color: #dbe6f7; }
.ghost-panel {
  background: linear-gradient(180deg, #161c26, #121720);
  border-color: #56657d;
}
.ghost-panel h2 { color: #c9d6ea; }
.ghost-panel .msg { background: #1e2633; border-color: #3a4658; }
.ghost-panel .msg.mine { background: #263245; border-color: #56657d; }
.ghost-panel .msg .who { color: #a9bddb; }
button.ghost-btn { background: #56657d; border-color: #56657d; color: #fff; font-weight: 600; }
#whoami { max-width: 28vw; overflow: hidden; text-overflow: ellipsis; }

/* ---- voting --------------------------------------------------------------- */

.vote-panel { border-color: var(--gold); }
.vote-panel h2 { margin-top: 0; }
.vote-options { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 8px; margin: 12px 0; }
.vote-option { display: flex; align-items: center; gap: 8px; text-align: left; padding: 8px; }
.vote-option span:last-child { font-weight: 600; overflow-wrap: anywhere; }
.vote-option.picked { border-color: var(--gold); background: #3a2f1a; box-shadow: 0 0 0 1px var(--gold); }
.dagger-choice {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  margin: 12px 0;
  padding: 10px;
  border: 1px solid var(--red);
  border-radius: 10px;
  background: #1a0b0a;
}
.dagger-choice input { width: 22px; height: 22px; min-height: 0; padding: 0; flex: none; accent-color: var(--red-bright); }
.vote-voters { display: flex; flex-wrap: wrap; gap: 6px; margin: 12px 0; }
.tag.voted { color: #1a140c; background: #6fbf73; border-color: #6fbf73; }
.vote-verdict { font-weight: 600; color: var(--gold); }
.tag.dagger { color: #fff; background: #7a1d18; border-color: var(--red-bright); }
.dagger-note {
  background: #2a0f0d;
  border: 1px solid var(--red);
  border-radius: 10px;
  padding: 10px;
  color: #f3d3cf;
}

/* ---- alerts --------------------------------------------------------------- */

.badge {
  display: inline-block;
  min-width: 1.5em;
  margin-left: 6px;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--red-bright);
  color: #fff;
  font: 700 0.75rem/1.5em system-ui, sans-serif;
  text-align: center;
  vertical-align: middle;
}
.toast {
  position: fixed;
  top: 10px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 40;
  width: max-content;
  max-width: min(92vw, 460px);
  padding: 10px 14px;
  border: 1px solid var(--gold);
  border-radius: var(--radius);
  background: var(--panel-2);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.6);
  cursor: pointer;
  overflow-wrap: anywhere;
}
