@font-face {
  font-family: "Fusion Pixel 12 SC";
  src: url("src/assets/fonts/fusion-pixel-12px-proportional-sc.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "HelloFont ID XiangSuZhiCheng";
  src:
    local("HelloFont ID XiangSuZhiCheng"),
    local("HelloFont ID XiangSuZhiCheng Regular"),
    local("HelloFont-ID-XiangSuZhiCheng"),
    local("HelloFont ID Xiang Su Zhi Cheng"),
    local("字由点字像素之城");
  font-weight: 400;
  font-style: normal;
  font-display: block;
}

:root {
  --bg: #000;
  --fg: #fff;
  --muted: #8f8f8f;
  --blue: #1264ff;
  --gold: #d4a55a;
  --red: #ff3030;
  --yellow: #ffff00;
  --panel: #080808;
  --arena-size: 200px;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  min-height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: "Courier New", "Consolas", monospace;
  image-rendering: pixelated;
  -webkit-font-smoothing: none;
  font-smooth: never;
}

body {
  display: grid;
  place-items: center;
  padding: 18px;
  overflow-x: hidden;
}

button,
.ball-card,
.team-slot {
  font: inherit;
  image-rendering: pixelated;
}

.app {
  width: min(100%, 420px);
  min-height: 560px;
  display: grid;
  align-content: center;
  justify-items: center;
  gap: 18px;
}

.screen {
  width: 100%;
  display: none;
  justify-items: center;
  gap: 18px;
}

.screen.active {
  display: grid;
}

.title {
  margin: 0;
  color: var(--fg);
  font-size: clamp(34px, 12vw, 58px);
  line-height: 0.92;
  text-align: center;
  letter-spacing: 0;
  text-transform: uppercase;
  text-shadow:
    3px 0 0 #2b2b2b,
    0 3px 0 #2b2b2b,
    3px 3px 0 #2b2b2b;
}

.title .blue {
  color: var(--blue);
  text-shadow:
    3px 0 0 #001d65,
    0 3px 0 #001d65,
    3px 3px 0 #001d65;
}

.title .gold {
  color: var(--gold);
  text-shadow:
    3px 0 0 #5a3b12,
    0 3px 0 #5a3b12,
    3px 3px 0 #5a3b12;
}

.subtitle {
  margin: -6px 0 0;
  color: var(--muted);
  font-size: 12px;
  text-align: center;
  text-transform: uppercase;
}

.selection-title {
  font-size: 38px;
}

.mode-selector {
  width: 100%;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  border: 2px solid #4b4b4b;
}

.mode-selector button {
  min-width: 0;
  min-height: 34px;
  border: 0;
  border-right: 1px solid #4b4b4b;
  background: #050505;
  color: #8e8e8e;
  cursor: pointer;
}

.mode-selector button:last-child {
  border-right: 0;
}

.mode-selector button.active {
  background: #f2f2f2;
  color: #050505;
}

.arena-physics-control {
  width: 100%;
  display: grid;
  gap: 10px;
  padding: 12px 0;
  border-block: 1px solid #303030;
}

.arena-physics-copy {
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.arena-physics-slider {
  position: relative;
  width: 100%;
  height: 52px;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  border: 1px solid #414141;
  background: #080808;
  transition: border-color 120ms steps(2);
}

.arena-physics-slider button {
  position: relative;
  z-index: 1;
  min-width: 0;
  padding: 0;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 8px;
  border: 0;
  background: transparent;
  color: #8e8e8e;
  font-size: 12px;
  letter-spacing: 0;
  white-space: nowrap;
  cursor: pointer;
}

.arena-physics-slider button[aria-checked="true"] {
  color: #050505;
}

.control-icon {
  width: 18px;
  height: 18px;
  flex: 0 0 18px;
  filter: invert(1);
  pointer-events: none;
}

.arena-physics-slider button[aria-checked="true"] .control-icon {
  filter: none;
}

.arena-physics-slider button:disabled {
  color: #383838;
  cursor: not-allowed;
}

.arena-physics-slider button:focus-visible {
  outline: 2px solid var(--yellow);
  outline-offset: -3px;
}

.arena-physics-thumb {
  position: absolute;
  top: 2px;
  left: 2px;
  width: calc((100% - 4px) / 3);
  height: calc(100% - 4px);
  background: #e2e2e2;
  transition: transform 120ms steps(2), background 120ms steps(2);
}

.arena-physics-slider[data-physics="bounce"] {
  border-color: var(--blue);
}

.arena-physics-slider[data-physics="bounce"] .arena-physics-thumb {
  background: #73baff;
  transform: translateX(100%);
}

.arena-physics-slider[data-physics="gyro"] {
  border-color: var(--yellow);
}

.arena-physics-slider[data-physics="gyro"] .arena-physics-thumb {
  background: #f0d45c;
  transform: translateX(200%);
}

.arena-physics-control.is-disabled {
  opacity: 0.55;
}

.mode-toggle {
  min-height: 52px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 0;
  cursor: pointer;
}

.mode-toggle-copy {
  min-width: 0;
  display: grid;
  gap: 3px;
}

.mode-toggle-title {
  color: #f2f2f2;
  font-size: 12px;
  letter-spacing: 0;
}

.mode-toggle-hint {
  color: #aaa;
  font-size: 10px;
  line-height: 1.4;
}

.mode-toggle-input {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
}

.mode-toggle-track {
  flex: 0 0 auto;
  width: 42px;
  height: 22px;
  position: relative;
  border: 2px solid #555;
  background: #111;
  transition: border-color 120ms steps(2), background 120ms steps(2);
}

.mode-toggle-thumb {
  width: 14px;
  height: 14px;
  position: absolute;
  top: 2px;
  left: 2px;
  background: #777;
  transition: transform 120ms steps(2), background 120ms steps(2);
}

.mode-toggle-input:checked + .mode-toggle-track {
  border-color: var(--blue);
  background: #06184a;
}

.mode-toggle-input:checked + .mode-toggle-track .mode-toggle-thumb {
  background: var(--blue);
  transform: translateX(18px);
}

.mode-toggle-input:focus-visible + .mode-toggle-track {
  outline: 2px solid var(--yellow);
  outline-offset: 2px;
}

.start-row {
  width: 100%;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 12px;
}

.watermark-control {
  display: flex;
  align-items: center;
  gap: 8px;
}

.offline-render-options {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 12px;
  color: #aaa;
  font-size: 12px;
}

.offline-render-options select,
.offline-render-options input {
  min-height: 28px;
  width: 86px;
  border: 1px solid #777;
  color: #eee;
  background: #101010;
}

#offlineRenderAcceleration {
  width: 144px;
}

.offline-render-status {
  width: 100%;
  text-align: center;
  color: #ccc;
  font-size: 12px;
  overflow-wrap: anywhere;
}

.watermark-caption {
  color: #aaa;
  font-size: 10px;
  white-space: nowrap;
}

.watermark-slider {
  position: relative;
  width: 156px;
  height: 42px;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  border: 1px solid #414141;
  background: #080808;
}

.watermark-slider button {
  position: relative;
  z-index: 1;
  min-width: 0;
  padding: 0;
  border: 0;
  background: transparent;
  color: #8e8e8e;
  font-size: 11px;
  letter-spacing: 0;
  white-space: nowrap;
  cursor: pointer;
}

.watermark-slider button[aria-checked="true"] {
  color: #050505;
}

.watermark-slider button:disabled {
  color: #383838;
  cursor: not-allowed;
}

.watermark-slider button:focus-visible {
  outline: 2px solid var(--yellow);
  outline-offset: -3px;
}

.watermark-thumb {
  position: absolute;
  top: 2px;
  left: 2px;
  width: calc((100% - 4px) / 3);
  height: calc(100% - 4px);
  background: #e2e2e2;
  transition: transform 120ms steps(2), background 120ms steps(2);
}

.watermark-slider[data-watermark="drift"] {
  border-color: var(--blue);
}

.watermark-slider[data-watermark="drift"] .watermark-thumb {
  background: #73baff;
  transform: translateX(100%);
}

.watermark-slider[data-watermark="tile"] {
  border-color: var(--gold);
}

.watermark-slider[data-watermark="tile"] .watermark-thumb {
  background: #f0d45c;
  transform: translateX(200%);
}

.mode-selector button.mode-incompatible,
.mode-selector button:disabled {
  color: #383838;
  background: #030303;
  cursor: not-allowed;
  text-decoration: line-through;
}

.mode-selector button.mode-incompatible.active {
  color: #383838;
  background: #030303;
}

.mode-selector button:focus-visible,
.team-slot:focus-visible,
.slot-clear:focus-visible,
.count-button:focus-visible {
  outline: 2px solid var(--yellow);
  outline-offset: 2px;
}

.team-builder {
  width: 100%;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 28px minmax(0, 1fr);
  align-items: center;
  gap: 8px;
}

.team-column {
  min-width: 0;
}

.team-column-head {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  margin: 0 0 6px;
}

.team-column h3 {
  margin: 0;
  color: #a8a8a8;
  font-size: 11px;
  text-align: center;
}

/* 随机键：点一下整队重抽。自带几何，不复用 .count-button 的 28px 方块。 */
.team-random-button {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 6px;
  border: 1px solid #4b4b4b;
  background: #050505;
  color: #a5a5a5;
  font-size: 11px;
  line-height: 1.2;
  cursor: pointer;
}

.team-random-button .control-icon {
  width: 12px;
  height: 12px;
  flex: 0 0 12px;
}

.team-random-button:hover:not(:disabled) {
  border-color: var(--gold);
  color: var(--gold);
}

.team-random-button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.team-random-button:focus-visible {
  outline: 2px solid var(--yellow);
  outline-offset: 2px;
}

.builder-vs {
  color: var(--gold);
  font-weight: 700;
  text-align: center;
}

.team-slots {
  display: grid;
  gap: 6px;
}

.creator-selection .custom-battle-controls {
  display: grid;
  grid-template-columns: 1.3fr 1fr 1fr .8fr .8fr 1.4fr;
  gap: 8px;
  padding: 10px;
  margin-bottom: 12px;
  border: 1px solid #454037;
  background: #11100d;
}

.custom-battle-controls label,
.custom-team-entry label {
  display: grid;
  min-width: 0;
  gap: 4px;
  color: #aaa18d;
  font-size: 10px;
}

.custom-battle-controls input,
.custom-battle-controls select,
.custom-team-entry input {
  width: 100%;
  min-width: 0;
  box-sizing: border-box;
  height: 30px;
  padding: 4px 5px;
  border: 1px solid #4b4b4b;
  border-radius: 0;
  background: #050505;
  color: var(--fg);
  font: inherit;
  font-size: 12px;
}

.custom-team-entry {
  display: grid;
  grid-template-columns: minmax(70px, 1.5fr) repeat(3, minmax(46px, 1fr)) 24px;
  align-items: center;
  gap: 5px;
  padding: 7px;
  border: 1px solid #363636;
  background: #080808;
}

.creator-selection input.number-scrubber {
  appearance: textfield;
  -moz-appearance: textfield;
  cursor: ew-resize;
  font-variant-numeric: tabular-nums;
}
.creator-selection input.number-scrubber::-webkit-inner-spin-button,
.creator-selection input.number-scrubber::-webkit-outer-spin-button {
  appearance: none;
  margin: 0;
}
.creator-selection input.number-scrubber:focus { cursor: text; }
.creator-selection input.number-scrubber.is-scrubbing {
  cursor: ew-resize;
  border-color: var(--gold);
  background: #211c10;
  user-select: none;
}
.creator-selection input.number-scrubber:disabled { cursor: not-allowed; }

.custom-entry-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 11px;
}

.custom-team-target {
  min-height: 32px;
  border: 1px dashed #555;
  background: #0b0b0b;
  color: #aaa;
  cursor: pointer;
  font-size: 11px;
}

.custom-team-target.active {
  border-color: var(--gold);
  color: var(--gold);
}

.custom-team-entry.long-count { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) 24px; }
.custom-team-entry.long-count .custom-entry-name,
.custom-team-entry.long-count label:first-of-type { grid-column: 1 / -1; }
.canvas-shell.custom-arena canvas { border-color: transparent; box-shadow: none; }

.creator-selection .team-slots { max-height: 245px; overflow-y: auto; }
.selection-error { color: #ff8f75; font-size: 12px; }
.nvn-team-controls { display: flex; align-items: center; flex-wrap: wrap; gap: 10px; margin: 8px 0; }
.nvn-team-controls span { color: #999; font-size: 11px; }
.team-builder.multi-team-builder { grid-template-columns: repeat(auto-fit, minmax(min(100%, 290px), 1fr)); gap: 12px; }
.multi-team-builder .team-column { border: 1px solid #333; padding: 10px; background: #0b0b0b; }
.multi-team-builder .team-column-head h3 { margin-right: auto; }
#rigWinnerPicker { flex-wrap: wrap; }

@media (max-width: 1050px) {
  .creator-selection .custom-battle-controls { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .custom-team-entry { grid-template-columns: repeat(3, minmax(42px, 1fr)) 24px; }
  .custom-entry-name { grid-column: 1 / -1; }
}

@media (max-width: 650px) {
  .creator-selection .team-builder { grid-template-columns: minmax(0, 1fr); gap: 10px; }
  .creator-selection .builder-vs { display: none; }
  .creator-selection .team-slots { overflow-x: hidden; }
}

.team-slot-row {
  min-width: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 28px;
  gap: 4px;
}

.team-slot {
  min-width: 0;
  height: 50px;
  display: grid;
  grid-template-columns: 22px minmax(0, 1fr);
  align-items: center;
  gap: 7px;
  padding: 6px 8px;
  border: 2px solid #424242;
  background: #030303;
  color: #858585;
  cursor: pointer;
  text-align: left;
}

.team-slot.active {
  border-color: var(--yellow);
  color: var(--fg);
}

.team-slot.filled {
  color: var(--fg);
}

.slot-ball {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--slot-color, #333);
  box-shadow: 2px 0 var(--slot-color, #333), -2px 0 var(--slot-color, #333);
}

.slot-copy {
  min-width: 0;
  overflow: hidden;
  font-size: 11px;
  line-height: 1.2;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.slot-clear,
.count-button {
  border: 1px solid #4b4b4b;
  background: #050505;
  color: #a5a5a5;
  cursor: pointer;
}

.slot-clear:disabled,
.count-button:disabled {
  color: #333;
  cursor: not-allowed;
}

.boss-count-controls {
  display: flex;
  align-items: center;
  gap: 10px;
  color: #aaa;
  font-size: 11px;
}

.team-count-controls {
  width: 100%;
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 10px 18px;
  color: #aaa;
  font-size: 11px;
}

.team-count-group {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 30px;
}

.team-count-group > span,
.control-caption {
  color: #c5c5c5;
  font-size: 11px;
}

.coop-options {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 8px;
  color: #aaa;
  font-size: 11px;
}

.segmented-control {
  display: inline-flex;
  border: 1px solid #4b4b4b;
}

.segmented-control button {
  min-height: 28px;
  padding: 4px 8px;
  border: 0;
  border-right: 1px solid #4b4b4b;
  background: #050505;
  color: #888;
  cursor: pointer;
  font-size: 11px;
}

.segmented-control button:last-child {
  border-right: 0;
}

.segmented-control button.active,
.segmented-control button[aria-pressed="true"] {
  background: #f2f2f2;
  color: #050505;
}

.count-button {
  width: 28px;
  height: 28px;
  padding: 0;
  font-size: 18px;
}

.pixel-button {
  min-width: 128px;
  min-height: 42px;
  padding: 10px 18px;
  border: 2px solid var(--fg);
  border-radius: 0;
  background: #050505;
  color: var(--fg);
  cursor: pointer;
  text-align: center;
  text-transform: uppercase;
  box-shadow: 4px 4px 0 #3d3d3d;
  transition: transform 90ms steps(1), box-shadow 90ms steps(1), background 90ms steps(1);
}

.pixel-button:hover:not(:disabled),
.pixel-button:focus-visible:not(:disabled) {
  background: var(--fg);
  color: var(--bg);
  outline: none;
  transform: translate(2px, 2px);
  box-shadow: 2px 2px 0 #3d3d3d;
}

.pixel-button:disabled {
  color: #515151;
  border-color: #515151;
  cursor: not-allowed;
  box-shadow: 4px 4px 0 #171717;
}

.select-grid {
  width: 100%;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.ball-search-panel {
  width: 100%;
  display: grid;
  gap: 8px;
  text-align: left;
}

#ballSearch {
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  border: 2px solid #555;
  border-radius: 0;
  background: var(--panel);
  color: var(--fg);
  font: inherit;
}

#ballSearch:focus-visible {
  outline: 2px solid var(--gold, #ffd700);
  outline-offset: 2px;
}

#ballSearchStatus {
  margin: 0;
  font-size: 12px;
}

#ballSearchStatus:empty {
  display: none;
}

.ball-card {
  position: relative;
  min-height: 136px;
  display: grid;
  justify-items: center;
  align-content: center;
  gap: 8px;
  padding: 12px 8px;
  border: 2px solid #555;
  background: var(--panel);
  color: var(--fg);
  cursor: pointer;
  text-align: center;
  box-shadow: inset 0 0 0 2px #000;
}

.ball-card.blank-selection-card > * {
  visibility: hidden;
}

.ball-card.selected {
  border-color: var(--fg);
  box-shadow: inset 0 0 0 2px #000, 0 0 0 2px #2a2a2a;
}

.ball-card .ball-preview {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--ball-color);
  image-rendering: pixelated;
  box-shadow:
    4px 0 0 var(--ball-color),
    -4px 0 0 var(--ball-color),
    0 4px 0 var(--ball-color),
    0 -4px 0 var(--ball-color);
}

.ball-card .name {
  min-height: 32px;
  display: grid;
  place-items: center;
  color: var(--ball-color);
  font-weight: 700;
  line-height: 1.05;
  text-transform: uppercase;
}

.ball-card .meta {
  color: #aaa;
  font-size: 11px;
  line-height: 1.25;
}

.vs-title {
  width: 100%;
  min-height: 36px;
  display: flex;
  align-items: end;
  justify-content: center;
  gap: 10px;
  margin: 0;
  color: var(--fg);
  font-family: "Fusion Pixel 12 SC", "Microsoft YaHei", sans-serif;
  font-size: clamp(20px, 8vw, 32px);
  font-weight: 400;
  line-height: 1;
  text-align: center;
  text-transform: uppercase;
  text-shadow:
    2px 0 0 #222,
    0 2px 0 #222,
    2px 2px 0 #222;
}

.vs-title span {
  min-width: 0;
  overflow-wrap: anywhere;
}

.battle-wrap {
  display: grid;
  justify-items: center;
  gap: 12px;
}

.canvas-shell {
  position: relative;
  width: var(--arena-size);
  height: var(--arena-size);
  background: #000;
}

.canvas-shell.boss-arena {
  --arena-size: min(300px, calc(100vmin - 40px));
}

.canvas-shell.zombie-arena {
  --arena-size: min(400px, calc(100vmin - 40px));
}

.canvas-shell.hell-arena {
  --arena-size: min(400px, calc(100vmin - 40px));
}

body.creator-battle .app {
  width: 100%;
  min-height: calc(100dvh - 36px);
}

.creator-battle .battle-wrap {
  width: 100%;
}

.creator-battle .canvas-shell {
  width: min(calc(100vw - 40px), calc(max(160px, 100dvh - 210px) * var(--arena-ratio, 1)));
  height: auto;
  aspect-ratio: var(--arena-ratio, 1);
  overflow: hidden;
}

.creator-battle .canvas-shell canvas {
  position: absolute;
  left: 50%;
  top: 50%;
  width: var(--canvas-width, 100%);
  height: var(--canvas-height, 100%);
  max-width: none;
  transform: translate(-50%, -50%);
}

.creator-battle .vs-title {
  font-size: 32px;
  line-height: 1.2;
}

.player-watermark {
  position: absolute;
  inset: 0;
  z-index: 1;
  overflow: hidden;
  pointer-events: none;
  user-select: none;
}

.player-watermark-grid {
  position: absolute;
  inset: -20%;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  grid-auto-rows: 1fr;
  place-items: center;
  color: #fff;
  font-family: "Fusion Pixel 12 SC", "Courier New", monospace;
  font-size: max(10px, calc(var(--arena-size) * 0.06));
  letter-spacing: 0.02em;
  white-space: nowrap;
  opacity: 0.1;
  transform: rotate(-22deg) scale(1.15);
  transform-origin: center;
  animation: player-watermark-drift 15s linear infinite;
  will-change: transform, opacity;
}

.player-watermark-grid span {
  display: block;
  text-shadow: 0 1px 0 rgba(0, 0, 0, 0.35);
}

@keyframes player-watermark-drift {
  0% {
    transform: rotate(-22deg) scale(1.15) translate(0, 0);
    opacity: 0.08;
  }

  40% {
    opacity: 0.15;
  }

  70% {
    opacity: 0.11;
  }

  100% {
    transform: rotate(-22deg) scale(1.15) translate(4%, -3%);
    opacity: 0.08;
  }
}

canvas {
  width: 100%;
  height: 100%;
  display: block;
  border: 1px solid var(--fg);
  background: #000;
  image-rendering: auto;
}

.battle-state {
  min-height: 18px;
  color: #aaa;
  font-size: 12px;
  text-align: center;
  text-transform: uppercase;
}

.orb-farm-status {
  width: min(100%, 420px);
  min-height: 18px;
  color: #8fd0ff;
  font-size: 12px;
  text-align: center;
  letter-spacing: 0.04em;
}

.rig-panel {
  width: 100%;
  display: grid;
  gap: 10px;
  padding-bottom: 12px;
  border-bottom: 1px solid #303030;
}

/* Creator controls are opt-in on the desktop/web host; mobile keeps its panel. */
.rig-panel:not(.creator-rig) .rig-creator-only { display: none; }
.creator-rig .rig-creator-only { display: grid; }
.creator-rig {
  border: 1px solid #454039;
  border-top: 3px solid var(--gold);
  padding: 12px;
  background: var(--panel);
  box-shadow: 3px 3px 0 #1b1813;
  font-family: "Fusion Pixel 12 SC", "Consolas", monospace;
}
.creator-rig .mode-toggle { min-height: 36px; padding: 0 0 4px; }
.creator-rig .mode-toggle-title { color: var(--gold); }
.creator-rig .rig-controls { gap: 10px; }
.rig-filters { grid-column: 1 / -1; min-width: 0; }
.creator-rig .rig-filters > summary {
  display: list-item;
  padding: 8px;
  border: 1px solid #37332c;
  color: var(--gold);
  cursor: pointer;
  font-size: 12px;
}
.creator-rig .rig-filters > summary:focus-visible { outline: 1px solid var(--gold); outline-offset: 2px; }
#rigFilterSummary { margin-left: 6px; color: #aaa; font-size: 10px; line-height: 1.6; }
.creator-rig .rig-filter-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; margin-top: 10px; }
.creator-rig .rig-filter-grid > .rig-hp-filter { grid-column: auto; padding: 6px 8px; gap: 0 6px; }
.creator-rig .rig-filter-grid > .rig-drama-filter { grid-column: 1 / -1; }
.creator-rig .rig-filter-grid legend output { display: block; margin: 2px 0 0; font-size: 11px; }
.creator-rig .rig-filter-grid p { font-size: 10px; }
.creator-rig .rig-dual-filter > label {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
}
.creator-rig .rig-dual-range {
  position: relative;
  grid-column: 1 / -1;
  height: 30px;
  margin: 4px 0;
  --range-start: 0%;
  --range-end: 100%;
}
.creator-rig .rig-dual-range::before {
  content: "";
  position: absolute;
  inset: 13px 5px auto;
  height: 4px;
  background: linear-gradient(to right, #37332c var(--range-start), var(--gold) var(--range-start), var(--gold) var(--range-end), #37332c var(--range-end));
}
.creator-rig .rig-dual-range input[type="range"] {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 30px;
  margin: 0;
  pointer-events: none;
}
.creator-rig .rig-dual-range input::-webkit-slider-runnable-track { background: transparent; }
.creator-rig .rig-dual-range input::-moz-range-track { background: transparent; }
.creator-rig .rig-dual-range input::-webkit-slider-thumb { pointer-events: auto; }
.creator-rig .rig-dual-range input::-moz-range-thumb { pointer-events: auto; }
.creator-rig .rig-dual-range input:focus-visible { outline: none; z-index: 4 !important; }
.creator-rig .rig-dual-range input:focus-visible::-webkit-slider-thumb { outline: 2px solid #fff; outline-offset: 2px; }
.creator-rig .rig-dual-range input:focus-visible::-moz-range-thumb { outline: 2px solid #fff; outline-offset: 2px; }
.creator-rig #rigSearchMode { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); grid-column: 1 / -1; margin-top: 6px; }
.creator-rig #rigWinnerPicker { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.creator-rig #rigWinnerPicker button { padding-inline: 4px; font-size: 12px; }
.creator-rig .rig-hp-filter {
  border-color: #37332c;
  background: #0c0c0b;
  padding: 8px 10px;
  gap: 2px 10px;
}
.creator-rig .rig-hp-filter legend { color: #eee; }
.creator-rig .rig-hp-filter output { color: var(--gold); }
.creator-rig .rig-hp-filter input[type="range"] {
  appearance: none;
  height: 26px;
  background: transparent;
  cursor: pointer;
}
.creator-rig input[type="range"]::-webkit-slider-runnable-track { height: 4px; background: #484239; }
.creator-rig input[type="range"]::-webkit-slider-thumb {
  appearance: none;
  width: 10px;
  height: 14px;
  margin-top: -5px;
  border: 1px solid #fff0cf;
  border-radius: 0;
  background: var(--gold);
  box-shadow: 2px 2px 0 #000;
}
.creator-rig input[type="range"]::-moz-range-track { height: 4px; background: #484239; }
.creator-rig input[type="range"]::-moz-range-thumb {
  width: 8px; height: 12px; border: 1px solid #fff0cf; border-radius: 0; background: var(--gold);
}
.creator-rig input:disabled { opacity: 0.4; cursor: not-allowed; }
.rig-score-help { grid-column: 1 / -1; color: #b4a58b; font-size: 11px; line-height: 1.6; }
.rig-gpu-options { grid-column: 1 / -1; gap: 5px; font-size: 12px; }
.rig-gpu-options label { display: flex; align-items: center; gap: 7px; cursor: pointer; }
.rig-gpu-options input { margin: 0; accent-color: var(--gold); }
.rig-gpu-options p, .rig-gpu-status { margin: 0; color: #aaa; font-size: 10px; line-height: 1.6; }
.rig-gpu-status { grid-column: 1 / -1; overflow-wrap: anywhere; }
.rig-score-help summary { cursor: pointer; width: fit-content; }
.rig-score-help summary:focus-visible { outline: 1px solid var(--gold); outline-offset: 3px; }
.rig-statistics { grid-column: 1 / -1; gap: 5px; padding-top: 2px; font-size: 12px; }
.rig-statistics-heading, .rig-win-labels { display: flex; justify-content: space-between; gap: 8px; }
.rig-statistics-heading { color: #b6b1a8; }
#rigSampleCount { color: #888; }
.rig-win-labels { font-variant-numeric: tabular-nums; }
#rigLeftRate { color: #72acff; }
#rigRightRate { color: #ff8585; }
.rig-win-bar { display: flex; height: 8px; background: #303030; overflow: hidden; }
#rigLeftBar { background: #5299ff; }
#rigOtherBar { background: #494949; }
#rigRightBar { background: #ef6868; }
.rig-statistics p { margin: 0; font-size: 11px; color: #aaa; line-height: 1.5; }
.creator-rig .rig-candidate { padding: 10px; border-color: #423e37; font-size: 12px; }
.creator-rig .rig-candidate.selected { border-color: var(--gold); background: #19150e; box-shadow: inset 3px 0 var(--gold); }
.creator-rig .rig-candidates {
  max-height: 220px;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: #766348 #141414;
}
.creator-rig .rig-candidate:not(.selected) .rig-candidate-team,
.creator-rig .rig-candidate:not(.selected) .rig-health-curve { display: none; }
.creator-rig .rig-candidate-heading { gap: 5px; }
.creator-rig .rig-candidate-duration { font-size: 11px; }
.rig-candidate-analysis { display: flex; justify-content: space-between; gap: 6px; align-items: baseline; }
.rig-candidate-analysis strong { color: var(--gold); font-weight: 400; }
.rig-candidate-analysis > span { color: #aaa; font-size: 10px; }
.creator-rig .rig-candidate-analysis { align-items: flex-start; }
.creator-rig .rig-candidate-analysis strong { flex-shrink: 0; white-space: nowrap; }
.creator-rig .rig-candidate-analysis > span { text-align: right; line-height: 1.5; word-break: keep-all; font-variant-numeric: tabular-nums; }
.rig-health-curve {
  display: block;
  width: 100%;
  height: 64px;
  border-bottom: 1px solid #36332f;
  background: repeating-linear-gradient(to top, transparent 0 19px, #222 19px 20px);
}
.rig-health-curve polyline { fill: none; stroke-width: 1.5; stroke-linejoin: round; }
.rig-curve-left { stroke: #72acff; }
.rig-curve-right { stroke: #ff8585; }

.rig-controls {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
}

#rigWinnerPicker {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.rig-hp-filter {
  grid-column: 1 / -1;
  min-width: 0;
  margin: 0;
  padding: 10px 12px;
  border: 1px solid #383838;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 6px 12px;
  font-size: 12px;
}
.rig-hp-filter legend { padding: 0 5px; }
.rig-hp-filter output { color: #f0d45c; margin-left: 8px; }
.rig-hp-filter input { width: 100%; min-width: 0; min-height: 28px; margin: 0; accent-color: #f0d45c; }
.rig-hp-filter input:focus-visible { outline: 2px solid #f0d45c; outline-offset: 2px; }
.rig-hp-filter p { grid-column: 1 / -1; margin: 2px 0 0; color: #aaa; font-size: 11px; line-height: 1.5; }

#rigWinnerPicker button {
  min-width: 0;
  min-height: 44px;
  padding: 4px 8px;
  font-size: 12px;
}

#rigWinnerPicker button[aria-pressed="true"] {
  background: #eee;
  color: #080808;
}

.rig-controls .pixel-button {
  min-width: 96px;
  min-height: 44px;
  padding: 6px 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-size: 11px;
  box-shadow: 2px 2px 0 #3d3d3d;
  transition: transform 90ms steps(1), box-shadow 90ms steps(1);
}

.rig-controls .pixel-button:hover .control-icon,
.rig-controls .pixel-button:focus-visible .control-icon {
  filter: none;
}

.rig-controls .is-searching {
  border-color: #f0d45c;
  color: #f0d45c;
}

.rig-controls .pixel-button:hover:not(:disabled),
.rig-controls .pixel-button:focus-visible:not(:disabled) {
  box-shadow: 1px 1px 0 #3d3d3d;
}

.rig-status {
  color: #8fd0ff;
  font-size: 11px;
  line-height: 1.6;
  text-align: left;
  letter-spacing: 0;
  overflow-wrap: anywhere;
}

.rig-progress {
  display: block;
  appearance: none;
  width: 100%;
  height: 3px;
  border: 0;
  background: #252525;
  color: #f0d45c;
}

.rig-progress::-webkit-progress-bar { background: #252525; }
.rig-progress::-webkit-progress-value { background: #f0d45c; }
.rig-progress::-moz-progress-bar { background: #f0d45c; }

.rig-candidates {
  display: grid;
  gap: 6px;
  min-width: 0;
}

.rig-candidates:empty {
  padding-bottom: 0;
}

.rig-candidate {
  display: grid;
  gap: 6px;
  min-width: 0;
  width: 100%;
  padding: 10px;
  border: 1px solid #4b4b4b;
  border-radius: 0;
  background: #050505;
  color: #c5c5c5;
  cursor: pointer;
  font-size: 11px;
  line-height: 1.4;
  text-align: left;
}

.rig-candidate:hover,
.rig-candidate:focus-visible {
  border-color: var(--gold);
  color: #f2f2f2;
  outline: none;
}

.rig-candidate.selected {
  border-color: var(--gold);
  background: #141414;
  color: var(--gold);
}

.rig-candidate-heading {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto 18px;
  align-items: center;
  gap: 8px;
  color: #f0d45c;
  font-variant-numeric: tabular-nums;
}

.rig-candidate-duration { color: #ddd; }
.rig-candidate-check { visibility: hidden; }
.rig-candidate.selected .rig-candidate-check { visibility: visible; }

.rig-candidate-team {
  display: grid;
  grid-template-columns: 30px minmax(0, 1fr);
  align-items: baseline;
  gap: 8px;
  min-width: 0;
  color: #888;
}

.rig-candidate-balls {
  display: flex;
  flex-wrap: wrap;
  gap: 3px 12px;
  overflow-wrap: anywhere;
  min-width: 0;
}

.rig-candidate-team.winner { color: #e3e3e3; }
.rig-candidate-team.winner .rig-candidate-side { color: #83d9ad; }
.rig-candidate:disabled { cursor: wait; }

@media (prefers-reduced-motion: reduce) {
  .arena-physics-thumb, .mode-toggle-thumb { transition: none; }
}

.mode-status {
  width: min(100%, 420px);
  display: grid;
  gap: 6px;
  color: #bdbdbd;
  font-size: 10px;
  text-align: center;
}

.mode-status-teams {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.mode-status-team {
  min-width: 0;
  padding: 4px 5px;
  border: 1px solid #3d3d3d;
  background: #050505;
}

.mode-status-team[data-team-role="player"],
.mode-status-team[data-team-id="left"] {
  --team-accent: #4d8dff;
}

.mode-status-team[data-team-role="enemy"],
.mode-status-team[data-team-id="right"] {
  --team-accent: #ff4d5a;
}

.mode-status-team-title {
  display: block;
  margin-bottom: 3px;
  color: #eee;
}

.mode-status-slots {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 4px;
}

.mode-status-slot,
.coop-switch-button {
  min-width: 0;
  min-height: 30px;
  padding: 3px 5px;
  border: 1px solid #555;
  background: #111;
  color: #aaa;
  font-size: 10px;
  cursor: pointer;
}

.mode-status-slot {
  display: grid;
  grid-template-columns: 16px minmax(0, 1fr) 16px;
  grid-template-rows: auto 3px;
  align-items: center;
  gap: 2px 4px;
  width: 100%;
  text-align: left;
}

.mode-status-slot-index {
  color: #888;
  font-weight: 700;
  text-align: center;
}

.mode-status-slot-copy,
.coop-switch-copy {
  min-width: 0;
  display: grid;
  gap: 1px;
}

.mode-status-slot-name,
.coop-switch-name {
  min-width: 0;
  overflow: hidden;
  color: #ddd;
  font-size: 10px;
  font-weight: 400;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.mode-status-slot-hp,
.coop-switch-hp {
  color: #888;
  font-size: 9px;
  line-height: 1;
}

.mode-status-slot-mark {
  color: #5ecb78;
  font-size: 11px;
  font-weight: 700;
  text-align: center;
}

.mode-status-slot-bar {
  grid-column: 2 / -1;
  height: 3px;
  overflow: hidden;
  background: #292929;
}

.mode-status-slot-fill {
  display: block;
  height: 100%;
  background: var(--slot-color, #aaa);
}

.mode-status-slot.active,
.coop-switch-button.active {
  border-color: var(--team-accent, var(--yellow));
  color: #fff;
  box-shadow: 2px 2px 0 #222;
}

.mode-status-slot.defeated {
  border-color: #4a2528;
  background: #0b0808;
  opacity: 0.72;
}

.mode-status-slot.defeated .mode-status-slot-name,
.mode-status-slot.defeated .mode-status-slot-hp,
.mode-status-slot.defeated .mode-status-slot-index {
  color: #666;
  text-decoration: line-through;
}

.mode-status-slot.defeated .mode-status-slot-mark {
  color: #ff4d5a;
  font-size: 15px;
  text-decoration: none;
}

.coop-switch-controls {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 5px;
}

.coop-switch-heading {
  width: 100%;
  color: #d4a55a;
  font-size: 10px;
  text-align: left;
}

.coop-switch-button {
  display: grid;
  grid-template-columns: 18px minmax(0, 1fr);
  align-items: center;
  gap: 5px;
  border-left: 4px solid var(--slot-color, #777);
  text-align: left;
}

.coop-switch-index {
  color: #aaa;
  font-size: 12px;
  font-weight: 700;
  text-align: center;
}

.coop-switch-button:disabled {
  color: #444;
  cursor: not-allowed;
}

.actions {
  min-height: 46px;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 12px;
}

.hidden {
  display: none !important;
}

/* The creator selection page can use a wide viewport; menu/battle and the
   mobile host retain their own sizing. Media queries also follow page zoom. */
.creator-selection .selection-workspace,
.creator-selection .selection-main { display: contents; }
.creator-selection .selection-main > * { order: 4; }
.creator-selection #modeSelector { order: 1; }
.creator-selection #arenaPhysicsControl { order: 2; }
.creator-selection #rigPanel { order: 3; }

@media (min-width: 880px) {
  .creator-app:has(#selectScreen.active) { width: min(100%, 1360px); }
  .creator-selection .selection-workspace {
    display: grid;
    width: 100%;
    grid-template-columns: minmax(0, 1fr) clamp(340px, 34vw, 440px);
    align-items: start;
    gap: 24px;
  }
  .creator-selection .selection-main {
    display: grid;
    min-width: 0;
    gap: 14px;
    justify-items: center;
    align-content: start;
  }
  .creator-selection .selection-main > * { order: initial; }
  .creator-selection #modeSelector,
  .creator-selection #arenaPhysicsControl { order: initial; }
  .creator-selection #rigPanel {
    order: initial;
    position: sticky;
    top: 18px;
    max-height: calc(100dvh - 36px);
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: #766348 #141414;
  }
  .creator-selection .mode-selector { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .creator-selection .arena-physics-control { gap: 6px; padding-block: 8px; }
  .creator-selection .arena-physics-slider { height: 40px; }
  .creator-selection .select-grid {
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    grid-auto-rows: max-content;
    max-height: clamp(240px, 48dvh, 560px);
    overflow-y: auto;
    align-content: start;
    padding: 3px;
    scrollbar-width: thin;
    scrollbar-color: #555 #111;
  }
  .creator-selection .ball-card { align-content: start; }
  .creator-selection .rig-candidates { max-height: clamp(220px, 40dvh, 440px); }
}

@media (max-width: 360px) {
  body {
    padding: 12px;
  }

  .app {
    min-height: 520px;
  }

  .select-grid {
    grid-template-columns: 1fr;
  }

  .team-builder {
    grid-template-columns: minmax(0, 1fr) 22px minmax(0, 1fr);
    gap: 4px;
  }

  .team-slot-row {
    grid-template-columns: minmax(0, 1fr) 24px;
  }
}

.tournament-panel { margin: 14px 0; min-width: 0; }
.tournament-panel.hidden { display: none; }
.tournament-bracket-layout { display: grid; grid-template-columns: 32px minmax(0, 1fr); gap: 10px; align-items: start; }
.tournament-bracket-layout > button { margin-top: 8px; width: 32px; height: 32px; padding: 6px; }
.tournament-tree { display: grid; gap: 10px; min-width: 0; }
.tournament-initial { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
.tournament-semifinals, .tournament-finalists { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.tournament-entrant, .tournament-winner, .tournament-champion { padding: 8px; border-bottom: 2px solid var(--entrant-color, #666); text-align: center; overflow-wrap: anywhere; font-size: 12px; }
.tournament-match { min-width: 0; min-height: 74px; display: flex; flex-direction: column; gap: 6px; padding: 10px; background: #151515; color: #eee; border: 1px solid #555; border-radius: 4px; text-align: left; cursor: pointer; overflow-wrap: anywhere; }
.tournament-match.active { border-color: #62d6b4; background: #162722; }
.tournament-match:disabled { opacity: .45; cursor: default; }
.tournament-match strong { font-size: 12px; }
.tournament-match small { color: #aaa; }
.tournament-tree > .tournament-match, .tournament-champion { width: 60%; justify-self: center; }
.tournament-active .team-builder { grid-template-columns: repeat(2, minmax(0, 1fr)); }
@media (max-width: 520px) {
  .tournament-active .team-builder { grid-template-columns: minmax(0, 1fr); }
  .tournament-initial { gap: 4px; }
  .tournament-entrant { padding: 6px 2px; }
  .tournament-bracket-layout { gap: 6px; }
}
