/* MIT EMS Building Drill
   Night dispatch console. The campus starts unlit; correct placements burn in
   high-vis, so what you know is legible at a glance. */

:root {
  --void:  #070C13;   /* night */
  --panel: #0E1621;   /* console housing */
  --edge:  #1D2937;
  --slate: #18222E;   /* buildings you aren't being asked about */
  --water: #091823;

  --chalk: #DDE6EF;
  --mute:  #7C8CA0;
  --dim:   #4A5A6D;

  --hivis: #C6F135;   /* ANSI 107 retroreflective yellow-green */
  --alarm: #FF4438;   /* ambulance red — wrong answers only */
  --amber: #FFA51F;   /* revealed, not earned */

  --sans: "Helvetica Neue", Helvetica, Inter, system-ui, sans-serif;
  --mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;

  --bar: 60px;
  --tray: 280px;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--void);
  color: var(--chalk);
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

.app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
}

/* ── status bar ─────────────────────────────────────────────── */

.bar {
  flex: none;
  height: var(--bar);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 0 18px;
  border-bottom: 1px solid var(--edge);
  background: var(--panel);
}

.mark { display: flex; align-items: baseline; gap: 10px; min-width: 0; }

.mark__unit {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: .18em;
  color: var(--hivis);
  border: 1px solid color-mix(in srgb, var(--hivis) 35%, transparent);
  border-radius: 3px;
  padding: 3px 6px;
  white-space: nowrap;
}

.mark__title {
  margin: 0;
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -.02em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.bar__tools { display: flex; align-items: center; gap: 10px; }

.auth__login { text-decoration: none; white-space: nowrap; }
.auth__user { display: flex; align-items: center; gap: 8px; }
.auth__user[hidden] { display: none; }
.auth__user span {
  max-width: 150px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 12px;
  color: var(--hivis);
}

.tally {
  margin: 0 4px 0 0;
  display: flex;
  align-items: baseline;
  gap: 3px;
  font-family: var(--mono);
}
.tally__n  { font-size: 20px; font-weight: 600; color: var(--hivis); font-variant-numeric: tabular-nums; }
.tally__of { font-size: 13px; color: var(--dim); }
.tally__lbl{
  margin-left: 5px;
  font-family: var(--sans);
  font-size: 10px;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--mute);
}

.btn {
  font-family: var(--sans);
  font-size: 12px;
  font-weight: 500;
  letter-spacing: .04em;
  color: var(--chalk);
  background: transparent;
  border: 1px solid var(--edge);
  border-radius: 4px;
  padding: 7px 12px;
  cursor: pointer;
  transition: border-color .15s, color .15s, background .15s;
}
.btn:hover:not(:disabled) { border-color: var(--mute); }
.btn:disabled { color: var(--dim); cursor: default; }
.btn[aria-pressed="true"] {
  color: var(--void);
  background: var(--hivis);
  border-color: var(--hivis);
}
.btn--ghost { flex: 1; }
.btn--sm { padding: 5px 9px; font-size: 11px; }

:where(button, select, .chip):focus-visible {
  outline: 2px solid var(--hivis);
  outline-offset: 2px;
}

/* ── tray ───────────────────────────────────────────────────── */

.main { flex: 1; display: flex; min-height: 0; }

.tray {
  position: relative;
  flex: none;
  width: var(--tray);
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 16px 14px;
  border-right: 1px solid var(--edge);
  background: var(--panel);
}

.tray__head { display: flex; align-items: center; gap: 10px; }

.eyebrow {
  font-size: 10px;
  letter-spacing: .16em;
  text-transform: uppercase;
  color: var(--mute);
}

.route {
  flex: 1;
  min-width: 0;
  font-family: var(--sans);
  font-size: 12px;
  color: var(--chalk);
  background: var(--void);
  border: 1px solid var(--edge);
  border-radius: 4px;
  padding: 6px 8px;
}

.hint { margin: 0; font-size: 11.5px; line-height: 1.5; color: var(--mute); }

.chips {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-wrap: wrap;
  align-content: flex-start;
  gap: 6px;
  padding: 2px;
}

.chip {
  font-family: var(--mono);
  font-size: 13px;
  font-weight: 500;
  color: var(--chalk);
  background: var(--void);
  border: 1px solid var(--edge);
  border-radius: 4px;
  padding: 7px 9px;
  cursor: grab;
  user-select: none;
  touch-action: none;
  transition: border-color .12s, color .12s, transform .12s;
}
.chip:hover { border-color: var(--mute); }

/* Dorms are asked by name, so they read as words rather than designators. */
.chip--name {
  font-family: var(--sans);
  font-size: 12px;
  letter-spacing: .01em;
  border-style: dashed;
}

.chip.is-live {
  color: var(--void);
  background: var(--hivis);
  border-color: var(--hivis);
}

.chip.is-ghost {
  position: fixed;
  z-index: 40;
  pointer-events: none;
  cursor: grabbing;
  box-shadow: 0 6px 20px rgb(0 0 0 / .6);
}

.done {
  margin: 0;
  font-size: 12px;
  line-height: 1.6;
  color: var(--hivis);
}

.tray__foot { display: flex; align-items: center; gap: 10px; }

.misses {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--dim);
  white-space: nowrap;
}

.rank-status {
  margin: -4px 0 0;
  font-size: 10.5px;
  line-height: 1.45;
  color: var(--dim);
}
.rank-status.is-live { color: var(--hivis); }
.rank-status.is-error { color: var(--alarm); }

/* ── focus-set picker: takes over the tray while open ───────── */

.picker {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 16px 14px;
  background: var(--panel);
}
.picker[hidden] { display: none; }

.picker__head { display: flex; align-items: center; gap: 8px; }
.picker__head .eyebrow { flex: 1; }

.picker__n {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--hivis);
  white-space: nowrap;
}

.picker__bulk { display: flex; flex-wrap: wrap; gap: 6px; }

.picker__chips { align-content: flex-start; }

/* Unselected chips recede; selected ones read as in-play. */
.picker__chips .chip { color: var(--dim); border-color: var(--edge); cursor: pointer; }
.picker__chips .chip.is-on { color: var(--chalk); border-color: var(--mute); }
.picker__chips .chip.is-on::before {
  content: "";
  display: inline-block;
  width: 5px;
  height: 5px;
  margin-right: 6px;
  border-radius: 50%;
  background: var(--hivis);
  vertical-align: middle;
}

/* ── map ────────────────────────────────────────────────────── */

/* min-height matters in the stacked layout, min-width in the side-by-side one;
   without both the SVG refuses to shrink and spills over the bar. */
.map { position: relative; flex: 1; min-width: 0; min-height: 0; background: var(--void); }

#svg {
  display: block;
  width: 100%;
  height: 100%;
  cursor: grab;
  touch-action: none;
}
#svg.is-panning { cursor: grabbing; }

#water path { fill: var(--water); }

#roads path {
  fill: none;
  stroke: #16202B;
  stroke-width: 1.6px;
  vector-effect: non-scaling-stroke;
}
#roads path.major { stroke: #1E2A38; stroke-width: 3.2px; }

#context path {
  fill: var(--slate);
  stroke: #101A25;
  stroke-width: 1px;
  vector-effect: non-scaling-stroke;
}

/* Targets: unlit until placed. */
.bldg {
  fill: #223140;
  stroke: #33475C;
  stroke-width: 1.2px;
  vector-effect: non-scaling-stroke;
  cursor: pointer;
  transition: fill .2s, stroke .2s;
}
.bldg:hover { fill: #2C3F52; }

/* A chip is in hand: everything still in play steps forward. */
.is-armed .bldg:not(.is-set) {
  stroke: color-mix(in srgb, var(--hivis) 55%, transparent);
  stroke-width: 1.6px;
}
.is-armed .bldg:not(.is-set):hover { fill: #3A5064; }

/* Outside the focus set: drops back to context and stops taking taps. */
.bldg.is-out {
  fill: var(--slate);
  stroke: #101A25;
  pointer-events: none;
}

.bldg.is-set {
  fill: color-mix(in srgb, var(--hivis) 78%, #0A1018);
  stroke: var(--hivis);
  cursor: default;
}
.bldg.is-told {
  fill: color-mix(in srgb, var(--amber) 40%, #0A1018);
  stroke: var(--amber);
}
.bldg.is-wrong { fill: var(--alarm); stroke: var(--alarm); }

/* Small footprints can't contain their number, so each label carries a halo in
   its own state colour — dark on the fill, still legible where it overhangs. */
#labels text {
  fill: var(--void);
  stroke: var(--hivis);
  stroke-width: 3px;
  paint-order: stroke;
  vector-effect: non-scaling-stroke;
  font-family: var(--mono);
  font-weight: 600;
  text-anchor: middle;
  dominant-baseline: central;
  pointer-events: none;
}
#labels text.told { stroke: var(--amber); }
#labels text.study {
  fill: var(--mute);
  font-weight: 500;
  stroke: var(--void);
  stroke-width: 3.5px;
}

.legend {
  position: absolute;
  right: 12px;
  bottom: 10px;
  margin: 0;
  font-size: 10px;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--dim);
  pointer-events: none;
}

/* ── leaderboard ────────────────────────────────────────────── */

.leaderboard {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 20px;
}
.leaderboard[hidden] { display: none; }

.leaderboard__backdrop {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
  background: rgb(0 0 0 / .72);
  cursor: default;
}

.leaderboard__panel {
  position: relative;
  width: min(720px, 100%);
  max-height: min(680px, calc(100dvh - 40px));
  overflow: auto;
  padding: 22px;
  border: 1px solid var(--edge);
  border-radius: 6px;
  background: var(--panel);
  box-shadow: 0 24px 80px rgb(0 0 0 / .6);
}

.leaderboard__head { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; }
.leaderboard__head h2 { margin: 5px 0 0; font-size: 24px; letter-spacing: -.025em; }
.leaderboard__note { margin: 16px 0 20px; color: var(--mute); font-size: 12px; line-height: 1.5; }
.leaderboard__boards { display: grid; grid-template-columns: 1fr 1fr; gap: 26px; }
.leaderboard__boards h3 {
  margin: 0 0 8px;
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--hivis);
}

.board { margin: 0; padding: 0; list-style: none; border-top: 1px solid var(--edge); }
.board__row {
  display: grid;
  grid-template-columns: 28px minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  min-height: 42px;
  border-bottom: 1px solid var(--edge);
  font-size: 12px;
}
.board__rank { font-family: var(--mono); color: var(--dim); }
.board__name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.board__score { font-family: var(--mono); color: var(--chalk); font-variant-numeric: tabular-nums; }
.leaderboard__empty { margin: 24px 0 0; color: var(--mute); font-size: 12px; }

/* ── motion ─────────────────────────────────────────────────── */

@media (prefers-reduced-motion: no-preference) {
  @keyframes stamp {
    from { opacity: 0; transform: scale(2.2); }
    to   { opacity: 1; transform: scale(1); }
  }
  #labels text.new {
    animation: stamp .22s cubic-bezier(.2, .9, .3, 1) both;
    transform-box: fill-box;
    transform-origin: center;
  }

  @keyframes jolt {
    0%, 100% { transform: translateX(0); }
    25%      { transform: translateX(-4px); }
    75%      { transform: translateX(4px); }
  }
  .chip.is-jolt { animation: jolt .18s ease-in-out 2; }
}

/* ── narrow screens: tray becomes a bottom rail ─────────────── */

@media (max-width: 720px) {
  :root { --tray: auto; }

  .main { flex-direction: column-reverse; }

  .tray {
    width: auto;
    max-height: 44%;
    border-right: 0;
    border-top: 1px solid var(--edge);
    padding: 12px;
    gap: 10px;
  }

  /* The badge alone carries the identity; the tally and controls get the room. */
  .hint, .legend, .mark__title, .tally__lbl, .auth__user span { display: none; }
  .bar { gap: 8px; padding-inline: 10px; }
  .bar__tools { gap: 6px; }
  .bar__tools > .btn, .auth__user .btn { padding: 6px 8px; font-size: 10px; }
  #study { display: none; }
  .leaderboard { padding: 10px; }
  .leaderboard__panel { max-height: calc(100dvh - 20px); padding: 16px; }
  .leaderboard__boards { grid-template-columns: 1fr; }
}

@media (max-width: 480px) {
  .mark__unit { display: none; }
}
