:root {
  --paper: #f4f5f7;
  --panel: #ffffff;
  --ink: #16181d;
  --slate: #6b7280;
  --line: #dde1e7;
  --red: #d62626;   /* the striped guy's red, the one color the flies can barely see */
  --honey: #e9a21b; /* sugar */
  --volt: #3b5bff;  /* zap */
  --found: #22c55e; /* a fly just found him */
  --display: "Pixelify Sans", ui-monospace, "Courier New", monospace;
  --body: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 15px/1.5 var(--body);
}

a { color: inherit; }

button:focus-visible,
input:focus-visible {
  outline: 2px solid var(--volt);
  outline-offset: 2px;
}

.masthead {
  max-width: 1240px;
  margin: 0 auto;
  padding: 32px 24px 12px;
}

h1 {
  display: inline-block;
  margin: 0;
  padding-bottom: 14px;
  font-family: var(--display);
  font-weight: 700;
  font-size: clamp(36px, 5.5vw, 60px);
  line-height: 1;
  /* three 3px bands, the same stripes the striped guy wears */
  background: linear-gradient(var(--red) 0 3px, #fff 3px 6px, var(--red) 6px 9px) left bottom / 100% 9px no-repeat;
}

.lede {
  max-width: 68ch;
  margin: 14px 0 0;
  color: var(--slate);
  text-wrap: pretty;
}

.layout {
  max-width: 1240px;
  margin: 0 auto;
  padding: 12px 24px 24px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 330px;
  /* The side panels are taller than the stage. A flexible second row takes up that extra
     height, so the lab sits right under the stage instead of below a gap. */
  grid-template-rows: auto 1fr auto;
  grid-template-areas:
    "stage side"
    "lab   side"
    "chart chart";
  gap: 20px;
  align-items: start;
}

.stage { grid-area: stage; }
.labpanel { grid-area: lab; }
.side { grid-area: side; display: grid; gap: 16px; }
.chartpanel { grid-area: chart; }

h2 {
  margin: 0;
  font-family: var(--display);
  font-weight: 500;
  font-size: 19px;
  line-height: 1.2;
  text-wrap: balance;
}

.stagehead {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 4px 16px;
  margin-bottom: 8px;
}

.hint, .note {
  margin: 0;
  font-size: 12.5px;
  color: var(--slate);
}

.panel .note { margin-top: 10px; }
.panel h2 + .note { margin-top: 4px; }

.frame {
  position: relative;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #e8dcb0;
}

#page {
  display: block;
  width: 100%;
  aspect-ratio: 960 / 600;
}

.banner {
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  margin: 0;
  padding: 6px 14px;
  border-radius: 6px;
  background: var(--ink);
  color: #fff;
  font-family: var(--display);
  font-size: 18px;
  white-space: nowrap;
}

.controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 18px;
  margin-top: 12px;
}

.seg {
  display: inline-flex;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.seg button {
  padding: 7px 14px;
  border: 0;
  background: transparent;
  color: var(--ink);
  font: inherit;
  cursor: pointer;
}

.seg button[aria-pressed="true"] {
  background: var(--ink);
  color: #fff;
}

.zap {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
}

.zap .end { color: var(--slate); font-size: 12px; }
.zap input { width: 130px; accent-color: var(--volt); }

.actions { display: inline-flex; gap: 8px; margin-left: auto; }

.plain {
  padding: 7px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
  font: inherit;
  cursor: pointer;
}

.plain:hover, .seg button:hover:not([aria-pressed="true"]) { background: #eceef2; }

.panel {
  padding: 14px 16px 16px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
}

.lab {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 10px;
  margin-top: 12px;
}

.card {
  position: relative;
  display: grid;
  gap: 3px;
  padding: 6px 6px 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.card canvas {
  display: block;
  width: 100%;
  aspect-ratio: 16 / 10;
  margin-bottom: 3px;
  border-radius: 4px;
}

.card .name { font-family: var(--display); font-size: 15px; line-height: 1.1; }
.card .score { font-size: 12px; color: var(--slate); font-variant-numeric: tabular-nums; }

.card .rank {
  margin-left: 6px;
  padding: 1px 6px;
  border-radius: 999px;
  background: #eef0f3;
  color: var(--slate);
  font-family: var(--body);
  font-size: 10.5px;
  vertical-align: 2px;
}

.card .rank:empty { display: none; }
.card.leader .rank { background: var(--ink); color: #fff; }
.card:hover { border-color: #b9bfc9; }
.card[aria-pressed="true"] { border-color: var(--ink); box-shadow: 0 0 0 1px var(--ink); }
.card[data-flash="zap"] { border-color: var(--volt); box-shadow: 0 0 0 2px var(--volt); }

/* When a fly finds him, its card glows green for a second, on a layer of its own so the
   watched-fly outline underneath stays put. */
.card::after {
  content: "";
  position: absolute;
  inset: -4px;
  border-radius: 11px;
  box-shadow: 0 0 0 3px var(--found), 0 0 16px 2px rgba(34, 197, 94, 0.6);
  opacity: 0;
  pointer-events: none;
}

.card[data-flash="found"]::after { animation: found-glow 1s ease-out; }

@keyframes found-glow {
  0%, 55% { opacity: 1; }
  100% { opacity: 0; }
}

@media (prefers-reduced-motion: reduce) {
  .card[data-flash="found"]::after { animation: none; opacity: 1; }
}

.eyes {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-top: 12px;
}

.eyes figure { margin: 0; }
.eyes canvas { display: block; width: 100%; aspect-ratio: 1; }

figcaption {
  margin-top: 6px;
  font-size: 12px;
  color: var(--slate);
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.mb { margin-top: 12px; }
.mb span { display: block; margin-bottom: 4px; font-size: 12px; color: var(--slate); }
.mb canvas { display: block; width: 100%; height: 90px; }

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 14px;
  margin: 8px 0 0;
  font-size: 12px;
  color: var(--slate);
}

.legend > span { display: inline-flex; align-items: center; gap: 6px; }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; }
.dot.sugar { background: var(--honey); }
.dot.zapdot { background: var(--volt); }
.dot.firing { background: var(--line); box-shadow: inset 0 0 0 2px var(--ink); }
.key { display: inline-block; width: 18px; border-top: 2px solid var(--ink); }
.key.mine { border-top-color: var(--red); }
.key.band { height: 10px; border: 0; border-radius: 2px; background: rgba(22, 24, 29, 0.1); }
.key.base { border-top: 2px dashed var(--slate); }

.meter { margin-top: 14px; }

.track {
  position: relative;
  height: 10px;
  border-radius: 5px;
  background: var(--line);
}

.track::after {
  content: "";
  position: absolute;
  top: -3px;
  bottom: -3px;
  left: calc(50% - 1px);
  width: 2px;
  background: var(--ink);
}

.fill { position: absolute; top: 0; bottom: 0; width: 0; border-radius: 5px; }

.scale {
  display: flex;
  justify-content: space-between;
  margin-top: 5px;
  font-size: 12px;
  color: var(--slate);
}

.scale #chance { color: var(--ink); font-variant-numeric: tabular-nums; }

.dans { display: flex; gap: 8px; margin-top: 12px; }

.dan {
  padding: 3px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 12px;
  color: var(--slate);
  transition: background-color 0.15s, color 0.15s, border-color 0.15s;
}

.dan.pam.on { background: var(--honey); border-color: var(--honey); color: var(--ink); }
.dan.ppl1.on { background: var(--volt); border-color: var(--volt); color: #fff; }

.stats dl {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin: 12px 0 0;
}

.stats dt { font-size: 12px; color: var(--slate); }

.stats dd {
  margin: 0;
  font-family: var(--display);
  font-size: 26px;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}

.stats strong { color: var(--ink); }

.charthead {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px 24px;
}

.labnow { margin: 0; text-align: right; }
.labnow-label { display: block; font-size: 12px; color: var(--slate); }
.labnow-value { font: 600 30px/1.1 var(--body); }

.chartlegend { margin-top: 10px; }

.chartwrap { position: relative; margin-top: 6px; }

#chart { display: block; width: 100%; height: 250px; border-radius: 4px; }
#chart:focus-visible { outline: 2px solid var(--volt); outline-offset: 2px; }

.tip {
  position: absolute;
  z-index: 2;
  min-width: 190px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 6px 18px rgba(22, 24, 29, 0.12);
  font-size: 12px;
  pointer-events: none;
}

.tip .tip-round { margin-bottom: 4px; color: var(--slate); }
.tip .row { display: grid; grid-template-columns: 18px auto 1fr; align-items: center; gap: 8px; line-height: 1.7; }
.tip .value { font-weight: 600; font-variant-numeric: tabular-nums; }
.tip .label { color: var(--slate); }

.numbers { margin-top: 10px; font-size: 13px; }
.numbers summary { cursor: pointer; color: var(--slate); }
.numbers summary:focus-visible { outline: 2px solid var(--volt); outline-offset: 2px; }
.tablewrap { overflow-x: auto; }
.numbers table { margin-top: 8px; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.numbers caption { padding-bottom: 6px; color: var(--slate); text-align: left; font-size: 12px; }
.numbers th, .numbers td { padding: 4px 16px 4px 0; border-bottom: 1px solid var(--line); text-align: right; white-space: nowrap; }
.numbers th { font-weight: 600; }
.numbers th:first-child, .numbers td:first-child { text-align: left; }

.footer {
  max-width: 1240px;
  margin: 0 auto;
  padding: 0 24px 40px;
  font-size: 12.5px;
  color: var(--slate);
}

@media (max-width: 980px) {
  .layout {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: none;
    grid-template-areas: "stage" "lab" "side" "chart";
  }
  .lab { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
  .actions { margin-left: 0; }
}
