:root {
  --bg: #1b1d24;
  --panel: #262932;
  --panel-2: #2f3340;
  --text: #e8e8ee;
  --muted: #9a9fb0;
  --red: #d6453d;
  --red-dark: #8f2b26;
  --blue: #3b7dd8;
  --blue-dark: #27518c;
  --neutral: #c9b48a;
  --neutral-dark: #8b7a56;
  --assassin: #0b0b0f;
  --card: #f0e6cf;
  --card-text: #2b2a26;
  --accent: #f3c04b;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

.hidden { display: none !important; }
.muted { color: var(--muted); }

/* Top bar */
.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 18px;
  background: var(--panel);
  border-bottom: 1px solid #000;
}
.brand { color: var(--accent); font-weight: 700; font-size: 20px; text-decoration: none; letter-spacing: 1px; }
.room-info { flex: 1; }
.room-info strong { font-family: monospace; font-size: 18px; letter-spacing: 3px; }
.conn-status { font-size: 12px; color: var(--muted); margin-left: auto; }
.conn-status.ok { color: #6fcf7a; }
.conn-status.bad { color: var(--red); }

/* Buttons */
.btn {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid #444a5a;
  border-radius: 6px;
  padding: 8px 14px;
  font-size: 14px;
  cursor: pointer;
}
.btn:hover { background: #3a3f4f; }
.btn:disabled { opacity: .5; cursor: default; }
.btn-primary { background: var(--accent); color: #222; border-color: var(--accent); font-weight: 600; }
.btn-primary:hover { background: #ffd060; }
.btn-small { padding: 5px 10px; font-size: 12px; }

input[type=text], select {
  background: #15171d;
  color: var(--text);
  border: 1px solid #444a5a;
  border-radius: 6px;
  padding: 8px 10px;
  font-size: 15px;
}

/* Landing */
.panel { background: var(--panel); border-radius: 10px; padding: 24px; }
.landing { max-width: 420px; margin: 60px auto; display: flex; flex-direction: column; gap: 14px; }
.landing h1 { margin: 0; color: var(--accent); }
.landing label { display: flex; flex-direction: column; gap: 6px; font-size: 14px; color: var(--muted); }
.landing .row { display: flex; gap: 8px; }
.landing .row input { flex: 1; text-transform: uppercase; letter-spacing: 3px; }
.landing .or { text-align: center; color: var(--muted); margin: 8px 0; font-size: 13px; }
#landing-create { display: flex; flex-direction: column; }

/* Game layout */
.game {
  display: grid;
  grid-template-columns: 220px 1fr 220px;
  grid-template-rows: auto auto;
  gap: 14px;
  padding: 14px;
  max-width: 1300px;
  margin: 0 auto;
}
.sidebar { background: var(--panel); border-radius: 10px; padding: 12px; border-top: 5px solid; }
.team-red { border-color: var(--red); }
.team-blue { border-color: var(--blue); }
.team-header { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 8px; }
.team-name { font-weight: 700; font-size: 18px; }
.team-red .team-name { color: var(--red); }
.team-blue .team-name { color: var(--blue); }
.team-count { font-size: 28px; font-weight: 700; }
.roster-label { font-size: 11px; text-transform: uppercase; letter-spacing: 1px; color: var(--muted); margin-top: 8px; }
.player-list { list-style: none; margin: 4px 0; padding: 0; min-height: 20px; }
.player-list li { padding: 3px 6px; border-radius: 4px; font-size: 14px; display: flex; align-items: center; gap: 6px; }
.player-list li.me { background: rgba(243,192,75,.15); }
.player-list li.offline { opacity: .45; font-style: italic; }
.player-list li .kick { margin-left: auto; cursor: pointer; color: var(--muted); font-size: 12px; }
.player-list li .kick:hover { color: var(--red); }
.team-buttons { display: flex; flex-direction: column; gap: 6px; margin-top: 10px; }
.sidebar.active { box-shadow: 0 0 0 2px var(--accent) inset; }

.center { display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.status-bar {
  background: var(--panel);
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 16px;
  text-align: center;
}
.status-bar.red { border-left: 6px solid var(--red); }
.status-bar.blue { border-left: 6px solid var(--blue); }

.clue-display { display: flex; align-items: baseline; gap: 10px; justify-content: center; padding: 6px; }
.clue-label { font-size: 12px; text-transform: uppercase; color: var(--muted); letter-spacing: 1px; }
.clue-word { font-size: 28px; font-weight: 800; letter-spacing: 2px; }
.clue-number { font-size: 28px; font-weight: 800; color: var(--accent); }

.clue-form { display: flex; gap: 8px; justify-content: center; }
.clue-form input { flex: 0 1 260px; text-transform: uppercase; }

/* Board */
.board {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
}
.card {
  aspect-ratio: 5 / 3;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 6px;
  border-radius: 8px;
  background: var(--card);
  color: var(--card-text);
  font-weight: 700;
  font-size: clamp(10px, 1.4vw, 16px);
  letter-spacing: .5px;
  text-transform: uppercase;
  border: 3px solid transparent;
  user-select: none;
  transition: transform .08s;
  position: relative;
}
.card.clickable { cursor: pointer; }
.card.clickable:hover { transform: translateY(-2px); box-shadow: 0 4px 10px rgba(0,0,0,.4); }

/* Spymaster key (unrevealed): solid team colour backgrounds so the key is obvious at a glance. */
.card.key-red { background: var(--red); color: #fff; border-color: var(--red-dark); }
.card.key-blue { background: var(--blue); color: #fff; border-color: var(--blue-dark); }
.card.key-neutral { background: var(--neutral); color: var(--card-text); border-color: var(--neutral-dark); }
.card.key-assassin { background: #3a3a3a; color: #fff; border-color: #000; }

/* Revealed: full red / blue backgrounds. */
.card.revealed { color: #fff; font-weight: 500; }
.card.revealed.red { background: var(--red); border-color: var(--red-dark); }
.card.revealed.blue { background: var(--blue); border-color: var(--blue-dark); }
.card.revealed.neutral { background: var(--neutral-dark); border-color: var(--neutral); color: #f8f2e2; }
.card.revealed.assassin { background: var(--assassin); border-color: #000; color: #ddd; }
.card.revealed.assassin::after { content: "\2620"; position: absolute; top: 4px; right: 8px; font-size: 14px; }

/* Spymaster's board: already-guessed cards go dark so the agents still to find stand out. */
.board.key-view .card.revealed { filter: brightness(.45) saturate(.7); color: rgba(255,255,255,.7); }
.board.key-view .card.revealed.red { border-color: #4a1613; }
.board.key-view .card.revealed.blue { border-color: #142b4d; }
.board.key-view .card.revealed.neutral { color: rgba(255,255,255,.6); }

/* Duet mode: the rival team has no players */
.sidebar.rival { opacity: .6; }
.sidebar.rival .team-buttons { display: none; }
.mode-picker { display: flex; gap: 14px; justify-content: center; align-items: center; margin-bottom: 8px; color: var(--text); }
.mode-picker label { cursor: pointer; }

.actions { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }
.lobby-help { color: var(--muted); font-size: 14px; text-align: center; max-width: 520px; margin: 0 auto; }

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--red);
  color: #fff;
  padding: 10px 18px;
  border-radius: 8px;
  box-shadow: 0 4px 14px rgba(0,0,0,.5);
  z-index: 50;
}

/* Bottom: spectators + log */
.bottom { grid-column: 1 / -1; background: var(--panel); border-radius: 10px; padding: 12px; }
.spectators { font-size: 14px; }
.spectators .roster-label { margin: 0; display: inline; }
.log { list-style: none; margin: 4px 0 0; padding: 0; max-height: 160px; overflow-y: auto; font-size: 13px; color: var(--muted); }
.log li { padding: 2px 0; border-bottom: 1px solid #30343f; }
.log li:first-child { color: var(--text); }

/* Game over banner */
.status-bar.over { background: var(--accent); color: #222; font-weight: 700; font-size: 20px; }

@media (max-width: 900px) {
  .game { grid-template-columns: 1fr 1fr; }
  .center { grid-column: 1 / -1; grid-row: 1; }
  .card { font-size: 11px; }
}