:root {
  --bg: #09090b;
  --surface: #111114;
  --surface-2: #18181c;
  --surface-3: #232329;
  --line: rgba(255, 255, 255, 0.08);
  --line-strong: rgba(255, 255, 255, 0.14);
  --text: #f4f4f5;
  --muted: #a1a1aa;
  --subtle: #71717a;
  --accent: #4ade80;
  --accent-2: #2dd4bf;
  /* Position colors match the labels drawn on the field. */
  --off: #f2c230;
  --def: #5bc0f8;
  --st: #c4b5fd; /* special teams (the kicker) */
  --radius: 10px;
  --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-field: "Roboto Condensed", "Arial Narrow", sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

html, body { margin: 0; }

body {
  background:
    radial-gradient(900px 520px at 0% 0%, rgba(74, 222, 128, 0.07), transparent 65%),
    radial-gradient(700px 480px at 100% 100%, rgba(45, 212, 191, 0.05), transparent 65%),
    var(--bg);
  background-attachment: fixed;
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ---------- Layout (stacked: phones & tablets) ---------- */
.app {
  width: 100%;
  max-width: 1280px;
  margin: 0 auto;
  flex: 1;
  display: flex;
  flex-direction: column;
}
/* Phones/tablets: the panel's pieces join the page flow so the sprite switch can sit under the
   field (title, buttons, field, sprite switch), and the field runs edge to edge. */
.panel { display: contents; }
.toolbar { padding-inline: 16px; }
.stage { order: 1; padding: 0 0 18px; }
.style-switch { order: 2; }

/* ---------- Play 17–0 Challenge / Back to Builder ---------- */
/* Phones: top right of the page. Wide screens: top of the side panel. */
.cta-row { order: -1; display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; padding: 12px 16px 0; }
.mode-cta {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 9px 16px 9px 13px;
  border: 0;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 800;
  letter-spacing: -0.01em;
  white-space: nowrap;
  color: #1c1303;
  background: linear-gradient(135deg, #fde047, #f59e0b);
  box-shadow: 0 6px 22px rgba(245, 158, 11, 0.35), inset 0 1px 0 rgba(255, 255, 255, 0.45);
}
.mode-cta:hover { background: linear-gradient(135deg, #fef08a, #fbbf24); }
.mode-cta svg { width: 1em; height: 1em; flex: none; fill: currentColor; }
.mode-cta.back {
  padding-left: 11px;
  color: var(--text);
  background: rgba(9, 13, 17, 0.85);
  border: 1px solid rgba(255, 255, 255, 0.18);
  box-shadow: 0 6px 22px rgba(0, 0, 0, 0.35);
}
.mode-cta.back:hover { background: rgba(24, 24, 28, 0.95); }
.mode-cta.back svg { fill: none; stroke: currentColor; stroke-width: 2.6; stroke-linecap: round; stroke-linejoin: round; }

/* Play 151 Challenge: red, like Pokémon Red. Phones: across the row from the gold button. Wide
   screens: under it. */
.mode-cta.alt {
  color: #fff;
  background: linear-gradient(135deg, #f87171, #dc2626);
  box-shadow: 0 6px 22px rgba(220, 38, 38, 0.3), inset 0 1px 0 rgba(255, 255, 255, 0.35);
}
.mode-cta.alt:hover { background: linear-gradient(135deg, #fca5a5, #ef4444); }
.cta-row .mode-cta:not([hidden]) + .mode-cta.alt { order: -1; margin-right: auto; }
/* Leaderboard (gold, inside a challenge): across the row from Back to Builder. */
.cta-row .mode-cta.board { order: -1; margin-right: auto; }
.mode-cta svg.trophy, .mode-cta svg.line { fill: none; stroke: currentColor; stroke-width: 2.3; stroke-linecap: round; stroke-linejoin: round; }
/* Fantasy Draft (purple): phones give it the row under the two challenges. */
.mode-cta.fd {
  color: #1e1b4b;
  text-decoration: none;
  background: linear-gradient(135deg, #c4b5fd, #a5b4fc);
  box-shadow: 0 6px 22px rgba(165, 180, 252, 0.25), inset 0 1px 0 rgba(255, 255, 255, 0.35);
}
.mode-cta.fd:hover { background: linear-gradient(135deg, #ddd6fe, #c7d2fe); }
.mode-cta.fd:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }
.cta-row .mode-cta.fd { flex-basis: 100%; justify-content: center; }
.wide-only { display: none; }
/* Narrow phones (360px): both buttons still fit on one row (the very smallest wrap to two). */
@media (max-width: 370px) {
  .cta-row .mode-cta { gap: 6px; padding: 8px 12px 8px 10px; font-size: 13px; }
}

/* Builder vs. Draft Mode, and which challenge: 17–0 (region and type rolls) or 151 (one Pokémon a round) */
body.mode-draft .builder-only,
body:not(.mode-draft) .draft-only,
body.game-151 .only-170,
body:not(.game-151) .only-151 { display: none !important; }

.top {
  text-align: center;
  padding: 12px 16px 18px;
}
.top h1 {
  margin: 0;
  font-size: clamp(28px, 5vw, 40px);
  font-weight: 800;
  letter-spacing: -0.035em;
  line-height: 1.05;
}
/* "17–0 Challenge" is longer than "Builder": it gets its own, slightly smaller line. */
.top h1 .long { display: block; font-size: 0.8em; }
.top h1 .accent {
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.nowrap { white-space: nowrap; }
/* Discord: the same size as the Leaderboard button. Phones: right under it (8px apart; .home-links keeps its 18px
   bottom margin). Wide screens: under the sprite switch (see the wide-screen block). */
.discord-cta {
  order: 2;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: calc(100% - 32px);
  max-width: 420px;
  margin: -10px auto 18px;
  padding: 9px 12px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 800;
  line-height: normal;
  color: #fff;
  text-decoration: none;
  background: linear-gradient(90deg, #5865f2, #7c86f7);
  box-shadow: 0 6px 22px rgba(88, 101, 242, 0.3), inset 0 1px 0 rgba(255, 255, 255, 0.3);
}
.discord-cta:hover { background: linear-gradient(90deg, #6f7af4, #949cf8); }
.discord-cta svg { width: 16px; height: 16px; flex: none; fill: currentColor; }

.sub {
  margin: 8px auto 0;
  max-width: 560px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.5;
}

/* ---------- Buttons ---------- */
.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  margin-bottom: 14px;
}
button {
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 9px 14px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.1s;
}
button:hover { background: var(--surface-3); border-color: var(--line-strong); }
button:active { transform: scale(0.98); }
button.primary {
  background: #fafafa;
  color: #09090b;
  border-color: transparent;
}
button.primary:hover { background: #e4e4e7; }
button:disabled { opacity: 0.45; cursor: not-allowed; transform: none; }
button:disabled:hover { background: var(--surface-2); border-color: var(--line); }
button.primary:disabled:hover { background: #fafafa; border-color: transparent; }
button.wide { width: 100%; }
button:focus-visible, input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.toolbar button {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
.toolbar svg, .close svg {
  width: 16px;
  height: 16px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.toolbar button:not(.primary) svg { color: var(--muted); }

/* Builder: the leaderboard, under the sprite switch, in the title's All-22 colors. */
.home-links { order: 2; display: flex; gap: 8px; width: calc(100% - 32px); max-width: 420px; margin: 6px auto 18px; }
.lb-home {
  display: flex;
  flex: 1;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-width: 0;
  padding: 9px 12px;
  border: 0;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 800;
  color: #052e16;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  box-shadow: 0 6px 22px rgba(45, 212, 191, 0.25), inset 0 1px 0 rgba(255, 255, 255, 0.35);
}
.lb-home:hover { background: linear-gradient(90deg, #86efac, #5eead4); }
.lb-home svg { width: 16px; height: 16px; flex: none; fill: none; stroke: currentColor; stroke-width: 2.3; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- Sprite style: segmented control ---------- */
.style-switch {
  min-width: 0;
  margin: 0 auto 8px;
  padding: 0;
  border: 0;
  width: calc(100% - 32px);
  max-width: 320px;
}
.style-switch legend {
  padding: 0;
  margin: 0 auto 8px;
  color: var(--subtle);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
}
.segmented {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 2px;
  padding: 3px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
/* Legendaries on/off: a small switch on the Generation heading's line (so it adds no height). The
   heading stays centered on phones, like the others, with the switch at the right. */
.gen-switch legend { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; width: 100%; }
.gen-switch legend > span { grid-column: 2; }
.legend-toggle {
  grid-column: 3;
  justify-self: end;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--subtle);
  cursor: pointer;
}
.legend-toggle:hover, .legend-toggle:has(input:checked) { color: var(--text); }
.legend-toggle input { position: absolute; opacity: 0; pointer-events: none; }
.switch {
  position: relative;
  width: 26px;
  height: 15px;
  flex: none;
  border-radius: 999px;
  background: var(--surface-3);
  border: 1px solid var(--line-strong);
  transition: background 0.15s, border-color 0.15s;
}
.switch::after {
  content: "";
  position: absolute;
  top: 1px;
  left: 1px;
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: var(--muted);
  transition: transform 0.15s, background 0.15s;
}
.legend-toggle input:checked + .switch { background: var(--accent); border-color: transparent; }
.legend-toggle input:checked + .switch::after { transform: translateX(11px); background: #09090b; }
.legend-toggle input:focus-visible + .switch { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Generations: all nine regions plus All, five to a row. */
.segmented.gens { grid-template-columns: repeat(5, 1fr); }
/* Generation buttons: region name with the generation number underneath. */
.segmented.gens span { padding: 5px 0; line-height: 1.15; }
.segmented .rg { display: block; font-size: 11.5px; font-weight: 600; letter-spacing: -0.01em; }
.segmented .gn { display: block; font-size: 10px; font-weight: 500; color: var(--subtle); }
.segmented input:checked + span .gn { color: var(--muted); }
.segmented label { cursor: pointer; min-width: 0; }
.segmented input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}
.segmented span {
  display: block;
  text-align: center;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  padding: 7px 4px;
  border-radius: 7px;
  transition: background 0.15s, color 0.15s;
}
.segmented label:hover span { color: var(--text); }
.segmented input:checked + span {
  background: var(--surface-3);
  color: var(--text);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.4), inset 0 0 0 1px var(--line-strong);
}
.segmented input:disabled + span { opacity: 0.35; }
.segmented label:has(input:disabled) { cursor: not-allowed; }
.segmented label:has(input:disabled):hover span { color: var(--muted); }
.segmented input:focus-visible + span {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

/* ---------- Field ---------- */
.field-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 1536 / 1064;
  overflow: hidden;
  border-block: 1px solid var(--line);
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.6);
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}
/* The field is a size container: the roll pop-up scales with it. */
.field-wrap { container-type: inline-size; }
#field {
  display: block;
  width: 100%;
  height: 100%;
}
#hotspots { position: absolute; inset: 0; }

.hotspot {
  position: absolute;
  padding: 0;
  margin: 0;
  background: transparent;
  border: 2px solid transparent;
  border-radius: 12px;
  cursor: grab;
  touch-action: none;
}
.hotspot:hover { background: rgba(255, 255, 255, 0.08); border-color: rgba(255, 255, 255, 0.4); }
.hotspot.drop-target { background: rgba(74, 222, 128, 0.16); border-color: var(--accent); }
.hotspot.dragging { opacity: 0.4; }
.hotspot:active { transform: none; }
/* Draft Mode: no dragging (so swipes on the field scroll the page), open spots pulse while placing. */
#hotspots.draft .hotspot { cursor: pointer; touch-action: manipulation; }
#hotspots.draft .hotspot.locked { cursor: default; }
.hotspot.open-slot {
  border-color: rgba(74, 222, 128, 0.7);
  background: rgba(74, 222, 128, 0.07);
  animation: open-pulse 1.6s ease-in-out infinite;
}
.hotspot.open-slot:hover { background: rgba(74, 222, 128, 0.2); border-color: var(--accent); }
@keyframes open-pulse { 50% { border-color: rgba(74, 222, 128, 0.22); } }

/* ---------- Roll pop-up (17–0 Challenge) ---------- */
.roll-pop {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: grid;
  place-items: center;
  background: radial-gradient(closest-side, rgba(0, 0, 0, 0.5), rgba(0, 0, 0, 0.18));
  cursor: pointer;
  animation: roll-fade 0.18s ease-out;
  transition: opacity 0.18s;
}
.roll-pop.out { opacity: 0; }
@keyframes roll-fade { from { opacity: 0; } }
.roll-card {
  --reel-h: clamp(46px, 6.6cqw, 88px);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: clamp(6px, 1.2cqw, 14px);
  padding: clamp(10px, 2cqw, 24px) clamp(14px, 2.8cqw, 34px);
  border-radius: clamp(12px, 1.6cqw, 22px);
  background: rgba(9, 13, 17, 0.95);
  border: 1px solid rgba(255, 255, 255, 0.16);
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.65);
  animation: roll-card-in 0.3s cubic-bezier(0.2, 0.9, 0.3, 1.25);
}
@keyframes roll-card-in { from { transform: scale(0.85); opacity: 0; } }
.roll-title {
  font-family: var(--font-field);
  font-size: clamp(11px, 1.3cqw, 16px);
  font-weight: 800;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}
.reels { display: flex; gap: clamp(8px, 1.6cqw, 18px); }
.reel { display: flex; flex-direction: column; align-items: center; gap: clamp(4px, 0.6cqw, 8px); }
.reel-win {
  position: relative;
  width: clamp(112px, 15.5cqw, 210px);
  height: var(--reel-h);
  overflow: hidden;
  border-radius: clamp(8px, 1.1cqw, 14px);
  background: var(--surface-2);
  border: 1px solid var(--line-strong);
  transition: border-color 0.2s, box-shadow 0.2s;
}
/* Soft fade at the top and bottom of each window, like a slot machine. */
.reel-win::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: linear-gradient(var(--surface-2), transparent 20%, transparent 80%, var(--surface-2));
}
.reel-win.landed, .reel-win.held { border-color: rgba(74, 222, 128, 0.7); }
.reel-win.landed {
  box-shadow: 0 0 0 3px rgba(74, 222, 128, 0.18), 0 0 26px rgba(74, 222, 128, 0.28);
  animation: reel-land 0.4s ease-out;
}
@keyframes reel-land { 40% { transform: scale(1.07); } }
.reel-strip { position: absolute; top: 0; left: 0; right: 0; }
.reel-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: calc(var(--reel-h) - 2px); /* the window's height inside its 1px border */
  line-height: 1.1;
}
.reel-item b { font-size: clamp(17px, 2.5cqw, 32px); font-weight: 800; letter-spacing: -0.02em; }
.reel-item small { font-size: clamp(10px, 1.1cqw, 14px); font-weight: 600; color: var(--muted); }
.reel-item .type {
  padding: 0.22em 0.85em;
  border-radius: 999px;
  font-size: clamp(14px, 2cqw, 26px);
  font-weight: 800;
}
/* 151 Challenge: one wider reel of Pokémon, sprite and name. */
.reel.mon .reel-win { width: clamp(200px, 30cqw, 400px); }
.reel-item.mon { flex-direction: row; gap: clamp(6px, 1cqw, 12px); padding: 0 10px; }
.reel-item.mon img { flex: none; width: auto; height: calc(var(--reel-h) * 0.86); }
.reel-item.mon img.pixelated { image-rendering: pixelated; }
.reel-item.mon b { overflow: hidden; font-size: clamp(15px, 2.2cqw, 28px); white-space: nowrap; text-overflow: ellipsis; }
.reel-label, .roll-skip {
  font-size: clamp(10px, 1cqw, 13px);
  font-weight: 600;
  color: var(--subtle);
}
.reel-label { text-transform: uppercase; letter-spacing: 0.1em; }

.ghost {
  position: fixed;
  pointer-events: none;
  z-index: 50;
  width: 96px;
  height: 96px;
  transform: translate(-50%, -60%);
  filter: drop-shadow(0 8px 12px rgba(0, 0, 0, 0.5));
}
.ghost.pixelated { image-rendering: pixelated; }

/* ---------- Picker ---------- */
dialog.sheet {
  width: min(860px, calc(100vw - 32px));
  /* dvh: the height actually visible right now (phone browsers' 100vh assumes their toolbars are
     hidden, which made pop-ups taller than the screen and cut off their top). */
  max-height: min(760px, calc(100vh - 48px));
  max-height: min(760px, calc(100dvh - 48px));
  padding: 0;
  border: 1px solid var(--line-strong);
  border-radius: 16px;
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 30px 100px rgba(0, 0, 0, 0.7);
  display: none;
  flex-direction: column;
  overflow: hidden;
}
dialog.sheet[open] { display: flex; }
dialog#season { width: min(680px, calc(100vw - 32px)); }
dialog::backdrop { background: rgba(0, 0, 0, 0.6); backdrop-filter: blur(4px); }

.picker-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 16px 10px;
  margin: 0;
}
.picker-title { display: flex; align-items: center; gap: 10px; min-width: 0; }
.picker-title h2 { margin: 0; font-size: 18px; font-weight: 700; letter-spacing: -0.01em; }
.pos-chip {
  font-family: var(--font-field);
  font-weight: 700;
  font-size: 14px;
  padding: 3px 8px;
  border-radius: 6px;
  background: var(--bg);
  border: 1px solid var(--line-strong);
}
.pos-chip.off { color: var(--off); }
.pos-chip.def { color: var(--def); }
.pos-chip.st { color: var(--st); }
.close {
  display: inline-flex;
  padding: 8px;
  background: transparent;
  border-color: transparent;
  color: var(--muted);
}
.close:hover { color: var(--text); }

.picker-tools {
  display: flex;
  gap: 8px;
  padding: 0 16px;
}
.picker-tools input {
  flex: 1;
  min-width: 0;
  font: inherit;
  font-size: 16px;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  padding: 10px 12px;
  transition: border-color 0.15s;
}
.picker-tools input::placeholder { color: var(--subtle); }
.picker-tools input:focus { border-color: var(--accent); outline: none; }
.picker-hint {
  margin: 8px 16px 4px;
  color: var(--subtle);
  font-size: 12px;
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(104px, 1fr));
  gap: 8px;
  padding: 8px 16px 16px;
  overflow-y: auto;
}
.mon {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 8px 4px 10px;
  border-radius: 12px;
  background: var(--surface-2);
}
.mon:hover { transform: translateY(-1px); }
.mon[hidden], .empty-msg[hidden] { display: none; }
.mon img {
  width: 72px;
  height: 72px;
  image-rendering: pixelated;
}
.mon .num { color: var(--subtle); font-size: 11px; font-weight: 500; font-variant-numeric: tabular-nums; }
.mon .nm { font-size: 13px; font-weight: 600; line-height: 1.15; text-align: center; }
.mon.current { border-color: var(--accent); background: rgba(74, 222, 128, 0.08); }
.mon .tag {
  position: absolute;
  top: 6px;
  right: 6px;
  font-family: var(--font-field);
  font-weight: 700;
  font-size: 11px;
  padding: 1px 5px;
  border-radius: 4px;
  background: var(--bg);
  border: 1px solid var(--line);
}
.mon .tag.off { color: var(--off); }
.mon .tag.def { color: var(--def); }
.mon .tag.st { color: var(--st); }
.mon .leg { position: absolute; top: 5px; left: 8px; font-size: 12px; color: var(--off); }
.empty-msg { color: var(--muted); grid-column: 1 / -1; text-align: center; padding: 24px; }

/* ---------- Formation switches ---------- */
.formation { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.formation.two { grid-template-columns: 1fr 1fr; }
.fopt { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.fcap {
  font-size: 10.5px;
  font-weight: 600;
  text-align: center;
  color: var(--subtle);
}
.segmented.mini { grid-template-columns: 1fr 1fr; }
.segmented.mini span { padding: 5px 2px; font-size: 12.5px; }
.dp-setup-title { margin: 0; font-size: 13px; line-height: 1.4; color: var(--muted); }

/* ---------- Draft Mode ---------- */
.draft-panel {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: calc(100% - 32px);
  max-width: 560px;
  margin: 0 auto 14px;
  padding: 14px;
  border-radius: 14px;
  background: var(--surface);
  border: 1px solid var(--line);
}
.dp-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.dp-round {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}
.dp-link {
  padding: 2px 4px;
  background: none;
  border: 0;
  color: var(--subtle);
  font-size: 12px;
  font-weight: 600;
}
.dp-link:hover { background: none; color: var(--text); text-decoration: underline; text-underline-offset: 3px; }
.dp-progress { height: 4px; margin-top: -4px; border-radius: 2px; background: var(--surface-3); overflow: hidden; }
.dp-progress i {
  display: block;
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  transition: width 0.3s;
}
.dp-state { display: flex; flex-direction: column; gap: 10px; }
.dp-note { margin: 0; font-size: 12px; color: var(--subtle); text-align: center; }
/* Before a run: whether it counts for the leaderboard (or a way to sign in). */
.dp-lb { min-height: 1.4em; margin-top: -2px; overflow: hidden; color: var(--muted); white-space: nowrap; text-overflow: ellipsis; }
.dp-lb a { color: var(--accent); font-weight: 600; }
.dp-pick { display: flex; align-items: center; gap: 10px; }
.dp-pick .thumb { width: 56px; height: 56px; flex: none; }
.dp-pick > div { display: flex; flex: 1; flex-direction: column; gap: 2px; min-width: 0; }
.dp-pick-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.dp-pick b { font-size: 16px; color: var(--text); }
.dp-pick span { font-size: 13px; line-height: 1.35; color: var(--muted); }
.dp-pick .type { color: #16161a; } /* the 151 Challenge's type pills keep their own colors */
.dp-state > .rerolls button { flex: 1; justify-content: center; }
/* 151 Challenge: rerolling is the run's other big call, so its button stands out (red, like the
   151 button), with the rerolls left in a badge. */
.rerolls .reroll-cta {
  padding-block: 9px;
  font-size: 14px;
  font-weight: 800;
  color: #fff;
  background: linear-gradient(135deg, #f87171, #dc2626);
  border-color: transparent;
  box-shadow: 0 4px 18px rgba(220, 38, 38, 0.35), inset 0 1px 0 rgba(255, 255, 255, 0.3);
}
.rerolls .reroll-cta:hover { background: linear-gradient(135deg, #fca5a5, #ef4444); border-color: transparent; }
.rerolls .reroll-cta svg { width: 16px; height: 16px; stroke-width: 2.6; color: #fff; }
.rerolls .reroll-cta small { padding: 1px 8px; border-radius: 999px; font-size: 12px; font-weight: 700; color: #fff; background: rgba(0, 0, 0, 0.25); }
.rerolls .reroll-cta:disabled { color: var(--muted); background: var(--surface-2); border-color: var(--line); box-shadow: none; }
.rerolls .reroll-cta:disabled svg { color: var(--muted); }
.rerolls .reroll-cta:disabled small { color: var(--subtle); background: none; }
.dp-pair { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.dp-pair button { padding-inline: 8px; }
.dp-result { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.dp-result > b { font-family: var(--font-field); font-size: 40px; font-weight: 800; line-height: 1; }
.dp-result span { font-size: 13px; color: var(--muted); }
.dp-result span b { font-size: 18px; color: var(--text); }
.dp-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin: 0;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}
.dp-stats div { min-width: 0; }
.dp-stats dt {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--subtle);
}
.dp-stats dd { margin: 2px 0 0; font-size: 15px; font-weight: 700; font-variant-numeric: tabular-nums; }
.dp-result > b.perfect, .dp-stats dd.perfect { color: var(--off); }

/* Region and type chips */
.roll { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  display: inline-flex;
  align-items: baseline;
  gap: 6px;
  padding: 7px 14px;
  border-radius: 999px;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: -0.01em;
  background: var(--surface-3);
  border: 1px solid var(--line-strong);
}
.chip small { font-size: 11px; font-weight: 600; color: var(--muted); }
.chip.type { border-color: transparent; }
/* A round that hasn't been rolled yet. */
.chip.blank { color: var(--subtle); background: transparent; border-style: dashed; }
.chip.blank.spinning { animation: blank-pulse 0.7s ease-in-out infinite alternate; }
@keyframes blank-pulse { to { color: var(--text); border-color: var(--accent); } }

/* Pokémon type colors (dark text on the light ones) */
.type { background: rgb(var(--t)); color: #16161a; }
.t-normal { --t: 168, 167, 122; }
.t-fire { --t: 238, 129, 48; }
.t-water { --t: 99, 144, 240; }
.t-electric { --t: 247, 208, 44; }
.t-grass { --t: 122, 199, 76; }
.t-ice { --t: 150, 217, 214; }
.t-fighting { --t: 194, 46, 40; }
.t-poison { --t: 163, 62, 161; }
.t-ground { --t: 226, 191, 101; }
.t-flying { --t: 169, 143, 243; }
.t-psychic { --t: 249, 85, 135; }
.t-bug { --t: 166, 185, 26; }
.t-rock { --t: 182, 161, 54; }
.t-ghost { --t: 115, 87, 151; }
.t-dragon { --t: 111, 53, 252; }
.t-dark { --t: 112, 87, 70; }
.t-steel { --t: 183, 183, 206; }
.t-fairy { --t: 214, 133, 173; }
.t-fighting, .t-poison, .t-ghost, .t-dragon, .t-dark { color: #fff; }

/* Pick pop-up */
.roll-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 0 16px;
}
.rerolls { display: flex; gap: 6px; }
.rerolls button { display: inline-flex; align-items: center; gap: 6px; padding: 7px 10px; font-size: 13px; white-space: nowrap; }
.rerolls svg {
  width: 14px;
  height: 14px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  color: var(--muted);
}
.rerolls small { font-size: 11px; font-weight: 500; color: var(--subtle); }
.cand-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 8px;
  padding: 8px 16px 16px;
  overflow-y: auto;
}
.cand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 12px;
  text-align: left;
  font-weight: 400;
}
.cand:hover { transform: translateY(-1px); }
.cand.current { border-color: var(--accent); background: rgba(74, 222, 128, 0.08); }
/* A Legendary once the run has used all of its Legendaries: shown, but can't be picked. */
.cand.locked { opacity: 0.45; cursor: not-allowed; }
.cand.locked:hover { transform: none; }
.cand.locked .cand-foot { color: var(--off); font-weight: 600; }
.cand .thumb { width: 64px; height: 64px; flex: none; }
.cand-main { display: flex; flex: 1; flex-direction: column; gap: 6px; min-width: 0; }
.cand-name { display: flex; align-items: baseline; gap: 6px; min-width: 0; }
.cand-name .nm { overflow: hidden; font-size: 15px; font-weight: 700; text-overflow: ellipsis; white-space: nowrap; }
.cand-name .leg { font-size: 13px; color: var(--off); }
.cand-name .num { margin-left: auto; font-size: 11px; font-weight: 500; color: var(--subtle); font-variant-numeric: tabular-nums; }
.cand-types { display: flex; gap: 4px; }
.cand-types .type {
  padding: 1px 7px;
  border-radius: 999px;
  font-size: 10.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.cand-stats {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 2px;
  padding: 5px 0;
  border-block: 1px solid var(--line);
}
.cand-stats span {
  display: flex;
  flex-direction: column;
  align-items: center;
  font-size: 13px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.cand-stats i {
  font-size: 9.5px;
  font-style: normal;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--subtle);
}
.cand-stats .hi { color: #86efac; }
/* Stat tips: what a stat is, with a nudge (hover, or a tap in the 151 panel). */
[data-tip] { cursor: help; }
/* Touch screens: iPhones only turn a tap into a click on things that look tappable. */
@media (hover: none) { [data-tip] { cursor: pointer; } }
.stat-tip {
  position: fixed;
  z-index: 70;
  max-width: 230px;
  padding: 8px 10px;
  border: 1px solid var(--line-strong);
  border-radius: 9px;
  background: #1f1f25;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.55);
  font-size: 12.5px;
  font-weight: 500;
  line-height: 1.4;
  color: var(--muted);
  pointer-events: none;
}
.stat-tip[hidden] { display: none; }
.stat-tip b { display: block; margin-bottom: 2px; font-size: 13px; color: var(--text); }
/* The 151 Challenge's placing panel: height and weight under the stats. */
.cand-stats .size { display: block; grid-column: 1 / -1; padding-top: 3px; font-size: 12px; font-weight: 700; text-align: center; color: var(--text); }
.cand-stats .size i { display: inline; margin: 0; font-size: inherit; letter-spacing: 0; text-transform: none; }
.cand-stats .lo { color: var(--subtle); }
.cand-foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 12px; color: var(--muted); }

/* Season pop-up: the share card itself (sized to fit the screen, so it can be screenshotted or
   pressed and held), with the details folded away underneath. */
dialog#season { width: min(560px, calc(100vw - 32px)); }
.season-body { padding: 0 16px 4px; overflow-y: auto; }
.season-card { display: flex; justify-content: center; }
.season-card img {
  display: block;
  width: auto;
  height: auto;
  max-width: 100%;
  /* Leaves room for the title bar, the hint, "Season details" and the buttons. */
  max-height: calc(100vh - 270px);
  max-height: calc(100svh - 270px);
  border-radius: 12px;
  background: var(--surface-2);
  -webkit-touch-callout: default;
  user-select: auto;
  -webkit-user-select: auto;
}
.season-card img.loading { animation: card-wait 1s ease-in-out infinite alternate; }
@keyframes card-wait { to { background: var(--surface-3); } }
.season-hint { margin: 10px 0; font-size: 12.5px; line-height: 1.4; text-align: center; color: var(--subtle); }
.season-notes { margin: 0 0 10px; font-size: 13px; line-height: 1.45; color: var(--muted); }
.season-more { border-top: 1px solid var(--line); }
.season-more summary { padding: 10px 0; font-size: 13px; font-weight: 600; color: var(--muted); cursor: pointer; }
.season-more summary:hover, .season-more[open] summary { color: var(--text); }
.season-more .season-games { margin-bottom: 12px; }
.season-games {
  display: grid;
  grid-template-columns: 1fr 1fr;
  /* Weeks run down the first column, then the second. */
  grid-template-rows: repeat(9, auto);
  grid-auto-flow: column;
  gap: 4px 10px;
  margin: 0;
  padding: 0;
  list-style: none;
}
.season-games li {
  display: grid;
  grid-template-columns: 18px 14px 48px minmax(0, 1fr) auto;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-radius: 8px;
  background: var(--surface-2);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}
.season-games .wk, .season-games .ors { font-size: 11px; color: var(--subtle); }
.season-games .res { font-weight: 800; }
.season-games .win .res { color: var(--accent); }
.season-games .loss .res { color: #f87171; }
.season-games .opp { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.season-how { margin: 0 0 12px; font-size: 12px; line-height: 1.5; color: var(--subtle); }
/* Share: gold like the Play button. */
.share-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  color: #1c1303;
  background: linear-gradient(135deg, #fde047, #f59e0b);
  border-color: transparent;
}
.share-btn:hover { background: linear-gradient(135deg, #fef08a, #fbbf24); border-color: transparent; }
.share-btn svg {
  width: 16px;
  height: 16px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.season-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
  padding: 12px 16px 16px;
  border-top: 1px solid var(--line);
}
/* Post to the leaderboard: its own row above Share and New run. Once posted, it shows the ranks. */
.season-actions .post-btn { flex: 1 1 100%; }
.post-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-weight: 800;
  color: #052e16;
  background: linear-gradient(135deg, #4ade80, #2dd4bf);
  border-color: transparent;
}
.post-btn:hover { background: linear-gradient(135deg, #86efac, #5eead4); border-color: transparent; }
.post-btn svg { width: 17px; height: 17px; flex: none; fill: none; stroke: currentColor; stroke-width: 2.3; stroke-linecap: round; stroke-linejoin: round; }
.post-btn.posted { color: var(--text); background: var(--surface-2); border-color: rgba(74, 222, 128, 0.45); }
.post-btn.posted svg { color: var(--accent); }
.post-btn:disabled:hover { background: linear-gradient(135deg, #4ade80, #2dd4bf); }
.post-note { flex: 1 1 100%; margin: 0; font-size: 12.5px; line-height: 1.4; text-align: center; color: var(--subtle); }

/* ---------- Leaderboard ---------- */
/* A steady height that the list fills (it scrolls), so switching boards doesn't resize the pop-up. */
dialog.board-sheet { height: min(720px, calc(100vh - 48px)); height: min(720px, calc(100dvh - 48px)); }
.board-tabs { display: flex; flex-direction: column; gap: 8px; padding: 0 16px; }
/* Full challenge names: on narrow screens the longer ones wrap, and every tab keeps the row's height. */
.board-tabs .segmented label { display: flex; }
.board-tabs .segmented span { display: flex; flex: 1; align-items: center; justify-content: center; line-height: 1.2; }
.board-note { margin: 10px 16px 6px; font-size: 12.5px; line-height: 1.4; color: var(--muted); }
.board-list { flex: 1; min-height: 140px; margin: 0; padding: 0 10px 6px; list-style: none; overflow-y: auto; }
.board-row {
  display: grid;
  grid-template-columns: 28px 34px minmax(0, 1fr) auto auto auto;
  align-items: center;
  gap: 10px;
  padding: 7px 8px;
  border-radius: 10px;
}
.board-row + .board-row { border-top: 1px solid var(--line); }
.board-row.me { background: rgba(74, 222, 128, 0.1); box-shadow: inset 0 0 0 1px rgba(74, 222, 128, 0.45); }
.br-rank { font-family: var(--font-field); font-size: 17px; font-weight: 800; text-align: center; color: var(--muted); font-variant-numeric: tabular-nums; }
/* The top three: a trophy, a ring round the picture and a soft glow, in gold, silver and bronze. */
.board-row.top1 { --metal: #facc15; --metal-glow: rgba(250, 204, 21, 0.5); --metal-tint: rgba(250, 204, 21, 0.13); }
.board-row.top2 { --metal: #d4d4d8; --metal-glow: rgba(212, 212, 216, 0.4); --metal-tint: rgba(212, 212, 216, 0.1); }
.board-row.top3 { --metal: #e0975e; --metal-glow: rgba(224, 151, 94, 0.45); --metal-tint: rgba(224, 151, 94, 0.12); }
.board-row.top1, .board-row.top2, .board-row.top3 { background: linear-gradient(90deg, var(--metal-tint), transparent 80%); }
.board-row.top1 .br-pic, .board-row.top2 .br-pic, .board-row.top3 .br-pic { box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px var(--metal); }
.br-trophy { display: block; width: 26px; height: 26px; margin: 0 auto; color: var(--metal); filter: drop-shadow(0 0 5px var(--metal-glow)); }
.br-trophy .tr-body { fill: currentColor; }
.br-trophy .tr-handles { fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }
.br-trophy .tr-shine { fill: none; stroke: #fff; stroke-opacity: 0.6; stroke-width: 1.3; stroke-linecap: round; }
.br-pic {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  overflow: hidden;
  border-radius: 50%;
  background: var(--surface-3);
  font-weight: 700;
  color: var(--muted);
}
.br-pic img { width: 100%; height: 100%; object-fit: cover; }
.br-name { display: flex; flex-direction: column; min-width: 0; }
.br-name b, .br-name small { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.br-name b { font-size: 14px; }
.br-name small { font-size: 12px; color: var(--subtle); }
/* Record, then Team Score: the same big numbers (a perfect 17–0 in gold). */
.br-rec, .br-score { font-family: var(--font-field); font-size: 21px; font-weight: 800; line-height: 1; text-align: right; font-variant-numeric: tabular-nums; }
.br-rec { min-width: 3.4em; }
.br-rec.perfect { color: var(--off); }
.br-score { min-width: 2.2em; }
.br-remove { display: grid; place-items: center; width: 30px; height: 30px; padding: 0; color: #f87171; }
.br-remove svg { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
/* Admins: a player starting far more runs than a person plays (a line of its own under the row). */
.br-flag { grid-column: 3 / -1; margin: -4px 0 0; font-size: 12px; font-weight: 700; color: #f87171; }
/* Where the next 100 load as the list is scrolled. */
.board-more { padding: 12px 8px 16px; font-size: 12.5px; text-align: center; color: var(--subtle); }
.board-foot { padding: 10px 16px 14px; border-top: 1px solid var(--line); font-size: 13px; color: var(--muted); }
.board-foot p { margin: 0; }
.board-foot a { color: var(--accent); font-weight: 600; }
.board-foot .board-fine { margin-top: 6px; font-size: 11.5px; line-height: 1.4; color: var(--subtle); }
@media (prefers-reduced-motion: reduce) {
  .hotspot.open-slot, .chip.blank.spinning, .roll-pop, .roll-card, .reel-win.landed, .season-card img.loading { animation: none; }
}

/* ---------- Toast ---------- */
#toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translate(-50%, 20px);
  background: var(--surface-2);
  border: 1px solid var(--line-strong);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
  font-size: 14px;
  font-weight: 500;
  padding: 10px 16px;
  border-radius: var(--radius);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 60;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- Footer ---------- */
footer {
  text-align: center;
  padding: 24px 16px 32px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.5;
  border-top: 1px solid var(--line);
  margin-top: 16px;
}
footer p { margin: 0 0 4px; }
footer a { color: var(--accent); font-weight: 600; text-decoration: none; }
footer a:hover { text-decoration: underline; text-underline-offset: 3px; }
footer .fine { margin-top: 10px; font-size: 12px; color: var(--subtle); }

@media (max-width: 600px) {
  button { font-size: 13px; padding: 8px 12px; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); }
  .mon img { width: 56px; height: 56px; }
  .cand-grid { grid-template-columns: 1fr; }
  .roll-bar .rerolls { width: 100%; }
  .rerolls button { flex: 1; justify-content: center; padding-inline: 8px; }
  .rerolls svg { display: none; }
  .rerolls .reroll-cta svg { display: block; }
  .season-games { grid-template-columns: 1fr; grid-template-rows: none; grid-auto-flow: row; }
  .season-actions button { flex: 1; padding-inline: 8px; }
  dialog.sheet { max-height: calc(100vh - 24px); max-height: calc(100dvh - 24px); width: calc(100vw - 16px); }
  /* The leaderboard uses the whole screen height. */
  dialog.board-sheet { height: calc(100vh - 24px); height: calc(100dvh - 24px); }
  /* Leaderboard rows: a little tighter, so names have room. */
  .board-row { gap: 8px; }
  .br-rec, .br-score { font-size: 19px; }
  .br-rec { min-width: 3.1em; }
  /* The roll fills the field (sizes follow the field's width), so it reads at a glance. */
  .roll-card { --reel-h: 24cqw; gap: 2.4cqw; padding: 3.2cqw 4cqw; border-radius: 4cqw; }
  .roll-title { font-size: 3.6cqw; }
  .reels { gap: 2.4cqw; }
  .reel-win { width: 41cqw; border-radius: 3cqw; }
  .reel.mon .reel-win { width: 84cqw; }
  .reel-item b, .reel-item.mon b { font-size: 7cqw; }
  .reel-item small { font-size: 3.4cqw; }
  .reel-item .type { font-size: 5.8cqw; }
  .reel-label, .roll-skip { font-size: 3.2cqw; }
}

/* ---------- Wide screens: controls in a slim left column so the field can use the full window height ---------- */
@media (min-width: 1000px) and (min-height: 560px) {
  .app {
    display: grid;
    /* Field column is capped at the width whose height (1536:1064) fits the window (minus 16px top/bottom). */
    grid-template-columns: 248px minmax(0, calc((100vh - 32px) * 1536 / 1064));
    grid-template-columns: 248px minmax(0, calc((100svh - 32px) * 1536 / 1064));
    justify-content: center;
    align-items: center;
    gap: 28px;
    max-width: none;
    min-height: 100vh;
    min-height: 100svh;
    padding: 16px 24px;
  }
  /* The panel never scrolls: shorter windows get a tighter panel (see the height steps below). */
  .panel {
    --gap: 16px;
    --cta-gap: 6px;
    display: flex;
    flex-direction: column;
    gap: var(--gap);
  }
  .cta-row { padding: 0; flex-direction: column; gap: var(--cta-gap); }
  .cta-row .mode-cta, .cta-row .edition-link { width: 100%; justify-content: center; }
  .cta-row .edition-link, .cta-row .mode-cta.alt { padding-block: 6px; font-size: 13px; }
  /* The builder's buttons are all one size: 17–0, 151, Fantasy Draft, Leaderboard. */
  body:not(.mode-draft) .cta-row .mode-cta { padding-block: 6px; font-size: 13px; }
  .cta-row .mode-cta:not([hidden]) + .mode-cta.alt { order: 0; margin: 0; }
  .wide-only { display: inline; }
  .narrow-only { display: none; }
  /* Inside a challenge: Builder and Leaderboard side by side. */
  body.mode-draft .cta-row { flex-direction: row; }
  body.mode-draft .cta-row .mode-cta { flex: 1 1 0; width: auto; padding-inline: 8px; }
  .cta-row .mode-cta.board { order: 0; margin: 0; }
  .top, .toolbar { padding-inline: 0; }
  .top { text-align: left; padding: 0; }
  .top h1 { font-size: 34px; line-height: 1; }
  .top h1 span { display: block; }
  /* Discord: under the sprite switch, the same size as the buttons in the stack at the top. */
  .discord-cta { order: 2; width: auto; max-width: none; margin: calc(var(--cta-gap) - var(--gap)) 0 0; padding: 6px 16px 6px 13px; gap: 7px; font-size: 13px; }
  .discord-cta svg { width: 14px; height: 14px; }
  .sub { margin: 12px 0 0; font-size: 14px; }
  .toolbar {
    flex-direction: column;
    align-items: stretch;
    gap: 6px;
    margin: 0;
  }
  .toolbar button { justify-content: flex-start; }
  .style-switch { margin: 0; width: auto; max-width: none; }
  .cta-row .mode-cta.fd { flex-basis: auto; }
  /* The Leaderboard: under the challenge and Fantasy Draft buttons, the same size as them. */
  .home-links { order: -1; flex-direction: column; width: auto; max-width: none; margin: calc(var(--cta-gap) - var(--gap)) 0 0; gap: var(--cta-gap); }
  .lb-home { flex: none; gap: 7px; padding: 6px 16px 6px 13px; font-size: 13px; }
  .lb-home svg { width: 14px; height: 14px; }
  .draft-panel { width: auto; max-width: none; margin: 0; }
  .style-switch legend { margin: 0 0 8px; }
  .gen-switch legend { grid-template-columns: auto 1fr; }
  .gen-switch legend > span { grid-column: 1; }
  .legend-toggle { grid-column: 2; }
  .stage {
    min-width: 0;
    padding: 0;
  }
  .field-wrap {
    border-radius: 14px;
    border: 1px solid var(--line);
  }
}

/* Builder: room for the Discord button under the sprite switch, so the panel still never scrolls. Only the
   builder's panel is tightened (the challenges have no Discord button). */
@media (min-width: 1000px) and (min-height: 560px) {
  body:not(.mode-draft) .style-switch legend { margin-bottom: 5px; }
}
@media (min-width: 1000px) and (min-height: 560px) and (max-height: 969px) {
  .toolbar { display: grid; grid-template-columns: 1fr 1fr; }
  .toolbar .primary { grid-column: 1 / -1; }
  .toolbar button { padding: 8px 10px; gap: 6px; font-size: 13px; }
}

/* Height steps that keep the side panel within the window without scrolling. */
/* Under 930px tall: the secondary buttons go two to a row. */
@media (min-width: 1000px) and (min-height: 560px) and (max-height: 929px) {
  .panel { --gap: 11px; }
  .toolbar { display: grid; grid-template-columns: 1fr 1fr; }
  .toolbar .primary { grid-column: 1 / -1; }
  .toolbar button { padding: 8px 10px; gap: 6px; font-size: 13px; }
}
/* Under 810px: the title takes two lines ("Pokémon All-22" / mode) and the text is a touch smaller. */
@media (min-width: 1000px) and (min-height: 560px) and (max-height: 809px) {
  .panel { --gap: 8px; --cta-gap: 5px; }
  .top h1 { font-size: 28px; }
  .top h1 span { display: inline; }
  .top h1 #title-mode { display: block; }
  .sub { margin-top: 8px; font-size: 13px; line-height: 1.45; }
}
/* Very short windows: the descriptions make way for the controls (the run setup's choices keep
   their own labels). */
@media (min-width: 1000px) and (min-height: 560px) and (max-height: 729px) {
  .panel { --gap: 10px; }
  .sub.builder-only, .dp-setup-title { display: none; }
  /* In a challenge, the Sprites heading (still read out by screen readers). */
  body.mode-draft .sprite-switch legend {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
  }
}
@media (min-width: 1000px) and (min-height: 560px) and (max-height: 619px) {
  .panel { --gap: 7px; }
  .sub.draft-only { display: none !important; }
  /* The Formation and Sprites headings (still read out by screen readers). */
  .formation-switch legend, .sprite-switch legend {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
  }
}

/* Builder height steps with the Discord button (see "room for the Discord button" above): the same steps as the
   panel's, each a little tighter. Scoped to the builder so the challenges keep their own spacing. */
@media (min-width: 1000px) and (min-height: 560px) and (max-height: 929px) {
  body:not(.mode-draft) .panel { --gap: 9px; --cta-gap: 5px; }
  .toolbar button { padding-block: 6px; }
}
@media (min-width: 1000px) and (min-height: 560px) and (max-height: 809px) {
  body:not(.mode-draft) .panel { --gap: 6px; --cta-gap: 4px; }
}
@media (min-width: 1000px) and (min-height: 560px) and (max-height: 729px) {
  body:not(.mode-draft) .panel { --gap: 8px; --cta-gap: 4px; }
}
@media (min-width: 1000px) and (min-height: 560px) and (max-height: 619px) {
  body:not(.mode-draft) .panel { --gap: 5px; --cta-gap: 4px; }
  .toolbar { gap: 4px; }
}

/* Shared site theme for reading and challenge pages. */
:root {
  --bg: #fff7f2; --surface: #ffffff; --surface-2: #fff0eb; --surface-3: #ffe2db; --line: #f0d8d2; --line-strong: #e8c8c0;
  --text: #32151a; --muted: #795d62; --subtle: #a88789; --accent: #e3350d; --accent-2: #c82808;
  --off: #e3350d; --def: #2f6f86; --st: #8055a8; color-scheme: light;
}
body { background: linear-gradient(135deg,#fff7f2 0%,#fff 48%,#fff0ea 100%); color: var(--text); }
.info-page p, .info-page ul, .info-page li { color: var(--muted); }
.info-page a { color: var(--accent); }
.info-page code { background: var(--surface-3); color: var(--text); }
