:root {
  --bg: #2f2f2f;
  --text: #f1f1f1;
  --muted: #a3a3a3;
  --card: #3e3e3e;
  --ring: #5c5c5c;
  --accent: #8c8c8c;
  --danger: #dc2626;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  font-family: system-ui, Segoe UI, Roboto, Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
}

header {
  max-width: 1200px;
  margin: 0 auto;
  padding: 16px 20px 0 20px;
}

h1 {
  margin: 0 0 10px 0;
  font-size: 22px;
}

#tabs {
  background: var(--card);
  border: 1px solid var(--ring);
  border-radius: 10px;
  padding: 0;
}

#tabbar {
  display: flex;
  gap: 8px;
  border-bottom: 1px solid var(--ring);
  padding: 8px;
}

#deploy-list,
#buffs-list,
#school-list {
  margin: 8px 0 0 18px;
}

#school-panel {
  background: var(--card);
  border: 1px solid var(--ring);
  border-radius: 10px;
  padding: 14px;
}

#school-panel h2 {
  margin: 0 0 6px 0;
  font-size: 18px;
}

#modal {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 18px;
  z-index: 1;
  background: rgba(0, 0, 0, .55);
}

#modal[aria-hidden="false"] {
  display: flex;
}

#sheet {
  width: min(960px, 100%);
  max-height: 85vh;
  background: var(--card);
  border: 1px solid var(--ring);
  border-radius: 12px;
  overflow: auto;
}

#modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px;
  border-bottom: 1px solid var(--ring);
}

#modal-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

#search,
#closeModal {
  height: 36px;
  padding: 0 10px;
  border-radius: 8px;
  border: 1px solid var(--ring);
  background: #f8fafc;
  color: #0f172a;
}

#closeModal {
  background: #111827;
  color: #fff;
  border-color: #0b1223;
  cursor: pointer;
}

#gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 12px;
  padding: 12px;
}

#gallery .card {
  border: 1px solid var(--ring);
  border-radius: 10px;
  background: #f8fafc;
  padding: 8px;
  text-align: center;
  cursor: pointer;
}

#gallery .card img {
  width: 100%;
  height: 150px;
  object-fit: cover;
  border-radius: 8px;
}

#gallery .name {
  margin-top: 6px;
  font-weight: 600;
  font-size: 14px;
  color: #111827;
}

#gallery .meta {
  font-size: 12px;
  color: var(--muted);
  margin-top: 2px;
}

.meta-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.meta-card {
  border: 1px solid var(--ring);
  border-radius: 12px;
  padding: 10px;
  min-height: 80px;
  background: var(--card);
}

.meta-title {
  font-weight: 700;
  margin-bottom: 6px;
}

.meta-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 4px;
}

.dim {
  opacity: .8;
}

#toolbar-top {
  display: flex;
  gap: 10px;
  align-items: center;
  margin-left: auto;
  margin-bottom: 0;
}

#hint {
  margin: 8px 0 0 0;
  color: var(--muted);
  font-size: 13px;
}

#layout {
  max-width: 1200px;
  margin: 12px auto 24px auto;
  padding: 0 20px;
  display: grid;
  grid-template-columns: 1fr 320px;
  gap: 20px;
  align-items: start;
}

#main {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

#board {
  background: var(--card);
  border: 1px solid var(--ring);
  border-radius: 10px;
  position: relative;
  padding-top: 20px;
}

#row-top {
  margin-bottom: 12px;
}

#bench-row {
  margin-top: 14px;
  display: flex;
  gap: 12px;
  justify-content: center;
  align-items: center;
  flex-wrap: wrap;
}

#addBench {
  background: #0f172a;
  color: #fff;
  border: 1px solid #0b1223;
  border-radius: 8px;
  padding: 8px 10px;
  cursor: pointer;
}

.row {
  display: flex;
  gap: 16px;
  justify-content: center;
  align-items: center;
}

.slot {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.hex {
  width: 120px;
  height: 168px;
  border-radius: 10px;
  background: #626263;
  border: 1px dashed #cbd5e1;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  overflow: hidden;
}

.hex img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.label {
  margin-top: 6px;
  font-size: 13px;
  color: var(--muted);
  display: flex;
  gap: 6px;
  align-items: center;
  justify-content: center;
}

.bench-slot {
  width: 56px;
  height: 78px;
  border-radius: 6px;
  background: #eef2f7;
  border: 1px dashed #cbd5e1;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  overflow: hidden;
}

.bench-slot img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.remove-bench {
  margin-left: 8px;
  font-size: 11px;
  padding: 4px 6px;
  border: 1px solid #f3d2d2;
  background: #fee2e2;
  color: var(--danger);
  border-radius: 6px;
  cursor: pointer;
}

.tabbtn {
  background: #f3f4f6;
  border: 1px solid var(--ring);
  border-radius: 8px;
  padding: 8px 12px;
  cursor: pointer;
  color: #111827;
}

.tabbtn[aria-selected="true"] {
  outline: 2px solid var(--accent);
  background: #eef2ff;
}

.tabcontent {
  padding: 12px 14px 16px 14px;
}

.app-footer {
  background-color: #1f1f1f;
  padding: 20px 0;
  text-align: center;
  border-top: 1px solid #444;
  position: relative;
  bottom: 0;
  width: 100%;
  margin-top: 40px;
}

.footer-content {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 30px;
  flex-wrap: wrap;
}

.footer-icon {
  height: 36px;
  width: auto;
  transition: transform 0.2s ease, filter 0.2s ease;
  filter: brightness(0.95);
}

.footer-icon:hover {
  transform: scale(1.1);
  filter: brightness(1.2);
}

.app-nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--card);
  padding: 12px 20px;
  border-bottom: 1px solid var(--ring);
  position: sticky;
  top: 0;
  z-index: 1000;
  flex-wrap: wrap;
}

.nav-toggle {
  display: none;
  font-size: 24px;
  background: none;
  border: none;
  color: var(--text);
  cursor: pointer;
}

.nav-links {
  list-style: none;
  display: flex;
  gap: 20px;
  margin: 0;
  padding: 0;
  align-items: center;
}

.nav-links li a,
.nav-links li span {
  color: var(--text);
  text-decoration: none;
  font-weight: 500;
}

.nav-links li a:hover {
  color: var(--accent);
}

.nav-disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

#gallery.gallery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 10px;
  align-items: stretch;
}

#gallery .pos-filter-bar {
  grid-column: 1 / -1;
  display: flex;
  gap: 8px;
  margin-bottom: 4px;
  align-items: center;
  flex-wrap: wrap;
}

#gallery .pos-filter-bar button {
  padding: 6px 10px;
  border-radius: 8px;
  border: 1px solid var(--ring, #333);
  cursor: pointer;
  background: transparent;
  color: var(--text, #fff);
  font-weight: 600;
}

#gallery .pos-filter-bar button[aria-pressed="true"] {
  background: var(--accent, rgba(255, 255, 255, .12));
  font-weight: 700;
}

#gallery .card {
  border: 1px solid var(--ring, #444);
  border-radius: 10px;
  overflow: hidden;
  cursor: pointer;
  background: var(--card, #3e3e3e);
  display: flex;
  flex-direction: column;
}

#gallery .card img {
  width: 100%;
  aspect-ratio: 3 / 4;
  object-fit: cover;
  display: block;
}

#gallery .name {
  font-weight: 700;
  padding: 8px 8px 0 8px;
  line-height: 1.2;
  color: var(--text, #fff);
}

#gallery .meta {
  opacity: .8;
  font-size: .85rem;
  padding: 0 8px 8px 8px;
  color: var(--muted, #a3a3a3);
}

#gallery .card.is-disabled {
  opacity: .45;
  pointer-events: none;
}

.empty {
  opacity: .7;
  padding: 12px;
}

.slot-placeholder {
  opacity: .75;
}

.stats-row {
  display: grid;
  grid-template-columns: 140px 1fr 1fr;
  gap: 10px;
}

.stats-row.head .stat-label {
  font-weight: 700;
}

.col.stat-label {
  font-weight: 600;
  opacity: .9;
}

.dash {
  opacity: .5;
}

.bar {
  position: relative;
  height: 22px;
  border-radius: 6px;
  border: 1px solid var(--ring, #444);
  overflow: hidden;
  background: #272727;
}

.bar__fill {
  height: 100%;
  background: var(--accent, rgba(255, 255, 255, .15));
}

.bar__label {
  position: absolute;
  left: 8px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 0.9rem;
  font-weight: 600;
  text-shadow: 0 1px 0 rgba(0, 0, 0, .4);
}

.meta-card {
  border: 1px solid var(--ring, #333);
  border-radius: 12px;
  padding: 10px;
  min-height: 80px;
  background: var(--card, #3e3e3e);
}

.meta-title {
  font-weight: 700;
  margin-bottom: 6px;
}

.meta-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 4px;
}

.dim {
  opacity: .8;
}

#modal {
  transition: opacity .18s ease;
}

#modal.open {
  opacity: 1;
}

#modal[aria-hidden="true"] {
  opacity: 0;
}

#sheet {
  transform: scale(.98);
  opacity: .85;
  transition: transform .18s ease, opacity .18s ease;
}

#modal.open #sheet {
  transform: scale(1);
  opacity: 1;
}

@media (max-width: 768px) {
  #gallery.gallery-grid {
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  }
}

.nav-disabled span small {
  font-size: 12px;
  color: var(--muted);
}

.server-select-container {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px;
}

#serverSelect {
  font-size: 14px;
  padding: 4px 6px;
  border-radius: 6px;
  border: 1px solid var(--ring);
  background-color: var(--card);
  color: var(--text);
}

.coming-soon-note {
  font-size: 12px;
  color: var(--muted);
  font-style: italic;
}

.server-option {
  padding: 6px 12px;
  border: 1px solid var(--ring);
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
  user-select: none;
  color: white;
}

.server-option.active {
  background: var(--accent, #2563eb);
  border-color: var(--accent, #2563eb);
  font-weight: bold;
}

.server-toggle {
  display: flex;
  gap: 8px;
}

.server-option {
  padding: 6px 12px;
  border: 1px solid var(--ring);
  border-radius: 6px;
  cursor: pointer;
  user-select: none;
}

.server-option.active {
  background: var(--accent);
  border-color: var(--accent);
  font-weight: 600;
}

.server-label {
  font-size: 16px;
  font-weight: bold;
  opacity: .9;
}

#tabbar {
  align-items: center
}

#bond-filter {
  margin-left: auto;
  display: flex;
  gap: 12px;
  align-items: center
}

.bond-filter input[type="radio"] {
  accent-color: #6366f1
}

.bond-filter {
  display: flex;
  gap: 10px;
  align-items: center
}

.bond-filter label {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--text);
  font-size: 14px
}

#tabbar {
  align-items: center
}

.team-switcher {
  position: absolute;
  top: -31px;
  left: 10px;
  display: flex;
  gap: 6px;
  align-items: flex-end;
  z-index: 0;
}


.team-btn {
  appearance: none;
  border: 1px solid var(--ring);
  border-bottom: none;
  background: var(--card);
  color: var(--text);
  padding: 6px 12px;
  border-top-left-radius: 10px;
  border-top-right-radius: 10px;
  cursor: pointer;
  font-size: 14px;
  transform: translateY(1px);
  transition: background 0.2s, color 0.2s;
}

.team-btn.active {
  background: var(--bg);
  border-color: var(--ring);
  color: var(--text);
  font-weight: 600;
  box-shadow: 0 2px 0 var(--bg);
  transform: translateY(0);
}

.team-btn.add {
  background: var(--card);
  color: var(--muted);
}

.team-btn:hover {
  background: var(--accent);
  color: #fff;
}

.team-x {
  margin-left: 6px;
  color: var(--muted);
  font-weight: bold;
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
}

.team-x:hover {
  color: var(--danger);
}

.player-name {
  color: #c2c2c2;
  font-weight: 500;
}

.posless-wrap {
  user-select: none;
}

.posless-switch {
  position: relative;
  display: inline-block;
  width: 44px;
  height: 22px;
}

.posless-switch input {
  display: none;
}

.posless-slider {
  position: absolute;
  inset: 0;
  background: #434a57;
  border-radius: 999px;
  transition: .2s;
  border: 1px solid #2d3647;
}

.posless-slider:before {
  content: "";
  position: absolute;
  height: 16px;
  width: 16px;
  left: 3px;
  top: 2px;
  background: #fff;
  border-radius: 50%;
  transition: .2s;
}

.posless-switch input:checked+.posless-slider {
  background: #6aa9ff;
}

.posless-switch input:checked+.posless-slider:before {
  transform: translateX(22px);
}

.posless-label {
  font-size: 13px;
  opacity: .85;
}

#gallery.gallery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 10px;
}

#gallery .pos-filter-bar {
  grid-column: 1 / -1;
}

#missing-stats-box {
  margin-top: 12px;
  padding: 12px;
}

#missing-stats-box #missingStatsBtn {
  display: inline-block;
  padding: 10px 14px;
  border: none;
  border-radius: 10px;
  background: #2d2d2d;
  color: #fff;
  font-weight: 700;
  cursor: pointer;
  transition: background .2s ease, transform .15s ease, box-shadow .2s ease;
  box-shadow: 0 1px 2px rgba(0, 0, 0, .25);
}

#missing-stats-box #missingStatsBtn:hover {
  background: #404040;
  transform: translateY(-1px);
}

#missing-stats-box #missingStatsBtn:active {
  transform: none;
}

#missing-stats-box form#missingStatsForm {
  margin-top: 12px;
}

#missing-stats-box [hidden] {
  display: none !important;
}

#missing-stats-box #missingStatsForm>div {
  margin: 10px 0;
}

#missing-stats-box #missingStatsForm label {
  display: block;
  margin-bottom: 6px;
  color: #c9c9c9;
  font-size: 0.92rem;
}

#missing-stats-box #missingStatsForm input[type="text"],
#missing-stats-box #missingStatsForm input[type="number"],
#missing-stats-box #missingStatsForm select {
  width: 100%;
  box-sizing: border-box;
  padding: 10px 10px 10px;
  border: 1px solid #2a2a2a;
  border-radius: 8px;
  outline: none;
  transition: border-color .2s ease, box-shadow .2s ease;
}

#missing-stats-box #missingStatsForm input::placeholder {
  color: #8a8a8a;
}

#missing-stats-box #missingStatsForm input:focus,
#missing-stats-box #missingStatsForm select:focus {
  border-color: #6ea8ff;
  box-shadow: 0 0 0 3px rgba(110, 168, 255, .2);
}

#missing-stats-box #missingStatsForm .player-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

#missing-stats-box #missingStatsForm .player-row input[readonly] {
  flex: 1 1 auto;
}

#missing-stats-box #missingStatsForm .choose-btn {
  display: inline-block;
  padding: 8px 12px;
  border: none;
  border-radius: 8px;
  background: #2d2d2d;
  color: #fff;
  font-weight: 600;
  cursor: pointer;
  transition: background .2s ease, transform .15s ease, box-shadow .2s;
  box-shadow: 0 1px 2px rgba(0, 0, 0, .25);
  white-space: nowrap;
}

#missing-stats-box #missingStatsForm .choose-btn:hover {
  background: #404040;
  transform: translateY(-1px);
}

#missing-stats-box #missingStatsForm .choose-btn:active {
  background: #1f1f1f;
  transform: none;
}

#missing-stats-box #missingStatsForm .stats-hdr {
  margin: 10px 0 6px;
  font-weight: 700;
  color: #eaeaea;
}

#missing-stats-box #missingStatsForm .stats-grid {
  display: grid;
  grid-template-columns: auto 120px;
  align-items: center;
  column-gap: 10px;
  row-gap: 8px;
}

#missing-stats-box #missingStatsForm .stats-grid>div {
  color: #dddddd;
  font-size: 0.95rem;
}


#missing-stats-box #missingStatsForm .actions {
  margin-top: 12px;
  display: flex;
  gap: 8px;
}

#missing-stats-box #missingStatsForm .actions button[type="submit"] {
  padding: 10px 14px;
  border: none;
  border-radius: 10px;
  background: #3b7cff;
  color: #fff;
  font-weight: 700;
  cursor: pointer;
  transition: background .2s ease, transform .15s ease, box-shadow .2s;
  box-shadow: 0 1px 2px rgba(0, 0, 0, .25);
}

#missing-stats-box #missingStatsForm .actions button[type="submit"]:hover {
  background: #2f6aee;
  transform: translateY(-1px);
}

#missing-stats-box #missingStatsForm .actions button[type="submit"]:active {
  background: #2557c9;
  transform: none;
}

#missing-stats-box #missingStatsForm .actions button[type="button"] {
  padding: 10px 14px;
  border: 1px solid #2e2e2e;
  border-radius: 10px;
  background: #1a1a1a;
  color: #eaeaea;
  font-weight: 600;
  cursor: pointer;
  transition: background .2s ease, border-color .2s ease;
}

#missing-stats-box #missingStatsForm .actions button[type="button"]:hover {
  background: #232323;
  border-color: #3a3a3a;
}

@media (max-width: 768px) {

  header,
  #layout {
    padding: 0 12px;
  }

  h1 {
    font-size: 20px;
    text-align: center;
  }

  #layout {
    display: flex;
    flex-direction: column;
  }

  #gallery {
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  }

  .hex {
    width: 90px;
    height: 126px;
  }

  .bench-slot {
    width: 48px;
    height: 66px;
  }

  .remove-bench {
    margin-top: 6px;
    margin-left: 0;
    padding: 4px 6px;
    display: inline-block;
  }

  #modal {
    padding: 8px;
  }

  #sheet {
    max-height: 90vh;
  }

  #modal-header {
    flex-direction: column;
    align-items: stretch;
  }

  #search,
  #closeModal {
    width: 100%;
    margin-bottom: 6px;
  }

  .row {
    gap: 10px;
    flex-wrap: wrap;
  }

  .slot {
    flex-basis: 28%;
  }

  #school-panel h2 {
    font-size: 16px;
  }

  #tabs {
    border-radius: 0;
  }

  .tabbtn {
    flex: 1;
    text-align: center;
    padding: 10px 0;
  }

  .footer-content {
    align-items: center;
    flex-direction: row;
    gap: 16px;
  }

  .footer-icon {
    height: 30px;
  }

  .app-footer {
    padding: 16px 10px;
  }

  #addBench {
    width: 100%;
    padding: 10px;
  }

  .nav-toggle {
    display: block;
  }

  .nav-links {
    display: none;
    flex-direction: column;
    width: 100%;
    margin-top: 12px;
  }

  .nav-links.active {
    display: flex;
    gap: 12px;
    border-top: 1px solid var(--ring);
    padding-top: 10px;
  }

  .server-select-container {
    margin-left: 0;
  }

  #toolbar-top {
    margin-left: 0;
    width: 100%;
    justify-content: center;
    flex-wrap: wrap;
    order: 99;
    padding: 6px 0;
    gap: 8px;
  }

  .server-toggle {
    gap: 8px;
  }

  .server-option {
    padding: 6px 12px;
  }

  .server-label {
    font-size: 14px;
  }

  .coming-soon-note {
    width: 100%;
    text-align: center;
    opacity: .7;
  }

  #tab-filters {
    margin-left: 0;
    flex-wrap: wrap;
    justify-content: center;
    width: 100%;
    order: 2;
    padding: 6px 0
  }

  .team-switcher {
    position: absolute;
    top: -31px;
    left: 10px;
    display: flex;
    gap: 6px;
    align-items: flex-end;
    z-index: 0;
  }

  .team-btn {
    appearance: none;
    border: 1px solid var(--ring);
    border-bottom: none;
    background: var(--card);
    color: var(--text);
    padding: 6px 12px;
    border-top-left-radius: 10px;
    border-top-right-radius: 10px;
    cursor: pointer;
    font-size: 14px;
    transform: translateY(1px);
    transition: background 0.2s, color 0.2s;
  }

  .team-btn.active {
    background: var(--bg);
    border-color: var(--ring);
    color: var(--text);
    font-weight: 600;
    box-shadow: 0 2px 0 var(--bg);
    transform: translateY(0);
  }

  .team-btn.add {
    background: var(--card);
    color: var(--muted);
  }

  .team-btn:hover {
    background: var(--accent);
    color: #fff;
  }

  .team-x {
    margin-left: 6px;
    color: var(--muted);
    font-weight: bold;
    cursor: pointer;
    font-size: 16px;
    line-height: 1;
  }

  .team-x:hover {
    color: var(--danger);
  }

}

:root {

  --vs-card-w: clamp(220px, 88vw, 420px);
}

@media (max-width: 768px) {

  header {
    padding: 6px 10px 0 10px;
  }

  #board {
    padding: 10px;
  }

  .row#versus-row {
    flex-direction: column;
    align-items: center;
    gap: 12px;
  }

  .row#versus-row .slot {
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
  }

  .row#versus-row .hex {
    width: var(--vs-card-w);
    height: auto;
    aspect-ratio: 3 / 4;
    border-radius: 12px;
    border-style: solid;
    background: #2b2b2b;
  }

  .row#versus-row .hex img {
    width: 100%;
    height: 100%;
    object-fit: cover;
  }

  .row#versus-row .slot:nth-child(2) .hex {
    width: auto;
    aspect-ratio: auto;
    padding: 6px 12px;
    background: #2f2f2f;
    border-radius: 999px;
    font-weight: 700;
  }

  .label {
    font-size: 14px;
    margin-top: 8px;
  }

  #tabs {
    margin-top: 6px;
  }
}

@media (max-width: 420px) {
  :root {
    --vs-card-w: clamp(230px, 92vw, 400px);
  }
}