@font-face {
  /* Anton is an OFL-licensed Impact-like face bundled for offline Android use. */
  font-family: "Ball Impact";
  src: url("../src/assets/fonts/anton-regular.ttf") format("truetype");
  font-style: normal;
  font-weight: 400;
  font-display: block;
}

@font-face {
  font-family: "Ball Impact";
  src: url("../src/assets/fonts/anton-regular.ttf") format("truetype");
  font-style: normal;
  font-weight: 700;
  font-display: block;
}

:root {
  --mobile-safe-top: var(--safe-area-inset-top, env(safe-area-inset-top, 0px));
  --mobile-safe-right: var(--safe-area-inset-right, env(safe-area-inset-right, 0px));
  --mobile-safe-bottom: var(--safe-area-inset-bottom, env(safe-area-inset-bottom, 0px));
  --mobile-safe-left: var(--safe-area-inset-left, env(safe-area-inset-left, 0px));
}

html,
body {
  min-height: 100%;
  overscroll-behavior: none;
}

body {
  /* 12px / 100vh fallbacks keep the layout sane on WebViews older than
     Chromium 79 (no min()/max()) and 108 (no dvh), such as an un-updated
     Xiaomi Mi 9 on Android 9. */
  min-height: 100vh;
  min-height: 100dvh;
  padding: 12px;
  padding:
    max(12px, var(--mobile-safe-top))
    max(12px, var(--mobile-safe-right))
    max(12px, var(--mobile-safe-bottom))
    max(12px, var(--mobile-safe-left));
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
}

.app {
  width: 100%;
  max-width: 480px;
  width: min(100%, 480px);
  min-height: calc(100vh - 24px - var(--mobile-safe-top) - var(--mobile-safe-bottom));
  min-height: calc(
    100dvh - 24px - var(--mobile-safe-top) - var(--mobile-safe-bottom)
  );
}

button,
.ball-card,
.team-slot {
  min-height: 44px;
}

.mode-selector {
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 1px;
  border: 1px solid #4b4b4b;
  background: #4b4b4b;
}

.mode-selector button {
  min-height: 46px;
  border-right: 0;
}

.team-slot-row {
  grid-template-columns: minmax(0, 1fr) 44px;
}

.slot-clear,
.count-button {
  width: 44px;
  min-height: 44px;
}

.select-grid {
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
}

.ball-card {
  min-width: 0;
  min-height: 80px;
  padding: 8px 4px;
  gap: 6px;
}

.ball-card[hidden] {
  display: none;
}

.ball-card .ball-preview {
  width: 24px;
  height: 24px;
  box-shadow:
    3px 0 0 var(--ball-color),
    -3px 0 0 var(--ball-color),
    0 3px 0 var(--ball-color),
    0 -3px 0 var(--ball-color);
}

.ball-card .name {
  width: 100%;
  min-height: 28px;
  max-height: 28px;
  display: -webkit-box;
  overflow: hidden;
  font-size: 11px;
  line-height: 1.25;
  overflow-wrap: anywhere;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.ball-card .meta {
  display: none;
}

.mobile-selection-panel {
  position: sticky;
  top: 8px;
  top: max(8px, var(--mobile-safe-top));
  z-index: 4;
  width: 100%;
  display: grid;
  gap: 8px;
  padding: 8px;
  border: 2px solid #4b4b4b;
  background: #050505;
  box-shadow: 0 4px 0 #000;
}

.mobile-ball-search-row {
  min-width: 0;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 8px;
}

.mobile-ball-search-label {
  color: #aaa;
  font-size: 11px;
}

.mobile-ball-search {
  min-width: 0;
  min-height: 44px;
  padding: 8px 10px;
  border: 2px solid #555;
  border-radius: 0;
  outline: 0;
  background: #000;
  color: #fff;
  font: inherit;
  font-size: 12px;
}

.mobile-ball-search:focus {
  border-color: var(--yellow);
}

.mobile-ball-search::placeholder {
  color: #707070;
  opacity: 1;
}

.mobile-roster-filter {
  min-width: 0;
  max-width: 94px;
  height: 44px;
  border: 1px solid #555;
  border-radius: 0;
  background: #000;
  color: #ddd;
  font: inherit;
  font-size: 11px;
}
.mobile-ball-search-row { grid-template-columns: auto minmax(0, 1fr) auto; }
.manual-select-screen .mobile-ball-search-row { grid-template-columns: minmax(0, 1fr) auto; }
.mobile-roster-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 32px;
  gap: 4px;
  width: 100%;
  align-items: start;
}
.mobile-alphabet {
  position: sticky;
  top: 270px;
  display: flex;
  flex-direction: column;
  max-height: calc(100vh - 285px);
  overflow-y: auto;
  border: 1px solid #383838;
  background: #080808;
}
.mobile-alphabet button {
  flex: 0 0 26px;
  min-height: 26px;
  width: 30px;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--yellow);
  font: bold 13px monospace;
}
.mobile-alphabet button:active { background: #444; }
.manual-hint { color: #aaa; font-size: 11px; line-height: 1.7; }
.manual-opponent-detail {
  min-height: 64px;
  max-height: 88px;
  overflow-y: auto;
  white-space: pre-line;
  font-size: 11px;
  line-height: 1.7;
  color: #ccc;
}
.manual-controls {
  width: 100%;
  display: flex;
  justify-content: space-between;
  padding: 4px 14px 22px;
  user-select: none;
  -webkit-user-select: none;
}
.manual-controls[hidden] { display: none; }
.manual-stick {
  position: relative;
  width: 106px;
  height: 106px;
  border: 2px solid #555;
  border-radius: 50%;
  background: #101010;
  touch-action: none;
}
.manual-stick-knob {
  position: absolute;
  top: 33px;
  left: 33px;
  width: 36px;
  height: 36px;
  border: 2px solid #049381;
  border-radius: 50%;
  background: #1c3e37;
  pointer-events: none;
}
.manual-stick[data-stick="aim"] .manual-stick-knob { border-color: var(--yellow); background: #443d1a; }
.manual-stick-label {
  position: absolute;
  top: 112px;
  width: 100%;
  text-align: center;
  color: #aaa;
  font-size: 10px;
  pointer-events: none;
}
.manual-battle #mobileJudgeBtn { display: none; }
.manual-battle #battleActions { grid-template-columns: repeat(4, minmax(0, 1fr)); }

.mobile-ball-detail {
  min-width: 0;
  min-height: 142px;
  display: grid;
  grid-template-rows: auto auto 32px auto;
  gap: 6px;
  padding: 8px;
  border: 1px solid #383838;
  background: #000;
}

.mobile-ball-detail-header {
  min-width: 0;
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr) minmax(66px, auto);
  align-items: center;
  gap: 8px;
}

.mobile-ball-detail-swatch {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--detail-ball-color, #333);
  box-shadow:
    3px 0 0 var(--detail-ball-color, #333),
    -3px 0 0 var(--detail-ball-color, #333);
}

.mobile-ball-detail-identity {
  min-width: 0;
  display: grid;
  gap: 2px;
}

.mobile-ball-detail-name,
.mobile-ball-detail-english {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.mobile-ball-detail-name {
  color: var(--detail-ball-color, #fff);
  font-size: 14px;
}

.mobile-ball-detail-english {
  color: #8f8f8f;
  font-size: 10px;
}

.mobile-current-slot {
  min-width: 0;
  color: var(--yellow);
  font-size: 10px;
  line-height: 1.2;
  text-align: right;
  overflow-wrap: anywhere;
}

.mobile-ball-detail-stats {
  display: flex;
  gap: 14px;
  color: #d7d7d7;
  font-size: 10px;
}

.mobile-ball-detail-description {
  min-width: 0;
  height: 32px;
  display: -webkit-box;
  margin: 0;
  overflow: hidden;
  color: #aaa;
  font-size: 10px;
  line-height: 1.6;
  overflow-wrap: anywhere;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.mobile-selection-actions,
.mobile-selection-actions .pixel-button {
  width: 100%;
}

.mobile-empty-results {
  width: 100%;
  min-height: 80px;
  display: grid;
  place-items: center;
  margin: 0;
  border: 1px dashed #4b4b4b;
  color: #8f8f8f;
  font-size: 11px;
}
.mobile-empty-results[hidden] { display: none; }

@media (max-height: 600px) {
  .manual-battle #battleScreen { gap: 8px; }
  .manual-battle .vs-title { font-size: 20px; }
  .manual-battle .battle-wrap { gap: 6px; }
  .manual-battle .canvas-shell {
    --arena-size: 120px;
    --arena-size: min(100%, max(100px, calc(100vh - 230px)), 420px);
  }
  .manual-battle .manual-controls { max-width: 300px; padding: 2px 12px 20px; }
  .manual-battle .manual-stick { width: 64px; height: 64px; }
  .manual-battle .manual-stick-knob { top: 12px; left: 12px; }
  .manual-battle .manual-stick-label { top: 68px; }
}

#battleActions {
  width: 100%;
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 8px;
}

#fightStartBtn {
  width: 100%;
  grid-column: 1 / -1;
}

#restartBtn,
#backBtn {
  display: none !important;
}

.mobile-battle-control {
  min-width: 0;
  width: 100%;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  padding: 8px 4px;
  font-size: 11px;
}

.mobile-battle-control-icon {
  width: 14px;
  color: var(--yellow);
  font-size: 14px;
  line-height: 1;
}

.mobile-battle-control:hover:not(:disabled) .mobile-battle-control-icon,
.mobile-battle-control:focus-visible:not(:disabled) .mobile-battle-control-icon,
.mobile-battle-control:active:not(:disabled) .mobile-battle-control-icon {
  color: #000;
}

/* 不可用时整颗按钮（含黄色图标）一起变灰：直接判定有 90 秒锁定期，
   光靠 .pixel-button:disabled 的文字变灰还不够明显。 */
.mobile-battle-control:disabled .mobile-battle-control-icon {
  color: #515151;
}

.battle-wrap {
  width: 100%;
}

.mode-status {
  width: 100%;
  gap: 8px;
}

.mode-status-team {
  padding: 6px;
}

.mode-status-team-title {
  margin-bottom: 5px;
  font-size: 11px;
}

.mode-status-slot {
  min-height: 38px;
  padding: 4px 5px;
}

#coopSwitchControls {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 7px;
}

.coop-switch-heading {
  grid-column: 1 / -1;
}

.coop-switch-button {
  width: 100%;
  min-height: 48px;
  padding: 6px 8px;
}

.coop-switch-name {
  color: #fff;
  font-size: 11px;
}

.coop-switch-button.active .coop-switch-hp::after {
  content: " · 当前上场";
  color: var(--yellow);
}

/* 62vmin keeps the arena usable on engines without min()/max() (Chromium
   older than 79); the viewport formula takes over when supported. The
   WebView is fullscreen, so vh matches dvh there. */
.canvas-shell,
.canvas-shell.boss-arena,
.canvas-shell.zombie-arena,
.canvas-shell.hell-arena {
  --arena-size: 62vmin;
}

@supports (width: min(1px, 1px)) {
  .canvas-shell,
  .canvas-shell.boss-arena,
  .canvas-shell.zombie-arena,
  .canvas-shell.hell-arena {
    --arena-size: min(100%, max(180px, calc(100vh - 190px)), 420px);
  }
}

canvas {
  touch-action: none;
}

/* clamp() needs Chromium 79; the vw fallback keeps both titles readable on
   older system WebViews. */
.title {
  font-size: 12vw;
  font-size: clamp(34px, 12vw, 58px);
}

.vs-title {
  font-size: 8vw;
  font-size: clamp(20px, 8vw, 32px);
}

@media (hover: none) {
  .pixel-button:hover:not(:disabled) {
    background: #050505;
    color: var(--fg);
    transform: none;
    box-shadow: 4px 4px 0 #3d3d3d;
  }

  .rig-controls .pixel-button:hover:not(:disabled) .control-icon {
    filter: invert(1);
  }

  .rig-controls .pixel-button:active:not(:disabled) .control-icon {
    filter: none;
  }

  .pixel-button:active:not(:disabled) {
    background: var(--fg);
    color: var(--bg);
    transform: translate(2px, 2px);
    box-shadow: 2px 2px 0 #3d3d3d;
  }

  .mobile-battle-control:hover:not(:disabled) .mobile-battle-control-icon {
    color: var(--yellow);
  }

  .mobile-battle-control:active:not(:disabled) .mobile-battle-control-icon {
    color: #000;
  }
}

@media (max-width: 360px) {
  .team-slot-row {
    grid-template-columns: minmax(0, 1fr) 40px;
  }

  .slot-clear,
  .count-button {
    width: 40px;
  }

  .ball-card .name {
    font-size: 10px;
  }

  .mobile-ball-detail-header {
    grid-template-columns: 30px minmax(0, 1fr) minmax(58px, auto);
    gap: 6px;
  }
}

/* Tournament mode */

#tournamentMenuBtn {
  min-height: 42px;
}

.tournament-screen {
  align-content: start;
  justify-items: stretch;
  gap: 12px;
}

.tournament-header {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  width: 100%;
}

.tournament-back-button {
  min-width: 44px;
  min-height: 44px;
  padding: 8px 12px;
}

.tournament-title-wrap {
  min-width: 0;
  display: grid;
  gap: 2px;
}

.tournament-mode-picker {
  width: 100%;
  display: grid;
  gap: 8px;
  padding: 12px 0;
  border-block: 1px solid #383838;
}

.tournament-mode-picker-title {
  margin: 0;
  color: var(--fg);
  font-size: 13px;
}

.tournament-mode-picker-hint {
  margin: 0;
  color: #8f8f8f;
  font-size: 10px;
  line-height: 1.4;
}

.tournament-mode-options {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
}

.tournament-mode-option {
  min-width: 0;
  min-height: 78px;
  display: grid;
  align-content: center;
  justify-items: center;
  gap: 6px;
  padding: 8px 4px;
  border-color: #4b4b4b;
  text-align: center;
  box-shadow: none;
}

.tournament-mode-option-label {
  color: #ddd;
  font-size: 12px;
  font-weight: 400;
}

.tournament-mode-option-description {
  color: #888;
  font-size: 9px;
  line-height: 1.3;
  overflow-wrap: anywhere;
}

.tournament-mode-option.selected {
  border-color: var(--yellow);
  background: #151515;
  box-shadow: inset 0 -2px var(--yellow);
}

.tournament-mode-option.selected .tournament-mode-option-label {
  color: var(--yellow);
}

.tournament-mode-confirm {
  width: 100%;
  min-height: 44px;
}

.tournament-elite-filter {
  padding: 8px;
  border: 1px solid #4b4b4b;
  background: #0a0a0a;
}

.tournament-setup-group {
  display: grid;
  gap: 6px;
}

.tournament-setup-group-title {
  margin: 0;
  color: #bdbdbd;
  font-size: 11px;
  letter-spacing: 0;
  text-transform: uppercase;
}

.tournament-size-options {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.tournament-size-option {
  min-width: 0;
  min-height: 62px;
  display: grid;
  align-content: center;
  justify-items: start;
  gap: 4px;
  padding: 8px;
  border-color: #4b4b4b;
  text-align: left;
}

.tournament-size-option-label {
  color: #ddd;
  font-size: 12px;
}

.tournament-size-option-description {
  color: #888;
  font-size: 9px;
  line-height: 1.3;
}

.tournament-size-option.selected {
  border-color: var(--yellow);
  background: #171703;
  box-shadow: 2px 2px 0 #2b2b12;
}

.tournament-size-option.selected .tournament-size-option-label {
  color: var(--yellow);
}

.tournament-size-option:disabled {
  opacity: 0.4;
}

.tournament-title {
  margin: 0;
  color: var(--gold);
  font-size: 20px;
  line-height: 1;
  text-transform: uppercase;
  text-shadow:
    2px 0 0 #5a3b12,
    0 2px 0 #5a3b12,
    2px 2px 0 #5a3b12;
}

.tournament-round-status {
  margin: 0;
  color: #8f8f8f;
  font-size: 10px;
  line-height: 1.3;
  overflow-wrap: anywhere;
}

.tournament-champion {
  display: grid;
  justify-items: center;
  gap: 6px;
  padding: 10px;
  border: 2px solid var(--gold);
  background: #0a0703;
}

.tournament-champion-caption {
  color: var(--gold);
  font-size: 12px;
  letter-spacing: 4px;
  text-transform: uppercase;
}

.tournament-champion .tournament-chip {
  justify-self: center;
}

.tournament-champion .tournament-chip-name {
  color: var(--gold);
  font-size: 16px;
}

.tournament-rounds {
  width: 100%;
  display: grid;
  gap: 10px;
}

.tournament-round {
  min-width: 0;
  display: grid;
  gap: 4px;
  padding: 8px;
  border: 1px solid #383838;
  background: #050505;
}

.tournament-round-heading {
  margin: 0;
  color: #a8a8a8;
  font-size: 11px;
  text-transform: uppercase;
}

.tournament-round-heading.final-round {
  color: var(--gold);
}

.tournament-match {
  min-width: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 34px minmax(0, 1fr);
  align-items: center;
  gap: 4px;
  padding: 4px 6px;
  border: 1px solid #242424;
  background: #000;
}

.tournament-match.next {
  border-color: var(--yellow);
  box-shadow: 2px 2px 0 #2b2b12;
}

.tournament-chip {
  min-width: 0;
  display: grid;
  grid-template-columns: 14px minmax(0, 1fr);
  align-items: center;
  gap: 6px;
}

.tournament-team-chip {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

/* Mobile already provides its search, tier filter and alphabetical index. */
.ball-search-panel {
  display: none;
}

.tournament-mode-picker[hidden] {
  display: none;
}

.tournament-chip-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--chip-ball-color, #555);
  box-shadow:
    2px 0 var(--chip-ball-color, #555),
    -2px 0 var(--chip-ball-color, #555);
}

.tournament-chip-name {
  min-width: 0;
  overflow: hidden;
  color: #bdbdbd;
  font-size: 11px;
  line-height: 1.2;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tournament-chip.winner .tournament-chip-name {
  color: var(--fg);
  font-weight: 700;
}

.tournament-chip.defeated .tournament-chip-name {
  color: #5c5c5c;
  text-decoration: line-through;
}

.tournament-chip.champion .tournament-chip-name {
  color: var(--gold);
}

.tournament-match-versus {
  color: var(--gold);
  font-size: 10px;
  text-align: center;
}

.tournament-match.next .tournament-match-versus {
  color: var(--yellow);
}

.tournament-match-badge {
  display: none;
}

.tournament-footer {
  width: 100%;
  display: grid;
  gap: 8px;
}

.tournament-next-match {
  margin: 0;
  min-height: 14px;
  color: #bdbdbd;
  font-size: 11px;
  text-align: center;
  overflow-wrap: anywhere;
}

.tournament-primary-button,
.tournament-reset-button,
.tournament-mode-confirm {
  width: 100%;
  min-height: 44px;
}

.tournament-reset-button {
  box-shadow: none;
  border-color: #4b4b4b;
  color: #8f8f8f;
}

.tournament-reset-button:hover:not(:disabled),
.tournament-reset-button:focus-visible:not(:disabled) {
  background: #0a0a0a;
  color: var(--fg);
  outline: none;
  transform: none;
}

/* 做局面板：桌面那套 28px 分段控件在手机上点不准，抬到触控目标下限。 */
#rigPanel .rig-controls {
  align-items: stretch;
}

#rigPanel #rigWinnerPicker button,
#rigPanel #rigFarmBtn {
  min-height: 44px;
}

#rigPanel #rigWinnerPicker {
  flex: 1 1 auto;
}

#rigPanel #rigWinnerPicker button {
  flex: 1 1 0;
  min-width: 0;
}

#rigPanel #rigFarmBtn {
  flex: 0 0 auto;
  padding: 0 10px;
}

#rigPanel .rig-candidate {
  min-height: 44px;
  text-align: left;
  line-height: 1.35;
  padding: 8px 10px;
}
