:root {
  --page: #2d2f2f;
  --panel: #192b3a;
  --grid-line: #4c5559;
  --text: #edf1f2;
  --muted: #aeb8bc;
  --gold: #ffd400;
  --blue: #4b8dbd;
  --red: #ff624c;
  --objective: #f7df47;
  --cell-size: clamp(34px, 7.4vw, 55px);
  --coordinate-grid-width: 210px;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html { min-height: 100%; background: var(--page); }

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  color: var(--text);
  font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
  background-color: var(--page);
  background-image: url("https://haloflashpoint.manticgames.com/res/public/img/circuit-board-gak.png");
  background-size: cover;
  background-position: center top;
  background-repeat: no-repeat;
  background-attachment: fixed;
}

button { font: inherit; }

.app-shell {
  width: min(100%, 760px);
  min-height: 100vh;
  margin: 0 auto;
  padding: 28px 16px 36px;
  text-align: center;
}

.brand { margin-bottom: 14px; }

.brand-logo {
  display: block;
  width: min(460px, 72vw);
  height: auto;
  margin: 0 auto;
}

.brand p {
  margin: -4px 0 0;
  font-size: clamp(2rem, 8vw, 3.8rem);
  font-weight: 650;
  line-height: 1;
  background: linear-gradient(to top, #cbd0d2, #fff);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.welcome { min-height: 170px; display: grid; place-items: center; }
.welcome[hidden],
.setup[hidden] { display: none; }
.scenario-heading { margin: 20px 0 18px; }

.eyebrow {
  display: block;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}

.scenario-heading h1 {
  margin: 3px 0;
  color: var(--gold);
  font-size: clamp(1.6rem, 6vw, 2.35rem);
  line-height: 1.1;
}

.scenario-heading p {
  max-width: 580px;
  margin: 8px auto 0;
  color: var(--muted);
  font-size: 0.93rem;
}

.scenario-rules {
  width: min(580px, 94%);
  margin: 10px auto 0;
  padding: 6px 10px;
  border: 1px solid rgba(255, 212, 0, 0.22);
  border-radius: 6px;
  background: rgba(17, 35, 51, 0.58);
  font-size: 0.8rem;
  line-height: 1.35;
  text-align: left;
}

.scenario-limits {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  padding-bottom: 5px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.scenario-limits > div {
  display: flex;
  align-items: baseline;
  gap: 7px;
  min-width: 0;
}

.scenario-limits > div + div {
  padding-left: 12px;
  border-left: 1px solid rgba(255, 255, 255, 0.1);
}

.scenario-scoring {
  display: grid;
  grid-template-columns: 58px 1fr;
  gap: 8px;
  padding-top: 5px;
}

.scenario-rules dt {
  color: var(--gold);
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.scenario-rules dd {
  margin: 0;
  color: var(--text);
}

.board {
  display: grid;
  grid-template-columns: 24px repeat(8, var(--cell-size));
  grid-template-rows: repeat(8, var(--cell-size)) 24px;
  justify-content: center;
  margin: 0 auto 22px;
  user-select: none;
}

.cell {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
  border: 1px solid var(--grid-line);
  background: var(--panel);
  overflow: visible;
}

.cell.deployment-blue { background: #4b8dbd; }
.cell.deployment-red { background: #ff624c; }
.cell.zone-cell {
  background: #22394a;
  box-shadow: inset 0 0 0 1px rgba(247, 223, 71, 0.22);
}
.cell.weapon-spawn { box-shadow: inset 0 0 0 3px var(--gold); }

.cell.weapon-spawn::after {
  content: "W";
  position: absolute;
  z-index: 0;
  color: rgba(255, 212, 0, 0.52);
  font-size: clamp(0.82rem, 3vw, 1.15rem);
  font-weight: 850;
  line-height: 1;
  pointer-events: none;
}

.axis-label {
  display: grid;
  place-items: center;
  color: var(--gold);
  font-size: 0.82rem;
  font-weight: 700;
}

.cell-markers {
  position: absolute;
  inset: 2px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 2px;
  pointer-events: none;
  z-index: 2;
}

.respawn-edge {
  --respawn-colour: var(--blue);
  position: absolute;
  z-index: 1;
  display: block;
  background: var(--respawn-colour);
  pointer-events: none;
}

.respawn-edge.red { --respawn-colour: var(--red); }

.respawn-edge.on-team-deployment {
  --respawn-colour: #69afe0;
  filter:
    drop-shadow(0 0 0.8px rgba(255, 255, 255, 0.95))
    drop-shadow(0 0 0.8px rgba(255, 255, 255, 0.8));
}

.respawn-edge.red.on-team-deployment { --respawn-colour: #ff7968; }

.respawn-edge.edge-left,
.respawn-edge.edge-right {
  width: 12px;
  height: 26px;
  top: 50%;
  transform: translateY(-50%);
}

.respawn-edge.edge-left {
  left: 8px;
  clip-path: polygon(0 0, 100% 50%, 0 100%);
}

.respawn-edge.edge-right {
  right: 8px;
  clip-path: polygon(100% 0, 0 50%, 100% 100%);
}

.respawn-edge.edge-top,
.respawn-edge.edge-bottom {
  width: 26px;
  height: 12px;
  left: 50%;
  transform: translateX(-50%);
}

.respawn-edge.edge-top {
  top: 8px;
  clip-path: polygon(0 0, 100% 0, 50% 100%);
}

.respawn-edge.edge-bottom {
  bottom: 8px;
  clip-path: polygon(0 100%, 50% 0, 100% 100%);
}

.respawn-edge.edge-centre {
  width: 18px;
  height: 18px;
  border-radius: 50%;
}

.marker {
  min-width: 18px;
  min-height: 18px;
  display: inline-grid;
  place-items: center;
  padding: 1px 3px;
  border-radius: 4px;
  font-size: clamp(0.65rem, 2.4vw, 0.84rem);
  font-weight: 800;
  line-height: 1;
}

.marker-item {
  color: #151b1e;
  background: var(--gold);
  box-shadow: 0 0 8px rgba(255, 212, 0, 0.45);
}

.marker-objective,
.marker-zone {
  min-width: 22px;
  min-height: 22px;
  padding: 0;
  color: #16191a;
  background: var(--objective);
  border: 2px solid #10212d;
  border-radius: 50%;
  box-shadow: 0 0 0 1px rgba(255, 243, 139, 0.78);
}

.marker-objective.flag-blue,
.marker-objective.flag-red,
.marker-objective.bomb-blue,
.marker-objective.bomb-red,
.marker-station {
  color: #fff;
  border: 2px solid #10212d;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.65);
}

.marker-objective.flag-blue,
.marker-objective.bomb-blue,
.marker-station.station-blue { background: #3e86b8; }

.marker-objective.flag-red,
.marker-objective.bomb-red,
.marker-station.station-red { background: #e64f3d; }

.marker-objective.control-neutral {
  color: #15232c;
  background: #d5d9da;
  border-color: var(--gold);
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.72);
}

.marker-zone {
  position: absolute;
  left: calc(100% + 2px);
  top: calc(100% + 2px);
  z-index: 3;
  transform: translate(-50%, -50%);
}

.marker-station {
  min-width: 25px;
  min-height: 21px;
  padding: 1px 3px;
}

.readouts { display: grid; gap: 18px; }

.readout h2 {
  margin: 0 0 8px;
  color: var(--gold);
  font-size: clamp(1.2rem, 4vw, 1.55rem);
}

.hill-rotation { margin-bottom: 2px; }

.hill-round-one {
  width: max-content;
  margin: 0 auto 7px;
  padding: 5px 10px;
  border-radius: 6px;
  color: #16191a;
  background: var(--objective);
  font-size: 0.88rem;
  font-weight: 800;
}

.hill-table-wrap {
  width: min(100%, 294px);
  margin: 0 auto;
  overflow-x: auto;
}

.hill-table {
  width: 100%;
  border: 0;
  border-collapse: separate;
  border-spacing: 4px;
  table-layout: fixed;
  font-variant-numeric: tabular-nums;
}

.hill-table th,
.hill-table td {
  height: 31px;
  padding: 4px 3px;
  border: 0;
  border-radius: 5px;
  text-align: center;
}

.hill-table thead th {
  color: var(--gold);
  font-size: 0.82rem;
  font-weight: 800;
}

.hill-table tbody th {
  color: #16191a;
  background: var(--objective);
  font-weight: 850;
}

.hill-table td {
  color: var(--text);
  background: #292d2f;
  font-size: 0.9rem;
  font-weight: 750;
}

.hill-table tbody tr:nth-child(even) td:nth-child(even),
.hill-table tbody tr:nth-child(odd) td:nth-child(odd) { background: #3a3f41; }

.objective-roll {
  width: max-content;
  margin: 0 auto 7px;
  padding: 5px 10px;
  border-radius: 6px;
  color: #16191a;
  background: var(--objective);
  font-size: 0.88rem;
  font-weight: 800;
}

.objective-table-wrap {
  width: min(100%, 168px);
  margin: 0 auto 7px;
}

.objective-table {
  width: 100%;
  border: 0;
  border-collapse: collapse;
  table-layout: fixed;
  font-variant-numeric: tabular-nums;
}

.objective-table th,
.objective-table td {
  width: 33.333%;
  padding: 4px 2px;
  border: 0;
  text-align: center;
}

.objective-table th {
  color: var(--gold);
  font-size: 1rem;
  font-weight: 800;
}

.objective-table td .coordinate { display: inline-block; }
.objective-table td:nth-child(even) .coordinate { background: #3a3f41; }

.objective-setup .button {
  min-height: 38px;
  margin-top: 5px;
  padding: 7px 12px;
  font-size: 0.82rem;
}

.coordinate-list {
  width: var(--coordinate-grid-width);
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  margin: 0 auto;
}

.coordinate {
  width: 100%;
  padding: 6px 9px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 6px;
  color: var(--text);
  background: #292d2f;
  font-variant-numeric: tabular-nums;
}

.coordinate:nth-child(even) { background: #3a3f41; }
.coordinate-list .coordinate:nth-child(5),
.coordinate-list .coordinate:nth-child(7) { background: #3a3f41; }
.coordinate-list .coordinate:nth-child(6),
.coordinate-list .coordinate:nth-child(8) { background: #292d2f; }
.coordinate strong { color: var(--gold); }

.weapon-table-wrap {
  width: min(100%, var(--coordinate-grid-width));
  margin: 0 auto;
  overflow-x: auto;
}

.weapon-table {
  width: 100%;
  border: 0;
  border-collapse: collapse;
  table-layout: fixed;
  font-variant-numeric: tabular-nums;
}

.weapon-table th,
.weapon-table td {
  width: 25%;
  padding: 4px 2px;
  border: 0;
  text-align: center;
}

.weapon-table th {
  color: var(--gold);
  font-size: 1rem;
  font-weight: 800;
}

.weapon-table td {
  color: var(--text);
  font-size: 0.95rem;
  font-weight: 650;
}

.weapon-table td .coordinate { display: inline-block; }
.weapon-table td:nth-child(even) .coordinate { background: #3a3f41; }

.readout-note {
  margin: 7px 0 0;
  color: var(--muted);
  font-size: 0.78rem;
}

.button {
  min-height: 44px;
  padding: 10px 18px;
  border: 1px solid transparent;
  border-radius: 10px;
  font-weight: 750;
  cursor: pointer;
  transition: transform 120ms ease, box-shadow 120ms ease, background 120ms ease;
}

.button:hover { transform: translateY(-1px); }
.button:active { transform: translateY(0); }

.button:focus-visible,
summary:focus-visible { outline: 3px solid #fff; outline-offset: 3px; }

.button-primary {
  color: #0a1e39;
  background: var(--gold);
  box-shadow: 0 0 11px rgba(255, 212, 0, 0.48);
}

.button-primary:hover {
  background: #eabd00;
  box-shadow: 0 0 16px rgba(255, 212, 0, 0.66);
}

.button-secondary {
  color: var(--gold);
  background: #182a39;
  border-color: var(--gold);
  box-shadow: inset 0 0 0 1px rgba(255, 212, 0, 0.22);
}

.button-secondary:hover {
  background: #20384b;
  box-shadow: 0 0 11px rgba(255, 212, 0, 0.25);
}

.button-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
}

.reroll-controls,
.mode-buttons {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 9px;
}

.reroll-controls { margin-top: 22px; }
.mode-picker { margin-top: 26px; }

.mode-picker > p {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.mode-buttons .button { min-width: 118px; }

.mode-buttons .button[aria-pressed="true"] {
  color: var(--gold);
  background: #182a39;
  border-color: var(--gold);
  box-shadow: inset 0 0 0 1px var(--gold), 0 0 11px rgba(255, 212, 0, 0.25);
}

.reference-link { margin-top: 22px; }

.reference-shell {
  width: min(100%, 940px);
  text-align: left;
}

.reference-shell .brand,
.reference-shell .project-footer { text-align: center; }

.back-link {
  display: inline-block;
  margin: 8px 0 22px;
  color: var(--gold);
  font-weight: 750;
  text-decoration: none;
}

.back-link:hover { text-decoration: underline; }

.back-link:focus-visible,
.reference-search:focus-visible {
  outline: 3px solid #fff;
  outline-offset: 3px;
}

.reference-heading { text-align: center; }

.reference-heading h1 {
  margin: 5px 0 8px;
  color: var(--gold);
  font-size: clamp(1.65rem, 6vw, 2.5rem);
  line-height: 1.1;
}

.reference-heading p {
  max-width: 650px;
  margin: 0 auto;
  color: var(--muted);
  line-height: 1.5;
}

.reference-controls {
  width: min(100%, 680px);
  margin: 26px auto 0;
}

.reference-tabs {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 9px;
  margin-bottom: 18px;
}

.reference-tabs .button[aria-pressed="true"] {
  color: #0a1e39;
  background: var(--gold);
  box-shadow: 0 0 11px rgba(255, 212, 0, 0.42);
}

.reference-search-label {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 750;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.reference-search {
  width: 100%;
  min-height: 48px;
  padding: 10px 14px;
  border: 1px solid rgba(174, 184, 188, 0.52);
  border-radius: 10px;
  color: var(--text);
  background: rgba(17, 35, 51, 0.9);
  font: inherit;
}

.reference-search::placeholder { color: #8f9a9f; }
.reference-search:focus { border-color: var(--gold); }

.reference-count {
  margin: 12px 2px;
  color: var(--muted);
  font-size: 0.82rem;
}

.reference-results {
  overflow: hidden;
  border: 1px solid rgba(174, 184, 188, 0.34);
  border-radius: 10px;
  background: rgba(17, 35, 51, 0.82);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.16);
}

.reference-table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}

.reference-table th,
.reference-table td {
  padding: 11px 13px;
  text-align: left;
  vertical-align: top;
}

.reference-table th {
  color: var(--gold);
  background: #182a39;
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.reference-table th:first-child,
.keyword-reference-table td:first-child { width: 29%; }

.item-reference-table th:first-child,
.item-reference-table td:first-child { width: 38%; }

.reference-table td {
  border-top: 1px solid rgba(174, 184, 188, 0.2);
  color: var(--text);
  font-size: 0.88rem;
  line-height: 1.45;
}

.reference-table tbody tr:nth-child(even) { background: rgba(255, 255, 255, 0.025); }
.reference-table tbody tr:hover { background: rgba(75, 141, 189, 0.1); }
.reference-entry-name { color: var(--gold); }

.item-reference-icon {
  display: grid;
  place-items: center;
  flex: 0 0 46px;
  width: 46px;
  height: 46px;
  overflow: hidden;
  border: 1px solid rgba(255, 212, 0, 0.38);
  border-radius: 7px;
  background: rgba(237, 241, 242, 0.92);
}

.item-reference-icon img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.item-icon-fallback {
  display: grid;
  place-items: center;
  width: 100%;
  height: 100%;
  color: #0a1e39;
  background: var(--gold);
  font-size: 0.95rem;
  font-weight: 900;
  letter-spacing: 0.04em;
}

.item-reference-heading {
  display: flex;
  align-items: center;
  gap: 10px;
}

.item-reference-label { min-width: 0; }

.item-type {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
}

.reference-empty {
  padding: 28px 16px;
  color: var(--muted);
  text-align: center;
}

.legend {
  width: min(100%, 570px);
  margin: 24px auto 0;
  color: var(--muted);
  font-size: 0.84rem;
}

.legend summary { cursor: pointer; }

.legend-items {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 12px;
  margin-top: 10px;
}

.legend-items span { display: flex; align-items: center; gap: 5px; }

.legend-swatch {
  width: 22px;
  height: 22px;
  display: inline-grid;
  place-items: center;
  border-radius: 4px;
  font-style: normal;
  font-weight: 800;
}

.item-marker { color: #151b1e; background: var(--gold); }
.weapon-marker {
  color: rgba(255, 212, 0, 0.72);
  background: var(--panel);
  box-shadow: inset 0 0 0 3px var(--gold);
}
.objective-marker {
  color: #151b1e;
  background: var(--objective);
  border: 2px solid #10212d;
  border-radius: 50%;
  box-shadow: 0 0 0 1px rgba(255, 243, 139, 0.78);
}
.respawn-marker {
  border-radius: 0;
  background: var(--blue);
  clip-path: polygon(0 0, 100% 50%, 0 100%);
}

.project-footer {
  width: min(100%, 590px);
  margin: 32px auto 0;
  padding-top: 18px;
  border-top: 1px solid rgba(174, 184, 188, 0.2);
  color: var(--muted);
  font-size: 0.76rem;
  line-height: 1.45;
}

.project-footer p { margin: 4px 0; }
.project-footer strong { color: var(--text); }
.project-footer a { color: var(--text); }

.creator-mark {
  display: block;
  width: 68px;
  height: auto;
  margin: 0 auto 16px;
  opacity: 0.9;
}

.footer-summary {
  color: rgba(174, 184, 188, 0.86);
  font-size: 0.72rem;
}

.release-meta {
  color: #c7d0d3;
  font-variant-numeric: tabular-nums;
}

.about-helper { margin-top: 12px; }
.about-helper summary {
  width: max-content;
  max-width: 100%;
  margin: 0 auto;
  cursor: pointer;
}

.about-helper[open] summary { margin-bottom: 8px; }

.update-banner {
  position: fixed;
  z-index: 20;
  right: 16px;
  bottom: 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px 10px 16px;
  border: 1px solid var(--gold);
  border-radius: 12px;
  color: var(--text);
  background: #182a39;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.45);
  font-size: 0.88rem;
  font-weight: 650;
}

.update-banner[hidden] { display: none; }
.update-banner .button { min-height: 38px; padding: 7px 12px; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@media (max-width: 520px) {
  :root { --coordinate-grid-width: 186px; }
  .app-shell { padding: 18px 8px 28px; }
  .brand { margin-bottom: 8px; }
  .brand p { font-size: 2rem; }
  .welcome { min-height: 130px; }
  .board {
    grid-template-columns: 20px repeat(8, var(--cell-size));
    grid-template-rows: repeat(8, var(--cell-size)) 20px;
  }
  .axis-label { font-size: 0.72rem; }
  .marker { min-width: 15px; min-height: 15px; padding: 1px 2px; }
  .respawn-edge.edge-left,
  .respawn-edge.edge-right { width: 9px; height: 19px; }
  .respawn-edge.edge-left { left: 5px; }
  .respawn-edge.edge-right { right: 5px; }
  .respawn-edge.edge-top,
  .respawn-edge.edge-bottom { width: 19px; height: 9px; }
  .respawn-edge.edge-top { top: 5px; }
  .respawn-edge.edge-bottom { bottom: 5px; }
  .coordinate-list { gap: 6px; }
  .coordinate { padding: 5px 6px; font-size: 0.88rem; }
  .weapon-table th,
  .weapon-table td { padding: 3px 4px; }
  .reroll-controls .button,
  .mode-buttons .button { flex: 1 1 135px; }
  .project-footer { margin-top: 30px; padding-inline: 8px; }
  .creator-mark { width: 62px; margin-bottom: 14px; }
  .reference-shell { padding-inline: 12px; }
  .reference-shell .brand-logo { width: min(410px, 84vw); }
  .reference-shell .brand p { font-size: 2rem; }
  .back-link { margin-bottom: 18px; }
  .reference-controls { margin-top: 22px; }
  .reference-tabs .button { padding-inline: 8px; }
  .reference-table th,
  .reference-table td { padding: 9px 8px; }
  .reference-table td { font-size: 0.8rem; line-height: 1.4; }
  .reference-table th:first-child,
  .keyword-reference-table td:first-child { width: 34%; }
  .item-reference-table th:first-child,
  .item-reference-table td:first-child { width: 43%; }
  .item-reference-heading { align-items: flex-start; gap: 7px; }
  .item-reference-icon { flex-basis: 38px; width: 38px; height: 38px; }
  .item-type { font-size: 0.65rem; }
  .update-banner {
    right: 8px;
    bottom: 8px;
    left: 8px;
    justify-content: space-between;
  }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; }
}
