/* ============ FORMATIONS BUILDER ============ */

.formations-app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

/* ── Team Select Modal ── */
.team-select-overlay {
  position: fixed; inset: 0;
  background: var(--bg);
  z-index: 9;
  display: flex; align-items: center; justify-content: center;
  animation: fadein 0.22s ease;
}
.team-select-modal {
  width: 480px; max-width: calc(100vw - 32px);
  max-height: 82vh;
  display: flex; flex-direction: column;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 20px;
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  animation: slideup 0.28s cubic-bezier(0.22, 1, 0.36, 1);
}
.team-select-hd {
  padding: 28px 24px 18px;
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
}
.team-select-title {
  font-size: 22px; font-weight: 700; letter-spacing: -0.03em;
  color: var(--ink); margin-bottom: 4px;
}
.team-select-sub {
  font-size: 13px; color: var(--ink-3); margin: 0;
  letter-spacing: -0.005em;
}
.team-select-search-wrap {
  display: flex; align-items: center; gap: 10px;
  padding: 14px 24px;
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
}
.team-select-search-icon { color: var(--ink-4); flex-shrink: 0; }
.team-select-input {
  background: transparent; border: none; outline: none;
  font: inherit; font-size: 14px; color: var(--ink);
  flex: 1; min-width: 0;
  letter-spacing: -0.005em;
}
.team-select-input::placeholder { color: var(--ink-4); }
.team-select-list {
  overflow-y: auto; flex: 1; padding: 6px 0;
}
.team-select-item {
  display: flex; align-items: center; gap: 12px;
  width: 100%; padding: 11px 24px;
  background: transparent; border: none;
  cursor: pointer; text-align: left; font: inherit;
  color: var(--ink);
  transition: background 0.12s ease;
}
.team-select-item:hover { background: var(--bg-soft); }
.team-select-item .flag { width: 28px; height: 20px; }
.team-select-name {
  flex: 1; font-size: 14px; font-weight: 500; letter-spacing: -0.01em;
}
.team-select-val {
  font-size: 12px; font-weight: 600; color: var(--gold);
  letter-spacing: -0.005em;
}

/* ── Main layout ── */
.formations-main {
  flex: 1 1 auto;
  display: flex;
  min-height: 0;
  overflow: hidden;
}

/* ── Side panels ── */
.formations-panel {
  flex: 0 0 220px;
  display: flex; flex-direction: column;
  border-right: 1px solid var(--line);
  background: var(--bg);
  overflow: hidden;
}
.formations-panel-right {
  border-right: none;
  border-left: 1px solid var(--line);
}
.panel-label {
  padding: 12px 16px 8px;
  font-size: 10px; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.12em;
  color: var(--ink-4);
  flex-shrink: 0;
}
.panel-search-wrap {
  display: flex; align-items: center; gap: 8px;
  margin: 0 12px 10px;
  background: var(--bg-soft); border: 1px solid var(--line);
  border-radius: 8px; padding: 7px 10px;
  flex-shrink: 0;
}
.panel-search-icon { color: var(--ink-4); flex-shrink: 0; }
.panel-search-input {
  background: transparent; border: none; outline: none;
  font: inherit; font-size: 12px; color: var(--ink); flex: 1; min-width: 0;
}
.panel-search-input::placeholder { color: var(--ink-4); }

/* ── Player list ── */
.player-list { flex: 1; overflow-y: auto; padding: 0 8px 8px; }
.player-list-empty {
  padding: 24px 12px; text-align: center;
  font-size: 12px; color: var(--ink-4);
}
.player-card {
  display: flex; align-items: center; gap: 9px;
  padding: 7px 8px; border-radius: 8px;
  cursor: grab; transition: background 0.12s ease;
  user-select: none;
  position: relative;
}
.player-card:hover { background: var(--bg-soft); }
.player-card:active { cursor: grabbing; }
.player-card.on-pitch { opacity: 0.4; pointer-events: none; }
.player-avatar {
  width: 32px; height: 32px; border-radius: 50%;
  display: grid; place-items: center; flex-shrink: 0;
  font-size: 10px; font-weight: 700; color: #fff;
  letter-spacing: 0.02em;
  overflow: hidden;
  box-shadow: 0 1px 4px rgba(0,0,0,0.15);
}
.player-avatar img {
  width: 100%; height: 100%; object-fit: cover;
}
.player-avatar.small { width: 24px; height: 24px; font-size: 8px; }
.player-card-info { flex: 1; min-width: 0; }
.player-card-name {
  font-size: 12px; font-weight: 600; letter-spacing: -0.01em;
  color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.player-card-club {
  font-size: 10px; color: var(--ink-4);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.player-card-pos {
  font-size: 9px; font-weight: 700;
  padding: 2px 5px; border-radius: 4px;
  border: 1px solid transparent;
  white-space: nowrap; flex-shrink: 0;
  letter-spacing: 0.04em;
}
.player-card-add {
  appearance: none; background: var(--bg-soft); border: 1px solid var(--line);
  border-radius: 50%; width: 20px; height: 20px;
  display: grid; place-items: center;
  cursor: pointer; color: var(--ink-3); font-size: 14px; line-height: 1;
  flex-shrink: 0; transition: all 0.15s ease;
  padding: 0;
}
.player-card-add:hover { background: var(--accent); border-color: var(--accent); color: #fff; }

/* ── Pitch ── */
.formations-pitch-wrap {
  flex: 1 1 auto;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg-soft);
  overflow: hidden;
  position: relative;
  padding: 12px 8px;
}
.formations-pitch-wrap.drag-over { background: var(--bg); }
.pitch-svg {
  height: 100%; max-height: 100%;
  width: auto; max-width: 100%;
  display: block;
  filter: drop-shadow(0 4px 24px rgba(0,0,0,0.12));
}

.pitch-bg   { fill: var(--bg-card); }
.pitch-line { stroke: var(--line-2); stroke-width: 1.2; fill: none; }
.pitch-spot { fill: var(--line-2); }
.pitch-goal { stroke: var(--line-2); stroke-width: 1.2; fill: none; }

.pitch-pos {
  transition: transform 0.45s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.pos-circle {
  fill: var(--bg-soft); stroke: var(--line-2); stroke-width: 1.5;
  transition: fill 0.2s ease, stroke 0.2s ease;
  cursor: pointer;
}
.pos-circle.hover { stroke: var(--accent); fill: var(--bg-elev); }
.pos-circle.filled { stroke: var(--line-2); stroke-width: 2; }
.pos-circle.filled.hover { stroke: var(--red); stroke-width: 2.5; }

.pos-role-label {
  font-size: 7.5px; fill: var(--ink-3); font-weight: 700;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Inter", sans-serif;
  pointer-events: none; letter-spacing: 0.05em;
}
.pos-player-initials {
  font-size: 10px; fill: #fff; font-weight: 700;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Inter", sans-serif;
  pointer-events: none;
}
.pos-player-name {
  font-size: 8px; fill: var(--ink-2); font-weight: 600;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Inter", sans-serif;
  pointer-events: none; letter-spacing: -0.01em;
}
.pos-remove-hint {
  font-size: 6px; fill: var(--red); font-weight: 600;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Inter", sans-serif;
  pointer-events: none; opacity: 0;
  transition: opacity 0.15s ease;
}
.pitch-pos:hover .pos-remove-hint { opacity: 1; }

/* ── Formation selector ── */
.formation-list {
  display: flex; flex-direction: column; gap: 3px;
  padding: 0 10px 10px; overflow-y: auto; flex: 1;
}
.formation-btn {
  appearance: none; border: 1px solid var(--line);
  background: transparent; border-radius: 8px;
  color: var(--ink-3); font: inherit; font-size: 14px; font-weight: 600;
  padding: 10px 14px; cursor: pointer; text-align: left;
  letter-spacing: -0.01em;
  transition: all 0.15s ease;
}
.formation-btn:hover { background: var(--bg-soft); color: var(--ink); }
.formation-btn.active {
  background: var(--ink); border-color: var(--ink); color: var(--bg);
}

/* ── Team switch btn in header ── */
.team-switch-btn {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 6px 14px; border-radius: 999px;
  background: var(--bg-soft); border: 1px solid var(--line);
  font: inherit; font-size: 13px; font-weight: 500;
  color: var(--ink-2); cursor: pointer;
  transition: all 0.18s ease;
}
.team-switch-btn:hover { background: var(--bg-card); color: var(--ink); border-color: var(--line-2); }
.team-switch-btn .flag { width: 20px; height: 14px; }

/* ── Bench ── */
.formations-bench {
  flex: 0 0 auto;
  background: var(--bg);
  border-top: 1px solid var(--line);
  transition: flex-basis 0.3s ease;
}
.formations-bench.closed { flex-basis: 42px; }
.formations-bench.open  { flex-basis: 110px; }

.bench-tabs {
  display: flex; align-items: center; gap: 8px;
  padding: 0 20px;
  height: 42px; flex-shrink: 0;
  border-bottom: 1px solid var(--line);
}
.bench-title {
  font-size: 11px; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.12em;
  color: var(--ink-4);
  display: flex; align-items: center; gap: 6px;
}
.bench-count {
  font-size: 10px; font-weight: 600;
  padding: 1px 6px; border-radius: 999px;
  background: var(--bg-soft); color: var(--ink-3);
  letter-spacing: 0.02em;
}
.bench-resize-btns { margin-left: auto; }

.bench-team-info {
  display: flex; align-items: center; gap: 6px;
  flex: 1;
  justify-content: center;
}
.bench-team-info .flag { width: 20px; height: 14px; }
.bench-team-name {
  font-size: 12px; font-weight: 600;
  color: var(--ink-2);
  letter-spacing: -0.01em;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  max-width: 130px;
}

.bench-players {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 20px; overflow-x: auto;
  height: calc(110px - 42px);
}
.bench-empty {
  font-size: 12px; color: var(--ink-4); padding: 4px 0;
  white-space: nowrap;
}
.bench-player {
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  position: relative; flex-shrink: 0;
  cursor: grab; padding: 4px 6px; border-radius: 8px;
  transition: background 0.12s ease;
}
.bench-player:hover { background: var(--bg-soft); }
.bench-player:active { cursor: grabbing; }
.bench-player-name {
  font-size: 9px; font-weight: 500; color: var(--ink-3);
  white-space: nowrap; max-width: 50px;
  overflow: hidden; text-overflow: ellipsis;
}
.bench-remove {
  position: absolute; top: 0; right: 0;
  appearance: none; border: none; background: transparent;
  color: var(--ink-4); font-size: 12px; line-height: 1;
  cursor: pointer; padding: 0; width: 14px; height: 14px;
  display: grid; place-items: center;
  border-radius: 50%;
  transition: all 0.12s ease; opacity: 0;
}
.bench-player:hover .bench-remove { opacity: 1; }
.bench-remove:hover { background: var(--red); color: #fff; }

/* ── Drag ghost ── */
.drag-ghost {
  position: fixed; pointer-events: none; z-index: 9999;
  background: var(--bg-card);
  border: 1px solid var(--accent);
  border-radius: 10px; padding: 6px 10px;
  display: flex; align-items: center; gap: 8px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.2);
  transform: translate(-50%, -50%);
  opacity: 0.95;
}

/* ── Mobile panel pull tabs ── */
.panel-pull-tab {
  display: none;
  position: absolute;
  top: 50%; transform: translateY(-50%);
  z-index: 55;
  appearance: none;
  background: var(--bg-card);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  width: 22px; height: 52px;
  padding: 0;
  align-items: center; justify-content: center;
  cursor: pointer; color: var(--ink-3);
  transition: background 0.15s ease, color 0.15s ease;
}
.panel-pull-tab:hover { background: var(--bg-soft); color: var(--ink); }
.panel-pull-tab-left  { left: 0;  border-left: none;  border-radius: 0 8px 8px 0; }
.panel-pull-tab-right { right: 0; border-right: none; border-radius: 8px 0 0 8px; }

/* ── Mobile backdrop (dims pitch when a panel is open) ── */
.panel-backdrop {
  display: none;
  position: absolute; inset: 0;
  background: rgba(0, 0, 0, 0.30);
  z-index: 45;
  cursor: pointer;
}
.panel-backdrop.visible { display: block; }

/* ── Mobile responsive ── */
@media (max-width: 900px) {
  .formations-main {
    position: relative;
    overflow: visible;
  }

  /* Panels become absolute overlays that slide in */
  .formations-panel {
    position: absolute;
    top: 0; bottom: 0;
    z-index: 50;
    width: 268px;
    flex: none;
    box-shadow: var(--shadow-lg);
    overflow-y: auto;
    transition: transform 0.38s cubic-bezier(0.22, 1, 0.36, 1);
  }
  .formations-panel-left {
    left: 0;
    transform: translateX(-100%);
    border-right: 1px solid var(--line);
  }
  .formations-panel-left.open  { transform: translateX(0); }
  .formations-panel-right {
    right: 0;
    transform: translateX(100%);
    border-left: 1px solid var(--line);
    border-right: none;
  }
  .formations-panel-right.open { transform: translateX(0); }

  /* Show pull tabs on mobile */
  .panel-pull-tab { display: flex; }
}
