.battle-tower-page {
  width: min(980px, 100%);
  margin: 0 auto;
}

.battle-tower-controls {
  width: min(900px, 100%);
  margin: 0 auto 10px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-areas:
    "level room"
    "honor zoom";
  align-items: center;
  row-gap: 8px;
}

.battle-control-level {
  grid-area: level;
  justify-self: start;
}

.battle-control-room {
  grid-area: room;
  justify-self: end;
}

.battle-honor-roll-label {
  grid-area: honor;
  justify-self: start;
  font-size: 8px;
  font-weight: 600;
  letter-spacing: 0;
}

.battle-control-zoom {
  grid-area: zoom;
  justify-self: end;
  width: 244px;
  max-width: 244px;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  column-gap: 12px;
  margin: 2px 0 4px;
}

.battle-tower-page .battle-zoom-label {
  font-size: 16px !important;
  line-height: 16px !important;
  white-space: nowrap;
}

.battle-zoom-buttons {
  width: auto;
  min-width: 0;
}

.battle-control-zoom .battle-zoom-btn {
  min-height: 32px !important;
  padding: 4px 0.75ch !important;
  font-size: 16px !important;
  line-height: 16px !important;
}

.battle-tower-controls .trade-region-filter {
  min-width: 244px;
}

.battle-table-shell {
  --bt-frame-left: 30px;
  --bt-frame-right: 37px;
  --bt-frame-top: 45px;
  --bt-frame-bottom: 48px;
  width: min(980px, 100%);
  margin: 0 auto;
  padding: var(--bt-frame-top) var(--bt-frame-right) var(--bt-frame-bottom) var(--bt-frame-left);
  box-sizing: border-box;
  position: relative;
  background: transparent;
  overflow: visible;
}

.battle-table-shell::before,
.battle-table-shell::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  pointer-events: none;
  image-rendering: pixelated;
  z-index: 3;
}

.battle-table-shell::before {
  top: 0;
  height: var(--bt-frame-top);
  background: url("/images/crystal/HonorRollBorderTop.png") no-repeat left top;
  background-size: 100% var(--bt-frame-top);
}

.battle-table-shell::after {
  bottom: 0;
  height: var(--bt-frame-bottom);
  background: url("/images/crystal/HonorRollBorderBottom.png") no-repeat left bottom;
  background-size: 100% var(--bt-frame-bottom);
}

/* The framed box now wraps the title + controls + table. The left/right
   frame borders and the white backdrop live on this wrapper so everything
   sits inside one honor-roll shell. */
.battle-table-inner {
  position: relative;
  background-color: #fff;
  z-index: 2;
  /* padding-top keeps the white backdrop flush under the top frame border
     (blocks the title's margin from collapsing out and exposing the wall). */
  padding-top: 6px;
}

.battle-table-grid {
  position: relative;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  gap: 20px;
  z-index: 2;
}

.battle-table-inner::before,
.battle-table-inner::after {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  pointer-events: none;
  image-rendering: pixelated;
  z-index: 1;
}

.battle-table-inner::before {
  left: calc(-1 * var(--bt-frame-left));
  width: var(--bt-frame-left);
  background: url("/images/crystal/HonorRollBorderLeft.png") no-repeat left top;
  background-size: var(--bt-frame-left) 100%;
}

.battle-table-inner::after {
  right: calc(-1 * var(--bt-frame-right));
  width: var(--bt-frame-right);
  background: url("/images/crystal/HonorRollBorderRight.png") no-repeat right top;
  background-size: var(--bt-frame-right) 100%;
}

.battle-table-panel {
  --battle-zoom-scale: 1;
  width: 440px;
  max-width: 440px;
  zoom: var(--battle-zoom-scale);
}

.battle-tower-page[data-battle-zoom="2"] .battle-table-panel {
  --battle-zoom-scale: 2;
}

.battle-tower-page[data-battle-zoom="2"] .battle-table-grid {
  display: grid;
  grid-template-columns: 1fr;
  justify-items: center;
  row-gap: 32px;
}

.battle-tower-page[data-battle-zoom="2"] .battle-table-shell {
  min-height: 0;
  overflow: visible;
}

.battle-tower-page[data-battle-zoom="2"] .battle-table-panel[data-bt-secondary][hidden] {
  display: none !important;
}

.battle-honor-table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
  background: #f8f8f8;
}

.battle-honor-table th,
.battle-honor-table td {
  border: 1px solid #c6c6c6;
  padding: 5px 6px;
  vertical-align: middle;
  font-size: 8px;
  line-height: 1;
}

.battle-honor-table th {
  text-align: center;
  background: #dfdfdf;
  font-size: 8px;
  letter-spacing: 0;
  font-weight: 600;
}

.battle-honor-table th:nth-child(1) {
  width: auto;
}

.battle-honor-table th:nth-child(2) {
  width: 24%;
}

.battle-honor-table th:nth-child(3) {
  width: 159px;
  min-width: 159px;
  max-width: 159px;
}

.bt-leader-cell {
  padding: 0 !important;
}

.bt-leader-subcols {
  display: grid;
  grid-template-columns: 60px minmax(0, 1fr);
  align-items: center;
  column-gap: 8px;
}

.bt-leader-sprite-col {
  padding: 5px 0 5px 6px;
}

.bt-leader-name-col {
  border-left: 1px solid #c6c6c6;
  padding: 5px 6px 5px 8px;
}

.bt-trainer-sprite {
  width: 56px;
  height: 56px;
  image-rendering: pixelated;
  flex: 0 0 auto;
}

.bt-leader-name-col {
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-height: 56px;
}

.bt-player-name {
  margin-top: 2px;
}

.bt-pokemon-list {
  margin: 0;
  padding-left: 0;
  list-style: none;
  display: block;
}

.bt-pokemon-list li {
  margin: 0;
  display: block !important;
  position: relative;
  /* px, not ch: this list is inside the zoomed .battle-table-panel, and Safari
     over-scales `ch` under `zoom` (see trade-corner cards). 1ch = 8px for this font. */
  padding-left: calc(7px + 8px);
  white-space: nowrap;
}

.bt-pokemon-list li + li {
  margin-top: 2px;
}

.bt-pokemon-list li::before {
  content: "";
  display: inline-block;
  width: 7px;
  height: 7px;
  min-width: 7px;
  position: absolute;
  left: 0;
  top: 1px;
  transform: none;
  background: url("/images/crystal/PokeballBulletPoint.png") no-repeat center center;
  background-size: 7px 7px;
  image-rendering: pixelated;
}

.bt-message-cell {
  vertical-align: top;
  width: 159px;
  min-width: 159px;
  max-width: 159px;
  padding: 2px !important;
}

.bt-message-box {
  width: 155px;
  min-width: 155px;
  max-width: 155px;
  height: 44px;
  min-height: 44px;
  box-sizing: border-box;
  border: 0;
  background: url("/images/crystal/MessageBox.png") no-repeat left top;
  background-size: 155px 44px;
  image-rendering: pixelated;
  padding: 13px 6px 0 6px;
  white-space: pre-line;
  line-height: 1;
  overflow: hidden;
}

.bt-empty-row td {
  text-align: center;
  padding: 14px;
}

.bt-empty-row td.crystal-empty-message {
  font-size: 16px !important;
  line-height: 16px !important;
}

.battle-honor-table .crystal-empty-message {
  font-size: 16px !important;
  line-height: 16px !important;
}

.battle-tower-page .battle-honor-table td.crystal-empty-message {
  font-size: 16px !important;
  line-height: 16px !important;
}

@media (max-width: 960px) {
  .battle-table-grid {
    flex-wrap: wrap;
    gap: 12px;
  }

  .battle-table-panel {
    max-width: 100%;
  }
}

@media (max-width: 991.98px) {
  .battle-tower-page {
    --bt-mobile-panel-base-width: min(440px, calc(100vw - 12px));
    width: 100%;
    max-width: 100%;
    padding-left: 0;
    padding-right: 0;
    box-sizing: border-box;
  }

  .battle-tower-controls {
    width: 100%;
    grid-template-columns: 1fr 1fr;
    grid-template-areas:
      "level room"
      "honor zoom";
    justify-items: stretch;
    row-gap: 8px;
  }

  .battle-control-level,
  .battle-honor-roll-label {
    justify-self: start;
    text-align: left;
  }

  .battle-control-room,
  .battle-control-zoom {
    justify-self: end;
    text-align: right;
  }

  .battle-control-zoom {
    width: auto;
    max-width: 100%;
    justify-content: flex-end;
    column-gap: 8px;
  }

  .battle-zoom-label {
    font-size: 16px !important;
    line-height: 16px !important;
  }

  .battle-tower-controls .trade-region-filter {
    min-width: min(220px, calc(50vw - 14px));
    width: min(220px, calc(50vw - 14px));
  }

  .battle-table-shell {
    width: 100%;
    max-width: 100%;
    padding: 0;
    overflow-x: auto;
    overflow-y: visible;
  }

  .battle-table-shell::before,
  .battle-table-shell::after,
  .battle-table-grid::before,
  .battle-table-grid::after {
    display: none;
  }

  .battle-table-grid {
    min-width: 100%;
    width: max-content;
    margin: 0 auto;
    display: grid;
    grid-template-columns: 1fr;
    gap: 14px;
    justify-content: flex-start;
  }

  .battle-table-panel {
    width: var(--bt-mobile-panel-base-width);
    max-width: var(--bt-mobile-panel-base-width);
  }

  .battle-tower-page[data-battle-zoom="2"] .battle-table-panel {
    width: 440px;
    min-width: 440px;
    max-width: 440px;
  }

  .battle-tower-page[data-battle-zoom="2"] .battle-table-grid {
    min-width: max-content;
    width: max-content;
    justify-content: flex-start;
  }

  .battle-tower-page[data-battle-zoom="2"] .battle-honor-table {
    width: 440px;
    min-width: 440px;
  }

  .battle-tower-page[data-battle-zoom="2"] .battle-honor-table th:nth-child(3),
  .battle-tower-page[data-battle-zoom="2"] .bt-message-cell {
    width: 159px;
    min-width: 159px;
    max-width: 159px;
  }

  .battle-tower-page[data-battle-zoom="2"] .bt-message-box {
    width: 155px;
    min-width: 155px;
    max-width: 155px;
    height: 44px;
    min-height: 44px;
    background-size: 155px 44px;
    padding: 13px 6px 0 6px;
  }

  .battle-honor-table {
    --bt-mobile-msg-cell-width: min(155px, max(112px, calc(100vw - 198px)));
    --bt-mobile-msg-box-width: calc(var(--bt-mobile-msg-cell-width) - 4px);
    --bt-mobile-msg-height: clamp(36px, calc(var(--bt-mobile-msg-cell-width) * 0.28), 44px);
    width: 100%;
    min-width: 0;
  }

  .battle-honor-table th:nth-child(2) {
    width: 22%;
  }

  .battle-honor-table th:nth-child(3),
  .bt-message-cell {
    width: var(--bt-mobile-msg-cell-width);
    min-width: var(--bt-mobile-msg-cell-width);
    max-width: var(--bt-mobile-msg-cell-width);
  }

  .bt-message-box {
    width: var(--bt-mobile-msg-box-width);
    min-width: var(--bt-mobile-msg-box-width);
    max-width: var(--bt-mobile-msg-box-width);
    height: var(--bt-mobile-msg-height);
    min-height: var(--bt-mobile-msg-height);
    background-size: var(--bt-mobile-msg-box-width) var(--bt-mobile-msg-height);
    padding: clamp(10px, calc(var(--bt-mobile-msg-height) * 0.28), 13px) 5px 0 5px;
    line-height: 1.15 !important;
  }

  .bt-pokemon-list li {
    white-space: normal;
    overflow: visible;
    text-overflow: clip;
    overflow-wrap: normal;
    word-break: keep-all;
    hyphens: none;
    line-height: 1.15;
  }

  .battle-honor-table th,
  .battle-honor-table td {
    padding: 4px;
    line-height: 1.15 !important;
  }
}

@media (max-width: 680px) {
  .battle-tower-controls .trade-region-filter {
    min-width: 96px;
    font-size: 8px;
    padding: 5px 6px;
  }

  .battle-honor-roll-label {
    font-size: 8px;
  }

  .battle-honor-table th,
  .battle-honor-table td {
    font-size: 8px;
    padding: 3px;
    line-height: 1.15 !important;
  }

  .bt-trainer-sprite {
    width: 44px;
    height: 44px;
  }

  .bt-leader-subcols {
    grid-template-columns: 48px minmax(0, 1fr);
    column-gap: 6px;
  }

  .bt-leader-name-col {
    min-height: 44px;
    padding-left: 6px;
  }

  .battle-honor-table th:nth-child(3),
  .bt-message-cell {
    width: min(145px, max(110px, calc(100vw - 186px)));
    min-width: min(145px, max(110px, calc(100vw - 186px)));
    max-width: min(145px, max(110px, calc(100vw - 186px)));
  }

  .bt-message-box {
    width: calc(min(145px, max(110px, calc(100vw - 186px))) - 4px);
    min-width: calc(min(145px, max(110px, calc(100vw - 186px))) - 4px);
    max-width: calc(min(145px, max(110px, calc(100vw - 186px))) - 4px);
    height: clamp(36px, calc(min(145px, max(110px, calc(100vw - 186px))) * 0.28), 42px);
    min-height: clamp(36px, calc(min(145px, max(110px, calc(100vw - 186px))) * 0.28), 42px);
    background-size: calc(min(145px, max(110px, calc(100vw - 186px))) - 4px) clamp(36px, calc(min(145px, max(110px, calc(100vw - 186px))) * 0.28), 42px);
    padding: clamp(10px, calc(min(145px, max(110px, calc(100vw - 186px))) * 0.08), 12px) 4px 0 4px;
    line-height: 1.15 !important;
  }
}
