/* PSXSUS spectator.
 *
 * DARK ONLY, deliberately. The whole page frames a canvas showing a ship in
 * space that the console draws on an (8,9,14) background; a light theme would
 * put a white surround around a black rectangle, which is worse than either.
 * That makes it a single committed look rather than a missing dark mode, so the
 * chart colours below are stepped and validated for THIS surface.
 *
 * The two data colours are the categorical aqua and red from the design
 * system's dark column. They sit in the 6-8 CVD warn band against each other,
 * which is legal only with secondary encoding - so every place they appear
 * ships a direct text label and a 2px gap between fills, never colour alone.
 */

:root {
  --surface:      #0d1016;
  --surface-2:    #141922;
  --surface-3:    #1b2230;
  --line:         #26303f;
  --line-soft:    #1c2431;

  --ink:          #e8edf5;
  --ink-2:        #9daabd;
  --ink-3:        #6b7789;

  /* Categorical, dark column. crew = aqua slot, impostor = red slot. */
  --crew:         #199e70;
  --impostor:     #e66767;
  /* Status. Reserved: never reused as a series colour. */
  --warn:         #c98500;
  --danger:       #e34948;

  --radius:       10px;
  --radius-sm:    6px;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, Consolas, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--surface);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.5;
}

a { color: inherit; text-decoration: none; }

/* ---------------------------------------------------------------- chrome */

.top {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 20px;
  background: color-mix(in srgb, var(--surface) 86%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  letter-spacing: 0.14em;
  font-size: 13px;
}
.brand b { color: var(--ink-3); font-weight: 700; margin-left: 6px; }

/* A crewmate silhouette in three boxes - the same shape the sprite sheet
   draws, at a size where detail would only turn to mud. */
.brand-mark {
  width: 14px; height: 16px;
  background: var(--impostor);
  border-radius: 7px 7px 3px 3px;
  box-shadow: inset -4px 0 0 rgb(0 0 0 / 0.25);
  position: relative;
}
.brand-mark::after {
  content: "";
  position: absolute; left: 3px; top: 4px;
  width: 8px; height: 5px;
  background: #9fd4e8;
  border-radius: 3px;
}

.live { display: flex; gap: 18px; margin-left: auto; font-size: 12px; color: var(--ink-2); }
.live b { color: var(--ink); font-variant-numeric: tabular-nums; }

.conn {
  font-size: 11px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  padding: 3px 9px;
  border-radius: 999px;
  border: 1px solid var(--line);
  color: var(--ink-3);
}
.conn[data-state="live"]   { color: var(--crew); border-color: color-mix(in srgb, var(--crew) 45%, transparent); }
.conn[data-state="lost"]   { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 45%, transparent); }

main { padding: 22px 20px 40px; max-width: 1500px; margin: 0 auto; }

.foot {
  padding: 18px 20px 30px;
  color: var(--ink-3);
  font-size: 12px;
  text-align: center;
  border-top: 1px solid var(--line-soft);
}

/* ------------------------------------------------------------- fair play */

#fairplay {
  margin: 14px 20px 0;
  padding: 12px 16px;
  border-radius: var(--radius);
  border: 1px solid color-mix(in srgb, var(--warn) 55%, transparent);
  background: color-mix(in srgb, var(--warn) 12%, var(--surface));
  color: var(--ink);
  font-size: 14px;
  display: flex;
  gap: 12px;
  align-items: flex-start;
  max-width: 1500px;
  margin-inline: auto;
}
#fairplay strong { color: var(--warn); }
#fairplay .icon { font-size: 18px; line-height: 1.2; }

/* ----------------------------------------------------------------- cards */

.card {
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

h2 {
  font-size: 12px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--ink-3);
  margin: 0 0 12px;
  font-weight: 600;
}

.home {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 380px;
  gap: 22px;
  align-items: start;
}
@media (max-width: 1080px) { .home { grid-template-columns: minmax(0, 1fr); } }

/* --------------------------------------------------------- stat tiles */

.tiles {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}

.tile { padding: 14px 16px; }
.tile .label {
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-3);
}
.tile .value {
  font-size: 30px;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
  margin-top: 2px;
  /* Text tokens, never a series colour - the swatch beside a number carries
     identity, the number itself stays ink. */
  color: var(--ink);
}
.tile .sub { font-size: 12px; color: var(--ink-2); }

/* ------------------------------------------------------- win-rate meter */

.meter { padding: 16px; margin-bottom: 18px; }

.meter-track {
  display: flex;
  height: 14px;
  /* The 2px gap between the two fills is the required secondary encoding for
     an adjacent pair in the CVD warn band - the fills must never touch. */
  gap: 2px;
  margin: 4px 0 10px;
}
.meter-fill { border-radius: 3px; min-width: 3px; }
.meter-fill.crew     { background: var(--crew); }
.meter-fill.impostor { background: var(--impostor); }
.meter-track.empty {
  background: var(--surface-3);
  border-radius: 3px;
}

/* Doubles as the legend and as the direct labels: swatch, name, value. */
.meter-keys { display: flex; justify-content: space-between; gap: 16px; font-size: 13px; }
.meter-key { display: flex; align-items: center; gap: 8px; color: var(--ink-2); }
.meter-key .swatch { width: 10px; height: 10px; border-radius: 3px; flex: none; }
.meter-key .swatch.crew     { background: var(--crew); }
.meter-key .swatch.impostor { background: var(--impostor); }
.meter-key b { color: var(--ink); font-variant-numeric: tabular-nums; }

/* --------------------------------------------------------------- tables */

table { width: 100%; border-collapse: collapse; font-size: 13px; }
th {
  text-align: left;
  font-weight: 600;
  font-size: 11px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-3);
  padding: 0 10px 8px 0;
  border-bottom: 1px solid var(--line);
}
td {
  padding: 9px 10px 9px 0;
  border-bottom: 1px solid var(--line-soft);
  color: var(--ink-2);
  font-variant-numeric: tabular-nums;
}
td.name { color: var(--ink); }
tr:last-child td { border-bottom: 0; }

.minibar { display: flex; gap: 2px; height: 6px; width: 90px; }
.minibar i { display: block; border-radius: 2px; }
.minibar .crew     { background: var(--crew); }
.minibar .impostor { background: var(--impostor); }

.chip {
  display: inline-block;
  padding: 1px 7px;
  border-radius: 999px;
  font-size: 11px;
  letter-spacing: 0.06em;
  font-weight: 600;
}
.chip.crew {
  color: var(--crew);
  background: color-mix(in srgb, var(--crew) 16%, transparent);
}
.chip.impostor {
  color: var(--impostor);
  background: color-mix(in srgb, var(--impostor) 16%, transparent);
}

.section { padding: 16px; margin-bottom: 18px; }
.empty { color: var(--ink-3); font-size: 13px; padding: 10px 0; }

/* ------------------------------------------------------------ room list */

.rooms { display: grid; gap: 12px; }

.room-card {
  padding: 14px 16px;
  display: block;
  position: relative;
  transition: border-color 120ms;
}
.room-card:hover,
.room-card:focus-visible { border-color: color-mix(in srgb, var(--crew) 60%, var(--line)); }
.room-card:focus-visible { outline: 2px solid var(--crew); outline-offset: 2px; }

/* The whole card is the link; this is what says so. */
.room-go {
  position: absolute;
  right: 16px;
  bottom: 14px;
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-3);
}
.room-card:hover .room-go { color: var(--crew); }
.room-go span { display: inline-block; transition: transform 120ms; }
.room-card:hover .room-go span { transform: translateX(3px); }

.room-head { display: flex; align-items: baseline; gap: 10px; }
.room-head .rname { font-weight: 650; font-size: 16px; }
.room-head .rmap { color: var(--ink-3); font-size: 12px; letter-spacing: 0.08em; }
.room-head .rstate { margin-left: auto; font-size: 12px; }

.state-playing { color: var(--crew); }
.state-meeting { color: var(--warn); }
.state-lobby   { color: var(--ink-3); }
.state-over    { color: var(--ink-2); }

.crew-strip { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.pip {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--ink-2);
  background: var(--surface-3);
  border-radius: 999px;
  padding: 2px 9px 2px 4px;
}
.pip .dot { width: 10px; height: 10px; border-radius: 999px; flex: none; }
.pip.dead { opacity: 0.45; text-decoration: line-through; }

/* ------------------------------------------------------------ room view */

.roomview { display: grid; grid-template-columns: minmax(0, 1fr) 330px; gap: 18px; align-items: start; }
@media (max-width: 1080px) { .roomview { grid-template-columns: minmax(0, 1fr); } }

.stage {
  position: relative;
  background: #08090e;   /* the console's own empty-space colour */
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  aspect-ratio: 4 / 3;
  touch-action: none;    /* we handle pan and pinch ourselves */
}
.stage canvas { display: block; width: 100%; height: 100%; cursor: grab; }
.stage canvas.dragging { cursor: grabbing; }

/* Fullscreen. The aspect-ratio that shapes the stage in the page would letterbox
   it against the screen, so it is dropped; the border and radius go with it
   because there is nothing left for them to separate the map from. */
.stage:fullscreen {
  aspect-ratio: auto;
  width: 100vw;
  height: 100vh;
  border: 0;
  border-radius: 0;
}
.stage:fullscreen .tools { bottom: 18px; right: 18px; }
.stage:fullscreen .stage-bar { inset: 18px 18px auto 18px; }

.stage-bar {
  position: absolute;
  inset: 10px 10px auto 10px;
  display: flex;
  align-items: center;
  gap: 10px;
  pointer-events: none;
  font-size: 12px;
}
.badge {
  background: color-mix(in srgb, #000 55%, transparent);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 3px 10px;
  backdrop-filter: blur(6px);
  color: var(--ink);
}
.badge.alert { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 50%, transparent); }
.badge.crit  { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 55%, transparent); }

.tools {
  position: absolute;
  right: 10px; bottom: 10px;
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: flex-end;
  max-width: calc(100% - 20px);
}
.tools button {
  font: inherit;
  font-size: 11px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-2);
  background: color-mix(in srgb, #000 55%, transparent);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 4px 11px;
  cursor: pointer;
  backdrop-filter: blur(6px);
}
.tools button:hover { color: var(--ink); border-color: var(--ink-3); }
.tools button[aria-pressed="true"] { color: var(--surface); background: var(--ink-2); border-color: var(--ink-2); }

/* Meeting overlay: the vote, as the players are seeing it. */
.vote-modal {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: color-mix(in srgb, #000 62%, transparent);
  backdrop-filter: blur(3px);
  padding: 20px;
}
.vote-box {
  width: min(460px, 100%);
  max-height: 100%;
  overflow: auto;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 18px;
}
/* Lighter than the vote overlay: there is no urgency between rounds, and the
   ship behind it is worth looking at. */
.lobby-modal { background: color-mix(in srgb, #000 45%, transparent); }

.vote-box h3 {
  margin: 0 0 2px;
  font-size: 15px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}
.vote-box .why { color: var(--ink-2); font-size: 13px; margin-bottom: 12px; }
.vote-row {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 6px 0;
  border-bottom: 1px solid var(--line-soft);
  font-size: 14px;
}
.vote-row:last-child { border-bottom: 0; }
.vote-row .dot { width: 12px; height: 12px; border-radius: 999px; flex: none; }
.vote-row .who { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.vote-row .tally { font-variant-numeric: tabular-nums; color: var(--ink); font-weight: 650; }
.vote-row .status { font-size: 11px; color: var(--ink-3); letter-spacing: 0.06em; text-transform: uppercase; }
.vote-row.dead { opacity: 0.4; }
.vote-result {
  margin-top: 12px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: var(--surface-3);
  font-size: 14px;
  text-align: center;
}

.over-banner {
  position: absolute;
  inset: auto 0 0 0;
  padding: 14px;
  text-align: center;
  font-size: 17px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  font-weight: 700;
  background: color-mix(in srgb, #000 70%, transparent);
  backdrop-filter: blur(6px);
}
.over-banner.crew     { color: var(--crew);     border-top: 2px solid var(--crew); }
.over-banner.impostor { color: var(--impostor); border-top: 2px solid var(--impostor); }
.over-banner small { display: block; font-size: 12px; letter-spacing: 0.06em; color: var(--ink-2); font-weight: 400; text-transform: none; margin-top: 3px; }

/* --------------------------------------------------------------- aside */

.side { display: grid; gap: 14px; }

.plist { display: grid; }
.prow {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 7px 0;
  border-bottom: 1px solid var(--line-soft);
  font-size: 13px;
  cursor: pointer;
  background: none;
  border-left: 0; border-right: 0; border-top: 0;
  color: inherit;
  font-family: inherit;
  text-align: left;
  width: 100%;
}
.prow:last-child { border-bottom: 0; }
.prow:hover .pname { color: #fff; }
.prow[aria-pressed="true"] { box-shadow: inset 2px 0 0 var(--ink-2); padding-left: 8px; }
.prow .dot { width: 12px; height: 12px; border-radius: 999px; flex: none; }
.prow .pname { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--ink); }
.prow .ptag {
  font-size: 10px;
  letter-spacing: 0.08em;
  padding: 1px 6px;
  border-radius: 999px;
  font-weight: 700;
}
.prow .ptag.imp { color: var(--impostor); background: color-mix(in srgb, var(--impostor) 18%, transparent); }
.prow .ptag.vent { color: var(--warn); background: color-mix(in srgb, var(--warn) 18%, transparent); }
.prow .ptasks { color: var(--ink-3); font-variant-numeric: tabular-nums; font-size: 12px; }
.prow.dead .pname { color: var(--ink-3); text-decoration: line-through; }

.taskbar {
  height: 6px;
  border-radius: 3px;
  background: var(--surface-3);
  overflow: hidden;
  margin-top: 8px;
}
.taskbar i { display: block; height: 100%; background: var(--crew); border-radius: 3px; }

.feed { display: grid; gap: 0; max-height: 340px; overflow: auto; }
.feed-row {
  display: flex;
  gap: 8px;
  padding: 6px 0;
  border-bottom: 1px solid var(--line-soft);
  font-size: 12.5px;
  color: var(--ink-2);
}
.feed-row:last-child { border-bottom: 0; }
.feed-row time { color: var(--ink-3); font-variant-numeric: tabular-nums; flex: none; }
.feed-row .dot { width: 8px; height: 8px; border-radius: 999px; flex: none; margin-top: 6px; }

.back {
  display: inline-block;
  margin-bottom: 14px;
  color: var(--ink-3);
  font-size: 13px;
}
.back:hover { color: var(--ink); }

.loading { color: var(--ink-3); padding: 40px 0; text-align: center; }
