:root {
  --ink: #172033;
  --muted: #64748b;
  --paper: #f8fafc;
  --panel: #ffffff;
  --line: #cbd5e1;
  --night: #243447;
  --mafia: #b4232a;
  --citizen: #0f8b8d;
  --police: #315fc6;
  --doctor: #168a54;
  --gold: #e0a928;
}

* {
  box-sizing: border-box;
}

.hidden {
  display: none !important;
}

body {
  margin: 0;
  color: var(--ink);
  background:
    linear-gradient(135deg, rgba(180, 35, 42, 0.12), transparent 32%),
    linear-gradient(315deg, rgba(15, 139, 141, 0.14), transparent 36%),
    #eef3f8;
  font-family: Arial, Helvetica, sans-serif;
}

.game {
  position: relative;
  display: grid;
  grid-template-rows: auto auto auto auto;
  gap: 12px;
  padding: 16px;
}

.topbar,
footer,
.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 32px;
  letter-spacing: 0;
}

h2 {
  font-size: 18px;
}

#contextLabel,
.section-heading p {
  color: var(--muted);
  font-size: 13px;
}

button {
  border: 0;
  border-radius: 8px;
  font: inherit;
  font-weight: 800;
  cursor: pointer;
}

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

.header-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.header-actions button,
.choice {
  min-height: 40px;
  padding: 10px 14px;
  color: white;
  background: var(--night);
}

.header-actions #startButton {
  background: var(--citizen);
}

.header-actions #resetButton {
  background: #6b7280;
}

.hud {
  display: grid;
  grid-template-columns: minmax(0, 2fr) minmax(0, 1fr);
  gap: 10px;
}

.meter,
.players-panel,
.action-panel,
footer {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.86);
  box-shadow: 0 12px 26px rgba(15, 23, 42, 0.08);
}

.meter {
  display: grid;
  gap: 4px;
  min-width: 0;
  padding: 10px 12px;
}

.meter span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.meter strong {
  overflow: hidden;
  font-size: 18px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* The phase drives what happens next, so it gets the most prominent emphasis. */
.meter-phase {
  border-color: var(--night);
  border-left: 6px solid var(--gold);
  background: linear-gradient(135deg, rgba(36, 52, 71, 0.96), rgba(36, 52, 71, 0.88));
  box-shadow: 0 12px 26px rgba(15, 23, 42, 0.22);
}

.meter-phase span {
  color: var(--gold);
  letter-spacing: 0.04em;
}

.meter-phase strong {
  color: white;
  font-size: 26px;
  line-height: 1.15;
}

.table {
  display: grid;
  grid-template-columns: minmax(260px, 420px) minmax(0, 1fr);
  gap: 16px;
  align-items: start;
}

.players-panel,
.action-panel {
  display: grid;
  gap: 12px;
  padding: 14px;
}

.players {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(176px, 1fr));
  gap: 10px;
}

.player {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 6px 10px;
  min-height: 64px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-left: 6px solid transparent;
  border-radius: 8px;
  background: var(--panel);
}

.player strong,
.player span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.player .meta {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.player .role {
  justify-self: end;
  padding: 4px 8px;
  border-radius: 999px;
  color: white;
  background: #6b7280;
  font-size: 12px;
  font-weight: 800;
}

.player.mafia {
  border-left-color: var(--mafia);
}

.player.police {
  border-left-color: var(--police);
}

.player.doctor {
  border-left-color: var(--doctor);
}

.player.citizen {
  border-left-color: var(--citizen);
}

.player.dead {
  color: #64748b;
  background: #eef2f7;
}

.player.dead strong {
  text-decoration: line-through;
}

/* The viewer's own card sits at the top of the list, spans the full row, and is emphasized. */
.player.current {
  grid-column: 1 / -1;
  border-color: var(--gold);
  background: linear-gradient(135deg, rgba(224, 169, 40, 0.16), rgba(224, 169, 40, 0.05));
  box-shadow: 0 0 0 2px var(--gold), 0 10px 22px rgba(224, 169, 40, 0.22);
}

.player.current strong {
  font-size: 17px;
}

.actions {
  display: grid;
  gap: 10px;
}

.choice {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  width: 100%;
  color: var(--ink);
  background: #edf2f7;
  text-align: left;
}

.choice:not(:disabled):hover,
.choice:not(:disabled):focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}

.choice.selected {
  color: white;
  background: var(--night);
}

.choice.danger.selected {
  background: var(--mafia);
}

.choice.safe.selected {
  background: var(--doctor);
}

.choice.info.selected {
  background: var(--police);
}

.choice span {
  color: inherit;
  font-size: 13px;
  opacity: 0.78;
}

.notice {
  padding: 12px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: #334155;
  background: #f8fafc;
  line-height: 1.45;
  white-space: pre-line;
}

.outcome {
  display: grid;
  gap: 6px;
  padding: 14px;
  border: 1px solid var(--line);
  border-left: 6px solid var(--muted);
  border-radius: 8px;
  background: var(--panel);
}

.outcome strong {
  font-size: 18px;
  line-height: 1.25;
}

.outcome p {
  color: #475569;
  font-size: 14px;
  line-height: 1.45;
}

.outcome.fatal {
  border-left-color: var(--mafia);
  background: #fef2f2;
}

.outcome.saved {
  border-left-color: var(--doctor);
  background: #f0fdf4;
}

.outcome.safe {
  border-left-color: var(--citizen);
  background: #f0fdfa;
}

footer {
  align-items: flex-start;
  padding: 12px 14px;
}

#status {
  max-width: 520px;
  line-height: 1.45;
}

.log {
  display: grid;
  gap: 4px;
  width: min(100%, 520px);
  max-height: 130px;
  margin: 0;
  padding-left: 24px;
  overflow: auto;
  color: #475569;
  font-size: 13px;
}

.result-overlay {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(15, 23, 42, 0.48);
}

.result-overlay.hidden {
  display: none;
}

.result-box {
  display: grid;
  gap: 16px;
  width: min(92vw, 560px);
  padding: 24px;
  border: 2px solid var(--gold);
  border-radius: 8px;
  background: rgba(248, 250, 252, 0.98);
  box-shadow: 0 24px 70px rgba(15, 23, 42, 0.32);
}

.result-actions {
  display: flex;
  gap: 8px;
}

.result-actions button {
  flex: 1;
  min-height: 44px;
  padding: 10px 14px;
  color: white;
  background: var(--citizen);
}

.result-actions button.secondary {
  background: #6b7280;
}

#resultMessage {
  font-size: clamp(30px, 7vmin, 58px);
  font-weight: 900;
  line-height: 1;
  text-align: center;
}

.reveal-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 8px;
}

.reveal {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
}

@media (max-width: 820px) {
  footer {
    align-items: flex-start;
    flex-direction: column;
  }

  .hud {
    width: 100%;
  }

  .table {
    grid-template-columns: 1fr;
  }

  .log {
    width: 100%;
  }
}

/* On mobile, auto-fit collapses to a single column, so keep two columns explicitly. */
@media (max-width: 640px) {
  .players {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
  }

  .player {
    min-height: 58px;
    padding: 8px 10px;
  }

  .player .role {
    padding: 3px 6px;
    font-size: 11px;
  }
}
