body:has(.v2-build-page) {
  overflow: hidden;
  height: 100dvh;
  background-image:
    linear-gradient(180deg, rgba(6, 8, 12, 0.28) 0%, rgba(6, 8, 12, 0.18) 42%, rgba(6, 8, 12, 0.62) 100%),
    url("/static/images/backgrounds/build-antique-interior.webp");
  background-size: auto, cover;
  background-position: center;
  background-attachment: fixed;
}

body:has(.v2-build-page) .shell {
  width: 100vw;
  max-width: none;
  height: 100dvh;
  margin: 0;
  padding: 0;
}

.v2-build-page {
  height: 100dvh;
  max-height: 100dvh;
  display: grid;
  grid-template-rows: 72px minmax(0, 1fr);
  overflow: hidden;
  color: var(--text);
}

.v2-build-page .v2-banner {
  position: absolute;
  left: 50%;
  top: 12px;
  z-index: 8;
  transform: translateX(-50%);
  width: min(360px, calc(100vw - 280px));
  pointer-events: none;
}

.v2-build-summary-bar {
  display: grid;
  justify-items: end;
  gap: 2px;
  min-width: 0;
  font-size: 12px;
  font-weight: 700;
  color: #d7cbb3;
}

.v2-build-summary-bar p { margin: 0; white-space: nowrap; }

#v2-build-name {
  width: min(160px, 18vw);
  padding: 6px 10px;
  border-radius: 10px;
  border: 1px solid rgba(232, 201, 136, 0.28);
  background: rgba(8, 10, 14, 0.65);
  color: #f4e6c4;
  font-weight: 700;
}

.v2-build-page .v2-home-account { gap: 8px; }

.v2-build-stage {
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) 148px;
  gap: 10px;
  padding: 10px 18px 14px;
  position: relative;
}

.v2-build-toolbar {
  display: flex;
  align-items: start;
  gap: 16px;
  min-width: 0;
}

#v2-build-library {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  flex-wrap: wrap;
}

#v2-build-library .subtle {
  margin: 0;
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.v2-deck-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.v2-deck-chip {
  min-height: 32px;
  padding: 6px 10px;
  font-size: 12px;
}

.v2-deck-chip {
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(10, 12, 16, 0.55);
  color: inherit;
  cursor: grab;
  touch-action: none;
  user-select: none;
}

.v2-deck-chip.selected {
  border-color: rgba(232, 201, 136, 0.75);
  background: rgba(232, 201, 136, 0.16);
}

.v2-deck-chip.is-dragging {
  opacity: 0.42;
  cursor: grabbing;
}

.v2-deck-chip.is-drop-before {
  box-shadow: inset 3px 0 0 rgba(232, 201, 136, 0.95);
}

.v2-deck-chip.is-drop-after {
  box-shadow: inset -3px 0 0 rgba(232, 201, 136, 0.95);
}

.v2-build-board {
  min-height: 0;
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr);
  gap: 16px;
  overflow: hidden;
}

.v2-build-focus {
  min-height: 0;
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  overflow: hidden;
  border-radius: 18px;
  border: 1px solid rgba(232, 201, 136, 0.16);
  background: rgba(8, 10, 14, 0.42);
}

.v2-build-focus-art {
  min-height: 0;
  overflow: hidden;
}

.v2-build-focus-art img,
.v2-build-focus-art .v2-image-fallback {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: top center;
}

.v2-build-focus-copy {
  padding: 12px 14px 14px;
  display: grid;
  gap: 6px;
  background: linear-gradient(180deg, transparent, rgba(8, 10, 14, 0.88));
}

.v2-build-focus-copy h2 { margin: 0; font-size: 22px; }
.v2-build-focus-copy .v2-character-meta { margin: 0; }
.v2-passive-box {
  display: grid;
  gap: 4px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
}

.v2-count.ok { color: var(--green); }
.v2-count.bad { color: var(--danger); }

.v2-build-cards {
  min-height: 0;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  grid-template-rows: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.v2-build-card {
  position: relative;
  display: grid;
  grid-template-rows: 1fr auto;
  min-height: 0;
  overflow: hidden;
  border-radius: 16px;
  border: 2px solid rgba(255, 255, 255, 0.12);
  background: rgba(16, 20, 28, 0.92);
  cursor: pointer;
}

.v2-build-card.is-empty {
  border-color: rgba(255, 255, 255, 0.08);
  box-shadow: none;
}

.v2-build-card.is-empty[data-card-type="battle"] {
  border-color: rgba(255, 122, 110, 0.3);
  box-shadow: inset 0 0 0 1px rgba(255, 122, 110, 0.12);
}

.v2-build-card.is-empty[data-card-type="tactic"] {
  border-color: rgba(110, 168, 254, 0.3);
  box-shadow: inset 0 0 0 1px rgba(110, 168, 254, 0.12);
}

.v2-build-card.is-empty[data-card-type="form"] {
  border-color: rgba(232, 201, 136, 0.3);
  box-shadow: inset 0 0 0 1px rgba(232, 201, 136, 0.12);
}

.v2-build-card-body {
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: 16px 12px 8px;
}

.v2-build-card-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 0 0 8px;
}

.v2-build-card h3 {
  margin: 0 0 6px;
  font-size: 16px;
  line-height: 1.2;
}

.v2-build-card p {
  margin: 0;
  flex: 1;
  overflow: auto;
  font-size: 12px;
  line-height: 1.45;
  color: #d7cbb3;
}

.v2-build-card-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 10px 10px;
  background: rgba(8, 10, 14, 0.9);
}

.v2-build-card .v2-frame-stats {
  min-height: 28px;
}

.v2-build-card .v2-stat-badge {
  position: static;
  min-height: 28px;
  font-size: 15px;
}

.v2-build-card .v2-stat-icon {
  width: 18px;
  height: 18px;
}

.v2-stepper {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-left: auto;
}

.v2-stepper button {
  width: 28px;
  min-width: 28px;
  min-height: 28px;
  padding: 0;
}

.v2-stepper strong {
  min-width: 1em;
  text-align: center;
  font-size: 16px;
}

.v2-build-copies {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 2;
  min-width: 28px;
  height: 28px;
  padding: 0 8px;
  border-radius: 999px;
  background: rgba(8, 10, 14, 0.86);
  border: 1px solid rgba(232, 201, 136, 0.45);
  color: #f4e6c4;
  font-weight: 800;
  line-height: 26px;
  text-align: center;
}

.v2-build-team {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  min-height: 0;
}

.v2-team-slot {
  position: relative;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: stretch;
  overflow: hidden;
  padding: 0;
  border-radius: 16px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(10, 12, 16, 0.55);
  color: inherit;
  cursor: pointer;
}

.v2-team-slot.selected {
  border-color: rgba(232, 201, 136, 0.85);
  box-shadow: 0 0 0 1px rgba(232, 201, 136, 0.35), 0 12px 28px rgba(0, 0, 0, 0.35);
}

.v2-team-slot.is-empty {
  display: grid;
  grid-template-columns: 1fr;
  place-items: center;
  color: #9aa3b5;
  border-style: dashed;
}

.v2-team-art {
  width: auto;
  height: 100%;
  aspect-ratio: 1;
  min-width: 0;
  overflow: hidden;
}

.v2-team-art img,
.v2-team-art .v2-image-fallback {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center;
}

.v2-team-meta {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
  gap: 8px;
  min-width: 0;
  padding: 10px 12px;
  background: rgba(8, 10, 14, 0.72);
}

.v2-team-meta strong { font-size: 15px; }
.v2-team-change {
  flex: none;
  align-self: stretch;
  min-height: 40px;
  padding: 8px 16px;
  font-size: 14px;
  font-weight: 700;
}

.v2-build-gallery {
  position: absolute;
  inset: 10px 18px 14px;
  z-index: 4;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 12px;
  padding: 16px;
  border-radius: 20px;
  border: 1px solid rgba(232, 201, 136, 0.22);
  background: rgba(8, 10, 14, 0.92);
  backdrop-filter: blur(16px);
}

.v2-build-gallery[hidden] { display: none !important; }

.v2-gallery-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.v2-roster-row {
  min-height: 0;
  overflow: auto;
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 10px;
}

.v2-roster-card {
  display: grid;
  grid-template-rows: minmax(120px, 1fr) auto;
  overflow: hidden;
  padding: 0;
  border-radius: 14px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: rgba(255, 255, 255, 0.04);
  color: inherit;
}

.v2-roster-card.selected { border-color: rgba(232, 201, 136, 0.7); }
.v2-roster-card.disabled { opacity: 0.38; }

.v2-roster-card img,
.v2-roster-card .v2-image-fallback {
  width: 100%;
  height: 100%;
  min-height: 168px;
  object-fit: cover;
  object-position: top center;
}

.v2-roster-card strong {
  padding: 8px;
  font-size: 13px;
}

@media (max-width: 980px) {
  .v2-build-page .v2-home-account { display: flex; }
  .v2-build-stage { grid-template-rows: auto minmax(0, 1fr) 120px; }
  .v2-build-board { grid-template-columns: 1fr; }
  .v2-build-focus { display: none; }
  .v2-team-meta { padding: 6px 8px; gap: 4px; }
  .v2-team-meta strong { font-size: 12px; }
  .v2-team-change { min-height: 34px; padding: 6px 12px; font-size: 13px; }
  .v2-roster-row { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .v2-build-cards { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* Phones use CSS viewport dimensions; DPR must not scale the layout. */
@media (max-width: 980px), (pointer: coarse) and (max-height: 600px) {
  body:has(.v2-build-page) {
    height: auto;
    overflow: auto;
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
  }
  body:has(.v2-build-page) .shell,
  .v2-build-page {
    height: auto;
    min-height: 100dvh;
    max-height: none;
    overflow: visible;
  }
  .v2-build-page { grid-template-rows: auto auto; }
  .v2-build-page .v2-home-nav {
    grid-template-columns: auto minmax(0, 1fr);
    gap: 8px 16px;
    padding: 8px max(12px, env(safe-area-inset-right)) 8px max(12px, env(safe-area-inset-left));
  }
  .v2-build-page .v2-home-links { justify-content: flex-end; }
  .v2-build-page .v2-home-account {
    grid-column: 1 / -1;
    display: flex;
    flex-wrap: wrap;
  }
  .v2-build-summary-bar { margin-right: auto; justify-items: start; }
  .v2-build-summary-bar p { white-space: normal; text-align: left; }
  .v2-build-page #v2-build-name { width: min(240px, 44vw); font-size: 16px; }
  .v2-build-stage {
    grid-template-rows: auto auto auto;
    padding: 10px max(12px, env(safe-area-inset-right)) max(16px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
  }
  .v2-build-toolbar { grid-row: 1; }
  .v2-build-team { grid-row: 2; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
  .v2-build-board { grid-row: 3; grid-template-columns: 1fr; overflow: visible; }
  .v2-build-focus { display: none; }
  .v2-build-cards {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    grid-template-rows: none;
    grid-auto-rows: minmax(200px, auto);
    gap: 10px;
  }
  .v2-build-card { grid-template-rows: minmax(0, 1fr) auto; }
  .v2-build-card-body { padding: 12px 10px 8px; }
  .v2-build-card h3 { padding-right: 30px; }
  .v2-build-card p { overflow: visible; }
  .v2-build-card-foot { flex-wrap: wrap; padding: 8px; }
  .v2-team-slot { grid-template-columns: 64px minmax(0, 1fr); min-height: 92px; }
  .v2-team-art { width: 64px; height: 100%; aspect-ratio: auto; }
  .v2-team-meta { padding: 6px; }
  .v2-build-page button { min-height: 44px; }
  .v2-build-page .v2-stepper button { width: 44px; min-width: 44px; }
  .v2-team-change { padding: 4px; }
  .v2-build-gallery { position: fixed; inset: 12px; }
  .v2-build-page .v2-banner { position: fixed; width: min(360px, calc(100vw - 24px)); }
}

@media (max-width: 600px) {
  .v2-build-cards { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .v2-build-team { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .v2-build-page .v2-home-nav { column-gap: 6px; }
  .v2-build-page .v2-home-links { gap: 0; }
  .v2-build-page .v2-home-links a { padding: 10px 8px; }
  .v2-build-page .v2-home-logo { width: 100px; }
  .v2-build-page .v2-home-account { gap: 6px; }
  .v2-build-page .v2-home-account button { padding: 8px 10px; }
  .v2-build-summary-bar { flex: 1 0 100%; }
  .v2-roster-row { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

.v2-build-transfer-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.v2-build-transfer { width: min(640px, calc(100vw - 32px)); max-height: 90dvh; overflow: auto; box-sizing: border-box; border: 1px solid #9c8963; border-radius: 16px; padding: 20px; background: #171b24; color: #f4e6c4; }
.v2-build-transfer::backdrop { background: rgba(0, 0, 0, .7); }
.v2-build-transfer textarea { display: block; box-sizing: border-box; width: 100%; margin: 8px 0; padding: 12px; background: #090d14; color: #f4e6c4; resize: vertical; font: 14px/1.5 monospace; }
#v2-build-transfer-error { color: #efc98d; }
