.lineup-planner {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  max-height: min(78vh, 900px);
  overflow-y: auto;
  padding-right: 0.2rem;
}

.lineup-planner h4 {
  font-size: 1rem;
  margin-bottom: 0.25rem;
}

.lineup-label,
.lineup-format legend {
  display: block;
  margin-bottom: 0.35rem;
  font-size: 0.9rem;
  font-weight: 700;
}

.lineup-optional,
.lineup-help {
  color: var(--text-muted);
  font-size: 0.8rem;
  font-weight: 400;
}

.lineup-help {
  margin: 0.25rem 0 0.6rem;
}

.lineup-plan-controls,
.lineup-import-actions,
.lineup-chain-actions,
.lineup-footer {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.lineup-plan-controls > select {
  flex: 1 1 180px;
}

.lineup-format {
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 0.75rem;
}

.lineup-mode {
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 0.75rem;
}

.lineup-mode legend {
  padding: 0 0.3rem;
  font-weight: 700;
}

.lineup-format-options {
  display: flex;
  gap: 0.6rem;
  flex-wrap: wrap;
}

.lineup-format-option {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  min-height: 44px;
  padding: 0.35rem 0.8rem;
  border: 1px solid var(--border-color);
  border-radius: 7px;
  cursor: pointer;
}

.lineup-format-option input {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
}

.lineup-section {
  padding: 0.85rem;
  border: 1px solid var(--border-color);
  border-radius: 9px;
  background: var(--bg-secondary);
}

.lineup-section-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.7rem;
}

.lineup-import-text {
  min-height: 90px;
  resize: vertical;
  margin-bottom: 0.55rem;
}

.lineup-file-label {
  position: relative;
  overflow: hidden;
  cursor: pointer;
}

.lineup-file-label input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
}

.lineup-manual-add {
  flex: 1 1 170px;
}

.lineup-candidate-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 0.4rem;
  margin: 0.7rem 0 0;
  padding: 0;
  list-style: none;
}

.lineup-candidate-list li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
  padding: 0.35rem 0.45rem 0.35rem 0.65rem;
  border: 1px solid var(--border-color);
  border-radius: 7px;
  background: var(--bg-card);
}

.lineup-lines {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

.lineup-line {
  min-width: 0;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 0.65rem;
}

.lineup-line legend {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0 0.3rem;
  font-weight: 800;
}

.lineup-chain-row + .lineup-chain-row {
  margin-top: 0.75rem;
  padding-top: 0.65rem;
  border-top: 1px solid var(--border-color);
}

.lineup-chain-row h5,
.lineup-role-group h5 {
  margin-bottom: 0.45rem;
  font-size: 0.9rem;
  color: var(--accent);
}

.lineup-role-group + .lineup-role-group {
  margin-top: 1rem;
  padding-top: 0.85rem;
  border-top: 1px solid var(--border-color);
}

.lineup-group-add {
  display: flex;
  gap: 0.5rem;
}

.lineup-group-add select {
  flex: 1;
  min-width: 0;
  min-height: 44px;
}

.lineup-role-list {
  display: grid;
  gap: 0.4rem;
  margin: 0.55rem 0 0;
  padding: 0;
  list-style: none;
}

.lineup-role-list--2 {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.lineup-role-list--3 {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.lineup-role-list li {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  grid-template-areas:
    "position remove"
    "name remove";
  align-items: center;
  gap: 0.5rem;
  padding: 0.35rem 0.45rem 0.35rem 0.65rem;
  border: 1px solid var(--border-color);
  border-radius: 7px;
  background: var(--bg-card);
}

.lineup-role-slot {
  min-width: 0;
  cursor: grab;
}

.lineup-role-slot:active {
  cursor: grabbing;
}

.lineup-role-slot:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.lineup-role-slot.is-selected {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.lineup-role-slot.is-dragging {
  opacity: 0.45;
}

.lineup-role-slot.is-drop-target {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 12%, var(--bg-card));
}

.lineup-role-slot--empty {
  min-height: 4.5rem;
  border-style: dashed !important;
  color: var(--text-muted);
}

.lineup-role-slot--standalone {
  grid-column: 1 / -1;
}

.lineup-role-position {
  grid-area: position;
  color: var(--text-muted);
  font-size: 0.7rem;
  line-height: 1.2;
}

.lineup-role-name {
  grid-area: name;
  min-width: 0;
  overflow-wrap: anywhere;
}

.lineup-role-list .btn {
  grid-area: remove;
}

.lineup-slots {
  display: grid;
  gap: 0.5rem;
}

.lineup-slots--2 {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.lineup-slots--3 {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.lineup-slot {
  min-width: 0;
  font-size: 0.78rem;
  font-weight: 700;
}

.lineup-slot select {
  min-height: 44px;
  margin-top: 0.2rem;
}

.lineup-save-note,
.lineup-empty,
.lineup-status {
  color: var(--text-muted);
  font-size: 0.82rem;
}

.lineup-status:empty {
  display: none;
}

.lineup-status.is-error {
  color: var(--danger);
}

.lineup-footer {
  justify-content: flex-end;
  padding-top: 0.65rem;
  border-top: 1px solid var(--border-color);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@media (max-width: 600px) {
  .lineup-planner {
    max-height: 70vh;
  }

  .lineup-section {
    padding: 0.65rem;
  }

  .lineup-import-actions > .btn,
  .lineup-file-label {
    min-height: 44px;
  }

  .lineup-manual-add {
    flex-basis: 100%;
  }

  .lineup-chain-actions {
    width: 100%;
  }

  .lineup-group-add {
    flex-direction: column;
  }

  .lineup-group-add .btn {
    min-height: 44px;
  }

  .lineup-role-list li {
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 0.25rem;
    padding: 0.35rem;
  }

  .lineup-role-list .btn {
    min-height: 44px;
    padding: 0.25rem 0.35rem;
  }

  .lineup-slots--3 {
    gap: 0.3rem;
  }

  .lineup-chain-actions .btn {
    flex: 1 1 150px;
    min-height: 44px;
  }

  .lineup-footer .btn {
    flex: 1 1 130px;
    min-height: 44px;
  }
}
