/* Ace Agents. Layout: the board on the left, controls in a side panel; they stack on phones. */
:root {
  /* Team colours are far apart in hue AND brightness, so they read apart at a glance:
     bright warm red vs deep blue-violet vs sandy bystander vs black bomb. */
  --team-red: #ff3d52;
  --team-purple: #5b2be0;
  --neutral: #c8b48c;
  --neutral-text: #3b3324;
  --bomb: #050507;
  --card-face: #ece8de;
  --card-ink: #15171d;
}

.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.small { font-size: .85rem; }
.t-red { color: var(--red); } .t-purple { color: var(--accent); } .t-bomb { color: var(--red); }

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 22px;
  padding-block: 22px;
  align-items: start;
}
@media (max-width: 900px) { .layout { grid-template-columns: minmax(0, 1fr); } }

.board-col { display: flex; flex-direction: column; gap: 12px; min-width: 0; }

/* Turn banner */
.status {
  display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap;
  border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 16px; background: var(--card);
  --team: var(--muted);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--team) 40%, transparent);
}
.status.red { --team: var(--red); }
.status.purple { --team: var(--accent); }
.status-main { font: 700 1.5rem/1.1 var(--display); letter-spacing: 2px; text-transform: uppercase; color: var(--team); }
.status-clue { font: 600 1.1rem/1.2 var(--display); letter-spacing: 1px; }
.status-clue b { font-size: 1.35rem; text-transform: uppercase; letter-spacing: 2px; }
.status-clue .muted { font-family: var(--body); font-size: .85rem; letter-spacing: 0; }

.scores { display: flex; gap: 10px; }
.score { display: flex; align-items: baseline; gap: 8px; padding: 6px 12px; border-radius: 8px; background: var(--card); border: 1px solid var(--line); }
.score b { font: 700 1.6rem/1 var(--display); font-variant-numeric: tabular-nums; }
.score span { color: var(--muted); font-size: .8rem; text-transform: uppercase; letter-spacing: 1px; }
.score.red b { color: var(--red); } .score.purple b { color: var(--accent); }

/* Board */
.grid { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: clamp(5px, 1vw, 10px); }
.card {
  position: relative; aspect-ratio: 1.55; min-width: 0;
  display: flex; align-items: center; justify-content: center; padding: 14px 4px 6px;
  background: var(--card-face); color: var(--card-ink);
  border: 0; border-radius: 8px; cursor: pointer;
  box-shadow: 0 3px 0 #9d988c, 0 6px 14px rgba(0,0,0,.35);
  font: 700 clamp(.62rem, 1.9vw, 1.2rem)/1.05 var(--display); letter-spacing: .06em; text-transform: uppercase;
  overflow-wrap: anywhere; text-align: center;
  transition: transform .12s, box-shadow .12s, background .25s, color .25s;
}
.card:hover:not(:disabled) { transform: translateY(-2px); box-shadow: 0 5px 0 #9d988c, 0 10px 18px rgba(0,0,0,.4); }
.card:active:not(:disabled) { transform: translateY(2px); box-shadow: 0 1px 0 #9d988c; }
.card:disabled { cursor: default; }
.card .coord {
  position: absolute; top: 5px; left: 7px;
  font: 600 clamp(.55rem, 1.1vw, .72rem)/1 var(--body); letter-spacing: .05em; opacity: .55;
}

/* Revealed cards */
.card.revealed { box-shadow: none; transform: none; }
.card.revealed.red { background: var(--team-red); color: #fff; }
.card.revealed.purple { background: var(--team-purple); color: #fff; }
.card.revealed.neutral { background: var(--neutral); color: var(--neutral-text); }
.card.revealed.red .coord, .card.revealed.purple .coord { color: #fff; opacity: .7; }
.card.revealed.bomb {
  background: repeating-linear-gradient(135deg, var(--bomb) 0 10px, #2a0a0e 10px 20px); color: var(--red);
  box-shadow: inset 0 0 0 2px var(--red);
}
.card.revealed .word { opacity: .9; }
.card.just { animation: flip .35s ease-out; }
@keyframes flip { from { transform: rotateX(90deg); } to { transform: rotateX(0); } }

/* Key shown on the board (spymaster mode, or after the game ends) */
/* Unrevealed cards: strong tint plus a thick team-coloured frame. Revealed cards fade back
   so the spymaster can see at a glance which agents are still out. */
.grid.show-key .card:not(.revealed).red {
  background: color-mix(in srgb, var(--team-red) 45%, var(--card-face));
  box-shadow: inset 0 0 0 4px var(--team-red), 0 3px 0 #9d988c;
}
.grid.show-key .card:not(.revealed).purple {
  background: color-mix(in srgb, var(--team-purple) 40%, var(--card-face));
  box-shadow: inset 0 0 0 4px var(--team-purple), 0 3px 0 #9d988c;
}
.grid.show-key .card:not(.revealed).neutral { background: color-mix(in srgb, var(--neutral) 45%, var(--card-face)); }
.grid.show-key .card:not(.revealed).bomb { background: #1a1a1f; color: var(--red); box-shadow: inset 0 0 0 4px var(--red); }
.grid.show-key .card.revealed { opacity: .45; }

/* Lobby: the board stays dark until the host presses Start game */
.grid.unlit .card {
  background: var(--card2); color: transparent; box-shadow: inset 0 0 0 1px var(--line); cursor: default;
}
.grid.unlit .card .coord { color: var(--muted); opacity: .6; }
.grid.light-up .card { animation: light-up .55s ease-out both; animation-delay: calc(var(--i, 0) * 55ms); }
@keyframes light-up {
  0% { background: var(--card2); color: transparent; transform: rotateX(90deg); }
  60% { filter: brightness(1.25); }
  100% { transform: rotateX(0); filter: none; }
}
.lobby-bar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  padding: 10px 14px; border: 1px dashed var(--line); border-radius: var(--radius); background: var(--card);
}
.lobby-bar p { margin: 0; color: var(--muted); }
.start-btn { font-size: 1.1rem; padding: 12px 22px; box-shadow: 0 0 18px color-mix(in srgb, var(--purple) 55%, transparent); }

.board-actions { display: flex; gap: 8px; flex-wrap: wrap; }
#spyToggle[aria-pressed="true"] { border-color: var(--red); color: var(--red); }

.confirm { background: var(--card); border: 1px solid var(--red); border-radius: var(--radius); padding: 14px 16px; }
.confirm p { margin: 0 0 10px; }

/* Side panel */
.panel { display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.box { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; display: flex; flex-direction: column; gap: 10px; }
.box h2 { margin: 0; font-size: 1.15rem; letter-spacing: 1.5px; text-transform: uppercase; }
.box p { margin: 0; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row input { flex: 1 1 120px; }
.stack { display: flex; flex-direction: column; gap: 8px; }
.error { color: var(--red); font-size: .9rem; }
.code-row { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.code { font: 700 1.25rem/1 var(--display); letter-spacing: 2px; color: var(--gold); }
.copy-fallback { width: 100%; font-size: .8rem; }

.log { margin: 0; padding-left: 0; list-style: none; display: flex; flex-direction: column; gap: 4px; max-height: 260px; overflow-y: auto; font-size: .9rem; }
.log li { display: flex; gap: 8px; align-items: baseline; }
.log li::before { content: ""; flex: none; width: 8px; height: 8px; border-radius: 2px; background: var(--muted); transform: translateY(-1px); }
.log li.red::before { background: var(--red); }
.log li.purple::before { background: var(--accent); }
.log li.neutral::before { background: var(--neutral-text); }
.log li.bomb::before { background: var(--bomb); outline: 1px solid var(--red); }
.log .empty::before { display: none; }

.rules summary { cursor: pointer; list-style: none; }
.rules summary::-webkit-details-marker { display: none; }
.rules summary h2::after { content: " +"; color: var(--muted); }
.rules[open] summary h2::after { content: " –"; }
.rules ol { margin: 0; padding-left: 20px; display: flex; flex-direction: column; gap: 6px; }

/* Key view */
.key-view { padding-block: 22px; display: flex; flex-direction: column; gap: 14px; max-width: 640px; }
.key-head h1 { margin: 0; font-size: 2rem; letter-spacing: 2px; text-transform: uppercase; }
.key-head p { margin: 4px 0 0; }
.key-first { font: 700 1.2rem/1.2 var(--display); letter-spacing: 1.5px; text-transform: uppercase; }
.key-grid { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 6px; }
.key-cell {
  aspect-ratio: 1.3; border-radius: 6px; display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 4px; text-align: center; min-width: 0;
  font: 700 clamp(.55rem, 2.4vw, .95rem)/1.05 var(--display); text-transform: uppercase; letter-spacing: .04em; overflow-wrap: anywhere;
}
.key-cell small { font: 600 .6rem/1 var(--body); opacity: .7; margin-bottom: 3px; }
.key-cell.red, .sw.red { background: var(--team-red); color: #fff; }
.key-cell.purple, .sw.purple { background: var(--team-purple); color: #fff; }
.key-cell.neutral, .sw.neutral { background: var(--neutral); color: var(--neutral-text); }
.key-cell.bomb, .sw.bomb { background: var(--bomb); color: var(--red); box-shadow: inset 0 0 0 2px var(--red); }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: .9rem; color: var(--muted); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.sw { width: 14px; height: 14px; border-radius: 3px; display: inline-block; }
.key-view .btn { align-self: flex-start; text-decoration: none; }

@media (max-width: 520px) {
  .card { aspect-ratio: 1.05; padding: 12px 2px 4px; }
  .status-main { font-size: 1.2rem; }
}
@media (prefers-reduced-motion: reduce) {
  .card, .card.just, .grid.light-up .card { transition: none; animation: none; }
}

/* ---- Start screen ---- */
.start { padding-block: 28px 12px; display: flex; flex-direction: column; gap: 20px; }
.start-hero h1 { margin: 0 0 6px; font-size: clamp(2rem, 6vw, 3rem); letter-spacing: 2px; line-height: 1; }
.start-hero p { margin: 0; max-width: 60ch; }
.start-grid { display: grid; grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr); gap: 16px; align-items: start; }
@media (max-width: 760px) { .start-grid { grid-template-columns: minmax(0, 1fr); } }
.mode .btn { align-self: flex-start; text-decoration: none; }
.field { display: flex; flex-direction: column; gap: 4px; font-size: .85rem; color: var(--muted); }
.server-status { font-size: .88rem; padding: 8px 10px; border-radius: 8px; background: var(--bg2); border: 1px solid var(--line); }
.server-status::before { content: ""; display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 8px; background: var(--muted); }
.server-status.up::before { background: #3fbf7f; box-shadow: 0 0 8px #3fbf7f; }
.server-status.down::before { background: var(--red); }
.divider { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: .8rem; text-transform: uppercase; letter-spacing: 1px; }
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--line); }

/* ---- Online board extras ---- */
.you-text { margin: 0; padding: 8px 12px; border-radius: 8px; background: var(--card); border: 1px solid var(--line); font-size: .95rem; }
.you-text.red { border-color: color-mix(in srgb, var(--red) 45%, var(--line)); }
.you-text.purple { border-color: color-mix(in srgb, var(--accent) 45%, var(--line)); }
.conn-note { margin: 0; padding: 8px 12px; border-radius: 8px; border: 1px solid var(--gold); color: var(--gold); font-size: .9rem; }
.grid.can-pick .card:not(:disabled) { outline: 2px solid color-mix(in srgb, var(--accent) 55%, transparent); outline-offset: 1px; }
.clue-box { border-color: var(--purple); }
.invite-note { overflow-wrap: anywhere; }
.me-row { justify-content: space-between; }
.link-btn { background: none; border: 0; padding: 0; color: var(--accent); font: inherit; font-size: .85rem; cursor: pointer; text-decoration: underline; }

.teams { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 10px; }
.team { border: 1px solid var(--line); border-radius: 8px; padding: 10px; display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.team h3 { margin: 0; font-size: 1rem; letter-spacing: 1.5px; text-transform: uppercase; }
.team.red { border-color: color-mix(in srgb, var(--red) 40%, var(--line)); }
.team.red h3 { color: var(--red); }
.team.purple { border-color: color-mix(in srgb, var(--accent) 40%, var(--line)); }
.team.purple h3 { color: var(--accent); }
.players { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; font-size: .9rem; }
.players.inline { flex-direction: row; flex-wrap: wrap; gap: 4px 10px; }
.player { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px; min-width: 0; overflow-wrap: anywhere; }
.player.away { opacity: .5; }
.tag { font-size: .65rem; letter-spacing: .5px; text-transform: uppercase; color: var(--muted); border: 1px solid var(--line); border-radius: 999px; padding: 0 6px; }
.tag.spymaster { color: var(--gold); border-color: color-mix(in srgb, var(--gold) 50%, var(--line)); }
.tag.you { color: var(--text); }
.seat-btns { display: flex; flex-wrap: wrap; gap: 6px; margin-top: auto; }
.seat {
  font: 600 .78rem/1 var(--display); letter-spacing: 1px; text-transform: uppercase; cursor: pointer;
  background: var(--bg2); color: var(--muted); border: 1px solid var(--line); border-radius: 6px; padding: 7px 8px;
}
.seat:hover:not(:disabled) { color: var(--text); border-color: var(--accent); }
.seat.on { color: var(--text); background: var(--card2); border-color: var(--accent); }
.seat:disabled { opacity: .4; cursor: not-allowed; }
.watching { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }

/* Leader controls */
.tag.leader { color: var(--accent); border-color: color-mix(in srgb, var(--accent) 50%, var(--line)); }
.promote {
  margin-left: auto; background: none; border: 1px solid var(--line); border-radius: 999px; cursor: pointer;
  color: var(--muted); font: 600 .65rem/1 var(--body); letter-spacing: .5px; text-transform: uppercase; padding: 3px 7px;
}
.promote:hover { color: var(--text); border-color: var(--accent); }
.seat.random { border-color: color-mix(in srgb, var(--gold) 45%, var(--line)); color: var(--gold); }

/* Admin panel and locked teams */
.admin-box { border-color: color-mix(in srgb, var(--gold) 45%, var(--line)); }
.admin-box h2 { color: var(--gold); }
.admin-box select { width: 100%; }
.lock-note { margin: 0; color: var(--gold); }
.log li.admin { color: var(--gold); }
.log li.admin::before { background: var(--gold); }
